Hibernate SVN: r10600 - in branches/Lucene_Integration/HibernateExt/metadata/src: java/org/hibernate/lucene java/org/hibernate/lucene/bridge test/org/hibernate/lucene/test/bridge
by hibernate-commits@lists.jboss.org
Author: epbernard
Date: 2006-10-17 19:58:05 -0400 (Tue, 17 Oct 2006)
New Revision: 10600
Added:
branches/Lucene_Integration/HibernateExt/metadata/src/java/org/hibernate/lucene/DateBridge.java
Modified:
branches/Lucene_Integration/HibernateExt/metadata/src/java/org/hibernate/lucene/bridge/BridgeFactory.java
branches/Lucene_Integration/HibernateExt/metadata/src/java/org/hibernate/lucene/bridge/DateBridge.java
branches/Lucene_Integration/HibernateExt/metadata/src/test/org/hibernate/lucene/test/bridge/BridgeTest.java
branches/Lucene_Integration/HibernateExt/metadata/src/test/org/hibernate/lucene/test/bridge/Cloud.java
Log:
ANN-463 Clean DateBridge implementation, introduce @DateBridge
Added: branches/Lucene_Integration/HibernateExt/metadata/src/java/org/hibernate/lucene/DateBridge.java
===================================================================
--- branches/Lucene_Integration/HibernateExt/metadata/src/java/org/hibernate/lucene/DateBridge.java 2006-10-17 21:37:58 UTC (rev 10599)
+++ branches/Lucene_Integration/HibernateExt/metadata/src/java/org/hibernate/lucene/DateBridge.java 2006-10-17 23:58:05 UTC (rev 10600)
@@ -0,0 +1,24 @@
+//$Id: $
+package org.hibernate.lucene;
+
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+import java.lang.annotation.Target;
+import java.lang.annotation.ElementType;
+import java.lang.annotation.Documented;
+
+import org.hibernate.lucene.bridge.Resolution;
+
+/**
+ * Defines the temporal resolution of a given field
+ * Date are stored as String in GMT
+ *
+ * @author Emmanuel Bernard
+ */
+@Retention( RetentionPolicy.RUNTIME)
+(a)Target({ElementType.FIELD, ElementType.METHOD})
+@Documented
+//TODO allow pattern yyyyMMdd?
+public @interface DateBridge {
+ Resolution value();
+}
Modified: branches/Lucene_Integration/HibernateExt/metadata/src/java/org/hibernate/lucene/bridge/BridgeFactory.java
===================================================================
--- branches/Lucene_Integration/HibernateExt/metadata/src/java/org/hibernate/lucene/bridge/BridgeFactory.java 2006-10-17 21:37:58 UTC (rev 10599)
+++ branches/Lucene_Integration/HibernateExt/metadata/src/java/org/hibernate/lucene/bridge/BridgeFactory.java 2006-10-17 23:58:05 UTC (rev 10600)
@@ -1,8 +1,6 @@
//$Id: $
package org.hibernate.lucene.bridge;
-import java.lang.reflect.AnnotatedElement;
-import java.lang.reflect.Member;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;
@@ -11,7 +9,7 @@
import org.hibernate.reflection.XMember;
import org.hibernate.reflection.XClass;
import org.hibernate.annotations.Parameter;
-import org.hibernate.lucene.util.BinderHelper;
+import org.hibernate.lucene.DateBridge;
/**
* @author Emmanuel Bernard
@@ -49,25 +47,16 @@
builtInBridges.put( long.class.getName(), LONG );
builtInBridges.put( String.class.getName(), STRING );
- DATE_YEAR = createDateBridge( Resolution.YEAR );
- DATE_MONTH = createDateBridge( Resolution.MONTH );
- DATE_DAY = createDateBridge( Resolution.DAY );
- DATE_HOUR = createDateBridge( Resolution.HOUR );
- DATE_MINUTE = createDateBridge( Resolution.MINUTE );
- DATE_SECOND = createDateBridge( Resolution.SECOND );
- DATE_MILLISECOND = createDateBridge( Resolution.MILLISECOND );
+ DATE_YEAR = org.hibernate.lucene.bridge.DateBridge.DATE_YEAR;
+ DATE_MONTH = org.hibernate.lucene.bridge.DateBridge.DATE_MONTH;
+ DATE_DAY = org.hibernate.lucene.bridge.DateBridge.DATE_DAY;
+ DATE_HOUR = org.hibernate.lucene.bridge.DateBridge.DATE_HOUR;
+ DATE_MINUTE = org.hibernate.lucene.bridge.DateBridge.DATE_MINUTE;
+ DATE_SECOND = org.hibernate.lucene.bridge.DateBridge.DATE_SECOND;
+ DATE_MILLISECOND = org.hibernate.lucene.bridge.DateBridge.DATE_MILLISECOND;
builtInBridges.put( Date.class.getName(), DATE_MILLISECOND );
}
- private static FieldBridge createDateBridge(Resolution resolution) {
- DateBridge date;
- Map params = new HashMap(1);
- params.put( "resolution", resolution );
- date = new DateBridge();
- date.setParameterValues( params );
- return new String2FieldBridgeAdaptor( date );
- }
-
public static FieldBridge guessType(XMember member) {
FieldBridge bridge = null;
org.hibernate.lucene.FieldBridge bridgeAnn = member.getAnnotation( org.hibernate.lucene.FieldBridge.class );
@@ -94,7 +83,11 @@
throw new HibernateException("Unable to instanciate FieldBridge for " + member.getName(), e );
}
}
- else {
+ else if ( member.isAnnotationPresent( DateBridge.class ) ) {
+ Resolution resolution = member.getAnnotation( DateBridge.class ).value();
+ bridge = org.hibernate.lucene.bridge.DateBridge.getDateField( resolution );
+ }
+ else {
//find in built-ins
XClass returnType = member.getType();
bridge = builtInBridges.get( returnType.getName() );
Modified: branches/Lucene_Integration/HibernateExt/metadata/src/java/org/hibernate/lucene/bridge/DateBridge.java
===================================================================
--- branches/Lucene_Integration/HibernateExt/metadata/src/java/org/hibernate/lucene/bridge/DateBridge.java 2006-10-17 21:37:58 UTC (rev 10599)
+++ branches/Lucene_Integration/HibernateExt/metadata/src/java/org/hibernate/lucene/bridge/DateBridge.java 2006-10-17 23:58:05 UTC (rev 10600)
@@ -3,6 +3,7 @@
import java.text.ParseException;
import java.util.Date;
+import java.util.Locale;
import java.util.Map;
import org.apache.lucene.document.DateTools;
@@ -11,12 +12,30 @@
import org.hibernate.util.StringHelper;
/**
+ * Bridge a java.util.Date to a String, truncated to the resolution
+ * Date are stored GMT based
+ *
* @author Emmanuel Bernard
*/
public class DateBridge implements StringBridge, ParameterizedBridge {
- DateTools.Resolution resolution;
- public Object stringToObject(String stringValue) {
+ public static final String2FieldBridgeAdaptor DATE_YEAR = new String2FieldBridgeAdaptor( new DateBridge( Resolution.YEAR ) );
+ public static final String2FieldBridgeAdaptor DATE_MONTH = new String2FieldBridgeAdaptor( new DateBridge( Resolution.MONTH ) );
+ public static final String2FieldBridgeAdaptor DATE_DAY = new String2FieldBridgeAdaptor( new DateBridge( Resolution.DAY ) );
+ public static final String2FieldBridgeAdaptor DATE_HOUR = new String2FieldBridgeAdaptor( new DateBridge( Resolution.HOUR ) );
+ public static final String2FieldBridgeAdaptor DATE_MINUTE = new String2FieldBridgeAdaptor( new DateBridge( Resolution.MINUTE ) );
+ public static final String2FieldBridgeAdaptor DATE_SECOND = new String2FieldBridgeAdaptor( new DateBridge( Resolution.SECOND ) );
+ public static final String2FieldBridgeAdaptor DATE_MILLISECOND = new String2FieldBridgeAdaptor( new DateBridge( Resolution.MILLISECOND ) );
+
+ DateTools.Resolution resolution;
+
+ public DateBridge() {}
+
+ public DateBridge(Resolution resolution) {
+ setResolution( resolution );
+ }
+
+ public Object stringToObject(String stringValue) {
if ( StringHelper.isEmpty(stringValue) ) return null;
try {
return DateTools.stringToDate( stringValue );
@@ -33,32 +52,64 @@
}
public void setParameterValues(Map parameters) {
- Resolution hibResolution = (Resolution) parameters.get( "resolution" );
- switch ( hibResolution ) {
+ Object resolution = parameters.get( "resolution" );
+ Resolution hibResolution;
+ if (resolution instanceof String) {
+ hibResolution = Resolution.valueOf( ( (String) resolution ).toUpperCase( Locale.ENGLISH ) );
+ }
+ else {
+ hibResolution = (Resolution) resolution;
+ }
+ setResolution( hibResolution );
+ }
+
+ private void setResolution(Resolution hibResolution) {
+ switch ( hibResolution ) {
case YEAR:
- resolution = DateTools.Resolution.YEAR;
+ this.resolution = DateTools.Resolution.YEAR;
break;
case MONTH:
- resolution = DateTools.Resolution.MONTH;
+ this.resolution = DateTools.Resolution.MONTH;
break;
case DAY:
- resolution = DateTools.Resolution.DAY;
+ this.resolution = DateTools.Resolution.DAY;
break;
case HOUR:
- resolution = DateTools.Resolution.HOUR;
+ this.resolution = DateTools.Resolution.HOUR;
break;
case MINUTE:
- resolution = DateTools.Resolution.MINUTE;
+ this.resolution = DateTools.Resolution.MINUTE;
break;
case SECOND:
- resolution = DateTools.Resolution.SECOND;
+ this.resolution = DateTools.Resolution.SECOND;
break;
case MILLISECOND:
- resolution = DateTools.Resolution.MILLISECOND;
+ this.resolution = DateTools.Resolution.MILLISECOND;
break;
default:
throw new AssertionFailure( "Unknown Resolution: " + hibResolution );
}
- }
+ }
+
+ public static String2FieldBridgeAdaptor getDateField(Resolution resolution) {
+ switch( resolution ) {
+ case YEAR:
+ return DATE_YEAR;
+ case MONTH:
+ return DATE_MONTH;
+ case DAY:
+ return DATE_DAY;
+ case HOUR:
+ return DATE_HOUR;
+ case MINUTE:
+ return DATE_MINUTE;
+ case SECOND:
+ return DATE_SECOND;
+ case MILLISECOND:
+ return DATE_MILLISECOND;
+ default:
+ throw new AssertionFailure( "Unknown Resolution: " + resolution );
+ }
+ }
}
Modified: branches/Lucene_Integration/HibernateExt/metadata/src/test/org/hibernate/lucene/test/bridge/BridgeTest.java
===================================================================
--- branches/Lucene_Integration/HibernateExt/metadata/src/test/org/hibernate/lucene/test/bridge/BridgeTest.java 2006-10-17 21:37:58 UTC (rev 10599)
+++ branches/Lucene_Integration/HibernateExt/metadata/src/test/org/hibernate/lucene/test/bridge/BridgeTest.java 2006-10-17 23:58:05 UTC (rev 10600)
@@ -5,6 +5,7 @@
import java.util.List;
import java.util.GregorianCalendar;
import java.util.Calendar;
+import java.util.TimeZone;
import org.hibernate.Transaction;
@@ -60,8 +61,19 @@
public void testDateBridge() throws Exception {
Cloud cloud = new Cloud();
Calendar c = GregorianCalendar.getInstance();
- c.set(2000, 11, 15);
- cloud.setDate( c.getTime() );
+ c.setTimeZone( TimeZone.getTimeZone( "GMT" ) ); //for the sake of tests
+ c.set(2000, 11, 15, 3, 43, 2);
+ c.set( Calendar.MILLISECOND, 5 );
+
+ Date date = new Date( c.getTimeInMillis() );
+ cloud.setDate( date ); //5 millisecond
+ cloud.setDateDay( date );
+ cloud.setDateHour( date );
+ cloud.setDateMillisecond( date );
+ cloud.setDateMinute( date );
+ cloud.setDateMonth( date );
+ cloud.setDateSecond( date );
+ cloud.setDateYear( date );
org.hibernate.Session s = openSession();
Transaction tx = s.beginTransaction();
s.persist(cloud);
@@ -74,9 +86,17 @@
Query query;
List result;
- query = parser.parse("date:[19900101 TO 20060101]");
+ query = parser.parse("date:[19900101 TO 20060101]"
+ + " AND dateDay:[20001214 TO 2000121501]"
+ + " AND dateMonth:[200012 TO 20001201]"
+ + " AND dateYear:[2000 TO 200001]"
+ + " AND dateHour:[20001214 TO 2000121503]"
+ + " AND dateMinute:[20001214 TO 200012150343]"
+ + " AND dateSecond:[20001214 TO 20001215034302]"
+ + " AND dateMillisecond:[20001214 TO 20001215034302005]"
+ );
result = session.createLuceneQuery(query).list();
- assertEquals( "date found", 1, result.size() );
+ assertEquals( "Date not found or not property truncated", 1, result.size() );
s.delete( s.get( Cloud.class, cloud.getId() ) );
tx.commit();
Modified: branches/Lucene_Integration/HibernateExt/metadata/src/test/org/hibernate/lucene/test/bridge/Cloud.java
===================================================================
--- branches/Lucene_Integration/HibernateExt/metadata/src/test/org/hibernate/lucene/test/bridge/Cloud.java 2006-10-17 21:37:58 UTC (rev 10599)
+++ branches/Lucene_Integration/HibernateExt/metadata/src/test/org/hibernate/lucene/test/bridge/Cloud.java 2006-10-17 23:58:05 UTC (rev 10600)
@@ -8,10 +8,9 @@
import org.hibernate.lucene.Keyword;
import org.hibernate.lucene.Indexed;
-import org.hibernate.lucene.FieldBridge;
import org.hibernate.lucene.Text;
-import org.hibernate.lucene.bridge.DateBridge;
-import org.hibernate.annotations.Parameter;
+import org.hibernate.lucene.DateBridge;
+import org.hibernate.lucene.bridge.Resolution;
/**
* @author Emmanuel Bernard
@@ -34,6 +33,7 @@
private Date dateMonth;
private Date dateDay;
private Date dateHour;
+ private Date dateMinute;
private Date dateSecond;
private Date dateMillisecond;
@@ -126,7 +126,7 @@
public void setString(String string) {
this.string = string;
}
- //FIXME DATE and RESOLUTION
+
@Keyword
public Date getDate() {
return date;
@@ -136,6 +136,8 @@
this.date = date;
}
+ @Keyword
+ @DateBridge( Resolution.YEAR )
public Date getDateYear() {
return dateYear;
}
@@ -144,6 +146,8 @@
this.dateYear = dateYear;
}
+ @Keyword
+ @DateBridge( Resolution.MONTH )
public Date getDateMonth() {
return dateMonth;
}
@@ -152,6 +156,8 @@
this.dateMonth = dateMonth;
}
+ @Keyword
+ @DateBridge( Resolution.DAY )
public Date getDateDay() {
return dateDay;
}
@@ -160,6 +166,8 @@
this.dateDay = dateDay;
}
+ @Keyword
+ @DateBridge( Resolution.HOUR )
public Date getDateHour() {
return dateHour;
}
@@ -168,6 +176,19 @@
this.dateHour = dateHour;
}
+
+ @Keyword
+ @DateBridge( Resolution.MINUTE )
+ public Date getDateMinute() {
+ return dateMinute;
+ }
+
+ public void setDateMinute(Date dateMinute) {
+ this.dateMinute = dateMinute;
+ }
+
+ @Keyword
+ @DateBridge( Resolution.SECOND )
public Date getDateSecond() {
return dateSecond;
}
@@ -176,6 +197,8 @@
this.dateSecond = dateSecond;
}
+ @Keyword
+ @DateBridge( Resolution.MILLISECOND )
public Date getDateMillisecond() {
return dateMillisecond;
}
18 years, 11 months
about Hibernate and EJB
by Chaohua Wang
Folks,
I EJB entity bean specification. Looks like EJB entity bean can be
called remotely with JNDI, which means Entity can be downloaded as a
copy from different JVM. But seems Hibernate object can not do it.
am I right?
Thank you very much.
Chaohua
18 years, 11 months
Hibernate SVN: r10599 - trunk/Hibernate3/test/org/hibernate/test/optlock
by hibernate-commits@lists.jboss.org
Author: steve.ebersole(a)jboss.com
Date: 2006-10-17 17:37:58 -0400 (Tue, 17 Oct 2006)
New Revision: 10599
Modified:
trunk/Hibernate3/test/org/hibernate/test/optlock/OptimisticLockTest.java
Log:
test in case of versioning + batching
Modified: trunk/Hibernate3/test/org/hibernate/test/optlock/OptimisticLockTest.java
===================================================================
--- trunk/Hibernate3/test/org/hibernate/test/optlock/OptimisticLockTest.java 2006-10-17 21:37:42 UTC (rev 10598)
+++ trunk/Hibernate3/test/org/hibernate/test/optlock/OptimisticLockTest.java 2006-10-17 21:37:58 UTC (rev 10599)
@@ -4,13 +4,11 @@
import junit.framework.Test;
import junit.framework.TestSuite;
+import org.hibernate.JDBCException;
import org.hibernate.Session;
import org.hibernate.StaleObjectStateException;
-import org.hibernate.Transaction;
-import org.hibernate.JDBCException;
+import org.hibernate.StaleStateException;
import org.hibernate.dialect.SQLServerDialect;
-import org.hibernate.cfg.Configuration;
-import org.hibernate.cfg.Environment;
import org.hibernate.test.TestCase;
/**
@@ -29,11 +27,6 @@
return new String[] { "optlock/Document.hbm.xml" };
}
- protected void configure(Configuration cfg) {
- super.configure( cfg );
- cfg.setProperty( Environment.BATCH_VERSIONED_DATA, "false" );
- }
-
public static Test suite() {
return new TestSuite(OptimisticLockTest.class);
}
@@ -55,23 +48,23 @@
}
private void testUpdateOptimisticLockFailure(String entityName) {
- Session s = openSession();
- Transaction t = s.beginTransaction();
+ Session mainSession = openSession();
+ mainSession.beginTransaction();
Document doc = new Document();
doc.setTitle( "Hibernate in Action" );
doc.setAuthor( "Bauer et al" );
doc.setSummary( "Very boring book about persistence" );
doc.setText( "blah blah yada yada yada" );
doc.setPubDate( new PublicationDate( 2004 ) );
- s.save( entityName, doc );
- t.commit();
- s.close();
+ mainSession.save( entityName, doc );
+ mainSession.getTransaction().commit();
+ mainSession.close();
- s = openSession();
- t = s.beginTransaction();
- doc = ( Document ) s.get( entityName, doc.getId() );
+ mainSession = openSession();
+ mainSession.beginTransaction();
+ doc = ( Document ) mainSession.get( entityName, doc.getId() );
- Session otherSession = openSession();
+ Session otherSession = getSessions().openSession();
otherSession.beginTransaction();
Document otherDoc = ( Document ) otherSession.get( entityName, doc.getId() );
otherDoc.setSummary( "A modern classic" );
@@ -80,12 +73,15 @@
try {
doc.setSummary( "A machiavelian achievement of epic proportions" );
- s.flush();
+ mainSession.flush();
fail( "expecting opt lock failure" );
}
catch ( StaleObjectStateException expected ) {
// expected result...
}
+ catch( StaleStateException expected ) {
+ // expected result (if using versioned batching)...
+ }
catch( JDBCException e ) {
// SQLServer will report this condition via a SQLException
// when using its SNAPSHOT transaction isolation...
@@ -94,60 +90,63 @@
}
else {
// it seems to "lose track" of the transaction as well...
- t.rollback();
- t = s.beginTransaction();
+ mainSession.getTransaction().rollback();
+ mainSession.beginTransaction();
}
}
- s.clear();
- t.commit();
- s.close();
+ mainSession.clear();
+ mainSession.getTransaction().commit();
+ mainSession.close();
- s = openSession();
- t = s.beginTransaction();
- doc = ( Document ) s.load( entityName, doc.getId() );
- s.delete( entityName, doc );
- t.commit();
- s.close();
+ mainSession = openSession();
+ mainSession.beginTransaction();
+ doc = ( Document ) mainSession.load( entityName, doc.getId() );
+ mainSession.delete( entityName, doc );
+ mainSession.getTransaction().commit();
+ mainSession.close();
}
private void testDeleteOptimisticLockFailure(String entityName) {
- Session s = openSession();
- Transaction t = s.beginTransaction();
+ Session mainSession = openSession();
+ mainSession.beginTransaction();
Document doc = new Document();
doc.setTitle( "Hibernate in Action" );
doc.setAuthor( "Bauer et al" );
doc.setSummary( "Very boring book about persistence" );
doc.setText( "blah blah yada yada yada" );
doc.setPubDate( new PublicationDate( 2004 ) );
- s.save( entityName, doc );
- s.flush();
+ mainSession.save( entityName, doc );
+ mainSession.flush();
doc.setSummary( "A modern classic" );
- s.flush();
+ mainSession.flush();
doc.getPubDate().setMonth( new Integer( 3 ) );
- s.flush();
- t.commit();
- s.close();
+ mainSession.flush();
+ mainSession.getTransaction().commit();
+ mainSession.close();
- s = openSession();
- t = s.beginTransaction();
- doc = ( Document ) s.get( entityName, doc.getId() );
+ mainSession = openSession();
+ mainSession.beginTransaction();
+ doc = ( Document ) mainSession.get( entityName, doc.getId() );
- Session other = openSession();
- Transaction othert = other.beginTransaction();
- Document otherDoc = ( Document ) other.get( entityName, doc.getId() );
+ Session otherSession = openSession();
+ otherSession.beginTransaction();
+ Document otherDoc = ( Document ) otherSession.get( entityName, doc.getId() );
otherDoc.setSummary( "my other summary" );
- other.flush();
- othert.commit();
- other.close();
+ otherSession.flush();
+ otherSession.getTransaction().commit();
+ otherSession.close();
try {
- s.delete( doc );
- s.flush();
+ mainSession.delete( doc );
+ mainSession.flush();
fail( "expecting opt lock failure" );
}
catch ( StaleObjectStateException e ) {
// expected
}
+ catch( StaleStateException expected ) {
+ // expected result (if using versioned batching)...
+ }
catch( JDBCException e ) {
// SQLServer will report this condition via a SQLException
// when using its SNAPSHOT transaction isolation...
@@ -156,20 +155,20 @@
}
else {
// it seems to "lose track" of the transaction as well...
- t.rollback();
- t = s.beginTransaction();
+ mainSession.getTransaction().rollback();
+ mainSession.beginTransaction();
}
}
- s.clear();
- t.commit();
- s.close();
+ mainSession.clear();
+ mainSession.getTransaction().commit();
+ mainSession.close();
- s = openSession();
- t = s.beginTransaction();
- doc = ( Document ) s.load( entityName, doc.getId() );
- s.delete( entityName, doc );
- t.commit();
- s.close();
+ mainSession = openSession();
+ mainSession.beginTransaction();
+ doc = ( Document ) mainSession.load( entityName, doc.getId() );
+ mainSession.delete( entityName, doc );
+ mainSession.getTransaction().commit();
+ mainSession.close();
}
}
18 years, 11 months
Hibernate SVN: r10598 - branches/Branch_3_2/Hibernate3/test/org/hibernate/test/optlock
by hibernate-commits@lists.jboss.org
Author: steve.ebersole(a)jboss.com
Date: 2006-10-17 17:37:42 -0400 (Tue, 17 Oct 2006)
New Revision: 10598
Modified:
branches/Branch_3_2/Hibernate3/test/org/hibernate/test/optlock/OptimisticLockTest.java
Log:
test in case of versioning + batching
Modified: branches/Branch_3_2/Hibernate3/test/org/hibernate/test/optlock/OptimisticLockTest.java
===================================================================
--- branches/Branch_3_2/Hibernate3/test/org/hibernate/test/optlock/OptimisticLockTest.java 2006-10-17 21:30:03 UTC (rev 10597)
+++ branches/Branch_3_2/Hibernate3/test/org/hibernate/test/optlock/OptimisticLockTest.java 2006-10-17 21:37:42 UTC (rev 10598)
@@ -4,13 +4,11 @@
import junit.framework.Test;
import junit.framework.TestSuite;
+import org.hibernate.JDBCException;
import org.hibernate.Session;
import org.hibernate.StaleObjectStateException;
-import org.hibernate.Transaction;
-import org.hibernate.JDBCException;
+import org.hibernate.StaleStateException;
import org.hibernate.dialect.SQLServerDialect;
-import org.hibernate.cfg.Configuration;
-import org.hibernate.cfg.Environment;
import org.hibernate.test.TestCase;
/**
@@ -29,11 +27,6 @@
return new String[] { "optlock/Document.hbm.xml" };
}
- protected void configure(Configuration cfg) {
- super.configure( cfg );
- cfg.setProperty( Environment.BATCH_VERSIONED_DATA, "false" );
- }
-
public static Test suite() {
return new TestSuite(OptimisticLockTest.class);
}
@@ -53,25 +46,24 @@
public void testOptimisticLockAllDelete() {
testDeleteOptimisticLockFailure( "LockAll" );
}
-
private void testUpdateOptimisticLockFailure(String entityName) {
- Session s = openSession();
- Transaction t = s.beginTransaction();
+ Session mainSession = openSession();
+ mainSession.beginTransaction();
Document doc = new Document();
doc.setTitle( "Hibernate in Action" );
doc.setAuthor( "Bauer et al" );
doc.setSummary( "Very boring book about persistence" );
doc.setText( "blah blah yada yada yada" );
doc.setPubDate( new PublicationDate( 2004 ) );
- s.save( entityName, doc );
- t.commit();
- s.close();
+ mainSession.save( entityName, doc );
+ mainSession.getTransaction().commit();
+ mainSession.close();
- s = openSession();
- t = s.beginTransaction();
- doc = ( Document ) s.get( entityName, doc.getId() );
+ mainSession = openSession();
+ mainSession.beginTransaction();
+ doc = ( Document ) mainSession.get( entityName, doc.getId() );
- Session otherSession = openSession();
+ Session otherSession = getSessions().openSession();
otherSession.beginTransaction();
Document otherDoc = ( Document ) otherSession.get( entityName, doc.getId() );
otherDoc.setSummary( "A modern classic" );
@@ -80,12 +72,15 @@
try {
doc.setSummary( "A machiavelian achievement of epic proportions" );
- s.flush();
+ mainSession.flush();
fail( "expecting opt lock failure" );
}
catch ( StaleObjectStateException expected ) {
// expected result...
}
+ catch( StaleStateException expected ) {
+ // expected result (if using versioned batching)...
+ }
catch( JDBCException e ) {
// SQLServer will report this condition via a SQLException
// when using its SNAPSHOT transaction isolation...
@@ -94,60 +89,63 @@
}
else {
// it seems to "lose track" of the transaction as well...
- t.rollback();
- t = s.beginTransaction();
+ mainSession.getTransaction().rollback();
+ mainSession.beginTransaction();
}
}
- s.clear();
- t.commit();
- s.close();
+ mainSession.clear();
+ mainSession.getTransaction().commit();
+ mainSession.close();
- s = openSession();
- t = s.beginTransaction();
- doc = ( Document ) s.load( entityName, doc.getId() );
- s.delete( entityName, doc );
- t.commit();
- s.close();
+ mainSession = openSession();
+ mainSession.beginTransaction();
+ doc = ( Document ) mainSession.load( entityName, doc.getId() );
+ mainSession.delete( entityName, doc );
+ mainSession.getTransaction().commit();
+ mainSession.close();
}
private void testDeleteOptimisticLockFailure(String entityName) {
- Session s = openSession();
- Transaction t = s.beginTransaction();
+ Session mainSession = openSession();
+ mainSession.beginTransaction();
Document doc = new Document();
doc.setTitle( "Hibernate in Action" );
doc.setAuthor( "Bauer et al" );
doc.setSummary( "Very boring book about persistence" );
doc.setText( "blah blah yada yada yada" );
doc.setPubDate( new PublicationDate( 2004 ) );
- s.save( entityName, doc );
- s.flush();
+ mainSession.save( entityName, doc );
+ mainSession.flush();
doc.setSummary( "A modern classic" );
- s.flush();
+ mainSession.flush();
doc.getPubDate().setMonth( new Integer( 3 ) );
- s.flush();
- t.commit();
- s.close();
+ mainSession.flush();
+ mainSession.getTransaction().commit();
+ mainSession.close();
- s = openSession();
- t = s.beginTransaction();
- doc = ( Document ) s.get( entityName, doc.getId() );
+ mainSession = openSession();
+ mainSession.beginTransaction();
+ doc = ( Document ) mainSession.get( entityName, doc.getId() );
- Session other = openSession();
- Transaction othert = other.beginTransaction();
- Document otherDoc = ( Document ) other.get( entityName, doc.getId() );
+ Session otherSession = openSession();
+ otherSession.beginTransaction();
+ Document otherDoc = ( Document ) otherSession.get( entityName, doc.getId() );
otherDoc.setSummary( "my other summary" );
- other.flush();
- othert.commit();
- other.close();
+ otherSession.flush();
+ otherSession.getTransaction().commit();
+ otherSession.close();
try {
- s.delete( doc );
- s.flush();
+ mainSession.delete( doc );
+ mainSession.flush();
fail( "expecting opt lock failure" );
}
catch ( StaleObjectStateException e ) {
// expected
}
+ catch( StaleStateException expected ) {
+ // expected result (if using versioned batching)...
+ }
catch( JDBCException e ) {
// SQLServer will report this condition via a SQLException
// when using its SNAPSHOT transaction isolation...
@@ -156,20 +154,20 @@
}
else {
// it seems to "lose track" of the transaction as well...
- t.rollback();
- t = s.beginTransaction();
+ mainSession.getTransaction().rollback();
+ mainSession.beginTransaction();
}
}
- s.clear();
- t.commit();
- s.close();
+ mainSession.clear();
+ mainSession.getTransaction().commit();
+ mainSession.close();
- s = openSession();
- t = s.beginTransaction();
- doc = ( Document ) s.load( entityName, doc.getId() );
- s.delete( entityName, doc );
- t.commit();
- s.close();
+ mainSession = openSession();
+ mainSession.beginTransaction();
+ doc = ( Document ) mainSession.load( entityName, doc.getId() );
+ mainSession.delete( entityName, doc );
+ mainSession.getTransaction().commit();
+ mainSession.close();
}
}
18 years, 11 months
Hibernate SVN: r10597 - branches/Branch_3_2/Hibernate3/test/org/hibernate/test/legacy
by hibernate-commits@lists.jboss.org
Author: steve.ebersole(a)jboss.com
Date: 2006-10-17 17:30:03 -0400 (Tue, 17 Oct 2006)
New Revision: 10597
Modified:
branches/Branch_3_2/Hibernate3/test/org/hibernate/test/legacy/MasterDetailTest.java
branches/Branch_3_2/Hibernate3/test/org/hibernate/test/legacy/MultiTableTest.java
Log:
fixed minor issue in use of save
Modified: branches/Branch_3_2/Hibernate3/test/org/hibernate/test/legacy/MasterDetailTest.java
===================================================================
--- branches/Branch_3_2/Hibernate3/test/org/hibernate/test/legacy/MasterDetailTest.java 2006-10-17 21:29:45 UTC (rev 10596)
+++ branches/Branch_3_2/Hibernate3/test/org/hibernate/test/legacy/MasterDetailTest.java 2006-10-17 21:30:03 UTC (rev 10597)
@@ -1,10 +1,6 @@
//$Id$
package org.hibernate.test.legacy;
-import java.io.ByteArrayInputStream;
-import java.io.ByteArrayOutputStream;
-import java.io.ObjectInputStream;
-import java.io.ObjectOutputStream;
import java.io.Serializable;
import java.sql.Connection;
import java.util.ArrayList;
@@ -25,13 +21,11 @@
import org.hibernate.classic.Session;
import org.hibernate.criterion.Example;
import org.hibernate.criterion.Expression;
-import org.hibernate.dialect.DerbyDialect;
import org.hibernate.dialect.HSQLDialect;
import org.hibernate.dialect.MckoiDialect;
import org.hibernate.dialect.MySQLDialect;
import org.hibernate.dialect.Oracle9Dialect;
import org.hibernate.dialect.SAPDBDialect;
-import org.hibernate.dialect.SybaseDialect;
import org.hibernate.mapping.MetaAttribute;
import org.hibernate.mapping.PersistentClass;
@@ -518,26 +512,6 @@
s.close();
}
- /*public void testCascading2() throws Exception {
- Session s = sessionsopenSession();
- Detail d1 = new Detail();
- Detail d2 = new Detail();
- Master m = new Master();
- m.getMoreDetails().add(d1);
- m.getMoreDetails().add(d2);
- Serializable mid = s.save(m);
- s.flush();
- s.connection().commit();
- s.close();
- s = sessionsopenSession();
- m = (Master) s.load(Master.class, mid);
- assertTrue( m.getMoreDetails().size()==2, "cascade save" );
- s.delete(m);
- s.flush();
- s.connection().commit();
- s.close();
- }*/
-
public void testNamedQuery() throws Exception {
Session s = openSession();
Query q = s.getNamedQuery("all_details");
@@ -546,111 +520,23 @@
s.close();
}
-
-// This stuff is tested elsewhere
-// public void testSerialization() throws Exception {
-//
-// if (getDialect() instanceof HSQLDialect) return;
-//
-// Session s = openSession();
-// Master m = new Master();
-// Detail d1 = new Detail();
-// Detail d2 = new Detail();
-// Serializable mid = s.save(m);
-// d1.setMaster(m);
-// d2.setMaster(m);
-// m.addDetail(d1);
-// m.addDetail(d2);
-// if ( (getDialect() instanceof SybaseDialect) || (getDialect() instanceof DerbyDialect) ) {
-// s.save(d1);
-// }
-// else {
-// s.save( d1, new Long(666) );
-// }
-// //s.save(d2);
-// s.flush();
-// s.connection().commit();
-// s.disconnect();
-// ByteArrayOutputStream os = new ByteArrayOutputStream();
-// new ObjectOutputStream(os).writeObject(s);
-// byte[] bytes = os.toByteArray();
-// System.out.println(bytes.length);
-// s = (Session) new ObjectInputStream( new ByteArrayInputStream(bytes) ).readObject();
-// s.reconnect();
-// Master m2 = (Master) s.load(Master.class, mid);
-// assertTrue( "serialized state", m2.getDetails().size()==2 );
-// Iterator iter = m2.getDetails().iterator();
-// while ( iter.hasNext() ) {
-// Detail d = (Detail) iter.next();
-// assertTrue( "deserialization", d.getMaster()==m2 );
-// try {
-// s.getIdentifier(d);
-// s.delete(d);
-// }
-// catch (Exception e) {}
-// }
-// s.delete(m2);
-// s.flush();
-// s.connection().commit();
-// s.close();
-//
-// s = openSession();
-// mid = s.save( new Master() );
-// Serializable mid2 = s.save( new Master() );
-// s.flush();
-// s.connection().commit();
-// s.disconnect();
-// os = new ByteArrayOutputStream();
-// new ObjectOutputStream(os).writeObject(s);
-// bytes = os.toByteArray();
-// System.out.println(bytes.length);
-// s = (Session) new ObjectInputStream( new ByteArrayInputStream(bytes) ).readObject();
-// s.reconnect();
-// s.delete( s.load(Master.class, mid) );
-// s.delete( s.load(Master.class, mid2) );
-// s.flush();
-// s.connection().commit();
-// s.close();
-//
-// s = openSession();
-// s.connection(); //force session to grab a connection
-// try {
-// os = new ByteArrayOutputStream();
-// new ObjectOutputStream(os).writeObject(s);
-// }
-// catch (Exception e) {
-// assertTrue("illegal state", e instanceof IllegalStateException );
-// s.connection().commit();
-// s.close();
-// return;
-// }
-// assertTrue("serialization should have failed", false);
-//
-// }
-
public void testUpdateLazyCollections() throws Exception {
-
Session s = openSession();
Master m = new Master();
+ Serializable mid = s.save(m);
Detail d1 = new Detail();
Detail d2 = new Detail();
d2.setX(14);
- Serializable mid = s.save(m);
- //s.flush();
d1.setMaster(m);
d2.setMaster(m);
+ s.save(d1);
+ s.save(d2);
m.addDetail(d1);
m.addDetail(d2);
- if ( (getDialect() instanceof SybaseDialect) || (getDialect() instanceof DerbyDialect) ) {
- s.save(d1); s.save(d2);
- }
- else {
- s.save( d1, new Long(666) );
- s.save( d2, new Long(667) );
- }
s.flush();
s.connection().commit();
s.close();
+
s = openSession();
m = (Master) s.load(Master.class, mid);
s.connection().commit();
@@ -671,7 +557,6 @@
s.flush();
s.connection().commit();
s.close();
-
}
public void testMultiLevelCascade() throws Exception {
Modified: branches/Branch_3_2/Hibernate3/test/org/hibernate/test/legacy/MultiTableTest.java
===================================================================
--- branches/Branch_3_2/Hibernate3/test/org/hibernate/test/legacy/MultiTableTest.java 2006-10-17 21:29:45 UTC (rev 10596)
+++ branches/Branch_3_2/Hibernate3/test/org/hibernate/test/legacy/MultiTableTest.java 2006-10-17 21:30:03 UTC (rev 10597)
@@ -19,6 +19,7 @@
import org.hibernate.classic.Session;
import org.hibernate.criterion.Expression;
import org.hibernate.Transaction;
+import org.hibernate.id.PostInsertIdentifierGenerator;
import org.hibernate.dialect.MySQLDialect;
import org.hibernate.dialect.SybaseDialect;
@@ -159,15 +160,8 @@
}
public void testQueries() throws Exception {
-
Session s = openSession();
- Long id = new Long(1);
- if (getDialect() instanceof SybaseDialect) { // chekked because identity insert not possible with predefined value.
- id = (Long) s.save( new TrivialClass() );
- }
- else{
- s.save( new TrivialClass(), id );
- }
+ Long id = ( Long ) s.save( new TrivialClass() );
s.flush();
s.connection().commit();
@@ -191,17 +185,11 @@
}
public void testConstraints() throws Exception {
-
Session s = openSession();
Transaction t = s.beginTransaction();
SubMulti sm = new SubMulti();
sm.setAmount(66.5f);
- if ( getDialect() instanceof SybaseDialect ) {
- s.save(sm);
- }
- else {
- s.save( sm, new Long(2) );
- }
+ s.save( sm );
t.commit();
s.close();
s = openSession();
@@ -212,39 +200,21 @@
}
public void testMultiTable() throws Exception {
-
Session s = openSession();
Transaction t = s.beginTransaction();
Multi multi = new Multi();
multi.setExtraProp("extra");
- //multi.setCount(666);
multi.setName("name");
Top simp = new Top();
simp.setDate( new Date() );
simp.setName("simp");
- //simp.setCount(132);
- Serializable mid;
- Serializable sid;
- if ( getDialect() instanceof SybaseDialect ) {
- mid = s.save(multi);
- sid = s.save(simp);
- }
- else {
- mid = new Long(123);
- s.save(multi, mid);
- sid = new Long(1234);
- s.save(simp, sid);
- }
+
+ Serializable mid = s.save(multi);
+ Serializable sid = s.save(simp);
+
SubMulti sm = new SubMulti();
sm.setAmount(66.5f);
- Serializable smid;
- if (getDialect() instanceof SybaseDialect) {
- smid = s.save(sm);
- }
- else {
- smid = new Long(2);
- s.save(sm, smid);
- }
+ Serializable smid = s.save(sm);
t.commit();
s.close();
@@ -483,30 +453,19 @@
}
public void testMultiTableCollections() throws Exception {
-
Session s = openSession();
Transaction t = s.beginTransaction();
assertTrue( s.find("from Top").size()==0 );
Multi multi = new Multi();
multi.setExtraProp("extra");
- //multi.setCount(666);
multi.setName("name");
Top simp = new Top();
simp.setDate( new Date() );
simp.setName("simp");
- //simp.setCount(132);
- Serializable mid;
- Serializable sid;
- if ( getDialect() instanceof SybaseDialect ) {
- mid = s.save(multi);
- sid = s.save(simp);
- }
- else {
- mid = new Long(123);
- sid = new Long(1234);
- s.save(multi, mid);
- s.save(simp, sid);
- }
+
+ s.save(multi);
+ s.save(simp);
+
Lower ls = new Lower();
ls.setOther(ls);
ls.setAnother(ls);
@@ -516,14 +475,7 @@
ls.setSet(set);
set.add(multi);
set.add(simp);
- Serializable id;
- if ( getDialect() instanceof SybaseDialect ) {
- id = s.save(ls);
- }
- else {
- id = new Long(2);
- s.save( ls, new Long(2) );
- }
+ Serializable id = s.save(ls);
t.commit();
s.close();
assertTrue( ls.getOther()==ls && ls.getAnother()==ls && ls.getYetanother()==ls );
@@ -548,39 +500,22 @@
}
public void testMultiTableManyToOne() throws Exception {
-
Session s = openSession();
Transaction t = s.beginTransaction();
assertTrue( s.find("from Top").size()==0 );
Multi multi = new Multi();
multi.setExtraProp("extra");
- //multi.setCount(666);
multi.setName("name");
Top simp = new Top();
simp.setDate( new Date() );
simp.setName("simp");
- //simp.setCount(132);
- Serializable mid;
- if ( getDialect() instanceof SybaseDialect ) {
- mid = s.save(multi);
- }
- else {
- mid = new Long(123);
- s.save(multi, mid);
- }
+ s.save(multi);
Lower ls = new Lower();
ls.setOther(ls);
ls.setAnother(multi);
ls.setYetanother(ls);
ls.setName("Less Simple");
- Serializable id;
- if ( getDialect() instanceof SybaseDialect ) {
- id = s.save(ls);
- }
- else {
- id = new Long(2);
- s.save( ls, new Long(2) );
- }
+ Serializable id = s.save(ls);
t.commit();
s.close();
assertTrue( ls.getOther()==ls && ls.getAnother()==multi && ls.getYetanother()==ls );
18 years, 11 months
Hibernate SVN: r10596 - trunk/Hibernate3/test/org/hibernate/test/legacy
by hibernate-commits@lists.jboss.org
Author: steve.ebersole(a)jboss.com
Date: 2006-10-17 17:29:45 -0400 (Tue, 17 Oct 2006)
New Revision: 10596
Modified:
trunk/Hibernate3/test/org/hibernate/test/legacy/MasterDetailTest.java
trunk/Hibernate3/test/org/hibernate/test/legacy/MultiTableTest.java
Log:
fixed minor issue in use of save
Modified: trunk/Hibernate3/test/org/hibernate/test/legacy/MasterDetailTest.java
===================================================================
--- trunk/Hibernate3/test/org/hibernate/test/legacy/MasterDetailTest.java 2006-10-17 21:18:17 UTC (rev 10595)
+++ trunk/Hibernate3/test/org/hibernate/test/legacy/MasterDetailTest.java 2006-10-17 21:29:45 UTC (rev 10596)
@@ -518,26 +518,6 @@
s.close();
}
- /*public void testCascading2() throws Exception {
- Session s = sessionsopenSession();
- Detail d1 = new Detail();
- Detail d2 = new Detail();
- Master m = new Master();
- m.getMoreDetails().add(d1);
- m.getMoreDetails().add(d2);
- Serializable mid = s.save(m);
- s.flush();
- s.connection().commit();
- s.close();
- s = sessionsopenSession();
- m = (Master) s.load(Master.class, mid);
- assertTrue( m.getMoreDetails().size()==2, "cascade save" );
- s.delete(m);
- s.flush();
- s.connection().commit();
- s.close();
- }*/
-
public void testNamedQuery() throws Exception {
Session s = openSession();
Query q = s.getNamedQuery("all_details");
@@ -546,111 +526,23 @@
s.close();
}
-
-// This stuff is tested elsewhere
-// public void testSerialization() throws Exception {
-//
-// if (getDialect() instanceof HSQLDialect) return;
-//
-// Session s = openSession();
-// Master m = new Master();
-// Detail d1 = new Detail();
-// Detail d2 = new Detail();
-// Serializable mid = s.save(m);
-// d1.setMaster(m);
-// d2.setMaster(m);
-// m.addDetail(d1);
-// m.addDetail(d2);
-// if ( (getDialect() instanceof SybaseDialect) || (getDialect() instanceof DerbyDialect) ) {
-// s.save(d1);
-// }
-// else {
-// s.save( d1, new Long(666) );
-// }
-// //s.save(d2);
-// s.flush();
-// s.connection().commit();
-// s.disconnect();
-// ByteArrayOutputStream os = new ByteArrayOutputStream();
-// new ObjectOutputStream(os).writeObject(s);
-// byte[] bytes = os.toByteArray();
-// System.out.println(bytes.length);
-// s = (Session) new ObjectInputStream( new ByteArrayInputStream(bytes) ).readObject();
-// s.reconnect();
-// Master m2 = (Master) s.load(Master.class, mid);
-// assertTrue( "serialized state", m2.getDetails().size()==2 );
-// Iterator iter = m2.getDetails().iterator();
-// while ( iter.hasNext() ) {
-// Detail d = (Detail) iter.next();
-// assertTrue( "deserialization", d.getMaster()==m2 );
-// try {
-// s.getIdentifier(d);
-// s.delete(d);
-// }
-// catch (Exception e) {}
-// }
-// s.delete(m2);
-// s.flush();
-// s.connection().commit();
-// s.close();
-//
-// s = openSession();
-// mid = s.save( new Master() );
-// Serializable mid2 = s.save( new Master() );
-// s.flush();
-// s.connection().commit();
-// s.disconnect();
-// os = new ByteArrayOutputStream();
-// new ObjectOutputStream(os).writeObject(s);
-// bytes = os.toByteArray();
-// System.out.println(bytes.length);
-// s = (Session) new ObjectInputStream( new ByteArrayInputStream(bytes) ).readObject();
-// s.reconnect();
-// s.delete( s.load(Master.class, mid) );
-// s.delete( s.load(Master.class, mid2) );
-// s.flush();
-// s.connection().commit();
-// s.close();
-//
-// s = openSession();
-// s.connection(); //force session to grab a connection
-// try {
-// os = new ByteArrayOutputStream();
-// new ObjectOutputStream(os).writeObject(s);
-// }
-// catch (Exception e) {
-// assertTrue("illegal state", e instanceof IllegalStateException );
-// s.connection().commit();
-// s.close();
-// return;
-// }
-// assertTrue("serialization should have failed", false);
-//
-// }
-
public void testUpdateLazyCollections() throws Exception {
-
Session s = openSession();
Master m = new Master();
+ Serializable mid = s.save(m);
Detail d1 = new Detail();
Detail d2 = new Detail();
d2.setX(14);
- Serializable mid = s.save(m);
- //s.flush();
d1.setMaster(m);
d2.setMaster(m);
+ s.save(d1);
+ s.save(d2);
m.addDetail(d1);
m.addDetail(d2);
- if ( (getDialect() instanceof SybaseDialect) || (getDialect() instanceof DerbyDialect) ) {
- s.save(d1); s.save(d2);
- }
- else {
- s.save( d1, new Long(666) );
- s.save( d2, new Long(667) );
- }
s.flush();
s.connection().commit();
s.close();
+
s = openSession();
m = (Master) s.load(Master.class, mid);
s.connection().commit();
@@ -671,7 +563,6 @@
s.flush();
s.connection().commit();
s.close();
-
}
public void testMultiLevelCascade() throws Exception {
Modified: trunk/Hibernate3/test/org/hibernate/test/legacy/MultiTableTest.java
===================================================================
--- trunk/Hibernate3/test/org/hibernate/test/legacy/MultiTableTest.java 2006-10-17 21:18:17 UTC (rev 10595)
+++ trunk/Hibernate3/test/org/hibernate/test/legacy/MultiTableTest.java 2006-10-17 21:29:45 UTC (rev 10596)
@@ -16,11 +16,10 @@
import org.hibernate.Criteria;
import org.hibernate.FetchMode;
import org.hibernate.LockMode;
+import org.hibernate.Transaction;
import org.hibernate.classic.Session;
import org.hibernate.criterion.Expression;
-import org.hibernate.Transaction;
import org.hibernate.dialect.MySQLDialect;
-import org.hibernate.dialect.SybaseDialect;
public class MultiTableTest extends LegacyTestCase {
@@ -159,15 +158,8 @@
}
public void testQueries() throws Exception {
-
Session s = openSession();
- Long id = new Long(1);
- if (getDialect() instanceof SybaseDialect) { // chekked because identity insert not possible with predefined value.
- id = (Long) s.save( new TrivialClass() );
- }
- else{
- s.save( new TrivialClass(), id );
- }
+ Long id = ( Long ) s.save( new TrivialClass() );
s.flush();
s.connection().commit();
@@ -191,17 +183,11 @@
}
public void testConstraints() throws Exception {
-
Session s = openSession();
Transaction t = s.beginTransaction();
SubMulti sm = new SubMulti();
sm.setAmount(66.5f);
- if ( getDialect() instanceof SybaseDialect ) {
- s.save(sm);
- }
- else {
- s.save( sm, new Long(2) );
- }
+ s.save( sm );
t.commit();
s.close();
s = openSession();
@@ -212,39 +198,21 @@
}
public void testMultiTable() throws Exception {
-
Session s = openSession();
Transaction t = s.beginTransaction();
Multi multi = new Multi();
multi.setExtraProp("extra");
- //multi.setCount(666);
multi.setName("name");
Top simp = new Top();
simp.setDate( new Date() );
simp.setName("simp");
- //simp.setCount(132);
- Serializable mid;
- Serializable sid;
- if ( getDialect() instanceof SybaseDialect ) {
- mid = s.save(multi);
- sid = s.save(simp);
- }
- else {
- mid = new Long(123);
- s.save(multi, mid);
- sid = new Long(1234);
- s.save(simp, sid);
- }
+
+ Serializable mid = s.save(multi);
+ Serializable sid = s.save(simp);
+
SubMulti sm = new SubMulti();
sm.setAmount(66.5f);
- Serializable smid;
- if (getDialect() instanceof SybaseDialect) {
- smid = s.save(sm);
- }
- else {
- smid = new Long(2);
- s.save(sm, smid);
- }
+ Serializable smid = s.save(sm);
t.commit();
s.close();
@@ -483,30 +451,19 @@
}
public void testMultiTableCollections() throws Exception {
-
Session s = openSession();
Transaction t = s.beginTransaction();
assertTrue( s.find("from Top").size()==0 );
Multi multi = new Multi();
multi.setExtraProp("extra");
- //multi.setCount(666);
multi.setName("name");
Top simp = new Top();
simp.setDate( new Date() );
simp.setName("simp");
- //simp.setCount(132);
- Serializable mid;
- Serializable sid;
- if ( getDialect() instanceof SybaseDialect ) {
- mid = s.save(multi);
- sid = s.save(simp);
- }
- else {
- mid = new Long(123);
- sid = new Long(1234);
- s.save(multi, mid);
- s.save(simp, sid);
- }
+
+ s.save(multi);
+ s.save(simp);
+
Lower ls = new Lower();
ls.setOther(ls);
ls.setAnother(ls);
@@ -516,14 +473,7 @@
ls.setSet(set);
set.add(multi);
set.add(simp);
- Serializable id;
- if ( getDialect() instanceof SybaseDialect ) {
- id = s.save(ls);
- }
- else {
- id = new Long(2);
- s.save( ls, new Long(2) );
- }
+ Serializable id = s.save(ls);
t.commit();
s.close();
assertTrue( ls.getOther()==ls && ls.getAnother()==ls && ls.getYetanother()==ls );
@@ -548,39 +498,22 @@
}
public void testMultiTableManyToOne() throws Exception {
-
Session s = openSession();
Transaction t = s.beginTransaction();
assertTrue( s.find("from Top").size()==0 );
Multi multi = new Multi();
multi.setExtraProp("extra");
- //multi.setCount(666);
multi.setName("name");
Top simp = new Top();
simp.setDate( new Date() );
simp.setName("simp");
- //simp.setCount(132);
- Serializable mid;
- if ( getDialect() instanceof SybaseDialect ) {
- mid = s.save(multi);
- }
- else {
- mid = new Long(123);
- s.save(multi, mid);
- }
+ s.save(multi);
Lower ls = new Lower();
ls.setOther(ls);
ls.setAnother(multi);
ls.setYetanother(ls);
ls.setName("Less Simple");
- Serializable id;
- if ( getDialect() instanceof SybaseDialect ) {
- id = s.save(ls);
- }
- else {
- id = new Long(2);
- s.save( ls, new Long(2) );
- }
+ Serializable id = s.save(ls);
t.commit();
s.close();
assertTrue( ls.getOther()==ls && ls.getAnother()==multi && ls.getYetanother()==ls );
18 years, 11 months
Hibernate SVN: r10595 - branches/Branch_3_2/Hibernate3/src/org/hibernate/impl
by hibernate-commits@lists.jboss.org
Author: steve.ebersole(a)jboss.com
Date: 2006-10-17 17:18:17 -0400 (Tue, 17 Oct 2006)
New Revision: 10595
Modified:
branches/Branch_3_2/Hibernate3/src/org/hibernate/impl/SessionImpl.java
Log:
HHH-1663 : <any/> mappings during flush
Modified: branches/Branch_3_2/Hibernate3/src/org/hibernate/impl/SessionImpl.java
===================================================================
--- branches/Branch_3_2/Hibernate3/src/org/hibernate/impl/SessionImpl.java 2006-10-17 21:17:39 UTC (rev 10594)
+++ branches/Branch_3_2/Hibernate3/src/org/hibernate/impl/SessionImpl.java 2006-10-17 21:18:17 UTC (rev 10595)
@@ -1719,7 +1719,13 @@
public String bestGuessEntityName(Object object) {
if (object instanceof HibernateProxy) {
- object = ( (HibernateProxy) object ).getHibernateLazyInitializer().getImplementation();
+ LazyInitializer initializer = ( ( HibernateProxy ) object ).getHibernateLazyInitializer();
+ // it is possible for this method to be called during flush processing,
+ // so make certain that we do not accidently initialize an uninitialized proxy
+ if ( initializer.isUninitialized() ) {
+ return initializer.getEntityName();
+ }
+ object = initializer.getImplementation();
}
EntityEntry entry = persistenceContext.getEntry(object);
if (entry==null) {
18 years, 11 months
Hibernate SVN: r10594 - in branches/Branch_3_2/Hibernate3/test/org/hibernate/test: . any
by hibernate-commits@lists.jboss.org
Author: steve.ebersole(a)jboss.com
Date: 2006-10-17 17:17:39 -0400 (Tue, 17 Oct 2006)
New Revision: 10594
Added:
branches/Branch_3_2/Hibernate3/test/org/hibernate/test/any/Address.java
branches/Branch_3_2/Hibernate3/test/org/hibernate/test/any/AnyTypeTest.java
branches/Branch_3_2/Hibernate3/test/org/hibernate/test/any/Person.hbm.xml
branches/Branch_3_2/Hibernate3/test/org/hibernate/test/any/Person.java
Modified:
branches/Branch_3_2/Hibernate3/test/org/hibernate/test/AllTests.java
Log:
HHH-1663 : <any/> mappings during flush
Modified: branches/Branch_3_2/Hibernate3/test/org/hibernate/test/AllTests.java
===================================================================
--- branches/Branch_3_2/Hibernate3/test/org/hibernate/test/AllTests.java 2006-10-17 21:16:52 UTC (rev 10593)
+++ branches/Branch_3_2/Hibernate3/test/org/hibernate/test/AllTests.java 2006-10-17 21:17:39 UTC (rev 10594)
@@ -131,6 +131,7 @@
import org.hibernate.test.version.db.DbVersionTest;
import org.hibernate.test.version.sybase.SybaseTimestampVersioningTest;
import org.hibernate.test.where.WhereTest;
+import org.hibernate.test.any.AnyTypeTest;
/**
* @author Gavin King
@@ -291,6 +292,7 @@
suite.addTest( AbstractComponentPropertyRefTest.suite() );
suite.addTest( AbstractCompositeIdTest.suite() );
suite.addTest( UtilSuite.suite() );
+ suite.addTest(AnyTypeTest.suite() );
return filter( suite );
//return suite;
Added: branches/Branch_3_2/Hibernate3/test/org/hibernate/test/any/Address.java
===================================================================
--- branches/Branch_3_2/Hibernate3/test/org/hibernate/test/any/Address.java 2006-10-17 21:16:52 UTC (rev 10593)
+++ branches/Branch_3_2/Hibernate3/test/org/hibernate/test/any/Address.java 2006-10-17 21:17:39 UTC (rev 10594)
@@ -0,0 +1,30 @@
+package org.hibernate.test.any;
+
+import java.util.Set;
+import java.util.HashSet;
+
+/**
+ * todo: describe Address
+ *
+ * @author Steve Ebersole
+ */
+public class Address {
+ private Long id;
+ private Set lines = new HashSet();
+
+ public Long getId() {
+ return id;
+ }
+
+ public void setId(Long id) {
+ this.id = id;
+ }
+
+ public Set getLines() {
+ return lines;
+ }
+
+ public void setLines(Set lines) {
+ this.lines = lines;
+ }
+}
Added: branches/Branch_3_2/Hibernate3/test/org/hibernate/test/any/AnyTypeTest.java
===================================================================
--- branches/Branch_3_2/Hibernate3/test/org/hibernate/test/any/AnyTypeTest.java 2006-10-17 21:16:52 UTC (rev 10593)
+++ branches/Branch_3_2/Hibernate3/test/org/hibernate/test/any/AnyTypeTest.java 2006-10-17 21:17:39 UTC (rev 10594)
@@ -0,0 +1,58 @@
+package org.hibernate.test.any;
+
+import org.hibernate.test.TestCase;
+import org.hibernate.Session;
+import junit.framework.Test;
+import junit.framework.TestSuite;
+
+/**
+ * todo: describe AnyTypeTest
+ *
+ * @author Steve Ebersole
+ */
+public class AnyTypeTest extends TestCase {
+ public AnyTypeTest(String name) {
+ super( name );
+ }
+
+ protected String[] getMappings() {
+ return new String[] { "any/Person.hbm.xml" };
+ }
+
+ protected String getCacheConcurrencyStrategy() {
+ // having second level cache causes a condition whereby the original test case would not fail...
+ return null;
+ }
+
+ public static Test suite() {
+ return new TestSuite( AnyTypeTest.class );
+ }
+
+ /**
+ * Specific test for HHH-1663...
+ */
+ public void testFlushProcessing() {
+ Session session = openSession();
+ session.beginTransaction();
+ Person person = new Person();
+ Address address = new Address();
+ person.setData( address );
+ session.saveOrUpdate(person);
+ session.saveOrUpdate(address);
+ session.getTransaction().commit();
+ session.close();
+
+ session = openSession();
+ session.beginTransaction();
+ person = (Person) session.load( Person.class, person.getId() );
+ person.setName("makingpersondirty");
+ session.getTransaction().commit();
+ session.close();
+
+ session = openSession();
+ session.beginTransaction();
+ session.delete( person );
+ session.getTransaction().commit();
+ session.close();
+ }
+}
Added: branches/Branch_3_2/Hibernate3/test/org/hibernate/test/any/Person.hbm.xml
===================================================================
--- branches/Branch_3_2/Hibernate3/test/org/hibernate/test/any/Person.hbm.xml 2006-10-17 21:16:52 UTC (rev 10593)
+++ branches/Branch_3_2/Hibernate3/test/org/hibernate/test/any/Person.hbm.xml 2006-10-17 21:17:39 UTC (rev 10594)
@@ -0,0 +1,30 @@
+<?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.any">
+
+ <class name="Person" table="T_ANY_PERSON">
+ <id name="id" column="ID_">
+ <generator class="increment" />
+ </id>
+ <property name="name" />
+ <any name="data" id-type="long" cascade="none">
+ <meta-value value="A" class="Address"/>
+ <column name="DATATYPE_"/>
+ <column name="DATAID_"/>
+ </any>
+ </class>
+
+ <class name="Address" table="T_ANY_ADDRESS">
+ <id name="id" column="ID_">
+ <generator class="increment" />
+ </id>
+ <set name="lines" table="LINE">
+ <key column="ADDRESS" />
+ <element type="string" />
+ </set>
+ </class>
+
+</hibernate-mapping>
Added: branches/Branch_3_2/Hibernate3/test/org/hibernate/test/any/Person.java
===================================================================
--- branches/Branch_3_2/Hibernate3/test/org/hibernate/test/any/Person.java 2006-10-17 21:16:52 UTC (rev 10593)
+++ branches/Branch_3_2/Hibernate3/test/org/hibernate/test/any/Person.java 2006-10-17 21:17:39 UTC (rev 10594)
@@ -0,0 +1,37 @@
+package org.hibernate.test.any;
+
+/**
+ * todo: describe Person
+ *
+ * @author Steve Ebersole
+ */
+public class Person {
+ private Long id;
+ private String name;
+ private Object data;
+
+
+ public Long getId() {
+ return id;
+ }
+
+ public void setId(Long id) {
+ this.id = id;
+ }
+
+ public String getName() {
+ return name;
+ }
+
+ public void setName(String name) {
+ this.name = name;
+ }
+
+ public Object getData() {
+ return data;
+ }
+
+ public void setData(Object data) {
+ this.data = data;
+ }
+}
18 years, 11 months
Hibernate SVN: r10593 - trunk/Hibernate3/src/org/hibernate/impl
by hibernate-commits@lists.jboss.org
Author: steve.ebersole(a)jboss.com
Date: 2006-10-17 17:16:52 -0400 (Tue, 17 Oct 2006)
New Revision: 10593
Modified:
trunk/Hibernate3/src/org/hibernate/impl/SessionImpl.java
Log:
HHH-1663 : <any/> mappings during flush
Modified: trunk/Hibernate3/src/org/hibernate/impl/SessionImpl.java
===================================================================
--- trunk/Hibernate3/src/org/hibernate/impl/SessionImpl.java 2006-10-17 17:25:55 UTC (rev 10592)
+++ trunk/Hibernate3/src/org/hibernate/impl/SessionImpl.java 2006-10-17 21:16:52 UTC (rev 10593)
@@ -1719,7 +1719,13 @@
public String bestGuessEntityName(Object object) {
if (object instanceof HibernateProxy) {
- object = ( (HibernateProxy) object ).getHibernateLazyInitializer().getImplementation();
+ LazyInitializer initializer = ( ( HibernateProxy ) object ).getHibernateLazyInitializer();
+ // it is possible for this method to be called during flush processing,
+ // so make certain that we do not accidently initialize an uninitialized proxy
+ if ( initializer.isUninitialized() ) {
+ return initializer.getEntityName();
+ }
+ object = initializer.getImplementation();
}
EntityEntry entry = persistenceContext.getEntry(object);
if (entry==null) {
18 years, 11 months
Hibernate SVN: r10592 - in trunk/Hibernate3/test/org/hibernate/test: . any
by hibernate-commits@lists.jboss.org
Author: steve.ebersole(a)jboss.com
Date: 2006-10-17 13:25:55 -0400 (Tue, 17 Oct 2006)
New Revision: 10592
Added:
trunk/Hibernate3/test/org/hibernate/test/any/Address.java
trunk/Hibernate3/test/org/hibernate/test/any/AnyTypeTest.java
trunk/Hibernate3/test/org/hibernate/test/any/ComplexPropertyValue.java
trunk/Hibernate3/test/org/hibernate/test/any/Person.hbm.xml
trunk/Hibernate3/test/org/hibernate/test/any/Person.java
Modified:
trunk/Hibernate3/test/org/hibernate/test/AllTests.java
trunk/Hibernate3/test/org/hibernate/test/any/Properties.hbm.xml
Log:
HHH-1663 : <any/> -> mappings during flush
Modified: trunk/Hibernate3/test/org/hibernate/test/AllTests.java
===================================================================
--- trunk/Hibernate3/test/org/hibernate/test/AllTests.java 2006-10-17 08:57:26 UTC (rev 10591)
+++ trunk/Hibernate3/test/org/hibernate/test/AllTests.java 2006-10-17 17:25:55 UTC (rev 10592)
@@ -131,6 +131,7 @@
import org.hibernate.test.version.db.DbVersionTest;
import org.hibernate.test.version.sybase.SybaseTimestampVersioningTest;
import org.hibernate.test.where.WhereTest;
+import org.hibernate.test.any.AnyTypeTest;
/**
* @author Gavin King
@@ -291,6 +292,7 @@
suite.addTest( AbstractComponentPropertyRefTest.suite() );
suite.addTest( AbstractCompositeIdTest.suite() );
suite.addTest( UtilSuite.suite() );
+ suite.addTest( AnyTypeTest.suite() );
return filter( suite );
//return suite;
Added: trunk/Hibernate3/test/org/hibernate/test/any/Address.java
===================================================================
--- trunk/Hibernate3/test/org/hibernate/test/any/Address.java 2006-10-17 08:57:26 UTC (rev 10591)
+++ trunk/Hibernate3/test/org/hibernate/test/any/Address.java 2006-10-17 17:25:55 UTC (rev 10592)
@@ -0,0 +1,31 @@
+package org.hibernate.test.any;
+
+import java.util.Set;
+import java.util.HashSet;
+
+/**
+ * todo: describe Address
+ *
+ * @author Steve Ebersole
+ */
+public class Address {
+ private Long id;
+ private Set lines = new HashSet();
+
+
+ public Long getId() {
+ return id;
+ }
+
+ public void setId(Long id) {
+ this.id = id;
+ }
+
+ public Set getLines() {
+ return lines;
+ }
+
+ public void setLines(Set lines) {
+ this.lines = lines;
+ }
+}
Added: trunk/Hibernate3/test/org/hibernate/test/any/AnyTypeTest.java
===================================================================
--- trunk/Hibernate3/test/org/hibernate/test/any/AnyTypeTest.java 2006-10-17 08:57:26 UTC (rev 10591)
+++ trunk/Hibernate3/test/org/hibernate/test/any/AnyTypeTest.java 2006-10-17 17:25:55 UTC (rev 10592)
@@ -0,0 +1,58 @@
+package org.hibernate.test.any;
+
+import org.hibernate.test.TestCase;
+import org.hibernate.Session;
+import junit.framework.Test;
+import junit.framework.TestSuite;
+
+/**
+ * todo: describe AnyTypeTest
+ *
+ * @author Steve Ebersole
+ */
+public class AnyTypeTest extends TestCase {
+ public AnyTypeTest(String name) {
+ super( name );
+ }
+
+ protected String[] getMappings() {
+ return new String[] { "any/Person.hbm.xml" };
+ }
+
+ protected String getCacheConcurrencyStrategy() {
+ // having second level cache causes a condition whereby the original test case would not fail...
+ return null;
+ }
+
+ public static Test suite() {
+ return new TestSuite( AnyTypeTest.class );
+ }
+
+ /**
+ * Specific test for HHH-1663...
+ */
+ public void testFlushProcessing() {
+ Session session = openSession();
+ session.beginTransaction();
+ Person person = new Person();
+ Address address = new Address();
+ person.setData( address );
+ session.saveOrUpdate(person);
+ session.saveOrUpdate(address);
+ session.getTransaction().commit();
+ session.close();
+
+ session = openSession();
+ session.beginTransaction();
+ person = (Person) session.load( Person.class, person.getId() );
+ person.setName("makingpersondirty");
+ session.getTransaction().commit();
+ session.close();
+
+ session = openSession();
+ session.beginTransaction();
+ session.delete( person );
+ session.getTransaction().commit();
+ session.close();
+ }
+}
Added: trunk/Hibernate3/test/org/hibernate/test/any/ComplexPropertyValue.java
===================================================================
--- trunk/Hibernate3/test/org/hibernate/test/any/ComplexPropertyValue.java 2006-10-17 08:57:26 UTC (rev 10591)
+++ trunk/Hibernate3/test/org/hibernate/test/any/ComplexPropertyValue.java 2006-10-17 17:25:55 UTC (rev 10592)
@@ -0,0 +1,47 @@
+package org.hibernate.test.any;
+
+import java.util.Map;
+import java.util.HashMap;
+import java.util.Iterator;
+
+/**
+ * todo: describe ${NAME}
+ *
+ * @author Steve Ebersole
+ */
+public class ComplexPropertyValue implements PropertyValue {
+ private Long id;
+ private Map subProperties = new HashMap();
+
+ public Long getId() {
+ return id;
+ }
+
+ public void setId(Long id) {
+ this.id = id;
+ }
+
+ public Map getSubProperties() {
+ return subProperties;
+ }
+
+ public void setSubProperties(Map subProperties) {
+ this.subProperties = subProperties;
+ }
+
+ public String asString() {
+ return "complex[" + keyString() + "]";
+ }
+
+ private String keyString() {
+ StringBuffer buff = new StringBuffer();
+ Iterator itr = subProperties.keySet().iterator();
+ while ( itr.hasNext() ) {
+ buff.append( itr.next() );
+ if ( itr.hasNext() ) {
+ buff.append( ", " );
+ }
+ }
+ return buff.toString();
+ }
+}
Added: trunk/Hibernate3/test/org/hibernate/test/any/Person.hbm.xml
===================================================================
--- trunk/Hibernate3/test/org/hibernate/test/any/Person.hbm.xml 2006-10-17 08:57:26 UTC (rev 10591)
+++ trunk/Hibernate3/test/org/hibernate/test/any/Person.hbm.xml 2006-10-17 17:25:55 UTC (rev 10592)
@@ -0,0 +1,30 @@
+<?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.any">
+
+ <class name="Person" table="T_ANY_PERSON">
+ <id name="id" column="ID_">
+ <generator class="increment" />
+ </id>
+ <property name="name" />
+ <any name="data" id-type="long" cascade="none">
+ <meta-value value="A" class="Address"/>
+ <column name="DATATYPE_"/>
+ <column name="DATAID_"/>
+ </any>
+ </class>
+
+ <class name="Address" table="T_ANY_ADDRESS">
+ <id name="id" column="ID_">
+ <generator class="increment" />
+ </id>
+ <set name="lines" table="LINE">
+ <key column="ADDRESS" />
+ <element type="string" />
+ </set>
+ </class>
+
+</hibernate-mapping>
Added: trunk/Hibernate3/test/org/hibernate/test/any/Person.java
===================================================================
--- trunk/Hibernate3/test/org/hibernate/test/any/Person.java 2006-10-17 08:57:26 UTC (rev 10591)
+++ trunk/Hibernate3/test/org/hibernate/test/any/Person.java 2006-10-17 17:25:55 UTC (rev 10592)
@@ -0,0 +1,37 @@
+package org.hibernate.test.any;
+
+/**
+ * todo: describe Person
+ *
+ * @author Steve Ebersole
+ */
+public class Person {
+ private Long id;
+ private String name;
+ private Object data;
+
+
+ public Long getId() {
+ return id;
+ }
+
+ public void setId(Long id) {
+ this.id = id;
+ }
+
+ public String getName() {
+ return name;
+ }
+
+ public void setName(String name) {
+ this.name = name;
+ }
+
+ public Object getData() {
+ return data;
+ }
+
+ public void setData(Object data) {
+ this.data = data;
+ }
+}
Modified: trunk/Hibernate3/test/org/hibernate/test/any/Properties.hbm.xml
===================================================================
--- trunk/Hibernate3/test/org/hibernate/test/any/Properties.hbm.xml 2006-10-17 08:57:26 UTC (rev 10591)
+++ trunk/Hibernate3/test/org/hibernate/test/any/Properties.hbm.xml 2006-10-17 17:25:55 UTC (rev 10592)
@@ -13,6 +13,7 @@
<any name="someSpecificProperty" id-type="long" meta-type="string" cascade="all">
<meta-value value="I" class="IntegerPropertyValue"/>
<meta-value value="S" class="StringPropertyValue"/>
+ <meta-value value="C" class="ComplexPropertyValue" />
<column name="S_S_PROP_TYPE"/>
<column name="S_S_PROP_ID"/>
</any>
@@ -42,4 +43,14 @@
<property name="value" column="VAL" not-null="true" type="integer"/>
</class>
+ <class name="ComplexPropertyValue" table="T_COMPLEX_PROP">
+ <id name="id" column="ID" type="long">
+ <generator class="increment"/>
+ </id>
+ <map name="subProperties" table="T_COMPLEX_SUB_PROPS" lazy="true">
+ <key column="PROP_ID" />
+ <map-key type="string" column="SUB_PROP_NAME" />
+ <element type="string" column="SUB_PROP_VAL" />
+ </map>
+ </class>
</hibernate-mapping>
\ No newline at end of file
18 years, 11 months