Hibernate SVN: r11273 - branches/Branch_3_2/Hibernate3/src/org/hibernate/transaction.
by hibernate-commits@lists.jboss.org
Author: epbernard
Date: 2007-03-11 20:18:13 -0400 (Sun, 11 Mar 2007)
New Revision: 11273
Modified:
branches/Branch_3_2/Hibernate3/src/org/hibernate/transaction/SunONETransactionManagerLookup.java
Log:
JavaDoc
Modified: branches/Branch_3_2/Hibernate3/src/org/hibernate/transaction/SunONETransactionManagerLookup.java
===================================================================
--- branches/Branch_3_2/Hibernate3/src/org/hibernate/transaction/SunONETransactionManagerLookup.java 2007-03-12 00:17:45 UTC (rev 11272)
+++ branches/Branch_3_2/Hibernate3/src/org/hibernate/transaction/SunONETransactionManagerLookup.java 2007-03-12 00:18:13 UTC (rev 11273)
@@ -2,7 +2,8 @@
package org.hibernate.transaction;
/**
- * TransactionManager lookup strategy for Sun ONE Application Server 7
+ * TransactionManager lookup strategy for Sun ONE Application Server 7 and above
+ *
* @author Robert Davidson, Sanjeev Krishnan
* @author Emmanuel Bernard
*/
17 years, 1 month
Hibernate SVN: r11272 - trunk/Hibernate3/src/org/hibernate/event.
by hibernate-commits@lists.jboss.org
Author: epbernard
Date: 2007-03-11 20:17:45 -0400 (Sun, 11 Mar 2007)
New Revision: 11272
Modified:
trunk/Hibernate3/src/org/hibernate/event/PreDeleteEventListener.java
trunk/Hibernate3/src/org/hibernate/event/PreInsertEventListener.java
trunk/Hibernate3/src/org/hibernate/event/PreUpdateEventListener.java
Log:
JavaDoc
Modified: trunk/Hibernate3/src/org/hibernate/event/PreDeleteEventListener.java
===================================================================
--- trunk/Hibernate3/src/org/hibernate/event/PreDeleteEventListener.java 2007-03-12 00:16:48 UTC (rev 11271)
+++ trunk/Hibernate3/src/org/hibernate/event/PreDeleteEventListener.java 2007-03-12 00:17:45 UTC (rev 11272)
@@ -9,5 +9,8 @@
* @author Gavin King
*/
public interface PreDeleteEventListener extends Serializable {
+ /**
+ * Return true if the operation should be vetoed
+ */
public boolean onPreDelete(PreDeleteEvent event);
}
Modified: trunk/Hibernate3/src/org/hibernate/event/PreInsertEventListener.java
===================================================================
--- trunk/Hibernate3/src/org/hibernate/event/PreInsertEventListener.java 2007-03-12 00:16:48 UTC (rev 11271)
+++ trunk/Hibernate3/src/org/hibernate/event/PreInsertEventListener.java 2007-03-12 00:17:45 UTC (rev 11272)
@@ -9,5 +9,8 @@
* @author Gavin King
*/
public interface PreInsertEventListener extends Serializable {
+ /**
+ * Return true if the operation should be vetoed
+ */
public boolean onPreInsert(PreInsertEvent event);
}
Modified: trunk/Hibernate3/src/org/hibernate/event/PreUpdateEventListener.java
===================================================================
--- trunk/Hibernate3/src/org/hibernate/event/PreUpdateEventListener.java 2007-03-12 00:16:48 UTC (rev 11271)
+++ trunk/Hibernate3/src/org/hibernate/event/PreUpdateEventListener.java 2007-03-12 00:17:45 UTC (rev 11272)
@@ -9,5 +9,8 @@
* @author Gavin King
*/
public interface PreUpdateEventListener extends Serializable {
+ /**
+ * Return true if the operation should be vetoed
+ */
public boolean onPreUpdate(PreUpdateEvent event);
}
17 years, 1 month
Hibernate SVN: r11271 - branches/Branch_3_2/Hibernate3/src/org/hibernate/event.
by hibernate-commits@lists.jboss.org
Author: epbernard
Date: 2007-03-11 20:16:48 -0400 (Sun, 11 Mar 2007)
New Revision: 11271
Modified:
branches/Branch_3_2/Hibernate3/src/org/hibernate/event/PreDeleteEventListener.java
branches/Branch_3_2/Hibernate3/src/org/hibernate/event/PreInsertEventListener.java
branches/Branch_3_2/Hibernate3/src/org/hibernate/event/PreUpdateEventListener.java
Log:
JavaDoc
Modified: branches/Branch_3_2/Hibernate3/src/org/hibernate/event/PreDeleteEventListener.java
===================================================================
--- branches/Branch_3_2/Hibernate3/src/org/hibernate/event/PreDeleteEventListener.java 2007-03-10 00:03:27 UTC (rev 11270)
+++ branches/Branch_3_2/Hibernate3/src/org/hibernate/event/PreDeleteEventListener.java 2007-03-12 00:16:48 UTC (rev 11271)
@@ -9,5 +9,8 @@
* @author Gavin King
*/
public interface PreDeleteEventListener extends Serializable {
+ /**
+ * Return true if the operation should be vetoed
+ */
public boolean onPreDelete(PreDeleteEvent event);
}
Modified: branches/Branch_3_2/Hibernate3/src/org/hibernate/event/PreInsertEventListener.java
===================================================================
--- branches/Branch_3_2/Hibernate3/src/org/hibernate/event/PreInsertEventListener.java 2007-03-10 00:03:27 UTC (rev 11270)
+++ branches/Branch_3_2/Hibernate3/src/org/hibernate/event/PreInsertEventListener.java 2007-03-12 00:16:48 UTC (rev 11271)
@@ -9,5 +9,8 @@
* @author Gavin King
*/
public interface PreInsertEventListener extends Serializable {
+ /**
+ * Return true if the operation should be vetoed
+ */
public boolean onPreInsert(PreInsertEvent event);
}
Modified: branches/Branch_3_2/Hibernate3/src/org/hibernate/event/PreUpdateEventListener.java
===================================================================
--- branches/Branch_3_2/Hibernate3/src/org/hibernate/event/PreUpdateEventListener.java 2007-03-10 00:03:27 UTC (rev 11270)
+++ branches/Branch_3_2/Hibernate3/src/org/hibernate/event/PreUpdateEventListener.java 2007-03-12 00:16:48 UTC (rev 11271)
@@ -9,5 +9,8 @@
* @author Gavin King
*/
public interface PreUpdateEventListener extends Serializable {
+ /**
+ * Return true if the operation should be vetoed
+ */
public boolean onPreUpdate(PreUpdateEvent event);
}
17 years, 1 month
Hibernate SVN: r11270 - in branches/Branch_3_2/HibernateExt/entitymanager/src: test and 1 other directory.
by hibernate-commits@lists.jboss.org
Author: epbernard
Date: 2007-03-09 19:03:27 -0500 (Fri, 09 Mar 2007)
New Revision: 11270
Modified:
branches/Branch_3_2/HibernateExt/entitymanager/src/java/org/hibernate/ejb/packaging/JarVisitor.java
branches/Branch_3_2/HibernateExt/entitymanager/src/test/log4j.properties
Log:
EJB-275 WAS does not encode URL, fantastic!
Modified: branches/Branch_3_2/HibernateExt/entitymanager/src/java/org/hibernate/ejb/packaging/JarVisitor.java
===================================================================
--- branches/Branch_3_2/HibernateExt/entitymanager/src/java/org/hibernate/ejb/packaging/JarVisitor.java 2007-03-09 21:00:58 UTC (rev 11269)
+++ branches/Branch_3_2/HibernateExt/entitymanager/src/java/org/hibernate/ejb/packaging/JarVisitor.java 2007-03-10 00:03:27 UTC (rev 11270)
@@ -57,17 +57,28 @@
if ( "jar".equals( protocol )
|| "wsjar".equals( protocol ) ) { //Websphere has it's own way
+ //Original URL is like jar:protocol
jarUrl = new URL( file );
+ if ( "file".equals( jarUrl.getProtocol() ) ) {
+ //Do some voodoo magic because WAS doesn't think escaping URL is an interesting feature
+ if ( file.indexOf( ' ' ) != -1 ) {
+ //not escaped, need to voodoo
+ jarUrl = new File( jarUrl.getFile() ).toURI().toURL(); //goes by toURI to escape the path
+ }
+ } //otherwise left as is
}
- else if ( "zip".equals( protocol ) ) { //Weblogic has it's own way
+ else if ( "zip".equals( protocol ) //Weblogic has it's own way
+ || "code-source".equals( url.getProtocol() ) ) { //OC4J prevent ejb.jar access (ie everything without path)
//we have extracted the zip file, so it should be read as a file
- jarUrl = new URL( "file", null, file );
+ //Just in case some containers are as stupid as WAS: luckily WAS is closed source so nobody will dupe the bug
+ if ( file.indexOf( ' ' ) != -1 ) {
+ //not escaped, need to voodoo
+ jarUrl = new File(file).toURI().toURL(); //goes by toURI to escape the path
+ }
+ else {
+ jarUrl = new File(file).toURL();
+ }
}
- else if ("code-source".equals( url.getProtocol() ) ) {
- //OC4J prevent ejb.jar access (ie everything without path
- //fix contributed by the community
- jarUrl = new File(file).toURL();
- }
else {
jarUrl = new URL( protocol, url.getHost(), url.getPort(), file );
}
@@ -77,6 +88,7 @@
"Unable to determine JAR Url from " + url + ". Cause: " + e.getMessage()
);
}
+ log.trace("JAR URL from URL Entry: " + url + " >> " + jarUrl);
return jarUrl;
}
Modified: branches/Branch_3_2/HibernateExt/entitymanager/src/test/log4j.properties
===================================================================
--- branches/Branch_3_2/HibernateExt/entitymanager/src/test/log4j.properties 2007-03-09 21:00:58 UTC (rev 11269)
+++ branches/Branch_3_2/HibernateExt/entitymanager/src/test/log4j.properties 2007-03-10 00:03:27 UTC (rev 11270)
@@ -18,6 +18,7 @@
#log4j.logger.org.hibernate=debug
log4j.logger.org.hibernate.ejb=debug
+log4j.logger.org.hibernate.ejb.packaging=debug
log4j.logger.org.hibernate.reflection=debug
#log4j.logger.org.hibernate.engine.Cascades=debug
17 years, 1 month
Hibernate SVN: r11269 - branches/Branch_3_2/HibernateExt/annotations/doc/reference/en/modules.
by hibernate-commits@lists.jboss.org
Author: epbernard
Date: 2007-03-09 16:00:58 -0500 (Fri, 09 Mar 2007)
New Revision: 11269
Modified:
branches/Branch_3_2/HibernateExt/annotations/doc/reference/en/modules/entity.xml
Log:
ANN-570 doc typo
Modified: branches/Branch_3_2/HibernateExt/annotations/doc/reference/en/modules/entity.xml
===================================================================
--- branches/Branch_3_2/HibernateExt/annotations/doc/reference/en/modules/entity.xml 2007-03-09 17:10:33 UTC (rev 11268)
+++ branches/Branch_3_2/HibernateExt/annotations/doc/reference/en/modules/entity.xml 2007-03-09 21:00:58 UTC (rev 11269)
@@ -2704,7 +2704,7 @@
</sect3>
</sect2>
- <sect2 id="entity-hibspec-inheritance" revision="2">
+ <sect2 id="entity-hibspec-inheritance" revision="3">
<title>Inheritance</title>
<para>SINGLE_TABLE is a very powerful strategy but sometimes, and
@@ -2717,7 +2717,7 @@
column).</para>
<programlisting>@Entity
-<emphasis role="bold">@DiscriminatorForumla("case when forest_type is null then 0 else forest_type end")</emphasis>
+<emphasis role="bold">@DiscriminatorFormula("case when forest_type is null then 0 else forest_type end")</emphasis>
public class Forest { ... }</programlisting>
<para>By default, when querying the top entities, Hibernate does not put
17 years, 1 month
Hibernate SVN: r11268 - in branches/Branch_3_2/HibernateExt: validator/doc/reference/en and 1 other directory.
by hibernate-commits@lists.jboss.org
Author: epbernard
Date: 2007-03-09 12:10:33 -0500 (Fri, 09 Mar 2007)
New Revision: 11268
Modified:
branches/Branch_3_2/HibernateExt/entitymanager/src/java/org/hibernate/ejb/AbstractEntityManagerImpl.java
branches/Branch_3_2/HibernateExt/validator/doc/reference/en/master.xml
Log:
minor
Modified: branches/Branch_3_2/HibernateExt/entitymanager/src/java/org/hibernate/ejb/AbstractEntityManagerImpl.java
===================================================================
--- branches/Branch_3_2/HibernateExt/entitymanager/src/java/org/hibernate/ejb/AbstractEntityManagerImpl.java 2007-03-09 17:09:19 UTC (rev 11267)
+++ branches/Branch_3_2/HibernateExt/entitymanager/src/java/org/hibernate/ejb/AbstractEntityManagerImpl.java 2007-03-09 17:10:33 UTC (rev 11268)
@@ -640,7 +640,7 @@
Object entity = getRawSession().load( sose.getEntityName(), identifier );
if ( entity instanceof Serializable ) {
//avoid some user errors regarding boundary crossing
- pe = new OptimisticLockException( null, e, entity );
+ pe = new OptimisticLockException( null, e, entity );
}
else {
pe = new OptimisticLockException( e );
Modified: branches/Branch_3_2/HibernateExt/validator/doc/reference/en/master.xml
===================================================================
--- branches/Branch_3_2/HibernateExt/validator/doc/reference/en/master.xml 2007-03-09 17:09:19 UTC (rev 11267)
+++ branches/Branch_3_2/HibernateExt/validator/doc/reference/en/master.xml 2007-03-09 17:10:33 UTC (rev 11268)
@@ -1,69 +1,65 @@
-<?xml version="1.0" encoding="ISO-8859-1"?>
+<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE book PUBLIC "-//OASIS//DTD DocBook XML V4.3CR3//EN"
- "../../../../../Hibernate3/doc/reference/support/docbook-dtd/docbookx.dtd" [
- <!ENTITY defineconstraints SYSTEM "modules/defineconstraints.xml">
- <!ENTITY checkconstraints SYSTEM "modules/checkconstraints.xml">
- ]>
+"../../../../../Hibernate3/doc/reference/support/docbook-dtd/docbookx.dtd" [
+<!ENTITY defineconstraints SYSTEM "modules/defineconstraints.xml">
+<!ENTITY checkconstraints SYSTEM "modules/checkconstraints.xml">
+]>
<book lang="en">
- <bookinfo>
- <title>Hibernate Validator</title>
+ <bookinfo>
+ <title>Hibernate Validator</title>
- <subtitle>Reference Guide</subtitle>
+ <subtitle>Reference Guide</subtitle>
- <releaseinfo>3.2.2.GA</releaseinfo>
+ <releaseinfo>3.2.2.GA</releaseinfo>
- <mediaobject>
- <imageobject>
- <imagedata fileref="images/hibernate_logo_a.png" format="png"/>
- </imageobject>
- </mediaobject>
- </bookinfo>
+ <mediaobject>
+ <imageobject>
+ <imagedata fileref="images/hibernate_logo_a.png" format="png" />
+ </imageobject>
+ </mediaobject>
+ </bookinfo>
- <toc></toc>
+ <toc></toc>
- <preface id="preface" revision="1">
- <title>Preface</title>
- <para>Annotations are a very convenient and elegant way to specify invariant
- constraints for a domain model. You can, for example, express that a
- property should never be null, that the account balance should be strictly
- positive, etc. These domain model constraints are declared in the bean
- itself by annotating its properties. A validator can then read them and
- check for constraint violations. The validation mechanism can be executed in
- different layers in your application without having to duplicate any of
- these rules (presentation layer, data access layer). Following the DRY principle,
- Hibernate Validator has been designed for that purpose.
- </para>
+ <preface id="preface" revision="2">
+ <title>Preface</title>
- <para>Hibernate Validator works at two levels. First, it is able to check
- in-memory instances of a class for constraint violations. Second, it can
- apply the constraints to the Hibernate metamodel and incorporate them into
- the generated database schema.
- </para>
+ <para>Annotations are a very convenient and elegant way to specify
+ invariant constraints for a domain model. You can, for example, express
+ that a property should never be null, that the account balance should be
+ strictly positive, etc. These domain model constraints are declared in the
+ bean itself by annotating its properties. A validator can then read them
+ and check for constraint violations. The validation mechanism can be
+ executed in different layers in your application without having to
+ duplicate any of these rules (presentation layer, data access layer).
+ Following the DRY principle, Hibernate Validator has been designed for
+ that purpose.</para>
- <para>Each constraint annotation is associated to a validator implementation
- responsible for checking the constraint on the entity instance. A validator
- can also (optionally) apply the constraint to the Hibernate metamodel,
- allowing Hibernate to generate DDL that expresses the constraint. With the
- appropriate event listener, you can execute the checking operation on
- inserts and updates done by Hibernate. Hibernate Validator is not limited to
- use with Hibernate. You can easily use it anywhere in your
- application.
- </para>
+ <para>Hibernate Validator works at two levels. First, it is able to check
+ in-memory instances of a class for constraint violations. Second, it can
+ apply the constraints to the Hibernate metamodel and incorporate them into
+ the generated database schema.</para>
- <para>When checking instances at runtime, Hibernate Validator returns
- information about constraint violations in an array of
- <classname>InvalidValue</classname>
- s. Among other information, the
- <classname>InvalidValue</classname>
- contains an error description message
- that can embed the parameter values bundle with the annotation (eg. length
- limit), and message strings that may be externalized to a
- <classname>ResourceBundle</classname>
- .
- </para>
- </preface>
+ <para>Each constraint annotation is associated to a validator
+ implementation responsible for checking the constraint on the entity
+ instance. A validator can also (optionally) apply the constraint to the
+ Hibernate metamodel, allowing Hibernate to generate DDL that expresses the
+ constraint. With the appropriate event listener, you can execute the
+ checking operation on inserts and updates done by Hibernate. Hibernate
+ Validator is not limited to use with Hibernate. You can easily use it
+ anywhere in your application as well as with any Java Persistence provider
+ (entity listener provided).</para>
- &defineconstraints;
- &checkconstraints;
+ <para>When checking instances at runtime, Hibernate Validator returns
+ information about constraint violations in an array of
+ <classname>InvalidValue</classname> s. Among other information, the
+ <classname>InvalidValue</classname> contains an error description message
+ that can embed the parameter values bundle with the annotation (eg. length
+ limit), and message strings that may be externalized to a
+ <classname>ResourceBundle</classname> .</para>
+ </preface>
+ &defineconstraints;
+
+ &checkconstraints;
</book>
\ No newline at end of file
17 years, 1 month
Hibernate SVN: r11267 - branches/Branch_3_2/HibernateExt/search/src/test.
by hibernate-commits@lists.jboss.org
Author: epbernard
Date: 2007-03-09 12:09:19 -0500 (Fri, 09 Mar 2007)
New Revision: 11267
Modified:
branches/Branch_3_2/HibernateExt/search/src/test/hibernate.properties
branches/Branch_3_2/HibernateExt/search/src/test/log4j.properties
Log:
minor
Modified: branches/Branch_3_2/HibernateExt/search/src/test/hibernate.properties
===================================================================
--- branches/Branch_3_2/HibernateExt/search/src/test/hibernate.properties 2007-03-09 17:08:56 UTC (rev 11266)
+++ branches/Branch_3_2/HibernateExt/search/src/test/hibernate.properties 2007-03-09 17:09:19 UTC (rev 11267)
@@ -32,9 +32,9 @@
hibernate.connection.driver_class org.hsqldb.jdbcDriver
hibernate.connection.username sa
hibernate.connection.password
-hibernate.connection.url jdbc:hsqldb:hsql://localhost
-hibernate.connection.url jdbc:hsqldb:test
-hibernate.connection.url jdbc:hsqldb:.
+#hibernate.connection.url jdbc:hsqldb:hsql://localhost
+#hibernate.connection.url jdbc:hsqldb:test
+hibernate.connection.url jdbc:hsqldb:mem:common
## MySQL
Modified: branches/Branch_3_2/HibernateExt/search/src/test/log4j.properties
===================================================================
--- branches/Branch_3_2/HibernateExt/search/src/test/log4j.properties 2007-03-09 17:08:56 UTC (rev 11266)
+++ branches/Branch_3_2/HibernateExt/search/src/test/log4j.properties 2007-03-09 17:09:19 UTC (rev 11267)
@@ -13,10 +13,14 @@
### set log levels - for more verbose logging change 'info' to 'debug' ###
log4j.rootLogger=warn, stdout
+log4j.logger.org.jboss=info
+#log4j.logger.com.jboss=debug
log4j.logger.org.hibernate=info
+log4j.logger.org.hibernate.search=debug
+
### log just the SQL
log4j.logger.org.hibernate.SQL=debug
@@ -26,7 +30,7 @@
#log4j.logger.org.hibernate.type=debug
### log schema export/update ###
-log4j.logger.org.hibernate.tool.hbm2ddl=debug
+log4j.logger.org.hibernate.tool.hbm2ddl=warn
### log cache activity ###
#log4j.logger.org.hibernate.cache=debug
17 years, 1 month
Hibernate SVN: r11266 - in branches/Branch_3_2/HibernateExt/search: src/java/org/hibernate/search/backend/impl and 1 other directories.
by hibernate-commits@lists.jboss.org
Author: epbernard
Date: 2007-03-09 12:08:56 -0500 (Fri, 09 Mar 2007)
New Revision: 11266
Modified:
branches/Branch_3_2/HibernateExt/search/doc/reference/en/modules/architecture.xml
branches/Branch_3_2/HibernateExt/search/src/java/org/hibernate/search/backend/impl/BatchedQueueingProcessor.java
branches/Branch_3_2/HibernateExt/search/src/java/org/hibernate/search/backend/impl/lucene/LuceneWorker.java
Log:
minor and doc
Modified: branches/Branch_3_2/HibernateExt/search/doc/reference/en/modules/architecture.xml
===================================================================
--- branches/Branch_3_2/HibernateExt/search/doc/reference/en/modules/architecture.xml 2007-03-09 16:28:58 UTC (rev 11265)
+++ branches/Branch_3_2/HibernateExt/search/doc/reference/en/modules/architecture.xml 2007-03-09 17:08:56 UTC (rev 11266)
@@ -19,7 +19,9 @@
<para><productname>Hibernate Search</productname> can also use a Lucene
index to search an entity and return a (list of) managed entity saving you
from the tedious Object / Lucene Document mapping and low level Lucene APIs.
- The application code use the unified
+ The same persistence context is shared between Hibernate and Hibernate
+ Search ; as a matter of fact, the Seearch Session is built on top of the
+ Hibernate Session. The application code use the unified
<classname>org.hibernate.Query</classname> API exactly the way a HQL or
native query would be done.</para>
Modified: branches/Branch_3_2/HibernateExt/search/src/java/org/hibernate/search/backend/impl/BatchedQueueingProcessor.java
===================================================================
--- branches/Branch_3_2/HibernateExt/search/src/java/org/hibernate/search/backend/impl/BatchedQueueingProcessor.java 2007-03-09 16:28:58 UTC (rev 11265)
+++ branches/Branch_3_2/HibernateExt/search/src/java/org/hibernate/search/backend/impl/BatchedQueueingProcessor.java 2007-03-09 17:08:56 UTC (rev 11266)
@@ -89,7 +89,14 @@
public void add(Work work, List<Work> queue) {
//TODO optimize by getting rid of dupe works
if ( work instanceof UpdateWork ) {
- //split in 2 to optimize the process (reader first, writer next
+ //split in 2 to optimize the process (reader first, writer next)
+ /**
+ * even with Lucene 2.1, use of indexWriter to update is not an option
+ * We can only delete by term, and the index doesn't have a term that
+ * uniquely identify the entry.
+ * But essentially the optimization we are doing is the same Lucene is doing, the only extra cost is the
+ * double file opening.
+ */
queue.add( new DeleteWork( work.getId(), work.getEntity() ) );
queue.add( new AddWork( work.getId(), work.getEntity(), work.getDocument() ) );
}
Modified: branches/Branch_3_2/HibernateExt/search/src/java/org/hibernate/search/backend/impl/lucene/LuceneWorker.java
===================================================================
--- branches/Branch_3_2/HibernateExt/search/src/java/org/hibernate/search/backend/impl/lucene/LuceneWorker.java 2007-03-09 16:28:58 UTC (rev 11265)
+++ branches/Branch_3_2/HibernateExt/search/src/java/org/hibernate/search/backend/impl/lucene/LuceneWorker.java 2007-03-09 17:08:56 UTC (rev 11266)
@@ -68,6 +68,11 @@
}
public void performWork(UpdateWork work) {
+ /**
+ * even with Lucene 2.1, use of indexWriter to update is not an option
+ * We can only delete by term, and the index doesn't have a term that
+ * uniquely identify the entry.
+ */
Class entity = work.getEntity();
Serializable id = work.getId();
Document document = work.getDocument();
@@ -82,6 +87,11 @@
}
private void remove(Class entity, Serializable id) {
+ /**
+ * even with Lucene 2.1, use of indexWriter to delte is not an option
+ * We can only delete by term, and the index doesn't have a termt that
+ * uniquely identify the entry. See logic below
+ */
log.trace( "remove from Lucene index: " + entity + "#" + id );
DocumentBuilder builder = workspace.getDocumentBuilder( entity );
Term term = builder.getTerm( id );
17 years, 1 month
Hibernate SVN: r11265 - in branches/Branch_3_2/HibernateExt/annotations: src/java/org/hibernate/annotations and 3 other directories.
by hibernate-commits@lists.jboss.org
Author: epbernard
Date: 2007-03-09 11:28:58 -0500 (Fri, 09 Mar 2007)
New Revision: 11265
Added:
branches/Branch_3_2/HibernateExt/annotations/src/java/org/hibernate/annotations/Persister.java
branches/Branch_3_2/HibernateExt/annotations/src/test/org/hibernate/test/annotations/persister/
branches/Branch_3_2/HibernateExt/annotations/src/test/org/hibernate/test/annotations/persister/Card.java
branches/Branch_3_2/HibernateExt/annotations/src/test/org/hibernate/test/annotations/persister/CollectionPersister.java
branches/Branch_3_2/HibernateExt/annotations/src/test/org/hibernate/test/annotations/persister/Deck.java
branches/Branch_3_2/HibernateExt/annotations/src/test/org/hibernate/test/annotations/persister/EntityPersister.java
branches/Branch_3_2/HibernateExt/annotations/src/test/org/hibernate/test/annotations/persister/PersisterTest.java
Modified:
branches/Branch_3_2/HibernateExt/annotations/doc/reference/en/modules/entity.xml
branches/Branch_3_2/HibernateExt/annotations/src/java/org/hibernate/cfg/annotations/CollectionBinder.java
branches/Branch_3_2/HibernateExt/annotations/src/java/org/hibernate/cfg/annotations/EntityBinder.java
branches/Branch_3_2/HibernateExt/annotations/src/java/org/hibernate/cfg/annotations/PropertyBinder.java
Log:
ANN-567 Persister for collections (Shawn Clowater)
Modified: branches/Branch_3_2/HibernateExt/annotations/doc/reference/en/modules/entity.xml
===================================================================
--- branches/Branch_3_2/HibernateExt/annotations/doc/reference/en/modules/entity.xml 2007-03-09 04:24:33 UTC (rev 11264)
+++ branches/Branch_3_2/HibernateExt/annotations/doc/reference/en/modules/entity.xml 2007-03-09 16:28:58 UTC (rev 11265)
@@ -2268,10 +2268,6 @@
</listitem>
<listitem>
- persister: allow the overriding of the default persister implementation
- </listitem>
-
- <listitem>
optimisticLock: optimistic locking strategy (OptimisticLockType.VERSION, OptimisticLockType.NONE, OptimisticLockType.DIRTY or OptimisticLockType.ALL)
</listitem>
</itemizedlist></para>
@@ -2362,6 +2358,14 @@
entity may not be updated or deleted by the application. This allows
Hibernate to make some minor performance optimizations.</para>
+ <para><literal>@Persister</literal> lets you define your own custom
+ persistence strategy. You may, for example, specify your own subclass of
+ <classname>org.hibernate.persister.EntityPersister</classname> or you
+ might even provide a completely new implementation of the interface
+ <literal>org.hibernate.persister.ClassPersister</literal> that
+ implements persistence via, for example, stored procedure calls,
+ serialization to flat files or LDAP.</para>
+
<para><programlisting>@Entity
@BatchSize(size=5)
@org.hibernate.annotations.Entity(
@@ -2371,6 +2375,7 @@
polymorphism = PolymorphismType.EXPLICIT)
@Where(clause="1=1")
@org.hibernate.annotations.Table(name="Forest", indexes = { @Index(name="idx", columnNames = { "name", "length" } ) } )
+(a)Persister(impl=MyEntityPersister.class)
public class Forest { ... }</programlisting><programlisting>@Entity
@Inheritance(
strategy=InheritanceType.JOINED
@@ -2923,6 +2928,14 @@
<listitem>
the collection immutability using @Immutable: if set specifies that the elements of the collection never change (a minor performance optimization in some cases)
</listitem>
+
+ <listitem>
+ <para>a custom collection persister (ie the persistence strategy
+ used) using <literal>@Persister</literal>: the class must
+ implement
+ <classname>org.hibernate.persister.collectionCollectionPersister</classname>
+ </para>
+ </listitem>
</itemizedlist></para>
<para>You can also declare a sort comparator. Use the
Added: branches/Branch_3_2/HibernateExt/annotations/src/java/org/hibernate/annotations/Persister.java
===================================================================
--- branches/Branch_3_2/HibernateExt/annotations/src/java/org/hibernate/annotations/Persister.java (rev 0)
+++ branches/Branch_3_2/HibernateExt/annotations/src/java/org/hibernate/annotations/Persister.java 2007-03-09 16:28:58 UTC (rev 11265)
@@ -0,0 +1,16 @@
+//$Id: $
+package org.hibernate.annotations;
+
+import java.lang.annotation.*;
+
+/**
+ * Specify a custom persister.
+ *
+ * @author Shawn Clowater
+ */
+(a)java.lang.annotation.Target({ElementType.TYPE, ElementType.METHOD, ElementType.FIELD})
+@Retention( RetentionPolicy.RUNTIME )
+public @interface Persister {
+ /** Custom persister */
+ Class impl();
+}
Modified: branches/Branch_3_2/HibernateExt/annotations/src/java/org/hibernate/cfg/annotations/CollectionBinder.java
===================================================================
--- branches/Branch_3_2/HibernateExt/annotations/src/java/org/hibernate/cfg/annotations/CollectionBinder.java 2007-03-09 04:24:33 UTC (rev 11264)
+++ branches/Branch_3_2/HibernateExt/annotations/src/java/org/hibernate/cfg/annotations/CollectionBinder.java 2007-03-09 16:28:58 UTC (rev 11265)
@@ -47,6 +47,7 @@
import org.hibernate.annotations.Loader;
import org.hibernate.annotations.Immutable;
import org.hibernate.annotations.OptimisticLock;
+import org.hibernate.annotations.Persister;
import org.hibernate.cfg.AnnotatedClassType;
import org.hibernate.cfg.AnnotationBinder;
import org.hibernate.cfg.BinderHelper;
@@ -310,6 +311,8 @@
collection.setMutable( ! property.isAnnotationPresent( Immutable.class ) );
OptimisticLock lockAnn = property.getAnnotation( OptimisticLock.class );
if (lockAnn != null) collection.setOptimisticLocked( ! lockAnn.excluded() );
+ Persister persisterAnn = property.getAnnotation( Persister.class );
+ if ( persisterAnn != null ) collection.setCollectionPersisterClass( persisterAnn.impl() );
// set ordering
if ( orderBy != null ) collection.setOrderBy( orderBy );
Modified: branches/Branch_3_2/HibernateExt/annotations/src/java/org/hibernate/cfg/annotations/EntityBinder.java
===================================================================
--- branches/Branch_3_2/HibernateExt/annotations/src/java/org/hibernate/cfg/annotations/EntityBinder.java 2007-03-09 04:24:33 UTC (rev 11264)
+++ branches/Branch_3_2/HibernateExt/annotations/src/java/org/hibernate/cfg/annotations/EntityBinder.java 2007-03-09 16:28:58 UTC (rev 11265)
@@ -39,6 +39,7 @@
import org.hibernate.annotations.Tuplizer;
import org.hibernate.annotations.Immutable;
import org.hibernate.annotations.FetchMode;
+import org.hibernate.annotations.Persister;
import org.hibernate.cache.CacheFactory;
import org.hibernate.cfg.AnnotationBinder;
import org.hibernate.cfg.BinderHelper;
@@ -79,7 +80,6 @@
private boolean dynamicUpdate;
private boolean explicitHibernateEntityAnnotation;
private OptimisticLockType optimisticLockType;
- private String persister;
private PolymorphismType polymorphismType;
private boolean selectBeforeUpdate;
private int batchSize;
@@ -123,17 +123,16 @@
dynamicInsert = hibAnn.dynamicInsert();
dynamicUpdate = hibAnn.dynamicUpdate();
optimisticLockType = hibAnn.optimisticLock();
- persister = hibAnn.persister();
selectBeforeUpdate = hibAnn.selectBeforeUpdate();
polymorphismType = hibAnn.polymorphism();
explicitHibernateEntityAnnotation = true;
+ //persister handled in bind
}
else {
//default values when the annotation is not there
dynamicInsert = false;
dynamicUpdate = false;
optimisticLockType = OptimisticLockType.VERSION;
- persister = "";
polymorphismType = PolymorphismType.IMPLICIT;
selectBeforeUpdate = false;
}
@@ -200,14 +199,27 @@
}
persistentClass.setOptimisticLockMode( getVersioning( optimisticLockType ) );
persistentClass.setSelectBeforeUpdate( selectBeforeUpdate );
- if ( !BinderHelper.isDefault( persister ) ) {
- try {
- persistentClass.setEntityPersisterClass( ReflectHelper.classForName( persister ) );
+
+ //set persister if needed
+ //@Persister has precedence over @Entity.persister
+ Persister persisterAnn = annotatedClass.getAnnotation( Persister.class );
+ Class persister = null;
+ if ( persisterAnn!= null ) {
+ persister = persisterAnn.impl();
+ }
+ else {
+ org.hibernate.annotations.Entity entityAnn = annotatedClass.getAnnotation( org.hibernate.annotations.Entity.class );
+ if (entityAnn != null && !BinderHelper.isDefault( entityAnn.persister() ) ) {
+ try {
+ persister = ReflectHelper.classForName( entityAnn.persister() );
+ }
+ catch (ClassNotFoundException cnfe) {
+ throw new AnnotationException( "Could not find persister class: " + persister );
+ }
}
- catch (ClassNotFoundException cnfe) {
- throw new AnnotationException( "Could not find persister class: " + persister );
- }
}
+ if ( persister != null ) persistentClass.setEntityPersisterClass(persister);
+
persistentClass.setBatchSize( batchSize );
//SQL overriding
Modified: branches/Branch_3_2/HibernateExt/annotations/src/java/org/hibernate/cfg/annotations/PropertyBinder.java
===================================================================
--- branches/Branch_3_2/HibernateExt/annotations/src/java/org/hibernate/cfg/annotations/PropertyBinder.java 2007-03-09 04:24:33 UTC (rev 11264)
+++ branches/Branch_3_2/HibernateExt/annotations/src/java/org/hibernate/cfg/annotations/PropertyBinder.java 2007-03-09 16:28:58 UTC (rev 11265)
@@ -155,7 +155,9 @@
}
prop.setInsertable( insertable );
prop.setUpdateable( updatable );
- OptimisticLock lockAnn = property.getAnnotation( OptimisticLock.class );
+ OptimisticLock lockAnn = property != null ?
+ property.getAnnotation( OptimisticLock.class ) :
+ null;
if ( lockAnn != null) {
prop.setOptimisticLocked( ! lockAnn.excluded() );
//TODO this should go to the core as a mapping validation checking
Added: branches/Branch_3_2/HibernateExt/annotations/src/test/org/hibernate/test/annotations/persister/Card.java
===================================================================
--- branches/Branch_3_2/HibernateExt/annotations/src/test/org/hibernate/test/annotations/persister/Card.java (rev 0)
+++ branches/Branch_3_2/HibernateExt/annotations/src/test/org/hibernate/test/annotations/persister/Card.java 2007-03-09 16:28:58 UTC (rev 11265)
@@ -0,0 +1,21 @@
+package org.hibernate.test.annotations.persister;
+
+import java.io.Serializable;
+import javax.persistence.Entity;
+import javax.persistence.Id;
+import javax.persistence.JoinColumn;
+import javax.persistence.ManyToOne;
+
+/**
+ * @author Shawn Clowater
+ */
+@Entity
+(a)org.hibernate.annotations.Entity( persister = "org.hibernate.persister.entity.SingleTableEntityPersister" )
+public class Card implements Serializable {
+ @Id
+ public Integer id;
+
+ @ManyToOne()
+ @JoinColumn()
+ public Deck deck;
+}
\ No newline at end of file
Added: branches/Branch_3_2/HibernateExt/annotations/src/test/org/hibernate/test/annotations/persister/CollectionPersister.java
===================================================================
--- branches/Branch_3_2/HibernateExt/annotations/src/test/org/hibernate/test/annotations/persister/CollectionPersister.java (rev 0)
+++ branches/Branch_3_2/HibernateExt/annotations/src/test/org/hibernate/test/annotations/persister/CollectionPersister.java 2007-03-09 16:28:58 UTC (rev 11265)
@@ -0,0 +1,19 @@
+package org.hibernate.test.annotations.persister;
+
+import org.hibernate.MappingException;
+import org.hibernate.cache.CacheConcurrencyStrategy;
+import org.hibernate.cache.CacheException;
+import org.hibernate.cfg.Configuration;
+import org.hibernate.engine.SessionFactoryImplementor;
+import org.hibernate.mapping.Collection;
+import org.hibernate.persister.collection.OneToManyPersister;
+
+/**
+ * @author Shawn Clowater
+ */
+public class CollectionPersister extends OneToManyPersister {
+ public CollectionPersister(Collection collection, CacheConcurrencyStrategy cache, Configuration cfg,
+ SessionFactoryImplementor factory) throws MappingException, CacheException {
+ super( collection, cache, cfg, factory );
+ }
+}
\ No newline at end of file
Added: branches/Branch_3_2/HibernateExt/annotations/src/test/org/hibernate/test/annotations/persister/Deck.java
===================================================================
--- branches/Branch_3_2/HibernateExt/annotations/src/test/org/hibernate/test/annotations/persister/Deck.java (rev 0)
+++ branches/Branch_3_2/HibernateExt/annotations/src/test/org/hibernate/test/annotations/persister/Deck.java 2007-03-09 16:28:58 UTC (rev 11265)
@@ -0,0 +1,25 @@
+package org.hibernate.test.annotations.persister;
+
+import java.io.Serializable;
+import java.util.Set;
+import javax.persistence.Entity;
+import javax.persistence.Id;
+import javax.persistence.OneToMany;
+
+import org.hibernate.annotations.Persister;
+
+
+/**
+ * @author Shawn Clowater
+ */
+@Entity
+(a)org.hibernate.annotations.Entity( persister = "org.hibernate.persister.entity.SingleTableEntityPersister" )
+@Persister( impl = org.hibernate.test.annotations.persister.EntityPersister.class )
+public class Deck implements Serializable {
+ @Id
+ public Integer id;
+
+ @OneToMany( mappedBy = "deck" )
+ @Persister( impl = org.hibernate.test.annotations.persister.CollectionPersister.class )
+ public Set<Card> cards;
+}
\ No newline at end of file
Added: branches/Branch_3_2/HibernateExt/annotations/src/test/org/hibernate/test/annotations/persister/EntityPersister.java
===================================================================
--- branches/Branch_3_2/HibernateExt/annotations/src/test/org/hibernate/test/annotations/persister/EntityPersister.java (rev 0)
+++ branches/Branch_3_2/HibernateExt/annotations/src/test/org/hibernate/test/annotations/persister/EntityPersister.java 2007-03-09 16:28:58 UTC (rev 11265)
@@ -0,0 +1,18 @@
+package org.hibernate.test.annotations.persister;
+
+import org.hibernate.HibernateException;
+import org.hibernate.cache.CacheConcurrencyStrategy;
+import org.hibernate.engine.Mapping;
+import org.hibernate.engine.SessionFactoryImplementor;
+import org.hibernate.mapping.PersistentClass;
+import org.hibernate.persister.entity.SingleTableEntityPersister;
+
+/**
+ * @author Shawn Clowater
+ */
+public class EntityPersister extends SingleTableEntityPersister {
+ public EntityPersister(PersistentClass persistentClass, CacheConcurrencyStrategy cache,
+ SessionFactoryImplementor factory, Mapping cfg) throws HibernateException {
+ super( persistentClass, cache, factory, cfg );
+ }
+}
\ No newline at end of file
Added: branches/Branch_3_2/HibernateExt/annotations/src/test/org/hibernate/test/annotations/persister/PersisterTest.java
===================================================================
--- branches/Branch_3_2/HibernateExt/annotations/src/test/org/hibernate/test/annotations/persister/PersisterTest.java (rev 0)
+++ branches/Branch_3_2/HibernateExt/annotations/src/test/org/hibernate/test/annotations/persister/PersisterTest.java 2007-03-09 16:28:58 UTC (rev 11265)
@@ -0,0 +1,47 @@
+package org.hibernate.test.annotations.persister;
+
+import org.hibernate.mapping.Collection;
+import org.hibernate.mapping.PersistentClass;
+import org.hibernate.persister.entity.SingleTableEntityPersister;
+import org.hibernate.test.annotations.TestCase;
+
+/**
+ * @author Shawn Clowater
+ */
+public class PersisterTest extends TestCase {
+ public PersisterTest(String x) {
+ super( x );
+ }
+
+ public void testEntityEntityPersisterAndPersisterSpecified() throws Exception {
+ //checks to see that the persister specified with the @Persister annotation takes precedence if a @Entity.persister() is also specified
+ PersistentClass persistentClass = (PersistentClass) getCfg().getClassMapping( Deck.class.getName() );
+ assertEquals( "Incorrect Persister class for " + persistentClass.getMappedClass(), EntityPersister.class,
+ persistentClass.getEntityPersisterClass() );
+ }
+
+ public void testEntityEntityPersisterSpecified() throws Exception {
+ //tests the persister specified with an @Entity.persister()
+ PersistentClass persistentClass = (PersistentClass) getCfg().getClassMapping( Card.class.getName() );
+ assertEquals( "Incorrect Persister class for " + persistentClass.getMappedClass(),
+ SingleTableEntityPersister.class, persistentClass.getEntityPersisterClass() );
+ }
+
+ public void testCollectionPersisterSpecified() throws Exception {
+ //tests the persister specified by the @Persister annotation on a collection
+ Collection collection = (Collection) getCfg().getCollectionMapping( Deck.class.getName() + ".cards" );
+ assertEquals( "Incorrect Persister class for collection " + collection.getRole(), CollectionPersister.class,
+ collection.getCollectionPersisterClass() );
+ }
+
+ /**
+ * @see org.hibernate.test.annotations.TestCase#getMappings()
+ */
+ protected Class[] getMappings() {
+ return new Class[]{
+ Card.class,
+ Deck.class
+ };
+ }
+
+}
\ No newline at end of file
17 years, 1 month
Hibernate SVN: r11264 - in branches/Branch_3_2/HibernateExt/annotations: src/java/org/hibernate/annotations and 3 other directories.
by hibernate-commits@lists.jboss.org
Author: epbernard
Date: 2007-03-08 23:24:33 -0500 (Thu, 08 Mar 2007)
New Revision: 11264
Added:
branches/Branch_3_2/HibernateExt/annotations/src/java/org/hibernate/annotations/OptimisticLock.java
branches/Branch_3_2/HibernateExt/annotations/src/test/org/hibernate/test/annotations/various/VersionTest.java
Modified:
branches/Branch_3_2/HibernateExt/annotations/doc/reference/en/modules/entity.xml
branches/Branch_3_2/HibernateExt/annotations/src/java/org/hibernate/cfg/AnnotationBinder.java
branches/Branch_3_2/HibernateExt/annotations/src/java/org/hibernate/cfg/annotations/CollectionBinder.java
branches/Branch_3_2/HibernateExt/annotations/src/java/org/hibernate/cfg/annotations/PropertyBinder.java
branches/Branch_3_2/HibernateExt/annotations/src/test/org/hibernate/test/annotations/various/Conductor.java
Log:
ANN-26 Support exclusion from optimistic locking scheme
Modified: branches/Branch_3_2/HibernateExt/annotations/doc/reference/en/modules/entity.xml
===================================================================
--- branches/Branch_3_2/HibernateExt/annotations/doc/reference/en/modules/entity.xml 2007-03-08 01:42:10 UTC (rev 11263)
+++ branches/Branch_3_2/HibernateExt/annotations/doc/reference/en/modules/entity.xml 2007-03-09 04:24:33 UTC (rev 11264)
@@ -2324,7 +2324,7 @@
</note>
<para><literal>@org.hibernate.annotations.Table</literal> can also be
- used to define the following elements of secondary tables: </para>
+ used to define the following elements of secondary tables:</para>
<itemizedlist>
<listitem>
@@ -2349,7 +2349,7 @@
<para><literal>optional</literal>: If enabled (the default),
Hibernate will insert a row only if the properties defined by this
join are non-null and will always use an outer join to retrieve the
- properties. </para>
+ properties.</para>
</listitem>
<listitem>
@@ -2685,6 +2685,18 @@
<para></para>
</sect3>
+
+ <sect3>
+ <title>Optimistic lock</title>
+
+ <para>It is sometimes useful to avoid increasing the version number
+ even if a given property is dirty (particularly collections). You can
+ do that by annotating the property (or collection) with
+ <literal>@OptimisticLock(excluded=true)</literal>.</para>
+
+ <para>More formally, specifies that updates to this property do not
+ require acquisition of the optimistic lock.</para>
+ </sect3>
</sect2>
<sect2 id="entity-hibspec-inheritance" revision="2">
@@ -3414,7 +3426,7 @@
</sect2>
<sect2 id="entity-hibspec-customsql" revision="1">
- <title> Custom SQL for CRUD operations</title>
+ <title>Custom SQL for CRUD operations</title>
<para>Hibernate gives you the avility to override every single SQL
statement generated. We have seen native SQL query usage already, but
Added: branches/Branch_3_2/HibernateExt/annotations/src/java/org/hibernate/annotations/OptimisticLock.java
===================================================================
--- branches/Branch_3_2/HibernateExt/annotations/src/java/org/hibernate/annotations/OptimisticLock.java (rev 0)
+++ branches/Branch_3_2/HibernateExt/annotations/src/java/org/hibernate/annotations/OptimisticLock.java 2007-03-09 04:24:33 UTC (rev 11264)
@@ -0,0 +1,24 @@
+//$Id: $
+package org.hibernate.annotations;
+
+import java.lang.annotation.ElementType;
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+import java.lang.annotation.Target;
+
+/**
+ * Whether or not update entity's version on property's change
+ * If the annotation is not present, the property is involved in the optimistic lock srategy (default)
+ *
+ * @author Logi Ragnarsson
+ */
+@Target( {ElementType.METHOD, ElementType.FIELD} )
+@Retention( RetentionPolicy.RUNTIME )
+public @interface OptimisticLock {
+
+ /**
+ * If true, the annotated property change will not trigger a version upgrade
+ */
+ boolean excluded();
+
+}
Modified: branches/Branch_3_2/HibernateExt/annotations/src/java/org/hibernate/cfg/AnnotationBinder.java
===================================================================
--- branches/Branch_3_2/HibernateExt/annotations/src/java/org/hibernate/cfg/AnnotationBinder.java 2007-03-08 01:42:10 UTC (rev 11263)
+++ branches/Branch_3_2/HibernateExt/annotations/src/java/org/hibernate/cfg/AnnotationBinder.java 2007-03-09 04:24:33 UTC (rev 11264)
@@ -1201,7 +1201,7 @@
|| property.isAnnotationPresent( EmbeddedId.class ) ) ) {
if ( isIdentifierMapper ) {
throw new AnnotationException(
- "@IdClass class should not have @Id nor @EmbeddedId proeperties"
+ "@IdClass class should not have @Id nor @EmbeddedId properties"
);
}
log.debug( inferredData.getPropertyName() + " is an id" );
Modified: branches/Branch_3_2/HibernateExt/annotations/src/java/org/hibernate/cfg/annotations/CollectionBinder.java
===================================================================
--- branches/Branch_3_2/HibernateExt/annotations/src/java/org/hibernate/cfg/annotations/CollectionBinder.java 2007-03-08 01:42:10 UTC (rev 11263)
+++ branches/Branch_3_2/HibernateExt/annotations/src/java/org/hibernate/cfg/annotations/CollectionBinder.java 2007-03-09 04:24:33 UTC (rev 11264)
@@ -46,6 +46,7 @@
import org.hibernate.annotations.SQLDeleteAll;
import org.hibernate.annotations.Loader;
import org.hibernate.annotations.Immutable;
+import org.hibernate.annotations.OptimisticLock;
import org.hibernate.cfg.AnnotatedClassType;
import org.hibernate.cfg.AnnotationBinder;
import org.hibernate.cfg.BinderHelper;
@@ -307,6 +308,8 @@
}
collection.setMutable( ! property.isAnnotationPresent( Immutable.class ) );
+ OptimisticLock lockAnn = property.getAnnotation( OptimisticLock.class );
+ if (lockAnn != null) collection.setOptimisticLocked( ! lockAnn.excluded() );
// set ordering
if ( orderBy != null ) collection.setOrderBy( orderBy );
Modified: branches/Branch_3_2/HibernateExt/annotations/src/java/org/hibernate/cfg/annotations/PropertyBinder.java
===================================================================
--- branches/Branch_3_2/HibernateExt/annotations/src/java/org/hibernate/cfg/annotations/PropertyBinder.java 2007-03-08 01:42:10 UTC (rev 11263)
+++ branches/Branch_3_2/HibernateExt/annotations/src/java/org/hibernate/cfg/annotations/PropertyBinder.java 2007-03-09 04:24:33 UTC (rev 11264)
@@ -1,11 +1,15 @@
//$Id$
package org.hibernate.cfg.annotations;
+import javax.persistence.Id;
+import javax.persistence.EmbeddedId;
+
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.hibernate.AnnotationException;
import org.hibernate.annotations.Generated;
import org.hibernate.annotations.GenerationTime;
+import org.hibernate.annotations.OptimisticLock;
import org.hibernate.cfg.Ejb3Column;
import org.hibernate.cfg.ExtendedMappings;
import org.hibernate.cfg.PropertyHolder;
@@ -151,6 +155,18 @@
}
prop.setInsertable( insertable );
prop.setUpdateable( updatable );
+ OptimisticLock lockAnn = property.getAnnotation( OptimisticLock.class );
+ if ( lockAnn != null) {
+ prop.setOptimisticLocked( ! lockAnn.excluded() );
+ //TODO this should go to the core as a mapping validation checking
+ if ( lockAnn.excluded() && (
+ property.isAnnotationPresent( javax.persistence.Version.class )
+ || property.isAnnotationPresent( Id.class )
+ || property.isAnnotationPresent( EmbeddedId.class ) ) ) {
+ throw new AnnotationException("@OptimisticLock.exclude=true incompatible with @Id, @EmbeddedId and @Version: "
+ + StringHelper.qualify( holder.getPath(), name ) );
+ }
+ }
log.trace( "Cascading " + name + " with " + cascade );
return prop;
}
Modified: branches/Branch_3_2/HibernateExt/annotations/src/test/org/hibernate/test/annotations/various/Conductor.java
===================================================================
--- branches/Branch_3_2/HibernateExt/annotations/src/test/org/hibernate/test/annotations/various/Conductor.java 2007-03-08 01:42:10 UTC (rev 11263)
+++ branches/Branch_3_2/HibernateExt/annotations/src/test/org/hibernate/test/annotations/various/Conductor.java 2007-03-09 04:24:33 UTC (rev 11264)
@@ -5,8 +5,10 @@
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
+import javax.persistence.Version;
import org.hibernate.annotations.Index;
+import org.hibernate.annotations.OptimisticLock;
/**
* @author Emmanuel Bernard
@@ -19,8 +21,21 @@
@Column(name = "cond_name")
@Index(name = "cond_name")
+ @OptimisticLock(excluded = true)
private String name;
+ @Version
+ private Long version;
+
+
+ public Long getVersion() {
+ return version;
+ }
+
+ public void setVersion(Long version) {
+ this.version = version;
+ }
+
public Integer getId() {
return id;
}
Added: branches/Branch_3_2/HibernateExt/annotations/src/test/org/hibernate/test/annotations/various/VersionTest.java
===================================================================
--- branches/Branch_3_2/HibernateExt/annotations/src/test/org/hibernate/test/annotations/various/VersionTest.java (rev 0)
+++ branches/Branch_3_2/HibernateExt/annotations/src/test/org/hibernate/test/annotations/various/VersionTest.java 2007-03-09 04:24:33 UTC (rev 11264)
@@ -0,0 +1,41 @@
+//$Id: $
+package org.hibernate.test.annotations.various;
+
+import org.hibernate.Session;
+import org.hibernate.test.annotations.TestCase;
+
+/**
+ * @author Emmanuel Bernard
+ */
+public class VersionTest extends TestCase {
+
+ public void testOptimisticLockDisabled() throws Exception {
+ Conductor c = new Conductor();
+ c.setName( "Bob" );
+ Session s = openSession( );
+ s.getTransaction().begin();
+ s.persist( c );
+ s.flush();
+
+ s.clear();
+
+ c = (Conductor) s.get( Conductor.class, c.getId() );
+ Long version = c.getVersion();
+ c.setName( "Don" );
+ s.flush();
+
+ s.clear();
+
+ c = (Conductor) s.get( Conductor.class, c.getId() );
+ assertEquals( version, c.getVersion() );
+
+ s.getTransaction().rollback();
+ s.close();
+ }
+
+ protected Class[] getMappings() {
+ return new Class[] {
+ Conductor.class
+ };
+ }
+}
17 years, 1 month