Methods Summary |
---|
public java.lang.String[] | getMappings()
return new String[] { "entitymode/multi/Stock.hbm.xml", "entitymode/multi/Valuation.hbm.xml" };
|
private void | prettyPrint(org.dom4j.Element element)
//System.out.println( element.asXML() );
try {
OutputFormat format = OutputFormat.createPrettyPrint();
new XMLWriter( System.out, format ).write( element );
System.out.println();
}
catch ( Throwable t ) {
System.err.println( "Unable to pretty print element : " + t );
}
|
public static junit.framework.Test | suite()
return new FunctionalTestClassTestSuite( MultiRepresentationTest.class );
|
public void | testDom4jHQL()
TestData testData = new TestData();
testData.create();
Session session = openSession();
Transaction txn = session.beginTransaction();
org.hibernate.Session dom4j = session.getSession( EntityMode.DOM4J );
List result = dom4j.createQuery( "from Stock" ).list();
assertEquals( "Incorrect result size", 1, result.size() );
Element element = ( Element ) result.get( 0 );
assertEquals( "Something wrong!", testData.stockId, Long.valueOf( element.attributeValue( "id" ) ) );
System.out.println( "**** XML: ****************************************************" );
prettyPrint( element );
System.out.println( "**************************************************************" );
txn.rollback();
session.close();
testData.destroy();
|
public void | testDom4jRetreival()
TestData testData = new TestData();
testData.create();
Session session = openSession();
Transaction txn = session.beginTransaction();
org.hibernate.Session dom4j = session.getSession( EntityMode.DOM4J );
Object rtn = dom4j.get( Stock.class.getName(), testData.stockId );
Element element = ( Element ) rtn;
assertEquals( "Something wrong!", testData.stockId, Long.valueOf( element.attributeValue( "id" ) ) );
System.out.println( "**** XML: ****************************************************" );
prettyPrint( element );
System.out.println( "**************************************************************" );
Element currVal = element.element( "currentValuation" );
System.out.println( "**** XML: ****************************************************" );
prettyPrint( currVal );
System.out.println( "**************************************************************" );
txn.rollback();
session.close();
testData.destroy();
|
public void | testDom4jSave()
TestData testData = new TestData();
testData.create();
Session pojos = openSession();
Transaction txn = pojos.beginTransaction();
org.hibernate.Session dom4j = pojos.getSession( EntityMode.DOM4J );
Element stock = DocumentFactory.getInstance().createElement( "stock" );
stock.addElement( "tradeSymbol" ).setText( "IBM" );
Element val = stock.addElement( "currentValuation" ).addElement( "valuation" );
val.appendContent( stock );
val.addElement( "valuationDate" ).setText( new java.util.Date().toString() );
val.addElement( "value" ).setText( "121.00" );
dom4j.save( Stock.class.getName(), stock );
dom4j.flush();
txn.rollback();
pojos.close();
assertTrue( !pojos.isOpen() );
assertTrue( !dom4j.isOpen() );
prettyPrint( stock );
testData.destroy();
|
public void | testPojoRetreival()
TestData testData = new TestData();
testData.create();
Session session = openSession();
Transaction txn = session.beginTransaction();
Stock stock = ( Stock ) session.get( Stock.class, new Long( 1 ) );
assertEquals( "Something wrong!", new Long( 1 ), stock.getId() );
txn.commit();
session.close();
testData.destroy();
|