Update of /cvsroot/hibernate/HibernateExt/tools/src/test/org/hibernate/tools/test/jdbc2cfg In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv3041/src/test/org/hibernate/tools/test/jdbc2cfg Modified Files: DynamicPersistentClassesTest.java CompositeIdTest.java IndexTest.java Removed Files: CaveatEmptorTestCase.java Log Message: - do not generate dynamic classes per default - handle basic composite key, including foreignkeys (not foreignkeys inside composite keys) (need more testing) Index: DynamicPersistentClassesTest.java =================================================================== RCS file: /cvsroot/hibernate/HibernateExt/tools/src/test/org/hibernate/tools/test/jdbc2cfg/DynamicPersistentClassesTest.java,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** DynamicPersistentClassesTest.java 6 Jan 2005 12:53:39 -0000 1.1 --- DynamicPersistentClassesTest.java 14 Jan 2005 23:17:50 -0000 1.2 *************** *** 11,14 **** --- 11,15 ---- import org.hibernate.HibernateException; import org.hibernate.SessionFactory; + import org.hibernate.cfg.JDBCMetaDataConfiguration; import org.hibernate.classic.Session; import org.hibernate.mapping.Collection; *************** *** 24,32 **** * @author max * - * TODO: dynamic-class cannot support recursive relationships because of hashcode() dependencies. - * Need to add options for not generating these. */ public class DynamicPersistentClassesTest extends JDBCMetaDataBinderTestCase { protected String[] getCreateSQL() { --- 25,37 ---- * @author max * */ public class DynamicPersistentClassesTest extends JDBCMetaDataBinderTestCase { + /* (non-Javadoc) + * @see org.hibernate.tools.JDBCMetaDataBinderTestCase#configure(org.hibernate.cfg.JDBCMetaDataConfiguration) + */ + protected void configure(JDBCMetaDataConfiguration cfg) { + cfg.setGeneratingDynamicClasses(true); + } protected String[] getCreateSQL() { *************** *** 127,131 **** Map loadedChild = (Map) session.get(toClassName("child"),new Character('B')); ! assertEquals(child,loadedChild); loadedChild = (Map) session.createQuery("from " + toClassName("child") + " ch").uniqueResult(); --- 132,136 ---- Map loadedChild = (Map) session.get(toClassName("child"),new Character('B')); ! assertEquals(child.get(toPropertyName("masterref")),loadedChild.get(toPropertyName("masterref"))); loadedChild = (Map) session.createQuery("from " + toClassName("child") + " ch").uniqueResult(); Index: CompositeIdTest.java =================================================================== RCS file: /cvsroot/hibernate/HibernateExt/tools/src/test/org/hibernate/tools/test/jdbc2cfg/CompositeIdTest.java,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** CompositeIdTest.java 13 Jan 2005 16:44:25 -0000 1.1 --- CompositeIdTest.java 14 Jan 2005 23:17:50 -0000 1.2 *************** *** 6,16 **** import java.io.File; import org.hibernate.cfg.Configuration; ! import org.hibernate.mapping.ForeignKey; ! import org.hibernate.mapping.Table; import org.hibernate.tool.hbm2x.ConfigurationNavigator; import org.hibernate.tool.hbm2x.Exporter; import org.hibernate.tool.hbm2x.HibernateMappingExporter; import org.hibernate.tools.JDBCMetaDataBinderTestCase; --- 6,25 ---- import java.io.File; + import java.io.FilenameFilter; + import java.io.PrintWriter; + import java.io.StringWriter; + import java.lang.reflect.Method; + import java.net.MalformedURLException; + import java.net.URL; + import java.net.URLClassLoader; + import org.apache.tools.ant.BuildException; + import org.hibernate.SessionFactory; import org.hibernate.cfg.Configuration; ! import org.hibernate.classic.Session; import org.hibernate.tool.hbm2x.ConfigurationNavigator; import org.hibernate.tool.hbm2x.Exporter; import org.hibernate.tool.hbm2x.HibernateMappingExporter; + import org.hibernate.tool.hbm2x.POJOExporter; import org.hibernate.tools.JDBCMetaDataBinderTestCase; *************** *** 24,40 **** return new String[] { ! "create table LineItem (\r\n" + ! " customerId varchar2(10) not null,\r\n" + ! " orderNumber number(10,0) not null,\r\n" + ! " productId varchar2(10) not null,\r\n" + " quantity number(10,0),\r\n" + ! " primary key (customerId, orderNumber, productId)\r\n" + ")", "create table Product (\r\n" + ! " productId varchar2(10) not null,\r\n" + " description varchar2(200) not null,\r\n" + " price number(19,3),\r\n" + " numberAvailable number(10,0),\r\n" + ! " primary key (productId)\r\n" + ")", "create table Customer (\r\n" + --- 33,51 ---- return new String[] { ! "create table SimpleLineItem (\r\n" + ! " lineItemId varchar2(10) not null,\r\n" + ! " customerOrderId varchar2(10),\r\n" + ! " productId varchar2(10) not null,\r\n" + ! " extraId varchar2(10) not null,\r\n" + " quantity number(10,0),\r\n" + ! " primary key (lineItemId)\r\n" + ")", "create table Product (\r\n" + ! " productId varchar2(10) not null,\r\n" + ! " extraId varchar2(10) not null,\r\n" + " description varchar2(200) not null,\r\n" + " price number(19,3),\r\n" + " numberAvailable number(10,0),\r\n" + ! " primary key (productId, extraId)\r\n" + ")", "create table Customer (\r\n" + *************** *** 44,47 **** --- 55,77 ---- " primary key (customerId)\r\n" + ")", + "create table SimpleCustomerOrder (\r\n" + + " customerOrderId varchar2(10) not null,\r\n" + + " customerId varchar2(10) not null,\r\n" + + " orderNumber number(10,0) not null,\r\n" + + " orderDate date not null,\r\n" + + " primary key (customerOrderId)\r\n" + + ")", + "alter table SimpleLineItem add constraint toSimpleCustomerOrder foreign key (customerOrderId) references SimpleCustomerOrder", + "alter table SimpleLineItem add constraint fromSimpletoProduct foreign key (productId,extraId) references Product", + "alter table SimpleCustomerOrder add constraint fromSimpletoCustomer foreign key (customerId) references Customer", + /* + "create table LineItem (\r\n" + + " customerId varchar2(10) not null,\r\n" + + " orderNumber number(10,0) not null,\r\n" + + " productId varchar2(10) not null,\r\n" + + " quantity number(10,0),\r\n" + + " primary key (customerId, orderNumber, productId)\r\n" + + ")", + "create table CustomerOrder (\r\n" + " customerId varchar2(10) not null,\r\n" + *************** *** 50,56 **** " primary key (customerId, orderNumber)\r\n" + ")", "alter table LineItem add constraint toCustomerOrder foreign key (customerId, orderNumber) references CustomerOrder", "alter table LineItem add constraint toProduct foreign key (productId) references Product", ! "alter table CustomerOrder add constraint toCustomer foreign key (customerId) references Customer" }; } --- 80,89 ---- " primary key (customerId, orderNumber)\r\n" + ")", + "alter table LineItem add constraint toCustomerOrder foreign key (customerId, orderNumber) references CustomerOrder", "alter table LineItem add constraint toProduct foreign key (productId) references Product", ! "alter table CustomerOrder add constraint toCustomer foreign key (customerId) references Customer", ! */ ! }; } *************** *** 58,71 **** protected String[] getDropSQL() { return new String[] { ! "drop table LineItem cascade constraints", "drop table Product cascade constraints", "drop table Customer cascade constraints", ! "drop table CustomerOrder cascade constraints", }; } ! public void testMultiColumnForeignKeys() { ! Table table = getTable(identifier("LineItem")); ! ForeignKey foreignKey = getForeignKey(table, identifier("toCustomerOrder")); assertNotNull(foreignKey); --- 91,106 ---- protected String[] getDropSQL() { return new String[] { ! "drop table SimpleLineItem cascade constraints", "drop table Product cascade constraints", "drop table Customer cascade constraints", ! "drop table SimpleCustomerOrder cascade constraints", ! /*"drop table CustomerOrder cascade constraints", ! "drop table LineItem cascade constraints",*/ }; } ! /* public void testMultiColumnForeignKeys() { ! Table table = getTable(identifier("LineItem")); ! assertNotNull(table); ForeignKey foreignKey = getForeignKey(table, identifier("toCustomerOrder")); assertNotNull(foreignKey); *************** *** 75,81 **** assertEquals(2,foreignKey.getColumnSpan()); ! } ! public void testGeneration() { File outputdir = new File("reverseoutput"); outputdir.mkdirs(); --- 110,116 ---- assertEquals(2,foreignKey.getColumnSpan()); ! }*/ ! public void testGeneration() throws MalformedURLException { File outputdir = new File("reverseoutput"); outputdir.mkdirs(); *************** *** 85,101 **** ConfigurationNavigator cv = new ConfigurationNavigator(); Exporter exporter = new HibernateMappingExporter(cfg, outputdir); ! cv.export(cfg, exporter); Configuration derived = new Configuration(); ! derived.addFile(new File(outputdir, "CustomerOrder.hbm.xml")); ! derived.addFile(new File(outputdir, "LineItem.hbm.xml")); ! derived.buildMappings(); ! assertNotNull(derived.getClassMapping("org.reveng.Child")); ! assertNotNull(derived.getClassMapping("org.reveng.Master")); ! } } --- 120,188 ---- ConfigurationNavigator cv = new ConfigurationNavigator(); Exporter exporter = new HibernateMappingExporter(cfg, outputdir); ! Exporter javaExp = new POJOExporter(cfg, outputdir); cv.export(cfg, exporter); + cv.export(cfg, javaExp); + + compile(outputdir); Configuration derived = new Configuration(); ! derived.addFile(new File(outputdir, "SimplecustomerOrder.hbm.xml")); ! derived.addFile(new File(outputdir, "SimpleLineItem.hbm.xml")); ! derived.addFile(new File(outputdir, "Product.hbm.xml")); ! derived.addFile(new File(outputdir, "Customer.hbm.xml")); ! derived.buildMappings(); ! /*assertNotNull(derived.getClassMapping("org.reveng.Child")); ! assertNotNull(derived.getClassMapping("org.reveng.Master"));*/ ! URL[] urls = new URL[] { outputdir.toURL() }; ! URLClassLoader ucl = new URLClassLoader(urls, Thread.currentThread().getContextClassLoader()); ! Thread.currentThread().setContextClassLoader(ucl); ! SessionFactory factory = derived.buildSessionFactory(); ! Session session = factory.openSession(); ! session.createQuery("from Product"); ! Thread.currentThread().setContextClassLoader(ucl.getParent()); ! } ! ! /** ! * @param outputdir ! * @return ! */ ! private boolean compile(File outputdir) { ! ! String[] toggles = new String[] { "-verbose", "-sourcepath", ! outputdir.getAbsolutePath() +'\\', "-d", outputdir.getAbsolutePath() +'\\', }; ! ! File[] files = outputdir.listFiles(new FilenameFilter() { ! public boolean accept(File dir, String name) { ! // TODO Auto-generated method stub ! return name.endsWith(".java"); ! } ! }); ! ! String[] strings = new String[files.length]; ! for (int i = 0; i < strings.length; i++) { ! strings[i] = files[i].getAbsolutePath(); ! } ! ! String[] arguments = new String[toggles.length + strings.length]; ! System.arraycopy(toggles, 0, arguments, 0, toggles.length); ! System.arraycopy(strings, 0, arguments, toggles.length, ! strings.length); ! ! StringWriter sw = new StringWriter(); ! int result = com.sun.tools.javac.Main.compile(arguments, new PrintWriter(sw)); ! if (result != 0) { ! fail(sw.toString()); ! return false; ! } else { ! return true; ! } ! ! } ! } + + Index: IndexTest.java =================================================================== RCS file: /cvsroot/hibernate/HibernateExt/tools/src/test/org/hibernate/tools/test/jdbc2cfg/IndexTest.java,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** IndexTest.java 1 Dec 2004 10:59:45 -0000 1.1 --- IndexTest.java 14 Jan 2005 23:17:50 -0000 1.2 *************** *** 41,45 **** public void testUniqueKey() { ! Table table = (Table) cfg.getTableMappings().next(); UniqueKey uniqueKey = table.getUniqueKey(identifier("otherIdx")); --- 41,45 ---- public void testUniqueKey() { ! Table table = getTable(identifier("withIndex")); UniqueKey uniqueKey = table.getUniqueKey(identifier("otherIdx")); *************** *** 57,61 **** public void testWithIndex() { ! Table table = (Table) cfg.getTableMappings().next(); assertEqualIdentifiers("withIndex", table.getName()); --- 57,61 ---- public void testWithIndex() { ! Table table = getTable(identifier("withIndex")); assertEqualIdentifiers("withIndex", table.getName()); --- CaveatEmptorTestCase.java DELETED --- |