Author: steve.ebersole(a)jboss.com
Date: 2006-09-01 14:35:19 -0400 (Fri, 01 Sep 2006)
New Revision: 10401
Modified:
trunk/Hibernate3/test/org/hibernate/test/sql/GeneralTest.java
Log:
cleanup : wow
Modified: trunk/Hibernate3/test/org/hibernate/test/sql/GeneralTest.java
===================================================================
--- trunk/Hibernate3/test/org/hibernate/test/sql/GeneralTest.java 2006-09-01 18:32:37 UTC
(rev 10400)
+++ trunk/Hibernate3/test/org/hibernate/test/sql/GeneralTest.java 2006-09-01 18:35:19 UTC
(rev 10401)
@@ -399,14 +399,14 @@
public void testAutoDetectAliasing() {
Session s = openSession();
Transaction t = s.beginTransaction();
- Organization ifa = new Organization("IFA");
- Organization jboss = new Organization("JBoss");
- Person gavin = new Person("Gavin");
- Employment emp = new Employment(gavin, jboss, "AU");
- Serializable orgId = s.save(jboss);
- Serializable orgId2 = s.save(ifa);
- s.save(gavin);
- s.save(emp);
+ Organization ifa = new Organization( "IFA" );
+ Organization jboss = new Organization( "JBoss" );
+ Person gavin = new Person( "Gavin" );
+ Employment emp = new Employment( gavin, jboss, "AU" );
+ Serializable orgId = s.save( jboss );
+ Serializable orgId2 = s.save( ifa );
+ s.save( gavin );
+ s.save( emp );
t.commit();
s.close();
@@ -415,50 +415,53 @@
List list = s.createSQLQuery( getEmploymentSQL() )
.addEntity( Employment.class.getName() )
.list();
- assertEquals( 1,list.size() );
+ assertEquals( 1, list.size() );
- Employment emp2 = (Employment) list.get(0);
- assertEquals(emp2.getEmploymentId(), emp.getEmploymentId() );
- assertEquals(emp2.getStartDate().getDate(), emp.getStartDate().getDate() );
- assertEquals(emp2.getEndDate(), emp.getEndDate() );
+ Employment emp2 = ( Employment ) list.get( 0 );
+ assertEquals( emp2.getEmploymentId(), emp.getEmploymentId() );
+ assertEquals( emp2.getStartDate().getDate(), emp.getStartDate().getDate() );
+ assertEquals( emp2.getEndDate(), emp.getEndDate() );
s.clear();
list = s.createSQLQuery( getEmploymentSQL() )
- .addEntity( Employment.class.getName() )
- .setResultTransformer(Transformers.ALIAS_TO_ENTITY_MAP)
- .list();
- assertEquals( 1,list.size() );
- Map m = (Map) list.get(0);
- assertTrue(m.containsKey("Employment"));
- assertEquals(1,m.size());
+ .addEntity( Employment.class.getName() )
+ .setResultTransformer( Transformers.ALIAS_TO_ENTITY_MAP )
+ .list();
+ assertEquals( 1, list.size() );
+ Map m = ( Map ) list.get( 0 );
+ assertTrue( m.containsKey( "Employment" ) );
+ assertEquals( 1, m.size() );
- list = s.createSQLQuery(getEmploymentSQL()).list();
- assertEquals(1, list.size());
- Object[] o = (Object[]) list.get(0);
- assertEquals(8, o.length);
+ list = s.createSQLQuery( getEmploymentSQL() ).list();
+ assertEquals( 1, list.size() );
+ Object[] o = ( Object[] ) list.get( 0 );
+ assertEquals( 8, o.length );
- list =
s.createSQLQuery(getEmploymentSQL()).setResultTransformer(Transformers.ALIAS_TO_ENTITY_MAP).list();
- assertEquals(1, list.size());
- m = (Map) list.get(0);
- assertTrue(m.containsKey("EMPID"));
- assertTrue(m.containsKey("VALUE"));
- assertTrue(m.containsKey("ENDDATE"));
- assertEquals(8, m.size());
+ list = s.createSQLQuery( getEmploymentSQL() ).setResultTransformer(
Transformers.ALIAS_TO_ENTITY_MAP ).list();
+ assertEquals( 1, list.size() );
+ m = ( Map ) list.get( 0 );
+ assertTrue( m.containsKey( "EMPID" ) );
+ assertTrue( m.containsKey( "VALUE" ) );
+ assertTrue( m.containsKey( "ENDDATE" ) );
+ assertEquals( 8, m.size() );
- list = s.createSQLQuery( getEmploymentSQLMixedScalarEntity() ).addScalar(
"employerid" ).addEntity( Employment.class ).list();
- assertEquals(1, list.size());
- o = (Object[]) list.get(0);
- assertEquals(2, o.length);
- assertClassAssignability( o[0].getClass(), Number.class);
- assertClassAssignability( o[1].getClass(), Employment.class);
+ list =
+ s.createSQLQuery( getEmploymentSQLMixedScalarEntity() )
+ .addScalar( "employerid" )
+ .addEntity( Employment.class )
+ .list();
+ assertEquals( 1, list.size() );
+ o = ( Object[] ) list.get( 0 );
+ assertEquals( 2, o.length );
+ assertClassAssignability( o[0].getClass(), Number.class );
+ assertClassAssignability( o[1].getClass(), Employment.class );
-
- Query queryWithCollection =
s.getNamedQuery("organizationEmploymentsExplicitAliases");
- queryWithCollection.setLong("id", jboss.getId() );
+ Query queryWithCollection = s.getNamedQuery(
"organizationEmploymentsExplicitAliases" );
+ queryWithCollection.setLong( "id", jboss.getId() );
list = queryWithCollection.list();
- assertEquals(list.size(),1);
+ assertEquals( list.size(), 1 );
s.clear();
@@ -466,7 +469,7 @@
.addEntity( "org", Organization.class )
.addJoin( "emp", "org.employments" )
.list();
- assertEquals( 2,list.size() );
+ assertEquals( 2, list.size() );
s.clear();
@@ -474,30 +477,30 @@
.addEntity( "org", Organization.class )
.addJoin( "emp", "org.employments" )
.list();
- assertEquals( 2,list.size() );
+ assertEquals( 2, list.size() );
s.clear();
// TODO : why twice?
s.getNamedQuery( "organizationreturnproperty" ).list();
list = s.getNamedQuery( "organizationreturnproperty" ).list();
- assertEquals( 2,list.size() );
+ assertEquals( 2, list.size() );
s.clear();
list = s.getNamedQuery( "organizationautodetect" ).list();
- assertEquals( 2,list.size() );
+ assertEquals( 2, list.size() );
t.commit();
s.close();
s = openSession();
t = s.beginTransaction();
- s.delete(emp2);
+ s.delete( emp2 );
- s.delete(jboss);
- s.delete(gavin);
- s.delete(ifa);
+ s.delete( jboss );
+ s.delete( gavin );
+ s.delete( ifa );
t.commit();
s.close();
@@ -505,8 +508,9 @@
t = s.beginTransaction();
Dimension dim = new Dimension( 3, Integer.MAX_VALUE );
s.save( dim );
-// s.flush();
- list = s.createSQLQuery( "select d_len * d_width as surface, d_len * d_width * 10
as volume from Dimension" ).list();
+ list =
+ s.createSQLQuery( "select d_len * d_width as surface, d_len * d_width * 10 as
volume from Dimension" )
+ .list();
s.delete( dim );
t.commit();
s.close();
@@ -517,29 +521,17 @@
enterprise.setModel( "USS" );
enterprise.setName( "Entreprise" );
enterprise.setSpeed( 50d );
- Dimension d = new Dimension(45, 10);
+ Dimension d = new Dimension( 45, 10 );
enterprise.setDimensions( d );
s.save( enterprise );
-// s.flush();
- Object[] result = (Object[]) s.getNamedQuery( "spaceship" ).uniqueResult();
- enterprise = (SpaceShip) result[0];
- assertTrue(50d == enterprise.getSpeed() );
+ Object[] result = ( Object[] ) s.getNamedQuery( "spaceship"
).uniqueResult();
+ enterprise = ( SpaceShip ) result[0];
+ assertTrue( 50d == enterprise.getSpeed() );
assertTrue( 450d == extractDoubleValue( result[1] ) );
assertTrue( 4500d == extractDoubleValue( result[2] ) );
- s.delete( dim );
+ s.delete( enterprise );
t.commit();
s.close();
-
- s = openSession();
- t = s.beginTransaction();
- s.delete(emp2);
-
- s.delete(jboss);
- s.delete(gavin);
- s.delete(ifa);
- t.commit();
- s.close();
-
}
public void testMixAndMatchEntityScalar() {