[hibernate-commits] Hibernate SVN: r11191 - in branches/Branch_3_2/HibernateExt/annotations/src: java/org/hibernate/cfg/annotations and 1 other directories.
hibernate-commits at lists.jboss.org
hibernate-commits at lists.jboss.org
Sat Feb 10 04:23:53 EST 2007
Author: epbernard
Date: 2007-02-10 04:23:53 -0500 (Sat, 10 Feb 2007)
New Revision: 11191
Added:
branches/Branch_3_2/HibernateExt/annotations/src/java/org/hibernate/annotations/Immutable.java
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/EntityBinder.java
branches/Branch_3_2/HibernateExt/annotations/src/test/org/hibernate/test/annotations/onetomany/City.java
branches/Branch_3_2/HibernateExt/annotations/src/test/org/hibernate/test/annotations/onetomany/OneToManyTest.java
Log:
ANN-542 immutable implementation
Added: branches/Branch_3_2/HibernateExt/annotations/src/java/org/hibernate/annotations/Immutable.java
===================================================================
--- branches/Branch_3_2/HibernateExt/annotations/src/java/org/hibernate/annotations/Immutable.java (rev 0)
+++ branches/Branch_3_2/HibernateExt/annotations/src/java/org/hibernate/annotations/Immutable.java 2007-02-10 09:23:53 UTC (rev 11191)
@@ -0,0 +1,15 @@
+//$Id: $
+package org.hibernate.annotations;
+
+import java.lang.annotation.*;
+
+/**
+ * Mark an Entity or a Collection as immutable
+ * No annotation means the element is mutable
+ *
+ * @author Emmanuel Bernard
+ */
+ at java.lang.annotation.Target({ElementType.TYPE, ElementType.METHOD, ElementType.FIELD})
+ at Retention( RetentionPolicy.RUNTIME )
+public @interface Immutable {
+}
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-02-10 09:20:51 UTC (rev 11190)
+++ branches/Branch_3_2/HibernateExt/annotations/src/java/org/hibernate/cfg/annotations/CollectionBinder.java 2007-02-10 09:23:53 UTC (rev 11191)
@@ -45,6 +45,7 @@
import org.hibernate.annotations.SQLDelete;
import org.hibernate.annotations.SQLDeleteAll;
import org.hibernate.annotations.Loader;
+import org.hibernate.annotations.Immutable;
import org.hibernate.cfg.AnnotatedClassType;
import org.hibernate.cfg.AnnotationBinder;
import org.hibernate.cfg.BinderHelper;
@@ -305,6 +306,8 @@
);
}
+ collection.setMutable( ! property.isAnnotationPresent( Immutable.class ) );
+
// set ordering
if ( orderBy != null ) collection.setOrderBy( orderBy );
if ( isSorted ) {
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-02-10 09:20:51 UTC (rev 11190)
+++ branches/Branch_3_2/HibernateExt/annotations/src/java/org/hibernate/cfg/annotations/EntityBinder.java 2007-02-10 09:23:53 UTC (rev 11191)
@@ -37,6 +37,7 @@
import org.hibernate.annotations.SQLDeleteAll;
import org.hibernate.annotations.Tuplizers;
import org.hibernate.annotations.Tuplizer;
+import org.hibernate.annotations.Immutable;
import org.hibernate.cache.CacheFactory;
import org.hibernate.cfg.AnnotationBinder;
import org.hibernate.cfg.BinderHelper;
@@ -75,7 +76,6 @@
private boolean dynamicInsert;
private boolean dynamicUpdate;
private boolean explicitHibernateEntityAnnotation;
- private boolean mutable;
private OptimisticLockType optimisticLockType;
private String persister;
private PolymorphismType polymorphismType;
@@ -120,7 +120,6 @@
if ( hibAnn != null ) {
dynamicInsert = hibAnn.dynamicInsert();
dynamicUpdate = hibAnn.dynamicUpdate();
- mutable = hibAnn.mutable();
optimisticLockType = hibAnn.optimisticLock();
persister = hibAnn.persister();
selectBeforeUpdate = hibAnn.selectBeforeUpdate();
@@ -131,7 +130,6 @@
//default values when the annotation is not there
dynamicInsert = false;
dynamicUpdate = false;
- mutable = true;
optimisticLockType = OptimisticLockType.VERSION;
persister = "";
polymorphismType = PolymorphismType.IMPLICIT;
@@ -170,6 +168,18 @@
if ( persistentClass instanceof RootClass ) {
RootClass rootClass = (RootClass) persistentClass;
+ boolean mutable = true;
+ //priority on @Immutable, then @Entity.mutable()
+ if ( annotatedClass.isAnnotationPresent( Immutable.class ) ) {
+ mutable = false;
+ }
+ else {
+ org.hibernate.annotations.Entity entityAnn =
+ annotatedClass.getAnnotation( org.hibernate.annotations.Entity.class );
+ if ( entityAnn != null ) {
+ mutable = entityAnn.mutable();
+ }
+ }
rootClass.setMutable( mutable );
rootClass.setExplicitPolymorphism( isExplicitPolymorphism( polymorphismType ) );
if ( StringHelper.isNotEmpty( where ) ) rootClass.setWhere( where );
Modified: branches/Branch_3_2/HibernateExt/annotations/src/test/org/hibernate/test/annotations/onetomany/City.java
===================================================================
--- branches/Branch_3_2/HibernateExt/annotations/src/test/org/hibernate/test/annotations/onetomany/City.java 2007-02-10 09:20:51 UTC (rev 11190)
+++ branches/Branch_3_2/HibernateExt/annotations/src/test/org/hibernate/test/annotations/onetomany/City.java 2007-02-10 09:23:53 UTC (rev 11191)
@@ -11,6 +11,7 @@
import javax.persistence.OrderBy;
import org.hibernate.annotations.ForeignKey;
+import org.hibernate.annotations.Immutable;
/**
* @author Emmanuel Bernard
@@ -54,6 +55,7 @@
@JoinColumn(name = "mainstreetcity_id")
@ForeignKey(name = "CITYSTR_FK")
@OrderBy
+ @Immutable
public List<Street> getMainStreets() {
return mainStreets;
}
Modified: branches/Branch_3_2/HibernateExt/annotations/src/test/org/hibernate/test/annotations/onetomany/OneToManyTest.java
===================================================================
--- branches/Branch_3_2/HibernateExt/annotations/src/test/org/hibernate/test/annotations/onetomany/OneToManyTest.java 2007-02-10 09:20:51 UTC (rev 11190)
+++ branches/Branch_3_2/HibernateExt/annotations/src/test/org/hibernate/test/annotations/onetomany/OneToManyTest.java 2007-02-10 09:23:53 UTC (rev 11191)
@@ -72,9 +72,10 @@
s.persist( grandeArmee );
paris.addMainStreet( chmpsElysees );
paris.addMainStreet( grandeArmee );
- tx.commit();
+
+ s.flush();
s.clear();
- tx = s.beginTransaction();
+
//testing @OrderBy with explicit values including Formula
paris = (City) s.get( City.class, paris.getId() );
assertEquals( 3, paris.getStreets().size() );
@@ -86,7 +87,7 @@
assertTrue( previousId < street.getId() );
previousId = street.getId();
}
- tx.commit();
+ tx.rollback();
s.close();
}
More information about the hibernate-commits
mailing list