Hibernate SVN: r11654 - in branches/Branch_3_2/Hibernate3/test/org/hibernate/test: hql and 1 other directories.
by hibernate-commits@lists.jboss.org
Author: steve.ebersole(a)jboss.com
Date: 2007-06-07 18:48:34 -0400 (Thu, 07 Jun 2007)
New Revision: 11654
Modified:
branches/Branch_3_2/Hibernate3/test/org/hibernate/test/exception/SQLExceptionConversionTest.java
branches/Branch_3_2/Hibernate3/test/org/hibernate/test/hql/ASTParserLoadingTest.java
branches/Branch_3_2/Hibernate3/test/org/hibernate/test/hql/BulkManipulationTest.java
branches/Branch_3_2/Hibernate3/test/org/hibernate/test/hql/Name.java
branches/Branch_3_2/Hibernate3/test/org/hibernate/test/sql/hand/query/NativeSQLQueriesTest.java
Log:
HHH-2662: PostgreSQL testsuite
Modified: branches/Branch_3_2/Hibernate3/test/org/hibernate/test/exception/SQLExceptionConversionTest.java
===================================================================
--- branches/Branch_3_2/Hibernate3/test/org/hibernate/test/exception/SQLExceptionConversionTest.java 2007-06-07 22:48:18 UTC (rev 11653)
+++ branches/Branch_3_2/Hibernate3/test/org/hibernate/test/exception/SQLExceptionConversionTest.java 2007-06-07 22:48:34 UTC (rev 11654)
@@ -45,6 +45,7 @@
SQLExceptionConverter converter = getDialect().buildSQLExceptionConverter();
Session session = openSession();
+ session.beginTransaction();
Connection connection = session.connection();
// Attempt to insert some bad values into the T_MEMBERSHIP table that should
@@ -76,6 +77,7 @@
}
}
+ session.getTransaction().rollback();
session.close();
}
@@ -85,10 +87,10 @@
Session session = openSession();
Connection connection = session.connection();
- // prepare a query against a non-existent table
+ // prepare/execute a query against a non-existent table
PreparedStatement ps = null;
try {
- ps = connection.prepareStatement("SELECT user_id, user_name FROM tbl_user");
+ ps = connection.prepareStatement("SELECT user_id, user_name FROM tbl_no_there");
ps.executeQuery();
fail("SQL compilation should have failed");
Modified: branches/Branch_3_2/Hibernate3/test/org/hibernate/test/hql/ASTParserLoadingTest.java
===================================================================
--- branches/Branch_3_2/Hibernate3/test/org/hibernate/test/hql/ASTParserLoadingTest.java 2007-06-07 22:48:18 UTC (rev 11653)
+++ branches/Branch_3_2/Hibernate3/test/org/hibernate/test/hql/ASTParserLoadingTest.java 2007-06-07 22:48:34 UTC (rev 11654)
@@ -961,10 +961,7 @@
private Human genSimpleHuman(String fName, String lName) {
Human h = new Human();
- h.setName( new Name() );
- h.getName().setFirst( fName );
- h.getName().setLast( lName );
- h.getName().setInitial('X');
+ h.setName( new Name( fName, 'X', lName ) );
return h;
}
@@ -1241,17 +1238,11 @@
Transaction txn = session.beginTransaction();
Human human = new Human();
- human.setName( new Name() );
- human.getName().setFirst( "Steve" );
- human.getName().setInitial( 'L' );
- human.getName().setLast( "Ebersole" );
+ human.setName( new Name( "Steve", 'L', "Ebersole" ) );
session.save( human );
Human friend = new Human();
- friend.setName( new Name() );
- friend.getName().setFirst( "John" );
- friend.getName().setInitial( 'Q' );
- friend.getName().setLast( "Doe" );
+ friend.setName( new Name( "John", 'Q', "Doe" ) );
friend.setBodyWeight( 11.0f );
session.save( friend );
Modified: branches/Branch_3_2/Hibernate3/test/org/hibernate/test/hql/BulkManipulationTest.java
===================================================================
--- branches/Branch_3_2/Hibernate3/test/org/hibernate/test/hql/BulkManipulationTest.java 2007-06-07 22:48:18 UTC (rev 11653)
+++ branches/Branch_3_2/Hibernate3/test/org/hibernate/test/hql/BulkManipulationTest.java 2007-06-07 22:48:34 UTC (rev 11654)
@@ -600,10 +600,7 @@
Transaction t = s.beginTransaction();
Human human = new Human();
- human.setName( new Name() );
- human.getName().setFirst("Stevee");
- human.getName().setInitial('X');
- human.getName().setLast("Ebersole");
+ human.setName( new Name( "Stevee", 'X', "Ebersole" ) );
s.save( human );
s.flush();
@@ -654,14 +651,10 @@
Transaction t = s.beginTransaction();
Human human = new Human();
- human.setName( new Name() );
- human.getName().setFirst( "Steve" );
- human.getName().setInitial('E');
+ human.setName( new Name( "Steve", 'E', null ) );
Human mother = new Human();
- mother.setName( new Name() );
- mother.getName().setFirst( "Jane" );
- mother.getName().setInitial('E');
+ mother.setName( new Name( "Jane", 'E', null ) );
human.setMother( mother );
s.save( human );
Modified: branches/Branch_3_2/Hibernate3/test/org/hibernate/test/hql/Name.java
===================================================================
--- branches/Branch_3_2/Hibernate3/test/org/hibernate/test/hql/Name.java 2007-06-07 22:48:18 UTC (rev 11653)
+++ branches/Branch_3_2/Hibernate3/test/org/hibernate/test/hql/Name.java 2007-06-07 22:48:34 UTC (rev 11654)
@@ -6,17 +6,21 @@
*/
public class Name {
private String first;
- private char initial;
+ private Character initial;
private String last;
protected Name() {}
- public Name(String first, char initial, String last) {
+ public Name(String first, Character initial, String last) {
this.first = first;
this.initial = initial;
this.last = last;
}
+ public Name(String first, char initial, String last) {
+ this( first, new Character( initial ), last );
+ }
+
public String getFirst() {
return first;
}
@@ -25,11 +29,11 @@
this.first = first;
}
- public char getInitial() {
+ public Character getInitial() {
return initial;
}
- public void setInitial(char initial) {
+ public void setInitial(Character initial) {
this.initial = initial;
}
Modified: branches/Branch_3_2/Hibernate3/test/org/hibernate/test/sql/hand/query/NativeSQLQueriesTest.java
===================================================================
--- branches/Branch_3_2/Hibernate3/test/org/hibernate/test/sql/hand/query/NativeSQLQueriesTest.java 2007-06-07 22:48:18 UTC (rev 11653)
+++ branches/Branch_3_2/Hibernate3/test/org/hibernate/test/sql/hand/query/NativeSQLQueriesTest.java 2007-06-07 22:48:34 UTC (rev 11654)
@@ -99,6 +99,7 @@
// throwing a sql exception because the SQL gets passed
// "un-processed"...
Session s = openSession();
+ s.beginTransaction();
try {
String sql = "select {org.*} " +
"from organization org";
@@ -109,6 +110,7 @@
// expected behavior
}
finally {
+ s.getTransaction().rollback();
s.close();
}
}
18 years, 10 months
Hibernate SVN: r11653 - in trunk/Hibernate3/code/testsuite/src/test/java/org/hibernate/test: hql and 1 other directories.
by hibernate-commits@lists.jboss.org
Author: steve.ebersole(a)jboss.com
Date: 2007-06-07 18:48:18 -0400 (Thu, 07 Jun 2007)
New Revision: 11653
Modified:
trunk/Hibernate3/code/testsuite/src/test/java/org/hibernate/test/exception/SQLExceptionConversionTest.java
trunk/Hibernate3/code/testsuite/src/test/java/org/hibernate/test/hql/ASTParserLoadingTest.java
trunk/Hibernate3/code/testsuite/src/test/java/org/hibernate/test/hql/BulkManipulationTest.java
trunk/Hibernate3/code/testsuite/src/test/java/org/hibernate/test/hql/Name.java
trunk/Hibernate3/code/testsuite/src/test/java/org/hibernate/test/sql/hand/query/NativeSQLQueriesTest.java
Log:
HHH-2662: PostgreSQL testsuite
Modified: trunk/Hibernate3/code/testsuite/src/test/java/org/hibernate/test/exception/SQLExceptionConversionTest.java
===================================================================
--- trunk/Hibernate3/code/testsuite/src/test/java/org/hibernate/test/exception/SQLExceptionConversionTest.java 2007-06-07 18:26:42 UTC (rev 11652)
+++ trunk/Hibernate3/code/testsuite/src/test/java/org/hibernate/test/exception/SQLExceptionConversionTest.java 2007-06-07 22:48:18 UTC (rev 11653)
@@ -45,6 +45,7 @@
SQLExceptionConverter converter = getDialect().buildSQLExceptionConverter();
Session session = openSession();
+ session.beginTransaction();
Connection connection = session.connection();
// Attempt to insert some bad values into the T_MEMBERSHIP table that should
@@ -76,6 +77,7 @@
}
}
+ session.getTransaction().rollback();
session.close();
}
@@ -85,10 +87,10 @@
Session session = openSession();
Connection connection = session.connection();
- // prepare a query against a non-existent table
+ // prepare/execute a query against a non-existent table
PreparedStatement ps = null;
try {
- ps = connection.prepareStatement("SELECT user_id, user_name FROM tbl_user");
+ ps = connection.prepareStatement("SELECT user_id, user_name FROM tbl_no_there");
ps.executeQuery();
fail("SQL compilation should have failed");
Modified: trunk/Hibernate3/code/testsuite/src/test/java/org/hibernate/test/hql/ASTParserLoadingTest.java
===================================================================
--- trunk/Hibernate3/code/testsuite/src/test/java/org/hibernate/test/hql/ASTParserLoadingTest.java 2007-06-07 18:26:42 UTC (rev 11652)
+++ trunk/Hibernate3/code/testsuite/src/test/java/org/hibernate/test/hql/ASTParserLoadingTest.java 2007-06-07 22:48:18 UTC (rev 11653)
@@ -961,10 +961,7 @@
private Human genSimpleHuman(String fName, String lName) {
Human h = new Human();
- h.setName( new Name() );
- h.getName().setFirst( fName );
- h.getName().setLast( lName );
- h.getName().setInitial('X');
+ h.setName( new Name( fName, 'X', lName ) );
return h;
}
@@ -1241,17 +1238,11 @@
Transaction txn = session.beginTransaction();
Human human = new Human();
- human.setName( new Name() );
- human.getName().setFirst( "Steve" );
- human.getName().setInitial( 'L' );
- human.getName().setLast( "Ebersole" );
+ human.setName( new Name( "Steve", 'L', "Ebersole" ) );
session.save( human );
Human friend = new Human();
- friend.setName( new Name() );
- friend.getName().setFirst( "John" );
- friend.getName().setInitial( 'Q' );
- friend.getName().setLast( "Doe" );
+ friend.setName( new Name( "John", 'Q', "Doe" ) );
friend.setBodyWeight( 11.0f );
session.save( friend );
Modified: trunk/Hibernate3/code/testsuite/src/test/java/org/hibernate/test/hql/BulkManipulationTest.java
===================================================================
--- trunk/Hibernate3/code/testsuite/src/test/java/org/hibernate/test/hql/BulkManipulationTest.java 2007-06-07 18:26:42 UTC (rev 11652)
+++ trunk/Hibernate3/code/testsuite/src/test/java/org/hibernate/test/hql/BulkManipulationTest.java 2007-06-07 22:48:18 UTC (rev 11653)
@@ -600,10 +600,7 @@
Transaction t = s.beginTransaction();
Human human = new Human();
- human.setName( new Name() );
- human.getName().setFirst("Stevee");
- human.getName().setInitial('X');
- human.getName().setLast("Ebersole");
+ human.setName( new Name( "Stevee", 'X', "Ebersole" ) );
s.save( human );
s.flush();
@@ -654,14 +651,10 @@
Transaction t = s.beginTransaction();
Human human = new Human();
- human.setName( new Name() );
- human.getName().setFirst( "Steve" );
- human.getName().setInitial('E');
+ human.setName( new Name( "Steve", 'E', null ) );
Human mother = new Human();
- mother.setName( new Name() );
- mother.getName().setFirst( "Jane" );
- mother.getName().setInitial('E');
+ mother.setName( new Name( "Jane", 'E', null ) );
human.setMother( mother );
s.save( human );
Modified: trunk/Hibernate3/code/testsuite/src/test/java/org/hibernate/test/hql/Name.java
===================================================================
--- trunk/Hibernate3/code/testsuite/src/test/java/org/hibernate/test/hql/Name.java 2007-06-07 18:26:42 UTC (rev 11652)
+++ trunk/Hibernate3/code/testsuite/src/test/java/org/hibernate/test/hql/Name.java 2007-06-07 22:48:18 UTC (rev 11653)
@@ -6,17 +6,21 @@
*/
public class Name {
private String first;
- private char initial;
+ private Character initial;
private String last;
protected Name() {}
- public Name(String first, char initial, String last) {
+ public Name(String first, Character initial, String last) {
this.first = first;
this.initial = initial;
this.last = last;
}
+ public Name(String first, char initial, String last) {
+ this( first, new Character( initial ), last );
+ }
+
public String getFirst() {
return first;
}
@@ -25,11 +29,11 @@
this.first = first;
}
- public char getInitial() {
+ public Character getInitial() {
return initial;
}
- public void setInitial(char initial) {
+ public void setInitial(Character initial) {
this.initial = initial;
}
Modified: trunk/Hibernate3/code/testsuite/src/test/java/org/hibernate/test/sql/hand/query/NativeSQLQueriesTest.java
===================================================================
--- trunk/Hibernate3/code/testsuite/src/test/java/org/hibernate/test/sql/hand/query/NativeSQLQueriesTest.java 2007-06-07 18:26:42 UTC (rev 11652)
+++ trunk/Hibernate3/code/testsuite/src/test/java/org/hibernate/test/sql/hand/query/NativeSQLQueriesTest.java 2007-06-07 22:48:18 UTC (rev 11653)
@@ -99,6 +99,7 @@
// throwing a sql exception because the SQL gets passed
// "un-processed"...
Session s = openSession();
+ s.beginTransaction();
try {
String sql = "select {org.*} " +
"from organization org";
@@ -109,6 +110,7 @@
// expected behavior
}
finally {
+ s.getTransaction().rollback();
s.close();
}
}
18 years, 10 months
Hibernate SVN: r11652 - in trunk/Hibernate3/code/core/src/main/java/org/hibernate: engine/loading and 1 other directories.
by hibernate-commits@lists.jboss.org
Author: steve.ebersole(a)jboss.com
Date: 2007-06-07 14:26:42 -0400 (Thu, 07 Jun 2007)
New Revision: 11652
Modified:
trunk/Hibernate3/code/core/src/main/java/org/hibernate/engine/StatefulPersistenceContext.java
trunk/Hibernate3/code/core/src/main/java/org/hibernate/engine/loading/CollectionLoadContext.java
trunk/Hibernate3/code/core/src/main/java/org/hibernate/engine/loading/EntityLoadContext.java
trunk/Hibernate3/code/core/src/main/java/org/hibernate/engine/loading/LoadContexts.java
trunk/Hibernate3/code/core/src/main/java/org/hibernate/impl/AbstractScrollableResults.java
trunk/Hibernate3/code/core/src/main/java/org/hibernate/impl/IteratorImpl.java
Log:
HHH-2631 : LoadContext cleanup
Modified: trunk/Hibernate3/code/core/src/main/java/org/hibernate/engine/StatefulPersistenceContext.java
===================================================================
--- trunk/Hibernate3/code/core/src/main/java/org/hibernate/engine/StatefulPersistenceContext.java 2007-06-07 18:22:50 UTC (rev 11651)
+++ trunk/Hibernate3/code/core/src/main/java/org/hibernate/engine/StatefulPersistenceContext.java 2007-06-07 18:26:42 UTC (rev 11652)
@@ -203,6 +203,9 @@
batchFetchQueue.clear();
}
hasNonReadOnlyEntities = false;
+ if ( loadContexts != null ) {
+ loadContexts.cleanup();
+ }
}
public boolean hasNonReadOnlyEntities() {
Modified: trunk/Hibernate3/code/core/src/main/java/org/hibernate/engine/loading/CollectionLoadContext.java
===================================================================
--- trunk/Hibernate3/code/core/src/main/java/org/hibernate/engine/loading/CollectionLoadContext.java 2007-06-07 18:22:50 UTC (rev 11651)
+++ trunk/Hibernate3/code/core/src/main/java/org/hibernate/engine/loading/CollectionLoadContext.java 2007-06-07 18:26:42 UTC (rev 11652)
@@ -2,7 +2,6 @@
import java.sql.ResultSet;
import java.io.Serializable;
-import java.util.Map;
import java.util.List;
import java.util.Iterator;
import java.util.ArrayList;
@@ -126,7 +125,7 @@
collection.beforeInitialize( persister, -1 );
collection.beginRead();
localLoadingCollectionKeys.add( collectionKey );
- loadContexts.registerLoadingCollectionEntry( collectionKey, new LoadingCollectionEntry( resultSet, persister, key, collection ) );
+ loadContexts.registerLoadingCollectionXRef( collectionKey, new LoadingCollectionEntry( resultSet, persister, key, collection ) );
return collection;
}
else {
@@ -152,8 +151,7 @@
*/
public void endLoadingCollections(CollectionPersister persister) {
SessionImplementor session = getLoadContext().getPersistenceContext().getSession();
- if ( loadContexts.getLoadingCollectionEntryMap() == null
- || loadContexts.getLoadingCollectionEntryMap().isEmpty()
+ if ( !loadContexts.hasLoadingCollectionEntries()
|| localLoadingCollectionKeys.isEmpty() ) {
return;
}
@@ -165,12 +163,14 @@
// in a temp collection. the temp collection is then used to "drive"
// the #endRead processing.
List matches = null;
- Iterator iter = loadContexts.getLoadingCollectionEntryMap().entrySet().iterator();
+ Iterator iter = localLoadingCollectionKeys.iterator();
while ( iter.hasNext() ) {
- final Map.Entry mapEntry = ( Map.Entry ) iter.next();
- final CollectionKey collectionKey = ( CollectionKey ) mapEntry.getKey();
- final LoadingCollectionEntry lce = ( LoadingCollectionEntry ) mapEntry.getValue();
- if ( localLoadingCollectionKeys.contains( collectionKey ) && lce.getResultSet() == resultSet && lce.getPersister() == persister) {
+ final CollectionKey collectionKey = (CollectionKey) iter.next();
+ final LoadingCollectionEntry lce = loadContexts.locateLoadingCollectionEntry( collectionKey );
+ if ( lce == null) {
+ log.warn( "In CollectionLoadContext#endLoadingCollections, localLoadingCollectionKeys contained [" + collectionKey + "], but no LoadingCollectionEntry was found in loadContexts" );
+ }
+ else if ( lce.getResultSet() == resultSet && lce.getPersister() == persister ) {
if ( matches == null ) {
matches = new ArrayList();
}
@@ -184,11 +184,23 @@
if ( log.isTraceEnabled() ) {
log.trace( "removing collection load entry [" + lce + "]" );
}
+
+ // todo : i'd much rather have this done from #endLoadingCollection(CollectionPersister,LoadingCollectionEntry)...
+ loadContexts.unregisterLoadingCollectionXRef( collectionKey );
iter.remove();
}
}
endLoadingCollections( persister, matches );
+ if ( localLoadingCollectionKeys.isEmpty() ) {
+ // todo : hack!!!
+ // NOTE : here we cleanup the load context when we have no more local
+ // LCE entries. This "works" for the time being because really
+ // only the collection load contexts are implemented. Long term,
+ // this cleanup should become part of the "close result set"
+ // processing from the (sandbox/jdbc) jdbc-container code.
+ loadContexts.cleanup( resultSet );
+ }
}
private void endLoadingCollections(CollectionPersister persister, List matchedCollectionEntries) {
@@ -309,9 +321,9 @@
void cleanup() {
if ( !localLoadingCollectionKeys.isEmpty() ) {
- log.warn( "On CollectionLoadContext#clear, loadingCollections contained [" + localLoadingCollectionKeys.size() + "] entries" );
+ log.warn( "On CollectionLoadContext#cleanup, localLoadingCollectionKeys contained [" + localLoadingCollectionKeys.size() + "] entries" );
}
- loadContexts.cleanupCollectionEntries( localLoadingCollectionKeys );
+ loadContexts.cleanupCollectionXRefs( localLoadingCollectionKeys );
localLoadingCollectionKeys.clear();
}
Modified: trunk/Hibernate3/code/core/src/main/java/org/hibernate/engine/loading/EntityLoadContext.java
===================================================================
--- trunk/Hibernate3/code/core/src/main/java/org/hibernate/engine/loading/EntityLoadContext.java 2007-06-07 18:22:50 UTC (rev 11651)
+++ trunk/Hibernate3/code/core/src/main/java/org/hibernate/engine/loading/EntityLoadContext.java 2007-06-07 18:26:42 UTC (rev 11652)
@@ -30,4 +30,10 @@
}
hydratingEntities.clear();
}
+
+
+ public String toString() {
+ return super.toString() + "<rs=" + resultSet + ">";
+ }
+
}
Modified: trunk/Hibernate3/code/core/src/main/java/org/hibernate/engine/loading/LoadContexts.java
===================================================================
--- trunk/Hibernate3/code/core/src/main/java/org/hibernate/engine/loading/LoadContexts.java 2007-06-07 18:22:50 UTC (rev 11651)
+++ trunk/Hibernate3/code/core/src/main/java/org/hibernate/engine/loading/LoadContexts.java 2007-06-07 18:26:42 UTC (rev 11652)
@@ -63,7 +63,80 @@
return persistenceContext;
}
+ private SessionImplementor getSession() {
+ return getPersistenceContext().getSession();
+ }
+
+ private EntityMode getEntityMode() {
+ return getSession().getEntityMode();
+ }
+
+
+ // cleanup code ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+
+ /**
+ * Release internal state associated with the given result set.
+ * <p/>
+ * This should be called when we are done with processing said result set,
+ * ideally as the result set is being closed.
+ *
+ * @param resultSet The result set for which it is ok to release
+ * associated resources.
+ */
+ public void cleanup(ResultSet resultSet) {
+ if ( collectionLoadContexts != null ) {
+ CollectionLoadContext collectionLoadContext = ( CollectionLoadContext ) collectionLoadContexts.remove( resultSet );
+ collectionLoadContext.cleanup();
+ }
+ if ( entityLoadContexts != null ) {
+ EntityLoadContext entityLoadContext = ( EntityLoadContext ) entityLoadContexts.remove( resultSet );
+ entityLoadContext.cleanup();
+ }
+ }
+
/**
+ * Release internal state associated with *all* result sets.
+ * <p/>
+ * This is intended as a "failsafe" process to make sure we get everything
+ * cleaned up and released.
+ */
+ public void cleanup() {
+ if ( collectionLoadContexts != null ) {
+ Iterator itr = collectionLoadContexts.values().iterator();
+ while ( itr.hasNext() ) {
+ CollectionLoadContext collectionLoadContext = ( CollectionLoadContext ) itr.next();
+ log.warn( "fail-safe cleanup (collections) : " + collectionLoadContext );
+ collectionLoadContext.cleanup();
+ }
+ collectionLoadContexts.clear();
+ }
+ if ( entityLoadContexts != null ) {
+ Iterator itr = entityLoadContexts.values().iterator();
+ while ( itr.hasNext() ) {
+ EntityLoadContext entityLoadContext = ( EntityLoadContext ) itr.next();
+ log.warn( "fail-safe cleanup (entities) : " + entityLoadContext );
+ entityLoadContext.cleanup();
+ }
+ entityLoadContexts.clear();
+ }
+ }
+
+
+ // Collection load contexts ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+
+ /**
+ * Do we currently have any internal entries corresponding to loading
+ * collections?
+ *
+ * @return True if we currently hold state pertaining to loading collections;
+ * false otherwise.
+ */
+ public boolean hasLoadingCollectionEntries() {
+ return ( xrefLoadingCollectionEntries != null && !xrefLoadingCollectionEntries.isEmpty() );
+ }
+
+
+ /**
* Get the {@link CollectionLoadContext} associated with the given
* {@link ResultSet}, creating one if needed.
*
@@ -113,7 +186,60 @@
}
}
+
+
+
+ // loading collection xrefs ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+
/**
+ * Register a loading collection xref.
+ * <p/>
+ * This xref map is used because sometimes a collection is in process of
+ * being loaded from one result set, but needs to be accessed from the
+ * context of another "nested" result set processing.
+ * <p/>
+ * Implementation note: package protected, as this is meant solely for use
+ * by {@link CollectionLoadContext} to be able to locate collections
+ * being loaded by other {@link CollectionLoadContext}s/{@link ResultSet}s.
+ *
+ * @param entryKey The xref collection key
+ * @param entry The corresponding loading collection entry
+ */
+ void registerLoadingCollectionXRef(CollectionKey entryKey, LoadingCollectionEntry entry) {
+ if ( xrefLoadingCollectionEntries == null ) {
+ xrefLoadingCollectionEntries = new HashMap();
+ }
+ xrefLoadingCollectionEntries.put( entryKey, entry );
+ }
+
+ /**
+ * The inverse of {@link #registerLoadingCollectionXRef}. Here, we are done
+ * processing the said collection entry, so we remove it from the
+ * load context.
+ * <p/>
+ * The idea here is that other loading collections can now reference said
+ * collection directly from the {@link PersistenceContext} because it
+ * has completed its load cycle.
+ * <p/>
+ * Implementation note: package protected, as this is meant solely for use
+ * by {@link CollectionLoadContext} to be able to locate collections
+ * being loaded by other {@link CollectionLoadContext}s/{@link ResultSet}s.
+ *
+ * @param key The key of the collection we are done processing.
+ */
+ void unregisterLoadingCollectionXRef(CollectionKey key) {
+ if ( !hasLoadingCollectionEntries() ) {
+ return;
+ }
+ xrefLoadingCollectionEntries.remove(key);
+ }
+
+ /*package*/Map getLoadingCollectionXRefs() {
+ return xrefLoadingCollectionEntries;
+ }
+
+
+ /**
* Locate the LoadingCollectionEntry within *any* of the tracked
* {@link CollectionLoadContext}s.
* <p/>
@@ -143,18 +269,7 @@
return rtn;
}
- /*package*/void registerLoadingCollectionEntry(CollectionKey entryKey, LoadingCollectionEntry entry) {
- if ( xrefLoadingCollectionEntries == null ) {
- xrefLoadingCollectionEntries = new HashMap();
- }
- xrefLoadingCollectionEntries.put( entryKey, entry );
- }
-
- /*package*/Map getLoadingCollectionEntryMap() {
- return xrefLoadingCollectionEntries;
- }
-
- /*package*/void cleanupCollectionEntries(Set entryKeys) {
+ /*package*/void cleanupCollectionXRefs(Set entryKeys) {
Iterator itr = entryKeys.iterator();
while ( itr.hasNext() ) {
final CollectionKey entryKey = ( CollectionKey ) itr.next();
@@ -162,6 +277,10 @@
}
}
+
+ // Entity load contexts ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ // * currently, not yet used...
+
public EntityLoadContext getEntityLoadContext(ResultSet resultSet) {
EntityLoadContext context = null;
if ( entityLoadContexts == null ) {
@@ -177,23 +296,4 @@
return context;
}
- public void cleanup(ResultSet resultSet) {
- if ( collectionLoadContexts != null ) {
- CollectionLoadContext collectionLoadContext = ( CollectionLoadContext ) collectionLoadContexts.remove( resultSet );
- collectionLoadContext.cleanup();
- }
- if ( entityLoadContexts != null ) {
- EntityLoadContext entityLoadContext = ( EntityLoadContext ) entityLoadContexts.remove( resultSet );
- entityLoadContext.cleanup();
- }
- }
-
- private SessionImplementor getSession() {
- return getPersistenceContext().getSession();
- }
-
- private EntityMode getEntityMode() {
- return getSession().getEntityMode();
- }
-
}
Modified: trunk/Hibernate3/code/core/src/main/java/org/hibernate/impl/AbstractScrollableResults.java
===================================================================
--- trunk/Hibernate3/code/core/src/main/java/org/hibernate/impl/AbstractScrollableResults.java 2007-06-07 18:22:50 UTC (rev 11651)
+++ trunk/Hibernate3/code/core/src/main/java/org/hibernate/impl/AbstractScrollableResults.java 2007-06-07 18:26:42 UTC (rev 11652)
@@ -13,6 +13,9 @@
import java.util.Locale;
import java.util.TimeZone;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
import org.hibernate.Hibernate;
import org.hibernate.HibernateException;
import org.hibernate.MappingException;
@@ -31,6 +34,8 @@
*/
public abstract class AbstractScrollableResults implements ScrollableResults {
+ private static final Log log = LogFactory.getLog( AbstractScrollableResults.class );
+
private final ResultSet resultSet;
private final PreparedStatement ps;
private final SessionImplementor session;
@@ -91,7 +96,7 @@
public final void close() throws HibernateException {
try {
// not absolutely necessary, but does help with aggressive release
- session.getBatcher().closeQueryStatement(ps, resultSet);
+ session.getBatcher().closeQueryStatement( ps, resultSet );
}
catch (SQLException sqle) {
throw JDBCExceptionHelper.convert(
@@ -100,6 +105,15 @@
"could not close results"
);
}
+ finally {
+ try {
+ session.getPersistenceContext().getLoadContexts().cleanup( resultSet );
+ }
+ catch( Throwable ignore ) {
+ // ignore this error for now
+ log.trace( "exception trying to cleanup load context : " + ignore.getMessage() );
+ }
+ }
}
public final Object[] get() throws HibernateException {
Modified: trunk/Hibernate3/code/core/src/main/java/org/hibernate/impl/IteratorImpl.java
===================================================================
--- trunk/Hibernate3/code/core/src/main/java/org/hibernate/impl/IteratorImpl.java 2007-06-07 18:22:50 UTC (rev 11651)
+++ trunk/Hibernate3/code/core/src/main/java/org/hibernate/impl/IteratorImpl.java 2007-06-07 18:26:42 UTC (rev 11652)
@@ -76,6 +76,15 @@
"Unable to close iterator"
);
}
+ finally {
+ try {
+ session.getPersistenceContext().getLoadContexts().cleanup( rs );
+ }
+ catch( Throwable ignore ) {
+ // ignore this error for now
+ log.trace( "exception trying to cleanup load context : " + ignore.getMessage() );
+ }
+ }
}
}
18 years, 10 months
Hibernate SVN: r11651 - in branches/Branch_3_2/Hibernate3/src/org/hibernate: engine/loading and 1 other directories.
by hibernate-commits@lists.jboss.org
Author: steve.ebersole(a)jboss.com
Date: 2007-06-07 14:22:50 -0400 (Thu, 07 Jun 2007)
New Revision: 11651
Modified:
branches/Branch_3_2/Hibernate3/src/org/hibernate/engine/StatefulPersistenceContext.java
branches/Branch_3_2/Hibernate3/src/org/hibernate/engine/loading/CollectionLoadContext.java
branches/Branch_3_2/Hibernate3/src/org/hibernate/engine/loading/EntityLoadContext.java
branches/Branch_3_2/Hibernate3/src/org/hibernate/engine/loading/LoadContexts.java
branches/Branch_3_2/Hibernate3/src/org/hibernate/impl/AbstractScrollableResults.java
branches/Branch_3_2/Hibernate3/src/org/hibernate/impl/IteratorImpl.java
Log:
HHH-2631 : LoadContext cleanup
Modified: branches/Branch_3_2/Hibernate3/src/org/hibernate/engine/StatefulPersistenceContext.java
===================================================================
--- branches/Branch_3_2/Hibernate3/src/org/hibernate/engine/StatefulPersistenceContext.java 2007-06-07 16:44:52 UTC (rev 11650)
+++ branches/Branch_3_2/Hibernate3/src/org/hibernate/engine/StatefulPersistenceContext.java 2007-06-07 18:22:50 UTC (rev 11651)
@@ -203,6 +203,9 @@
batchFetchQueue.clear();
}
hasNonReadOnlyEntities = false;
+ if ( loadContexts != null ) {
+ loadContexts.cleanup();
+ }
}
public boolean hasNonReadOnlyEntities() {
Modified: branches/Branch_3_2/Hibernate3/src/org/hibernate/engine/loading/CollectionLoadContext.java
===================================================================
--- branches/Branch_3_2/Hibernate3/src/org/hibernate/engine/loading/CollectionLoadContext.java 2007-06-07 16:44:52 UTC (rev 11650)
+++ branches/Branch_3_2/Hibernate3/src/org/hibernate/engine/loading/CollectionLoadContext.java 2007-06-07 18:22:50 UTC (rev 11651)
@@ -2,7 +2,6 @@
import java.sql.ResultSet;
import java.io.Serializable;
-import java.util.Map;
import java.util.List;
import java.util.Iterator;
import java.util.ArrayList;
@@ -127,7 +126,7 @@
collection.beforeInitialize( persister, -1 );
collection.beginRead();
localLoadingCollectionKeys.add( collectionKey );
- loadContexts.registerLoadingCollectionEntry( collectionKey, new LoadingCollectionEntry( resultSet, persister, key, collection ) );
+ loadContexts.registerLoadingCollectionXRef( collectionKey, new LoadingCollectionEntry( resultSet, persister, key, collection ) );
return collection;
}
else {
@@ -153,8 +152,7 @@
*/
public void endLoadingCollections(CollectionPersister persister) {
SessionImplementor session = getLoadContext().getPersistenceContext().getSession();
- if ( loadContexts.getLoadingCollectionEntryMap() == null
- || loadContexts.getLoadingCollectionEntryMap().isEmpty()
+ if ( !loadContexts.hasLoadingCollectionEntries()
|| localLoadingCollectionKeys.isEmpty() ) {
return;
}
@@ -166,12 +164,14 @@
// in a temp collection. the temp collection is then used to "drive"
// the #endRead processing.
List matches = null;
- Iterator iter = loadContexts.getLoadingCollectionEntryMap().entrySet().iterator();
+ Iterator iter = localLoadingCollectionKeys.iterator();
while ( iter.hasNext() ) {
- final Map.Entry mapEntry = ( Map.Entry ) iter.next();
- final CollectionKey collectionKey = ( CollectionKey ) mapEntry.getKey();
- final LoadingCollectionEntry lce = ( LoadingCollectionEntry ) mapEntry.getValue();
- if ( localLoadingCollectionKeys.contains( collectionKey ) && lce.getResultSet() == resultSet && lce.getPersister() == persister) {
+ final CollectionKey collectionKey = (CollectionKey) iter.next();
+ final LoadingCollectionEntry lce = loadContexts.locateLoadingCollectionEntry( collectionKey );
+ if ( lce == null) {
+ log.warn( "In CollectionLoadContext#endLoadingCollections, localLoadingCollectionKeys contained [" + collectionKey + "], but no LoadingCollectionEntry was found in loadContexts" );
+ }
+ else if ( lce.getResultSet() == resultSet && lce.getPersister() == persister ) {
if ( matches == null ) {
matches = new ArrayList();
}
@@ -185,11 +185,23 @@
if ( log.isTraceEnabled() ) {
log.trace( "removing collection load entry [" + lce + "]" );
}
+
+ // todo : i'd much rather have this done from #endLoadingCollection(CollectionPersister,LoadingCollectionEntry)...
+ loadContexts.unregisterLoadingCollectionXRef( collectionKey );
iter.remove();
}
}
endLoadingCollections( persister, matches );
+ if ( localLoadingCollectionKeys.isEmpty() ) {
+ // todo : hack!!!
+ // NOTE : here we cleanup the load context when we have no more local
+ // LCE entries. This "works" for the time being because really
+ // only the collection load contexts are implemented. Long term,
+ // this cleanup should become part of the "close result set"
+ // processing from the (sandbox/jdbc) jdbc-container code.
+ loadContexts.cleanup( resultSet );
+ }
}
private void endLoadingCollections(CollectionPersister persister, List matchedCollectionEntries) {
@@ -314,9 +326,9 @@
void cleanup() {
if ( !localLoadingCollectionKeys.isEmpty() ) {
- log.warn( "On CollectionLoadContext#clear, loadingCollections contained [" + localLoadingCollectionKeys.size() + "] entries" );
+ log.warn( "On CollectionLoadContext#cleanup, localLoadingCollectionKeys contained [" + localLoadingCollectionKeys.size() + "] entries" );
}
- loadContexts.cleanupCollectionEntries( localLoadingCollectionKeys );
+ loadContexts.cleanupCollectionXRefs( localLoadingCollectionKeys );
localLoadingCollectionKeys.clear();
}
Modified: branches/Branch_3_2/Hibernate3/src/org/hibernate/engine/loading/EntityLoadContext.java
===================================================================
--- branches/Branch_3_2/Hibernate3/src/org/hibernate/engine/loading/EntityLoadContext.java 2007-06-07 16:44:52 UTC (rev 11650)
+++ branches/Branch_3_2/Hibernate3/src/org/hibernate/engine/loading/EntityLoadContext.java 2007-06-07 18:22:50 UTC (rev 11651)
@@ -30,4 +30,10 @@
}
hydratingEntities.clear();
}
+
+
+ public String toString() {
+ return super.toString() + "<rs=" + resultSet + ">";
+ }
+
}
Modified: branches/Branch_3_2/Hibernate3/src/org/hibernate/engine/loading/LoadContexts.java
===================================================================
--- branches/Branch_3_2/Hibernate3/src/org/hibernate/engine/loading/LoadContexts.java 2007-06-07 16:44:52 UTC (rev 11650)
+++ branches/Branch_3_2/Hibernate3/src/org/hibernate/engine/loading/LoadContexts.java 2007-06-07 18:22:50 UTC (rev 11651)
@@ -63,7 +63,80 @@
return persistenceContext;
}
+ private SessionImplementor getSession() {
+ return getPersistenceContext().getSession();
+ }
+
+ private EntityMode getEntityMode() {
+ return getSession().getEntityMode();
+ }
+
+
+ // cleanup code ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+
+ /**
+ * Release internal state associated with the given result set.
+ * <p/>
+ * This should be called when we are done with processing said result set,
+ * ideally as the result set is being closed.
+ *
+ * @param resultSet The result set for which it is ok to release
+ * associated resources.
+ */
+ public void cleanup(ResultSet resultSet) {
+ if ( collectionLoadContexts != null ) {
+ CollectionLoadContext collectionLoadContext = ( CollectionLoadContext ) collectionLoadContexts.remove( resultSet );
+ collectionLoadContext.cleanup();
+ }
+ if ( entityLoadContexts != null ) {
+ EntityLoadContext entityLoadContext = ( EntityLoadContext ) entityLoadContexts.remove( resultSet );
+ entityLoadContext.cleanup();
+ }
+ }
+
/**
+ * Release internal state associated with *all* result sets.
+ * <p/>
+ * This is intended as a "failsafe" process to make sure we get everything
+ * cleaned up and released.
+ */
+ public void cleanup() {
+ if ( collectionLoadContexts != null ) {
+ Iterator itr = collectionLoadContexts.values().iterator();
+ while ( itr.hasNext() ) {
+ CollectionLoadContext collectionLoadContext = ( CollectionLoadContext ) itr.next();
+ log.warn( "fail-safe cleanup (collections) : " + collectionLoadContext );
+ collectionLoadContext.cleanup();
+ }
+ collectionLoadContexts.clear();
+ }
+ if ( entityLoadContexts != null ) {
+ Iterator itr = entityLoadContexts.values().iterator();
+ while ( itr.hasNext() ) {
+ EntityLoadContext entityLoadContext = ( EntityLoadContext ) itr.next();
+ log.warn( "fail-safe cleanup (entities) : " + entityLoadContext );
+ entityLoadContext.cleanup();
+ }
+ entityLoadContexts.clear();
+ }
+ }
+
+
+ // Collection load contexts ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+
+ /**
+ * Do we currently have any internal entries corresponding to loading
+ * collections?
+ *
+ * @return True if we currently hold state pertaining to loading collections;
+ * false otherwise.
+ */
+ public boolean hasLoadingCollectionEntries() {
+ return ( xrefLoadingCollectionEntries != null && !xrefLoadingCollectionEntries.isEmpty() );
+ }
+
+
+ /**
* Get the {@link CollectionLoadContext} associated with the given
* {@link ResultSet}, creating one if needed.
*
@@ -113,7 +186,60 @@
}
}
+
+
+
+ // loading collection xrefs ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+
/**
+ * Register a loading collection xref.
+ * <p/>
+ * This xref map is used because sometimes a collection is in process of
+ * being loaded from one result set, but needs to be accessed from the
+ * context of another "nested" result set processing.
+ * <p/>
+ * Implementation note: package protected, as this is meant solely for use
+ * by {@link CollectionLoadContext} to be able to locate collections
+ * being loaded by other {@link CollectionLoadContext}s/{@link ResultSet}s.
+ *
+ * @param entryKey The xref collection key
+ * @param entry The corresponding loading collection entry
+ */
+ void registerLoadingCollectionXRef(CollectionKey entryKey, LoadingCollectionEntry entry) {
+ if ( xrefLoadingCollectionEntries == null ) {
+ xrefLoadingCollectionEntries = new HashMap();
+ }
+ xrefLoadingCollectionEntries.put( entryKey, entry );
+ }
+
+ /**
+ * The inverse of {@link #registerLoadingCollectionXRef}. Here, we are done
+ * processing the said collection entry, so we remove it from the
+ * load context.
+ * <p/>
+ * The idea here is that other loading collections can now reference said
+ * collection directly from the {@link PersistenceContext} because it
+ * has completed its load cycle.
+ * <p/>
+ * Implementation note: package protected, as this is meant solely for use
+ * by {@link CollectionLoadContext} to be able to locate collections
+ * being loaded by other {@link CollectionLoadContext}s/{@link ResultSet}s.
+ *
+ * @param key The key of the collection we are done processing.
+ */
+ void unregisterLoadingCollectionXRef(CollectionKey key) {
+ if ( !hasLoadingCollectionEntries() ) {
+ return;
+ }
+ xrefLoadingCollectionEntries.remove(key);
+ }
+
+ /*package*/Map getLoadingCollectionXRefs() {
+ return xrefLoadingCollectionEntries;
+ }
+
+
+ /**
* Locate the LoadingCollectionEntry within *any* of the tracked
* {@link CollectionLoadContext}s.
* <p/>
@@ -143,18 +269,7 @@
return rtn;
}
- /*package*/void registerLoadingCollectionEntry(CollectionKey entryKey, LoadingCollectionEntry entry) {
- if ( xrefLoadingCollectionEntries == null ) {
- xrefLoadingCollectionEntries = new HashMap();
- }
- xrefLoadingCollectionEntries.put( entryKey, entry );
- }
-
- /*package*/Map getLoadingCollectionEntryMap() {
- return xrefLoadingCollectionEntries;
- }
-
- /*package*/void cleanupCollectionEntries(Set entryKeys) {
+ /*package*/void cleanupCollectionXRefs(Set entryKeys) {
Iterator itr = entryKeys.iterator();
while ( itr.hasNext() ) {
final CollectionKey entryKey = ( CollectionKey ) itr.next();
@@ -162,6 +277,10 @@
}
}
+
+ // Entity load contexts ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ // * currently, not yet used...
+
public EntityLoadContext getEntityLoadContext(ResultSet resultSet) {
EntityLoadContext context = null;
if ( entityLoadContexts == null ) {
@@ -177,23 +296,4 @@
return context;
}
- public void cleanup(ResultSet resultSet) {
- if ( collectionLoadContexts != null ) {
- CollectionLoadContext collectionLoadContext = ( CollectionLoadContext ) collectionLoadContexts.remove( resultSet );
- collectionLoadContext.cleanup();
- }
- if ( entityLoadContexts != null ) {
- EntityLoadContext entityLoadContext = ( EntityLoadContext ) entityLoadContexts.remove( resultSet );
- entityLoadContext.cleanup();
- }
- }
-
- private SessionImplementor getSession() {
- return getPersistenceContext().getSession();
- }
-
- private EntityMode getEntityMode() {
- return getSession().getEntityMode();
- }
-
}
Modified: branches/Branch_3_2/Hibernate3/src/org/hibernate/impl/AbstractScrollableResults.java
===================================================================
--- branches/Branch_3_2/Hibernate3/src/org/hibernate/impl/AbstractScrollableResults.java 2007-06-07 16:44:52 UTC (rev 11650)
+++ branches/Branch_3_2/Hibernate3/src/org/hibernate/impl/AbstractScrollableResults.java 2007-06-07 18:22:50 UTC (rev 11651)
@@ -13,6 +13,9 @@
import java.util.Locale;
import java.util.TimeZone;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
import org.hibernate.Hibernate;
import org.hibernate.HibernateException;
import org.hibernate.MappingException;
@@ -31,6 +34,8 @@
*/
public abstract class AbstractScrollableResults implements ScrollableResults {
+ private static final Log log = LogFactory.getLog( AbstractScrollableResults.class );
+
private final ResultSet resultSet;
private final PreparedStatement ps;
private final SessionImplementor session;
@@ -91,7 +96,7 @@
public final void close() throws HibernateException {
try {
// not absolutely necessary, but does help with aggressive release
- session.getBatcher().closeQueryStatement(ps, resultSet);
+ session.getBatcher().closeQueryStatement( ps, resultSet );
}
catch (SQLException sqle) {
throw JDBCExceptionHelper.convert(
@@ -100,6 +105,15 @@
"could not close results"
);
}
+ finally {
+ try {
+ session.getPersistenceContext().getLoadContexts().cleanup( resultSet );
+ }
+ catch( Throwable ignore ) {
+ // ignore this error for now
+ log.trace( "exception trying to cleanup load context : " + ignore.getMessage() );
+ }
+ }
}
public final Object[] get() throws HibernateException {
Modified: branches/Branch_3_2/Hibernate3/src/org/hibernate/impl/IteratorImpl.java
===================================================================
--- branches/Branch_3_2/Hibernate3/src/org/hibernate/impl/IteratorImpl.java 2007-06-07 16:44:52 UTC (rev 11650)
+++ branches/Branch_3_2/Hibernate3/src/org/hibernate/impl/IteratorImpl.java 2007-06-07 18:22:50 UTC (rev 11651)
@@ -76,6 +76,15 @@
"Unable to close iterator"
);
}
+ finally {
+ try {
+ session.getPersistenceContext().getLoadContexts().cleanup( rs );
+ }
+ catch( Throwable ignore ) {
+ // ignore this error for now
+ log.trace( "exception trying to cleanup load context : " + ignore.getMessage() );
+ }
+ }
}
}
18 years, 10 months
Hibernate SVN: r11650 - in trunk/HibernateExt/annotations/src: test/org/hibernate/test/annotations/cid and 1 other directory.
by hibernate-commits@lists.jboss.org
Author: epbernard
Date: 2007-06-07 12:44:52 -0400 (Thu, 07 Jun 2007)
New Revision: 11650
Added:
trunk/HibernateExt/annotations/src/java/org/hibernate/cfg/FkSecondPass.java
trunk/HibernateExt/annotations/src/java/org/hibernate/cfg/JoinedSubclassFkSecondPass.java
trunk/HibernateExt/annotations/src/java/org/hibernate/cfg/ToOneFkSecondPass.java
Removed:
trunk/HibernateExt/annotations/src/java/org/hibernate/cfg/FkSecondPass.java
Modified:
trunk/HibernateExt/annotations/src/java/org/hibernate/cfg/AnnotationBinder.java
trunk/HibernateExt/annotations/src/java/org/hibernate/cfg/AnnotationConfiguration.java
trunk/HibernateExt/annotations/src/java/org/hibernate/cfg/OneToOneSecondPass.java
trunk/HibernateExt/annotations/src/test/org/hibernate/test/annotations/cid/CompositeIdTest.java
Log:
ANN-621 handle JoinedSubclass FK/PK in a second pass
Modified: trunk/HibernateExt/annotations/src/java/org/hibernate/cfg/AnnotationBinder.java
===================================================================
--- trunk/HibernateExt/annotations/src/java/org/hibernate/cfg/AnnotationBinder.java 2007-06-07 14:34:51 UTC (rev 11649)
+++ trunk/HibernateExt/annotations/src/java/org/hibernate/cfg/AnnotationBinder.java 2007-06-07 16:44:52 UTC (rev 11650)
@@ -601,8 +601,9 @@
else {
key.setCascadeDeleteEnabled( false );
}
- TableBinder.bindFk( jsc.getSuperclass(), jsc, inheritanceJoinedColumns, key, false, mappings );
- //no need to handle inSecondPass this is an Etntiy related work
+ //we are never in a second pass at that stage, so queue it
+ SecondPass sp = new JoinedSubclassFkSecondPass(jsc, inheritanceJoinedColumns, key, mappings);
+ mappings.addSecondPass( sp );
mappings.addSecondPass( new CreateKeySecondPass( jsc ) );
}
@@ -1858,7 +1859,7 @@
if ( !BinderHelper.isDefault( fkName ) ) value.setForeignKeyName( fkName );
String path = propertyHolder.getPath() + "." + propertyName;
- FkSecondPass secondPass = new FkSecondPass(
+ FkSecondPass secondPass = new ToOneFkSecondPass(
value, columns,
!optional && unique, //cannot have nullabe and unique on certain DBs like Derby
propertyHolder.getEntityOwnerClassName(),
Modified: trunk/HibernateExt/annotations/src/java/org/hibernate/cfg/AnnotationConfiguration.java
===================================================================
--- trunk/HibernateExt/annotations/src/java/org/hibernate/cfg/AnnotationConfiguration.java 2007-06-07 14:34:51 UTC (rev 11649)
+++ trunk/HibernateExt/annotations/src/java/org/hibernate/cfg/AnnotationConfiguration.java 2007-06-07 16:44:52 UTC (rev 11650)
@@ -302,17 +302,6 @@
iter.remove();
}
}
-
- //process OneToManySecondPass in order: first
- iter = secondPasses.iterator();
- while ( iter.hasNext() ) {
- SecondPass sp = (SecondPass) iter.next();
-
- if ( sp instanceof CreateKeySecondPass ) {
- sp.doSecondPass( classes );
- iter.remove();
- }
- }
super.secondPassCompile();
inSecondPass = false;
Iterator tables = (Iterator<Map.Entry<Table, List<String[]>>>) tableUniqueConstraints.entrySet().iterator();
@@ -372,21 +361,16 @@
}
private void processFkSecondPassInOrder() {
- log.debug( "processing manytoone fk mappings" );
+ log.debug( "processing fk mappings (*ToOne and JoinedSubclass)" );
Iterator iter = secondPasses.iterator();
/* We need to process FKSecond pass trying to resolve any
* graph circularity (ie PK made of a many to one linking to
* an entity having a PK made of a ManyToOne ...
*/
SortedSet<FkSecondPass> fkSecondPasses = new TreeSet<FkSecondPass>(
- new Comparator() {
+ new Comparator<FkSecondPass>() {
//The comparator implementation has to respect the compare=0 => equals() = true for sets
- public int compare(Object o1, Object o2) {
- if (! (o1 instanceof FkSecondPass && o2 instanceof FkSecondPass) ) {
- throw new AssertionFailure("comparint FkSecondPass with non FkSecondPass");
- }
- FkSecondPass f1 = (FkSecondPass) o1;
- FkSecondPass f2 = (FkSecondPass) o2;
+ public int compare(FkSecondPass f1, FkSecondPass f2) {
int compare = f1.getValue().getTable().getQuotedName().compareTo(
f2.getValue().getTable().getQuotedName()
);
@@ -422,7 +406,7 @@
Iterator it = fkSecondPasses.iterator();
while ( it.hasNext() ) {
FkSecondPass sp = (FkSecondPass) it.next();
- String referenceEntityName = sp.getValue().getReferencedEntityName();
+ String referenceEntityName = sp.getReferencedEntityName();
PersistentClass classMapping = getClassMapping( referenceEntityName );
if ( sp.isInPrimaryKey() ) {
String dependentTable = classMapping.getTable().getQuotedName();
Deleted: trunk/HibernateExt/annotations/src/java/org/hibernate/cfg/FkSecondPass.java
===================================================================
--- trunk/HibernateExt/annotations/src/java/org/hibernate/cfg/FkSecondPass.java 2007-06-07 14:34:51 UTC (rev 11649)
+++ trunk/HibernateExt/annotations/src/java/org/hibernate/cfg/FkSecondPass.java 2007-06-07 16:44:52 UTC (rev 11650)
@@ -1,77 +0,0 @@
-// $Id$
-package org.hibernate.cfg;
-
-import org.hibernate.AnnotationException;
-import org.hibernate.AssertionFailure;
-import org.hibernate.MappingException;
-import org.hibernate.util.StringHelper;
-import org.hibernate.cfg.annotations.TableBinder;
-import org.hibernate.mapping.ManyToOne;
-import org.hibernate.mapping.OneToOne;
-import org.hibernate.mapping.PersistentClass;
-import org.hibernate.mapping.ToOne;
-import org.hibernate.mapping.Property;
-
-/**
- * Enable a proper set of the FK columns in respect with the id column order
- * Allow the correct implementation of the default EJB3 values which needs both
- * sides of the association to be resolved
- *
- * @author Emmanuel Bernard
- */
-public class FkSecondPass implements SecondPass {
- private ToOne value;
- private Ejb3JoinColumn[] columns;
- private boolean unique;
- private ExtendedMappings mappings;
- private String path;
- private String entityClassName;
-
- FkSecondPass(
- ToOne value, Ejb3JoinColumn[] columns, boolean unique, String entityClassName, String path, ExtendedMappings mappings
- ) {
- this.mappings = mappings;
- this.value = value;
- this.columns = columns;
- this.unique = unique;
- this.entityClassName = entityClassName;
- this.path = entityClassName != null ? path.substring( entityClassName.length() + 1 ) : path;
- }
-
- public ToOne getValue() {
- return value;
- }
-
- public boolean isInPrimaryKey() {
- if (entityClassName == null) return false;
- Property property = mappings.getClass( entityClassName ).getIdentifierProperty();
- return property != null && path != null && path.startsWith( property.getName() );
- }
-
- public void doSecondPass(java.util.Map persistentClasses) throws MappingException {
- if ( value instanceof ManyToOne ) {
- ManyToOne manyToOne = (ManyToOne) value;
- PersistentClass ref = (PersistentClass) persistentClasses.get( manyToOne.getReferencedEntityName() );
- if ( ref == null ) {
- throw new AnnotationException(
- "@OneToOne or @ManyToOne on "
- + StringHelper.qualify(entityClassName, path)
- + " references an unknown entity: "
- + manyToOne.getReferencedEntityName()
- );
- }
- BinderHelper.createSyntheticPropertyReference( columns, ref, null, manyToOne, false, mappings );
- TableBinder.bindFk( ref, null, columns, manyToOne, unique, mappings );
- /*
- * HbmBinder does this only when property-ref != null, but IMO, it makes sense event if it is null
- */
- if ( ! manyToOne.isIgnoreNotFound() ) manyToOne.createPropertyRefConstraints( persistentClasses );
- }
- else if ( value instanceof OneToOne ) {
- ( (OneToOne) value ).createForeignKey();
- }
- else {
- throw new AssertionFailure( "FkSecondPass for a wrong value type: " + value.getClass().getName() );
- }
- }
-}
Added: trunk/HibernateExt/annotations/src/java/org/hibernate/cfg/FkSecondPass.java
===================================================================
--- trunk/HibernateExt/annotations/src/java/org/hibernate/cfg/FkSecondPass.java (rev 0)
+++ trunk/HibernateExt/annotations/src/java/org/hibernate/cfg/FkSecondPass.java 2007-06-07 16:44:52 UTC (rev 11650)
@@ -0,0 +1,27 @@
+//$Id$
+package org.hibernate.cfg;
+
+import org.hibernate.mapping.Value;
+import org.hibernate.mapping.ToOne;
+import org.hibernate.mapping.SimpleValue;
+
+/**
+ * @author Emmanuel Bernard
+ */
+public abstract class FkSecondPass implements SecondPass {
+ protected SimpleValue value;
+ protected Ejb3JoinColumn[] columns;
+
+ public FkSecondPass(SimpleValue value, Ejb3JoinColumn[] columns) {
+ this.value = value;
+ this.columns = columns;
+ }
+
+ public Value getValue() {
+ return value;
+ }
+
+ public abstract String getReferencedEntityName();
+
+ public abstract boolean isInPrimaryKey();
+}
Added: trunk/HibernateExt/annotations/src/java/org/hibernate/cfg/JoinedSubclassFkSecondPass.java
===================================================================
--- trunk/HibernateExt/annotations/src/java/org/hibernate/cfg/JoinedSubclassFkSecondPass.java (rev 0)
+++ trunk/HibernateExt/annotations/src/java/org/hibernate/cfg/JoinedSubclassFkSecondPass.java 2007-06-07 16:44:52 UTC (rev 11650)
@@ -0,0 +1,37 @@
+//$Id$
+package org.hibernate.cfg;
+
+import java.util.Map;
+
+import org.hibernate.MappingException;
+import org.hibernate.cfg.annotations.TableBinder;
+import org.hibernate.mapping.Value;
+import org.hibernate.mapping.PersistentClass;
+import org.hibernate.mapping.JoinedSubclass;
+import org.hibernate.mapping.SimpleValue;
+
+/**
+ * @author Emmanuel Bernard
+ */
+public class JoinedSubclassFkSecondPass extends FkSecondPass {
+ private JoinedSubclass entity;
+ private ExtendedMappings mappings;
+
+ public JoinedSubclassFkSecondPass(JoinedSubclass entity, Ejb3JoinColumn[] inheritanceJoinedColumns, SimpleValue key, ExtendedMappings mappings) {
+ super(key, inheritanceJoinedColumns);
+ this.entity = entity;
+ this.mappings = mappings;
+ }
+
+ public String getReferencedEntityName() {
+ return entity.getSuperclass().getEntityName();
+ }
+
+ public boolean isInPrimaryKey() {
+ return true;
+ }
+
+ public void doSecondPass(Map persistentClasses) throws MappingException {
+ TableBinder.bindFk( entity.getSuperclass(), entity, columns, value, false, mappings );
+ }
+}
Modified: trunk/HibernateExt/annotations/src/java/org/hibernate/cfg/OneToOneSecondPass.java
===================================================================
--- trunk/HibernateExt/annotations/src/java/org/hibernate/cfg/OneToOneSecondPass.java 2007-06-07 14:34:51 UTC (rev 11649)
+++ trunk/HibernateExt/annotations/src/java/org/hibernate/cfg/OneToOneSecondPass.java 2007-06-07 16:44:52 UTC (rev 11650)
@@ -102,7 +102,7 @@
if (rightOrder) {
String path = StringHelper.qualify( propertyHolder.getPath(), propertyName );
- ( new FkSecondPass(
+ ( new ToOneFkSecondPass(
value, joinColumns,
!optional, //cannot have nullabe and unique on certain DBs
propertyHolder.getEntityOwnerClassName(),
Copied: trunk/HibernateExt/annotations/src/java/org/hibernate/cfg/ToOneFkSecondPass.java (from rev 11648, trunk/HibernateExt/annotations/src/java/org/hibernate/cfg/FkSecondPass.java)
===================================================================
--- trunk/HibernateExt/annotations/src/java/org/hibernate/cfg/ToOneFkSecondPass.java (rev 0)
+++ trunk/HibernateExt/annotations/src/java/org/hibernate/cfg/ToOneFkSecondPass.java 2007-06-07 16:44:52 UTC (rev 11650)
@@ -0,0 +1,75 @@
+// $Id$
+package org.hibernate.cfg;
+
+import org.hibernate.AnnotationException;
+import org.hibernate.AssertionFailure;
+import org.hibernate.MappingException;
+import org.hibernate.util.StringHelper;
+import org.hibernate.cfg.annotations.TableBinder;
+import org.hibernate.mapping.ManyToOne;
+import org.hibernate.mapping.OneToOne;
+import org.hibernate.mapping.PersistentClass;
+import org.hibernate.mapping.ToOne;
+import org.hibernate.mapping.Property;
+import org.hibernate.mapping.Value;
+
+/**
+ * Enable a proper set of the FK columns in respect with the id column order
+ * Allow the correct implementation of the default EJB3 values which needs both
+ * sides of the association to be resolved
+ *
+ * @author Emmanuel Bernard
+ */
+public class ToOneFkSecondPass extends FkSecondPass {
+ private boolean unique;
+ private ExtendedMappings mappings;
+ private String path;
+ private String entityClassName;
+
+ ToOneFkSecondPass(
+ ToOne value, Ejb3JoinColumn[] columns, boolean unique, String entityClassName, String path, ExtendedMappings mappings
+ ) {
+ super( value, columns );
+ this.mappings = mappings;
+ this.unique = unique;
+ this.entityClassName = entityClassName;
+ this.path = entityClassName != null ? path.substring( entityClassName.length() + 1 ) : path;
+ }
+
+ public String getReferencedEntityName() {
+ return ((ToOne) value).getReferencedEntityName();
+ }
+
+ public boolean isInPrimaryKey() {
+ if (entityClassName == null) return false;
+ Property property = mappings.getClass( entityClassName ).getIdentifierProperty();
+ return property != null && path != null && path.startsWith( property.getName() );
+ }
+
+ public void doSecondPass(java.util.Map persistentClasses) throws MappingException {
+ if ( value instanceof ManyToOne ) {
+ ManyToOne manyToOne = (ManyToOne) value;
+ PersistentClass ref = (PersistentClass) persistentClasses.get( manyToOne.getReferencedEntityName() );
+ if ( ref == null ) {
+ throw new AnnotationException(
+ "@OneToOne or @ManyToOne on "
+ + StringHelper.qualify(entityClassName, path)
+ + " references an unknown entity: "
+ + manyToOne.getReferencedEntityName()
+ );
+ }
+ BinderHelper.createSyntheticPropertyReference( columns, ref, null, manyToOne, false, mappings );
+ TableBinder.bindFk( ref, null, columns, manyToOne, unique, mappings );
+ /*
+ * HbmBinder does this only when property-ref != null, but IMO, it makes sense event if it is null
+ */
+ if ( ! manyToOne.isIgnoreNotFound() ) manyToOne.createPropertyRefConstraints( persistentClasses );
+ }
+ else if ( value instanceof OneToOne ) {
+ ( (OneToOne) value ).createForeignKey();
+ }
+ else {
+ throw new AssertionFailure( "FkSecondPass for a wrong value type: " + value.getClass().getName() );
+ }
+ }
+}
Property changes on: trunk/HibernateExt/annotations/src/java/org/hibernate/cfg/ToOneFkSecondPass.java
___________________________________________________________________
Name: svn:keywords
+ Author Date Id Revision
Name: svn:eol-style
+ native
Modified: trunk/HibernateExt/annotations/src/test/org/hibernate/test/annotations/cid/CompositeIdTest.java
===================================================================
--- trunk/HibernateExt/annotations/src/test/org/hibernate/test/annotations/cid/CompositeIdTest.java 2007-06-07 14:34:51 UTC (rev 11649)
+++ trunk/HibernateExt/annotations/src/test/org/hibernate/test/annotations/cid/CompositeIdTest.java 2007-06-07 16:44:52 UTC (rev 11650)
@@ -8,10 +8,6 @@
import org.hibernate.Session;
import org.hibernate.Transaction;
import org.hibernate.test.annotations.TestCase;
-import org.hibernate.test.annotations.cid.OrderLine;
-import org.hibernate.test.annotations.cid.Order;
-import org.hibernate.test.annotations.cid.Product;
-import org.hibernate.test.annotations.cid.OrderLinePk;
/**
* test some composite id functionalities
@@ -24,45 +20,47 @@
}
/**
- * This feature is not supported by the EJB3
- * this is an hibernate extension
- */
- public void testManyToOneInCompositePk() throws Exception {
- Session s;
- Transaction tx;
- s = openSession();
- tx = s.beginTransaction();
- ParentPk ppk = new ParentPk();
- ppk.setFirstName( "Emmanuel" );
- ppk.setLastName( "Bernard" );
- Parent p = new Parent();
- p.id = ppk;
- s.persist( p );
- ChildPk cpk = new ChildPk();
- cpk.parent = p;
- cpk.nthChild = 1;
- Child c = new Child();
- c.id = cpk;
- s.persist( c );
- tx.commit();
- s.close();
-
- s = openSession();
- tx = s.beginTransaction();
- Query q = s.createQuery( "select c from Child c where c.id.nthChild = :nth" );
- q.setInteger( "nth", 1 );
- List results = q.list();
- assertEquals( 1, results.size() );
- c = (Child) results.get( 0 );
- assertNotNull( c );
- assertNotNull( c.id.parent );
- //FIXME mke it work in unambigious cases
- // assertNotNull(c.id.parent.id);
- // assertEquals(p.id.getFirstName(), c.id.parent.id.getFirstName());
- tx.commit();
- s.close();
- }
+ * This feature is not supported by the EJB3
+ * this is an hibernate extension
+ */
+ public void testManyToOneInCompositePk() throws Exception {
+ Session s;
+ Transaction tx;
+ s = openSession();
+ tx = s.beginTransaction();
+ ParentPk ppk = new ParentPk();
+ ppk.setFirstName( "Emmanuel" );
+ ppk.setLastName( "Bernard" );
+ Parent p = new Parent();
+ p.id = ppk;
+ s.persist( p );
+ ChildPk cpk = new ChildPk();
+ cpk.parent = p;
+ cpk.nthChild = 1;
+ Child c = new Child();
+ c.id = cpk;
+ s.persist( c );
+ tx.commit();
+ s.close();
+ s = openSession();
+ tx = s.beginTransaction();
+ Query q = s.createQuery( "select c from Child c where c.id.nthChild = :nth" );
+ q.setInteger( "nth", 1 );
+ List results = q.list();
+ assertEquals( 1, results.size() );
+ c = (Child) results.get( 0 );
+ assertNotNull( c );
+ assertNotNull( c.id.parent );
+ //FIXME mke it work in unambigious cases
+ // assertNotNull(c.id.parent.id);
+ // assertEquals(p.id.getFirstName(), c.id.parent.id.getFirstName());
+ s.delete( c );
+ s.delete( c.id.parent );
+ tx.commit();
+ s.close();
+ }
+
/**
* This feature is not supported by the EJB3
* this is an hibernate extension
@@ -100,6 +98,8 @@
//FIXME mke it work in unambigious cases
// assertNotNull(c.id.parent.id);
// assertEquals(p.id.getFirstName(), c.id.parent.id.getFirstName());
+ s.delete( c );
+ s.delete( c.id.parent );
tx.commit();
s.close();
}
@@ -150,7 +150,7 @@
OrderLine orderLine = new OrderLine();
orderLine.order = order;
orderLine.product = product;
- s.persist(orderLine);
+ s.persist( orderLine );
s.flush();
s.clear();
@@ -159,23 +159,23 @@
assertEquals( order.id, orderLine.order.id );
assertNotNull( orderLine.product );
assertEquals( product.name, orderLine.product.name );
-
+
tx.rollback();
s.close();
}
protected Class[] getMappings() {
- return new Class[]{
+ return new Class[] {
Parent.class,
Child.class,
Channel.class,
TvMagazin.class,
Presenter.class,
- Order.class,
- Product.class,
- OrderLine.class,
- OrderLinePk.class,
- LittleGenius.class
- };
+ Order.class,
+ Product.class,
+ OrderLine.class,
+ OrderLinePk.class,
+ LittleGenius.class
+ };
}
}
18 years, 10 months
Hibernate SVN: r11649 - in trunk/HibernateExt/commons-annotations/src: test/org/hibernate/annotations/common/test/reflection/java and 2 other directories.
by hibernate-commits@lists.jboss.org
Author: nusco
Date: 2007-06-07 10:34:51 -0400 (Thu, 07 Jun 2007)
New Revision: 11649
Added:
trunk/HibernateExt/commons-annotations/src/test/org/hibernate/annotations/common/test/reflection/java/generics/deep/ANN612IssueTest.java
Modified:
trunk/HibernateExt/commons-annotations/src/java/org/hibernate/annotations/common/reflection/java/generics/TypeUtils.java
trunk/HibernateExt/commons-annotations/src/test/org/hibernate/annotations/common/test/reflection/java/JavaXClassTest.java
trunk/HibernateExt/commons-annotations/src/test/org/hibernate/annotations/common/test/reflection/java/JavaXPropertyTest.java
trunk/HibernateExt/commons-annotations/src/test/org/hibernate/annotations/common/test/reflection/java/generics/Dad.java
trunk/HibernateExt/commons-annotations/src/test/org/hibernate/annotations/common/test/reflection/java/generics/TypeUtilsTest.java
Log:
ANN-612
Modified: trunk/HibernateExt/commons-annotations/src/java/org/hibernate/annotations/common/reflection/java/generics/TypeUtils.java
===================================================================
--- trunk/HibernateExt/commons-annotations/src/java/org/hibernate/annotations/common/reflection/java/generics/TypeUtils.java 2007-06-06 21:37:42 UTC (rev 11648)
+++ trunk/HibernateExt/commons-annotations/src/java/org/hibernate/annotations/common/reflection/java/generics/TypeUtils.java 2007-06-07 14:34:51 UTC (rev 11649)
@@ -97,18 +97,12 @@
return new TypeSwitch<Boolean>() {
@Override
public Boolean caseClass(Class clazz) {
- return !clazz.isArray() && !isCollectionClass( clazz );// hum probably not fully accurate
- //return classType != void.class;
+ return !clazz.isArray() && !isCollectionClass( clazz ); // probably not fully accurate
}
@Override
public Boolean caseParameterizedType(ParameterizedType parameterizedType) {
- for ( Type actualTypeArgument : parameterizedType.getActualTypeArguments() ) {
- if ( !isSimple( actualTypeArgument ) ) {
- return false;
- }
- }
- return true;
+ return isSimple( parameterizedType.getRawType() );
}
@Override
Modified: trunk/HibernateExt/commons-annotations/src/test/org/hibernate/annotations/common/test/reflection/java/JavaXClassTest.java
===================================================================
--- trunk/HibernateExt/commons-annotations/src/test/org/hibernate/annotations/common/test/reflection/java/JavaXClassTest.java 2007-06-06 21:37:42 UTC (rev 11648)
+++ trunk/HibernateExt/commons-annotations/src/test/org/hibernate/annotations/common/test/reflection/java/JavaXClassTest.java 2007-06-07 14:34:51 UTC (rev 11649)
@@ -64,7 +64,7 @@
public void testExtractsPublicMethodsAsProperties() {
List<XProperty> methodProperties = fatherAsSeenFromSon.getDeclaredProperties( "property" );
- assertEquals( 7, methodProperties.size() );
+ assertEquals( 9, methodProperties.size() );
}
public void testCanBeAbstract() {
Modified: trunk/HibernateExt/commons-annotations/src/test/org/hibernate/annotations/common/test/reflection/java/JavaXPropertyTest.java
===================================================================
--- trunk/HibernateExt/commons-annotations/src/test/org/hibernate/annotations/common/test/reflection/java/JavaXPropertyTest.java 2007-06-06 21:37:42 UTC (rev 11648)
+++ trunk/HibernateExt/commons-annotations/src/test/org/hibernate/annotations/common/test/reflection/java/JavaXPropertyTest.java 2007-06-07 14:34:51 UTC (rev 11649)
@@ -1,5 +1,7 @@
package org.hibernate.annotations.common.test.reflection.java;
+import java.util.Arrays;
+import java.util.Collections;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
@@ -31,6 +33,8 @@
properties.add( "primitiveProperty" );
properties.add( "primitiveArrayProperty" );
properties.add( "arrayProperty" );
+ properties.add( "genericCollectionProperty" );
+ properties.add( "nongenericCollectionProperty" );
properties.add( "propertyStartingWithIs" );
properties.add( "language" );
List<XProperty> methodProperties = dadAsSeenFromSon.getDeclaredProperties( "property" );
@@ -44,7 +48,7 @@
}
public void testReturnsPropertiesWithUnresolvedParametricTypes() {
- assertEquals( 7, dadAsSeenFromItself.getDeclaredProperties( "property" ).size() );
+ assertEquals( 9, dadAsSeenFromItself.getDeclaredProperties( "property" ).size() );
}
public void testKnowsWhetherItsTypeIsFullyResolved() {
@@ -62,7 +66,7 @@
public void testCanBeFiltered() {
assertEquals(
- 8, dadAsSeenFromSon.getDeclaredProperties(
+ 10, dadAsSeenFromSon.getDeclaredProperties(
"property", new Filter() {
public boolean returnStatic() {
Modified: trunk/HibernateExt/commons-annotations/src/test/org/hibernate/annotations/common/test/reflection/java/generics/Dad.java
===================================================================
--- trunk/HibernateExt/commons-annotations/src/test/org/hibernate/annotations/common/test/reflection/java/generics/Dad.java 2007-06-06 21:37:42 UTC (rev 11648)
+++ trunk/HibernateExt/commons-annotations/src/test/org/hibernate/annotations/common/test/reflection/java/generics/Dad.java 2007-06-07 14:34:51 UTC (rev 11649)
@@ -2,6 +2,7 @@
import java.util.List;
import java.util.Map;
+
import javax.persistence.Entity;
/**
@@ -41,6 +42,14 @@
return null;
}
+ public List<T> getGenericCollectionProperty() {
+ return null;
+ }
+
+ public List<String> getNongenericCollectionProperty() {
+ return null;
+ }
+
public static Integer getStaticThing() {
return null;
}
Modified: trunk/HibernateExt/commons-annotations/src/test/org/hibernate/annotations/common/test/reflection/java/generics/TypeUtilsTest.java
===================================================================
--- trunk/HibernateExt/commons-annotations/src/test/org/hibernate/annotations/common/test/reflection/java/generics/TypeUtilsTest.java 2007-06-06 21:37:42 UTC (rev 11648)
+++ trunk/HibernateExt/commons-annotations/src/test/org/hibernate/annotations/common/test/reflection/java/generics/TypeUtilsTest.java 2007-06-07 14:34:51 UTC (rev 11649)
@@ -1,8 +1,11 @@
package org.hibernate.annotations.common.test.reflection.java.generics;
import java.lang.reflect.Type;
+import java.util.LinkedList;
+import java.util.List;
import junit.framework.TestCase;
+
import org.hibernate.annotations.common.reflection.java.generics.TypeEnvironment;
import org.hibernate.annotations.common.reflection.java.generics.TypeEnvironmentFactory;
import org.hibernate.annotations.common.reflection.java.generics.TypeUtils;
@@ -17,15 +20,26 @@
assertTrue( TypeUtils.isResolved( Dad.class ) );
}
- public void testKnowsIfAParametricTypeIsFullyResolved() throws Exception {
- Type simpleType = Dad.class.getMethod( "returnsGeneric", new Class[0] ).getGenericReturnType();
+ private Type getPropertyFromDad(String propertyName) throws NoSuchMethodException {
+ return Dad.class.getMethod( propertyName, new Class[0] ).getGenericReturnType();
+ }
+
+ public void testKnowsWhetherAParametricTypeIsFullyResolved() throws Exception {
+ Type simpleType = getPropertyFromDad( "returnsGeneric" );
assertFalse( TypeUtils.isResolved( dadContext.bind( simpleType ) ) );
assertTrue( TypeUtils.isResolved( sonContext.bind( simpleType ) ) );
}
- public void testKnowsIfAnArrayTypeIsFullyResolved() throws Exception {
- Type arrayType = Dad.class.getMethod( "getArrayProperty", new Class[0] ).getGenericReturnType();
+ public void testKnowsWhetherAnArrayTypeIsFullyResolved() throws Exception {
+ Type arrayType = getPropertyFromDad( "getArrayProperty" );
assertFalse( TypeUtils.isResolved( dadContext.bind( arrayType ) ) );
assertTrue( TypeUtils.isResolved( sonContext.bind( arrayType ) ) );
}
+
+ public void testKnowsWhetherATypeIsSimple() throws Exception {
+ assertTrue( TypeUtils.isSimple( String.class ) );
+ assertFalse( TypeUtils.isSimple( new String[1].getClass() ) );
+ assertFalse( TypeUtils.isSimple( getPropertyFromDad( "getNongenericCollectionProperty" ) ) );
+ assertFalse( TypeUtils.isSimple( getPropertyFromDad( "getGenericCollectionProperty" ) ) );
+ }
}
Added: trunk/HibernateExt/commons-annotations/src/test/org/hibernate/annotations/common/test/reflection/java/generics/deep/ANN612IssueTest.java
===================================================================
--- trunk/HibernateExt/commons-annotations/src/test/org/hibernate/annotations/common/test/reflection/java/generics/deep/ANN612IssueTest.java (rev 0)
+++ trunk/HibernateExt/commons-annotations/src/test/org/hibernate/annotations/common/test/reflection/java/generics/deep/ANN612IssueTest.java 2007-06-07 14:34:51 UTC (rev 11649)
@@ -0,0 +1,35 @@
+//$Id: $
+package org.hibernate.annotations.common.test.reflection.java.generics.deep;
+
+import java.util.List;
+
+import javax.persistence.Transient;
+
+import junit.framework.TestCase;
+
+import org.hibernate.annotations.common.reflection.XClass;
+import org.hibernate.annotations.common.reflection.XProperty;
+import org.hibernate.annotations.common.reflection.java.JavaReflectionManager;
+
+
+/**
+ * @author Paolo Perrotta
+ */
+public class ANN612IssueTest extends TestCase {
+
+
+ public static class J<T> {}
+
+ public static class C {
+ public J<Object> thisOneAlwaysWorkedFine;
+ public J<Object[]> thisOneUsedToCauseProblems;
+ }
+
+ public void testANN612IssueIsFixed() throws Exception {
+ JavaReflectionManager factory = new JavaReflectionManager();
+ XClass clazz = factory.toXClass( C.class );
+ List<XProperty> properties = clazz.getDeclaredProperties( XClass.ACCESS_FIELD );
+ for( XProperty property : properties )
+ assertTrue( property.isTypeResolved() );
+ }
+}
18 years, 10 months
Hibernate SVN: r11648 - trunk/Hibernate3/code/core/src/main/java/org/hibernate/dialect.
by hibernate-commits@lists.jboss.org
Author: steve.ebersole(a)jboss.com
Date: 2007-06-06 17:37:42 -0400 (Wed, 06 Jun 2007)
New Revision: 11648
Modified:
trunk/Hibernate3/code/core/src/main/java/org/hibernate/dialect/DialectFactory.java
Log:
HHH-2630 : dialect detection
Modified: trunk/Hibernate3/code/core/src/main/java/org/hibernate/dialect/DialectFactory.java
===================================================================
--- trunk/Hibernate3/code/core/src/main/java/org/hibernate/dialect/DialectFactory.java 2007-06-06 21:37:33 UTC (rev 11647)
+++ trunk/Hibernate3/code/core/src/main/java/org/hibernate/dialect/DialectFactory.java 2007-06-06 21:37:42 UTC (rev 11648)
@@ -114,14 +114,16 @@
// TODO : this is the stuff it'd be nice to move to a properties file or some other easily user-editable place
MAPPERS.put( "HSQL Database Engine", new VersionInsensitiveMapper( "org.hibernate.dialect.HSQLDialect" ) );
MAPPERS.put( "DB2/NT", new VersionInsensitiveMapper( "org.hibernate.dialect.DB2Dialect" ) );
+ MAPPERS.put( "DB2/LINUX", new VersionInsensitiveMapper( "org.hibernate.dialect.DB2Dialect" ) );
MAPPERS.put( "MySQL", new VersionInsensitiveMapper( "org.hibernate.dialect.MySQLDialect" ) );
MAPPERS.put( "PostgreSQL", new VersionInsensitiveMapper( "org.hibernate.dialect.PostgreSQLDialect" ) );
MAPPERS.put( "Microsoft SQL Server Database", new VersionInsensitiveMapper( "org.hibernate.dialect.SQLServerDialect" ) );
MAPPERS.put( "Microsoft SQL Server", new VersionInsensitiveMapper( "org.hibernate.dialect.SQLServerDialect" ) );
MAPPERS.put( "Sybase SQL Server", new VersionInsensitiveMapper( "org.hibernate.dialect.SybaseDialect" ) );
+ MAPPERS.put( "Adaptive Server Enterprise", new VersionInsensitiveMapper( "org.hibernate.dialect.SybaseDialect" ) );
MAPPERS.put( "Informix Dynamic Server", new VersionInsensitiveMapper( "org.hibernate.dialect.InformixDialect" ) );
MAPPERS.put( "Apache Derby", new VersionInsensitiveMapper( "org.hibernate.dialect.DerbyDialect" ) );
-
+
MAPPERS.put(
"Oracle",
new DatabaseDialectMapper() {
18 years, 10 months
Hibernate SVN: r11647 - branches/Branch_3_2/Hibernate3/src/org/hibernate/dialect.
by hibernate-commits@lists.jboss.org
Author: steve.ebersole(a)jboss.com
Date: 2007-06-06 17:37:33 -0400 (Wed, 06 Jun 2007)
New Revision: 11647
Modified:
branches/Branch_3_2/Hibernate3/src/org/hibernate/dialect/DialectFactory.java
Log:
HHH-2630 : dialect detection
Modified: branches/Branch_3_2/Hibernate3/src/org/hibernate/dialect/DialectFactory.java
===================================================================
--- branches/Branch_3_2/Hibernate3/src/org/hibernate/dialect/DialectFactory.java 2007-06-06 21:35:23 UTC (rev 11646)
+++ branches/Branch_3_2/Hibernate3/src/org/hibernate/dialect/DialectFactory.java 2007-06-06 21:37:33 UTC (rev 11647)
@@ -114,14 +114,16 @@
// TODO : this is the stuff it'd be nice to move to a properties file or some other easily user-editable place
MAPPERS.put( "HSQL Database Engine", new VersionInsensitiveMapper( "org.hibernate.dialect.HSQLDialect" ) );
MAPPERS.put( "DB2/NT", new VersionInsensitiveMapper( "org.hibernate.dialect.DB2Dialect" ) );
+ MAPPERS.put( "DB2/LINUX", new VersionInsensitiveMapper( "org.hibernate.dialect.DB2Dialect" ) );
MAPPERS.put( "MySQL", new VersionInsensitiveMapper( "org.hibernate.dialect.MySQLDialect" ) );
MAPPERS.put( "PostgreSQL", new VersionInsensitiveMapper( "org.hibernate.dialect.PostgreSQLDialect" ) );
MAPPERS.put( "Microsoft SQL Server Database", new VersionInsensitiveMapper( "org.hibernate.dialect.SQLServerDialect" ) );
MAPPERS.put( "Microsoft SQL Server", new VersionInsensitiveMapper( "org.hibernate.dialect.SQLServerDialect" ) );
MAPPERS.put( "Sybase SQL Server", new VersionInsensitiveMapper( "org.hibernate.dialect.SybaseDialect" ) );
+ MAPPERS.put( "Adaptive Server Enterprise", new VersionInsensitiveMapper( "org.hibernate.dialect.SybaseDialect" ) );
MAPPERS.put( "Informix Dynamic Server", new VersionInsensitiveMapper( "org.hibernate.dialect.InformixDialect" ) );
MAPPERS.put( "Apache Derby", new VersionInsensitiveMapper( "org.hibernate.dialect.DerbyDialect" ) );
-
+
MAPPERS.put(
"Oracle",
new DatabaseDialectMapper() {
18 years, 10 months
Hibernate SVN: r11646 - trunk/Hibernate3/code/testsuite/src/test/java/org/hibernate/test/naturalid.
by hibernate-commits@lists.jboss.org
Author: steve.ebersole(a)jboss.com
Date: 2007-06-06 17:35:23 -0400 (Wed, 06 Jun 2007)
New Revision: 11646
Removed:
trunk/Hibernate3/code/testsuite/src/test/java/org/hibernate/test/naturalid/NaturalIdTest.java
Log:
HHH-1569 : natural-id checks
Deleted: trunk/Hibernate3/code/testsuite/src/test/java/org/hibernate/test/naturalid/NaturalIdTest.java
===================================================================
--- trunk/Hibernate3/code/testsuite/src/test/java/org/hibernate/test/naturalid/NaturalIdTest.java 2007-06-06 21:33:31 UTC (rev 11645)
+++ trunk/Hibernate3/code/testsuite/src/test/java/org/hibernate/test/naturalid/NaturalIdTest.java 2007-06-06 21:35:23 UTC (rev 11646)
@@ -1,248 +0,0 @@
-//$Id: NaturalIdTest.java 10977 2006-12-12 23:28:04Z steve.ebersole(a)jboss.com $
-package org.hibernate.test.naturalid;
-
-import java.lang.reflect.Field;
-
-import junit.framework.Test;
-
-import org.hibernate.HibernateException;
-import org.hibernate.Session;
-import org.hibernate.Transaction;
-import org.hibernate.cfg.Configuration;
-import org.hibernate.cfg.Environment;
-import org.hibernate.criterion.Restrictions;
-import org.hibernate.junit.functional.FunctionalTestCase;
-import org.hibernate.junit.functional.FunctionalTestClassTestSuite;
-
-/**
- * @author Gavin King
- */
-public class NaturalIdTest extends FunctionalTestCase {
-
- public NaturalIdTest(String str) {
- super(str);
- }
-
- public String[] getMappings() {
- return new String[] { "naturalid/User.hbm.xml" };
- }
-
- public void configure(Configuration cfg) {
- cfg.setProperty(Environment.USE_SECOND_LEVEL_CACHE, "true");
- cfg.setProperty(Environment.USE_QUERY_CACHE, "true");
- cfg.setProperty(Environment.GENERATE_STATISTICS, "true");
- }
-
- public static Test suite() {
- return new FunctionalTestClassTestSuite( NaturalIdTest.class );
- }
-
- public void testNaturalIdCheck() throws Exception {
- Session s = openSession();
- Transaction t = s.beginTransaction();
-
- User u = new User("gavin", "hb", "secret");
- s.persist(u);
- Field name = u.getClass().getDeclaredField("name");
- name.setAccessible(true);
- name.set(u, "Gavin");
- try {
- s.flush();
- fail();
- }
- catch (HibernateException he) {}
- name.set(u, "gavin");
- s.delete(u);
- t.commit();
- s.close();
- }
-
- public void testNonexistentNaturalIdCache() {
- getSessions().getStatistics().clear();
-
- Session s = openSession();
- Transaction t = s.beginTransaction();
-
- Object nullUser = s.createCriteria(User.class)
- .add( Restrictions.naturalId()
- .set("name", "gavin")
- .set("org", "hb")
- )
- .setCacheable(true)
- .uniqueResult();
-
- assertNull(nullUser);
-
- t.commit();
- s.close();
-
- assertEquals( getSessions().getStatistics().getQueryExecutionCount(), 1 );
- assertEquals( getSessions().getStatistics().getQueryCacheHitCount(), 0 );
- assertEquals( getSessions().getStatistics().getQueryCachePutCount(), 0 );
-
- s = openSession();
- t = s.beginTransaction();
-
- User u = new User("gavin", "hb", "secret");
- s.persist(u);
-
- t.commit();
- s.close();
-
- getSessions().getStatistics().clear();
-
- s = openSession();
- t = s.beginTransaction();
-
- u = (User) s.createCriteria(User.class)
- .add( Restrictions.naturalId()
- .set("name", "gavin")
- .set("org", "hb")
- )
- .setCacheable(true)
- .uniqueResult();
-
- assertNotNull(u);
-
- t.commit();
- s.close();
-
- assertEquals( getSessions().getStatistics().getQueryExecutionCount(), 1 );
- assertEquals( getSessions().getStatistics().getQueryCacheHitCount(), 0 );
- assertEquals( getSessions().getStatistics().getQueryCachePutCount(), 1 );
-
- getSessions().getStatistics().clear();
-
- s = openSession();
- t = s.beginTransaction();
-
- u = (User) s.createCriteria(User.class)
- .add( Restrictions.naturalId()
- .set("name", "gavin")
- .set("org", "hb")
- ).setCacheable(true)
- .uniqueResult();
-
- s.delete(u);
-
- t.commit();
- s.close();
-
- assertEquals( getSessions().getStatistics().getQueryExecutionCount(), 0 );
- assertEquals( getSessions().getStatistics().getQueryCacheHitCount(), 1 );
-
- getSessions().getStatistics().clear();
-
- s = openSession();
- t = s.beginTransaction();
-
- nullUser = s.createCriteria(User.class)
- .add( Restrictions.naturalId()
- .set("name", "gavin")
- .set("org", "hb")
- )
- .setCacheable(true)
- .uniqueResult();
-
- assertNull(nullUser);
-
- t.commit();
- s.close();
-
- assertEquals( getSessions().getStatistics().getQueryExecutionCount(), 1 );
- assertEquals( getSessions().getStatistics().getQueryCacheHitCount(), 0 );
- assertEquals( getSessions().getStatistics().getQueryCachePutCount(), 0 );
-
- }
-
- public void testNaturalIdCache() {
- Session s = openSession();
- Transaction t = s.beginTransaction();
-
- User u = new User("gavin", "hb", "secret");
- s.persist(u);
-
- t.commit();
- s.close();
-
- getSessions().getStatistics().clear();
-
- s = openSession();
- t = s.beginTransaction();
-
- u = (User) s.createCriteria(User.class)
- .add( Restrictions.naturalId()
- .set("name", "gavin")
- .set("org", "hb")
- )
- .setCacheable(true)
- .uniqueResult();
-
- assertNotNull(u);
-
- t.commit();
- s.close();
-
- assertEquals( getSessions().getStatistics().getQueryExecutionCount(), 1 );
- assertEquals( getSessions().getStatistics().getQueryCacheHitCount(), 0 );
- assertEquals( getSessions().getStatistics().getQueryCachePutCount(), 1 );
-
- s = openSession();
- t = s.beginTransaction();
-
- User v = new User("xam", "hb", "foobar");
- s.persist(v);
-
- t.commit();
- s.close();
-
- getSessions().getStatistics().clear();
-
- s = openSession();
- t = s.beginTransaction();
-
- u = (User) s.createCriteria(User.class)
- .add( Restrictions.naturalId()
- .set("name", "gavin")
- .set("org", "hb")
- ).setCacheable(true)
- .uniqueResult();
-
- assertNotNull(u);
-
- t.commit();
- s.close();
-
- assertEquals( getSessions().getStatistics().getQueryExecutionCount(), 0 );
- assertEquals( getSessions().getStatistics().getQueryCacheHitCount(), 1 );
-
- s = openSession();
- t = s.beginTransaction();
- s.createQuery("delete User").executeUpdate();
- t.commit();
- s.close();
- }
-
- public void testQuerying() throws Exception {
- Session s = openSession();
- Transaction t = s.beginTransaction();
-
- User u = new User("emmanuel", "hb", "bh");
- s.persist(u);
-
- t.commit();
- s.close();
-
- s = openSession();
- t = s.beginTransaction();
-
- u = (User) s.createQuery( "from User u where u.name = :name" )
- .setParameter( "name", "emmanuel" ).uniqueResult();
- assertEquals( "emmanuel", u.getName() );
- s.delete( u );
-
- t.commit();
- s.close();
- }
-}
-
18 years, 10 months
Hibernate SVN: r11645 - in branches/Branch_3_2/Hibernate3: src/org/hibernate/event/def and 4 other directories.
by hibernate-commits@lists.jboss.org
Author: steve.ebersole(a)jboss.com
Date: 2007-06-06 17:33:31 -0400 (Wed, 06 Jun 2007)
New Revision: 11645
Added:
branches/Branch_3_2/Hibernate3/test/org/hibernate/test/naturalid/NaturalIdSuite.java
branches/Branch_3_2/Hibernate3/test/org/hibernate/test/naturalid/immutable/
branches/Branch_3_2/Hibernate3/test/org/hibernate/test/naturalid/immutable/ImmutableNaturalIdTest.java
branches/Branch_3_2/Hibernate3/test/org/hibernate/test/naturalid/immutable/User.hbm.xml
branches/Branch_3_2/Hibernate3/test/org/hibernate/test/naturalid/immutable/User.java
branches/Branch_3_2/Hibernate3/test/org/hibernate/test/naturalid/mutable/
branches/Branch_3_2/Hibernate3/test/org/hibernate/test/naturalid/mutable/MutableNaturalIdTest.java
branches/Branch_3_2/Hibernate3/test/org/hibernate/test/naturalid/mutable/User.hbm.xml
branches/Branch_3_2/Hibernate3/test/org/hibernate/test/naturalid/mutable/User.java
Removed:
branches/Branch_3_2/Hibernate3/test/org/hibernate/test/naturalid/NaturalIdTest.java
branches/Branch_3_2/Hibernate3/test/org/hibernate/test/naturalid/User.hbm.xml
branches/Branch_3_2/Hibernate3/test/org/hibernate/test/naturalid/User.java
Modified:
branches/Branch_3_2/Hibernate3/src/org/hibernate/engine/PersistenceContext.java
branches/Branch_3_2/Hibernate3/src/org/hibernate/event/def/DefaultFlushEntityEventListener.java
branches/Branch_3_2/Hibernate3/test/org/hibernate/test/AllTests.java
Log:
HHH-1569 : natural-id check
Modified: branches/Branch_3_2/Hibernate3/src/org/hibernate/engine/PersistenceContext.java
===================================================================
--- branches/Branch_3_2/Hibernate3/src/org/hibernate/engine/PersistenceContext.java 2007-06-06 21:33:10 UTC (rev 11644)
+++ branches/Branch_3_2/Hibernate3/src/org/hibernate/engine/PersistenceContext.java 2007-06-06 21:33:31 UTC (rev 11645)
@@ -83,6 +83,11 @@
public Object[] getCachedDatabaseSnapshot(EntityKey key);
+ /**
+ * Get the values of the natural id fields as known to the underlying
+ * database, or null if the entity has no natural id or there is no
+ * corresponding row.
+ */
public Object[] getNaturalIdSnapshot(Serializable id, EntityPersister persister)
throws HibernateException;
@@ -437,4 +442,4 @@
public void setReadOnly(Object entity, boolean readOnly);
void replaceDelayedEntityIdentityInsertKeys(EntityKey oldKey, Serializable generatedId);
-}
\ No newline at end of file
+}
Modified: branches/Branch_3_2/Hibernate3/src/org/hibernate/event/def/DefaultFlushEntityEventListener.java
===================================================================
--- branches/Branch_3_2/Hibernate3/src/org/hibernate/event/def/DefaultFlushEntityEventListener.java 2007-06-06 21:33:10 UTC (rev 11644)
+++ branches/Branch_3_2/Hibernate3/src/org/hibernate/event/def/DefaultFlushEntityEventListener.java 2007-06-06 21:33:31 UTC (rev 11645)
@@ -74,16 +74,23 @@
EntityMode entityMode,
SessionImplementor session) {
if ( persister.hasNaturalIdentifier() ) {
- if ( loaded == null ) {
- loaded = session.getPersistenceContext().getNaturalIdSnapshot( identifier, persister );
- }
+ Object[] snapshot = null;
Type[] types = persister.getPropertyTypes();
int[] props = persister.getNaturalIdentifierProperties();
boolean[] updateable = persister.getPropertyUpdateability();
for ( int i=0; i<props.length; i++ ) {
int prop = props[i];
if ( !updateable[prop] ) {
- if ( !types[prop].isEqual( current[prop], loaded[prop], entityMode ) ) {
+ Object loadedVal;
+ if ( loaded == null ) {
+ if ( snapshot == null) {
+ snapshot = session.getPersistenceContext().getNaturalIdSnapshot( identifier, persister );
+ }
+ loadedVal = snapshot[i];
+ } else {
+ loadedVal = loaded[prop];
+ }
+ if ( !types[prop].isEqual( current[prop], loadedVal, entityMode ) ) {
throw new HibernateException(
"immutable natural identifier of an instance of " +
persister.getEntityName() +
Modified: branches/Branch_3_2/Hibernate3/test/org/hibernate/test/AllTests.java
===================================================================
--- branches/Branch_3_2/Hibernate3/test/org/hibernate/test/AllTests.java 2007-06-06 21:33:10 UTC (rev 11644)
+++ branches/Branch_3_2/Hibernate3/test/org/hibernate/test/AllTests.java 2007-06-06 21:33:31 UTC (rev 11645)
@@ -49,6 +49,7 @@
import org.hibernate.test.idclass.IdClassTest;
import org.hibernate.test.idprops.IdentifierPropertyReferencesTest;
import org.hibernate.test.immutable.ImmutableTest;
+import org.hibernate.test.insertordering.InsertOrderingTest;
import org.hibernate.test.instrument.buildtime.InstrumentTest;
import org.hibernate.test.instrument.runtime.CGLIBInstrumentationTest;
import org.hibernate.test.instrument.runtime.JavassistInstrumentationTest;
@@ -91,7 +92,7 @@
import org.hibernate.test.mapping.ValueVisitorTest;
import org.hibernate.test.mappingexception.MappingExceptionTest;
import org.hibernate.test.mixed.MixedTest;
-import org.hibernate.test.naturalid.NaturalIdTest;
+import org.hibernate.test.naturalid.NaturalIdSuite;
import org.hibernate.test.ondelete.OnDeleteTest;
import org.hibernate.test.onetomany.OneToManyTest;
import org.hibernate.test.onetoone.OneToOneSuite;
@@ -104,6 +105,7 @@
import org.hibernate.test.proxy.ProxyTest;
import org.hibernate.test.querycache.QueryCacheTest;
import org.hibernate.test.readonly.ReadOnlyTest;
+import org.hibernate.test.reattachment.ReattachmentSuite;
import org.hibernate.test.rowid.RowIdTest;
import org.hibernate.test.sorted.SortTest;
import org.hibernate.test.sql.NativeSqlSupportSuite;
@@ -129,8 +131,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.insertordering.InsertOrderingTest;
-import org.hibernate.test.reattachment.ReattachmentSuite;
/**
* @author Gavin King
@@ -194,7 +194,7 @@
public static Test unfilteredSuite() {
TestSuite suite = new TestSuite("New tests suite");
suite.addTest( OpsSuite.suite() );
- suite.addTest( NaturalIdTest.suite() );
+ suite.addTest( NaturalIdSuite.suite() );
suite.addTest( ComponentSuite.suite() );
suite.addTest( ProxyTest.suite() );
suite.addTest( VersionTest.suite() );
Added: branches/Branch_3_2/Hibernate3/test/org/hibernate/test/naturalid/NaturalIdSuite.java
===================================================================
--- branches/Branch_3_2/Hibernate3/test/org/hibernate/test/naturalid/NaturalIdSuite.java (rev 0)
+++ branches/Branch_3_2/Hibernate3/test/org/hibernate/test/naturalid/NaturalIdSuite.java 2007-06-06 21:33:31 UTC (rev 11645)
@@ -0,0 +1,21 @@
+package org.hibernate.test.naturalid;
+
+import junit.framework.Test;
+import junit.framework.TestSuite;
+
+import org.hibernate.test.naturalid.immutable.ImmutableNaturalIdTest;
+import org.hibernate.test.naturalid.mutable.MutableNaturalIdTest;
+
+/**
+ * {@inheritDoc}
+ *
+ * @author Steve Ebersole
+ */
+public class NaturalIdSuite {
+ public static Test suite() {
+ TestSuite suite = new TestSuite( "natural ids" );
+ suite.addTest( MutableNaturalIdTest.suite() );
+ suite.addTest( ImmutableNaturalIdTest.suite() );
+ return suite;
+ }
+}
Deleted: branches/Branch_3_2/Hibernate3/test/org/hibernate/test/naturalid/NaturalIdTest.java
===================================================================
--- branches/Branch_3_2/Hibernate3/test/org/hibernate/test/naturalid/NaturalIdTest.java 2007-06-06 21:33:10 UTC (rev 11644)
+++ branches/Branch_3_2/Hibernate3/test/org/hibernate/test/naturalid/NaturalIdTest.java 2007-06-06 21:33:31 UTC (rev 11645)
@@ -1,248 +0,0 @@
-//$Id$
-package org.hibernate.test.naturalid;
-
-import java.lang.reflect.Field;
-
-import junit.framework.Test;
-
-import org.hibernate.HibernateException;
-import org.hibernate.Session;
-import org.hibernate.Transaction;
-import org.hibernate.cfg.Configuration;
-import org.hibernate.cfg.Environment;
-import org.hibernate.criterion.Restrictions;
-import org.hibernate.junit.functional.FunctionalTestCase;
-import org.hibernate.junit.functional.FunctionalTestClassTestSuite;
-
-/**
- * @author Gavin King
- */
-public class NaturalIdTest extends FunctionalTestCase {
-
- public NaturalIdTest(String str) {
- super(str);
- }
-
- public String[] getMappings() {
- return new String[] { "naturalid/User.hbm.xml" };
- }
-
- public void configure(Configuration cfg) {
- cfg.setProperty(Environment.USE_SECOND_LEVEL_CACHE, "true");
- cfg.setProperty(Environment.USE_QUERY_CACHE, "true");
- cfg.setProperty(Environment.GENERATE_STATISTICS, "true");
- }
-
- public static Test suite() {
- return new FunctionalTestClassTestSuite( NaturalIdTest.class );
- }
-
- public void testNaturalIdCheck() throws Exception {
- Session s = openSession();
- Transaction t = s.beginTransaction();
-
- User u = new User("gavin", "hb", "secret");
- s.persist(u);
- Field name = u.getClass().getDeclaredField("name");
- name.setAccessible(true);
- name.set(u, "Gavin");
- try {
- s.flush();
- fail();
- }
- catch (HibernateException he) {}
- name.set(u, "gavin");
- s.delete(u);
- t.commit();
- s.close();
- }
-
- public void testNonexistentNaturalIdCache() {
- getSessions().getStatistics().clear();
-
- Session s = openSession();
- Transaction t = s.beginTransaction();
-
- Object nullUser = s.createCriteria(User.class)
- .add( Restrictions.naturalId()
- .set("name", "gavin")
- .set("org", "hb")
- )
- .setCacheable(true)
- .uniqueResult();
-
- assertNull(nullUser);
-
- t.commit();
- s.close();
-
- assertEquals( getSessions().getStatistics().getQueryExecutionCount(), 1 );
- assertEquals( getSessions().getStatistics().getQueryCacheHitCount(), 0 );
- assertEquals( getSessions().getStatistics().getQueryCachePutCount(), 0 );
-
- s = openSession();
- t = s.beginTransaction();
-
- User u = new User("gavin", "hb", "secret");
- s.persist(u);
-
- t.commit();
- s.close();
-
- getSessions().getStatistics().clear();
-
- s = openSession();
- t = s.beginTransaction();
-
- u = (User) s.createCriteria(User.class)
- .add( Restrictions.naturalId()
- .set("name", "gavin")
- .set("org", "hb")
- )
- .setCacheable(true)
- .uniqueResult();
-
- assertNotNull(u);
-
- t.commit();
- s.close();
-
- assertEquals( getSessions().getStatistics().getQueryExecutionCount(), 1 );
- assertEquals( getSessions().getStatistics().getQueryCacheHitCount(), 0 );
- assertEquals( getSessions().getStatistics().getQueryCachePutCount(), 1 );
-
- getSessions().getStatistics().clear();
-
- s = openSession();
- t = s.beginTransaction();
-
- u = (User) s.createCriteria(User.class)
- .add( Restrictions.naturalId()
- .set("name", "gavin")
- .set("org", "hb")
- ).setCacheable(true)
- .uniqueResult();
-
- s.delete(u);
-
- t.commit();
- s.close();
-
- assertEquals( getSessions().getStatistics().getQueryExecutionCount(), 0 );
- assertEquals( getSessions().getStatistics().getQueryCacheHitCount(), 1 );
-
- getSessions().getStatistics().clear();
-
- s = openSession();
- t = s.beginTransaction();
-
- nullUser = s.createCriteria(User.class)
- .add( Restrictions.naturalId()
- .set("name", "gavin")
- .set("org", "hb")
- )
- .setCacheable(true)
- .uniqueResult();
-
- assertNull(nullUser);
-
- t.commit();
- s.close();
-
- assertEquals( getSessions().getStatistics().getQueryExecutionCount(), 1 );
- assertEquals( getSessions().getStatistics().getQueryCacheHitCount(), 0 );
- assertEquals( getSessions().getStatistics().getQueryCachePutCount(), 0 );
-
- }
-
- public void testNaturalIdCache() {
- Session s = openSession();
- Transaction t = s.beginTransaction();
-
- User u = new User("gavin", "hb", "secret");
- s.persist(u);
-
- t.commit();
- s.close();
-
- getSessions().getStatistics().clear();
-
- s = openSession();
- t = s.beginTransaction();
-
- u = (User) s.createCriteria(User.class)
- .add( Restrictions.naturalId()
- .set("name", "gavin")
- .set("org", "hb")
- )
- .setCacheable(true)
- .uniqueResult();
-
- assertNotNull(u);
-
- t.commit();
- s.close();
-
- assertEquals( getSessions().getStatistics().getQueryExecutionCount(), 1 );
- assertEquals( getSessions().getStatistics().getQueryCacheHitCount(), 0 );
- assertEquals( getSessions().getStatistics().getQueryCachePutCount(), 1 );
-
- s = openSession();
- t = s.beginTransaction();
-
- User v = new User("xam", "hb", "foobar");
- s.persist(v);
-
- t.commit();
- s.close();
-
- getSessions().getStatistics().clear();
-
- s = openSession();
- t = s.beginTransaction();
-
- u = (User) s.createCriteria(User.class)
- .add( Restrictions.naturalId()
- .set("name", "gavin")
- .set("org", "hb")
- ).setCacheable(true)
- .uniqueResult();
-
- assertNotNull(u);
-
- t.commit();
- s.close();
-
- assertEquals( getSessions().getStatistics().getQueryExecutionCount(), 0 );
- assertEquals( getSessions().getStatistics().getQueryCacheHitCount(), 1 );
-
- s = openSession();
- t = s.beginTransaction();
- s.createQuery("delete User").executeUpdate();
- t.commit();
- s.close();
- }
-
- public void testQuerying() throws Exception {
- Session s = openSession();
- Transaction t = s.beginTransaction();
-
- User u = new User("emmanuel", "hb", "bh");
- s.persist(u);
-
- t.commit();
- s.close();
-
- s = openSession();
- t = s.beginTransaction();
-
- u = (User) s.createQuery( "from User u where u.name = :name" )
- .setParameter( "name", "emmanuel" ).uniqueResult();
- assertEquals( "emmanuel", u.getName() );
- s.delete( u );
-
- t.commit();
- s.close();
- }
-}
-
Deleted: branches/Branch_3_2/Hibernate3/test/org/hibernate/test/naturalid/User.hbm.xml
===================================================================
--- branches/Branch_3_2/Hibernate3/test/org/hibernate/test/naturalid/User.hbm.xml 2007-06-06 21:33:10 UTC (rev 11644)
+++ branches/Branch_3_2/Hibernate3/test/org/hibernate/test/naturalid/User.hbm.xml 2007-06-06 21:33:31 UTC (rev 11645)
@@ -1,27 +0,0 @@
-<?xml version="1.0"?>
-<!DOCTYPE hibernate-mapping PUBLIC
- "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
- "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
-
-<!--
-
- This mapping illustrates use of <natural-id>.
-
--->
-
-<hibernate-mapping
- package="org.hibernate.test.naturalid"
- default-access="field">
-
- <class name="User" table="SystemUserInfo">
- <id name="id">
- <generator class="increment"/>
- </id>
- <natural-id>
- <property name="name"/>
- <property name="org"/>
- </natural-id>
- <property name="password"/>
- </class>
-
-</hibernate-mapping>
\ No newline at end of file
Deleted: branches/Branch_3_2/Hibernate3/test/org/hibernate/test/naturalid/User.java
===================================================================
--- branches/Branch_3_2/Hibernate3/test/org/hibernate/test/naturalid/User.java 2007-06-06 21:33:10 UTC (rev 11644)
+++ branches/Branch_3_2/Hibernate3/test/org/hibernate/test/naturalid/User.java 2007-06-06 21:33:31 UTC (rev 11645)
@@ -1,34 +0,0 @@
-//$Id$
-package org.hibernate.test.naturalid;
-
-/**
- * @author Gavin King
- */
-public class User {
-
- private Long id;
- private String name;
- private String org;
- private String password;
-
- User() {}
-
- public User(String name, String org, String password) {
- this.name = name;
- this.org = org;
- this.password = password;
- }
-
- public String getName() {
- return name;
- }
-
- public void setPassword(String password) {
- this.password = password;
- }
-
- public String getOrg() {
- return org;
- }
-
-}
Added: branches/Branch_3_2/Hibernate3/test/org/hibernate/test/naturalid/immutable/ImmutableNaturalIdTest.java
===================================================================
--- branches/Branch_3_2/Hibernate3/test/org/hibernate/test/naturalid/immutable/ImmutableNaturalIdTest.java (rev 0)
+++ branches/Branch_3_2/Hibernate3/test/org/hibernate/test/naturalid/immutable/ImmutableNaturalIdTest.java 2007-06-06 21:33:31 UTC (rev 11645)
@@ -0,0 +1,57 @@
+package org.hibernate.test.naturalid.immutable;
+
+import junit.framework.Test;
+
+import org.hibernate.Session;
+import org.hibernate.junit.functional.FunctionalTestCase;
+import org.hibernate.junit.functional.FunctionalTestClassTestSuite;
+
+/**
+ * {@inheritDoc}
+ *
+ * @author Steve Ebersole
+ */
+public class ImmutableNaturalIdTest extends FunctionalTestCase {
+ public ImmutableNaturalIdTest(String string) {
+ super( string );
+ }
+
+ public String[] getMappings() {
+ return new String[] { "naturalid/immutable/User.hbm.xml" };
+ }
+
+ public static Test suite() {
+ return new FunctionalTestClassTestSuite( ImmutableNaturalIdTest.class );
+ }
+
+ public void testUpdate() {
+ // prepare some test data...
+ Session session = openSession();
+ session.beginTransaction();
+ User user = new User();
+ user.setUserName( "steve" );
+ user.setEmail( "steve(a)hibernate.org" );
+ user.setFirstName( "Steve" );
+ user.setInitial( null);
+ user.setLastName( "Ebersole" );
+ user.setPassword( "brewhaha" );
+ session.save( user );
+ session.getTransaction().commit();
+ session.close();
+
+ // 'user' is now a detached entity, so lets change a property and reattch...
+ user.setPassword( "homebrew" );
+ session = openSession();
+ session.beginTransaction();
+ session.update( user );
+ session.getTransaction().commit();
+ session.close();
+
+ // clean up
+ session = openSession();
+ session.beginTransaction();
+ session.delete( user );
+ session.getTransaction().commit();
+ session.close();
+ }
+}
Added: branches/Branch_3_2/Hibernate3/test/org/hibernate/test/naturalid/immutable/User.hbm.xml
===================================================================
--- branches/Branch_3_2/Hibernate3/test/org/hibernate/test/naturalid/immutable/User.hbm.xml (rev 0)
+++ branches/Branch_3_2/Hibernate3/test/org/hibernate/test/naturalid/immutable/User.hbm.xml 2007-06-06 21:33:31 UTC (rev 11645)
@@ -0,0 +1,24 @@
+<?xml version="1.0"?>
+<!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.naturalid.immutable">
+
+ <class name="User" table="IMM_NAT_ID_USER" lazy="true">
+ <comment>Users may bid for or sell auction items.</comment>
+ <id name="myUserId" type="java.lang.Integer">
+ <generator class="increment"/>
+ </id>
+ <natural-id mutable="false">
+ <property name="userName" length="10"/>
+ </natural-id>
+ <version name="version"/>
+ <property name="password" not-null="true" length="15" column="`password`"/>
+ <property name="email"/>
+ <property name="firstName" length="50" not-null="true"/>
+ <property name="initial" column="`initial`"/>
+ <property name="lastName" length="50" not-null="true"/>
+ </class>
+
+</hibernate-mapping>
\ No newline at end of file
Added: branches/Branch_3_2/Hibernate3/test/org/hibernate/test/naturalid/immutable/User.java
===================================================================
--- branches/Branch_3_2/Hibernate3/test/org/hibernate/test/naturalid/immutable/User.java (rev 0)
+++ branches/Branch_3_2/Hibernate3/test/org/hibernate/test/naturalid/immutable/User.java 2007-06-06 21:33:31 UTC (rev 11645)
@@ -0,0 +1,86 @@
+package org.hibernate.test.naturalid.immutable;
+
+/**
+ * {@inheritDoc}
+ *
+ * @author Steve Ebersole
+ */
+public class User implements java.io.Serializable {
+
+ private Integer myUserId;
+ private Integer version;
+ private String userName;
+ private String password;
+ private String email;
+ private String firstName;
+ private Character initial;
+ private String lastName;
+
+ public User() {
+ }
+
+ public Integer getMyUserId() {
+ return this.myUserId;
+ }
+
+ public void setMyUserId(Integer myUserId) {
+ this.myUserId = myUserId;
+ }
+
+ public String getUserName() {
+ return this.userName;
+ }
+
+ public void setUserName(String userName) {
+ this.userName = userName;
+ }
+
+ public String getPassword() {
+ return this.password;
+ }
+
+ public void setPassword(String password) {
+ this.password = password;
+ }
+
+ public String getEmail() {
+ return this.email;
+ }
+
+ public void setEmail(String email) {
+ this.email = email;
+ }
+
+ public String getFirstName() {
+ return this.firstName;
+ }
+
+ public void setFirstName(String firstName) {
+ this.firstName = firstName;
+ }
+
+ public Character getInitial() {
+ return this.initial;
+ }
+
+ public void setInitial(Character initial) {
+ this.initial = initial;
+ }
+
+ public String getLastName() {
+ return this.lastName;
+ }
+
+ public void setLastName(String lastName) {
+ this.lastName = lastName;
+ }
+
+ public Integer getVersion() {
+ return this.version;
+ }
+
+ public void setVersion(Integer version) {
+ this.version = version;
+ }
+
+}
Copied: branches/Branch_3_2/Hibernate3/test/org/hibernate/test/naturalid/mutable/MutableNaturalIdTest.java (from rev 11632, branches/Branch_3_2/Hibernate3/test/org/hibernate/test/naturalid/NaturalIdTest.java)
===================================================================
--- branches/Branch_3_2/Hibernate3/test/org/hibernate/test/naturalid/mutable/MutableNaturalIdTest.java (rev 0)
+++ branches/Branch_3_2/Hibernate3/test/org/hibernate/test/naturalid/mutable/MutableNaturalIdTest.java 2007-06-06 21:33:31 UTC (rev 11645)
@@ -0,0 +1,287 @@
+//$Id$
+package org.hibernate.test.naturalid.mutable;
+
+import java.lang.reflect.Field;
+
+import junit.framework.Test;
+
+import org.hibernate.HibernateException;
+import org.hibernate.Session;
+import org.hibernate.Transaction;
+import org.hibernate.cfg.Configuration;
+import org.hibernate.cfg.Environment;
+import org.hibernate.criterion.Restrictions;
+import org.hibernate.junit.functional.FunctionalTestCase;
+import org.hibernate.junit.functional.FunctionalTestClassTestSuite;
+
+/**
+ * @author Gavin King
+ */
+public class MutableNaturalIdTest extends FunctionalTestCase {
+
+ public MutableNaturalIdTest(String str) {
+ super(str);
+ }
+
+ public String[] getMappings() {
+ return new String[] { "naturalid/mutable/User.hbm.xml" };
+ }
+
+ public void configure(Configuration cfg) {
+ cfg.setProperty(Environment.USE_SECOND_LEVEL_CACHE, "true");
+ cfg.setProperty(Environment.USE_QUERY_CACHE, "true");
+ cfg.setProperty(Environment.GENERATE_STATISTICS, "true");
+ }
+
+ public static Test suite() {
+ return new FunctionalTestClassTestSuite( MutableNaturalIdTest.class );
+ }
+
+ public void testReattachmentNaturalIdCheck() throws Throwable {
+ Session s = openSession();
+ s.beginTransaction();
+ User u = new User( "gavin", "hb", "secret" );
+ s.persist( u );
+ s.getTransaction().commit();
+ s.close();
+
+ Field name = u.getClass().getDeclaredField("name");
+ name.setAccessible(true);
+ name.set(u, "Gavin");
+ s = openSession();
+ s.beginTransaction();
+ try {
+ s.update( u );
+ s.getTransaction().commit();
+ }
+ catch( HibernateException expected ) {
+ s.getTransaction().rollback();
+ }
+ catch( Throwable t ) {
+ try {
+ s.getTransaction().rollback();
+ }
+ catch ( Throwable ignore ) {
+ }
+ throw t;
+ }
+ finally {
+ s.close();
+ }
+
+ s = openSession();
+ s.beginTransaction();
+ s.delete( u );
+ s.getTransaction().commit();
+ s.close();
+ }
+
+ public void testNaturalIdCheck() throws Exception {
+ Session s = openSession();
+ Transaction t = s.beginTransaction();
+
+ User u = new User("gavin", "hb", "secret");
+ s.persist(u);
+ Field name = u.getClass().getDeclaredField("name");
+ name.setAccessible(true);
+ name.set(u, "Gavin");
+ try {
+ s.flush();
+ fail();
+ }
+ catch (HibernateException he) {}
+ name.set(u, "gavin");
+ s.delete(u);
+ t.commit();
+ s.close();
+ }
+
+ public void testNonexistentNaturalIdCache() {
+ getSessions().getStatistics().clear();
+
+ Session s = openSession();
+ Transaction t = s.beginTransaction();
+
+ Object nullUser = s.createCriteria(User.class)
+ .add( Restrictions.naturalId()
+ .set("name", "gavin")
+ .set("org", "hb")
+ )
+ .setCacheable(true)
+ .uniqueResult();
+
+ assertNull(nullUser);
+
+ t.commit();
+ s.close();
+
+ assertEquals( getSessions().getStatistics().getQueryExecutionCount(), 1 );
+ assertEquals( getSessions().getStatistics().getQueryCacheHitCount(), 0 );
+ assertEquals( getSessions().getStatistics().getQueryCachePutCount(), 0 );
+
+ s = openSession();
+ t = s.beginTransaction();
+
+ User u = new User("gavin", "hb", "secret");
+ s.persist(u);
+
+ t.commit();
+ s.close();
+
+ getSessions().getStatistics().clear();
+
+ s = openSession();
+ t = s.beginTransaction();
+
+ u = (User) s.createCriteria(User.class)
+ .add( Restrictions.naturalId()
+ .set("name", "gavin")
+ .set("org", "hb")
+ )
+ .setCacheable(true)
+ .uniqueResult();
+
+ assertNotNull(u);
+
+ t.commit();
+ s.close();
+
+ assertEquals( getSessions().getStatistics().getQueryExecutionCount(), 1 );
+ assertEquals( getSessions().getStatistics().getQueryCacheHitCount(), 0 );
+ assertEquals( getSessions().getStatistics().getQueryCachePutCount(), 1 );
+
+ getSessions().getStatistics().clear();
+
+ s = openSession();
+ t = s.beginTransaction();
+
+ u = (User) s.createCriteria(User.class)
+ .add( Restrictions.naturalId()
+ .set("name", "gavin")
+ .set("org", "hb")
+ ).setCacheable(true)
+ .uniqueResult();
+
+ s.delete(u);
+
+ t.commit();
+ s.close();
+
+ assertEquals( getSessions().getStatistics().getQueryExecutionCount(), 0 );
+ assertEquals( getSessions().getStatistics().getQueryCacheHitCount(), 1 );
+
+ getSessions().getStatistics().clear();
+
+ s = openSession();
+ t = s.beginTransaction();
+
+ nullUser = s.createCriteria(User.class)
+ .add( Restrictions.naturalId()
+ .set("name", "gavin")
+ .set("org", "hb")
+ )
+ .setCacheable(true)
+ .uniqueResult();
+
+ assertNull(nullUser);
+
+ t.commit();
+ s.close();
+
+ assertEquals( getSessions().getStatistics().getQueryExecutionCount(), 1 );
+ assertEquals( getSessions().getStatistics().getQueryCacheHitCount(), 0 );
+ assertEquals( getSessions().getStatistics().getQueryCachePutCount(), 0 );
+
+ }
+
+ public void testNaturalIdCache() {
+ Session s = openSession();
+ Transaction t = s.beginTransaction();
+
+ User u = new User("gavin", "hb", "secret");
+ s.persist(u);
+
+ t.commit();
+ s.close();
+
+ getSessions().getStatistics().clear();
+
+ s = openSession();
+ t = s.beginTransaction();
+
+ u = (User) s.createCriteria(User.class)
+ .add( Restrictions.naturalId()
+ .set("name", "gavin")
+ .set("org", "hb")
+ )
+ .setCacheable(true)
+ .uniqueResult();
+
+ assertNotNull(u);
+
+ t.commit();
+ s.close();
+
+ assertEquals( getSessions().getStatistics().getQueryExecutionCount(), 1 );
+ assertEquals( getSessions().getStatistics().getQueryCacheHitCount(), 0 );
+ assertEquals( getSessions().getStatistics().getQueryCachePutCount(), 1 );
+
+ s = openSession();
+ t = s.beginTransaction();
+
+ User v = new User("xam", "hb", "foobar");
+ s.persist(v);
+
+ t.commit();
+ s.close();
+
+ getSessions().getStatistics().clear();
+
+ s = openSession();
+ t = s.beginTransaction();
+
+ u = (User) s.createCriteria( User.class)
+ .add( Restrictions.naturalId()
+ .set("name", "gavin")
+ .set("org", "hb")
+ ).setCacheable(true)
+ .uniqueResult();
+
+ assertNotNull(u);
+
+ t.commit();
+ s.close();
+
+ assertEquals( getSessions().getStatistics().getQueryExecutionCount(), 0 );
+ assertEquals( getSessions().getStatistics().getQueryCacheHitCount(), 1 );
+
+ s = openSession();
+ t = s.beginTransaction();
+ s.createQuery("delete User").executeUpdate();
+ t.commit();
+ s.close();
+ }
+
+ public void testQuerying() throws Exception {
+ Session s = openSession();
+ Transaction t = s.beginTransaction();
+
+ User u = new User("emmanuel", "hb", "bh");
+ s.persist(u);
+
+ t.commit();
+ s.close();
+
+ s = openSession();
+ t = s.beginTransaction();
+
+ u = (User) s.createQuery( "from User u where u.name = :name" )
+ .setParameter( "name", "emmanuel" ).uniqueResult();
+ assertEquals( "emmanuel", u.getName() );
+ s.delete( u );
+
+ t.commit();
+ s.close();
+ }
+}
+
Property changes on: branches/Branch_3_2/Hibernate3/test/org/hibernate/test/naturalid/mutable/MutableNaturalIdTest.java
___________________________________________________________________
Name: svn:executable
+ *
Name: svn:keywords
+ Author Date Id Revision
Name: svn:eol-style
+ native
Copied: branches/Branch_3_2/Hibernate3/test/org/hibernate/test/naturalid/mutable/User.hbm.xml (from rev 11632, branches/Branch_3_2/Hibernate3/test/org/hibernate/test/naturalid/User.hbm.xml)
===================================================================
--- branches/Branch_3_2/Hibernate3/test/org/hibernate/test/naturalid/mutable/User.hbm.xml (rev 0)
+++ branches/Branch_3_2/Hibernate3/test/org/hibernate/test/naturalid/mutable/User.hbm.xml 2007-06-06 21:33:31 UTC (rev 11645)
@@ -0,0 +1,27 @@
+<?xml version="1.0"?>
+<!DOCTYPE hibernate-mapping PUBLIC
+ "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
+ "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
+
+<!--
+
+ This mapping illustrates use of <natural-id>.
+
+-->
+
+<hibernate-mapping
+ package="org.hibernate.test.naturalid"
+ default-access="field">
+
+ <class name="org.hibernate.test.naturalid.mutable.User" table="SystemUserInfo">
+ <id name="id">
+ <generator class="increment"/>
+ </id>
+ <natural-id>
+ <property name="name"/>
+ <property name="org"/>
+ </natural-id>
+ <property name="password"/>
+ </class>
+
+</hibernate-mapping>
\ No newline at end of file
Property changes on: branches/Branch_3_2/Hibernate3/test/org/hibernate/test/naturalid/mutable/User.hbm.xml
___________________________________________________________________
Name: svn:executable
+ *
Name: svn:keywords
+ Author Date Id Revision
Name: svn:eol-style
+ native
Copied: branches/Branch_3_2/Hibernate3/test/org/hibernate/test/naturalid/mutable/User.java (from rev 11632, branches/Branch_3_2/Hibernate3/test/org/hibernate/test/naturalid/User.java)
===================================================================
--- branches/Branch_3_2/Hibernate3/test/org/hibernate/test/naturalid/mutable/User.java (rev 0)
+++ branches/Branch_3_2/Hibernate3/test/org/hibernate/test/naturalid/mutable/User.java 2007-06-06 21:33:31 UTC (rev 11645)
@@ -0,0 +1,34 @@
+//$Id$
+package org.hibernate.test.naturalid.mutable;
+
+/**
+ * @author Gavin King
+ */
+public class User {
+
+ private Long id;
+ private String name;
+ private String org;
+ private String password;
+
+ User() {}
+
+ public User(String name, String org, String password) {
+ this.name = name;
+ this.org = org;
+ this.password = password;
+ }
+
+ public String getName() {
+ return name;
+ }
+
+ public void setPassword(String password) {
+ this.password = password;
+ }
+
+ public String getOrg() {
+ return org;
+ }
+
+}
Property changes on: branches/Branch_3_2/Hibernate3/test/org/hibernate/test/naturalid/mutable/User.java
___________________________________________________________________
Name: svn:executable
+ *
Name: svn:keywords
+ Author Date Id Revision
Name: svn:eol-style
+ native
18 years, 10 months