You can subscribe to this list here.
2002 |
Jan
|
Feb
|
Mar
|
Apr
|
May
|
Jun
|
Jul
|
Aug
|
Sep
|
Oct
(22) |
Nov
(308) |
Dec
(131) |
---|---|---|---|---|---|---|---|---|---|---|---|---|
2003 |
Jan
(369) |
Feb
(171) |
Mar
(236) |
Apr
(187) |
May
(218) |
Jun
(217) |
Jul
(127) |
Aug
(448) |
Sep
(270) |
Oct
(231) |
Nov
(422) |
Dec
(255) |
2004 |
Jan
(111) |
Feb
(73) |
Mar
(338) |
Apr
(351) |
May
(349) |
Jun
(495) |
Jul
(394) |
Aug
(1048) |
Sep
(499) |
Oct
(142) |
Nov
(269) |
Dec
(638) |
2005 |
Jan
(825) |
Feb
(1272) |
Mar
(593) |
Apr
(690) |
May
(950) |
Jun
(958) |
Jul
(767) |
Aug
(839) |
Sep
(525) |
Oct
(449) |
Nov
(585) |
Dec
(455) |
2006 |
Jan
(603) |
Feb
(656) |
Mar
(195) |
Apr
(114) |
May
(136) |
Jun
(100) |
Jul
(128) |
Aug
(68) |
Sep
(7) |
Oct
(1) |
Nov
(1) |
Dec
(8) |
2007 |
Jan
(4) |
Feb
(3) |
Mar
(8) |
Apr
(16) |
May
(5) |
Jun
(4) |
Jul
(6) |
Aug
(23) |
Sep
(15) |
Oct
(5) |
Nov
(7) |
Dec
(5) |
2008 |
Jan
(5) |
Feb
(1) |
Mar
(1) |
Apr
(5) |
May
(1) |
Jun
(1) |
Jul
|
Aug
|
Sep
|
Oct
|
Nov
(1) |
Dec
|
2009 |
Jan
|
Feb
|
Mar
|
Apr
|
May
|
Jun
|
Jul
(1) |
Aug
|
Sep
|
Oct
|
Nov
(1) |
Dec
|
2011 |
Jan
|
Feb
|
Mar
|
Apr
|
May
|
Jun
|
Jul
|
Aug
|
Sep
|
Oct
|
Nov
|
Dec
(1) |
2012 |
Jan
|
Feb
|
Mar
|
Apr
(1) |
May
|
Jun
(1) |
Jul
(1) |
Aug
(1) |
Sep
|
Oct
(2) |
Nov
(3) |
Dec
(2) |
2013 |
Jan
(1) |
Feb
|
Mar
(2) |
Apr
(1) |
May
|
Jun
|
Jul
(1) |
Aug
|
Sep
|
Oct
|
Nov
|
Dec
|
2014 |
Jan
|
Feb
|
Mar
(1) |
Apr
|
May
(2) |
Jun
(1) |
Jul
|
Aug
(1) |
Sep
(1) |
Oct
|
Nov
(1) |
Dec
|
2015 |
Jan
|
Feb
|
Mar
|
Apr
(1) |
May
|
Jun
|
Jul
|
Aug
|
Sep
(1) |
Oct
|
Nov
|
Dec
|
2016 |
Jan
|
Feb
|
Mar
(1) |
Apr
|
May
(1) |
Jun
|
Jul
|
Aug
|
Sep
|
Oct
|
Nov
|
Dec
|
2017 |
Jan
(1) |
Feb
|
Mar
|
Apr
|
May
|
Jun
|
Jul
(1) |
Aug
|
Sep
|
Oct
|
Nov
|
Dec
|
From: <hib...@li...> - 2006-07-13 01:52:14
|
Author: epbernard Date: 2006-07-12 21:52:08 -0400 (Wed, 12 Jul 2006) New Revision: 10113 Added: branches/Lucene_Integration/HibernateExt/ Log: branch for lucene integration Copied: branches/Lucene_Integration/HibernateExt (from rev 10112, trunk/HibernateExt) |
From: <hib...@li...> - 2006-07-13 01:51:05
|
Author: epbernard Date: 2006-07-12 21:51:02 -0400 (Wed, 12 Jul 2006) New Revision: 10112 Added: branches/Lucene_Integration/ Log: Created folder remotely |
From: <hib...@li...> - 2006-07-13 01:48:19
|
Author: epbernard Date: 2006-07-12 21:48:14 -0400 (Wed, 12 Jul 2006) New Revision: 10111 Modified: trunk/HibernateExt/metadata/src/java/org/hibernate/cfg/AnnotationBinder.java Log: minor Modified: trunk/HibernateExt/metadata/src/java/org/hibernate/cfg/AnnotationBinder.java =================================================================== --- trunk/HibernateExt/metadata/src/java/org/hibernate/cfg/AnnotationBinder.java 2006-07-12 22:10:21 UTC (rev 10110) +++ trunk/HibernateExt/metadata/src/java/org/hibernate/cfg/AnnotationBinder.java 2006-07-13 01:48:14 UTC (rev 10111) @@ -334,8 +334,8 @@ if ( ! isDefault( seqGen.sequenceName() ) ) { idGen.addParam( org.hibernate.id.SequenceGenerator.SEQUENCE, seqGen.sequenceName() ); } - //FIXME: work on initialValue() and allocationSize() through SequenceGenerator.PARAMETERS - if ( seqGen.initialValue() != 0 ) { + //FIXME: work on initialValue() through SequenceGenerator.PARAMETERS + if ( seqGen.initialValue() != 1 ) { log.warn( "Hibernate does not support SequenceGenerator.initialValue()" ); |
From: <hib...@li...> - 2006-07-12 15:40:25
|
Author: ste...@jb... Date: 2006-07-12 11:39:59 -0400 (Wed, 12 Jul 2006) New Revision: 10109 Modified: trunk/Hibernate3/src/org/hibernate/util/ReflectHelper.java Log: HHH-1898 and other cleanup Modified: trunk/Hibernate3/src/org/hibernate/util/ReflectHelper.java =================================================================== --- trunk/Hibernate3/src/org/hibernate/util/ReflectHelper.java 2006-07-12 15:31:11 UTC (rev 10108) +++ trunk/Hibernate3/src/org/hibernate/util/ReflectHelper.java 2006-07-12 15:39:59 UTC (rev 10109) @@ -91,31 +91,25 @@ public static Class classForName(String name) throws ClassNotFoundException { try { ClassLoader contextClassLoader = Thread.currentThread().getContextClassLoader(); - if (contextClassLoader!=null) { + if ( contextClassLoader != null ) { return contextClassLoader.loadClass(name); - } - else { - return Class.forName(name); } } - catch (Exception e) { - return Class.forName(name); + catch ( Throwable t ) { } + return Class.forName( name ); } public static Class classForName(String name, Class caller) throws ClassNotFoundException { try { ClassLoader contextClassLoader = Thread.currentThread().getContextClassLoader(); - if (contextClassLoader!=null) { - return contextClassLoader.loadClass(name); + if ( contextClassLoader != null ) { + return contextClassLoader.loadClass( name ); } - else { - return Class.forName( name, true, caller.getClassLoader() ); - } } - catch (Exception e) { - return Class.forName( name, true, caller.getClassLoader() ); + catch ( Throwable e ) { } + return Class.forName( name, true, caller.getClassLoader() ); } public static boolean isPublic(Class clazz, Member member) { @@ -125,15 +119,15 @@ public static Object getConstantValue(String name) { Class clazz; try { - clazz = classForName( StringHelper.qualifier(name) ); + clazz = classForName( StringHelper.qualifier( name ) ); } - catch(Exception cnfe) { + catch ( Throwable t ) { return null; } try { - return clazz.getField( StringHelper.unqualify(name) ).get(null); + return clazz.getField( StringHelper.unqualify( name ) ).get(null); } - catch (Exception e) { + catch ( Throwable t ) { return null; } } |
From: <hib...@li...> - 2006-07-12 15:31:30
|
Author: ste...@jb... Date: 2006-07-12 11:31:11 -0400 (Wed, 12 Jul 2006) New Revision: 10108 Modified: trunk/Hibernate3/src/org/hibernate/util/ReflectHelper.java Log: HHH-1898 Modified: trunk/Hibernate3/src/org/hibernate/util/ReflectHelper.java =================================================================== --- trunk/Hibernate3/src/org/hibernate/util/ReflectHelper.java 2006-07-12 09:43:33 UTC (rev 10107) +++ trunk/Hibernate3/src/org/hibernate/util/ReflectHelper.java 2006-07-12 15:31:11 UTC (rev 10108) @@ -127,7 +127,7 @@ try { clazz = classForName( StringHelper.qualifier(name) ); } - catch(ClassNotFoundException cnfe) { + catch(Exception cnfe) { return null; } try { |
From: <hib...@li...> - 2006-07-12 09:43:37
|
Author: max...@jb... Date: 2006-07-12 05:43:33 -0400 (Wed, 12 Jul 2006) New Revision: 10107 Modified: trunk/HibernateExt/tools/etc/hibernate.properties Log: Modified: trunk/HibernateExt/tools/etc/hibernate.properties =================================================================== --- trunk/HibernateExt/tools/etc/hibernate.properties 2006-07-12 09:42:43 UTC (rev 10106) +++ trunk/HibernateExt/tools/etc/hibernate.properties 2006-07-12 09:43:33 UTC (rev 10107) @@ -42,6 +42,17 @@ #hibernate.connection.url jdbc:hsqldb:. #hibernate.connection.shutdown=true +## Derby + +#hibernate.dialect org.hibernate.dialect.DB2Dialect +#hibernate.connection.driver_class org.apache.derby.jdbc.EmbeddedDriver +#hibernate.connection.username sa +#hibernate.connection.password +#hibernate.connection.url jdbc:hsqldb:hsql://localhost +#hibernate.connection.url jdbc:derby:testdb/derby;create=true +#hibernate.connection.url jdbc:hsqldb:. +#hibernate.connection.shutdown=true + ## MySQL #hibernate.dialect org.hibernate.dialect.MySQLDialect @@ -57,9 +68,7 @@ #hibernate.dialect org.hibernate.dialect.OracleDialect #hibernate.dialect org.hibernate.dialect.Oracle9Dialect #hibernate.connection.driver_class oracle.jdbc.driver.OracleDriver -#hibernate.connection.username max -#hibernate.connection.password max -#hibernate.connection.url jdbc:oracle:thin:@localhost:1521:orcl +#hibernate.connection.url jdbc:oracle:thin:@localhost:1522:XE ## PostgreSQL @@ -382,7 +391,7 @@ ## set a prefix for cache region names -hibernate.cache.region_prefix hibernate.test +#hibernate.cache.region_prefix hibernate.test ## disable the second-level cache @@ -399,7 +408,7 @@ #hibernate.cache.provider_class org.hibernate.cache.EhCacheProvider #hibernate.cache.provider_class org.hibernate.cache.EmptyCacheProvider -hibernate.cache.provider_class org.hibernate.cache.HashtableCacheProvider +#hibernate.cache.provider_class org.hibernate.cache.HashtableCacheProvider #hibernate.cache.provider_class org.hibernate.cache.TreeCacheProvider #hibernate.cache.provider_class org.hibernate.cache.OSCacheProvider #hibernate.cache.provider_class org.hibernate.cache.SwarmCacheProvider |
From: <hib...@li...> - 2006-07-12 09:42:48
|
Author: max...@jb... Date: 2006-07-12 05:42:43 -0400 (Wed, 12 Jul 2006) New Revision: 10106 Modified: trunk/HibernateExt/tools/etc/log4j.properties Log: Modified: trunk/HibernateExt/tools/etc/log4j.properties =================================================================== --- trunk/HibernateExt/tools/etc/log4j.properties 2006-07-12 09:42:03 UTC (rev 10105) +++ trunk/HibernateExt/tools/etc/log4j.properties 2006-07-12 09:42:43 UTC (rev 10106) @@ -15,7 +15,8 @@ log4j.rootLogger=info, stdout log4j.logger.org.hibernate=warn -log4j.logger.org.hibernate.tools.jdbc2cfg=debug +log4j.logger.org.hibernate.cfg.reveng=debug +log4j.logger.org.hibernate.cfg.JDBCMetaDataConfiguration=debug ### log just the SQL log4j.logger.org.hibernate.SQL=debug @@ -37,5 +38,5 @@ #log4j.logger.org.hibernate.connection.DriverManagerConnectionProvider=trace log4j.logger.org.hibernate.tool=debug - +log4j.logger.org.hibernate.tool.hbm2x.TemplateHelper=info #log4j.logger.org.apache.velocity=off \ No newline at end of file |
Author: max...@jb... Date: 2006-07-12 05:42:03 -0400 (Wed, 12 Jul 2006) New Revision: 10105 Added: trunk/HibernateExt/tools/src/test/org/hibernate/tool/hbm2x/query/QueryAllTests.java trunk/HibernateExt/tools/src/test/org/hibernate/tool/ide/completion/CompletionAllTests.java trunk/HibernateExt/tools/src/test/org/hibernate/tool/test/DriverMetaDataTest.java trunk/HibernateExt/tools/src/test/org/hibernate/tool/test/jdbc2cfg/MetaDataTest.java trunk/HibernateExt/tools/src/test/org/hibernate/tool/test/jdbc2cfg/newformat.reveng.xml Modified: trunk/HibernateExt/tools/src/java/org/hibernate/cfg/reveng/JDBCReader.java trunk/HibernateExt/tools/src/java/org/hibernate/cfg/reveng/OverrideBinder.java trunk/HibernateExt/tools/src/java/org/hibernate/tool/hbm2x/Cfg2HbmTool.java trunk/HibernateExt/tools/src/templates/hbm/set.hbm.ftl trunk/HibernateExt/tools/src/test/org/hibernate/tool/BaseTestCase.java trunk/HibernateExt/tools/src/test/org/hibernate/tool/JDBCMetaDataBinderTestCase.java trunk/HibernateExt/tools/src/test/org/hibernate/tool/NonReflectiveTestCase.java trunk/HibernateExt/tools/src/test/org/hibernate/tool/ToolAllTests.java trunk/HibernateExt/tools/src/test/org/hibernate/tool/ant/BuildFileTestCase.java trunk/HibernateExt/tools/src/test/org/hibernate/tool/ant/HibernateToolTest.java trunk/HibernateExt/tools/src/test/org/hibernate/tool/ant/SeamAntTest.java trunk/HibernateExt/tools/src/test/org/hibernate/tool/hbm2x/HashcodeEqualsTest.java trunk/HibernateExt/tools/src/test/org/hibernate/tool/hbm2x/Hbm2JavaTest.java trunk/HibernateExt/tools/src/test/org/hibernate/tool/hbm2x/Hbm2SeamTest.java trunk/HibernateExt/tools/src/test/org/hibernate/tool/hbm2x/Order.hbm.xml trunk/HibernateExt/tools/src/test/org/hibernate/tool/hbm2x/hbm2hbmxml/Cfg2HbmAllTests.java trunk/HibernateExt/tools/src/test/org/hibernate/tool/hbm2x/hbm2hbmxml/ManyToManyTest.java trunk/HibernateExt/tools/src/test/org/hibernate/tool/hbm2x/query/QueryExporterTest.java trunk/HibernateExt/tools/src/test/org/hibernate/tool/test/jdbc2cfg/Jdbc2CfgAllTests.java trunk/HibernateExt/tools/src/test/org/hibernate/tool/test/jdbc2cfg/OracleCompositeIdOrderTest.java trunk/HibernateExt/tools/src/test/org/hibernate/tool/test/jdbc2cfg/OracleViewsTest.java trunk/HibernateExt/tools/src/test/org/hibernate/tool/test/jdbc2cfg/SearchEscapeStringTest.java trunk/HibernateExt/tools/src/test5.0/org/hibernate/tool/hbm2x/Hbm2JavaEjb3ForJDK50Test.java trunk/HibernateExt/tools/src/testsupport/anttest-build.xml Log: fixing tests so they don't leave garbage tables behind. Modified: trunk/HibernateExt/tools/src/java/org/hibernate/cfg/reveng/JDBCReader.java =================================================================== --- trunk/HibernateExt/tools/src/java/org/hibernate/cfg/reveng/JDBCReader.java 2006-07-11 17:18:43 UTC (rev 10104) +++ trunk/HibernateExt/tools/src/java/org/hibernate/cfg/reveng/JDBCReader.java 2006-07-12 09:42:03 UTC (rev 10105) @@ -508,7 +508,9 @@ String sqlTypeName = (String) columnRs.get("TYPE_NAME"); String columnName = (String) columnRs.get("COLUMN_NAME"); + + String comment = (String) columnRs.get("REMARKS"); TableIdentifier ti = TableIdentifier.create(table); Modified: trunk/HibernateExt/tools/src/java/org/hibernate/cfg/reveng/OverrideBinder.java =================================================================== --- trunk/HibernateExt/tools/src/java/org/hibernate/cfg/reveng/OverrideBinder.java 2006-07-11 17:18:43 UTC (rev 10104) +++ trunk/HibernateExt/tools/src/java/org/hibernate/cfg/reveng/OverrideBinder.java 2006-07-12 09:42:03 UTC (rev 10105) @@ -268,7 +268,8 @@ while (iterator.hasNext() ) { Element element = (Element) iterator.next(); - SQLTypeMapping mapping = new SQLTypeMapping(JDBCToHibernateTypeHelper.getJDBCType(element.attributeValue("jdbc-type") ) ); + int jdbcType = JDBCToHibernateTypeHelper.getJDBCType(element.attributeValue("jdbc-type") ); + SQLTypeMapping mapping = new SQLTypeMapping(jdbcType ); mapping.setHibernateType( getHibernateType( element ) ); mapping.setLength(getInteger(element.attributeValue("length"), SQLTypeMapping.UNKNOWN_LENGTH) ); mapping.setPrecision(getInteger(element.attributeValue("precision"), SQLTypeMapping.UNKNOWN_PRECISION) ); Modified: trunk/HibernateExt/tools/src/java/org/hibernate/tool/hbm2x/Cfg2HbmTool.java =================================================================== --- trunk/HibernateExt/tools/src/java/org/hibernate/tool/hbm2x/Cfg2HbmTool.java 2006-07-11 17:18:43 UTC (rev 10104) +++ trunk/HibernateExt/tools/src/java/org/hibernate/tool/hbm2x/Cfg2HbmTool.java 2006-07-12 09:42:03 UTC (rev 10105) @@ -260,6 +260,10 @@ } } + public String getClassName(OneToMany om) { + return om.getAssociatedClass().getClassName(); + } + public String getProxyInterfaceName(PersistentClass pc) { if (pc.hasPojoRepresentation() ) { return pc.getClassName(); Modified: trunk/HibernateExt/tools/src/templates/hbm/set.hbm.ftl =================================================================== --- trunk/HibernateExt/tools/src/templates/hbm/set.hbm.ftl 2006-07-11 17:18:43 UTC (rev 10104) +++ trunk/HibernateExt/tools/src/templates/hbm/set.hbm.ftl 2006-07-12 09:42:03 UTC (rev 10105) @@ -16,7 +16,7 @@ /> <#elseif c2h.isManyToMany(property)> <many-to-many - entity-name="${property.getValue().getElement().referencedEntityName}"> <#-- lookup needed classname --> + entity-name="$c2h.getClassName($property.getValue().getElement())"> <#-- lookup needed classname --> <#foreach column in property.getValue().getElement().columnIterator> <#include "column.hbm.ftl"> </#foreach> Modified: trunk/HibernateExt/tools/src/test/org/hibernate/tool/BaseTestCase.java =================================================================== --- trunk/HibernateExt/tools/src/test/org/hibernate/tool/BaseTestCase.java 2006-07-11 17:18:43 UTC (rev 10104) +++ trunk/HibernateExt/tools/src/test/org/hibernate/tool/BaseTestCase.java 2006-07-12 09:42:03 UTC (rev 10105) @@ -1,13 +1,25 @@ package org.hibernate.tool; import java.io.File; +import java.sql.Connection; +import java.sql.SQLException; +import java.util.Iterator; +import junit.framework.ComparisonFailure; +import junit.framework.TestCase; + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.hibernate.cfg.Configuration; +import org.hibernate.cfg.Settings; +import org.hibernate.cfg.reveng.dialect.JDBCMetaDataDialect; +import org.hibernate.dialect.Dialect; import org.hibernate.tool.test.TestHelper; -import junit.framework.TestCase; - public abstract class BaseTestCase extends TestCase { + protected static final Log SKIP_LOG = LogFactory.getLog("org.hibernate.tool.test.SKIPPED"); + private File outputdir; public BaseTestCase(String name) { @@ -29,9 +41,11 @@ } protected void tearDown() throws Exception { + if (getOutputDir()!=null) TestHelper.deleteDir(getOutputDir()); + //assertEquals("Method not found errors during template processing:\n " + HibernateUberspect.getMethodErrors(),0,HibernateUberspect.getMethodNotFoundCount()); - //assertEquals("Method not found errors during template processing:\n " + HibernateUberspect.getMethodErrors(),0,HibernateUberspect.getMethodNotFoundCount()); + assertNoTables(); } @@ -45,5 +59,62 @@ return outputdir; } + public void assertNoTables() throws SQLException { + Configuration configuration = new Configuration(); + Settings testSettings = configuration.buildSettings(); + + Connection con = null; + try { + + con = testSettings.getConnectionProvider().getConnection(); + + JDBCMetaDataDialect dialect = new JDBCMetaDataDialect(); + dialect.configure( testSettings.getConnectionProvider(), testSettings.getSQLExceptionConverter() ); + Iterator tables = dialect.getTables( testSettings.getDefaultCatalogName(), testSettings.getDefaultSchemaName(), null ); + + assertHasNext( 0, tables ); + } finally { + testSettings.getConnectionProvider().closeConnection(con); + } + + } + + protected void assertHasNext(int expected, Iterator iterator) { + assertHasNext(null, expected, iterator); + } + + /** + * @param i + * @param iterator + */ + protected void assertHasNext(String reason, int expected, Iterator iterator) { + int actual = 0; + Object last = null; + while(iterator.hasNext() && actual <= expected) { + last = iterator.next(); + actual ++; + } + + if(actual < expected) { + throw new ComparisonFailure(reason==null?"Expected were less":reason, ""+expected, ""+actual); + } + + if(actual > expected) { + throw new ComparisonFailure((reason==null?"Expected were higher":reason)+", Last: " + last, ""+expected, ""+actual); + } + } + + /** + * Intended to indicate that this test class as a whole is intended for + * a dialect or series of dialects. Skips here (appliesTo = false), therefore + * simply indicate that the given tests target a particular feature of the + * current database... + * + * @param dialect + */ + public boolean appliesTo(Dialect dialect) { + return true; + } + } Modified: trunk/HibernateExt/tools/src/test/org/hibernate/tool/JDBCMetaDataBinderTestCase.java =================================================================== --- trunk/HibernateExt/tools/src/test/org/hibernate/tool/JDBCMetaDataBinderTestCase.java 2006-07-11 17:18:43 UTC (rev 10104) +++ trunk/HibernateExt/tools/src/test/org/hibernate/tool/JDBCMetaDataBinderTestCase.java 2006-07-12 09:42:03 UTC (rev 10105) @@ -10,12 +10,12 @@ import java.sql.Statement; import java.util.Iterator; -import junit.framework.ComparisonFailure; import org.hibernate.cfg.Configuration; import org.hibernate.cfg.JDBCMetaDataConfiguration; import org.hibernate.cfg.Settings; import org.hibernate.cfg.reveng.TableIdentifier; +import org.hibernate.cfg.reveng.dialect.JDBCMetaDataDialect; import org.hibernate.mapping.ForeignKey; import org.hibernate.mapping.Table; @@ -67,13 +67,20 @@ * @param sqls * @throws SQLException */ - protected void executeDDL(String[] sqls, boolean ignoreErrors) throws SQLException { + protected void executeDDL(String[] sqls, boolean ignoreErrors) throws SQLException { Configuration configuration = new Configuration(); Settings testSettings = configuration.buildSettings(); - - Connection con = testSettings.getConnectionProvider().getConnection(); + if(!appliesTo( testSettings.getDialect() )) { + fail("test case does not apply to " + testSettings.getDialect()); + return; // don't do anything to avoid crippled db + } + Connection con = null; + try { + + con = testSettings.getConnectionProvider().getConnection(); + DatabaseMetaData metaData = con.getMetaData(); storesLowerCaseIdentifiers = metaData.storesLowerCaseIdentifiers(); storesUpperCaseIdentifiers = metaData.storesUpperCaseIdentifiers(); @@ -99,7 +106,9 @@ } if (statement!=null) statement.close(); con.commit(); - testSettings.getConnectionProvider().closeConnection(con); + } finally { + testSettings.getConnectionProvider().closeConnection(con); + } } protected abstract String[] getCreateSQL(); @@ -130,6 +139,7 @@ protected void tearDown() throws Exception { executeDDL(getDropSQL(), false); + assertNoTables(); super.tearDown(); } /** @@ -140,30 +150,7 @@ } - protected void assertHasNext(int expected, Iterator foreignKeyIterator) { - assertHasNext(null, expected, foreignKeyIterator); - } /** - * @param i - * @param foreignKeyIterator - */ - protected void assertHasNext(String reason, int expected, Iterator foreignKeyIterator) { - int actual = 0; - while(foreignKeyIterator.hasNext() && actual <= expected) { - foreignKeyIterator.next(); - actual ++; - } - - if(actual < expected) { - throw new ComparisonFailure(reason==null?"Expected were less":reason, ""+expected, ""+actual); - } - - if(actual > expected) { - throw new ComparisonFailure(reason==null?"Expected were higher":reason, ""+expected, ""+actual); - } - } - - /** * @param column * @return */ @@ -233,5 +220,8 @@ return value.equals(tf); } - + public Configuration getConfiguration() { + return cfg; + } + } Modified: trunk/HibernateExt/tools/src/test/org/hibernate/tool/NonReflectiveTestCase.java =================================================================== --- trunk/HibernateExt/tools/src/test/org/hibernate/tool/NonReflectiveTestCase.java 2006-07-11 17:18:43 UTC (rev 10104) +++ trunk/HibernateExt/tools/src/test/org/hibernate/tool/NonReflectiveTestCase.java 2006-07-12 09:42:03 UTC (rev 10105) @@ -2,9 +2,6 @@ package org.hibernate.tool; import java.io.File; -import java.sql.Blob; -import java.sql.Clob; -import java.util.Iterator; import org.hibernate.HibernateException; import org.hibernate.Interceptor; @@ -13,10 +10,6 @@ import org.hibernate.cfg.Environment; import org.hibernate.dialect.Dialect; import org.hibernate.engine.SessionFactoryImplementor; -import org.hibernate.mapping.Collection; -import org.hibernate.mapping.PersistentClass; -import org.hibernate.mapping.Property; -import org.hibernate.mapping.SimpleValue; import org.hibernate.tool.test.TestHelper; public abstract class NonReflectiveTestCase extends BaseTestCase { @@ -59,7 +52,7 @@ getCfg().addResource( files[i], this.getClass().getClassLoader() ); } - if ( getCacheConcurrencyStrategy()!=null ) { + /*if ( getCacheConcurrencyStrategy()!=null ) { Iterator iter = cfg.getClassMappings(); while ( iter.hasNext() ) { @@ -91,7 +84,7 @@ ); } - } + }*/ setDialect( Dialect.getDialect() ); getCfg().buildMappings(); @@ -199,4 +192,7 @@ return TestHelper.findFirstString(string, file); } + public Configuration getConfiguration() { + return getCfg(); + } } Modified: trunk/HibernateExt/tools/src/test/org/hibernate/tool/ToolAllTests.java =================================================================== --- trunk/HibernateExt/tools/src/test/org/hibernate/tool/ToolAllTests.java 2006-07-11 17:18:43 UTC (rev 10104) +++ trunk/HibernateExt/tools/src/test/org/hibernate/tool/ToolAllTests.java 2006-07-12 09:42:03 UTC (rev 10105) @@ -1,5 +1,8 @@ package org.hibernate.tool; +import org.hibernate.tool.hbm2x.query.QueryAllTests; +import org.hibernate.tool.ide.completion.CompletionAllTests; + import junit.framework.Test; import junit.framework.TestSuite; @@ -12,6 +15,8 @@ suite.addTest(org.hibernate.tool.hbm2x.hbm2hbmxml.Cfg2HbmAllTests.suite() ); suite.addTest(org.hibernate.tool.test.jdbc2cfg.Jdbc2CfgAllTests.suite() ); suite.addTest(org.hibernate.tool.hbm2x.Hbm2XAllTests.suite() ); + suite.addTest(CompletionAllTests.suite() ); + suite.addTest(QueryAllTests.suite() ); return suite; }} Modified: trunk/HibernateExt/tools/src/test/org/hibernate/tool/ant/BuildFileTestCase.java =================================================================== --- trunk/HibernateExt/tools/src/test/org/hibernate/tool/ant/BuildFileTestCase.java 2006-07-11 17:18:43 UTC (rev 10104) +++ trunk/HibernateExt/tools/src/test/org/hibernate/tool/ant/BuildFileTestCase.java 2006-07-12 09:42:03 UTC (rev 10105) @@ -21,13 +21,12 @@ import java.io.PrintStream; import java.net.URL; -import junit.framework.TestCase; - import org.apache.tools.ant.BuildEvent; import org.apache.tools.ant.BuildException; import org.apache.tools.ant.BuildListener; import org.apache.tools.ant.Project; import org.apache.tools.ant.ProjectHelper; +import org.hibernate.tool.BaseTestCase; /** * A BuildFileTest is a TestCase which executes targets from an Ant buildfile @@ -38,7 +37,7 @@ * * Copied into hibernate to avoid dependency on ant test src directory. */ -public abstract class BuildFileTestCase extends TestCase { +public abstract class BuildFileTestCase extends BaseTestCase { protected Project project; @@ -502,4 +501,5 @@ } + } Modified: trunk/HibernateExt/tools/src/test/org/hibernate/tool/ant/HibernateToolTest.java =================================================================== --- trunk/HibernateExt/tools/src/test/org/hibernate/tool/ant/HibernateToolTest.java 2006-07-11 17:18:43 UTC (rev 10104) +++ trunk/HibernateExt/tools/src/test/org/hibernate/tool/ant/HibernateToolTest.java 2006-07-12 09:42:03 UTC (rev 10105) @@ -25,7 +25,9 @@ } protected void tearDown() throws Exception { - System.out.println(getLog() ); + executeTarget("cleanup"); + System.out.println(getLog()); + super.tearDown(); } protected void setUp() throws Exception { configureProject("src/testsupport/anttest-build.xml"); Modified: trunk/HibernateExt/tools/src/test/org/hibernate/tool/ant/SeamAntTest.java =================================================================== --- trunk/HibernateExt/tools/src/test/org/hibernate/tool/ant/SeamAntTest.java 2006-07-11 17:18:43 UTC (rev 10104) +++ trunk/HibernateExt/tools/src/test/org/hibernate/tool/ant/SeamAntTest.java 2006-07-12 09:42:03 UTC (rev 10105) @@ -36,6 +36,7 @@ protected void tearDown() throws Exception { System.out.println(getLog() ); + super.tearDown(); } Modified: trunk/HibernateExt/tools/src/test/org/hibernate/tool/hbm2x/HashcodeEqualsTest.java =================================================================== --- trunk/HibernateExt/tools/src/test/org/hibernate/tool/hbm2x/HashcodeEqualsTest.java 2006-07-11 17:18:43 UTC (rev 10104) +++ trunk/HibernateExt/tools/src/test/org/hibernate/tool/hbm2x/HashcodeEqualsTest.java 2006-07-12 09:42:03 UTC (rev 10105) @@ -38,10 +38,6 @@ super( name, "hashcodeequals" ); } - protected void tearDown() throws Exception { - // TODO Auto-generated method stub - // super.tearDown(); - } protected void setUp() throws Exception { super.setUp(); Modified: trunk/HibernateExt/tools/src/test/org/hibernate/tool/hbm2x/Hbm2JavaTest.java =================================================================== --- trunk/HibernateExt/tools/src/test/org/hibernate/tool/hbm2x/Hbm2JavaTest.java 2006-07-11 17:18:43 UTC (rev 10104) +++ trunk/HibernateExt/tools/src/test/org/hibernate/tool/hbm2x/Hbm2JavaTest.java 2006-07-12 09:42:03 UTC (rev 10105) @@ -17,7 +17,6 @@ import org.hibernate.mapping.Property; import org.hibernate.mapping.RootClass; import org.hibernate.mapping.SingleTableSubclass; -import org.hibernate.mapping.Value; import org.hibernate.tool.NonReflectiveTestCase; import org.hibernate.tool.hbm2x.pojo.BasicPOJOClass; import org.hibernate.tool.hbm2x.pojo.ImportContext; @@ -200,6 +199,7 @@ "org.hibernate.tool.hbm2x.Order" ); Property property = pc.getProperty( "lineItems" ); assertEquals( "java.util.Collection", c2j.getJavaTypeName( property, false ) ); + } Modified: trunk/HibernateExt/tools/src/test/org/hibernate/tool/hbm2x/Hbm2SeamTest.java =================================================================== --- trunk/HibernateExt/tools/src/test/org/hibernate/tool/hbm2x/Hbm2SeamTest.java 2006-07-11 17:18:43 UTC (rev 10104) +++ trunk/HibernateExt/tools/src/test/org/hibernate/tool/hbm2x/Hbm2SeamTest.java 2006-07-12 09:42:03 UTC (rev 10105) @@ -31,9 +31,6 @@ } - protected void tearDown() throws Exception { - super.tearDown(); - } public void testFileExistence() { assertFileAndExists(new File(getOutputDir(), "src/org/hibernate/tool/hbm2x/Article.java") ); Modified: trunk/HibernateExt/tools/src/test/org/hibernate/tool/hbm2x/Order.hbm.xml =================================================================== --- trunk/HibernateExt/tools/src/test/org/hibernate/tool/hbm2x/Order.hbm.xml 2006-07-11 17:18:43 UTC (rev 10104) +++ trunk/HibernateExt/tools/src/test/org/hibernate/tool/hbm2x/Order.hbm.xml 2006-07-12 09:42:03 UTC (rev 10105) @@ -6,22 +6,6 @@ <hibernate-mapping package="org.hibernate.tool.hbm2x"> <!-- - This mapping demonstrates - - (1) composite keys and one-to-many associations on - composite keys - - (2) use of insert="false" update="false" on an - association mapping, when the foreign key is - also part of the primary key - - (3) use of a derived property which performs a - subselect against associated tables - - (4) use of <synchronize/> to ensure that auto-flush - works correctly for an entity with a property - derived from other tables - --> Modified: trunk/HibernateExt/tools/src/test/org/hibernate/tool/hbm2x/hbm2hbmxml/Cfg2HbmAllTests.java =================================================================== --- trunk/HibernateExt/tools/src/test/org/hibernate/tool/hbm2x/hbm2hbmxml/Cfg2HbmAllTests.java 2006-07-11 17:18:43 UTC (rev 10104) +++ trunk/HibernateExt/tools/src/test/org/hibernate/tool/hbm2x/hbm2hbmxml/Cfg2HbmAllTests.java 2006-07-12 09:42:03 UTC (rev 10105) @@ -8,6 +8,7 @@ public static Test suite() { TestSuite suite = new TestSuite( "Test for org.hibernate.tool.cfg2hbm" ); //$JUnit-BEGIN$ + suite.addTest( ManyToManyTest.suite() ); suite.addTest( Hbm2HbmXmlTest.suite() ); //$JUnit-END$ return suite; Modified: trunk/HibernateExt/tools/src/test/org/hibernate/tool/hbm2x/hbm2hbmxml/ManyToManyTest.java =================================================================== --- trunk/HibernateExt/tools/src/test/org/hibernate/tool/hbm2x/hbm2hbmxml/ManyToManyTest.java 2006-07-11 17:18:43 UTC (rev 10104) +++ trunk/HibernateExt/tools/src/test/org/hibernate/tool/hbm2x/hbm2hbmxml/ManyToManyTest.java 2006-07-12 09:42:03 UTC (rev 10105) @@ -8,10 +8,17 @@ package org.hibernate.tool.hbm2x.hbm2hbmxml; import java.io.File; +import java.util.List; import junit.framework.Test; import junit.framework.TestSuite; +import org.dom4j.Document; +import org.dom4j.DocumentException; +import org.dom4j.DocumentHelper; +import org.dom4j.Element; +import org.dom4j.Node; +import org.dom4j.XPath; import org.dom4j.io.SAXReader; import org.hibernate.cfg.Configuration; import org.hibernate.tool.NonReflectiveTestCase; @@ -57,11 +64,24 @@ } - protected void tearDown() throws Exception { - // TODO Auto-generated method stub - // super.tearDown(); + public void testManyToManyFailureExpected() throws DocumentException { + File outputXml = new File(getOutputDir(), getBaseForMappings() + "User.hbm.xml"); + assertFileAndExists(outputXml); + + SAXReader xmlReader = this.getSAXReader(); + + Document document = xmlReader.read(outputXml); + + XPath xpath = DocumentHelper.createXPath("//hibernate-mapping/class/set/many-to-many"); + List list = xpath.selectNodes(document); + assertEquals("Expected to get one many-to-many element", 1, list.size()); + Element node = (Element) list.get(0); + assertEquals(node.attribute( "class" ).getText(),"Group"); + + } - + + private SAXReader getSAXReader() { SAXReader xmlReader = new SAXReader(); xmlReader.setEntityResolver(new DTDEntityResolver() ); Added: trunk/HibernateExt/tools/src/test/org/hibernate/tool/hbm2x/query/QueryAllTests.java =================================================================== --- trunk/HibernateExt/tools/src/test/org/hibernate/tool/hbm2x/query/QueryAllTests.java 2006-07-11 17:18:43 UTC (rev 10104) +++ trunk/HibernateExt/tools/src/test/org/hibernate/tool/hbm2x/query/QueryAllTests.java 2006-07-12 09:42:03 UTC (rev 10105) @@ -0,0 +1,17 @@ +package org.hibernate.tool.hbm2x.query; + +import junit.framework.Test; +import junit.framework.TestSuite; + +public class QueryAllTests { + + public static Test suite() { + TestSuite suite = new TestSuite( + "Test for org.hibernate.tool.hbm2x.query" ); + //$JUnit-BEGIN$ + suite.addTestSuite( QueryExporterTest.class ); + //$JUnit-END$ + return suite; + } + +} Modified: trunk/HibernateExt/tools/src/test/org/hibernate/tool/hbm2x/query/QueryExporterTest.java =================================================================== --- trunk/HibernateExt/tools/src/test/org/hibernate/tool/hbm2x/query/QueryExporterTest.java 2006-07-11 17:18:43 UTC (rev 10104) +++ trunk/HibernateExt/tools/src/test/org/hibernate/tool/hbm2x/query/QueryExporterTest.java 2006-07-12 09:42:03 UTC (rev 10105) @@ -5,9 +5,11 @@ import java.util.List; import org.hibernate.SessionFactory; +import org.hibernate.Transaction; import org.hibernate.cfg.Environment; import org.hibernate.classic.Session; import org.hibernate.tool.NonReflectiveTestCase; +import org.hibernate.tool.hbm2ddl.SchemaExport; import org.hibernate.tool.hbm2x.QueryExporter; public class QueryExporterTest extends NonReflectiveTestCase { @@ -51,8 +53,14 @@ queries.add("from java.lang.Object"); exporter.setQueries( queries ); - exporter.start(); + exporter.start(); + } + + protected void tearDown() throws Exception { + SchemaExport export = new SchemaExport(getCfg()); + export.drop( false, true ); + super.tearDown(); } Added: trunk/HibernateExt/tools/src/test/org/hibernate/tool/ide/completion/CompletionAllTests.java =================================================================== --- trunk/HibernateExt/tools/src/test/org/hibernate/tool/ide/completion/CompletionAllTests.java 2006-07-11 17:18:43 UTC (rev 10104) +++ trunk/HibernateExt/tools/src/test/org/hibernate/tool/ide/completion/CompletionAllTests.java 2006-07-12 09:42:03 UTC (rev 10105) @@ -0,0 +1,19 @@ +package org.hibernate.tool.ide.completion; + +import junit.framework.Test; +import junit.framework.TestSuite; + +public class CompletionAllTests { + + public static Test suite() { + TestSuite suite = new TestSuite( + "Test for org.hibernate.tool.ide.completion" ); + //$JUnit-BEGIN$ + suite.addTestSuite( CompletionHelperTest.class ); + suite.addTestSuite( HqlAnalyzerTest.class ); + suite.addTestSuite( ModelCompletionTest.class ); + //$JUnit-END$ + return suite; + } + +} Added: trunk/HibernateExt/tools/src/test/org/hibernate/tool/test/DriverMetaDataTest.java =================================================================== --- trunk/HibernateExt/tools/src/test/org/hibernate/tool/test/DriverMetaDataTest.java 2006-07-11 17:18:43 UTC (rev 10104) +++ trunk/HibernateExt/tools/src/test/org/hibernate/tool/test/DriverMetaDataTest.java 2006-07-12 09:42:03 UTC (rev 10105) @@ -0,0 +1,94 @@ +package org.hibernate.tool.test; + +import java.util.Iterator; +import java.util.Map; + +import org.hibernate.cfg.JDBCReaderFactory; +import org.hibernate.cfg.Settings; +import org.hibernate.cfg.reveng.dialect.JDBCMetaDataDialect; +import org.hibernate.cfg.reveng.dialect.MetaDataDialect; +import org.hibernate.tool.JDBCMetaDataBinderTestCase; + + +/** + * Various tests to validate the "sanity" of the jdbc drivers meta data implementation. + * + * @author Max Rydahl Andersen + * + */ +public class DriverMetaDataTest extends JDBCMetaDataBinderTestCase { + +protected String[] getCreateSQL() { + + return new String[] { + "create table tab_master ( id char not null, name varchar(20), primary key (id) )", + "create table tab_child ( childid character not null, masterref character, primary key (childid), foreign key (masterref) references tab_master(id) )", + }; + } + + protected String[] getDropSQL() { + + return new String[] { + "drop table tab_child", + "drop table tab_master", + }; + } + + public void testExportedKeys() { + + MetaDataDialect dialect = new JDBCMetaDataDialect(); + + Settings settings = cfg.buildSettings(); + + dialect.configure( settings.getConnectionProvider(), settings.getSQLExceptionConverter() ); + + Iterator tables = dialect.getTables( settings.getDefaultCatalogName(), settings.getDefaultSchemaName(), identifier("tab_master") ); + + boolean foundMaster = false; + while(tables.hasNext()) { + Map map = (Map) tables.next(); + + String tableName = (String) map.get("TABLE_NAME"); + String schemaName = (String) map.get("TABLE_SCHEM"); + String catalogName = (String) map.get("TABLE_CAT"); + + if(tableName.equals(identifier("tab_master"))) { + foundMaster = true; + Iterator exportedKeys = dialect.getExportedKeys( catalogName, schemaName, tableName ); + int cnt = 0; + while ( exportedKeys.hasNext() ) { + Map element = (Map) exportedKeys.next(); + cnt++; + } + assertEquals(1,cnt); + /* assertEquals(schemaName, settings.getDefaultSchemaName()); + assertEquals(catalogName, settings.getDefaultCatalogName());*/ + } + } + + assertTrue(foundMaster); + } + + public void testDataType() { + + MetaDataDialect dialect = new JDBCMetaDataDialect(); + + Settings settings = cfg.buildSettings(); + + dialect.configure( settings.getConnectionProvider(), settings.getSQLExceptionConverter() ); + + Iterator tables = dialect.getColumns( settings.getDefaultCatalogName(), settings.getDefaultSchemaName(), "test", null ); + + + while(tables.hasNext()) { + Map map = (Map) tables.next(); + + System.out.println(map); + + } + + + } + + +} Modified: trunk/HibernateExt/tools/src/test/org/hibernate/tool/test/jdbc2cfg/Jdbc2CfgAllTests.java =================================================================== --- trunk/HibernateExt/tools/src/test/org/hibernate/tool/test/jdbc2cfg/Jdbc2CfgAllTests.java 2006-07-11 17:18:43 UTC (rev 10104) +++ trunk/HibernateExt/tools/src/test/org/hibernate/tool/test/jdbc2cfg/Jdbc2CfgAllTests.java 2006-07-12 09:42:03 UTC (rev 10105) @@ -7,18 +7,26 @@ public static Test suite() { TestSuite suite = new TestSuite( - "Test for org.hibernate.tool.test.jdbc2cfg"); + "Test for org.hibernate.tool.test.jdbc2cfg" ); //$JUnit-BEGIN$ - suite.addTest(NoPrimaryKeyTest.suite() ); - suite.addTest(DefaultReverseEngineeringStrategyTest.suite() ); - suite.addTest(AutoQuoteTest.suite() ); - suite.addTest(OverrideBinderTest.suite() ); - suite.addTest(CompositeIdTest.suite() ); - suite.addTest(KeyPropertyCompositeIdTest.suite() ); - suite.addTest(IndexTest.suite() ); - suite.addTest(ForeignKeysTest.suite() ); - suite.addTest(BasicTest.suite() ); - suite.addTest(PersistentClassesTest.suite() ); + suite.addTest( BasicMultiSchemaTest.suite() ); + suite.addTest( PerformanceTest.suite() ); + suite.addTest( NoPrimaryKeyTest.suite() ); + suite.addTest( SearchEscapeStringTest.suite() ); + suite.addTest( OverrideBinderTest.suite() ); + suite.addTest( VersioningTest.suite() ); + suite.addTest( MetaDataTest.suite() ); + suite.addTest( CompositeIdTest.suite() ); + suite.addTest( IndexTest.suite() ); + suite.addTest( OracleCompositeIdOrderTest.suite() ); + suite.addTest( ForeignKeysTest.suite() ); + suite.addTest( RevEngForeignKeyTests.suite() ); + suite.addTest( BasicTest.suite() ); + suite.addTest( OracleViewsTest.suite() ); + suite.addTest( AutoQuoteTest.suite() ); + suite.addTest( KeyPropertyCompositeIdTest.suite() ); + suite.addTest( PersistentClassesTest.suite() ); + suite.addTest( DefaultReverseEngineeringStrategyTest.suite() ); //$JUnit-END$ return suite; } Added: trunk/HibernateExt/tools/src/test/org/hibernate/tool/test/jdbc2cfg/MetaDataTest.java =================================================================== --- trunk/HibernateExt/tools/src/test/org/hibernate/tool/test/jdbc2cfg/MetaDataTest.java 2006-07-11 17:18:43 UTC (rev 10104) +++ trunk/HibernateExt/tools/src/test/org/hibernate/tool/test/jdbc2cfg/MetaDataTest.java 2006-07-12 09:42:03 UTC (rev 10105) @@ -0,0 +1,109 @@ +/* + * Created on 2004-11-23 + * + */ +package org.hibernate.tool.test.jdbc2cfg; + +import java.sql.SQLException; + +import junit.framework.Test; +import junit.framework.TestSuite; + +import org.hibernate.mapping.Column; +import org.hibernate.mapping.PrimaryKey; +import org.hibernate.mapping.Table; +import org.hibernate.tool.JDBCMetaDataBinderTestCase; + +/** + * @author max + * + */ +public class MetaDataTest extends JDBCMetaDataBinderTestCase { + + /** + * @return + */ + protected String[] getDropSQL() { + return new String[] { + "drop table basic", + "drop table somecolumnsnopk", + "drop table multikeyed" }; + } + + /** + * @return + */ + protected String[] getCreateSQL() { + + return new String[] { + "create table basic ( a int not null, name varchar(20), primary key (a) )", + "create table somecolumnsnopk ( pk varchar(25) not null, b char, c int not null, aBoolean boolean )", + "create table multikeyed ( orderid varchar(10), customerid varchar(10), name varchar(10), primary key(orderid, customerid) )" }; + } + + public void testBasic() throws SQLException { + + assertHasNext( "There should be three tables!", 3, cfg + .getTableMappings() ); + + Table table = getTable( identifier( "basic" ) ); + + assertEqualIdentifiers( "basic", table.getName() ); + assertEquals( 2, table.getColumnSpan() ); + + Column basicColumn = table.getColumn( 0 ); + assertEqualIdentifiers( "a", basicColumn.getName() ); + // TODO: we cannot call getSqlType(dialect,cfg) without a + // MappingassertEquals("INTEGER", basicColumn.getSqlType() ); // at + // least on hsqldb + // assertEquals(22, basicColumn.getLength() ); // at least on oracle + + PrimaryKey key = table.getPrimaryKey(); + assertNotNull( "There should be a primary key!", key ); + assertEquals( key.getColumnSpan(), 1 ); + + Column column = key.getColumn( 0 ); + assertTrue( column.isUnique() ); + + assertSame( basicColumn, column ); + + } + + public void testScalePrecisionLength() { + + Table table = getTable( identifier( "basic" ) ); + + Column nameCol = table.getColumn( new Column( identifier( "name" ) ) ); + assertEquals( nameCol.getLength(), 20 ); + assertEquals( nameCol.getPrecision(), Column.DEFAULT_PRECISION ); + assertEquals( nameCol.getScale(), Column.DEFAULT_SCALE ); + } + + /* + * public void testGetTables() { + * + * Table table = new Table(); table.setName("dummy"); cfg.addTable(table); + * + * Table foundTable = cfg.getTable(null,null,"dummy"); + * + * assertSame(table,foundTable); + * + * foundTable = cfg.getTable(null,"dschema", "dummy"); + * + * assertNotSame(table, foundTable); } + */ + + public void testCompositeKeys() { + + Table table = getTable( identifier( "multikeyed" ) ); + + PrimaryKey primaryKey = table.getPrimaryKey(); + + assertEquals( 2, primaryKey.getColumnSpan() ); + } + + public static Test suite() { + return new TestSuite( MetaDataTest.class ); + } + +} Modified: trunk/HibernateExt/tools/src/test/org/hibernate/tool/test/jdbc2cfg/OracleCompositeIdOrderTest.java =================================================================== --- trunk/HibernateExt/tools/src/test/org/hibernate/tool/test/jdbc2cfg/OracleCompositeIdOrderTest.java 2006-07-11 17:18:43 UTC (rev 10104) +++ trunk/HibernateExt/tools/src/test/org/hibernate/tool/test/jdbc2cfg/OracleCompositeIdOrderTest.java 2006-07-12 09:42:03 UTC (rev 10105) @@ -10,6 +10,8 @@ import junit.framework.TestSuite; import org.hibernate.cfg.JDBCMetaDataConfiguration; +import org.hibernate.dialect.Dialect; +import org.hibernate.dialect.Oracle9Dialect; import org.hibernate.mapping.Column; import org.hibernate.mapping.ForeignKey; import org.hibernate.mapping.PersistentClass; @@ -105,6 +107,10 @@ }; } + public boolean appliesTo(Dialect dialect) { + return dialect instanceof Oracle9Dialect; + } + public void testMultiColumnForeignKeys() { Table table = getTable(identifier("Course") ); Modified: trunk/HibernateExt/tools/src/test/org/hibernate/tool/test/jdbc2cfg/OracleViewsTest.java =================================================================== --- trunk/HibernateExt/tools/src/test/org/hibernate/tool/test/jdbc2cfg/OracleViewsTest.java 2006-07-11 17:18:43 UTC (rev 10104) +++ trunk/HibernateExt/tools/src/test/org/hibernate/tool/test/jdbc2cfg/OracleViewsTest.java 2006-07-12 09:42:03 UTC (rev 10105) @@ -9,6 +9,8 @@ import junit.framework.Test; import junit.framework.TestSuite; +import org.hibernate.dialect.Dialect; +import org.hibernate.dialect.Oracle9Dialect; import org.hibernate.mapping.PersistentClass; import org.hibernate.mapping.Table; import org.hibernate.tool.JDBCMetaDataBinderTestCase; @@ -19,6 +21,7 @@ */ public class OracleViewsTest extends JDBCMetaDataBinderTestCase { + /** * @return */ @@ -48,6 +51,9 @@ }; } + public boolean appliesTo(Dialect dialect) { + return dialect instanceof Oracle9Dialect; + } public void testViewAndSynonyms() throws SQLException { PersistentClass classMapping = cfg.getClassMapping(toClassName("basicview") ); Modified: trunk/HibernateExt/tools/src/test/org/hibernate/tool/test/jdbc2cfg/SearchEscapeStringTest.java =================================================================== --- trunk/HibernateExt/tools/src/test/org/hibernate/tool/test/jdbc2cfg/SearchEscapeStringTest.java 2006-07-11 17:18:43 UTC (rev 10104) +++ trunk/HibernateExt/tools/src/test/org/hibernate/tool/test/jdbc2cfg/SearchEscapeStringTest.java 2006-07-12 09:42:03 UTC (rev 10105) @@ -59,7 +59,6 @@ } protected void setUp() throws Exception { - //oracle.jdbc.driver.OracleLog.setTrace(true); super.setUp(); } } Added: trunk/HibernateExt/tools/src/test/org/hibernate/tool/test/jdbc2cfg/newformat.reveng.xml =================================================================== --- trunk/HibernateExt/tools/src/test/org/hibernate/tool/test/jdbc2cfg/newformat.reveng.xml 2006-07-11 17:18:43 UTC (rev 10104) +++ trunk/HibernateExt/tools/src/test/org/hibernate/tool/test/jdbc2cfg/newformat.reveng.xml 2006-07-12 09:42:03 UTC (rev 10105) @@ -0,0 +1,128 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!DOCTYPE hibernate-reverse-engineering SYSTEM "http://hibernate.sourceforge.net/hibernate-reverse-engineering-3.0.dtd" > + +<hibernate-reverse-engineering case-match="exact|upper|lower"> + + <!-- .* is valid, will be translated into % --> + <database-selection match-catalog="PUBLIC.*" match-schema="OVRTEST" match-table=".*"/> + + <type-mapping> + <from-sql-type native-type="varchar" jdbc-type="VARCHAR" length='20'> + <hibernate-type name="SomeUserType"><param></param></hibernate-type> + </from-sql-type> + </type-mapping> + + <table-filter match-schema=".*" match-name="TBL_.*"> + <entity package="org.werd"/> + </table-filter> + + + <table-filter match-name="DEFUNCT_TABLE" exclude="true" /> + <table-filter match-name="DoNotWantIt" exclude="true" /> + <table-filter match-name="WantedTable" /> + <table-filter match-catalog="BAD" match-schema="SCHEMA" + match-name=".*" exclude="true" /> + + <table-filter match-catalog=".*" match-schema=".*" + match-name="BIN$.*" exclude="true" /> + + <table-filter match-name=".*" exclude="false"/> + <!-- + <table name="CUSTOMER" package="org.funk" class-name="MyCustomer"> + <column name="order" property-name="orderName" /> + </table> + + <table name="CUSTOMER"> + <column name="ORDER" /> + </table> + + <table catalog="CUSTOMER" schema="WHATEVER" name="ORDER"> + <column name="name" exclude="true"> + <meta attribute="property-name">Name</meta> + </column> + </table> + --> + +<!-- hack for disable many-to-many + <table name="CategoryItem"> + <foreign-key constraint-name="CAT_FK" foreign-table="CATEGORY" > + <column-ref local-column="catid" foreign-column="id" /> + <many-to-one name="dfdf"/> + </foreign-key> + </table> +--> + <!-- + alter table Customer add constraint 'max' foreign key (addressid, x) references address (dfdf) + + default_schema PUBLIC + --> + <table name="ORDERS" class="Order"> + <primary-key property="id" key-class="OrderId"> + <generator class="sequence"> + <param name="table">seq_table</param> + </generator> + <key-column name="CUSTID1" property="val1" type="string"/> <!-- no exclude --> + <key-column name="CUSTID2" /> + <key-column name="CUSTID3" /> + </primary-key> + + <column name="generated" exclude="true" property="price"/> + + <for-columns exclude="false" property="price" type="MonetaryAmount"> + <column name="PRICE"/> + <column name="CURRENCY"/> + </for-columns> + + <!-- if constraint-name exist in db, use it! ignore foreign-x --> + <foreign-key constraint-name="SYS_CP20" foreign-table="PARENT" > + <column-ref local-column="parentid" foreign-column="id" /> + <column-ref local-column="extraparentid" foreign-column="extraid" /> + <many-to-one property="order"/> + <set name="orders"/> + </foreign-key> + + + <foreign-key constraint-name="SYS_CP20" foreign-table="PARENT" > + <column-ref local-column="parentid" foreign-column="id" /> + <column-ref local-column="extraparentid" foreign-column="extraid" /> + <many-to-one property="order"/> + <map name="orders"> + <map-key column="xxx"/> + </map> + </foreign-key> + + <foreign-key foreign-table="PARENT"> + <column-ref local-column="parentid" foreign-column="id" /> + <column-ref local-column="extraparentid" foreign-column="extraid" /> + </foreign-key> + + + bidirectionality + cardinality + + entity-name + collection-name + + <many-to-one ...> + < + + + </table> + + + <table name="CHILDREN"> + <foreign-key foreign-table="PARENT"> + <column-ref local-column="parentid" foreign-column="id" /> + <column-ref local-column="extraparentid" + foreign-column="extraid" /> + </foreign-key> + </table> + + <table name="EXCOLUMNS"> + <column name="EXCOLUMN" exclude="true"/> + </table> + + <table name="TblTest" class="org.test.Test"/> + + +</hibernate-reverse-engineering> \ No newline at end of file Modified: trunk/HibernateExt/tools/src/test5.0/org/hibernate/tool/hbm2x/Hbm2JavaEjb3ForJDK50Test.java =================================================================== --- trunk/HibernateExt/tools/src/test5.0/org/hibernate/tool/hbm2x/Hbm2JavaEjb3ForJDK50Test.java 2006-07-11 17:18:43 UTC (rev 10104) +++ trunk/HibernateExt/tools/src/test5.0/org/hibernate/tool/hbm2x/Hbm2JavaEjb3ForJDK50Test.java 2006-07-12 09:42:03 UTC (rev 10105) @@ -37,10 +37,6 @@ exporter.start(); } - protected void tearDown() throws Exception { - //super.tearDown(); - } - public void testFileExistence() { assertFileAndExists( new File( getOutputDir().getAbsolutePath() + "/org/hibernate/tool/hbm2x/Train.java" ) ); assertFileAndExists( Modified: trunk/HibernateExt/tools/src/testsupport/anttest-build.xml =================================================================== --- trunk/HibernateExt/tools/src/testsupport/anttest-build.xml 2006-07-11 17:18:43 UTC (rev 10104) +++ trunk/HibernateExt/tools/src/testsupport/anttest-build.xml 2006-07-12 09:42:03 UTC (rev 10105) @@ -21,6 +21,8 @@ </path> + <target name="cleanup" description="task used for ensuring cleanup to be done even in the case of test failure" depends="afterCfg2hbm"/> + <target name="testantcfg"> <mkdir dir="build/testsupport" /> @@ -61,7 +63,7 @@ <hbm2java /> <hbm2java templatepath="templates" /> - <hbm2cfgxml /> + <hbm2cfgxml/> </hibernatetool> </target> @@ -224,7 +226,7 @@ <hibernatetool destdir="${build.dir}/bottomup"> <configuration propertyfile="../../etc/hibernate.properties"> <fileset dir="../test/org/hibernate/tool/hbm2x"> - <include name="**/*.hbm.xml" /> + <include name="*.hbm.xml" /> </fileset> </configuration> |
From: <hib...@li...> - 2006-07-11 17:18:48
|
Author: max...@jb... Date: 2006-07-11 13:18:43 -0400 (Tue, 11 Jul 2006) New Revision: 10104 Modified: trunk/Hibernate3/src/org/hibernate/tool/hbm2ddl/SchemaExport.java Log: fixed NPE in case of schemaexport and export=false Modified: trunk/Hibernate3/src/org/hibernate/tool/hbm2ddl/SchemaExport.java =================================================================== --- trunk/Hibernate3/src/org/hibernate/tool/hbm2ddl/SchemaExport.java 2006-07-10 18:46:58 UTC (rev 10103) +++ trunk/Hibernate3/src/org/hibernate/tool/hbm2ddl/SchemaExport.java 2006-07-11 17:18:43 UTC (rev 10104) @@ -306,12 +306,13 @@ } if ( export ) { statement.executeUpdate( sql ); + SQLWarning warnings = statement.getWarnings(); + if ( warnings != null) { + JDBCExceptionReporter.logWarnings( warnings ); + } } - SQLWarning warnings = statement.getWarnings(); - if ( warnings != null) { - JDBCExceptionReporter.logWarnings( warnings ); - } + } public static void main(String[] args) { |
From: <hib...@li...> - 2006-07-10 18:47:09
|
Author: epbernard Date: 2006-07-10 14:46:58 -0400 (Mon, 10 Jul 2006) New Revision: 10103 Added: trunk/HibernateExt/ejb/src/test/org/hibernate/ejb/test/emops/Dress.java trunk/HibernateExt/ejb/src/test/org/hibernate/ejb/test/emops/FlushModeTest.java Modified: trunk/HibernateExt/ejb/src/java/org/hibernate/ejb/AbstractEntityManagerImpl.java trunk/HibernateExt/ejb/src/java/org/hibernate/ejb/CurrentEntityManagerImpl.java trunk/HibernateExt/ejb/src/java/org/hibernate/ejb/EntityManagerFactoryImpl.java trunk/HibernateExt/ejb/src/java/org/hibernate/ejb/EntityManagerImpl.java trunk/HibernateExt/ejb/src/java/org/hibernate/ejb/QueryImpl.java trunk/HibernateExt/ejb/src/java/org/hibernate/ejb/util/ConfigurationHelper.java Log: EJB-184 add flush mode through createEntityManager() Modified: trunk/HibernateExt/ejb/src/java/org/hibernate/ejb/AbstractEntityManagerImpl.java =================================================================== --- trunk/HibernateExt/ejb/src/java/org/hibernate/ejb/AbstractEntityManagerImpl.java 2006-07-10 18:31:16 UTC (rev 10102) +++ trunk/HibernateExt/ejb/src/java/org/hibernate/ejb/AbstractEntityManagerImpl.java 2006-07-10 18:46:58 UTC (rev 10103) @@ -8,6 +8,7 @@ import java.io.ObjectInputStream; import java.io.ObjectOutputStream; import java.io.Serializable; +import java.util.Map; import javax.persistence.EntityExistsException; import javax.persistence.EntityNotFoundException; import javax.persistence.EntityTransaction; @@ -44,12 +45,14 @@ import org.hibernate.QueryException; import org.hibernate.TransientObjectException; import org.hibernate.ejb.transaction.JoinableCMTTransaction; +import org.hibernate.ejb.util.ConfigurationHelper; import org.hibernate.engine.SessionFactoryImplementor; import org.hibernate.engine.SessionImplementor; import org.hibernate.exception.ConstraintViolationException; import org.hibernate.proxy.HibernateProxy; import org.hibernate.transaction.TransactionFactory; import org.hibernate.util.JTAHelper; +import org.hibernate.util.CollectionHelper; /** * @author <a href="mailto:ga...@hi...">Gavin King</a> @@ -60,17 +63,26 @@ protected transient TransactionImpl tx = new TransactionImpl( this ); protected PersistenceContextType persistenceContextType; - private FlushModeType flushMode = FlushModeType.AUTO; + private FlushModeType flushModeType = FlushModeType.AUTO; private PersistenceUnitTransactionType transactionType; + private Map properties; - protected AbstractEntityManagerImpl(PersistenceContextType type, PersistenceUnitTransactionType transactionType) { + protected AbstractEntityManagerImpl( + PersistenceContextType type, PersistenceUnitTransactionType transactionType, Map properties + ) { this.persistenceContextType = type; this.transactionType = transactionType; + this.properties = properties != null ? properties : CollectionHelper.EMPTY_MAP; } protected void postInit() { //register in Sync if needed if ( PersistenceUnitTransactionType.JTA.equals( transactionType ) ) joinTransaction( true ); + Object flushMode = properties.get( "org.hibernate.flushMode" ); + if (flushMode != null) { + getSession().setFlushMode( ConfigurationHelper.getFlushMode( flushMode ) ); + } + this.properties = null; } public Query createQuery(String ejbqlString) { @@ -296,16 +308,16 @@ return tx; } - public void setFlushMode(FlushModeType flushMode) { - this.flushMode = flushMode; - if ( flushMode == FlushModeType.AUTO ) { + public void setFlushMode(FlushModeType flushModeType) { + this.flushModeType = flushModeType; + if ( flushModeType == FlushModeType.AUTO ) { getSession().setFlushMode( FlushMode.AUTO ); } - else if ( flushMode == FlushModeType.COMMIT ) { + else if ( flushModeType == FlushModeType.COMMIT ) { getSession().setFlushMode( FlushMode.COMMIT ); } else { - throw new AssertionFailure( "Unknown FlushModeType: " + flushMode ); + throw new AssertionFailure( "Unknown FlushModeType: " + flushModeType ); } } @@ -322,10 +334,10 @@ public FlushModeType getFlushMode() { FlushMode mode = getSession().getFlushMode(); if ( mode == FlushMode.AUTO ) { - this.flushMode = FlushModeType.AUTO; + this.flushModeType = FlushModeType.AUTO; } else if ( mode == FlushMode.COMMIT ) { - this.flushMode = FlushModeType.COMMIT; + this.flushModeType = FlushModeType.COMMIT; } // else if ( mode == FlushMode.NEVER ) { // if ( PersistenceContextType.EXTENDED == persistenceContextType && !isTransactionInProgress() ) { @@ -340,7 +352,7 @@ return null; //TODO exception? } //otherwise this is an unknown mode for EJB3 - return flushMode; + return flushModeType; } public void lock(Object entity, LockModeType lockMode) { @@ -377,13 +389,13 @@ boolean isTransactionActive = isTransactionInProgress(); - if ( isTransactionActive && session.getFlushMode() == FlushMode.NEVER ) { - log.debug( "Transaction activated, move to FlushMode " + flushMode ); - setFlushMode( flushMode ); + if ( isTransactionActive && session.getFlushMode() == FlushMode.MANUAL ) { + log.debug( "Transaction activated, move to FlushMode " + flushModeType ); + setFlushMode( flushModeType ); } - else if ( ! isTransactionActive && session.getFlushMode() != FlushMode.NEVER ) { + else if ( ! isTransactionActive && session.getFlushMode() != FlushMode.MANUAL ) { log.debug( "Transaction not active, move to FlushMode NEVER" ); - session.setFlushMode( FlushMode.NEVER ); + session.setFlushMode( FlushMode.MANUAL ); } } @@ -585,7 +597,7 @@ } else if ( e instanceof TransientObjectException ) { markAsRollback(); - throw new IllegalStateException( e ); //Spec 3.2.3 Synchronozation rules + throw new IllegalStateException( e ); //Spec 3.2.3 Synchronization rules } else { throwPersistenceException( new PersistenceException( e ) ); Modified: trunk/HibernateExt/ejb/src/java/org/hibernate/ejb/CurrentEntityManagerImpl.java =================================================================== --- trunk/HibernateExt/ejb/src/java/org/hibernate/ejb/CurrentEntityManagerImpl.java 2006-07-10 18:31:16 UTC (rev 10102) +++ trunk/HibernateExt/ejb/src/java/org/hibernate/ejb/CurrentEntityManagerImpl.java 2006-07-10 18:46:58 UTC (rev 10103) @@ -1,6 +1,7 @@ //$Id$ package org.hibernate.ejb; +import java.util.Map; import javax.persistence.PersistenceContextType; import javax.persistence.spi.PersistenceUnitTransactionType; @@ -19,8 +20,8 @@ private SessionFactory sessionFactory; - public CurrentEntityManagerImpl(SessionFactory sessionFactory, PersistenceUnitTransactionType transactionType) { - super( PersistenceContextType.TRANSACTION, transactionType ); + public CurrentEntityManagerImpl(SessionFactory sessionFactory, PersistenceUnitTransactionType transactionType, Map properties) { + super( PersistenceContextType.TRANSACTION, transactionType, properties ); this.sessionFactory = sessionFactory; postInit(); } Modified: trunk/HibernateExt/ejb/src/java/org/hibernate/ejb/EntityManagerFactoryImpl.java =================================================================== --- trunk/HibernateExt/ejb/src/java/org/hibernate/ejb/EntityManagerFactoryImpl.java 2006-07-10 18:31:16 UTC (rev 10102) +++ trunk/HibernateExt/ejb/src/java/org/hibernate/ejb/EntityManagerFactoryImpl.java 2006-07-10 18:46:58 UTC (rev 10103) @@ -35,7 +35,7 @@ public EntityManager createEntityManager(Map map) { //TODO support discardOnClose, persistencecontexttype?, interceptor, return new EntityManagerImpl( - sessionFactory, PersistenceContextType.EXTENDED, transactionType, discardOnClose + sessionFactory, PersistenceContextType.EXTENDED, transactionType, discardOnClose, map ); } Modified: trunk/HibernateExt/ejb/src/java/org/hibernate/ejb/EntityManagerImpl.java =================================================================== --- trunk/HibernateExt/ejb/src/java/org/hibernate/ejb/EntityManagerImpl.java 2006-07-10 18:31:16 UTC (rev 10102) +++ trunk/HibernateExt/ejb/src/java/org/hibernate/ejb/EntityManagerImpl.java 2006-07-10 18:46:58 UTC (rev 10103) @@ -1,6 +1,7 @@ //$Id$ package org.hibernate.ejb; +import java.util.Map; import javax.persistence.PersistenceContextType; import javax.persistence.spi.PersistenceUnitTransactionType; import javax.transaction.Synchronization; @@ -27,9 +28,9 @@ public EntityManagerImpl( SessionFactory sessionFactory, PersistenceContextType pcType, PersistenceUnitTransactionType transactionType, - boolean discardOnClose + boolean discardOnClose, Map properties ) { - super( pcType, transactionType ); + super( pcType, transactionType, properties ); this.sessionFactory = sessionFactory; this.open = true; this.discardOnClose = discardOnClose; Modified: trunk/HibernateExt/ejb/src/java/org/hibernate/ejb/QueryImpl.java =================================================================== --- trunk/HibernateExt/ejb/src/java/org/hibernate/ejb/QueryImpl.java 2006-07-10 18:31:16 UTC (rev 10102) +++ trunk/HibernateExt/ejb/src/java/org/hibernate/ejb/QueryImpl.java 2006-07-10 18:46:58 UTC (rev 10103) @@ -18,6 +18,7 @@ import org.hibernate.QueryParameterException; import org.hibernate.SQLQuery; import org.hibernate.TypeMismatchException; +import org.hibernate.ejb.util.ConfigurationHelper; import org.hibernate.hql.QueryExecutionRequestException; /** @@ -143,7 +144,7 @@ query.setCacheMode( (CacheMode) value ); } else if ( "org.hibernate.flushMode".equals( hintName ) ) { - query.setFlushMode( (FlushMode) value ); + query.setFlushMode( ConfigurationHelper.getFlushMode( value ) ); } //TODO: /*else if ( "org.hibernate.lockMode".equals( hintName ) ) { Modified: trunk/HibernateExt/ejb/src/java/org/hibernate/ejb/util/ConfigurationHelper.java =================================================================== --- trunk/HibernateExt/ejb/src/java/org/hibernate/ejb/util/ConfigurationHelper.java 2006-07-10 18:31:16 UTC (rev 10102) +++ trunk/HibernateExt/ejb/src/java/org/hibernate/ejb/util/ConfigurationHelper.java 2006-07-10 18:46:58 UTC (rev 10103) @@ -5,6 +5,12 @@ import java.util.Properties; import java.util.Set; +import javax.persistence.FlushModeType; +import javax.persistence.PersistenceException; + +import org.hibernate.FlushMode; +import org.hibernate.AssertionFailure; + /** * @author Emmanuel Bernard */ @@ -16,4 +22,39 @@ } } } + + public static FlushMode getFlushMode(Object value) { + FlushMode flushMode = null; + if (value instanceof FlushMode) { + flushMode = (FlushMode) value; + } + else if (value instanceof javax.persistence.FlushModeType) { + flushMode = ConfigurationHelper.getFlushMode( (javax.persistence.FlushModeType) value); + } + else if (value instanceof String) { + flushMode = ConfigurationHelper.getFlushMode( (String) value); + } + if (flushMode == null) { + throw new PersistenceException("Unable to parse org.hibernate.flushMode: " + value); + } + return flushMode; + } + + private static FlushMode getFlushMode(String flushMode) { + if (flushMode == null) return null; + flushMode = flushMode.toUpperCase(); + return FlushMode.parse( flushMode ); + } + + private static FlushMode getFlushMode(FlushModeType flushMode) { + switch(flushMode) { + case AUTO: + return FlushMode.AUTO; + case COMMIT: + return FlushMode.COMMIT; + default: + throw new AssertionFailure("Unknown FlushModeType: " + flushMode); + } + + } } Added: trunk/HibernateExt/ejb/src/test/org/hibernate/ejb/test/emops/Dress.java =================================================================== --- trunk/HibernateExt/ejb/src/test/org/hibernate/ejb/test/emops/Dress.java 2006-07-10 18:31:16 UTC (rev 10102) +++ trunk/HibernateExt/ejb/src/test/org/hibernate/ejb/test/emops/Dress.java 2006-07-10 18:46:58 UTC (rev 10103) @@ -0,0 +1,14 @@ +//$Id: $ +package org.hibernate.ejb.test.emops; + +import javax.persistence.Id; +import javax.persistence.Entity; + +/** + * @author Emmanuel Bernard + */ +@Entity +public class Dress { + @Id public String name; + +} Added: trunk/HibernateExt/ejb/src/test/org/hibernate/ejb/test/emops/FlushModeTest.java =================================================================== --- trunk/HibernateExt/ejb/src/test/org/hibernate/ejb/test/emops/FlushModeTest.java 2006-07-10 18:31:16 UTC (rev 10102) +++ trunk/HibernateExt/ejb/src/test/org/hibernate/ejb/test/emops/FlushModeTest.java 2006-07-10 18:46:58 UTC (rev 10103) @@ -0,0 +1,39 @@ +//$Id: $ +package org.hibernate.ejb.test.emops; + +import java.util.Map; +import java.util.HashMap; +import javax.persistence.EntityManager; + +import org.hibernate.ejb.test.TestCase; + +/** + * @author Emmanuel Bernard + */ +public class FlushModeTest extends TestCase { + + public void testCreateEMFlushMode() throws Exception { + Map properties = new HashMap(); + properties.put( "org.hibernate.flushMode", "manual" ); + EntityManager em = factory.createEntityManager( properties ); + em.getTransaction().begin(); + Dress dress = new Dress(); + dress.name = "long dress"; + em.persist( dress ); + em.getTransaction().commit(); + + em.clear(); + + assertNull( em.find( Dress.class, dress.name ) ); + + em.close(); + } + + public Class[] getAnnotatedClasses() { + return new Class[] { + Race.class, + Competitor.class, + Dress.class + }; + } +} |
From: <hib...@li...> - 2006-07-10 18:31:37
|
Author: ste...@jb... Date: 2006-07-10 14:31:16 -0400 (Mon, 10 Jul 2006) New Revision: 10102 Modified: trunk/Hibernate3/etc/hibernate.properties.template Log: reflection optimizer setting Modified: trunk/Hibernate3/etc/hibernate.properties.template =================================================================== (Binary files differ) |
From: <hib...@li...> - 2006-07-10 17:13:00
|
Author: ste...@jb... Date: 2006-07-10 13:12:36 -0400 (Mon, 10 Jul 2006) New Revision: 10101 Modified: trunk/Hibernate3/src/org/hibernate/persister/entity/AbstractEntityPersister.java Log: HHH-1710 : collections based on property-ref to secondary table could not be joined in HQL Modified: trunk/Hibernate3/src/org/hibernate/persister/entity/AbstractEntityPersister.java =================================================================== --- trunk/Hibernate3/src/org/hibernate/persister/entity/AbstractEntityPersister.java 2006-07-10 16:31:09 UTC (rev 10100) +++ trunk/Hibernate3/src/org/hibernate/persister/entity/AbstractEntityPersister.java 2006-07-10 17:12:36 UTC (rev 10101) @@ -1321,10 +1321,18 @@ * which takes the entity name. */ public int getSubclassPropertyTableNumber(String propertyPath) { - final String rootPropertyName = StringHelper.root(propertyPath); + String rootPropertyName = StringHelper.root(propertyPath); Type type = propertyMapping.toType(rootPropertyName); - if ( type.isAssociationType() && ( (AssociationType) type ).useLHSPrimaryKey() ) { - return 0; + if ( type.isAssociationType() ) { + AssociationType assocType = ( AssociationType ) type; + if ( assocType.useLHSPrimaryKey() ) { + // performance op to avoid the array search + return 0; + } + else if ( type.isCollectionType() ) { + // properly handle property-ref-based associations + rootPropertyName = assocType.getLHSPropertyName(); + } } //Enable for HHH-440, which we don't like: /*if ( type.isComponentType() && !propertyName.equals(rootPropertyName) ) { |
From: <hib...@li...> - 2006-07-10 16:32:28
|
Author: ste...@jb... Date: 2006-07-10 12:31:09 -0400 (Mon, 10 Jul 2006) New Revision: 10100 Modified: trunk/Hibernate3/src/org/hibernate/type/OrderedMapType.java trunk/Hibernate3/src/org/hibernate/type/OrderedSetType.java trunk/Hibernate3/src/org/hibernate/type/SortedMapType.java trunk/Hibernate3/src/org/hibernate/type/SortedSetType.java trunk/Hibernate3/src/org/hibernate/util/LinkedHashCollectionHelper.java Log: HHH-1892 Modified: trunk/Hibernate3/src/org/hibernate/type/OrderedMapType.java =================================================================== --- trunk/Hibernate3/src/org/hibernate/type/OrderedMapType.java 2006-07-10 13:04:04 UTC (rev 10099) +++ trunk/Hibernate3/src/org/hibernate/type/OrderedMapType.java 2006-07-10 16:31:09 UTC (rev 10100) @@ -9,8 +9,8 @@ super( role, propertyRef, isEmbeddedInXML ); } - public Object instantiate() { - return LinkedHashCollectionHelper.createLinkedHashMap(); + public Object instantiate(int anticipatedSize) { + return LinkedHashCollectionHelper.createLinkedHashMap( anticipatedSize ); } } Modified: trunk/Hibernate3/src/org/hibernate/type/OrderedSetType.java =================================================================== --- trunk/Hibernate3/src/org/hibernate/type/OrderedSetType.java 2006-07-10 13:04:04 UTC (rev 10099) +++ trunk/Hibernate3/src/org/hibernate/type/OrderedSetType.java 2006-07-10 16:31:09 UTC (rev 10100) @@ -9,8 +9,8 @@ super( role, propertyRef, isEmbeddedInXML ); } - public Object instantiate() { - return LinkedHashCollectionHelper.createLinkedHashSet(); + public Object instantiate(int anticipatedSize) { + return LinkedHashCollectionHelper.createLinkedHashSet( anticipatedSize ); } } Modified: trunk/Hibernate3/src/org/hibernate/type/SortedMapType.java =================================================================== --- trunk/Hibernate3/src/org/hibernate/type/SortedMapType.java 2006-07-10 13:04:04 UTC (rev 10099) +++ trunk/Hibernate3/src/org/hibernate/type/SortedMapType.java 2006-07-10 16:31:09 UTC (rev 10100) @@ -39,7 +39,7 @@ return java.util.SortedMap.class; } - public Object instantiate() { + public Object instantiate(int anticipatedSize) { return new TreeMap(comparator); } Modified: trunk/Hibernate3/src/org/hibernate/type/SortedSetType.java =================================================================== --- trunk/Hibernate3/src/org/hibernate/type/SortedSetType.java 2006-07-10 13:04:04 UTC (rev 10099) +++ trunk/Hibernate3/src/org/hibernate/type/SortedSetType.java 2006-07-10 16:31:09 UTC (rev 10100) @@ -37,7 +37,7 @@ return java.util.SortedSet.class; } - public Object instantiate() { + public Object instantiate(int anticipatedSize) { return new TreeSet(comparator); } Modified: trunk/Hibernate3/src/org/hibernate/util/LinkedHashCollectionHelper.java =================================================================== --- trunk/Hibernate3/src/org/hibernate/util/LinkedHashCollectionHelper.java 2006-07-10 13:04:04 UTC (rev 10099) +++ trunk/Hibernate3/src/org/hibernate/util/LinkedHashCollectionHelper.java 2006-07-10 16:31:09 UTC (rev 10100) @@ -3,6 +3,7 @@ import java.util.Map; import java.util.Set; +import java.lang.reflect.Constructor; import org.hibernate.AssertionFailure; @@ -10,19 +11,33 @@ private static final Class SET_CLASS; private static final Class MAP_CLASS; + private static final Class[] CAPACITY_CTOR_SIG = new Class[] { int.class, float.class }; + private static final Constructor SET_CAPACITY_CTOR; + private static final Constructor MAP_CAPACITY_CTOR; + private static final float LOAD_FACTOR_V = .75f; + private static final Float LOAD_FACTOR = new Float( LOAD_FACTOR_V ); + static { Class setClass; Class mapClass; + Constructor setCtor; + Constructor mapCtor; try { - setClass = Class.forName("java.util.LinkedHashSet"); - mapClass = Class.forName("java.util.LinkedHashMap"); + setClass = Class.forName( "java.util.LinkedHashSet" ); + mapClass = Class.forName( "java.util.LinkedHashMap" ); + setCtor = setClass.getConstructor( CAPACITY_CTOR_SIG ); + mapCtor = mapClass.getConstructor( CAPACITY_CTOR_SIG ); } - catch (ClassNotFoundException cnfe) { + catch ( Throwable t ) { setClass = null; mapClass = null; + setCtor = null; + mapCtor = null; } SET_CLASS = setClass; MAP_CLASS = mapClass; + SET_CAPACITY_CTOR = setCtor; + MAP_CAPACITY_CTOR = mapCtor; } public static Set createLinkedHashSet() { @@ -34,6 +49,19 @@ } } + public static Set createLinkedHashSet(int anticipatedSize) { + if ( anticipatedSize <= 0 ) { + return createLinkedHashSet(); + } + int initialCapacity = anticipatedSize + (int)( anticipatedSize * LOAD_FACTOR_V ); + try { + return ( Set ) SET_CAPACITY_CTOR.newInstance( new Object[] { new Integer( initialCapacity ), LOAD_FACTOR } ); + } + catch (Exception e) { + throw new AssertionFailure("Could not instantiate LinkedHashSet", e); + } + } + public static Map createLinkedHashMap() { try { return (Map) MAP_CLASS.newInstance(); @@ -43,6 +71,19 @@ } } + public static Map createLinkedHashMap(int anticipatedSize) { + if ( anticipatedSize <= 0 ) { + return createLinkedHashMap(); + } + int initialCapacity = anticipatedSize + (int)( anticipatedSize * LOAD_FACTOR_V ); + try { + return ( Map ) MAP_CAPACITY_CTOR.newInstance( new Object[] { new Integer( initialCapacity ), LOAD_FACTOR } ); + } + catch (Exception e) { + throw new AssertionFailure("Could not instantiate LinkedHashMap", e); + } + } + private LinkedHashCollectionHelper() {} } |
Author: epbernard Date: 2006-07-07 06:55:11 -0400 (Fri, 07 Jul 2006) New Revision: 10096 Added: trunk/HibernateExt/ejb/src/test/org/hibernate/ejb/test/emops/RefreshTest.java Modified: trunk/HibernateExt/ejb/src/java/org/hibernate/ejb/AbstractEntityManagerImpl.java trunk/HibernateExt/ejb/src/java/org/hibernate/ejb/event/CallbackResolver.java trunk/HibernateExt/ejb/src/test/org/hibernate/ejb/test/QueryTest.java Log: EJB-205 refresh chech contains before delegating to refresh Modified: trunk/HibernateExt/ejb/src/java/org/hibernate/ejb/AbstractEntityManagerImpl.java =================================================================== --- trunk/HibernateExt/ejb/src/java/org/hibernate/ejb/AbstractEntityManagerImpl.java 2006-07-06 16:07:04 UTC (rev 10095) +++ trunk/HibernateExt/ejb/src/java/org/hibernate/ejb/AbstractEntityManagerImpl.java 2006-07-07 10:55:11 UTC (rev 10096) @@ -243,6 +243,9 @@ checkTransactionNeeded(); //adjustFlushMode(); try { + if ( ! getSession().contains( entity ) ) { + throw new IllegalArgumentException( "Entity not managed" ); + } getSession().refresh( entity ); } catch (MappingException e) { Modified: trunk/HibernateExt/ejb/src/java/org/hibernate/ejb/event/CallbackResolver.java =================================================================== --- trunk/HibernateExt/ejb/src/java/org/hibernate/ejb/event/CallbackResolver.java 2006-07-06 16:07:04 UTC (rev 10095) +++ trunk/HibernateExt/ejb/src/java/org/hibernate/ejb/event/CallbackResolver.java 2006-07-07 10:55:11 UTC (rev 10096) @@ -55,40 +55,39 @@ boolean stopListeners = false; boolean stopDefaultListeners = false; do { - //FIXME exclude overriden callback methods Callback callback = null; List<XMethod> methods = currentClazz.getDeclaredMethods(); final int size = methods.size(); for ( int i = 0; i < size ; i++ ) { final XMethod xMethod = methods.get( i ); if ( xMethod.isAnnotationPresent( annotation ) ) { - if ( callback == null ) { - Method method = reflectionManager.toMethod( xMethod ); - callback = new BeanCallback( method ); - Class returnType = method.getReturnType(); - Class[] args = method.getParameterTypes(); - if ( returnType != Void.TYPE || args.length != 0 ) { - throw new RuntimeException( - "Callback methods annotated on the bean class must return void and take no arguments: " + annotation - .getName() + " - " + xMethod - ); - } - if ( ! method.isAccessible() ) { - method.setAccessible( true ); - } - final String methodName = method.getName(); - if ( ! callbacksMethodNames.contains( methodName) ) { - //overriden method, remove the superclass overriden method + Method method = reflectionManager.toMethod( xMethod ); + final String methodName = method.getName(); + if ( ! callbacksMethodNames.contains( methodName ) ) { + //overriden method, remove the superclass overriden method + if ( callback == null ) { + callback = new BeanCallback( method ); + Class returnType = method.getReturnType(); + Class[] args = method.getParameterTypes(); + if ( returnType != Void.TYPE || args.length != 0 ) { + throw new RuntimeException( + "Callback methods annotated on the bean class must return void and take no arguments: " + annotation + .getName() + " - " + xMethod + ); + } + if ( ! method.isAccessible() ) { + method.setAccessible( true ); + } callbacks.add( 0, callback ); //superclass first callbacksMethodNames.add( 0, methodName ); } + else { + throw new PersistenceException( + "You can only annotate one callback method with " + + annotation.getName() + " in bean class: " + beanClass.getName() + ); + } } - else { - throw new PersistenceException( - "You can only annotate one callback method with " - + annotation.getName() + " in bean class: " + beanClass.getName() - ); - } } } if ( !stopListeners ) { @@ -123,50 +122,59 @@ Callback callback = null; if ( listener != null ) { XClass xListener = reflectionManager.toXClass( listener ); - List<XMethod> methods = xListener.getDeclaredMethods(); - final int size = methods.size(); - for ( int i = 0; i < size ; i++ ) { - final XMethod xMethod = methods.get(i); - final Method method = reflectionManager.toMethod( xMethod ); - if ( xMethod.isAnnotationPresent( annotation ) ) { - if ( callback == null ) { - try { - callback = new ListenerCallback( method, listener.newInstance() ); + callbacksMethodNames = new ArrayList<String>(); + do { + List<XMethod> methods = xListener.getDeclaredMethods(); + final int size = methods.size(); + for ( int i = 0; i < size ; i++ ) { + final XMethod xMethod = methods.get(i); + if ( xMethod.isAnnotationPresent( annotation ) ) { + final Method method = reflectionManager.toMethod( xMethod ); + final String methodName = method.getName(); + if ( ! callbacksMethodNames.contains( methodName ) ) { + //overriden method, remove the superclass overriden method + if ( callback == null ) { + try { + callback = new ListenerCallback( method, listener.newInstance() ); + } + catch (IllegalAccessException e) { + throw new PersistenceException( + "Unable to create instance of " + listener.getName() + + " as a listener of beanClass", e + ); + } + catch (InstantiationException e) { + throw new PersistenceException( + "Unable to create instance of " + listener.getName() + + " as a listener of beanClass", e + ); + } + Class returnType = method.getReturnType(); + Class[] args = method.getParameterTypes(); + if ( returnType != Void.TYPE || args.length != 1 ) { + throw new PersistenceException( + "Callback methods annotated in a listener bean class must return void and take one argument: " + annotation + .getName() + " - " + method + ); + } + if ( ! method.isAccessible() ) { + method.setAccessible( true ); + } + callbacks.add( 0, callback ); // listeners first + } + else { + throw new PersistenceException( + "You can only annotate one callback method with " + + annotation.getName() + " in bean class: " + beanClass.getName() + " and callback listener: " + + listener.getName() + ); + } } - catch (IllegalAccessException e) { - throw new PersistenceException( - "Unable to create instance of " + listener.getName() - + " as a listener of beanClass", e - ); - } - catch (InstantiationException e) { - throw new PersistenceException( - "Unable to create instance of " + listener.getName() - + " as a listener of beanClass", e - ); - } - Class returnType = method.getReturnType(); - Class[] args = method.getParameterTypes(); - if ( returnType != Void.TYPE || args.length != 1 ) { - throw new PersistenceException( - "Callback methods annotated in a listener bean class must return void and take one argument: " + annotation - .getName() + " - " + method - ); - } - if ( ! method.isAccessible() ) { - method.setAccessible( true ); - } - callbacks.add( 0, callback ); // listeners first } - else { - throw new PersistenceException( - "You can only annotate one callback method with " - + annotation.getName() + " in bean class: " + beanClass.getName() + " and callback listener: " - + listener.getName() - ); - } } + xListener = null; //xListener.getSuperclass(); } + while (xListener != null); } } return callbacks.toArray( new Callback[ callbacks.size() ] ); Modified: trunk/HibernateExt/ejb/src/test/org/hibernate/ejb/test/QueryTest.java =================================================================== --- trunk/HibernateExt/ejb/src/test/org/hibernate/ejb/test/QueryTest.java 2006-07-06 16:07:04 UTC (rev 10095) +++ trunk/HibernateExt/ejb/src/test/org/hibernate/ejb/test/QueryTest.java 2006-07-07 10:55:11 UTC (rev 10096) @@ -23,7 +23,7 @@ em.persist( item ); item = new Item( "Computer", "Apple II" ); em.persist( item ); - Query q = em.createQuery( "select i from Item i where i.name like :itemName" ); + Query q = em.createQuery( "select i from " + Item.class.getName() + " i where i.name like :itemName" ); q.setParameter( "itemName", "%" ); q.setMaxResults( 1 ); q.getSingleResult(); Added: trunk/HibernateExt/ejb/src/test/org/hibernate/ejb/test/emops/RefreshTest.java =================================================================== --- trunk/HibernateExt/ejb/src/test/org/hibernate/ejb/test/emops/RefreshTest.java 2006-07-06 16:07:04 UTC (rev 10095) +++ trunk/HibernateExt/ejb/src/test/org/hibernate/ejb/test/emops/RefreshTest.java 2006-07-07 10:55:11 UTC (rev 10096) @@ -0,0 +1,39 @@ +//$Id: $ +package org.hibernate.ejb.test.emops; + +import javax.persistence.EntityManager; + +import org.hibernate.ejb.test.TestCase; + +/** + * @author Emmanuel Bernard + */ +public class RefreshTest extends TestCase { + + public void testRefreshNonManaged() throws Exception { + EntityManager em = factory.createEntityManager(); + em.getTransaction().begin(); + Race race = new Race(); + em.persist( race ); + em.flush(); + em.clear(); + + try { + em.refresh( race ); + fail("Refresh should fail on a non managed entity"); + } + catch( IllegalArgumentException e) { + //success + } + + em.getTransaction().rollback(); + em.close(); + } + + public Class[] getAnnotatedClasses() { + return new Class[] { + Race.class, + Competitor.class + }; + } +} |
From: <hib...@li...> - 2006-07-06 16:07:06
|
Author: ste...@jb... Date: 2006-07-06 12:07:04 -0400 (Thu, 06 Jul 2006) New Revision: 10095 Added: tags/v32cr3/Hibernate3/ Log: copied 3.2.0.cr3 content Copied: tags/v32cr3/Hibernate3 (from rev 10094, trunk/Hibernate3) |
From: <hib...@li...> - 2006-07-06 16:04:44
|
Author: ste...@jb... Date: 2006-07-06 12:04:25 -0400 (Thu, 06 Jul 2006) New Revision: 10094 Modified: trunk/Hibernate3/doc/reference/en/master.xml Log: prep 3.2.0.cr3 Modified: trunk/Hibernate3/doc/reference/en/master.xml =================================================================== --- trunk/Hibernate3/doc/reference/en/master.xml 2006-07-06 16:03:36 UTC (rev 10093) +++ trunk/Hibernate3/doc/reference/en/master.xml 2006-07-06 16:04:25 UTC (rev 10094) @@ -33,7 +33,7 @@ <bookinfo> <title>HIBERNATE - Relational Persistence for Idiomatic Java</title> <subtitle>Hibernate Reference Documentation</subtitle> - <releaseinfo>3.2 cr2</releaseinfo> + <releaseinfo>3.2 cr3</releaseinfo> </bookinfo> <toc/> |
From: <hib...@li...> - 2006-07-06 16:03:54
|
Author: ste...@jb... Date: 2006-07-06 12:03:36 -0400 (Thu, 06 Jul 2006) New Revision: 10093 Modified: trunk/Hibernate3/src/org/hibernate/cfg/Environment.java Log: prep 3.2.0.cr3 Modified: trunk/Hibernate3/src/org/hibernate/cfg/Environment.java =================================================================== --- trunk/Hibernate3/src/org/hibernate/cfg/Environment.java 2006-07-06 16:02:24 UTC (rev 10092) +++ trunk/Hibernate3/src/org/hibernate/cfg/Environment.java 2006-07-06 16:03:36 UTC (rev 10093) @@ -153,7 +153,7 @@ */ public final class Environment { - public static final String VERSION = "3.2 cr2"; + public static final String VERSION = "3.2 cr3"; /** * <tt>ConnectionProvider</tt> implementor to use when obtaining connections |
From: <hib...@li...> - 2006-07-06 16:02:42
|
Author: ste...@jb... Date: 2006-07-06 12:02:24 -0400 (Thu, 06 Jul 2006) New Revision: 10092 Modified: trunk/Hibernate3/readme.txt Log: prep 3.2.0.cr3 Modified: trunk/Hibernate3/readme.txt =================================================================== --- trunk/Hibernate3/readme.txt 2006-07-06 16:01:45 UTC (rev 10091) +++ trunk/Hibernate3/readme.txt 2006-07-06 16:02:24 UTC (rev 10092) @@ -1,6 +1,6 @@ Hibernate - Relational Persistence for Idiomatic Java ===================================================== -version 3.2 cr2, May 5, 2006 +version 3.2 cr3, July 7, 2006 Instructions ------------ |
From: <hib...@li...> - 2006-07-06 16:02:03
|
Author: ste...@jb... Date: 2006-07-06 12:01:45 -0400 (Thu, 06 Jul 2006) New Revision: 10091 Modified: trunk/Hibernate3/build.xml Log: prep 3.2.0.cr3 Modified: trunk/Hibernate3/build.xml =================================================================== --- trunk/Hibernate3/build.xml 2006-07-06 15:59:43 UTC (rev 10090) +++ trunk/Hibernate3/build.xml 2006-07-06 16:01:45 UTC (rev 10091) @@ -19,7 +19,7 @@ <property name="version.major" value="3"/> <property name="version.minor" value="2"/> <property name="version.micro" value="0"/> - <property name="version.qualifier" value="cr2"/> + <property name="version.qualifier" value="cr3"/> <property name="version.full" value="${version.major}.${version.minor}.${version.micro}.${version.qualifier}"/> <property name="version.major_minor" value="${version.major}.${version.minor}"/> <property name="fullname" value="${name}-${version.full}"/> |
From: <hib...@li...> - 2006-07-06 16:00:01
|
Author: ste...@jb... Date: 2006-07-06 11:59:43 -0400 (Thu, 06 Jul 2006) New Revision: 10090 Modified: trunk/Hibernate3/changelog.txt Log: prep 3.2.0.cr3 Modified: trunk/Hibernate3/changelog.txt =================================================================== --- trunk/Hibernate3/changelog.txt 2006-07-06 15:52:26 UTC (rev 10089) +++ trunk/Hibernate3/changelog.txt 2006-07-06 15:59:43 UTC (rev 10090) @@ -5,6 +5,60 @@ refer to the particular case on JIRA using the issue tracking number to learn more about each case. +Chages in version 3.2 cr3 (2006.07.06) +------------------------------------------- + +** Bug + * [HHH-1452] - Native SQL query is missing join if entity includes many-to-one on secondary table + * [HHH-1507] - one-to-one can have formula or meta but not both of them. + * [HHH-1552] - Error when using ?1 and parameterList + * [HHH-1586] - ClassCastException in CollectionType.toLoggableString if using CustomCollectionType + * [HHH-1732] - EhCache.toMap still assumes Serializable objects + * [HHH-1734] - Connection leak when using hilo strategy in SE environment + * [HHH-1741] - Bug in reference documentation + * [HHH-1746] - NullPointerException at IdentNode.resolveAsNakedComponentPropertyRefLHS(IdentNode.java:195 + * [HHH-1748] - Setting a comment that contains a single quote on a query results in an unintuitive exception + * [HHH-1763] - Bug in InputStream org.hibernate.util.ConfigHelper.getResourceAsStream(String resource) + * [HHH-1791] - property update="false" ignored since 3.2.0.cr2 + * [HHH-1816] - serializing session from a named session factory to a different vm broken + * [HHH-1822] - flushing entity linked to transient instance (non cascaded) should always fail + * [HHH-1828] - registering a transaction marked for Rollback is illegal + * [HHH-1833] - Not Generating HibernateException + * [HHH-1838] - Wrong SQL generated for hql query on "any" relation + * [HHH-1855] - booleans not properly handled in assignment clause of UPDATE statements + * [HHH-1858] - wrong sql generated against many-to-any association table + * [HHH-1871] - query type autodiscovery assume wrong column when mixing entities and scalars + +** Deprecation + * [HHH-1792] - Callable update/insert/delete statements should not force rowcount out parameter + +** Improvement + * [HHH-1617] - Check the second-level cache before adding a PK to a batch fetch + * [HHH-1773] - Typo in ImprovedNamingStrategy + * [HHH-1779] - Allow Session.remove() on transient object + * [HHH-1789] - improve efficiency of collection initialization from L2 cache hits + * [HHH-1795] - default cache provider to NoCacheProvider + * [HHH-1796] - TreeCache based providers and Fqn + * [HHH-1800] - session.get() / load() should raise exception when the id is of the wrong type + * [HHH-1818] - remove() should force subsequent contains() calls to return false + * [HHH-1831] - Batch loading the same EntityKey (one side of manytoone ) more than once + * [HHH-1861] - More complete component handling in HQL + * [HHH-1881] - introduce LoggableUserType interface + +** New Feature + * [HHH-1709] - Be able to raise ENFE rather than LIE in proxies + * [HHH-1727] - Add a SQLFunctionRegistry + * [HHH-1817] - Introduce setting for JPA-QL strict compliance + * [HHH-1826] - Built-in type for char[] -> VARCHAR Byte[] and Character[] + +** Patch + * [HHH-1558] - Dialect for new database engine H2 + * [HHH-1847] - QBE 'like' clause with backslashes don't work with MySQL + +** Task + * [HHH-1839] - rename FlushMode.NEVER -> FlushMode.MANUAL + + Chages in version 3.2 cr2 (2006.05.05) ------------------------------------------- |
From: <hib...@li...> - 2006-07-06 15:52:30
|
Author: ste...@jb... Date: 2006-07-06 11:52:26 -0400 (Thu, 06 Jul 2006) New Revision: 10089 Added: tags/v32cr3/ Log: created tag directory for 3.2.0.cr3 release |
Author: ste...@jb... Date: 2006-07-06 10:59:36 -0400 (Thu, 06 Jul 2006) New Revision: 10088 Added: branches/HQL_ANTLR_2/Hibernate3/src/org/hibernate/hql/ast/resolve/AbstractPropertyPathHandler.java branches/HQL_ANTLR_2/Hibernate3/src/org/hibernate/hql/ast/resolve/FromClausePropertyPathHandler.java branches/HQL_ANTLR_2/Hibernate3/src/org/hibernate/hql/ast/resolve/NormalPropertyPathHandler.java branches/HQL_ANTLR_2/Hibernate3/src/org/hibernate/hql/ast/resolve/OnFragmentPropertyPathHandler.java branches/HQL_ANTLR_2/Hibernate3/src/org/hibernate/hql/ast/resolve/PropertyPathHandler.java branches/HQL_ANTLR_2/Hibernate3/src/org/hibernate/hql/ast/resolve/WithFragmentPropertyPathHandler.java Removed: branches/HQL_ANTLR_2/Hibernate3/src/org/hibernate/hql/ast/resolve/AbstractImplicitJoinContext.java branches/HQL_ANTLR_2/Hibernate3/src/org/hibernate/hql/ast/resolve/FromClauseImplicitJoinContext.java branches/HQL_ANTLR_2/Hibernate3/src/org/hibernate/hql/ast/resolve/ImplicitJoinContext.java branches/HQL_ANTLR_2/Hibernate3/src/org/hibernate/hql/ast/resolve/JoinSource.java branches/HQL_ANTLR_2/Hibernate3/src/org/hibernate/hql/ast/resolve/NormalImplicitJoinContext.java Modified: branches/HQL_ANTLR_2/Hibernate3/g2/parse.g branches/HQL_ANTLR_2/Hibernate3/g2/resolve.g branches/HQL_ANTLR_2/Hibernate3/src/org/hibernate/hql/ast/resolve/EntityPersisterReference.java branches/HQL_ANTLR_2/Hibernate3/src/org/hibernate/hql/ast/resolve/HqlResolver.java branches/HQL_ANTLR_2/Hibernate3/src/org/hibernate/hql/ast/resolve/HqlResolverASTFactory.java branches/HQL_ANTLR_2/Hibernate3/src/org/hibernate/hql/ast/resolve/JoinNode.java branches/HQL_ANTLR_2/Hibernate3/src/org/hibernate/hql/ast/resolve/PersisterReference.java branches/HQL_ANTLR_2/Hibernate3/src/org/hibernate/hql/ast/resolve/PersisterReferenceBuilder.java branches/HQL_ANTLR_2/Hibernate3/src/org/hibernate/hql/ast/resolve/PropertyReference.java branches/HQL_ANTLR_2/Hibernate3/src/org/hibernate/hql/ast/resolve/StatementNode.java branches/HQL_ANTLR_2/Hibernate3/src/org/hibernate/hql/ast/util/ASTPrinter.java branches/HQL_ANTLR_2/Hibernate3/test/org/hibernate/test/hql/redesign/ResolverTest.java Log: implemented handling of both on and with fragments Modified: branches/HQL_ANTLR_2/Hibernate3/g2/parse.g =================================================================== --- branches/HQL_ANTLR_2/Hibernate3/g2/parse.g 2006-07-06 12:21:30 UTC (rev 10087) +++ branches/HQL_ANTLR_2/Hibernate3/g2/parse.g 2006-07-06 14:59:36 UTC (rev 10088) @@ -198,6 +198,10 @@ return node.getText(); } + public boolean isEntityName(AST node) { + return false; + } + public boolean isJavaConstant() throws RecognitionException, TokenStreamException { return false; } @@ -286,7 +290,6 @@ : c:path { weakKeywords(); } (a:asAlias)? (p:propertyFetch)? { String entityName = extractEntityName( #c ); AST en = #( [ENTITY_NAME, entityName] ); - en.initialize( #c ); #fromClassOrOuterQueryPath = #([RANGE, "RANGE"], [ENTITY_NAME, entityName], #a, #p); } ; @@ -313,10 +316,37 @@ //fromJoin // : ( ( ( LEFT | RIGHT ) (OUTER)? ) | FULL | INNER )? JOIN^ (FETCH)? path (asAlias)? (propertyFetch)? (withClause)? // ; +//fromJoin! +// : (jt:joinType)? j:JOIN (f:FETCH)? p:path (a:asAlias)? (pf:propertyFetch)? (w:withClause)? { +// #fromJoin = #( #j, #jt, #f, #a, #pf, #p, #w ); +// } +// ; + fromJoin! - : (jt:joinType)? j:JOIN (f:FETCH)? p:path (a:asAlias)? (pf:propertyFetch)? (w:withClause)? { - #fromJoin = #( #j, #jt, #f, #a, #pf, #p, #w ); - } + : (jt:joinType)? j:JOIN (f:FETCH)? p:path (a:asAlias)? + ( + // try to use the ON keyword to disambiguate + o:onFragment { + if ( #f != null ) { + throw new org.hibernate.QueryException( "Cannot use fetch keyword in conjunction with an ad hoc join" ); + } + String entityName = extractEntityName( #p ); + AST en = #( [ENTITY_NAME, entityName] ); + #fromJoin = #( #j, #jt, #en, #a, #o ); + } + // otherwise, we need to actually check the recognized path + | { isEntityName( #p ) }? { + if ( #f != null ) { + throw new org.hibernate.QueryException( "Cannot use fetch keyword in conjunction with an ad hoc join" ); + } + String entityName = extractEntityName( #p ); + AST en = #( [ENTITY_NAME, entityName] ); + #fromJoin = #( #j, #jt, #en, #a ); + } + | (pf:propertyFetch)? (w:withClause)? { + #fromJoin = #( #j, #jt, #f, #a, #pf, #p, #w ); + } + ) ; joinType @@ -329,6 +359,9 @@ : WITH^ logicalExpression ; +onFragment + : ON^ logicalExpression + ; // Alias rule - Parses the optional 'as' token and forces an AST identifier node. asAlias Modified: branches/HQL_ANTLR_2/Hibernate3/g2/resolve.g =================================================================== --- branches/HQL_ANTLR_2/Hibernate3/g2/resolve.g 2006-07-06 12:21:30 UTC (rev 10087) +++ branches/HQL_ANTLR_2/Hibernate3/g2/resolve.g 2006-07-06 14:59:36 UTC (rev 10088) @@ -60,23 +60,39 @@ } - // implicit join context pushing/popping ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + // property-path context pushing/popping ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - protected void pushExplicitJoinContext(AST joinType, AST fetch, AST alias, AST propertyFetch) { + protected void pushFromClausePropertyPathContext(AST joinType, AST fetch, AST alias, AST propertyFetch) { } - protected void popExplicitJoinContext() { + protected void popFromClausePropertyPathContext() { } + protected void pushOnFragmentPropertyPathContext(AST rhsPersisterReference) { + } + + protected void popOnFragmentPropertyPathContext() { + } + + protected void pushWithFragmentPropertyPathContext(AST rhsPersisterReference) { + } + + protected void popWithFragmentPropertyPathContext() { + } + + // persister reference handling ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ protected AST buildEntityPersisterReference(AST entityName, AST alias, AST propertyFetch) { return null; } - protected void handleAdHocJoinNode(AST persisterReference, AST joinType, AST onClause) { + protected AST buildAdHocJoinNode(AST persisterReference, AST joinType, AST withFragment) { + return null; } + protected void applyWithFragment(AST withFragment) { + } // property reference handling ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ @@ -133,12 +149,12 @@ fromClause - : #( f:FROM range ( explicitJoin | range )* ) + : #( f:FROM rootFromElement ( explicitJoin | rootFromElement )* ) ; -range! +rootFromElement! : #( RANGE e:entityPersisterReference ) { - #range = #e; + #rootFromElement = #e; } ; @@ -149,18 +165,22 @@ ; explicitJoin! - : #(JOIN (jt:joinType)? joinRhs[jt] ) + : #( + j:JOIN (jt:joinType)? + ( + e:entityPersisterReference (on:onFragment[#e])? { + buildAdHocJoinNode( #e, #jt, #on ); + if ( on != null ) { + popOnFragmentPropertyPathContext(); + } + } + | (f:FETCH)? (a:ALIAS)? (pf:PROP_FETCH)? { pushFromClausePropertyPathContext( jt, #f, #a, #pf ); } prop:propertyPath (with:withFragment[#prop])? { + popFromClausePropertyPathContext(); + } + ) + ) ; -joinRhs! [AST joinType] - : e:entityPersisterReference (on:ON)? { - handleAdHocJoinNode( #e, joinType, on ); - } - | (f:FETCH)? (a:ALIAS)? (pf:PROP_FETCH)? { pushExplicitJoinContext( joinType, #f, #a, #pf ); } prop:propertyPath (with:WITH)? { - popExplicitJoinContext(); - } - ; - // TODO : still need to account for index operators in this series of rules... propertyPath : singlePartPropertyPath @@ -202,6 +222,21 @@ | INNER ; +onFragment[ AST rhsPersisterReference ] + : #( o:ON { pushOnFragmentPropertyPathContext( rhsPersisterReference ); } le:logicalExpr ) { + #onFragment = #( o, le ); + } + ; + +withFragment[ AST rhsPropertyReference ] + : #( w:WITH { pushWithFragmentPropertyPathContext( rhsPropertyReference ); } le:logicalExpr ) { + #withFragment = #( w, le ); + applyWithFragment( #withFragment ); + popWithFragmentPropertyPathContext(); + } + ; + + intoClause : #(i:INTO (subtree)* ) ; Deleted: branches/HQL_ANTLR_2/Hibernate3/src/org/hibernate/hql/ast/resolve/AbstractImplicitJoinContext.java =================================================================== --- branches/HQL_ANTLR_2/Hibernate3/src/org/hibernate/hql/ast/resolve/AbstractImplicitJoinContext.java 2006-07-06 12:21:30 UTC (rev 10087) +++ branches/HQL_ANTLR_2/Hibernate3/src/org/hibernate/hql/ast/resolve/AbstractImplicitJoinContext.java 2006-07-06 14:59:36 UTC (rev 10088) @@ -1,49 +0,0 @@ -package org.hibernate.hql.ast.resolve; - -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; - -/** - * Provides basic templating around how the two {@link org.hibernate.hql.ast.resolve.ImplicitJoinContext} - * method calls need to be interpreted and handled in different scenarios. - * - * @author Steve Ebersole - */ -public abstract class AbstractImplicitJoinContext implements ImplicitJoinContext { - - public static final Log log = LogFactory.getLog( AbstractImplicitJoinContext.class ); - - private PropertyPathPart prior; - - protected abstract PropertyPathPart handleRoot(String rootPathPart); - protected abstract PropertyReference handleRootAsTerminus(String pathPart); - - public final void handleIntermediatePathPart(String pathPart) { - if ( prior == null ) { - prior = handleRoot( pathPart ); - } - else { - prior = prior.handleIntermediatePathPart( pathPart ); - } - } - - public final PropertyReference handleTerminalPathPart(String pathPart) { - try { - if ( prior == null ) { - return handleRootAsTerminus( pathPart ); - } - else { - return prior.handleTerminalPathPart( pathPart ); - } - } - finally { - // clear our processing state in preparation for any future path expression - prior = null; - } - } - - protected static interface PropertyPathPart { - public PropertyPathPart handleIntermediatePathPart(String name); - public PropertyReference handleTerminalPathPart(String name); - } -} Copied: branches/HQL_ANTLR_2/Hibernate3/src/org/hibernate/hql/ast/resolve/AbstractPropertyPathHandler.java (from rev 10070, branches/HQL_ANTLR_2/Hibernate3/src/org/hibernate/hql/ast/resolve/AbstractImplicitJoinContext.java) =================================================================== --- branches/HQL_ANTLR_2/Hibernate3/src/org/hibernate/hql/ast/resolve/AbstractImplicitJoinContext.java 2006-06-30 05:55:55 UTC (rev 10070) +++ branches/HQL_ANTLR_2/Hibernate3/src/org/hibernate/hql/ast/resolve/AbstractPropertyPathHandler.java 2006-07-06 14:59:36 UTC (rev 10088) @@ -0,0 +1,72 @@ +package org.hibernate.hql.ast.resolve; + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.hibernate.hql.antlr.ResolveTokenTypes; +import antlr.collections.AST; +import antlr.ASTFactory; + +/** + * Provides basic templating around how the two {@link org.hibernate.hql.ast.resolve.PropertyPathHandler} + * method calls need to be interpreted and handled in different scenarios. + * + * @author Steve Ebersole + */ +public abstract class AbstractPropertyPathHandler implements PropertyPathHandler { + + public static final Log log = LogFactory.getLog( AbstractPropertyPathHandler.class ); + + private PropertyPathPart prior; + + protected abstract PropertyPathPart handleRoot(String rootPathPart); + protected abstract PropertyReference handleRootAsTerminus(String pathPart); + + protected void cleanup() { + } + + public final void handleIntermediatePathPart(String pathPart) { + if ( prior == null ) { + prior = handleRoot( pathPart ); + } + else { + prior = prior.handleIntermediatePathPart( pathPart ); + } + } + + public final PropertyReference handleTerminalPathPart(String pathPart) { + try { + if ( prior == null ) { + return handleRootAsTerminus( pathPart ); + } + else { + return prior.handleTerminalPathPart( pathPart ); + } + } + finally { + // clear our processing state in preparation for any future path expression + prior = null; + cleanup(); + } + } + + + protected final PropertyReference generatePropertyReference( + PersisterReference persisterReference, + String propertyName, + ASTFactory astFactory) { + PropertyReference propertyReferenceNode = ( PropertyReference ) astFactory.create( ResolveTokenTypes.PROPERTY_REF, persisterReference.getAlias() + "." + propertyName ); + + AST aliasNode = astFactory.create( ResolveTokenTypes.ALIAS, persisterReference.getAlias() ); + propertyReferenceNode.addChild( aliasNode ); + + AST propertyNameNode = astFactory.create( ResolveTokenTypes.IDENT, propertyName ); + propertyReferenceNode.addChild( propertyNameNode ); + + return propertyReferenceNode; + } + + protected static interface PropertyPathPart { + public PropertyPathPart handleIntermediatePathPart(String name); + public PropertyReference handleTerminalPathPart(String name); + } +} Modified: branches/HQL_ANTLR_2/Hibernate3/src/org/hibernate/hql/ast/resolve/EntityPersisterReference.java =================================================================== --- branches/HQL_ANTLR_2/Hibernate3/src/org/hibernate/hql/ast/resolve/EntityPersisterReference.java 2006-07-06 12:21:30 UTC (rev 10087) +++ branches/HQL_ANTLR_2/Hibernate3/src/org/hibernate/hql/ast/resolve/EntityPersisterReference.java 2006-07-06 14:59:36 UTC (rev 10088) @@ -47,18 +47,26 @@ } public Type getPropertyType(String propertyName) { - return getEntityPersister().getPropertyType( propertyName ); - } - - public boolean containsProperty(String propertyName) { try { - return getPropertyType( propertyName ) != null; + return getEntityPersister().getPropertyType( propertyName ); } catch( Throwable t ) { - return false; + return null; } } + protected PersisterReference producePersisterReference( + String propertyName, + String alias, + boolean propertyFetching, + PersisterReferenceBuilder builder) { + return null; //To change body of implemented methods use File | Settings | File Templates. + } + + public boolean containsProperty(String propertyName) { + return getPropertyType( propertyName ) != null; + } + public String toString() { return "EntityPersisterReference {entity-name=" + entityName + ", alias=" + alias + "}"; } Deleted: branches/HQL_ANTLR_2/Hibernate3/src/org/hibernate/hql/ast/resolve/FromClauseImplicitJoinContext.java =================================================================== --- branches/HQL_ANTLR_2/Hibernate3/src/org/hibernate/hql/ast/resolve/FromClauseImplicitJoinContext.java 2006-07-06 12:21:30 UTC (rev 10087) +++ branches/HQL_ANTLR_2/Hibernate3/src/org/hibernate/hql/ast/resolve/FromClauseImplicitJoinContext.java 2006-07-06 14:59:36 UTC (rev 10088) @@ -1,98 +0,0 @@ -package org.hibernate.hql.ast.resolve; - -import org.hibernate.QueryException; -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; - -/** - * todo: describe FromClauseImplicitJoinContext - * - * @author Steve Ebersole - */ -public class FromClauseImplicitJoinContext extends AbstractImplicitJoinContext { - - public static final Log log = LogFactory.getLog( FromClauseImplicitJoinContext.class ); - - private final PersisterReferenceContext persisterReferenceContext; - private final PersisterReferenceBuilder persisterReferenceBuilder; - - private final JoinType joinType; - private final String alias; - private final boolean fetching; - private final boolean propertyFetching; - - public FromClauseImplicitJoinContext( - PersisterReferenceContext persisterReferenceContext, - PersisterReferenceBuilder persisterReferenceBuilder, - JoinType joinType, - String alias, - boolean fetching, - boolean propertyFetching) { - this.persisterReferenceContext = persisterReferenceContext; - this.persisterReferenceBuilder = persisterReferenceBuilder; - this.joinType = joinType; - this.alias = alias; - this.fetching = fetching; - this.propertyFetching = propertyFetching; - } - - protected PropertyPathPart handleRoot(String rootPathPart) { - log.debug( "attempting to resolve [" + rootPathPart + "] as alias" ); - PersisterReference ref = persisterReferenceContext.locatePersisterReferenceByAlias( rootPathPart ); - if ( ref == null ) { - log.debug( "attempting to resolve [" + rootPathPart + "] as unqualified property reference" ); - ref = persisterReferenceContext.locatePersisterReferenceExposingProperty( rootPathPart ); - if ( ref == null ) { - throw new QueryException( "unable to resolve path expression root [" + rootPathPart + "]" ); - } - else { - ref = ( PersisterReference ) persisterReferenceBuilder - .buildPropertyJoin( ref, rootPathPart, joinType, null, fetching, false ) - .getFirstChild(); - } - } - return new PathPart( ref ); - } - - protected PropertyReference handleRootAsTerminus(String pathPart) { - // this should only ever mean that we have a simple unqualified property reference - log.debug( "attempting to resolve [" + pathPart + "] as unqualified property reference" ); - PersisterReference ref = persisterReferenceContext.locatePersisterReferenceExposingProperty( pathPart ); - if ( ref == null ) { - throw new QueryException( "unable to resolve unqualified property reference [" + pathPart + "]" ); - } - persisterReferenceBuilder.buildPropertyJoin( ref, pathPart, joinType, alias, fetching, propertyFetching ); - - // for joins in the from clause, we dont care about the property ref... - return null; - } - - private class PathPart implements PropertyPathPart { - private final PersisterReference persisterReference; - - public PathPart(PersisterReference persisterReference) { - this.persisterReference = persisterReference; - } - - public PropertyPathPart handleIntermediatePathPart(String name) { - return new PathPart( ( PersisterReference ) buildJoin( name, null, false ).getFirstChild() ); - } - - public PropertyReference handleTerminalPathPart(String name) { - buildJoin( name, alias, propertyFetching ); - // for joins in the from clause, we dont care about the property ref... - return null; - } - - private JoinNode buildJoin(String name, String alias, boolean propertyFetching) { - return persisterReferenceBuilder.buildPropertyJoin( - persisterReference, - name, - joinType, - alias, - fetching, - propertyFetching - ); - } - } -} Copied: branches/HQL_ANTLR_2/Hibernate3/src/org/hibernate/hql/ast/resolve/FromClausePropertyPathHandler.java (from rev 10070, branches/HQL_ANTLR_2/Hibernate3/src/org/hibernate/hql/ast/resolve/FromClauseImplicitJoinContext.java) =================================================================== --- branches/HQL_ANTLR_2/Hibernate3/src/org/hibernate/hql/ast/resolve/FromClauseImplicitJoinContext.java 2006-06-30 05:55:55 UTC (rev 10070) +++ branches/HQL_ANTLR_2/Hibernate3/src/org/hibernate/hql/ast/resolve/FromClausePropertyPathHandler.java 2006-07-06 14:59:36 UTC (rev 10088) @@ -0,0 +1,134 @@ +package org.hibernate.hql.ast.resolve; + +import org.hibernate.QueryException; +import org.hibernate.type.Type; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; + +/** + * todo: describe FromClausePropertyPathHandler + * + * @author Steve Ebersole + */ +public class FromClausePropertyPathHandler extends AbstractPropertyPathHandler { + + public static final Log log = LogFactory.getLog( FromClausePropertyPathHandler.class ); + + private final PersisterReferenceContext persisterReferenceContext; + private final PersisterReferenceBuilder persisterReferenceBuilder; + + private final JoinType joinType; + private final String alias; + private final boolean fetching; + private final boolean propertyFetching; + + public FromClausePropertyPathHandler( + PersisterReferenceContext persisterReferenceContext, + PersisterReferenceBuilder persisterReferenceBuilder, + JoinType joinType, + String alias, + boolean fetching, + boolean propertyFetching) { + this.persisterReferenceContext = persisterReferenceContext; + this.persisterReferenceBuilder = persisterReferenceBuilder; + this.joinType = joinType; + this.alias = alias; + this.fetching = fetching; + this.propertyFetching = propertyFetching; + } + + protected PropertyPathPart handleRoot(String rootPathPart) { + log.debug( "attempting to resolve [" + rootPathPart + "] as alias" ); + PersisterReference ref = persisterReferenceContext.locatePersisterReferenceByAlias( rootPathPart ); + if ( ref == null ) { + log.debug( "attempting to resolve [" + rootPathPart + "] as unqualified property reference" ); + ref = persisterReferenceContext.locatePersisterReferenceExposingProperty( rootPathPart ); + if ( ref == null ) { + throw new QueryException( "unable to resolve path expression root [" + rootPathPart + "]" ); + } + else { + ref = ( PersisterReference ) persisterReferenceBuilder + .buildPropertyJoin( ref, rootPathPart, joinType, null, fetching, false ) + .getFirstChild(); + } + } + return new PathPart( ref ); + } + + protected PropertyReference handleRootAsTerminus(String pathPart) { + // this should only ever mean that we have a simple unqualified property reference + log.debug( "attempting to resolve [" + pathPart + "] as unqualified property reference" ); + PersisterReference ref = persisterReferenceContext.locatePersisterReferenceExposingProperty( pathPart ); + if ( ref == null ) { + throw new QueryException( "unable to resolve unqualified property reference [" + pathPart + "]" ); + } + JoinNode join = persisterReferenceBuilder.buildPropertyJoin( ref, pathPart, joinType, alias, fetching, propertyFetching ); + + return new PropertyReferenceAdapter( ref, pathPart, join.getRhs() ); + } + + private class PathPart implements PropertyPathPart { + private final PersisterReference persisterReference; + + public PathPart(PersisterReference persisterReference) { + this.persisterReference = persisterReference; + } + + public PropertyPathPart handleIntermediatePathPart(String name) { + return new PathPart( ( PersisterReference ) buildJoin( name, null, false ).getFirstChild() ); + } + + public PropertyReference handleTerminalPathPart(String name) { + JoinNode join = buildJoin( name, alias, propertyFetching ); + return new PropertyReferenceAdapter( persisterReference, name, join.getRhs() ); + } + + private JoinNode buildJoin(String name, String alias, boolean propertyFetching) { + return persisterReferenceBuilder.buildPropertyJoin( + persisterReference, + name, + joinType, + alias, + fetching, + propertyFetching + ); + } + } + + public static class PropertyReferenceAdapter extends PropertyReference { + + private final PersisterReference lhs; + private final String propertyName; + private final PersisterReference rhs; + + public PropertyReferenceAdapter(PersisterReference lhs, String propertyName, PersisterReference rhs) { + this.lhs = lhs; + this.propertyName = propertyName; + this.rhs = rhs; + } + + public String getOriginationAlias() { + return lhs.getAlias(); + } + + public String getPropertyName() { + return propertyName; + } + + public PersisterReference getOrigination() { + return lhs; + } + + public Type getPropertyType() { + return lhs.getPropertyType( propertyName ); + } + + public PersisterReference getRhs() { + return rhs; + } + + public String getDisplayText() { + return " ADPATER : SHOULD NEVER END UP IN TREE {origin=" + getOrigination().getText() + ", name=" + getPropertyName() + ", type=" + getPropertyType().getName() + "}"; + } + } +} Modified: branches/HQL_ANTLR_2/Hibernate3/src/org/hibernate/hql/ast/resolve/HqlResolver.java =================================================================== --- branches/HQL_ANTLR_2/Hibernate3/src/org/hibernate/hql/ast/resolve/HqlResolver.java 2006-07-06 12:21:30 UTC (rev 10087) +++ branches/HQL_ANTLR_2/Hibernate3/src/org/hibernate/hql/ast/resolve/HqlResolver.java 2006-07-06 14:59:36 UTC (rev 10088) @@ -1,6 +1,8 @@ package org.hibernate.hql.ast.resolve; import org.hibernate.hql.antlr.GeneratedHqlResolver; +import org.hibernate.hql.antlr.ResolveTokenTypes; +import org.hibernate.hql.ast.util.ASTPrinter; import org.hibernate.engine.SessionFactoryImplementor; import org.hibernate.QueryException; @@ -8,6 +10,7 @@ import org.apache.commons.logging.LogFactory; import antlr.collections.AST; +import antlr.Token; import java.util.LinkedList; @@ -18,24 +21,26 @@ * @author Joshua Davis * @author Steve Ebersole */ -public class HqlResolver extends GeneratedHqlResolver implements HqlResolverASTFactory.Context { +public class HqlResolver extends GeneratedHqlResolver + implements HqlResolverASTFactory.InjectionContext, PersisterReferenceBuilder.Listener { private static Log log = LogFactory.getLog( HqlResolver.class ); + private static final ASTPrinter printer = new ASTPrinter( ResolveTokenTypes.class ).setShowClassNames( false ); private final SessionFactoryImplementor sessionFactory; private final PersisterReferenceBuilder persisterReferenceBuilder; private StatementNode currentStatement; - private ImplicitJoinContextTracker implicitJoinContextTracker = new ImplicitJoinContextTracker(); + private PropertyPathHandlerStack propertyPathHandlerStack = new PropertyPathHandlerStack(); public HqlResolver(SessionFactoryImplementor sessionFactory) { super(); this.sessionFactory = sessionFactory; setASTFactory( new HqlResolverASTFactory( this ) ); - persisterReferenceBuilder = new PersisterReferenceBuilder( getASTFactory(), sessionFactory ); + persisterReferenceBuilder = new PersisterReferenceBuilder( getASTFactory(), sessionFactory, this ); } - // HqlResolverASTFactory.Context implementation ~~~~~~~~~~~~~~~~~~~~~~~~~~~ + // HqlResolverASTFactory.InjectionContext implementation ~~~~~~~~~~~~~~~~~~ public SessionFactoryImplementor getSessionFactory() { return sessionFactory; @@ -46,6 +51,13 @@ } + // PersisterReferenceBuilder.Listener implementation ~~~~~~~~~~~~~~~~~~~~~~ + + public void persisterReferenceBuilt(PersisterReference persisterReference) { + currentStatement.registerPersisterReference( persisterReference ); + } + + // semantic action implementations ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ /** @@ -56,9 +68,8 @@ protected void pushStatement(AST statementNode) { log.trace( "pushing new statement context : " + currentStatement + " -> " + statementNode ); StatementNode statement = ( StatementNode ) statementNode; - statement.setPersisterReferenceBuilder( persisterReferenceBuilder ); - implicitJoinContextTracker.push( - new NormalImplicitJoinContext( statement, persisterReferenceBuilder, getASTFactory() ) + propertyPathHandlerStack.push( + new NormalPropertyPathHandler( statement, persisterReferenceBuilder, getASTFactory() ) ); if ( currentStatement != null ) { currentStatement.pushChild( statement ); @@ -72,13 +83,13 @@ protected void popStatement() { log.trace( "popping statement context : " + currentStatement + " -> " + currentStatement.getParentStatement() ); currentStatement = currentStatement.getParentStatement(); - implicitJoinContextTracker.pop(); + propertyPathHandlerStack.pop( NormalPropertyPathHandler.class ); } - protected void pushExplicitJoinContext(AST joinTypeNode, AST fetch, AST alias, AST propertyFetch) { - log.debug( "pushing explicit (from-clause) implicit join context" ); - implicitJoinContextTracker.push( - new FromClauseImplicitJoinContext( + protected void pushFromClausePropertyPathContext(AST joinTypeNode, AST fetch, AST alias, AST propertyFetch) { + log.debug( "pushing explicit (from clause) property path context" ); + propertyPathHandlerStack.push( + new FromClausePropertyPathHandler( currentStatement, persisterReferenceBuilder, resolveJoinType( joinTypeNode ), @@ -89,11 +100,49 @@ ); } - protected void popExplicitJoinContext() { - log.debug( "popping implicit join context" ); - implicitJoinContextTracker.pop(); + protected void popFromClausePropertyPathContext() { + log.debug( "popping explicit (from clause) property path context" ); + propertyPathHandlerStack.pop( FromClausePropertyPathHandler.class ); } + protected void pushOnFragmentPropertyPathContext(AST rhsPersisterReference) { + propertyPathHandlerStack.push( + new OnFragmentPropertyPathHandler( + currentStatement, + ( PersisterReference ) rhsPersisterReference, + astFactory, + sessionFactory + ) + ); + log.debug( "pushing on-fragment path handler [rhs=" + rhsPersisterReference.getText() + "]" ); + } + + protected void popOnFragmentPropertyPathContext() { + log.debug( "popping on-fragment path handler" ); + propertyPathHandlerStack.pop( OnFragmentPropertyPathHandler.class ); + } + + protected void pushWithFragmentPropertyPathContext(AST rhsPropertyReference) { + // can only be used in conjunction with property reference generated + // directly from FromClausePropertyPathHandler... + FromClausePropertyPathHandler.PropertyReferenceAdapter propertyReference = ( FromClausePropertyPathHandler.PropertyReferenceAdapter ) rhsPropertyReference; + propertyPathHandlerStack.push( + new WithFragmentPropertyPathHandler( + currentStatement, + propertyReference.getOrigination(), + propertyReference.getRhs(), + astFactory, + sessionFactory + ) + ); + log.debug( "pushing with-fragment path handler" ); + } + + protected void popWithFragmentPropertyPathContext() { + log.debug( "popping on-fragment path handler" ); + propertyPathHandlerStack.pop( WithFragmentPropertyPathHandler.class ); + } + /** * Semantic action called to perform generation of an {@link EntityPersisterReference} * representing a "root" persister reference. @@ -117,34 +166,40 @@ return node == null ? null : node.getText(); } - private JoinNode createJoinNode(JoinType type, JoinSource source, boolean fetch, PersisterReference rhs) { + private JoinNode createJoinNode(JoinType type, String propertyName, boolean fetch, PersisterReference lhs) { JoinNode node = ( JoinNode ) getASTFactory().create( JOIN, "join" ); - node.initialize( type, source, fetch, rhs ); - rhs.addChild( node ); + node.initialize( type, propertyName, fetch, lhs ); + lhs.addChild( node ); return node; } protected void handleIntermediatePathPart(AST name) { log.debug( "handling intermediate path part [" + name.getText() + "]" ); - implicitJoinContextTracker.getCurrent().handleIntermediatePathPart( name.getText() ); + propertyPathHandlerStack.getCurrent().handleIntermediatePathPart( name.getText() ); } protected AST handleTerminalPathPart(AST name) { log.debug( "handling terminal path part [" + name.getText() + "]" ); - return implicitJoinContextTracker.getCurrent().handleTerminalPathPart( name.getText() ); + return propertyPathHandlerStack.getCurrent().handleTerminalPathPart( name.getText() ); } - protected void handleAdHocJoinNode(AST persisterReference, AST joinType, AST onClause) { - // todo : need to be able to resolve the lhs join operand - EntityPersisterReference other = null; - JoinNode join = createJoinNode( resolveJoinType( joinType ), JoinSource.AD_HOC, false, other ); - join.setFirstChild( persisterReference ); - if ( onClause != null ) { - join.addChild( onClause ); - } + protected AST buildAdHocJoinNode(AST rhs, AST joinTypeNode, AST onClause) { + log.debug( printer.showAsString( onClause, "ON fragment for ad hoc join building" ) ); + JoinType joinType = resolveJoinType( joinTypeNode ); + OnFragmentPropertyPathHandler handler = ( OnFragmentPropertyPathHandler ) propertyPathHandlerStack.getCurrent(); + EntityPersisterReference lhs = ( EntityPersisterReference ) handler.getDiscoveredLhs(); + JoinNode join = createJoinNode( joinType, null, false, lhs ); + join.setFirstChild( rhs ); + join.applyExplicitJoinConditions( onClause ); + return join; } + protected void applyWithFragment(AST withFragment) { + WithFragmentPropertyPathHandler handler = ( WithFragmentPropertyPathHandler ) propertyPathHandlerStack.getCurrent(); + handler.applyWithFragment( withFragment ); + } + private JoinType resolveJoinType(AST joinType) { int joinTypeType = joinType == null ? INNER : joinType.getType(); switch ( joinTypeType ) { @@ -173,22 +228,30 @@ return buffer.toString(); } - private class ImplicitJoinContextTracker { + private class PropertyPathHandlerStack { private LinkedList stack = new LinkedList(); - public ImplicitJoinContextTracker() { + public PropertyPathHandlerStack() { } - public void push(ImplicitJoinContext context) { + public void push(PropertyPathHandler context) { stack.addFirst( context ); } - public void pop() { - stack.removeFirst(); + public void pop(Class expectedCurrentHandlerClass) { + PropertyPathHandler handler = ( PropertyPathHandler ) stack.removeFirst(); + if ( !expectedCurrentHandlerClass.isInstance( handler ) ) { + throw new IllegalStateException( + "INTERNAL PARSER ERROR : unexpected property path handler type encountered on pop" + + " [expecting=" + expectedCurrentHandlerClass.getName() + + ", encountered=" + handler.getClass().getName() + "]" + ); + } + log.debug( "popped path handler; current now : " + ( stack.isEmpty() ? null : getCurrent() ) ); } - public ImplicitJoinContext getCurrent() { - return ( ImplicitJoinContext ) stack.getFirst(); + public PropertyPathHandler getCurrent() { + return ( PropertyPathHandler ) stack.getFirst(); } } } Modified: branches/HQL_ANTLR_2/Hibernate3/src/org/hibernate/hql/ast/resolve/HqlResolverASTFactory.java =================================================================== --- branches/HQL_ANTLR_2/Hibernate3/src/org/hibernate/hql/ast/resolve/HqlResolverASTFactory.java 2006-07-06 12:21:30 UTC (rev 10087) +++ branches/HQL_ANTLR_2/Hibernate3/src/org/hibernate/hql/ast/resolve/HqlResolverASTFactory.java 2006-07-06 14:59:36 UTC (rev 10088) @@ -17,14 +17,14 @@ */ public class HqlResolverASTFactory extends HqlASTFactory implements ResolveTokenTypes { - public static interface Context { + public static interface InjectionContext { public SessionFactoryImplementor getSessionFactory(); public PersisterReferenceContext getPersisterReferenceContext(); } - private final Context context; + private final InjectionContext context; - public HqlResolverASTFactory(Context context) { + public HqlResolverASTFactory(InjectionContext context) { this.context = context; } Deleted: branches/HQL_ANTLR_2/Hibernate3/src/org/hibernate/hql/ast/resolve/ImplicitJoinContext.java =================================================================== --- branches/HQL_ANTLR_2/Hibernate3/src/org/hibernate/hql/ast/resolve/ImplicitJoinContext.java 2006-07-06 12:21:30 UTC (rev 10087) +++ branches/HQL_ANTLR_2/Hibernate3/src/org/hibernate/hql/ast/resolve/ImplicitJoinContext.java 2006-07-06 14:59:36 UTC (rev 10088) @@ -1,11 +0,0 @@ -package org.hibernate.hql.ast.resolve; - -/** - * Contract for how implicit joins are handled. - * - * @author Steve Ebersole - */ -public interface ImplicitJoinContext { - public void handleIntermediatePathPart(String pathPart); - public PropertyReference handleTerminalPathPart(String pathPart); -} Modified: branches/HQL_ANTLR_2/Hibernate3/src/org/hibernate/hql/ast/resolve/JoinNode.java =================================================================== --- branches/HQL_ANTLR_2/Hibernate3/src/org/hibernate/hql/ast/resolve/JoinNode.java 2006-07-06 12:21:30 UTC (rev 10087) +++ branches/HQL_ANTLR_2/Hibernate3/src/org/hibernate/hql/ast/resolve/JoinNode.java 2006-07-06 14:59:36 UTC (rev 10088) @@ -1,6 +1,7 @@ package org.hibernate.hql.ast.resolve; import antlr.Token; +import antlr.collections.AST; import org.hibernate.hql.ast.tree.Node; import org.hibernate.hql.ast.tree.DisplayableNode; @@ -18,7 +19,7 @@ // to both the left-hand and right-hand persister references private JoinType joinType; - private JoinSource source; + private String propertyName; private boolean fetch; private PersisterReference lhs; @@ -26,14 +27,9 @@ super.setText( "join" ); } - public JoinNode(Token tok) { - super( tok ); - super.setText( "join" ); - } - - public void initialize(JoinType joinType, JoinSource source, boolean fetch, PersisterReference lhs) { + public void initialize(JoinType joinType, String propertyName, boolean fetch, PersisterReference lhs) { this.joinType = joinType; - this.source = source; + this.propertyName = propertyName; this.fetch = fetch; this.lhs = lhs; } @@ -46,14 +42,6 @@ this.joinType = joinType; } - public JoinSource getSource() { - return source; - } - - public void setSource(JoinSource source) { - this.source = source; - } - public boolean isFetch() { return fetch; } @@ -62,8 +50,27 @@ this.fetch = fetch; } + public PersisterReference getLhs() { + return lhs; + } + + public PersisterReference getRhs() { + return ( PersisterReference ) getFirstChild(); + } + + public AST getExplicitJoinConditions() { + return getFirstChild().getNextSibling(); + } + + public void applyExplicitJoinConditions(AST conditions) { + getFirstChild().setNextSibling( conditions ); + } + public String getDisplayText() { - return "{" + "type=" + joinType + ", source=" + source + ", fetch=" + fetch + ", lhs=" + lhs.getAlias() + "}"; + return "{" + "type=" + joinType + + ", fetch=" + fetch + + ", lhs=" + ( lhs == null ? "???" : lhs.getAlias() ) + + ", property=" + ( propertyName == null ? "n/a" : propertyName ) + "}"; } public String toString() { Deleted: branches/HQL_ANTLR_2/Hibernate3/src/org/hibernate/hql/ast/resolve/JoinSource.java =================================================================== --- branches/HQL_ANTLR_2/Hibernate3/src/org/hibernate/hql/ast/resolve/JoinSource.java 2006-07-06 12:21:30 UTC (rev 10087) +++ branches/HQL_ANTLR_2/Hibernate3/src/org/hibernate/hql/ast/resolve/JoinSource.java 2006-07-06 14:59:36 UTC (rev 10088) @@ -1,55 +0,0 @@ -package org.hibernate.hql.ast.resolve; - -import java.util.HashMap; -import java.io.Serializable; - -/** - * Represents the source of a join, in the context of the HQL query. - * - * @author Steve Ebersole - */ -public class JoinSource implements Serializable { - - /** - * Indicates a join using the HQL explicit join syntax (i.e. the join keyword). - */ - public static final JoinSource EXPLICIT = new JoinSource( "explicit" ); - /** - * Indicates a join defined by implicit syntax (i.e. a path expression). - */ - public static final JoinSource IMPLICIT = new JoinSource( "implicit" ); - /** - * Indicates a join that is the result of an indexed operation (i.e. []) - * on an indexed or keyed collection (list or map). - */ - public static final JoinSource INDEXED = new JoinSource( "indexed" ); - /** - * Indicates a theta-style join (i.e. from A a, B b where a.id = b.id...) - */ - public static final JoinSource THETA = new JoinSource( "theta" ); - - public static final JoinSource AD_HOC = new JoinSource( "ad_hoc" ); - - private static final HashMap INSTANCES = new HashMap(); - static { - INSTANCES.put( EXPLICIT.name, EXPLICIT ); - INSTANCES.put( IMPLICIT.name, IMPLICIT ); - INSTANCES.put( INDEXED.name, INDEXED ); - INSTANCES.put( THETA.name, THETA ); - INSTANCES.put( AD_HOC.name, AD_HOC ); - } - - private final String name; - - private JoinSource(String name) { - this.name = name; - } - - public String toString() { - return name; - } - - private Object readResolve() { - return INSTANCES.get( name ); - } -} Deleted: branches/HQL_ANTLR_2/Hibernate3/src/org/hibernate/hql/ast/resolve/NormalImplicitJoinContext.java =================================================================== --- branches/HQL_ANTLR_2/Hibernate3/src/org/hibernate/hql/ast/resolve/NormalImplicitJoinContext.java 2006-07-06 12:21:30 UTC (rev 10087) +++ branches/HQL_ANTLR_2/Hibernate3/src/org/hibernate/hql/ast/resolve/NormalImplicitJoinContext.java 2006-07-06 14:59:36 UTC (rev 10088) @@ -1,236 +0,0 @@ -package org.hibernate.hql.ast.resolve; - -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; -import org.hibernate.hql.antlr.ResolveTokenTypes; -import org.hibernate.hql.CollectionProperties; -import org.hibernate.QueryException; -import org.hibernate.type.Type; -import org.hibernate.type.ComponentType; -import antlr.ASTFactory; -import antlr.collections.AST; - -/** - * Defines the behavior of how implicit joins are normally handled. - * <p/> - * All other implementations of {@link org.hibernate.hql.ast.resolve.ImplicitJoinContext} are - * considered special cases. - * - * @author Steve Ebersole - */ -public class NormalImplicitJoinContext extends AbstractImplicitJoinContext { - - public static final Log log = LogFactory.getLog( NormalImplicitJoinContext.class ); - - private final PersisterReferenceContext persisterReferenceContext; - private final PersisterReferenceBuilder persisterReferenceBuilder; - private final ASTFactory astFactory; - - private PropertyPathPart prior; - - public NormalImplicitJoinContext( - PersisterReferenceContext persisterReferenceContext, - PersisterReferenceBuilder persisterReferenceBuilder, - ASTFactory astFactory) { - this.persisterReferenceContext = persisterReferenceContext; - this.persisterReferenceBuilder = persisterReferenceBuilder; - this.astFactory = astFactory; - } - - protected PropertyPathPart handleRoot(String pathPart) { - PersisterReference persisterReference = resolveAsAlias( pathPart ); - if ( persisterReference != null ) { - return new PropertyPathRoot( ( EntityPersisterReference ) persisterReference ); - } - - persisterReference = resolveAsUnqualified( pathPart ); - if ( persisterReference != null ) { - return new EntityPropertyReference( ( EntityPersisterReference ) persisterReference, pathPart, false ); - } - - throw new QueryException( "unable to resolve path expression root [" + pathPart + "]" ); - } - - protected PropertyReference handleRootAsTerminus(String pathPart) { - PersisterReference ref = resolveAsUnqualified( pathPart ); - return generatePropertyReference( ref, pathPart ); - } - - - - - private PropertyReference generatePropertyReference(PersisterReference persisterReference, String propertyName) { - PropertyReference propertyReferenceNode = ( PropertyReference ) astFactory.create( ResolveTokenTypes.PROPERTY_REF, persisterReference.getAlias() + "." + propertyName ); - - AST aliasNode = astFactory.create( ResolveTokenTypes.ALIAS, persisterReference.getAlias() ); - propertyReferenceNode.addChild( aliasNode ); - - AST propertyNameNode = astFactory.create( ResolveTokenTypes.IDENT, propertyName ); - propertyReferenceNode.addChild( propertyNameNode ); - - return propertyReferenceNode; - } - - private EntityPersisterReference resolveAsAlias(String name) { - return ( EntityPersisterReference ) persisterReferenceContext.locatePersisterReferenceByAlias( name ); - } - - private EntityPersisterReference resolveAsUnqualified(String firstPathExpression) { - return persisterReferenceContext.locatePersisterReferenceExposingProperty( firstPathExpression ); - } - - private PropertyPathPart determineAppropriatePartType(EntityPersisterReference origin, String propertyName) { - Type propertyType = origin.getPropertyType( propertyName ); - if ( propertyType.isComponentType() ) { - return new ComponentPropertyReference( origin, propertyName, ( ComponentType ) propertyType ); - } - else if ( propertyType.isEntityType() ) { - return new EntityPropertyReference( origin, propertyName, false ); - } - else if ( propertyType.isCollectionType() ) { - return new CollectionPropertyReference( origin, propertyName ); - } - else { - return new SimplePropertyReference( origin, propertyName ); - } - } - - private int locateComponentPropertyIndex(ComponentType componentType, String subPropertyName) { - String[] componentPropertyNames = componentType.getPropertyNames(); - for ( int i = 0; i < componentPropertyNames.length; i++ ) { - if ( componentPropertyNames[i].equals( subPropertyName ) ) { - return i; - } - } - throw new QueryException( "could not locate component property [" + subPropertyName + "]" ); - } - - private class PropertyPathRoot implements PropertyPathPart { - private final EntityPersisterReference persisterReference; - - public PropertyPathRoot(EntityPersisterReference persisterReference) { - this.persisterReference = persisterReference; - } - - public PropertyPathPart handleIntermediatePathPart(String name) { - return determineAppropriatePartType( persisterReference, name ); - } - - public PropertyReference handleTerminalPathPart(String name) { - // todo : this really needs to consider whether a join might be needed - // based on the property type and type of clause - return generatePropertyReference( persisterReference, name ); - } - - } - - private class SimplePropertyReference implements PropertyPathPart { - private final EntityPersisterReference origin; - private final String propertyName; - - public SimplePropertyReference(EntityPersisterReference origin, String propertyName) { - this.origin = origin; - this.propertyName = propertyName; - } - - public PropertyPathPart handleIntermediatePathPart(String name) { - throw new QueryException( "cannot perform implicit join based on simple property" ); - } - - public PropertyReference handleTerminalPathPart(String name) { - throw new QueryException( "cannot perform implicit join based on simple property" ); - } - } - - private class ComponentPropertyReference implements PropertyPathPart { - private final EntityPersisterReference origin; - private final String componentPropertyName; - private final ComponentType componentType; - - public ComponentPropertyReference(EntityPersisterReference origin, String componentPropertyName) { - this( origin, componentPropertyName, ( ComponentType ) origin.getPropertyType( componentPropertyName ) ); - } - - public ComponentPropertyReference(EntityPersisterReference origin, String componentPropertyName, ComponentType componentType) { - this.origin = origin; - this.componentPropertyName = componentPropertyName; - this.componentType = componentType; - } - - public PropertyPathPart handleIntermediatePathPart(String propertyName) { - int index = locateComponentPropertyIndex( componentType, propertyName ); - String path = buildDerefPath( propertyName ); - Type propertyType = componentType.getSubtypes()[index]; - if ( propertyType.isComponentType() ) { - return new ComponentPropertyReference( origin, path, ( ComponentType ) propertyType ); - } - else if ( propertyType.isEntityType() ) { - return new EntityPropertyReference( origin, path, false ); - } - else { - return new SimplePropertyReference( origin, path ); - } - } - - public PropertyReference handleTerminalPathPart(String name) { - return generatePropertyReference( origin, buildDerefPath( name ) ); - } - - private String buildDerefPath(String subPropertyName) { - return componentPropertyName + "." + subPropertyName; - } - } - - private class EntityPropertyReference implements PropertyPathPart { - private final EntityPersisterReference origin; - private final String propertyName; - - private boolean joined; - - public EntityPropertyReference(EntityPersisterReference origin, String propertyName, boolean joined) { - this.origin = origin; - this.propertyName = propertyName; - this.joined = joined; - } - - public PropertyPathPart handleIntermediatePathPart(String name) { - EntityPersisterReference joinedPersister = ( EntityPersisterReference ) buildPropertyJoin( origin, propertyName ); - return determineAppropriatePartType( joinedPersister, name ); - } - - public PropertyReference handleTerminalPathPart(String name) { - // not always needed (i.e. : .id) - EntityPersisterReference joinedPersister = ( EntityPersisterReference ) buildPropertyJoin( origin, propertyName ); - return generatePropertyReference( joinedPersister, name ); - } - } - - private class CollectionPropertyReference implements PropertyPathPart { - private final EntityPersisterReference origin; - private final String collectionPropertyName; - - public CollectionPropertyReference(EntityPersisterReference origin, String collectionPropertyName) { - this.origin = origin; - this.collectionPropertyName = collectionPropertyName; - } - - public PropertyPathPart handleIntermediatePathPart(String name) { - throw new QueryException( "illegal attempt to perform implicit join across collection property" ); - } - - public PropertyReference handleTerminalPathPart(String name) { - if ( CollectionProperties.isAnyCollectionProperty( name ) ) { - CollectionPersisterReference joinedPersister = ( CollectionPersisterReference ) buildPropertyJoin( origin, collectionPropertyName ); - return generatePropertyReference( joinedPersister, name ); - } - throw new QueryException( "illegal attempt to perform implicit join across collection property" ); - } - } - - - private PersisterReference buildPropertyJoin(EntityPersisterReference origin, String propertyName) { - return ( PersisterReference ) persisterReferenceBuilder - .buildPropertyJoin( origin, propertyName, JoinType.INNER, null, false, false ) - .getFirstChild(); - } -} Copied: branches/HQL_ANTLR_2/Hibernate3/src/org/hibernate/hql/ast/resolve/NormalPropertyPathHandler.java (from rev 10070, branches/HQL_ANTLR_2/Hibernate3/src/org/hibernate/hql/ast/resolve/NormalImplicitJoinContext.java) =================================================================== --- branches/HQL_ANTLR_2/Hibernate3/src/org/hibernate/hql/ast/resolve/NormalImplicitJoinContext.java 2006-06-30 05:55:55 UTC (rev 10070) +++ branches/HQL_ANTLR_2/Hibernate3/src/org/hibernate/hql/ast/resolve/NormalPropertyPathHandler.java 2006-07-06 14:59:36 UTC (rev 10088) @@ -0,0 +1,218 @@ +package org.hibernate.hql.ast.resolve; + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.hibernate.hql.CollectionProperties; +import org.hibernate.QueryException; +import org.hibernate.type.Type; +import org.hibernate.type.ComponentType; +import antlr.ASTFactory; + +/** + * Defines the behavior of how implicit joins are normally handled. + * <p/> + * All other implementations of {@link org.hibernate.hql.ast.resolve.PropertyPathHandler} are + * considered special cases. + * + * @author Steve Ebersole + */ +public class NormalPropertyPathHandler extends AbstractPropertyPathHandler { + + public static final Log log = LogFactory.getLog( NormalPropertyPathHandler.class ); + + private final PersisterReferenceContext persisterReferenceContext; + private final PersisterReferenceBuilder persisterReferenceBuilder; + private final ASTFactory astFactory; + + public NormalPropertyPathHandler( + PersisterReferenceContext persisterReferenceContext, + PersisterReferenceBuilder persisterReferenceBuilder, + ASTFactory astFactory) { + this.persisterReferenceContext = persisterReferenceContext; + this.persisterReferenceBuilder = persisterReferenceBuilder; + this.astFactory = astFactory; + } + + protected PropertyPathPart handleRoot(String pathPart) { + PersisterReference persisterReference = resolveAsAlias( pathPart ); + if ( persisterReference != null ) { + return new PropertyPathRoot( ( EntityPersisterReference ) persisterReference ); + } + + persisterReference = resolveAsUnqualified( pathPart ); + if ( persisterReference != null ) { + return new EntityPropertyReference( ( EntityPersisterReference ) persisterReference, pathPart, false ); + } + + throw new QueryException( "unable to resolve path expression root [" + pathPart + "]" ); + } + + protected PropertyReference handleRootAsTerminus(String pathPart) { + PersisterReference ref = resolveAsUnqualified( pathPart ); + return generatePropertyReference( ref, pathPart, astFactory ); + } + + + private EntityPersisterReference resolveAsAlias(String name) { + return ( EntityPersisterReference ) persisterReferenceContext.locatePersisterReferenceByAlias( name ); + } + + private EntityPersisterReference resolveAsUnqualified(String firstPathExpression) { + return persisterReferenceContext.locatePersisterReferenceExposingProperty( firstPathExpression ); + } + + private PropertyPathPart determineAppropriatePartType(EntityPersisterReference origin, String propertyName) { + Type propertyType = origin.getPropertyType( propertyName ); + if ( propertyType.isComponentType() ) { + return new ComponentPropertyReference( origin, propertyName, ( ComponentType ) propertyType ); + } + else if ( propertyType.isEntityType() ) { + return new EntityPropertyReference( origin, propertyName, false ); + } + else if ( propertyType.isCollectionType() ) { + return new CollectionPropertyReference( origin, propertyName ); + } + else { + return new SimplePropertyReference( origin, propertyName ); + } + } + + private int locateComponentPropertyIndex(ComponentType componentType, String subPropertyName) { + String[] componentPropertyNames = componentType.getPropertyNames(); + for ( int i = 0; i < componentPropertyNames.length; i++ ) { + if ( componentPropertyNames[i].equals( subPropertyName ) ) { + return i; + } + } + throw new QueryException( "could not locate component property [" + subPropertyName + "]" ); + } + + private class PropertyPathRoot implements PropertyPathPart { + private final EntityPersisterReference persisterReference; + + public PropertyPathRoot(EntityPersisterReference persisterReference) { + this.persisterReference = persisterReference; + } + + public PropertyPathPart handleIntermediatePathPart(String name) { + return determineAppropriatePartType( persisterReference, name ); + } + + public PropertyReference handleTerminalPathPart(String name) { + // todo : this really needs to consider whether a join might be needed + // based on the property type and type of clause + return generatePropertyReference( persisterReference, name, astFactory ); + } + + } + + private class SimplePropertyReference implements PropertyPathPart { + private final EntityPersisterReference origin; + private final String propertyName; + + public SimplePropertyReference(EntityPersisterReference origin, String propertyName) { + this.origin = origin; + this.propertyName = propertyName; + } + + public PropertyPathPart handleIntermediatePathPart(String name) { + throw new QueryException( "cannot perform implicit join based on simple property" ); + } + + public PropertyReference handleTerminalPathPart(String name) { + throw new QueryException( "cannot perform implicit join based on simple property" ); + } + } + + private class ComponentPropertyReference implements PropertyPathPart { + private final EntityPersisterReference origin; + private final String componentPropertyName; + private final ComponentType componentType; + + public ComponentPropertyReference(EntityPersisterReference origin, String componentPropertyName) { + this( origin, componentPropertyName, ( ComponentType ) origin.getPropertyType( componentPropertyName ) ); + } + + public ComponentPropertyReference(EntityPersisterReference origin, String componentPropertyName, ComponentType componentType) { + this.origin = origin; + this.componentPropertyName = componentPropertyName; + this.componentType = componentType; + } + + public PropertyPathPart handleIntermediatePathPart(String propertyName) { + int index = locateComponentPropertyIndex( componentType, propertyName ); + String path = buildDerefPath( propertyName ); + Type propertyType = componentType.getSubtypes()[index]; + if ( propertyType.isComponentType() ) { + return new ComponentPropertyReference( origin, path, ( ComponentType ) propertyType ); + } + else if ( propertyType.isEntityType() ) { + return new EntityPropertyReference( origin, path, false ); + } + else { + return new SimplePropertyReference( origin, path ); + } + } + + public PropertyReference handleTerminalPathPart(String name) { + return generatePropertyReference( origin, buildDerefPath( name ), astFactory ); + } + + private String buildDerefPath(String subPropertyName) { + return componentPropertyName + "." + subPropertyName; + } + } + + private class EntityPropertyReference implements PropertyPathPart { + private final EntityPersisterReference origin; + private final String propertyName; + + private boolean joined; + + public EntityPropertyReference(EntityPersisterReference origin, String propertyName, boolean joined) { + this.origin = origin; + this.propertyName = propertyName; + this.joined = joined; + } + + public PropertyPathPart handleIntermediatePathPart(String name) { + EntityPersisterReference joinedPersister = ( EntityPersisterReference ) buildPropertyJoin( origin, propertyName ); + return determineAppropriatePartType( joinedPersister, name ); + } + + public PropertyReference handleTerminalPathPart(String name) { + // not always needed (i.e. : .id) + EntityPersisterReference joinedPersister = ( EntityPersisterReference ) buildPropertyJoin( origin, propertyName ); + return generatePropertyReference( joinedPersister, name, astFactory ); + } + } + + private class CollectionPropertyReference implements PropertyPathPart { + private final EntityPersisterReference origin; + private final String collectionPropertyName; + + public CollectionPropertyReference(EntityPersisterReference origin, String collectionPropertyName) { + this.origin = origin; + this.collectionPropertyName = collectionPropertyName; + } + + public PropertyPathPart handleIntermediatePathPart(String name) { + throw new QueryException( "illegal attempt to perform implicit join across collection property" ); + } + + public PropertyReference handleTerminalPathPart(String name) { + if ( CollectionProperties.isAnyCollectionProperty( name ) ) { + CollectionPersisterReference joinedPersister = ( CollectionPersisterReference ) buildPropertyJoin( origin, collectionPropertyName ); + return generatePropertyReference( joinedPersister, name, astFactory ); + } + throw new QueryException( "illegal attempt to perform implicit join across collection property" ); + } + } + + + private PersisterReference buildPropertyJoin(EntityPersisterReference origin, String propertyName) { + return ( PersisterReference ) persisterReferenceBuilder + .buildPropertyJoin( origin, propertyName, JoinType.INNER, null, false, false ) + .getFirstChild(); + } +} Added: branches/HQL_ANTLR_2/Hibernate3/src/org/hibernate/hql/ast/resolve/OnFragmentPropertyPathHandler.java =================================================================== --- branches/HQL_ANTLR_2/Hibernate3/src/org/hibernate/hql/ast/resolve/OnFragmentPropertyPathHandler.java 2006-07-06 12:21:30 UTC (rev 10087) +++ branches/HQL_ANTLR_2/Hibernate3/src/org/hibernate/hql/ast/resolve/OnFragmentPropertyPathHandler.java 2006-07-06 14:59:36 UTC (rev 10088) @@ -0,0 +1,159 @@ +package org.hibernate.hql.ast.resolve; + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.hibernate.type.Type; +import org.hibernate.QueryException; +import org.hibernate.engine.SessionFactoryImplementor; +import antlr.ASTFactory; + +/** + * todo: describe OnFragmentPropertyPathHandler + * + * @author Steve Ebersole + */ +public class OnFragmentPropertyPathHandler extends AbstractPropertyPathHandler { + + public static final Log log = LogFactory.getLog( OnFragmentPropertyPathHandler.class ); + + private final PersisterReferenceContext persisterReferenceContext; + private final PersisterReference joinRhs; + private final ASTFactory astFactory; + private final SessionFactoryImplementor sessionFactory; + + private PersisterReference joinLhs; + + public OnFragmentPropertyPathHandler( + PersisterReferenceContext persisterReferenceContext, + PersisterReference joinRhs, + ASTFactory astFactory, + SessionFactoryImplementor sessionFactory) { + this.astFactory = astFactory; + this.persisterReferenceContext = persisterReferenceContext; + this.joinRhs = joinRhs; + this.sessionFactory = sessionFactory; + } + + public PersisterReference getDiscoveredLhs() { + return joinLhs; + } + + protected PropertyPathPart handleRoot(String rootPathPart) { + // might indicte a number of situations: + // 1) alias to joinRhs + // 2) unq... [truncated message content] |
From: <hib...@li...> - 2006-07-06 12:21:48
|
Author: ste...@jb... Date: 2006-07-06 08:21:30 -0400 (Thu, 06 Jul 2006) New Revision: 10087 Modified: trunk/Hibernate3/src/org/hibernate/loader/custom/CustomLoader.java Log: HHH-1871 : native sql partial auto-discovery with entity/scalar result mix Modified: trunk/Hibernate3/src/org/hibernate/loader/custom/CustomLoader.java =================================================================== --- trunk/Hibernate3/src/org/hibernate/loader/custom/CustomLoader.java 2006-07-05 18:17:27 UTC (rev 10086) +++ trunk/Hibernate3/src/org/hibernate/loader/custom/CustomLoader.java 2006-07-06 12:21:30 UTC (rev 10087) @@ -101,8 +101,7 @@ resultColumnProcessors.add( new ScalarResultColumnProcessor( scalarRtn.getColumnAlias(), - scalarRtn.getType(), - resultTypes.size() + scalarRtn.getType() ) ); hasScalars = true; @@ -377,12 +376,12 @@ this.columnProcessors = columnProcessors; } - public void prepareForAutoDiscovery(ResultSetMetaData resultSetMetaData) throws SQLException { + public void prepareForAutoDiscovery(Metadata metadata) throws SQLException { if ( columnProcessors == null || columnProcessors.length == 0 ) { - int columns = resultSetMetaData.getColumnCount(); + int columns = metadata.getColumnCount(); columnProcessors = new ResultColumnProcessor[ columns ]; for ( int i = 1; i <= columns; i++ ) { - columnProcessors[ i - 1 ] = new ScalarResultColumnProcessor( null, null, i ); + columnProcessors[ i - 1 ] = new ScalarResultColumnProcessor( i ); } } @@ -432,7 +431,7 @@ private static interface ResultColumnProcessor { public Object extract(Object[] data, ResultSet resultSet, SessionImplementor session) throws SQLException, HibernateException; - public void performDiscovery(ResultSetMetaData resultSetMetaData, List types, List aliases) throws SQLException, HibernateException; + public void performDiscovery(Metadata metadata, List types, List aliases) throws SQLException, HibernateException; } public class NonScalarResultColumnProcessor implements ResultColumnProcessor { @@ -449,20 +448,23 @@ return data[ position ]; } - public void performDiscovery(ResultSetMetaData resultSetMetaData, List types, List aliases) { + public void performDiscovery(Metadata metadata, List types, List aliases) { } } public class ScalarResultColumnProcessor implements ResultColumnProcessor { - private final int position; + private int position = -1; private String alias; private Type type; - public ScalarResultColumnProcessor(String alias, Type type, int position) { + public ScalarResultColumnProcessor(int position) { + this.position = position; + } + + public ScalarResultColumnProcessor(String alias, Type type) { this.alias = alias; this.type = type; - this.position = position; } public Object extract( @@ -472,42 +474,31 @@ return type.nullSafeGet( resultSet, alias, session, null ); } - public void performDiscovery(ResultSetMetaData resultSetMetaData, List types, List aliases) throws SQLException { + public void performDiscovery(Metadata metadata, List types, List aliases) throws SQLException { if ( alias == null ) { - alias = resultSetMetaData.getColumnName( position ); + alias = metadata.getColumnName( position ); } + else if ( position < 0 ) { + position = metadata.resolveColumnPosition( alias ); + } if ( type == null ) { - type = getHibernateType( position, resultSetMetaData ); + type = metadata.getHibernateType( position ); } types.add( type ); aliases.add( alias ); } } - private Type getHibernateType(int columnPos, ResultSetMetaData metaData) throws SQLException { - int columnType = metaData.getColumnType( columnPos ); - int scale = metaData.getScale( columnPos ); - int precision = metaData.getPrecision( columnPos ); - return TypeFactory.heuristicType( - getFactory().getDialect().getHibernateTypeName( - columnType, - precision, - precision, - scale - ) - ); - } - protected void autoDiscoverTypes(ResultSet rs) { try { - ResultSetMetaData metaData = rs.getMetaData(); + Metadata metadata = new Metadata( getFactory(), rs ); List aliases = new ArrayList(); List types = new ArrayList(); - rowProcessor.prepareForAutoDiscovery( metaData ); + rowProcessor.prepareForAutoDiscovery( metadata ); for ( int i = 0; i < rowProcessor.columnProcessors.length; i++ ) { - rowProcessor.columnProcessors[i].performDiscovery( metaData, types, aliases ); + rowProcessor.columnProcessors[i].performDiscovery( metadata, types, aliases ); } resultTypes = ArrayHelper.toTypeArray( types ); @@ -518,4 +509,61 @@ } } + private static class Metadata { + private final SessionFactoryImplementor factory; + private final ResultSet resultSet; + private final ResultSetMetaData resultSetMetaData; + + public Metadata(SessionFactoryImplementor factory, ResultSet resultSet) throws HibernateException { + try { + this.factory = factory; + this.resultSet = resultSet; + this.resultSetMetaData = resultSet.getMetaData(); + } + catch( SQLException e ) { + throw new HibernateException( "Could not extract result set metadata", e ); + } + } + + public int getColumnCount() throws HibernateException { + try { + return resultSetMetaData.getColumnCount(); + } + catch( SQLException e ) { + throw new HibernateException( "Could not determine result set column count", e ); + } + } + + public int resolveColumnPosition(String columnName) throws HibernateException { + try { + return resultSet.findColumn( columnName ); + } + catch( SQLException e ) { + throw new HibernateException( "Could not resolve column name in result set [" + columnName + "]", e ); + } + } + + public String getColumnName(int position) throws HibernateException { + try { + return resultSetMetaData.getColumnName( position ); + } + catch( SQLException e ) { + throw new HibernateException( "Could not resolve column name [" + position + "]", e ); + } + } + + public Type getHibernateType(int columnPos) throws SQLException { + int columnType = resultSetMetaData.getColumnType( columnPos ); + int scale = resultSetMetaData.getScale( columnPos ); + int precision = resultSetMetaData.getPrecision( columnPos ); + return TypeFactory.heuristicType( + factory.getDialect().getHibernateTypeName( + columnType, + precision, + precision, + scale + ) + ); + } + } } |
Author: ste...@jb... Date: 2006-07-05 14:17:27 -0400 (Wed, 05 Jul 2006) New Revision: 10086 Modified: trunk/Hibernate3/src/org/hibernate/collection/PersistentArrayHolder.java trunk/Hibernate3/src/org/hibernate/collection/PersistentBag.java trunk/Hibernate3/src/org/hibernate/collection/PersistentCollection.java trunk/Hibernate3/src/org/hibernate/collection/PersistentElementHolder.java trunk/Hibernate3/src/org/hibernate/collection/PersistentIdentifierBag.java trunk/Hibernate3/src/org/hibernate/collection/PersistentIndexedElementHolder.java trunk/Hibernate3/src/org/hibernate/collection/PersistentList.java trunk/Hibernate3/src/org/hibernate/collection/PersistentMap.java trunk/Hibernate3/src/org/hibernate/collection/PersistentSet.java trunk/Hibernate3/src/org/hibernate/engine/CollectionLoadContext.java trunk/Hibernate3/src/org/hibernate/type/ArrayType.java trunk/Hibernate3/src/org/hibernate/type/BagType.java trunk/Hibernate3/src/org/hibernate/type/CollectionType.java trunk/Hibernate3/src/org/hibernate/type/CustomCollectionType.java trunk/Hibernate3/src/org/hibernate/type/IdentifierBagType.java trunk/Hibernate3/src/org/hibernate/type/ListType.java trunk/Hibernate3/src/org/hibernate/type/MapType.java trunk/Hibernate3/src/org/hibernate/type/SetType.java trunk/Hibernate3/src/org/hibernate/usertype/UserCollectionType.java trunk/Hibernate3/test/org/hibernate/test/usercollection/MyListType.java trunk/Hibernate3/test/org/hibernate/test/usercollection/UserCollectionTypeTest.java Log: HHH-1789 : proper collection sizing for improved performance Modified: trunk/Hibernate3/src/org/hibernate/collection/PersistentArrayHolder.java =================================================================== --- trunk/Hibernate3/src/org/hibernate/collection/PersistentArrayHolder.java 2006-07-05 16:35:26 UTC (rev 10085) +++ trunk/Hibernate3/src/org/hibernate/collection/PersistentArrayHolder.java 2006-07-05 18:17:27 UTC (rev 10086) @@ -137,7 +137,7 @@ return true; } - public void beforeInitialize(CollectionPersister persister) { + public void beforeInitialize(CollectionPersister persister, int anticipatedSize) { //if (tempList==null) throw new UnsupportedOperationException("Can't lazily initialize arrays"); } Modified: trunk/Hibernate3/src/org/hibernate/collection/PersistentBag.java =================================================================== --- trunk/Hibernate3/src/org/hibernate/collection/PersistentBag.java 2006-07-05 16:35:26 UTC (rev 10085) +++ trunk/Hibernate3/src/org/hibernate/collection/PersistentBag.java 2006-07-05 18:17:27 UTC (rev 10086) @@ -71,8 +71,8 @@ return element; } - public void beforeInitialize(CollectionPersister persister) { - this.bag = (List) persister.getCollectionType().instantiate(); + public void beforeInitialize(CollectionPersister persister, int anticipatedSize) { + this.bag = ( List ) persister.getCollectionType().instantiate( anticipatedSize ); } public boolean equalsSnapshot(CollectionPersister persister) throws HibernateException { @@ -134,11 +134,14 @@ public void initializeFromCache(CollectionPersister persister, Serializable disassembled, Object owner) throws HibernateException { - beforeInitialize(persister); Serializable[] array = (Serializable[]) disassembled; - for ( int i=0; i<array.length; i++ ) { + int size = array.length; + beforeInitialize( persister, size ); + for ( int i = 0; i < size; i++ ) { Object element = persister.getElementType().assemble( array[i], getSession(), owner ); - if ( element!=null ) bag.add( element ); + if ( element!=null ) { + bag.add( element ); + } } } Modified: trunk/Hibernate3/src/org/hibernate/collection/PersistentCollection.java =================================================================== --- trunk/Hibernate3/src/org/hibernate/collection/PersistentCollection.java 2006-07-05 16:35:26 UTC (rev 10085) +++ trunk/Hibernate3/src/org/hibernate/collection/PersistentCollection.java 2006-07-05 18:17:27 UTC (rev 10086) @@ -151,8 +151,11 @@ /** * Called before any elements are read into the collection, * allowing appropriate initializations to occur. + * + * @param persister The underlying collection persister. + * @param anticipatedSize The anticipated size of the collection after initilization is complete. */ - public void beforeInitialize(CollectionPersister persister); + public void beforeInitialize(CollectionPersister persister, int anticipatedSize); /** * Does the current state exactly match the snapshot? Modified: trunk/Hibernate3/src/org/hibernate/collection/PersistentElementHolder.java =================================================================== --- trunk/Hibernate3/src/org/hibernate/collection/PersistentElementHolder.java 2006-07-05 16:35:26 UTC (rev 10085) +++ trunk/Hibernate3/src/org/hibernate/collection/PersistentElementHolder.java 2006-07-05 18:17:27 UTC (rev 10086) @@ -120,7 +120,7 @@ return result.iterator(); } - public void beforeInitialize(CollectionPersister persister) {} + public void beforeInitialize(CollectionPersister persister, int anticipatedSize) {} public boolean isDirectlyAccessible() { return true; Modified: trunk/Hibernate3/src/org/hibernate/collection/PersistentIdentifierBag.java =================================================================== --- trunk/Hibernate3/src/org/hibernate/collection/PersistentIdentifierBag.java 2006-07-05 16:35:26 UTC (rev 10085) +++ trunk/Hibernate3/src/org/hibernate/collection/PersistentIdentifierBag.java 2006-07-05 18:17:27 UTC (rev 10086) @@ -61,9 +61,10 @@ public void initializeFromCache(CollectionPersister persister, Serializable disassembled, Object owner) throws HibernateException { - beforeInitialize(persister); Serializable[] array = (Serializable[]) disassembled; - for ( int i=0; i<array.length; i+=2 ) { + int size = array.length; + beforeInitialize( persister, size ); + for ( int i = 0; i < size; i+=2 ) { identifiers.put( new Integer(i/2), persister.getIdentifierType().assemble( array[i], getSession(), owner ) @@ -159,14 +160,13 @@ return values.toArray(a); } - public void beforeInitialize(CollectionPersister persister) { - identifiers = new HashMap(); - values = new ArrayList(); + public void beforeInitialize(CollectionPersister persister, int anticipatedSize) { + identifiers = anticipatedSize <= 0 ? new HashMap() : new HashMap( anticipatedSize + 1 + (int)( anticipatedSize * .75f ), .75f ); + values = anticipatedSize <= 0 ? new ArrayList() : new ArrayList( anticipatedSize ); } public Serializable disassemble(CollectionPersister persister) - throws HibernateException { - + throws HibernateException { Serializable[] result = new Serializable[ values.size() * 2 ]; int i=0; for (int j=0; j< values.size(); j++) { Modified: trunk/Hibernate3/src/org/hibernate/collection/PersistentIndexedElementHolder.java =================================================================== --- trunk/Hibernate3/src/org/hibernate/collection/PersistentIndexedElementHolder.java 2006-07-05 16:35:26 UTC (rev 10085) +++ trunk/Hibernate3/src/org/hibernate/collection/PersistentIndexedElementHolder.java 2006-07-05 18:17:27 UTC (rev 10086) @@ -161,7 +161,7 @@ return result.iterator(); } - public void beforeInitialize(CollectionPersister persister) {} + public void beforeInitialize(CollectionPersister persister, int anticipatedSize) {} public boolean isDirectlyAccessible() { return true; Modified: trunk/Hibernate3/src/org/hibernate/collection/PersistentList.java =================================================================== --- trunk/Hibernate3/src/org/hibernate/collection/PersistentList.java 2006-07-05 16:35:26 UTC (rev 10085) +++ trunk/Hibernate3/src/org/hibernate/collection/PersistentList.java 2006-07-05 18:17:27 UTC (rev 10086) @@ -74,8 +74,8 @@ setDirectlyAccessible(true); } - public void beforeInitialize(CollectionPersister persister) { - this.list = (List) persister.getCollectionType().instantiate(); + public void beforeInitialize(CollectionPersister persister, int anticipatedSize) { + this.list = ( List ) persister.getCollectionType().instantiate( anticipatedSize ); } public boolean isWrapper(Object collection) { @@ -372,9 +372,10 @@ public void initializeFromCache(CollectionPersister persister, Serializable disassembled, Object owner) throws HibernateException { - beforeInitialize(persister); - Serializable[] array = (Serializable[]) disassembled; - for ( int i=0; i<array.length; i++ ) { + Serializable[] array = ( Serializable[] ) disassembled; + int size = array.length; + beforeInitialize( persister, size ); + for ( int i = 0; i < size; i++ ) { list.add( persister.getElementType().assemble( array[i], getSession(), owner ) ); } } Modified: trunk/Hibernate3/src/org/hibernate/collection/PersistentMap.java =================================================================== --- trunk/Hibernate3/src/org/hibernate/collection/PersistentMap.java 2006-07-05 16:35:26 UTC (rev 10085) +++ trunk/Hibernate3/src/org/hibernate/collection/PersistentMap.java 2006-07-05 18:17:27 UTC (rev 10086) @@ -31,10 +31,8 @@ protected Map map; - public Serializable getSnapshot(CollectionPersister persister) - throws HibernateException { + public Serializable getSnapshot(CollectionPersister persister) throws HibernateException { EntityMode entityMode = getSession().getEntityMode(); - HashMap clonedMap = new HashMap( map.size() ); Iterator iter = map.entrySet().iterator(); while ( iter.hasNext() ) { @@ -77,8 +75,8 @@ public PersistentMap() {} //needed for SOAP libraries, etc - public void beforeInitialize(CollectionPersister persister) { - this.map = (Map) persister.getCollectionType().instantiate(); + public void beforeInitialize(CollectionPersister persister, int anticipatedSize) { + this.map = ( Map ) persister.getCollectionType().instantiate( anticipatedSize ); } public PersistentMap(SessionImplementor session, Map map) { @@ -317,9 +315,10 @@ public void initializeFromCache(CollectionPersister persister, Serializable disassembled, Object owner) throws HibernateException { - beforeInitialize(persister); - Serializable[] array = (Serializable[]) disassembled; - for (int i=0; i<array.length; i+=2 ) { + Serializable[] array = ( Serializable[] ) disassembled; + int size = array.length; + beforeInitialize( persister, size ); + for ( int i = 0; i < size; i+=2 ) { map.put( persister.getIndexType().assemble( array[i], getSession(), owner ), persister.getElementType().assemble( array[i+1], getSession(), owner ) Modified: trunk/Hibernate3/src/org/hibernate/collection/PersistentSet.java =================================================================== --- trunk/Hibernate3/src/org/hibernate/collection/PersistentSet.java 2006-07-05 16:35:26 UTC (rev 10085) +++ trunk/Hibernate3/src/org/hibernate/collection/PersistentSet.java 2006-07-05 18:17:27 UTC (rev 10086) @@ -78,8 +78,8 @@ public PersistentSet() {} //needed for SOAP libraries, etc - public void beforeInitialize(CollectionPersister persister) { - this.set = (Set) persister.getCollectionType().instantiate(); + public void beforeInitialize(CollectionPersister persister, int anticipatedSize) { + this.set = ( Set ) persister.getCollectionType().instantiate( anticipatedSize ); } public PersistentSet(SessionImplementor session, java.util.Set set) { @@ -95,11 +95,14 @@ public void initializeFromCache(CollectionPersister persister, Serializable disassembled, Object owner) throws HibernateException { - beforeInitialize(persister); - Serializable[] array = (Serializable[]) disassembled; - for (int i=0; i<array.length; i++ ) { + Serializable[] array = ( Serializable[] ) disassembled; + int size = array.length; + beforeInitialize( persister, size ); + for (int i = 0; i < size; i++ ) { Object element = persister.getElementType().assemble( array[i], getSession(), owner ); - if (element!=null) set.add(element); + if ( element != null ) { + set.add( element ); + } } } Modified: trunk/Hibernate3/src/org/hibernate/engine/CollectionLoadContext.java =================================================================== --- trunk/Hibernate3/src/org/hibernate/engine/CollectionLoadContext.java 2006-07-05 16:35:26 UTC (rev 10085) +++ trunk/Hibernate3/src/org/hibernate/engine/CollectionLoadContext.java 2006-07-05 18:17:27 UTC (rev 10086) @@ -102,7 +102,7 @@ .instantiate( context.getSession(), persister, key ); } } - collection.beforeInitialize(persister); + collection.beforeInitialize( persister, -1 ); collection.beginRead(); addLoadingCollectionEntry(ckey, collection, persister, resultSetId); return collection; Modified: trunk/Hibernate3/src/org/hibernate/type/ArrayType.java =================================================================== --- trunk/Hibernate3/src/org/hibernate/type/ArrayType.java 2006-07-05 16:35:26 UTC (rev 10085) +++ trunk/Hibernate3/src/org/hibernate/type/ArrayType.java 2006-07-05 18:17:27 UTC (rev 10086) @@ -96,7 +96,7 @@ } - public Object instantiate() { + public Object instantiate(int anticipatedSize) { throw new UnsupportedOperationException(); } Modified: trunk/Hibernate3/src/org/hibernate/type/BagType.java =================================================================== --- trunk/Hibernate3/src/org/hibernate/type/BagType.java 2006-07-05 16:35:26 UTC (rev 10085) +++ trunk/Hibernate3/src/org/hibernate/type/BagType.java 2006-07-05 18:17:27 UTC (rev 10086) @@ -43,9 +43,8 @@ } } - public Object instantiate() { - //TODO: does not work for EntityMode.DOM4J yet - return new ArrayList(); + public Object instantiate(int anticipatedSize) { + return anticipatedSize <= 0 ? new ArrayList() : new ArrayList( anticipatedSize + 1 ); } } Modified: trunk/Hibernate3/src/org/hibernate/type/CollectionType.java =================================================================== --- trunk/Hibernate3/src/org/hibernate/type/CollectionType.java 2006-07-05 16:35:26 UTC (rev 10085) +++ trunk/Hibernate3/src/org/hibernate/type/CollectionType.java 2006-07-05 18:17:27 UTC (rev 10086) @@ -418,15 +418,29 @@ return result; } - - public Object instantiateResult(Object original) { - return instantiate(); + + /** + * Instantiate a new "underlying" collection exhibiting the same capacity + * charactersitcs and the passed "original". + * + * @param original The original collection. + * @return The newly instantiated collection. + */ + protected Object instantiateResult(Object original) { + // by default just use an unanticipated capacity since we don't + // know how to extract the capacity to use from original here... + return instantiate( -1 ); } /** - * Instantiate an empty instance of the "underlying" collection (not a wrapper) + * Instantiate an empty instance of the "underlying" collection (not a wrapper), + * but with the given anticipated size (i.e. accounting for initial capacity + * and perhaps load factor). + * + * @param anticipatedSize The anticipated size of the instaniated collection + * after we are done populating it. */ - public abstract Object instantiate(); + public abstract Object instantiate(int anticipatedSize); public Object replace( final Object original, @@ -436,12 +450,17 @@ final Map copyCache) throws HibernateException { - if ( original == null ) return null; - if ( !Hibernate.isInitialized( original ) ) return target; + if ( original == null ) { + return null; + } + if ( !Hibernate.isInitialized( original ) ) { + return target; + } //if ( original == target ) return target; // can't do this, since need to merge element references - Object result = target==null || target==original ? //instead, put the merged elements in a new collection - instantiateResult( original ) : target; + // for a null target, or a target which is the same as the original, we + // need to put the merged elements in a new collection + Object result = target == null || target == original ? instantiateResult( original ) : target; //for arrays, replaceElements() may return a different reference, since //the array length might not match Modified: trunk/Hibernate3/src/org/hibernate/type/CustomCollectionType.java =================================================================== --- trunk/Hibernate3/src/org/hibernate/type/CustomCollectionType.java 2006-07-05 16:35:26 UTC (rev 10085) +++ trunk/Hibernate3/src/org/hibernate/type/CustomCollectionType.java 2006-07-05 18:17:27 UTC (rev 10086) @@ -7,7 +7,6 @@ import org.hibernate.HibernateException; import org.hibernate.MappingException; -import org.hibernate.Hibernate; import org.hibernate.collection.PersistentCollection; import org.hibernate.engine.SessionImplementor; import org.hibernate.engine.SessionFactoryImplementor; @@ -57,11 +56,11 @@ } public Class getReturnedClass() { - return userType.instantiate().getClass(); + return userType.instantiate( -1 ).getClass(); } - public Object instantiate() { - return userType.instantiate(); + public Object instantiate(int anticipatedType) { + return userType.instantiate( anticipatedType ); } public Iterator getElementsIterator(Object collection) { Modified: trunk/Hibernate3/src/org/hibernate/type/IdentifierBagType.java =================================================================== --- trunk/Hibernate3/src/org/hibernate/type/IdentifierBagType.java 2006-07-05 16:35:26 UTC (rev 10085) +++ trunk/Hibernate3/src/org/hibernate/type/IdentifierBagType.java 2006-07-05 18:17:27 UTC (rev 10086) @@ -24,8 +24,8 @@ return new PersistentIdentifierBag(session); } - public Object instantiate() { - return new ArrayList(); + public Object instantiate(int anticipatedSize) { + return anticipatedSize <= 0 ? new ArrayList() : new ArrayList( anticipatedSize + 1 ); } public Class getReturnedClass() { Modified: trunk/Hibernate3/src/org/hibernate/type/ListType.java =================================================================== --- trunk/Hibernate3/src/org/hibernate/type/ListType.java 2006-07-05 16:35:26 UTC (rev 10085) +++ trunk/Hibernate3/src/org/hibernate/type/ListType.java 2006-07-05 18:17:27 UTC (rev 10086) @@ -41,8 +41,8 @@ } } - public Object instantiate() { - return new ArrayList(); + public Object instantiate(int anticipatedSize) { + return anticipatedSize <= 0 ? new ArrayList() : new ArrayList( anticipatedSize + 1 ); } public Object indexOf(Object collection, Object element) { Modified: trunk/Hibernate3/src/org/hibernate/type/MapType.java =================================================================== --- trunk/Hibernate3/src/org/hibernate/type/MapType.java 2006-07-05 16:35:26 UTC (rev 10085) +++ trunk/Hibernate3/src/org/hibernate/type/MapType.java 2006-07-05 18:17:27 UTC (rev 10086) @@ -48,8 +48,10 @@ } } - public Object instantiate() { - return new HashMap(); + public Object instantiate(int anticipatedSize) { + return anticipatedSize <= 0 + ? new HashMap() + : new HashMap( anticipatedSize + (int)( anticipatedSize * .75f ), .75f ); } public Object replaceElements( Modified: trunk/Hibernate3/src/org/hibernate/type/SetType.java =================================================================== --- trunk/Hibernate3/src/org/hibernate/type/SetType.java 2006-07-05 16:35:26 UTC (rev 10085) +++ trunk/Hibernate3/src/org/hibernate/type/SetType.java 2006-07-05 18:17:27 UTC (rev 10086) @@ -40,9 +40,10 @@ } } - public Object instantiate() { - //TODO: Might need to be a LinkedHashSet!!!!!! - return new HashSet(); + public Object instantiate(int anticipatedSize) { + return anticipatedSize <= 0 + ? new HashSet() + : new HashSet( anticipatedSize + (int)( anticipatedSize * .75f ), .75f ); } } Modified: trunk/Hibernate3/src/org/hibernate/usertype/UserCollectionType.java =================================================================== --- trunk/Hibernate3/src/org/hibernate/usertype/UserCollectionType.java 2006-07-05 16:35:26 UTC (rev 10085) +++ trunk/Hibernate3/src/org/hibernate/usertype/UserCollectionType.java 2006-07-05 18:17:27 UTC (rev 10086) @@ -54,10 +54,17 @@ Map copyCache, SessionImplementor session) throws HibernateException; - + /** - * Instantiate an empty instance of the "underlying" collection (not a wrapper) + * Instantiate an empty instance of the "underlying" collection (not a wrapper), + * but with the given anticipated size (i.e. accounting for initial size + * and perhaps load factor). + * + * @param anticipatedSize The anticipated size of the instaniated collection + * after we are done populating it. Note, may be negative to indicate that + * we not yet know anything about the anticipated size (i.e., when initializing + * from a result set row by row). */ - public Object instantiate(); + public Object instantiate(int anticipatedSize); } Modified: trunk/Hibernate3/test/org/hibernate/test/usercollection/MyListType.java =================================================================== --- trunk/Hibernate3/test/org/hibernate/test/usercollection/MyListType.java 2006-07-05 16:35:26 UTC (rev 10085) +++ trunk/Hibernate3/test/org/hibernate/test/usercollection/MyListType.java 2006-07-05 18:17:27 UTC (rev 10086) @@ -12,6 +12,8 @@ public class MyListType implements UserCollectionType { + static int lastInstantiationRequest = -2; + public PersistentCollection instantiate(SessionImplementor session, CollectionPersister persister) throws HibernateException { return new PersistentMyList(session); } @@ -43,18 +45,14 @@ } public Object replaceElements(Object original, Object target, CollectionPersister persister, Object owner, Map copyCache, SessionImplementor session) throws HibernateException { - IMyList result = (IMyList) target; - result.clear(); - result.addAll((MyList)original); - return result; - } - public Object instantiate() { + public Object instantiate(int anticipatedSize) { + lastInstantiationRequest = anticipatedSize; return new MyList(); } Modified: trunk/Hibernate3/test/org/hibernate/test/usercollection/UserCollectionTypeTest.java =================================================================== --- trunk/Hibernate3/test/org/hibernate/test/usercollection/UserCollectionTypeTest.java 2006-07-05 16:35:26 UTC (rev 10085) +++ trunk/Hibernate3/test/org/hibernate/test/usercollection/UserCollectionTypeTest.java 2006-07-05 18:17:27 UTC (rev 10086) @@ -33,9 +33,22 @@ User u2 = (User) s.createCriteria(User.class).uniqueResult(); assertTrue( Hibernate.isInitialized( u2.getEmailAddresses() ) ); assertEquals( u2.getEmailAddresses().size(), 2 ); - s.delete(u2); t.commit(); s.close(); + + s = openSession(); + t = s.beginTransaction(); + u2 = ( User ) s.get( User.class, u.getUserName() ); + u2.getEmailAddresses().size(); + assertEquals( 2, MyListType.lastInstantiationRequest ); + t.commit(); + s.close(); + + s = openSession(); + t = s.beginTransaction(); + s.delete( u ); + t.commit(); + s.close(); } |
From: <hib...@li...> - 2006-07-05 16:35:44
|
Author: ste...@jb... Date: 2006-07-05 12:35:26 -0400 (Wed, 05 Jul 2006) New Revision: 10085 Modified: trunk/Hibernate3/test/org/hibernate/test/hql/BulkManipulationTest.java Log: fixed test Modified: trunk/Hibernate3/test/org/hibernate/test/hql/BulkManipulationTest.java =================================================================== --- trunk/Hibernate3/test/org/hibernate/test/hql/BulkManipulationTest.java 2006-07-05 15:03:52 UTC (rev 10084) +++ trunk/Hibernate3/test/org/hibernate/test/hql/BulkManipulationTest.java 2006-07-05 16:35:26 UTC (rev 10085) @@ -452,7 +452,13 @@ public void testIncorrectSyntax() { Session s = openSession(); Transaction t = s.beginTransaction(); - s.createQuery( "update Human set Human.description = 'xyz' where Human.id = 1 and Human.description is null" ).executeUpdate(); + try { + s.createQuery( "update Human set Human.description = 'xyz' where Human.id = 1 and Human.description is null" ); + fail( "expected failure" ); + } + catch( QueryException expected ) { + // ignore : expected behavior + } t.commit(); s.close(); } |