Hibernate SVN: r10761 - branches/Branch_3_2/Hibernate3/test/org/hibernate/test
by hibernate-commits@lists.jboss.org
Author: steve.ebersole(a)jboss.com
Date: 2006-11-07 19:03:29 -0500 (Tue, 07 Nov 2006)
New Revision: 10761
Modified:
branches/Branch_3_2/Hibernate3/test/org/hibernate/test/AllTests.java
Log:
added OpsSuite to AllTests
Modified: branches/Branch_3_2/Hibernate3/test/org/hibernate/test/AllTests.java
===================================================================
--- branches/Branch_3_2/Hibernate3/test/org/hibernate/test/AllTests.java 2006-11-08 00:01:34 UTC (rev 10760)
+++ branches/Branch_3_2/Hibernate3/test/org/hibernate/test/AllTests.java 2006-11-08 00:03:29 UTC (rev 10761)
@@ -4,9 +4,11 @@
import junit.framework.Test;
import junit.framework.TestSuite;
import junit.textui.TestRunner;
+
import org.hibernate.dialect.Dialect;
import org.hibernate.test.abstractembeddedcomponents.cid.AbstractCompositeIdTest;
import org.hibernate.test.abstractembeddedcomponents.propertyref.AbstractComponentPropertyRefTest;
+import org.hibernate.test.any.AnyTypeTest;
import org.hibernate.test.array.ArrayTest;
import org.hibernate.test.ast.ASTIteratorTest;
import org.hibernate.test.ast.ASTUtilTest;
@@ -93,10 +95,7 @@
import org.hibernate.test.onetomany.OneToManyTest;
import org.hibernate.test.onetoone.joined.OneToOneTest;
import org.hibernate.test.onetooneformula.OneToOneFormulaTest;
-import org.hibernate.test.ops.CreateTest;
-import org.hibernate.test.ops.GetLoadTest;
-import org.hibernate.test.ops.MergeTest;
-import org.hibernate.test.ops.SaveOrUpdateTest;
+import org.hibernate.test.ops.OpsSuite;
import org.hibernate.test.optlock.OptimisticLockTest;
import org.hibernate.test.ordered.OrderByTest;
import org.hibernate.test.orphan.OrphanIdRollbackTest;
@@ -131,7 +130,6 @@
import org.hibernate.test.version.db.DbVersionTest;
import org.hibernate.test.version.sybase.SybaseTimestampVersioningTest;
import org.hibernate.test.where.WhereTest;
-import org.hibernate.test.any.AnyTypeTest;
/**
* @author Gavin King
@@ -172,10 +170,7 @@
*/
public static Test suite() {
TestSuite suite = new TestSuite("New tests suite");
- suite.addTest( GetLoadTest.suite() );
- suite.addTest( CreateTest.suite() );
- suite.addTest( SaveOrUpdateTest.suite() );
- suite.addTest( MergeTest.suite() );
+ suite.addTest( OpsSuite.suite() );
suite.addTest( NaturalIdTest.suite() );
suite.addTest( ComponentTest.suite() );
suite.addTest( ProxyTest.suite() );
@@ -292,7 +287,7 @@
suite.addTest( AbstractComponentPropertyRefTest.suite() );
suite.addTest( AbstractCompositeIdTest.suite() );
suite.addTest( UtilSuite.suite() );
- suite.addTest(AnyTypeTest.suite() );
+ suite.addTest( AnyTypeTest.suite() );
return filter( suite );
//return suite;
18 years, 2 months
Hibernate SVN: r10760 - in branches/Branch_3_2/Hibernate3: src/org/hibernate/event/def test/org/hibernate/test/ops
by hibernate-commits@lists.jboss.org
Author: steve.ebersole(a)jboss.com
Date: 2006-11-07 19:01:34 -0500 (Tue, 07 Nov 2006)
New Revision: 10760
Added:
branches/Branch_3_2/Hibernate3/test/org/hibernate/test/ops/AbstractOperationTestCase.java
branches/Branch_3_2/Hibernate3/test/org/hibernate/test/ops/DeleteTest.java
branches/Branch_3_2/Hibernate3/test/org/hibernate/test/ops/OpsSuite.java
Modified:
branches/Branch_3_2/Hibernate3/src/org/hibernate/event/def/DefaultDeleteEventListener.java
branches/Branch_3_2/Hibernate3/test/org/hibernate/test/ops/CreateTest.java
branches/Branch_3_2/Hibernate3/test/org/hibernate/test/ops/MergeTest.java
branches/Branch_3_2/Hibernate3/test/org/hibernate/test/ops/Node.hbm.xml
branches/Branch_3_2/Hibernate3/test/org/hibernate/test/ops/Node.java
branches/Branch_3_2/Hibernate3/test/org/hibernate/test/ops/OptLockEntity.hbm.xml
Log:
hhh-1564 : delete + versioned + collections = extra updates
Modified: branches/Branch_3_2/Hibernate3/src/org/hibernate/event/def/DefaultDeleteEventListener.java
===================================================================
--- branches/Branch_3_2/Hibernate3/src/org/hibernate/event/def/DefaultDeleteEventListener.java 2006-11-08 00:00:53 UTC (rev 10759)
+++ branches/Branch_3_2/Hibernate3/src/org/hibernate/event/def/DefaultDeleteEventListener.java 2006-11-08 00:01:34 UTC (rev 10760)
@@ -147,8 +147,10 @@
*
* @param session The session which is the source of the event
* @param entity The entity being delete processed
- * @param cascadeDeleteEnabled
+ * @param cascadeDeleteEnabled Is cascading of deletes enabled
* @param persister The entity persister
+ * @param transientEntities A cache of already visited transient entities
+ * (to avoid infinite recursion).
*/
protected void deleteTransientEntity(
EventSource session,
@@ -182,9 +184,7 @@
}
final PersistenceContext persistenceContext = session.getPersistenceContext();
-
- Type[] propTypes = persister.getPropertyTypes();
-
+ final Type[] propTypes = persister.getPropertyTypes();
final Object version = entityEntry.getVersion();
final Object[] currentState;
@@ -195,14 +195,7 @@
currentState = entityEntry.getLoadedState();
}
- final Object[] deletedState = new Object[propTypes.length];
- TypeFactory.deepCopy(
- currentState,
- propTypes,
- persister.getPropertyUpdateability(),
- deletedState,
- session
- );
+ final Object[] deletedState = createDeletedState( persister, currentState, session );
entityEntry.setDeletedState(deletedState);
session.getInterceptor().onDelete(
@@ -211,7 +204,7 @@
deletedState,
persister.getPropertyNames(),
propTypes
- );
+ );
// before any callbacks, etc, so subdeletions see that this deletion happened first
persistenceContext.setEntryStatus(entityEntry, Status.DELETED);
@@ -220,7 +213,7 @@
cascadeBeforeDelete( session, persister, entity, entityEntry, transientEntities );
new ForeignKeys.Nullifier(entity, true, false, session)
- .nullifyTransientReferences( entityEntry.getDeletedState(), propTypes );
+ .nullifyTransientReferences( entityEntry.getDeletedState(), propTypes );
new Nullability(session).checkNullability( entityEntry.getDeletedState(), persister, true );
persistenceContext.getNullifiableEntityKeys().add(key);
@@ -234,8 +227,8 @@
persister,
isCascadeDeleteEnabled,
session
- )
- );
+ )
+ );
cascadeAfterDelete( session, persister, entity, transientEntities );
@@ -243,7 +236,16 @@
// override the stale snapshot
// This is now handled by removeEntity() in EntityDeleteAction
//persistenceContext.removeDatabaseSnapshot(key);
+ }
+ private Object[] createDeletedState(EntityPersister persister, Object[] currentState, EventSource session) {
+ Type[] propTypes = persister.getPropertyTypes();
+ final Object[] deletedState = new Object[propTypes.length];
+// TypeFactory.deepCopy( currentState, propTypes, persister.getPropertyUpdateability(), deletedState, session );
+ boolean[] copyability = new boolean[propTypes.length];
+ java.util.Arrays.fill( copyability, true );
+ TypeFactory.deepCopy( currentState, propTypes, copyability, deletedState, session );
+ return deletedState;
}
protected boolean invokeDeleteLifecycle(EventSource session, Object entity, EntityPersister persister) {
Added: branches/Branch_3_2/Hibernate3/test/org/hibernate/test/ops/AbstractOperationTestCase.java
===================================================================
--- branches/Branch_3_2/Hibernate3/test/org/hibernate/test/ops/AbstractOperationTestCase.java 2006-11-08 00:00:53 UTC (rev 10759)
+++ branches/Branch_3_2/Hibernate3/test/org/hibernate/test/ops/AbstractOperationTestCase.java 2006-11-08 00:01:34 UTC (rev 10760)
@@ -0,0 +1,51 @@
+package org.hibernate.test.ops;
+
+import java.util.Iterator;
+
+import org.hibernate.test.TestCase;
+import org.hibernate.cfg.Configuration;
+import org.hibernate.cfg.Environment;
+import org.hibernate.Session;
+
+/**
+ * {@inheritDoc}
+ *
+ * @author Steve Ebersole
+ */
+public abstract class AbstractOperationTestCase extends TestCase {
+ public AbstractOperationTestCase(String name) {
+ super( name );
+ }
+
+ protected void configure(Configuration cfg) {
+ cfg.setProperty( Environment.GENERATE_STATISTICS, "true");
+ cfg.setProperty( Environment.STATEMENT_BATCH_SIZE, "0" );
+ }
+
+ protected String[] getMappings() {
+ return new String[] { "ops/Node.hbm.xml", "ops/Employer.hbm.xml", "ops/OptLockEntity.hbm.xml" };
+ }
+
+ public String getCacheConcurrencyStrategy() {
+ return null;
+ }
+
+ protected void clearCounts() {
+ getSessions().getStatistics().clear();
+ }
+
+ protected void assertInsertCount(int expected) {
+ int inserts = ( int ) getSessions().getStatistics().getEntityInsertCount();
+ assertEquals( "unexpected insert count", expected, inserts );
+ }
+
+ protected void assertUpdateCount(int expected) {
+ int updates = ( int ) getSessions().getStatistics().getEntityUpdateCount();
+ assertEquals( "unexpected update counts", expected, updates );
+ }
+
+ protected void assertDeleteCount(int expected) {
+ int deletes = ( int ) getSessions().getStatistics().getEntityDeleteCount();
+ assertEquals( "unexpected delete counts", expected, deletes );
+ }
+}
Modified: branches/Branch_3_2/Hibernate3/test/org/hibernate/test/ops/CreateTest.java
===================================================================
--- branches/Branch_3_2/Hibernate3/test/org/hibernate/test/ops/CreateTest.java 2006-11-08 00:00:53 UTC (rev 10759)
+++ branches/Branch_3_2/Hibernate3/test/org/hibernate/test/ops/CreateTest.java 2006-11-08 00:01:34 UTC (rev 10760)
@@ -10,20 +10,48 @@
import org.hibernate.PersistentObjectException;
import org.hibernate.Session;
import org.hibernate.Transaction;
-import org.hibernate.cfg.Configuration;
-import org.hibernate.cfg.Environment;
import org.hibernate.exception.ConstraintViolationException;
-import org.hibernate.test.TestCase;
/**
* @author Gavin King
*/
-public class CreateTest extends TestCase {
+public class CreateTest extends AbstractOperationTestCase {
public CreateTest(String str) {
- super(str);
+ super( str );
}
-
+
+ public static Test suite() {
+ return new TestSuite( CreateTest.class );
+ }
+
+ public void testNoUpdatesOnCreateVersionedWithCollection() {
+ clearCounts();
+
+ Session s = openSession();
+ Transaction tx = s.beginTransaction();
+ VersionedEntity root = new VersionedEntity( "root", "root" );
+ VersionedEntity child = new VersionedEntity( "c1", "child-1" );
+ root.getChildren().add( child );
+ child.setParent( root );
+ s.save(root);
+ tx.commit();
+ s.close();
+
+ assertInsertCount( 2 );
+ assertUpdateCount( 0 );
+ assertDeleteCount( 0 );
+
+ s = openSession();
+ tx = s.beginTransaction();
+ s.delete( root );
+ tx.commit();
+ s.close();
+
+ assertUpdateCount( 0 );
+ assertDeleteCount( 2 );
+ }
+
public void testCreateTree() {
clearCounts();
@@ -186,40 +214,5 @@
tx.commit();
s.close();
}
-
- private void clearCounts() {
- getSessions().getStatistics().clear();
- }
-
- private void assertInsertCount(int count) {
- int inserts = (int) getSessions().getStatistics().getEntityInsertCount();
- assertEquals(count, inserts);
- }
-
- private void assertUpdateCount(int count) {
- int updates = (int) getSessions().getStatistics().getEntityUpdateCount();
- assertEquals(count, updates);
- }
-
- protected void configure(Configuration cfg) {
- cfg.setProperty(Environment.GENERATE_STATISTICS, "true");
- cfg.setProperty(Environment.STATEMENT_BATCH_SIZE, "0");
- }
-
- protected String[] getMappings() {
- return new String[] {
- "ops/Node.hbm.xml",
- "ops/Employer.hbm.xml"
- };
- }
-
- public static Test suite() {
- return new TestSuite(CreateTest.class);
- }
-
- public String getCacheConcurrencyStrategy() {
- return null;
- }
-
}
Added: branches/Branch_3_2/Hibernate3/test/org/hibernate/test/ops/DeleteTest.java
===================================================================
--- branches/Branch_3_2/Hibernate3/test/org/hibernate/test/ops/DeleteTest.java 2006-11-08 00:00:53 UTC (rev 10759)
+++ branches/Branch_3_2/Hibernate3/test/org/hibernate/test/ops/DeleteTest.java 2006-11-08 00:01:34 UTC (rev 10760)
@@ -0,0 +1,91 @@
+package org.hibernate.test.ops;
+
+import junit.framework.Test;
+import junit.framework.TestSuite;
+
+import org.hibernate.Session;
+
+/**
+ * {@inheritDoc}
+ *
+ * @author Steve Ebersole
+ */
+public class DeleteTest extends AbstractOperationTestCase {
+ public DeleteTest(String name) {
+ super( name );
+ }
+
+ public static Test suite() {
+ return new TestSuite( DeleteTest.class );
+ }
+
+ public void testDeleteVersionedWithCollectionNoUpdate() {
+ // test adapted from HHH-1564...
+ Session s = openSession();
+ s.beginTransaction();
+ VersionedEntity c = new VersionedEntity( "c1", "child-1" );
+ VersionedEntity p = new VersionedEntity( "root", "root");
+ p.getChildren().add( c );
+ c.setParent( p );
+ s.save( p );
+ s.getTransaction().commit();
+ s.close();
+
+ clearCounts();
+
+ s = openSession();
+ s.beginTransaction();
+ VersionedEntity loadedParent = ( VersionedEntity ) s.get( VersionedEntity.class, "root" );
+ s.delete( loadedParent );
+ s.getTransaction().commit();
+ s.close();
+
+ assertInsertCount( 0 );
+ assertUpdateCount( 0 );
+ assertDeleteCount( 2 );
+ }
+
+ public void testNoUpdateOnDelete() {
+ Session s = openSession();
+ s.beginTransaction();
+ Node node = new Node( "test" );
+ s.persist( node );
+ s.getTransaction().commit();
+ s.close();
+
+ clearCounts();
+
+ s = openSession();
+ s.beginTransaction();
+ s.delete( node );
+ s.getTransaction().commit();
+ s.close();
+
+ assertUpdateCount( 0 );
+ assertInsertCount( 0 );
+ }
+
+ public void testNoUpdateOnDeleteWithCollection() {
+ Session s = openSession();
+ s.beginTransaction();
+ Node parent = new Node( "parent" );
+ Node child = new Node( "child" );
+ parent.getCascadingChildren().add( child );
+ s.persist( parent );
+ s.getTransaction().commit();
+ s.close();
+
+ clearCounts();
+
+ s = openSession();
+ s.beginTransaction();
+ parent = ( Node ) s.get( Node.class, "parent" );
+ s.delete( parent );
+ s.getTransaction().commit();
+ s.close();
+
+ assertUpdateCount( 0 );
+ assertInsertCount( 0 );
+ assertDeleteCount( 2 );
+ }
+}
Modified: branches/Branch_3_2/Hibernate3/test/org/hibernate/test/ops/MergeTest.java
===================================================================
--- branches/Branch_3_2/Hibernate3/test/org/hibernate/test/ops/MergeTest.java 2006-11-08 00:00:53 UTC (rev 10759)
+++ branches/Branch_3_2/Hibernate3/test/org/hibernate/test/ops/MergeTest.java 2006-11-08 00:01:34 UTC (rev 10760)
@@ -11,20 +11,21 @@
import org.hibernate.Session;
import org.hibernate.Transaction;
import org.hibernate.NonUniqueObjectException;
-import org.hibernate.cfg.Configuration;
-import org.hibernate.cfg.Environment;
import org.hibernate.criterion.Projections;
-import org.hibernate.test.TestCase;
/**
* @author Gavin King
*/
-public class MergeTest extends TestCase {
+public class MergeTest extends AbstractOperationTestCase {
public MergeTest(String str) {
- super(str);
+ super( str );
}
+ public static Test suite() {
+ return new TestSuite( MergeTest.class );
+ }
+
public void testNoExtraUpdatesOnMerge() throws Exception {
Session s = openSession();
s.beginTransaction();
@@ -505,34 +506,7 @@
cleanup();
}
-
- private void clearCounts() {
- getSessions().getStatistics().clear();
- }
-
- private void assertInsertCount(int expected) {
- int inserts = (int) getSessions().getStatistics().getEntityInsertCount();
- assertEquals( "unexpected insert count", expected, inserts );
- }
-
- private void assertUpdateCount(int expected) {
- int updates = (int) getSessions().getStatistics().getEntityUpdateCount();
- assertEquals( "unexpected update counts", expected, updates );
- }
-
- protected void configure(Configuration cfg) {
- cfg.setProperty(Environment.GENERATE_STATISTICS, "true");
- cfg.setProperty(Environment.STATEMENT_BATCH_SIZE, "0");
- }
-
- protected String[] getMappings() {
- return new String[] { "ops/Node.hbm.xml", "ops/Employer.hbm.xml", "ops/OptLockEntity.hbm.xml" };
- }
- public static Test suite() {
- return new TestSuite(MergeTest.class);
- }
-
private void cleanup() {
Session s = openSession();
s.beginTransaction();
Modified: branches/Branch_3_2/Hibernate3/test/org/hibernate/test/ops/Node.hbm.xml
===================================================================
--- branches/Branch_3_2/Hibernate3/test/org/hibernate/test/ops/Node.hbm.xml 2006-11-08 00:00:53 UTC (rev 10759)
+++ branches/Branch_3_2/Hibernate3/test/org/hibernate/test/ops/Node.hbm.xml 2006-11-08 00:01:34 UTC (rev 10760)
@@ -22,8 +22,11 @@
<key column="parent"/>
<one-to-many class="Node"/>
</set>
-
- </class>
+ <set name="cascadingChildren" inverse="false" cascade="persist,merge,save-update,evict,delete">
+ <key column="CASC_PARENT"/>
+ <one-to-many class="Node"/>
+ </set>
+ </class>
<class name="NumberedNode" polymorphism="explicit">
<id name="id" unsaved-value="0">
Modified: branches/Branch_3_2/Hibernate3/test/org/hibernate/test/ops/Node.java
===================================================================
--- branches/Branch_3_2/Hibernate3/test/org/hibernate/test/ops/Node.java 2006-11-08 00:00:53 UTC (rev 10759)
+++ branches/Branch_3_2/Hibernate3/test/org/hibernate/test/ops/Node.java 2006-11-08 00:01:34 UTC (rev 10760)
@@ -9,47 +9,34 @@
* @author Gavin King
*/
public class Node {
-
+
private String name;
+ private String description;
+ private Date created;
private Node parent;
private Set children = new HashSet();
- private String description;
- private Date created;
-
- public Node() {}
-
+ private Set cascadingChildren = new HashSet();
+
+ public Node() {
+ }
+
public Node(String name) {
this.name = name;
created = generateCurrentDate();
}
- public Set getChildren() {
- return children;
- }
- public void setChildren(Set children) {
- this.children = children;
- }
public String getName() {
return name;
}
+
public void setName(String name) {
this.name = name;
}
- public Node getParent() {
- return parent;
- }
- public void setParent(Node parent) {
- this.parent = parent;
- }
-
- public Node addChild(Node child) {
- children.add(child);
- child.setParent(this);
- return this;
- }
+
public String getDescription() {
return description;
}
+
public void setDescription(String description) {
this.description = description;
}
@@ -62,6 +49,36 @@
this.created = created;
}
+ public Node getParent() {
+ return parent;
+ }
+
+ public void setParent(Node parent) {
+ this.parent = parent;
+ }
+
+ public Set getChildren() {
+ return children;
+ }
+
+ public void setChildren(Set children) {
+ this.children = children;
+ }
+
+ public Node addChild(Node child) {
+ children.add( child );
+ child.setParent( this );
+ return this;
+ }
+
+ public Set getCascadingChildren() {
+ return cascadingChildren;
+ }
+
+ public void setCascadingChildren(Set cascadingChildren) {
+ this.cascadingChildren = cascadingChildren;
+ }
+
private Date generateCurrentDate() {
// Note : done as java.sql.Date mainly to work around issue with
// MySQL and its lack of milli-second precision on its DATETIME
Added: branches/Branch_3_2/Hibernate3/test/org/hibernate/test/ops/OpsSuite.java
===================================================================
--- branches/Branch_3_2/Hibernate3/test/org/hibernate/test/ops/OpsSuite.java 2006-11-08 00:00:53 UTC (rev 10759)
+++ branches/Branch_3_2/Hibernate3/test/org/hibernate/test/ops/OpsSuite.java 2006-11-08 00:01:34 UTC (rev 10760)
@@ -0,0 +1,21 @@
+package org.hibernate.test.ops;
+
+import junit.framework.Test;
+import junit.framework.TestSuite;
+
+/**
+ * {@inheritDoc}
+ *
+ * @author Steve Ebersole
+ */
+public class OpsSuite {
+ public static Test suite() {
+ TestSuite suite = new TestSuite( "Operations tests" );
+ suite.addTest( CreateTest.suite() );
+ suite.addTest( DeleteTest.suite() );
+ suite.addTest( GetLoadTest.suite() );
+ suite.addTest( MergeTest.suite() );
+ suite.addTest( SaveOrUpdateTest.suite() );
+ return suite;
+ }
+}
Modified: branches/Branch_3_2/Hibernate3/test/org/hibernate/test/ops/OptLockEntity.hbm.xml
===================================================================
--- branches/Branch_3_2/Hibernate3/test/org/hibernate/test/ops/OptLockEntity.hbm.xml 2006-11-08 00:00:53 UTC (rev 10759)
+++ branches/Branch_3_2/Hibernate3/test/org/hibernate/test/ops/OptLockEntity.hbm.xml 2006-11-08 00:01:34 UTC (rev 10760)
@@ -18,7 +18,7 @@
<many-to-one name="parent" class="VersionedEntity"/>
<set name="children"
inverse="true"
- cascade="persist,merge,save-update,evict">
+ cascade="persist,merge,save-update,evict,delete">
<key column="parent"/>
<one-to-many class="VersionedEntity"/>
</set>
18 years, 2 months
Hibernate SVN: r10759 - in trunk/Hibernate3: src/org/hibernate/event/def test/org/hibernate/test/ops
by hibernate-commits@lists.jboss.org
Author: steve.ebersole(a)jboss.com
Date: 2006-11-07 19:00:53 -0500 (Tue, 07 Nov 2006)
New Revision: 10759
Added:
trunk/Hibernate3/test/org/hibernate/test/ops/AbstractOperationTestCase.java
trunk/Hibernate3/test/org/hibernate/test/ops/DeleteTest.java
trunk/Hibernate3/test/org/hibernate/test/ops/OpsSuite.java
Modified:
trunk/Hibernate3/src/org/hibernate/event/def/DefaultDeleteEventListener.java
trunk/Hibernate3/test/org/hibernate/test/ops/CreateTest.java
trunk/Hibernate3/test/org/hibernate/test/ops/MergeTest.java
trunk/Hibernate3/test/org/hibernate/test/ops/Node.hbm.xml
trunk/Hibernate3/test/org/hibernate/test/ops/Node.java
trunk/Hibernate3/test/org/hibernate/test/ops/OptLockEntity.hbm.xml
Log:
hhh-1564 : delete + versioned + collections = extra updates
Modified: trunk/Hibernate3/src/org/hibernate/event/def/DefaultDeleteEventListener.java
===================================================================
--- trunk/Hibernate3/src/org/hibernate/event/def/DefaultDeleteEventListener.java 2006-11-07 23:50:28 UTC (rev 10758)
+++ trunk/Hibernate3/src/org/hibernate/event/def/DefaultDeleteEventListener.java 2006-11-08 00:00:53 UTC (rev 10759)
@@ -52,7 +52,7 @@
public void onDelete(DeleteEvent event, Set transientEntities) throws HibernateException {
final EventSource source = event.getSession();
-
+
final PersistenceContext persistenceContext = source.getPersistenceContext();
Object entity = persistenceContext.unproxyAndReassociate( event.getObject() );
@@ -82,13 +82,13 @@
"the detached instance passed to delete() had a null identifier"
);
}
-
+
EntityKey key = new EntityKey( id, persister, source.getEntityMode() );
persistenceContext.checkUniqueness(key, entity);
new OnUpdateVisitor( source, id ).process( entity, persister );
-
+
version = persister.getVersion( entity, source.getEntityMode() );
entityEntry = persistenceContext.addEntity(
@@ -147,8 +147,10 @@
*
* @param session The session which is the source of the event
* @param entity The entity being delete processed
- * @param cascadeDeleteEnabled
+ * @param cascadeDeleteEnabled Is cascading of deletes enabled
* @param persister The entity persister
+ * @param transientEntities A cache of already visited transient entities
+ * (to avoid infinite recursion).
*/
protected void deleteTransientEntity(
EventSource session,
@@ -182,9 +184,7 @@
}
final PersistenceContext persistenceContext = session.getPersistenceContext();
-
- Type[] propTypes = persister.getPropertyTypes();
-
+ final Type[] propTypes = persister.getPropertyTypes();
final Object version = entityEntry.getVersion();
final Object[] currentState;
@@ -195,14 +195,7 @@
currentState = entityEntry.getLoadedState();
}
- final Object[] deletedState = new Object[propTypes.length];
- TypeFactory.deepCopy(
- currentState,
- propTypes,
- persister.getPropertyUpdateability(),
- deletedState,
- session
- );
+ final Object[] deletedState = createDeletedState( persister, currentState, session );
entityEntry.setDeletedState(deletedState);
session.getInterceptor().onDelete(
@@ -211,7 +204,7 @@
deletedState,
persister.getPropertyNames(),
propTypes
- );
+ );
// before any callbacks, etc, so subdeletions see that this deletion happened first
persistenceContext.setEntryStatus(entityEntry, Status.DELETED);
@@ -220,7 +213,7 @@
cascadeBeforeDelete( session, persister, entity, entityEntry, transientEntities );
new ForeignKeys.Nullifier(entity, true, false, session)
- .nullifyTransientReferences( entityEntry.getDeletedState(), propTypes );
+ .nullifyTransientReferences( entityEntry.getDeletedState(), propTypes );
new Nullability(session).checkNullability( entityEntry.getDeletedState(), persister, true );
persistenceContext.getNullifiableEntityKeys().add(key);
@@ -234,8 +227,8 @@
persister,
isCascadeDeleteEnabled,
session
- )
- );
+ )
+ );
cascadeAfterDelete( session, persister, entity, transientEntities );
@@ -243,7 +236,16 @@
// override the stale snapshot
// This is now handled by removeEntity() in EntityDeleteAction
//persistenceContext.removeDatabaseSnapshot(key);
+ }
+ private Object[] createDeletedState(EntityPersister persister, Object[] currentState, EventSource session) {
+ Type[] propTypes = persister.getPropertyTypes();
+ final Object[] deletedState = new Object[propTypes.length];
+// TypeFactory.deepCopy( currentState, propTypes, persister.getPropertyUpdateability(), deletedState, session );
+ boolean[] copyability = new boolean[propTypes.length];
+ java.util.Arrays.fill( copyability, true );
+ TypeFactory.deepCopy( currentState, propTypes, copyability, deletedState, session );
+ return deletedState;
}
protected boolean invokeDeleteLifecycle(EventSource session, Object entity, EntityPersister persister) {
@@ -256,7 +258,7 @@
}
return false;
}
-
+
protected void cascadeBeforeDelete(
EventSource session,
EntityPersister persister,
Added: trunk/Hibernate3/test/org/hibernate/test/ops/AbstractOperationTestCase.java
===================================================================
--- trunk/Hibernate3/test/org/hibernate/test/ops/AbstractOperationTestCase.java 2006-11-07 23:50:28 UTC (rev 10758)
+++ trunk/Hibernate3/test/org/hibernate/test/ops/AbstractOperationTestCase.java 2006-11-08 00:00:53 UTC (rev 10759)
@@ -0,0 +1,51 @@
+package org.hibernate.test.ops;
+
+import java.util.Iterator;
+
+import org.hibernate.test.TestCase;
+import org.hibernate.cfg.Configuration;
+import org.hibernate.cfg.Environment;
+import org.hibernate.Session;
+
+/**
+ * {@inheritDoc}
+ *
+ * @author Steve Ebersole
+ */
+public abstract class AbstractOperationTestCase extends TestCase {
+ public AbstractOperationTestCase(String name) {
+ super( name );
+ }
+
+ protected void configure(Configuration cfg) {
+ cfg.setProperty( Environment.GENERATE_STATISTICS, "true");
+ cfg.setProperty( Environment.STATEMENT_BATCH_SIZE, "0" );
+ }
+
+ protected String[] getMappings() {
+ return new String[] { "ops/Node.hbm.xml", "ops/Employer.hbm.xml", "ops/OptLockEntity.hbm.xml" };
+ }
+
+ public String getCacheConcurrencyStrategy() {
+ return null;
+ }
+
+ protected void clearCounts() {
+ getSessions().getStatistics().clear();
+ }
+
+ protected void assertInsertCount(int expected) {
+ int inserts = ( int ) getSessions().getStatistics().getEntityInsertCount();
+ assertEquals( "unexpected insert count", expected, inserts );
+ }
+
+ protected void assertUpdateCount(int expected) {
+ int updates = ( int ) getSessions().getStatistics().getEntityUpdateCount();
+ assertEquals( "unexpected update counts", expected, updates );
+ }
+
+ protected void assertDeleteCount(int expected) {
+ int deletes = ( int ) getSessions().getStatistics().getEntityDeleteCount();
+ assertEquals( "unexpected delete counts", expected, deletes );
+ }
+}
Modified: trunk/Hibernate3/test/org/hibernate/test/ops/CreateTest.java
===================================================================
--- trunk/Hibernate3/test/org/hibernate/test/ops/CreateTest.java 2006-11-07 23:50:28 UTC (rev 10758)
+++ trunk/Hibernate3/test/org/hibernate/test/ops/CreateTest.java 2006-11-08 00:00:53 UTC (rev 10759)
@@ -10,24 +10,52 @@
import org.hibernate.PersistentObjectException;
import org.hibernate.Session;
import org.hibernate.Transaction;
-import org.hibernate.cfg.Configuration;
-import org.hibernate.cfg.Environment;
import org.hibernate.exception.ConstraintViolationException;
-import org.hibernate.test.TestCase;
/**
* @author Gavin King
*/
-public class CreateTest extends TestCase {
-
+public class CreateTest extends AbstractOperationTestCase {
+
public CreateTest(String str) {
- super(str);
+ super( str );
}
-
+
+ public static Test suite() {
+ return new TestSuite( CreateTest.class );
+ }
+
+ public void testNoUpdatesOnCreateVersionedWithCollection() {
+ clearCounts();
+
+ Session s = openSession();
+ Transaction tx = s.beginTransaction();
+ VersionedEntity root = new VersionedEntity( "root", "root" );
+ VersionedEntity child = new VersionedEntity( "c1", "child-1" );
+ root.getChildren().add( child );
+ child.setParent( root );
+ s.save(root);
+ tx.commit();
+ s.close();
+
+ assertInsertCount( 2 );
+ assertUpdateCount( 0 );
+ assertDeleteCount( 0 );
+
+ s = openSession();
+ tx = s.beginTransaction();
+ s.delete( root );
+ tx.commit();
+ s.close();
+
+ assertUpdateCount( 0 );
+ assertDeleteCount( 2 );
+ }
+
public void testCreateTree() {
-
+
clearCounts();
-
+
Session s = openSession();
Transaction tx = s.beginTransaction();
Node root = new Node("root");
@@ -36,7 +64,7 @@
s.persist(root);
tx.commit();
s.close();
-
+
assertInsertCount(2);
assertUpdateCount(0);
@@ -49,15 +77,15 @@
System.out.println("committing");
tx.commit();
s.close();
-
+
assertInsertCount(3);
assertUpdateCount(0);
}
-
+
public void testCreateTreeWithGeneratedId() {
-
+
clearCounts();
-
+
Session s = openSession();
Transaction tx = s.beginTransaction();
NumberedNode root = new NumberedNode("root");
@@ -66,7 +94,7 @@
s.persist(root);
tx.commit();
s.close();
-
+
assertInsertCount(2);
assertUpdateCount(0);
@@ -77,11 +105,11 @@
root.addChild(child2);
tx.commit();
s.close();
-
+
assertInsertCount(3);
assertUpdateCount(0);
}
-
+
public void testCreateException() {
Session s = openSession();
Transaction tx = s.beginTransaction();
@@ -90,7 +118,7 @@
s.persist(dupe);
tx.commit();
s.close();
-
+
s = openSession();
tx = s.beginTransaction();
s.persist(dupe);
@@ -103,10 +131,10 @@
}
tx.rollback();
s.close();
-
+
Node nondupe = new Node("nondupe");
nondupe.addChild(dupe);
-
+
s = openSession();
tx = s.beginTransaction();
s.persist(nondupe);
@@ -120,7 +148,7 @@
tx.rollback();
s.close();
}
-
+
public void testCreateExceptionWithGeneratedId() {
Session s = openSession();
Transaction tx = s.beginTransaction();
@@ -129,7 +157,7 @@
s.persist(dupe);
tx.commit();
s.close();
-
+
s = openSession();
tx = s.beginTransaction();
try {
@@ -141,10 +169,10 @@
}
tx.rollback();
s.close();
-
+
NumberedNode nondupe = new NumberedNode("nondupe");
nondupe.addChild(dupe);
-
+
s = openSession();
tx = s.beginTransaction();
try {
@@ -186,40 +214,5 @@
tx.commit();
s.close();
}
-
- private void clearCounts() {
- getSessions().getStatistics().clear();
- }
-
- private void assertInsertCount(int count) {
- int inserts = (int) getSessions().getStatistics().getEntityInsertCount();
- assertEquals(count, inserts);
- }
-
- private void assertUpdateCount(int count) {
- int updates = (int) getSessions().getStatistics().getEntityUpdateCount();
- assertEquals(count, updates);
- }
-
- protected void configure(Configuration cfg) {
- cfg.setProperty(Environment.GENERATE_STATISTICS, "true");
- cfg.setProperty(Environment.STATEMENT_BATCH_SIZE, "0");
- }
-
- protected String[] getMappings() {
- return new String[] {
- "ops/Node.hbm.xml",
- "ops/Employer.hbm.xml"
- };
- }
-
- public static Test suite() {
- return new TestSuite(CreateTest.class);
- }
-
- public String getCacheConcurrencyStrategy() {
- return null;
- }
-
}
Added: trunk/Hibernate3/test/org/hibernate/test/ops/DeleteTest.java
===================================================================
--- trunk/Hibernate3/test/org/hibernate/test/ops/DeleteTest.java 2006-11-07 23:50:28 UTC (rev 10758)
+++ trunk/Hibernate3/test/org/hibernate/test/ops/DeleteTest.java 2006-11-08 00:00:53 UTC (rev 10759)
@@ -0,0 +1,91 @@
+package org.hibernate.test.ops;
+
+import junit.framework.Test;
+import junit.framework.TestSuite;
+
+import org.hibernate.Session;
+
+/**
+ * {@inheritDoc}
+ *
+ * @author Steve Ebersole
+ */
+public class DeleteTest extends AbstractOperationTestCase {
+ public DeleteTest(String name) {
+ super( name );
+ }
+
+ public static Test suite() {
+ return new TestSuite( DeleteTest.class );
+ }
+
+ public void testDeleteVersionedWithCollectionNoUpdate() {
+ // test adapted from HHH-1564...
+ Session s = openSession();
+ s.beginTransaction();
+ VersionedEntity c = new VersionedEntity( "c1", "child-1" );
+ VersionedEntity p = new VersionedEntity( "root", "root");
+ p.getChildren().add( c );
+ c.setParent( p );
+ s.save( p );
+ s.getTransaction().commit();
+ s.close();
+
+ clearCounts();
+
+ s = openSession();
+ s.beginTransaction();
+ VersionedEntity loadedParent = ( VersionedEntity ) s.get( VersionedEntity.class, "root" );
+ s.delete( loadedParent );
+ s.getTransaction().commit();
+ s.close();
+
+ assertInsertCount( 0 );
+ assertUpdateCount( 0 );
+ assertDeleteCount( 2 );
+ }
+
+ public void testNoUpdateOnDelete() {
+ Session s = openSession();
+ s.beginTransaction();
+ Node node = new Node( "test" );
+ s.persist( node );
+ s.getTransaction().commit();
+ s.close();
+
+ clearCounts();
+
+ s = openSession();
+ s.beginTransaction();
+ s.delete( node );
+ s.getTransaction().commit();
+ s.close();
+
+ assertUpdateCount( 0 );
+ assertInsertCount( 0 );
+ }
+
+ public void testNoUpdateOnDeleteWithCollection() {
+ Session s = openSession();
+ s.beginTransaction();
+ Node parent = new Node( "parent" );
+ Node child = new Node( "child" );
+ parent.getCascadingChildren().add( child );
+ s.persist( parent );
+ s.getTransaction().commit();
+ s.close();
+
+ clearCounts();
+
+ s = openSession();
+ s.beginTransaction();
+ parent = ( Node ) s.get( Node.class, "parent" );
+ s.delete( parent );
+ s.getTransaction().commit();
+ s.close();
+
+ assertUpdateCount( 0 );
+ assertInsertCount( 0 );
+ assertDeleteCount( 2 );
+ }
+}
Modified: trunk/Hibernate3/test/org/hibernate/test/ops/MergeTest.java
===================================================================
--- trunk/Hibernate3/test/org/hibernate/test/ops/MergeTest.java 2006-11-07 23:50:28 UTC (rev 10758)
+++ trunk/Hibernate3/test/org/hibernate/test/ops/MergeTest.java 2006-11-08 00:00:53 UTC (rev 10759)
@@ -2,7 +2,6 @@
package org.hibernate.test.ops;
import java.util.ArrayList;
-import java.util.Date;
import java.util.Iterator;
import junit.framework.Test;
@@ -12,20 +11,21 @@
import org.hibernate.Session;
import org.hibernate.Transaction;
import org.hibernate.NonUniqueObjectException;
-import org.hibernate.cfg.Configuration;
-import org.hibernate.cfg.Environment;
import org.hibernate.criterion.Projections;
-import org.hibernate.test.TestCase;
/**
* @author Gavin King
*/
-public class MergeTest extends TestCase {
-
+public class MergeTest extends AbstractOperationTestCase {
+
public MergeTest(String str) {
- super(str);
+ super( str );
}
+ public static Test suite() {
+ return new TestSuite( MergeTest.class );
+ }
+
public void testNoExtraUpdatesOnMerge() throws Exception {
Session s = openSession();
s.beginTransaction();
@@ -206,11 +206,7 @@
tx.commit();
s.close();
- s = openSession();
- tx = s.beginTransaction();
- s.delete( entity );
- tx.commit();
- s.close();
+ cleanup();
}
public void testPersistThenMergeInSameTxnWithTimestamp() {
@@ -232,17 +228,13 @@
tx.commit();
s.close();
- s = openSession();
- tx = s.beginTransaction();
- s.delete( entity );
- tx.commit();
- s.close();
+ cleanup();
}
public void testMergeDeepTree() {
-
+
clearCounts();
-
+
Session s = openSession();
Transaction tx = s.beginTransaction();
Node root = new Node("root");
@@ -253,11 +245,11 @@
s.merge(root);
tx.commit();
s.close();
-
+
assertInsertCount(3);
assertUpdateCount(0);
clearCounts();
-
+
grandchild.setDescription("the grand child");
Node grandchild2 = new Node("grandchild2");
child.addChild( grandchild2 );
@@ -267,26 +259,26 @@
s.merge(root);
tx.commit();
s.close();
-
+
assertInsertCount(1);
assertUpdateCount(1);
clearCounts();
-
+
Node child2 = new Node("child2");
Node grandchild3 = new Node("grandchild3");
child2.addChild( grandchild3 );
root.addChild(child2);
-
+
s = openSession();
tx = s.beginTransaction();
s.merge(root);
tx.commit();
s.close();
-
+
assertInsertCount(2);
assertUpdateCount(0);
clearCounts();
-
+
s = openSession();
tx = s.beginTransaction();
s.delete(grandchild);
@@ -297,13 +289,13 @@
s.delete(root);
tx.commit();
s.close();
-
+
}
-
+
public void testMergeDeepTreeWithGeneratedId() {
-
+
clearCounts();
-
+
Session s = openSession();
Transaction tx = s.beginTransaction();
NumberedNode root = new NumberedNode("root");
@@ -314,11 +306,11 @@
root = (NumberedNode) s.merge(root);
tx.commit();
s.close();
-
+
assertInsertCount(3);
assertUpdateCount(0);
clearCounts();
-
+
child = (NumberedNode) root.getChildren().iterator().next();
grandchild = (NumberedNode) child.getChildren().iterator().next();
grandchild.setDescription("the grand child");
@@ -330,28 +322,28 @@
root = (NumberedNode) s.merge(root);
tx.commit();
s.close();
-
+
assertInsertCount(1);
assertUpdateCount(1);
clearCounts();
-
+
getSessions().evict(NumberedNode.class);
-
+
NumberedNode child2 = new NumberedNode("child2");
NumberedNode grandchild3 = new NumberedNode("grandchild3");
child2.addChild( grandchild3 );
root.addChild(child2);
-
+
s = openSession();
tx = s.beginTransaction();
root = (NumberedNode) s.merge(root);
tx.commit();
s.close();
-
+
assertInsertCount(2);
assertUpdateCount(0);
clearCounts();
-
+
s = openSession();
tx = s.beginTransaction();
s.createQuery("delete from NumberedNode where name like 'grand%'").executeUpdate();
@@ -359,13 +351,13 @@
s.createQuery("delete from NumberedNode").executeUpdate();
tx.commit();
s.close();
-
+
}
-
+
public void testMergeTree() {
-
+
clearCounts();
-
+
Session s = openSession();
Transaction tx = s.beginTransaction();
Node root = new Node("root");
@@ -374,39 +366,33 @@
s.persist(root);
tx.commit();
s.close();
-
+
assertInsertCount(2);
clearCounts();
-
+
root.setDescription("The root node");
child.setDescription("The child node");
-
+
Node secondChild = new Node("second child");
-
+
root.addChild(secondChild);
-
+
s = openSession();
tx = s.beginTransaction();
s.merge(root);
tx.commit();
s.close();
-
+
assertInsertCount(1);
assertUpdateCount(2);
-
- s = openSession();
- tx = s.beginTransaction();
- s.createQuery("delete from Node where parent is not null").executeUpdate();
- s.createQuery("delete from Node").executeUpdate();
- tx.commit();
- s.close();
-
+
+ cleanup();
}
-
+
public void testMergeTreeWithGeneratedId() {
-
+
clearCounts();
-
+
Session s = openSession();
Transaction tx = s.beginTransaction();
NumberedNode root = new NumberedNode("root");
@@ -415,45 +401,39 @@
s.persist(root);
tx.commit();
s.close();
-
+
assertInsertCount(2);
clearCounts();
-
+
root.setDescription("The root node");
child.setDescription("The child node");
-
+
NumberedNode secondChild = new NumberedNode("second child");
-
+
root.addChild(secondChild);
-
+
s = openSession();
tx = s.beginTransaction();
s.merge(root);
tx.commit();
s.close();
-
+
assertInsertCount(1);
assertUpdateCount(2);
-
- s = openSession();
- tx = s.beginTransaction();
- s.createQuery("delete from NumberedNode where parent is not null").executeUpdate();
- s.createQuery("delete from NumberedNode").executeUpdate();
- tx.commit();
- s.close();
+ cleanup();
}
-
+
public void testMergeManaged() {
-
+
Session s = openSession();
Transaction tx = s.beginTransaction();
NumberedNode root = new NumberedNode("root");
s.persist(root);
tx.commit();
-
+
clearCounts();
-
+
tx = s.beginTransaction();
NumberedNode child = new NumberedNode("child");
root.addChild(child);
@@ -466,27 +446,24 @@
assertTrue( root.getChildren().contains(mergedChild) );
//assertNotSame( mergedChild, s.merge(child) ); //yucky :(
tx.commit();
-
+
assertInsertCount(1);
assertUpdateCount(0);
-
+
assertEquals( root.getChildren().size(), 1 );
assertTrue( root.getChildren().contains(mergedChild) );
-
+
tx = s.beginTransaction();
- assertEquals(
+ assertEquals(
s.createCriteria(NumberedNode.class)
.setProjection( Projections.rowCount() )
- .uniqueResult(),
- new Integer(2)
+ .uniqueResult(),
+ new Integer(2)
);
- s.delete(root);
- s.delete(mergedChild);
- tx.commit();
- s.close();
-
+
+ cleanup();
}
-
+
public void testRecursiveMergeTransient() {
Session s = openSession();
Transaction tx = s.beginTransaction();
@@ -502,7 +479,9 @@
s.clear();
s.merge( jboss.getEmployees().iterator().next() );
tx.commit();
- s.close();
+ s.close();
+
+ cleanup();
}
public void testDeleteAndMerge() throws Exception {
@@ -524,22 +503,10 @@
s.merge( jboss );
s.getTransaction().commit();
s.close();
- }
-
- private void clearCounts() {
- getSessions().getStatistics().clear();
- }
- private void assertInsertCount(int expected) {
- int inserts = (int) getSessions().getStatistics().getEntityInsertCount();
- assertEquals( "unexpected insert count", expected, inserts );
+ cleanup();
}
- private void assertUpdateCount(int expected) {
- int updates = (int) getSessions().getStatistics().getEntityUpdateCount();
- assertEquals( "unexpected update counts", expected, updates );
- }
-
private void cleanup() {
Session s = openSession();
s.beginTransaction();
@@ -560,19 +527,5 @@
s.getTransaction().commit();
s.close();
}
-
- protected void configure(Configuration cfg) {
- cfg.setProperty(Environment.GENERATE_STATISTICS, "true");
- cfg.setProperty(Environment.STATEMENT_BATCH_SIZE, "0");
- }
-
- protected String[] getMappings() {
- return new String[] { "ops/Node.hbm.xml", "ops/Employer.hbm.xml", "ops/OptLockEntity.hbm.xml" };
- }
-
- public static Test suite() {
- return new TestSuite(MergeTest.class);
- }
-
}
Modified: trunk/Hibernate3/test/org/hibernate/test/ops/Node.hbm.xml
===================================================================
--- trunk/Hibernate3/test/org/hibernate/test/ops/Node.hbm.xml 2006-11-07 23:50:28 UTC (rev 10758)
+++ trunk/Hibernate3/test/org/hibernate/test/ops/Node.hbm.xml 2006-11-08 00:00:53 UTC (rev 10759)
@@ -1,14 +1,14 @@
<?xml version="1.0"?>
-<!DOCTYPE hibernate-mapping PUBLIC
+<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<!--
-
+
-->
<hibernate-mapping package="org.hibernate.test.ops">
-
+
<class name="Node" polymorphism="explicit">
<id name="name">
<generator class="assigned"/>
@@ -16,15 +16,18 @@
<property name="description"/>
<many-to-one name="parent"/>
<property name="created" not-null="true"/>
- <set name="children"
+ <set name="children"
inverse="true"
cascade="persist,merge,save-update,evict">
<key column="parent"/>
<one-to-many class="Node"/>
</set>
-
- </class>
-
+ <set name="cascadingChildren" inverse="false" cascade="persist,merge,save-update,evict,delete">
+ <key column="CASC_PARENT"/>
+ <one-to-many class="Node"/>
+ </set>
+ </class>
+
<class name="NumberedNode" polymorphism="explicit">
<id name="id" unsaved-value="0">
<generator class="native"/>
@@ -36,13 +39,13 @@
<property name="created" not-null="true"
type="imm_date"/>
<many-to-one name="parent" class="NumberedNode"/>
- <set name="children"
+ <set name="children"
inverse="true"
cascade="persist,merge,save-update">
<key column="parent"/>
<one-to-many class="NumberedNode"/>
</set>
</class>
-
+
</hibernate-mapping>
Modified: trunk/Hibernate3/test/org/hibernate/test/ops/Node.java
===================================================================
--- trunk/Hibernate3/test/org/hibernate/test/ops/Node.java 2006-11-07 23:50:28 UTC (rev 10758)
+++ trunk/Hibernate3/test/org/hibernate/test/ops/Node.java 2006-11-08 00:00:53 UTC (rev 10759)
@@ -9,47 +9,34 @@
* @author Gavin King
*/
public class Node {
-
+
private String name;
+ private String description;
+ private Date created;
private Node parent;
private Set children = new HashSet();
- private String description;
- private Date created;
-
- public Node() {}
-
+ private Set cascadingChildren = new HashSet();
+
+ public Node() {
+ }
+
public Node(String name) {
this.name = name;
created = generateCurrentDate();
}
- public Set getChildren() {
- return children;
- }
- public void setChildren(Set children) {
- this.children = children;
- }
public String getName() {
return name;
}
+
public void setName(String name) {
this.name = name;
}
- public Node getParent() {
- return parent;
- }
- public void setParent(Node parent) {
- this.parent = parent;
- }
-
- public Node addChild(Node child) {
- children.add(child);
- child.setParent(this);
- return this;
- }
+
public String getDescription() {
return description;
}
+
public void setDescription(String description) {
this.description = description;
}
@@ -62,6 +49,36 @@
this.created = created;
}
+ public Node getParent() {
+ return parent;
+ }
+
+ public void setParent(Node parent) {
+ this.parent = parent;
+ }
+
+ public Set getChildren() {
+ return children;
+ }
+
+ public void setChildren(Set children) {
+ this.children = children;
+ }
+
+ public Node addChild(Node child) {
+ children.add( child );
+ child.setParent( this );
+ return this;
+ }
+
+ public Set getCascadingChildren() {
+ return cascadingChildren;
+ }
+
+ public void setCascadingChildren(Set cascadingChildren) {
+ this.cascadingChildren = cascadingChildren;
+ }
+
private Date generateCurrentDate() {
// Note : done as java.sql.Date mainly to work around issue with
// MySQL and its lack of milli-second precision on its DATETIME
Added: trunk/Hibernate3/test/org/hibernate/test/ops/OpsSuite.java
===================================================================
--- trunk/Hibernate3/test/org/hibernate/test/ops/OpsSuite.java 2006-11-07 23:50:28 UTC (rev 10758)
+++ trunk/Hibernate3/test/org/hibernate/test/ops/OpsSuite.java 2006-11-08 00:00:53 UTC (rev 10759)
@@ -0,0 +1,21 @@
+package org.hibernate.test.ops;
+
+import junit.framework.Test;
+import junit.framework.TestSuite;
+
+/**
+ * {@inheritDoc}
+ *
+ * @author Steve Ebersole
+ */
+public class OpsSuite {
+ public static Test suite() {
+ TestSuite suite = new TestSuite( "Operations tests" );
+ suite.addTest( CreateTest.suite() );
+ suite.addTest( DeleteTest.suite() );
+ suite.addTest( GetLoadTest.suite() );
+ suite.addTest( MergeTest.suite() );
+ suite.addTest( SaveOrUpdateTest.suite() );
+ return suite;
+ }
+}
Modified: trunk/Hibernate3/test/org/hibernate/test/ops/OptLockEntity.hbm.xml
===================================================================
--- trunk/Hibernate3/test/org/hibernate/test/ops/OptLockEntity.hbm.xml 2006-11-07 23:50:28 UTC (rev 10758)
+++ trunk/Hibernate3/test/org/hibernate/test/ops/OptLockEntity.hbm.xml 2006-11-08 00:00:53 UTC (rev 10759)
@@ -1,10 +1,10 @@
<?xml version="1.0"?>
-<!DOCTYPE hibernate-mapping PUBLIC
+<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<!--
-
+
-->
<hibernate-mapping package="org.hibernate.test.ops">
@@ -18,7 +18,7 @@
<many-to-one name="parent" class="VersionedEntity"/>
<set name="children"
inverse="true"
- cascade="persist,merge,save-update,evict">
+ cascade="persist,merge,save-update,evict,delete">
<key column="parent"/>
<one-to-many class="VersionedEntity"/>
</set>
18 years, 2 months
Hibernate SVN: r10758 - in branches/Branch_3_2/HibernateExt/ejb/src: java/org/hibernate/ejb test/org/hibernate/ejb/test/transaction
by hibernate-commits@lists.jboss.org
Author: epbernard
Date: 2006-11-07 18:50:28 -0500 (Tue, 07 Nov 2006)
New Revision: 10758
Modified:
branches/Branch_3_2/HibernateExt/ejb/src/java/org/hibernate/ejb/AbstractEntityManagerImpl.java
branches/Branch_3_2/HibernateExt/ejb/src/java/org/hibernate/ejb/HibernateEntityManagerImplementor.java
branches/Branch_3_2/HibernateExt/ejb/src/java/org/hibernate/ejb/TransactionImpl.java
branches/Branch_3_2/HibernateExt/ejb/src/test/org/hibernate/ejb/test/transaction/FlushAndTransactionTest.java
Log:
EJB-248 wrap SSE into OptimisticLockException whe em.getTransaction().commit() is used
Modified: branches/Branch_3_2/HibernateExt/ejb/src/java/org/hibernate/ejb/AbstractEntityManagerImpl.java
===================================================================
--- branches/Branch_3_2/HibernateExt/ejb/src/java/org/hibernate/ejb/AbstractEntityManagerImpl.java 2006-11-07 21:35:44 UTC (rev 10757)
+++ branches/Branch_3_2/HibernateExt/ejb/src/java/org/hibernate/ejb/AbstractEntityManagerImpl.java 2006-11-07 23:50:28 UTC (rev 10758)
@@ -596,26 +596,8 @@
public void throwPersistenceException(HibernateException e) {
if ( e instanceof StaleStateException ) {
- if ( e instanceof StaleObjectStateException ) {
- StaleObjectStateException sose = (StaleObjectStateException) e;
- Serializable identifier = sose.getIdentifier();
- if (identifier != null) {
- Object entity = getRawSession().load( sose.getEntityName(), identifier );
- if ( entity instanceof Serializable ) {
- //avoid some user errors regarding boundary crossing
- throwPersistenceException( new OptimisticLockException( null, e, entity ) );
- }
- else {
- throwPersistenceException( new OptimisticLockException( e ) );
- }
- }
- else {
- throwPersistenceException( new OptimisticLockException( e ) );
- }
- }
- else {
- throwPersistenceException( new OptimisticLockException( e ) );
- }
+ PersistenceException pe = wrapStaleStateException( (StaleStateException) e );
+ throwPersistenceException( pe );
}
else if ( e instanceof ConstraintViolationException ) {
//FIXME this is bad cause ConstraintViolationException happens in other circumstances
@@ -647,4 +629,29 @@
throwPersistenceException( new PersistenceException( e ) );
}
}
+
+ public PersistenceException wrapStaleStateException(StaleStateException e) {
+ PersistenceException pe;
+ if ( e instanceof StaleObjectStateException ) {
+ StaleObjectStateException sose = (StaleObjectStateException) e;
+ Serializable identifier = sose.getIdentifier();
+ if (identifier != null) {
+ Object entity = getRawSession().load( sose.getEntityName(), identifier );
+ if ( entity instanceof Serializable ) {
+ //avoid some user errors regarding boundary crossing
+ pe = new OptimisticLockException( null, e, entity );
+ }
+ else {
+ pe = new OptimisticLockException( e );
+ }
+ }
+ else {
+ pe = new OptimisticLockException( e );
+ }
+ }
+ else {
+ pe = new OptimisticLockException( e );
+ }
+ return pe;
+ }
}
Modified: branches/Branch_3_2/HibernateExt/ejb/src/java/org/hibernate/ejb/HibernateEntityManagerImplementor.java
===================================================================
--- branches/Branch_3_2/HibernateExt/ejb/src/java/org/hibernate/ejb/HibernateEntityManagerImplementor.java 2006-11-07 21:35:44 UTC (rev 10757)
+++ branches/Branch_3_2/HibernateExt/ejb/src/java/org/hibernate/ejb/HibernateEntityManagerImplementor.java 2006-11-07 23:50:28 UTC (rev 10758)
@@ -4,6 +4,7 @@
import javax.persistence.PersistenceException;
import org.hibernate.HibernateException;
+import org.hibernate.StaleStateException;
/**
* @author Emmanuel Bernard
@@ -14,4 +15,6 @@
public void throwPersistenceException(PersistenceException e);
public void throwPersistenceException(HibernateException e);
+
+ public PersistenceException wrapStaleStateException(StaleStateException e);
}
Modified: branches/Branch_3_2/HibernateExt/ejb/src/java/org/hibernate/ejb/TransactionImpl.java
===================================================================
--- branches/Branch_3_2/HibernateExt/ejb/src/java/org/hibernate/ejb/TransactionImpl.java 2006-11-07 21:35:44 UTC (rev 10757)
+++ branches/Branch_3_2/HibernateExt/ejb/src/java/org/hibernate/ejb/TransactionImpl.java 2006-11-07 23:50:28 UTC (rev 10758)
@@ -8,6 +8,7 @@
import org.hibernate.HibernateException;
import org.hibernate.Session;
import org.hibernate.Transaction;
+import org.hibernate.StaleStateException;
/**
* @author Gavin King
@@ -15,7 +16,7 @@
*/
public class TransactionImpl implements EntityTransaction {
- private AbstractEntityManagerImpl entityManager;
+ private HibernateEntityManagerImplementor entityManager;
private Transaction tx;
private boolean rollbackOnly;
@@ -53,6 +54,13 @@
tx.commit();
}
catch (Exception e) {
+ Exception wrappedException;
+ if (e instanceof StaleStateException) {
+ wrappedException = entityManager.wrapStaleStateException( (StaleStateException) e );
+ }
+ else {
+ wrappedException = e;
+ }
try {
//as per the spec we should rollback if commit fails
tx.rollback();
@@ -60,7 +68,7 @@
catch (Exception re) {
//swallow
}
- throw new RollbackException( "Error while commiting the transaction", e );
+ throw new RollbackException( "Error while commiting the transaction", wrappedException );
}
finally {
rollbackOnly = false;
Modified: branches/Branch_3_2/HibernateExt/ejb/src/test/org/hibernate/ejb/test/transaction/FlushAndTransactionTest.java
===================================================================
--- branches/Branch_3_2/HibernateExt/ejb/src/test/org/hibernate/ejb/test/transaction/FlushAndTransactionTest.java 2006-11-07 21:35:44 UTC (rev 10757)
+++ branches/Branch_3_2/HibernateExt/ejb/src/test/org/hibernate/ejb/test/transaction/FlushAndTransactionTest.java 2006-11-07 23:50:28 UTC (rev 10758)
@@ -7,10 +7,12 @@
import javax.persistence.RollbackException;
import javax.persistence.TransactionRequiredException;
import javax.persistence.PersistenceException;
+import javax.persistence.OptimisticLockException;
import org.hibernate.ejb.HibernateEntityManagerFactory;
import org.hibernate.ejb.test.TestCase;
import org.hibernate.stat.Statistics;
+import org.hibernate.Session;
/**
* @author Emmanuel Bernard
@@ -235,6 +237,34 @@
}
+ public void testRollbackExceptionOnOptimisticLockException() throws Exception {
+ Book book = new Book();
+ book.name = "Stolen keys";
+ book.id = null; //new Integer( 50 );
+ EntityManager em = factory.createEntityManager();
+ em.getTransaction().begin();
+ em.persist( book );
+ em.flush();
+ em.clear();
+ book.setName( "kitty kid");
+ em.merge( book );
+ em.flush();
+ em.clear();
+ book.setName( "kitty kid2"); //non updated version
+ ( (Session) em.getDelegate() ).update( book );
+ try {
+ em.getTransaction().commit();
+ fail( "Commit should be rollbacked" );
+ }
+ catch (RollbackException e) {
+ assertTrue( "During flush a StateStateException is wrapped into a OptimisticLockException", e.getCause() instanceof OptimisticLockException );
+ }
+ finally {
+ em.close();
+ }
+
+ }
+
public void testRollbackClearPC() throws Exception {
Book book = new Book();
book.name = "Stolen keys";
18 years, 2 months
Hibernate SVN: r10757 - branches/Branch_3_2/Hibernate3/src/org/hibernate/type
by hibernate-commits@lists.jboss.org
Author: steve.ebersole(a)jboss.com
Date: 2006-11-07 16:35:44 -0500 (Tue, 07 Nov 2006)
New Revision: 10757
Modified:
branches/Branch_3_2/Hibernate3/src/org/hibernate/type/TypeFactory.java
Log:
javadocs
Modified: branches/Branch_3_2/Hibernate3/src/org/hibernate/type/TypeFactory.java
===================================================================
--- branches/Branch_3_2/Hibernate3/src/org/hibernate/type/TypeFactory.java 2006-11-07 21:35:24 UTC (rev 10756)
+++ branches/Branch_3_2/Hibernate3/src/org/hibernate/type/TypeFactory.java 2006-11-07 21:35:44 UTC (rev 10757)
@@ -139,7 +139,7 @@
* A one-to-one association type for the given class
*/
public static EntityType oneToOne(
- String persistentClass,
+ String persistentClass,
ForeignKeyDirection foreignKeyType,
String uniqueKeyPropertyName,
boolean lazy,
@@ -314,11 +314,36 @@
return new SortedSetType( role, propertyRef, comparator, embedded );
}
+ public static void injectParameters(Object type, Properties parameters) {
+ if (type instanceof ParameterizedType) {
+ ( (ParameterizedType) type ).setParameterValues(parameters);
+ }
+ else if ( parameters!=null && !parameters.isEmpty() ) {
+ throw new MappingException(
+ "type is not parameterized: " +
+ type.getClass().getName()
+ );
+ }
+ }
+
+
+ // convenience methods relating to operations across arrays of types...
+
/**
- * Deep copy values in the first array into the second
+ * Deep copy a series of values from one array to another...
+ *
+ * @param values The values to copy (the source)
+ * @param types The value types
+ * @param copy an array indicating which values to include in the copy
+ * @param target The array into which to copy the values
+ * @param session The orginating session
*/
- public static void deepCopy(Object[] values, Type[] types, boolean[] copy, Object[] target,
- SessionImplementor session) throws HibernateException {
+ public static void deepCopy(
+ final Object[] values,
+ final Type[] types,
+ final boolean[] copy,
+ final Object[] target,
+ final SessionImplementor session) {
for ( int i = 0; i < types.length; i++ ) {
if ( copy[i] ) {
if ( values[i] == LazyPropertyInitializer.UNFETCHED_PROPERTY
@@ -334,57 +359,17 @@
}
/**
- * Determine if any of the given field values are dirty, returning an array containing indexes
- * of the dirty fields or <tt>null</tt> if no fields are dirty.
+ * Apply the {@link Type#beforeAssemble} operation across a series of values.
+ *
+ * @param row The values
+ * @param types The value types
+ * @param session The orginating session
*/
- /*public static int[] findDirty(Type[] types, Object[] x, Object[] y, boolean[] check,
- SessionImplementor session) throws HibernateException {
- int[] results = null;
- int count = 0;
+ public static void beforeAssemble(
+ final Serializable[] row,
+ final Type[] types,
+ final SessionImplementor session) {
for ( int i = 0; i < types.length; i++ ) {
- if ( check[i] && types[i].isDirty( x[i], y[i], session ) ) {
- if ( results == null ) results = new int[types.length];
- results[count++] = i;
- }
- }
- if ( count == 0 ) {
- return null;
- }
- else {
- int[] trimmed = new int[count];
- System.arraycopy( results, 0, trimmed, 0, count );
- return trimmed;
- }
- }*/
-
- /**
- * Determine if any of the given field values are modified, returning an array containing
- * indexes of the dirty fields or <tt>null</tt> if no fields are dirty.
- */
- /*public static int[] findModified(Type[] types, Object[] old, Object[] current, boolean[] check,
- SessionImplementor session) throws HibernateException {
- int[] results = null;
- int count = 0;
- for ( int i = 0; i < types.length; i++ ) {
- if ( check[i]
- && types[i].isModified( old[i], current[i], session ) ) {
- if ( results == null ) results = new int[types.length];
- results[count++] = i;
- }
- }
- if ( count == 0 ) {
- return null;
- }
- else {
- int[] trimmed = new int[count];
- System.arraycopy( results, 0, trimmed, 0, count );
- return trimmed;
- }
- }*/
-
- public static void beforeAssemble(Serializable[] row, Type[] types, SessionImplementor session)
- throws HibernateException {
- for ( int i = 0; i < types.length; i++ ) {
if ( row[i] != LazyPropertyInitializer.UNFETCHED_PROPERTY
&& row[i] != BackrefPropertyAccessor.UNKNOWN ) {
types[i].beforeAssemble( row[i], session );
@@ -392,12 +377,23 @@
}
}
- public static Object[] assemble(Serializable[] row, Type[] types, SessionImplementor session,
- Object owner) throws HibernateException {
+ /**
+ * Apply the {@link Type#assemble} operation across a series of values.
+ *
+ * @param row The values
+ * @param types The value types
+ * @param session The orginating session
+ * @param owner The entity "owning" the values
+ * @return The assembled state
+ */
+ public static Object[] assemble(
+ final Serializable[] row,
+ final Type[] types,
+ final SessionImplementor session,
+ final Object owner) {
Object[] assembled = new Object[row.length];
for ( int i = 0; i < types.length; i++ ) {
- if ( row[i] == LazyPropertyInitializer.UNFETCHED_PROPERTY
- || row[i] == BackrefPropertyAccessor.UNKNOWN ) {
+ if ( row[i] == LazyPropertyInitializer.UNFETCHED_PROPERTY || row[i] == BackrefPropertyAccessor.UNKNOWN ) {
assembled[i] = row[i];
}
else {
@@ -407,15 +403,28 @@
return assembled;
}
- public static Serializable[] disassemble(Object[] row, Type[] types, boolean[] nonCacheable, SessionImplementor session,
- Object owner) throws HibernateException {
+ /**
+ * Apply the {@link Type#disassemble} operation across a series of values.
+ *
+ * @param row The values
+ * @param types The value types
+ * @param nonCacheable An array indicating which values to include in the disassemled state
+ * @param session The orginating session
+ * @param owner The entity "owning" the values
+ * @return The disassembled state
+ */
+ public static Serializable[] disassemble(
+ final Object[] row,
+ final Type[] types,
+ final boolean[] nonCacheable,
+ final SessionImplementor session,
+ final Object owner) {
Serializable[] disassembled = new Serializable[row.length];
for ( int i = 0; i < row.length; i++ ) {
if ( nonCacheable!=null && nonCacheable[i] ) {
disassembled[i] = LazyPropertyInitializer.UNFETCHED_PROPERTY;
}
- else if ( row[i] == LazyPropertyInitializer.UNFETCHED_PROPERTY
- || row[i] == BackrefPropertyAccessor.UNKNOWN ) {
+ else if ( row[i] == LazyPropertyInitializer.UNFETCHED_PROPERTY || row[i] == BackrefPropertyAccessor.UNKNOWN ) {
disassembled[i] = (Serializable) row[i];
}
else {
@@ -425,8 +434,24 @@
return disassembled;
}
- public static Object[] replace(Object[] original, Object[] target, Type[] types,
- SessionImplementor session, Object owner, Map copyCache) throws HibernateException {
+ /**
+ * Apply the {@link Type#replace} operation across a series of values.
+ *
+ * @param original The source of the state
+ * @param target The target into which to replace the source values.
+ * @param types The value types
+ * @param session The orginating session
+ * @param owner The entity "owning" the values
+ * @param copyCache A map representing a cache of already replaced state
+ * @return The replaced state
+ */
+ public static Object[] replace(
+ final Object[] original,
+ final Object[] target,
+ final Type[] types,
+ final SessionImplementor session,
+ final Object owner,
+ final Map copyCache) {
Object[] copied = new Object[original.length];
for ( int i = 0; i < types.length; i++ ) {
if ( original[i] == LazyPropertyInitializer.UNFETCHED_PROPERTY
@@ -440,9 +465,26 @@
return copied;
}
- public static Object[] replace(Object[] original, Object[] target, Type[] types,
- SessionImplementor session, Object owner, Map copyCache,
- ForeignKeyDirection foreignKeyDirection) throws HibernateException {
+ /**
+ * Apply the {@link Type#replace} operation across a series of values.
+ *
+ * @param original The source of the state
+ * @param target The target into which to replace the source values.
+ * @param types The value types
+ * @param session The orginating session
+ * @param owner The entity "owning" the values
+ * @param copyCache A map representing a cache of already replaced state
+ * @param foreignKeyDirection FK directionality to be applied to the replacement
+ * @return The replaced state
+ */
+ public static Object[] replace(
+ final Object[] original,
+ final Object[] target,
+ final Type[] types,
+ final SessionImplementor session,
+ final Object owner,
+ final Map copyCache,
+ final ForeignKeyDirection foreignKeyDirection) {
Object[] copied = new Object[original.length];
for ( int i = 0; i < types.length; i++ ) {
if ( original[i] == LazyPropertyInitializer.UNFETCHED_PROPERTY
@@ -460,36 +502,39 @@
/**
* Determine if any of the given field values are dirty, returning an array containing
- * indexes of the dirty fields or <tt>null</tt> if no fields are dirty.
- * @param x the current state of the entity
- * @param y the snapshot state from the time the object was loaded
+ * indices of the dirty fields.
+ * <p/>
+ * If it is determined that no fields are dirty, null is returned.
+ *
+ * @param properties The property definitions
+ * @param currentState The current state of the entity
+ * @param previousState The baseline state of the entity
+ * @param includeColumns Columns to be included in the dirty checking, per property
+ * @param anyUninitializedProperties Does the entity currently hold any uninitialized property values?
+ * @param session The session from which the dirty check request originated.
+ * @return Array containing indices of the dirty properties, or null if no properties considered dirty.
*/
public static int[] findDirty(
final StandardProperty[] properties,
- final Object[] x,
- final Object[] y,
+ final Object[] currentState,
+ final Object[] previousState,
final boolean[][] includeColumns,
final boolean anyUninitializedProperties,
- final SessionImplementor session)
- throws HibernateException {
-
+ final SessionImplementor session) {
int[] results = null;
int count = 0;
int span = properties.length;
for ( int i = 0; i < span; i++ ) {
-
- final boolean dirty = x[i]!=LazyPropertyInitializer.UNFETCHED_PROPERTY //x is the "current" state
- && properties[i].isDirtyCheckable(anyUninitializedProperties)
- && properties[i].getType().isDirty( y[i], x[i], includeColumns[i], session );
-
+ final boolean dirty = currentState[i] != LazyPropertyInitializer.UNFETCHED_PROPERTY
+ && properties[i].isDirtyCheckable( anyUninitializedProperties )
+ && properties[i].getType().isDirty( previousState[i], currentState[i], includeColumns[i], session );
if ( dirty ) {
if ( results == null ) {
results = new int[span];
}
results[count++] = i;
}
-
}
if ( count == 0 ) {
@@ -504,28 +549,33 @@
/**
* Determine if any of the given field values are modified, returning an array containing
- * indexes of the dirty fields or <tt>null</tt> if no fields are dirty.
- * @param x the current state of the entity
- * @param y the snapshot state just retrieved from the database
+ * indices of the modified fields.
+ * <p/>
+ * If it is determined that no fields are dirty, null is returned.
+ *
+ * @param properties The property definitions
+ * @param currentState The current state of the entity
+ * @param previousState The baseline state of the entity
+ * @param includeColumns Columns to be included in the mod checking, per property
+ * @param anyUninitializedProperties Does the entity currently hold any uninitialized property values?
+ * @param session The session from which the dirty check request originated.
+ * @return Array containing indices of the modified properties, or null if no properties considered modified.
*/
public static int[] findModified(
final StandardProperty[] properties,
- final Object[] x,
- final Object[] y,
+ final Object[] currentState,
+ final Object[] previousState,
final boolean[][] includeColumns,
final boolean anyUninitializedProperties,
- final SessionImplementor session)
- throws HibernateException {
-
+ final SessionImplementor session) {
int[] results = null;
int count = 0;
int span = properties.length;
for ( int i = 0; i < span; i++ ) {
-
- final boolean modified = x[i]!=LazyPropertyInitializer.UNFETCHED_PROPERTY //x is the "current" state
+ final boolean modified = currentState[i]!=LazyPropertyInitializer.UNFETCHED_PROPERTY
&& properties[i].isDirtyCheckable(anyUninitializedProperties)
- && properties[i].getType().isModified( y[i], x[i], includeColumns[i], session );
+ && properties[i].getType().isModified( previousState[i], currentState[i], includeColumns[i], session );
if ( modified ) {
if ( results == null ) {
@@ -533,7 +583,6 @@
}
results[count++] = i;
}
-
}
if ( count == 0 ) {
@@ -546,16 +595,4 @@
}
}
- public static void injectParameters(Object type, Properties parameters) {
- if (type instanceof ParameterizedType) {
- ( (ParameterizedType) type ).setParameterValues(parameters);
- }
- else if ( parameters!=null && !parameters.isEmpty() ) {
- throw new MappingException(
- "type is not parameterized: " +
- type.getClass().getName()
- );
- }
- }
-
}
18 years, 2 months
Hibernate SVN: r10756 - trunk/Hibernate3/src/org/hibernate/type
by hibernate-commits@lists.jboss.org
Author: steve.ebersole(a)jboss.com
Date: 2006-11-07 16:35:24 -0500 (Tue, 07 Nov 2006)
New Revision: 10756
Modified:
trunk/Hibernate3/src/org/hibernate/type/TypeFactory.java
Log:
javadocs
Modified: trunk/Hibernate3/src/org/hibernate/type/TypeFactory.java
===================================================================
--- trunk/Hibernate3/src/org/hibernate/type/TypeFactory.java 2006-11-07 21:12:32 UTC (rev 10755)
+++ trunk/Hibernate3/src/org/hibernate/type/TypeFactory.java 2006-11-07 21:35:24 UTC (rev 10756)
@@ -34,7 +34,7 @@
/**
* Used internally to obtain instances of <tt>Type</tt>. Applications should use static methods
* and constants on <tt>org.hibernate.Hibernate</tt>.
- *
+ *
* @see org.hibernate.Hibernate
* @author Gavin King
*/
@@ -114,7 +114,7 @@
Type type = new AdaptedImmutableType(Hibernate.DATE);
basics.put( type.getName(), type );
type = new AdaptedImmutableType(Hibernate.TIME);
- basics.put( type.getName(), type );
+ basics.put( type.getName(), type );
type = new AdaptedImmutableType(Hibernate.TIMESTAMP);
basics.put( type.getName(), type );
type = new AdaptedImmutableType( new DbTimestampType() );
@@ -127,7 +127,7 @@
basics.put( type.getName(), type );
type = new AdaptedImmutableType(Hibernate.BINARY);
basics.put( type.getName(), type );
-
+
BASIC_TYPES = Collections.unmodifiableMap( basics );
}
@@ -139,13 +139,13 @@
* A one-to-one association type for the given class
*/
public static EntityType oneToOne(
- String persistentClass,
+ String persistentClass,
ForeignKeyDirection foreignKeyType,
- String uniqueKeyPropertyName,
- boolean lazy,
+ String uniqueKeyPropertyName,
+ boolean lazy,
boolean unwrapProxy,
- boolean isEmbeddedInXML,
- String entityName,
+ boolean isEmbeddedInXML,
+ String entityName,
String propertyName
) {
return new OneToOneType(
@@ -156,7 +156,7 @@
unwrapProxy,
isEmbeddedInXML,
entityName,
- propertyName
+ propertyName
);
}
@@ -178,18 +178,18 @@
* A many-to-one association type for the given class
*/
public static EntityType manyToOne(
- String persistentClass,
+ String persistentClass,
String uniqueKeyPropertyName,
- boolean lazy,
- boolean unwrapProxy,
+ boolean lazy,
+ boolean unwrapProxy,
boolean isEmbeddedInXML,
boolean ignoreNotFound
) {
- return new ManyToOneType(
- persistentClass,
- uniqueKeyPropertyName,
+ return new ManyToOneType(
+ persistentClass,
+ uniqueKeyPropertyName,
lazy,
- unwrapProxy,
+ unwrapProxy,
isEmbeddedInXML,
ignoreNotFound
);
@@ -232,9 +232,9 @@
type = (Type) typeClass.newInstance();
}
catch (Exception e) {
- throw new MappingException(
+ throw new MappingException(
"Could not instantiate Type: " + typeClass.getName(),
- e
+ e
);
}
injectParameters(type, parameters);
@@ -314,11 +314,36 @@
return new SortedSetType( role, propertyRef, comparator, embedded );
}
+ public static void injectParameters(Object type, Properties parameters) {
+ if (type instanceof ParameterizedType) {
+ ( (ParameterizedType) type ).setParameterValues(parameters);
+ }
+ else if ( parameters!=null && !parameters.isEmpty() ) {
+ throw new MappingException(
+ "type is not parameterized: " +
+ type.getClass().getName()
+ );
+ }
+ }
+
+
+ // convenience methods relating to operations across arrays of types...
+
/**
- * Deep copy values in the first array into the second
+ * Deep copy a series of values from one array to another...
+ *
+ * @param values The values to copy (the source)
+ * @param types The value types
+ * @param copy an array indicating which values to include in the copy
+ * @param target The array into which to copy the values
+ * @param session The orginating session
*/
- public static void deepCopy(Object[] values, Type[] types, boolean[] copy, Object[] target,
- SessionImplementor session) throws HibernateException {
+ public static void deepCopy(
+ final Object[] values,
+ final Type[] types,
+ final boolean[] copy,
+ final Object[] target,
+ final SessionImplementor session) {
for ( int i = 0; i < types.length; i++ ) {
if ( copy[i] ) {
if ( values[i] == LazyPropertyInitializer.UNFETCHED_PROPERTY
@@ -334,57 +359,17 @@
}
/**
- * Determine if any of the given field values are dirty, returning an array containing indexes
- * of the dirty fields or <tt>null</tt> if no fields are dirty.
+ * Apply the {@link Type#beforeAssemble} operation across a series of values.
+ *
+ * @param row The values
+ * @param types The value types
+ * @param session The orginating session
*/
- /*public static int[] findDirty(Type[] types, Object[] x, Object[] y, boolean[] check,
- SessionImplementor session) throws HibernateException {
- int[] results = null;
- int count = 0;
+ public static void beforeAssemble(
+ final Serializable[] row,
+ final Type[] types,
+ final SessionImplementor session) {
for ( int i = 0; i < types.length; i++ ) {
- if ( check[i] && types[i].isDirty( x[i], y[i], session ) ) {
- if ( results == null ) results = new int[types.length];
- results[count++] = i;
- }
- }
- if ( count == 0 ) {
- return null;
- }
- else {
- int[] trimmed = new int[count];
- System.arraycopy( results, 0, trimmed, 0, count );
- return trimmed;
- }
- }*/
-
- /**
- * Determine if any of the given field values are modified, returning an array containing
- * indexes of the dirty fields or <tt>null</tt> if no fields are dirty.
- */
- /*public static int[] findModified(Type[] types, Object[] old, Object[] current, boolean[] check,
- SessionImplementor session) throws HibernateException {
- int[] results = null;
- int count = 0;
- for ( int i = 0; i < types.length; i++ ) {
- if ( check[i]
- && types[i].isModified( old[i], current[i], session ) ) {
- if ( results == null ) results = new int[types.length];
- results[count++] = i;
- }
- }
- if ( count == 0 ) {
- return null;
- }
- else {
- int[] trimmed = new int[count];
- System.arraycopy( results, 0, trimmed, 0, count );
- return trimmed;
- }
- }*/
-
- public static void beforeAssemble(Serializable[] row, Type[] types, SessionImplementor session)
- throws HibernateException {
- for ( int i = 0; i < types.length; i++ ) {
if ( row[i] != LazyPropertyInitializer.UNFETCHED_PROPERTY
&& row[i] != BackrefPropertyAccessor.UNKNOWN ) {
types[i].beforeAssemble( row[i], session );
@@ -392,12 +377,23 @@
}
}
- public static Object[] assemble(Serializable[] row, Type[] types, SessionImplementor session,
- Object owner) throws HibernateException {
+ /**
+ * Apply the {@link Type#assemble} operation across a series of values.
+ *
+ * @param row The values
+ * @param types The value types
+ * @param session The orginating session
+ * @param owner The entity "owning" the values
+ * @return The assembled state
+ */
+ public static Object[] assemble(
+ final Serializable[] row,
+ final Type[] types,
+ final SessionImplementor session,
+ final Object owner) {
Object[] assembled = new Object[row.length];
for ( int i = 0; i < types.length; i++ ) {
- if ( row[i] == LazyPropertyInitializer.UNFETCHED_PROPERTY
- || row[i] == BackrefPropertyAccessor.UNKNOWN ) {
+ if ( row[i] == LazyPropertyInitializer.UNFETCHED_PROPERTY || row[i] == BackrefPropertyAccessor.UNKNOWN ) {
assembled[i] = row[i];
}
else {
@@ -407,15 +403,28 @@
return assembled;
}
- public static Serializable[] disassemble(Object[] row, Type[] types, boolean[] nonCacheable, SessionImplementor session,
- Object owner) throws HibernateException {
+ /**
+ * Apply the {@link Type#disassemble} operation across a series of values.
+ *
+ * @param row The values
+ * @param types The value types
+ * @param nonCacheable An array indicating which values to include in the disassemled state
+ * @param session The orginating session
+ * @param owner The entity "owning" the values
+ * @return The disassembled state
+ */
+ public static Serializable[] disassemble(
+ final Object[] row,
+ final Type[] types,
+ final boolean[] nonCacheable,
+ final SessionImplementor session,
+ final Object owner) {
Serializable[] disassembled = new Serializable[row.length];
for ( int i = 0; i < row.length; i++ ) {
if ( nonCacheable!=null && nonCacheable[i] ) {
disassembled[i] = LazyPropertyInitializer.UNFETCHED_PROPERTY;
}
- else if ( row[i] == LazyPropertyInitializer.UNFETCHED_PROPERTY
- || row[i] == BackrefPropertyAccessor.UNKNOWN ) {
+ else if ( row[i] == LazyPropertyInitializer.UNFETCHED_PROPERTY || row[i] == BackrefPropertyAccessor.UNKNOWN ) {
disassembled[i] = (Serializable) row[i];
}
else {
@@ -425,8 +434,24 @@
return disassembled;
}
- public static Object[] replace(Object[] original, Object[] target, Type[] types,
- SessionImplementor session, Object owner, Map copyCache) throws HibernateException {
+ /**
+ * Apply the {@link Type#replace} operation across a series of values.
+ *
+ * @param original The source of the state
+ * @param target The target into which to replace the source values.
+ * @param types The value types
+ * @param session The orginating session
+ * @param owner The entity "owning" the values
+ * @param copyCache A map representing a cache of already replaced state
+ * @return The replaced state
+ */
+ public static Object[] replace(
+ final Object[] original,
+ final Object[] target,
+ final Type[] types,
+ final SessionImplementor session,
+ final Object owner,
+ final Map copyCache) {
Object[] copied = new Object[original.length];
for ( int i = 0; i < types.length; i++ ) {
if ( original[i] == LazyPropertyInitializer.UNFETCHED_PROPERTY
@@ -440,9 +465,26 @@
return copied;
}
- public static Object[] replace(Object[] original, Object[] target, Type[] types,
- SessionImplementor session, Object owner, Map copyCache,
- ForeignKeyDirection foreignKeyDirection) throws HibernateException {
+ /**
+ * Apply the {@link Type#replace} operation across a series of values.
+ *
+ * @param original The source of the state
+ * @param target The target into which to replace the source values.
+ * @param types The value types
+ * @param session The orginating session
+ * @param owner The entity "owning" the values
+ * @param copyCache A map representing a cache of already replaced state
+ * @param foreignKeyDirection FK directionality to be applied to the replacement
+ * @return The replaced state
+ */
+ public static Object[] replace(
+ final Object[] original,
+ final Object[] target,
+ final Type[] types,
+ final SessionImplementor session,
+ final Object owner,
+ final Map copyCache,
+ final ForeignKeyDirection foreignKeyDirection) {
Object[] copied = new Object[original.length];
for ( int i = 0; i < types.length; i++ ) {
if ( original[i] == LazyPropertyInitializer.UNFETCHED_PROPERTY
@@ -459,37 +501,40 @@
/**
- * Determine if any of the given field values are dirty, returning an array containing
- * indexes of the dirty fields or <tt>null</tt> if no fields are dirty.
- * @param x the current state of the entity
- * @param y the snapshot state from the time the object was loaded
+ * Determine if any of the given field values are dirty, returning an array containing
+ * indices of the dirty fields.
+ * <p/>
+ * If it is determined that no fields are dirty, null is returned.
+ *
+ * @param properties The property definitions
+ * @param currentState The current state of the entity
+ * @param previousState The baseline state of the entity
+ * @param includeColumns Columns to be included in the dirty checking, per property
+ * @param anyUninitializedProperties Does the entity currently hold any uninitialized property values?
+ * @param session The session from which the dirty check request originated.
+ * @return Array containing indices of the dirty properties, or null if no properties considered dirty.
*/
public static int[] findDirty(
- final StandardProperty[] properties,
- final Object[] x,
- final Object[] y,
+ final StandardProperty[] properties,
+ final Object[] currentState,
+ final Object[] previousState,
final boolean[][] includeColumns,
final boolean anyUninitializedProperties,
- final SessionImplementor session)
- throws HibernateException {
-
+ final SessionImplementor session) {
int[] results = null;
int count = 0;
int span = properties.length;
for ( int i = 0; i < span; i++ ) {
-
- final boolean dirty = x[i]!=LazyPropertyInitializer.UNFETCHED_PROPERTY //x is the "current" state
- && properties[i].isDirtyCheckable(anyUninitializedProperties)
- && properties[i].getType().isDirty( y[i], x[i], includeColumns[i], session );
-
+ final boolean dirty = currentState[i] != LazyPropertyInitializer.UNFETCHED_PROPERTY
+ && properties[i].isDirtyCheckable( anyUninitializedProperties )
+ && properties[i].getType().isDirty( previousState[i], currentState[i], includeColumns[i], session );
if ( dirty ) {
if ( results == null ) {
results = new int[span];
}
results[count++] = i;
}
-
}
if ( count == 0 ) {
@@ -504,28 +549,33 @@
/**
* Determine if any of the given field values are modified, returning an array containing
- * indexes of the dirty fields or <tt>null</tt> if no fields are dirty.
- * @param x the current state of the entity
- * @param y the snapshot state just retrieved from the database
+ * indices of the modified fields.
+ * <p/>
+ * If it is determined that no fields are dirty, null is returned.
+ *
+ * @param properties The property definitions
+ * @param currentState The current state of the entity
+ * @param previousState The baseline state of the entity
+ * @param includeColumns Columns to be included in the mod checking, per property
+ * @param anyUninitializedProperties Does the entity currently hold any uninitialized property values?
+ * @param session The session from which the dirty check request originated.
+ * @return Array containing indices of the modified properties, or null if no properties considered modified.
*/
public static int[] findModified(
final StandardProperty[] properties,
- final Object[] x,
- final Object[] y,
+ final Object[] currentState,
+ final Object[] previousState,
final boolean[][] includeColumns,
- final boolean anyUninitializedProperties,
- final SessionImplementor session)
- throws HibernateException {
-
+ final boolean anyUninitializedProperties,
+ final SessionImplementor session) {
int[] results = null;
int count = 0;
int span = properties.length;
for ( int i = 0; i < span; i++ ) {
-
- final boolean modified = x[i]!=LazyPropertyInitializer.UNFETCHED_PROPERTY //x is the "current" state
+ final boolean modified = currentState[i]!=LazyPropertyInitializer.UNFETCHED_PROPERTY
&& properties[i].isDirtyCheckable(anyUninitializedProperties)
- && properties[i].getType().isModified( y[i], x[i], includeColumns[i], session );
+ && properties[i].getType().isModified( previousState[i], currentState[i], includeColumns[i], session );
if ( modified ) {
if ( results == null ) {
@@ -533,7 +583,6 @@
}
results[count++] = i;
}
-
}
if ( count == 0 ) {
@@ -546,16 +595,4 @@
}
}
- public static void injectParameters(Object type, Properties parameters) {
- if (type instanceof ParameterizedType) {
- ( (ParameterizedType) type ).setParameterValues(parameters);
- }
- else if ( parameters!=null && !parameters.isEmpty() ) {
- throw new MappingException(
- "type is not parameterized: " +
- type.getClass().getName()
- );
- }
- }
-
}
18 years, 2 months
Hibernate SVN: r10755 - branches/Branch_3_2/Hibernate3/src/org/hibernate/persister/entity
by hibernate-commits@lists.jboss.org
Author: steve.ebersole(a)jboss.com
Date: 2006-11-07 16:12:32 -0500 (Tue, 07 Nov 2006)
New Revision: 10755
Modified:
branches/Branch_3_2/Hibernate3/src/org/hibernate/persister/entity/EntityPersister.java
Log:
started javadocing the persister
Modified: branches/Branch_3_2/Hibernate3/src/org/hibernate/persister/entity/EntityPersister.java
===================================================================
--- branches/Branch_3_2/Hibernate3/src/org/hibernate/persister/entity/EntityPersister.java 2006-11-07 21:12:19 UTC (rev 10754)
+++ branches/Branch_3_2/Hibernate3/src/org/hibernate/persister/entity/EntityPersister.java 2006-11-07 21:12:32 UTC (rev 10755)
@@ -20,11 +20,12 @@
import org.hibernate.type.VersionType;
/**
- * Concrete <tt>EntityPersister</tt>s implement mapping and persistence logic for a particular persistent class.
- * <br><br>
+ * Implementors define mapping and persistence logic for a particular
+ * strategy of entity mapping. An instance of entity persisters corresponds
+ * to a given mapped entity.
+ * <p/>
* Implementors must be threadsafe (preferrably immutable) and must provide a constructor
- * of type
- * <tt>(org.hibernate.map.PersistentClass, org.hibernate.impl.SessionFactoryImplementor)</tt>.
+ * matching the signature of: {@link org.hibernate.mapping.PersistentClass}, {@link org.hibernate.engine.SessionFactoryImplementor}
*
* @author Gavin King
*/
@@ -36,9 +37,12 @@
public static final String ENTITY_ID = "id";
/**
- * Finish the initialization of this object, once all <tt>ClassPersisters</tt> have been instantiated.
+ * Finish the initialization of this object.
+ * <p/>
+ * Called only once per {@link org.hibernate.SessionFactory} lifecycle,
+ * after all entity persisters have been instantiated.
*
- * Called only once, before any other method.
+ * @throws org.hibernate.MappingException Indicates an issue in the metdata.
*/
public void postInstantiate() throws MappingException;
@@ -55,129 +59,208 @@
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/**
- * Returns an object that identifies the space in which identifiers of this class hierarchy are unique.
+ * Returns an object that identifies the space in which identifiers of
+ * this entity hierarchy are unique. Might be a table name, a JNDI URL, etc.
*
- * A table name, a JNDI URL, etc.
+ * @return The root entity name.
*/
public String getRootEntityName();
/**
- * The classname of the persistent class (used only for messages)
+ * The entity name which this persister maps.
+ *
+ * @return The name of the entity which this persister maps.
*/
public String getEntityName();
/**
- * Is the given entity name the name of a subclass, or this class?
+ * Determine whether the given name represents a subclass entity
+ * (or this entity itself) of the entity mapped by this persister.
+ *
+ * @param entityName The entity name to be checked.
+ * @return True if the given entity name represents either the entity
+ * mapped by this persister or one of its subclass entities; false
+ * otherwise.
*/
public boolean isSubclassEntityName(String entityName);
/**
- * Returns an array of objects that identify spaces in which properties of this class are persisted,
- * for instances of this class only.
+ * Returns an array of objects that identify spaces in which properties of
+ * this entity are persisted, for instances of this class only.
+ * <p/>
+ * For most implementations, this returns the complete set of table names
+ * to which instances of the mapped entity are persisted (not accounting
+ * for superclass entity mappings).
+ *
+ * @return The property spaces.
*/
public Serializable[] getPropertySpaces();
/**
- * Returns an array of objects that identify spaces in which properties of this class are persisted,
- * for instances of this class and its subclasses.
+ * Returns an array of objects that identify spaces in which properties of
+ * this entity are persisted, for instances of this class and its subclasses.
+ * <p/>
+ * Much like {@link #getPropertySpaces()}, except that here we include subclass
+ * entity spaces.
+ *
+ * @return The query spaces.
*/
public Serializable[] getQuerySpaces();
/**
- * Does this class support dynamic proxies.
+ * Determine whether this entity supports dynamic proxies.
+ *
+ * @return True if the entity has dynamic proxy support; false otherwise.
*/
public boolean hasProxy();
/**
- * Do instances of this class contain collections.
+ * Determine whether this entity contains references to persistent collections.
+ *
+ * @return True if the entity does contain persistent collections; false otherwise.
*/
public boolean hasCollections();
/**
- * Does this entity declare any properties of
- * mutable type?
+ * Determine whether any properties of this entity are considered mutable.
+ *
+ * @return True if any properties of the entity are mutable; false otherwise (meaning none are).
*/
public boolean hasMutableProperties();
/**
- * Does this entity own any collections which are
- * fetchable by subselect?
+ * Determine whether this entity contains references to persistent collections
+ * which are fetchable by subselect?
+ *
+ * @return True if the entity contains collections fetchable by subselect; false otherwise.
*/
public boolean hasSubselectLoadableCollections();
/**
- * Does this class declare any cascading save/update/deletes.
+ * Determine whether this entity has any non-none cascading.
+ *
+ * @return True if the entity has any properties with a cscade other than NONE;
+ * false otherwise (aka, no cascading).
*/
public boolean hasCascades();
/**
- * Are instances of this class mutable.
+ * Determine whether instances of this entity are considered mutable.
+ *
+ * @return True if the entity is considered mutable; false otherwise.
*/
public boolean isMutable();
/**
- * Is this class mapped as a subclass of another class?
+ * Determine whether the entity is inherited one or more other entities.
+ * In other words, is this entity a subclass of other entities.
+ *
+ * @return True if other entities extend this entity; false otherwise.
*/
public boolean isInherited();
/**
- * Is the identifier assigned before the insert by an <tt>IDGenerator</tt>. Or
- * is it returned by the <tt>insert()</tt> method? This determines which form
- * of <tt>insert()</tt> will be called.
+ * Are identifiers of this entity assigned known before the insert execution?
+ * Or, are they generated (in the database) by the insert execution.
+ *
+ * @return True if identifiers for this entity are generated by the insert
+ * execution.
*/
public boolean isIdentifierAssignedByInsert();
/**
- * Get the type of a particular property
+ * Get the type of a particular property by name.
+ *
+ * @param propertyName The name of the property for which to retrieve
+ * the typpe.
+ * @return The type.
+ * @throws org.hibernate.MappingException Typically indicates an unknown
+ * property name.
*/
public Type getPropertyType(String propertyName) throws MappingException;
/**
- * Compare two snapshots of the state of an instance to determine if the persistent state
- * was modified
- * @return <tt>null</tt> or the indices of the dirty properties
+ * Compare the two snapshots to determine if they represent dirty state.
+ *
+ * @param currentState The current snapshot
+ * @param previousState The baseline snapshot
+ * @param owner The entity containing the state
+ * @param session The originating session
+ * @return The indices of all dirty properties, or null if no properties
+ * were dirty.
*/
- public int[] findDirty(Object[] x, Object[] y, Object owner, SessionImplementor session)
- throws HibernateException;
+ public int[] findDirty(Object[] currentState, Object[] previousState, Object owner, SessionImplementor session);
/**
- * Compare the state of an instance to the current database state
- * @return <tt>null</tt> or the indices of the dirty properties
+ * Compare the two snapshots to determine if they represent modified state.
+ *
+ * @param old The baseline snapshot
+ * @param current The current snapshot
+ * @param object The entity containing the state
+ * @param session The originating session
+ * @return The indices of all modified properties, or null if no properties
+ * were modified.
*/
- public int[] findModified(Object[] old, Object[] current, Object object, SessionImplementor session)
- throws HibernateException;
+ public int[] findModified(Object[] old, Object[] current, Object object, SessionImplementor session);
/**
- * Does the class have a property holding the identifier value?
+ * Determine whether the entity has a particular property holding
+ * the identifier value.
+ *
+ * @return True if the entity has a specific property holding identifier value.
*/
public boolean hasIdentifierProperty();
+
/**
- * Do detached instances of this class carry their own identifier value?
+ * Determine whether detahced instances of this entity carry their own
+ * identifier value.
+ * <p/>
+ * The other option is the deperecated feature where users could supply
+ * the id during session calls.
+ *
+ * @return True if either (1) {@link #hasIdentifierProperty()} or
+ * (2) the identifier is an embedded composite identifier; false otherwise.
*/
public boolean canExtractIdOutOfEntity();
/**
- * Are instances of this class versioned by a timestamp or version number column.
+ * Determine whether optimistic locking by column is enabled for this
+ * entity.
+ *
+ * @return True if optimistic locking by column (i.e., <version/> or
+ * <timestamp/>) is enabled; false otherwise.
*/
public boolean isVersioned();
/**
- * Get the type of versioning (optional operation)
+ * If {@link #isVersioned()}, then what is the type of the property
+ * holding the locking value.
+ *
+ * @return The type of the version property; or null, if not versioned.
*/
public VersionType getVersionType();
/**
- * Which property holds the version number (optional operation).
+ * If {@link #isVersioned()}, then what is the index of the property
+ * holding the locking value.
+ *
+ * @return The type of the version property; or -66, if not versioned.
*/
public int getVersionProperty();
/**
- * Does this entity declare a natural id?
+ * Determine whether this entity defines a natural identifier.
+ *
+ * @return True if the entity defines a natural id; false otherwise.
*/
public boolean hasNaturalIdentifier();
/**
- * Which properties hold the natural id?
+ * If the entity defines a natural id ({@link #hasNaturalIdentifier()}), which
+ * properties make up the natural id.
+ *
+ * @return The indices of the properties making of the natural id; or
+ * null, if no natural id is defined.
*/
public int[] getNaturalIdentifierProperties();
@@ -188,15 +271,20 @@
* @param session The session from which the request originated.
* @return The natural-id snapshot.
*/
- public Object[] getNaturalIdentifierSnapshot(Serializable id, SessionImplementor session) throws HibernateException;
+ public Object[] getNaturalIdentifierSnapshot(Serializable id, SessionImplementor session);
/**
- * Return the <tt>IdentifierGenerator</tt> for the class
+ * Determine which identifier generation strategy is used for this entity.
+ *
+ * @return The identifier generation strategy.
*/
- public IdentifierGenerator getIdentifierGenerator() throws HibernateException;
+ public IdentifierGenerator getIdentifierGenerator();
/**
- * Does this entity define some lazy attributes?
+ * Determine whether this entity defines any lazy properties (ala
+ * bytecode instrumentation).
+ *
+ * @return True if the entity has properties mapped as lazy; false otherwise.
*/
public boolean hasLazyProperties();
18 years, 2 months
Hibernate SVN: r10754 - trunk/Hibernate3/src/org/hibernate/persister/entity
by hibernate-commits@lists.jboss.org
Author: steve.ebersole(a)jboss.com
Date: 2006-11-07 16:12:19 -0500 (Tue, 07 Nov 2006)
New Revision: 10754
Modified:
trunk/Hibernate3/src/org/hibernate/persister/entity/EntityPersister.java
Log:
started javadocing the persister
Modified: trunk/Hibernate3/src/org/hibernate/persister/entity/EntityPersister.java
===================================================================
--- trunk/Hibernate3/src/org/hibernate/persister/entity/EntityPersister.java 2006-11-07 17:04:27 UTC (rev 10753)
+++ trunk/Hibernate3/src/org/hibernate/persister/entity/EntityPersister.java 2006-11-07 21:12:19 UTC (rev 10754)
@@ -20,11 +20,12 @@
import org.hibernate.type.VersionType;
/**
- * Concrete <tt>EntityPersister</tt>s implement mapping and persistence logic for a particular persistent class.
- * <br><br>
+ * Implementors define mapping and persistence logic for a particular
+ * strategy of entity mapping. An instance of entity persisters corresponds
+ * to a given mapped entity.
+ * <p/>
* Implementors must be threadsafe (preferrably immutable) and must provide a constructor
- * of type
- * <tt>(org.hibernate.map.PersistentClass, org.hibernate.impl.SessionFactoryImplementor)</tt>.
+ * matching the signature of: {@link org.hibernate.mapping.PersistentClass}, {@link org.hibernate.engine.SessionFactoryImplementor}
*
* @author Gavin King
*/
@@ -36,9 +37,12 @@
public static final String ENTITY_ID = "id";
/**
- * Finish the initialization of this object, once all <tt>ClassPersisters</tt> have been instantiated.
+ * Finish the initialization of this object.
+ * <p/>
+ * Called only once per {@link org.hibernate.SessionFactory} lifecycle,
+ * after all entity persisters have been instantiated.
*
- * Called only once, before any other method.
+ * @throws org.hibernate.MappingException Indicates an issue in the metdata.
*/
public void postInstantiate() throws MappingException;
@@ -55,129 +59,208 @@
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/**
- * Returns an object that identifies the space in which identifiers of this class hierarchy are unique.
+ * Returns an object that identifies the space in which identifiers of
+ * this entity hierarchy are unique. Might be a table name, a JNDI URL, etc.
*
- * A table name, a JNDI URL, etc.
+ * @return The root entity name.
*/
public String getRootEntityName();
/**
- * The classname of the persistent class (used only for messages)
+ * The entity name which this persister maps.
+ *
+ * @return The name of the entity which this persister maps.
*/
public String getEntityName();
-
+
/**
- * Is the given entity name the name of a subclass, or this class?
+ * Determine whether the given name represents a subclass entity
+ * (or this entity itself) of the entity mapped by this persister.
+ *
+ * @param entityName The entity name to be checked.
+ * @return True if the given entity name represents either the entity
+ * mapped by this persister or one of its subclass entities; false
+ * otherwise.
*/
public boolean isSubclassEntityName(String entityName);
/**
- * Returns an array of objects that identify spaces in which properties of this class are persisted,
- * for instances of this class only.
+ * Returns an array of objects that identify spaces in which properties of
+ * this entity are persisted, for instances of this class only.
+ * <p/>
+ * For most implementations, this returns the complete set of table names
+ * to which instances of the mapped entity are persisted (not accounting
+ * for superclass entity mappings).
+ *
+ * @return The property spaces.
*/
public Serializable[] getPropertySpaces();
/**
- * Returns an array of objects that identify spaces in which properties of this class are persisted,
- * for instances of this class and its subclasses.
+ * Returns an array of objects that identify spaces in which properties of
+ * this entity are persisted, for instances of this class and its subclasses.
+ * <p/>
+ * Much like {@link #getPropertySpaces()}, except that here we include subclass
+ * entity spaces.
+ *
+ * @return The query spaces.
*/
public Serializable[] getQuerySpaces();
/**
- * Does this class support dynamic proxies.
+ * Determine whether this entity supports dynamic proxies.
+ *
+ * @return True if the entity has dynamic proxy support; false otherwise.
*/
public boolean hasProxy();
/**
- * Do instances of this class contain collections.
+ * Determine whether this entity contains references to persistent collections.
+ *
+ * @return True if the entity does contain persistent collections; false otherwise.
*/
public boolean hasCollections();
-
+
/**
- * Does this entity declare any properties of
- * mutable type?
+ * Determine whether any properties of this entity are considered mutable.
+ *
+ * @return True if any properties of the entity are mutable; false otherwise (meaning none are).
*/
public boolean hasMutableProperties();
-
+
/**
- * Does this entity own any collections which are
- * fetchable by subselect?
+ * Determine whether this entity contains references to persistent collections
+ * which are fetchable by subselect?
+ *
+ * @return True if the entity contains collections fetchable by subselect; false otherwise.
*/
public boolean hasSubselectLoadableCollections();
/**
- * Does this class declare any cascading save/update/deletes.
+ * Determine whether this entity has any non-none cascading.
+ *
+ * @return True if the entity has any properties with a cscade other than NONE;
+ * false otherwise (aka, no cascading).
*/
public boolean hasCascades();
/**
- * Are instances of this class mutable.
+ * Determine whether instances of this entity are considered mutable.
+ *
+ * @return True if the entity is considered mutable; false otherwise.
*/
public boolean isMutable();
/**
- * Is this class mapped as a subclass of another class?
+ * Determine whether the entity is inherited one or more other entities.
+ * In other words, is this entity a subclass of other entities.
+ *
+ * @return True if other entities extend this entity; false otherwise.
*/
public boolean isInherited();
/**
- * Is the identifier assigned before the insert by an <tt>IDGenerator</tt>. Or
- * is it returned by the <tt>insert()</tt> method? This determines which form
- * of <tt>insert()</tt> will be called.
+ * Are identifiers of this entity assigned known before the insert execution?
+ * Or, are they generated (in the database) by the insert execution.
+ *
+ * @return True if identifiers for this entity are generated by the insert
+ * execution.
*/
public boolean isIdentifierAssignedByInsert();
/**
- * Get the type of a particular property
+ * Get the type of a particular property by name.
+ *
+ * @param propertyName The name of the property for which to retrieve
+ * the typpe.
+ * @return The type.
+ * @throws org.hibernate.MappingException Typically indicates an unknown
+ * property name.
*/
public Type getPropertyType(String propertyName) throws MappingException;
/**
- * Compare two snapshots of the state of an instance to determine if the persistent state
- * was modified
- * @return <tt>null</tt> or the indices of the dirty properties
+ * Compare the two snapshots to determine if they represent dirty state.
+ *
+ * @param currentState The current snapshot
+ * @param previousState The baseline snapshot
+ * @param owner The entity containing the state
+ * @param session The originating session
+ * @return The indices of all dirty properties, or null if no properties
+ * were dirty.
*/
- public int[] findDirty(Object[] x, Object[] y, Object owner, SessionImplementor session)
- throws HibernateException;
+ public int[] findDirty(Object[] currentState, Object[] previousState, Object owner, SessionImplementor session);
/**
- * Compare the state of an instance to the current database state
- * @return <tt>null</tt> or the indices of the dirty properties
+ * Compare the two snapshots to determine if they represent modified state.
+ *
+ * @param old The baseline snapshot
+ * @param current The current snapshot
+ * @param object The entity containing the state
+ * @param session The originating session
+ * @return The indices of all modified properties, or null if no properties
+ * were modified.
*/
- public int[] findModified(Object[] old, Object[] current, Object object, SessionImplementor session)
- throws HibernateException;
+ public int[] findModified(Object[] old, Object[] current, Object object, SessionImplementor session);
/**
- * Does the class have a property holding the identifier value?
+ * Determine whether the entity has a particular property holding
+ * the identifier value.
+ *
+ * @return True if the entity has a specific property holding identifier value.
*/
public boolean hasIdentifierProperty();
+
/**
- * Do detached instances of this class carry their own identifier value?
+ * Determine whether detahced instances of this entity carry their own
+ * identifier value.
+ * <p/>
+ * The other option is the deperecated feature where users could supply
+ * the id during session calls.
+ *
+ * @return True if either (1) {@link #hasIdentifierProperty()} or
+ * (2) the identifier is an embedded composite identifier; false otherwise.
*/
public boolean canExtractIdOutOfEntity();
/**
- * Are instances of this class versioned by a timestamp or version number column.
+ * Determine whether optimistic locking by column is enabled for this
+ * entity.
+ *
+ * @return True if optimistic locking by column (i.e., <version/> or
+ * <timestamp/>) is enabled; false otherwise.
*/
public boolean isVersioned();
/**
- * Get the type of versioning (optional operation)
+ * If {@link #isVersioned()}, then what is the type of the property
+ * holding the locking value.
+ *
+ * @return The type of the version property; or null, if not versioned.
*/
public VersionType getVersionType();
/**
- * Which property holds the version number (optional operation).
+ * If {@link #isVersioned()}, then what is the index of the property
+ * holding the locking value.
+ *
+ * @return The type of the version property; or -66, if not versioned.
*/
public int getVersionProperty();
-
+
/**
- * Does this entity declare a natural id?
+ * Determine whether this entity defines a natural identifier.
+ *
+ * @return True if the entity defines a natural id; false otherwise.
*/
public boolean hasNaturalIdentifier();
/**
- * Which properties hold the natural id?
+ * If the entity defines a natural id ({@link #hasNaturalIdentifier()}), which
+ * properties make up the natural id.
+ *
+ * @return The indices of the properties making of the natural id; or
+ * null, if no natural id is defined.
*/
public int[] getNaturalIdentifierProperties();
@@ -188,18 +271,23 @@
* @param session The session from which the request originated.
* @return The natural-id snapshot.
*/
- public Object[] getNaturalIdentifierSnapshot(Serializable id, SessionImplementor session) throws HibernateException;
+ public Object[] getNaturalIdentifierSnapshot(Serializable id, SessionImplementor session);
/**
- * Return the <tt>IdentifierGenerator</tt> for the class
+ * Determine which identifier generation strategy is used for this entity.
+ *
+ * @return The identifier generation strategy.
*/
- public IdentifierGenerator getIdentifierGenerator() throws HibernateException;
-
+ public IdentifierGenerator getIdentifierGenerator();
+
/**
- * Does this entity define some lazy attributes?
+ * Determine whether this entity defines any lazy properties (ala
+ * bytecode instrumentation).
+ *
+ * @return True if the entity has properties mapped as lazy; false otherwise.
*/
public boolean hasLazyProperties();
-
+
/**
* Load an instance of the persistent class.
*/
@@ -277,7 +365,7 @@
* (does the property appear in an SQL UPDATE)
*/
public boolean[] getPropertyUpdateability();
-
+
/**
* Get the "checkability" of the properties of this class
* (is the property dirty checked, does the cache need
@@ -372,7 +460,7 @@
* Try to discover the entity mode from the entity instance
*/
public EntityMode guessEntityMode(Object object);
-
+
/**
* Has the class actually been bytecode instrumented?
*/
@@ -487,7 +575,7 @@
*/
public boolean implementsValidatable(EntityMode entityMode);
/**
- * Get the proxy interface that instances of <em>this</em> concrete class will be
+ * Get the proxy interface that instances of <em>this</em> concrete class will be
* cast to (optional operation).
*/
public Class getConcreteProxyClass(EntityMode entityMode);
@@ -511,7 +599,7 @@
* Get the value of a particular property
*/
public Object getPropertyValue(Object object, int i, EntityMode entityMode) throws HibernateException;
-
+
/**
* Get the value of a particular property
*/
@@ -521,7 +609,7 @@
* Get the identifier of an instance (throw an exception if no identifier property)
*/
public Serializable getIdentifier(Object object, EntityMode entityMode) throws HibernateException;
-
+
/**
* Set the identifier of an instance (or do nothing if no identifier property)
*/
@@ -541,14 +629,14 @@
* Is the given object an instance of this entity?
*/
public boolean isInstance(Object object, EntityMode entityMode);
-
+
/**
* Does the given instance have any uninitialized lazy properties?
*/
public boolean hasUninitializedLazyProperties(Object object, EntityMode entityMode);
-
+
/**
- * Set the identifier and version of the given instance back
+ * Set the identifier and version of the given instance back
* to its "unsaved" value, returning the id
* @param currentId TODO
* @param currentVersion TODO
18 years, 2 months
Hibernate SVN: r10753 - branches/Branch_3_2/HibernateExt/ejb/src/java/org/hibernate/ejb
by hibernate-commits@lists.jboss.org
Author: epbernard
Date: 2006-11-07 12:04:27 -0500 (Tue, 07 Nov 2006)
New Revision: 10753
Modified:
branches/Branch_3_2/HibernateExt/ejb/src/java/org/hibernate/ejb/HibernatePersistence.java
Log:
EJB-247 return null when not a HEM
Modified: branches/Branch_3_2/HibernateExt/ejb/src/java/org/hibernate/ejb/HibernatePersistence.java
===================================================================
--- branches/Branch_3_2/HibernateExt/ejb/src/java/org/hibernate/ejb/HibernatePersistence.java 2006-11-07 14:48:59 UTC (rev 10752)
+++ branches/Branch_3_2/HibernateExt/ejb/src/java/org/hibernate/ejb/HibernatePersistence.java 2006-11-07 17:04:27 UTC (rev 10753)
@@ -117,14 +117,14 @@
*/
public EntityManagerFactory createEntityManagerFactory(String persistenceUnitName, Map overridenProperties) {
Ejb3Configuration cfg = new Ejb3Configuration();
- cfg.configure( persistenceUnitName, overridenProperties );
- return cfg.buildEntityManagerFactory();
+ Ejb3Configuration configured = cfg.configure( persistenceUnitName, overridenProperties );
+ return configured != null ? configured.buildEntityManagerFactory() : null;
}
public EntityManagerFactory createContainerEntityManagerFactory(PersistenceUnitInfo info, Map map) {
Ejb3Configuration cfg = new Ejb3Configuration();
- cfg.configure( info, map );
- return cfg.buildEntityManagerFactory();
+ Ejb3Configuration configured = cfg.configure( info, map );
+ return configured != null ? configured.buildEntityManagerFactory() : null;
}
/**
18 years, 2 months
Hibernate SVN: r10752 - trunk/Hibernate3/src/org/hibernate/proxy/pojo/javassist
by hibernate-commits@lists.jboss.org
Author: epbernard
Date: 2006-11-07 09:48:59 -0500 (Tue, 07 Nov 2006)
New Revision: 10752
Modified:
trunk/Hibernate3/src/org/hibernate/proxy/pojo/javassist/JavassistLazyInitializer.java
Log:
HHH-2219
Modified: trunk/Hibernate3/src/org/hibernate/proxy/pojo/javassist/JavassistLazyInitializer.java
===================================================================
--- trunk/Hibernate3/src/org/hibernate/proxy/pojo/javassist/JavassistLazyInitializer.java 2006-11-07 14:48:43 UTC (rev 10751)
+++ trunk/Hibernate3/src/org/hibernate/proxy/pojo/javassist/JavassistLazyInitializer.java 2006-11-07 14:48:59 UTC (rev 10752)
@@ -75,9 +75,9 @@
factory.setSuperclass( interfaces.length == 1 ? persistentClass : null );
factory.setInterfaces( interfaces );
factory.setFilter( FINALIZE_FILTER );
- factory.setHandler( instance );
Class cl = factory.createClass();
final HibernateProxy proxy = ( HibernateProxy ) cl.newInstance();
+ ( ( ProxyObject ) proxy ).setHandler( instance );
instance.constructed = true;
return proxy;
}
18 years, 2 months