Hibernate SVN: r10691 - branches/Branch_3_2/Hibernate3/src/org/hibernate/type
by hibernate-commits@lists.jboss.org
Author: steve.ebersole(a)jboss.com
Date: 2006-11-02 13:59:45 -0500 (Thu, 02 Nov 2006)
New Revision: 10691
Modified:
branches/Branch_3_2/Hibernate3/src/org/hibernate/type/SerializableType.java
Log:
HHH-2135 : SerializableType change for Terradata support
Modified: branches/Branch_3_2/Hibernate3/src/org/hibernate/type/SerializableType.java
===================================================================
--- branches/Branch_3_2/Hibernate3/src/org/hibernate/type/SerializableType.java 2006-11-02 18:59:31 UTC (rev 10690)
+++ branches/Branch_3_2/Hibernate3/src/org/hibernate/type/SerializableType.java 2006-11-02 18:59:45 UTC (rev 10691)
@@ -30,9 +30,9 @@
}
public Object get(ResultSet rs, String name) throws HibernateException, SQLException {
-
byte[] bytes = (byte[]) Hibernate.BINARY.get(rs, name);
- if ( bytes==null ) {
+ // Some JDBC drivers erroneously return an empty array here for a null DB value :/
+ if ( bytes == null || bytes.length == 0 ) {
return null;
}
else {
17 years, 7 months
Hibernate SVN: r10690 - trunk/Hibernate3/src/org/hibernate/type
by hibernate-commits@lists.jboss.org
Author: steve.ebersole(a)jboss.com
Date: 2006-11-02 13:59:31 -0500 (Thu, 02 Nov 2006)
New Revision: 10690
Modified:
trunk/Hibernate3/src/org/hibernate/type/SerializableType.java
Log:
HHH-2135 : SerializableType change for Terradata support
Modified: trunk/Hibernate3/src/org/hibernate/type/SerializableType.java
===================================================================
--- trunk/Hibernate3/src/org/hibernate/type/SerializableType.java 2006-11-02 18:53:54 UTC (rev 10689)
+++ trunk/Hibernate3/src/org/hibernate/type/SerializableType.java 2006-11-02 18:59:31 UTC (rev 10690)
@@ -30,9 +30,9 @@
}
public Object get(ResultSet rs, String name) throws HibernateException, SQLException {
-
byte[] bytes = (byte[]) Hibernate.BINARY.get(rs, name);
- if ( bytes==null ) {
+ // Some JDBC drivers erroneously return an empty array here for a null DB value :/
+ if ( bytes == null || bytes.length == 0 ) {
return null;
}
else {
17 years, 7 months
Hibernate SVN: r10689 - branches/Branch_3_2/Hibernate3/src/org/hibernate/impl
by hibernate-commits@lists.jboss.org
Author: steve.ebersole(a)jboss.com
Date: 2006-11-02 13:53:54 -0500 (Thu, 02 Nov 2006)
New Revision: 10689
Modified:
branches/Branch_3_2/Hibernate3/src/org/hibernate/impl/SessionImpl.java
Log:
HHH-2206 - SessionImpl serialization
Modified: branches/Branch_3_2/Hibernate3/src/org/hibernate/impl/SessionImpl.java
===================================================================
--- branches/Branch_3_2/Hibernate3/src/org/hibernate/impl/SessionImpl.java 2006-11-02 18:53:25 UTC (rev 10688)
+++ branches/Branch_3_2/Hibernate3/src/org/hibernate/impl/SessionImpl.java 2006-11-02 18:53:54 UTC (rev 10689)
@@ -1872,29 +1872,33 @@
* Used by JDK serialization...
*
* @param ois The input stream from which we are being read...
- * @throws IOException
- * @throws ClassNotFoundException
+ * @throws IOException Indicates a general IO stream exception
+ * @throws ClassNotFoundException Indicates a class resolution issue
*/
private void readObject(ObjectInputStream ois) throws IOException, ClassNotFoundException {
log.trace( "deserializing session" );
boolean isRootSession = ois.readBoolean();
+ connectionReleaseMode = ConnectionReleaseMode.parse( ( String ) ois.readObject() );
+ entityMode = EntityMode.parse( ( String ) ois.readObject() );
+ autoClear = ois.readBoolean();
+ flushMode = FlushMode.parse( ( String ) ois.readObject() );
+ cacheMode = CacheMode.parse( ( String ) ois.readObject() );
+ flushBeforeCompletionEnabled = ois.readBoolean();
+ autoCloseSessionEnabled = ois.readBoolean();
+ fetchProfile = ( String ) ois.readObject();
interceptor = ( Interceptor ) ois.readObject();
+
factory = SessionFactoryImpl.deserialize( ois );
listeners = factory.getEventListeners();
+
if ( isRootSession ) {
jdbcContext = JDBCContext.deserialize( ois, this, interceptor );
}
+
persistenceContext = StatefulPersistenceContext.deserialize( ois, this );
actionQueue = ActionQueue.deserialize( ois, this );
- entityMode = EntityMode.parse( ( String ) ois.readObject() );
- autoClear = ois.readBoolean();
- flushMode = FlushMode.parse( ( String ) ois.readObject() );
- cacheMode = CacheMode.parse( ( String ) ois.readObject() );
- flushBeforeCompletionEnabled = ois.readBoolean();
- autoCloseSessionEnabled = ois.readBoolean();
- connectionReleaseMode = ConnectionReleaseMode.parse( ( String ) ois.readObject() );
- fetchProfile = ( String ) ois.readObject();
+
enabledFilters = ( Map ) ois.readObject();
childSessionsByEntityMode = ( Map ) ois.readObject();
@@ -1917,7 +1921,7 @@
* Used by JDK serialization...
*
* @param oos The output stream to which we are being written...
- * @throws IOException
+ * @throws IOException Indicates a general IO stream exception
*/
private void writeObject(ObjectOutputStream oos) throws IOException {
if ( !jdbcContext.getConnectionManager().isReadyForSerialization() ) {
@@ -1927,22 +1931,26 @@
log.trace( "serializing session" );
oos.writeBoolean( rootSession == null );
+ oos.writeObject( connectionReleaseMode.toString() );
+ oos.writeObject( entityMode.toString() );
+ oos.writeBoolean( autoClear );
+ oos.writeObject( flushMode.toString() );
+ oos.writeObject( cacheMode.toString() );
+ oos.writeBoolean( flushBeforeCompletionEnabled );
+ oos.writeBoolean( autoCloseSessionEnabled );
+ oos.writeObject( fetchProfile );
// we need to writeObject() on this since interceptor is user defined
oos.writeObject( interceptor );
+
factory.serialize( oos );
+
if ( rootSession == null ) {
jdbcContext.serialize( oos );
}
+
persistenceContext.serialize( oos );
actionQueue.serialize( oos );
- oos.writeObject( entityMode.toString() );
- oos.writeBoolean( autoClear );
- oos.writeObject( flushMode.toString() );
- oos.writeObject( cacheMode.toString() );
- oos.writeBoolean( flushBeforeCompletionEnabled );
- oos.writeBoolean( autoCloseSessionEnabled );
- oos.writeObject( connectionReleaseMode.toString() );
- oos.writeObject( fetchProfile );
+
// todo : look at optimizing these...
oos.writeObject( enabledFilters );
oos.writeObject( childSessionsByEntityMode );
17 years, 7 months
Hibernate SVN: r10688 - trunk/Hibernate3/src/org/hibernate/impl
by hibernate-commits@lists.jboss.org
Author: steve.ebersole(a)jboss.com
Date: 2006-11-02 13:53:25 -0500 (Thu, 02 Nov 2006)
New Revision: 10688
Modified:
trunk/Hibernate3/src/org/hibernate/impl/SessionImpl.java
Log:
HHH-2206 - SessionImpl serialization
Modified: trunk/Hibernate3/src/org/hibernate/impl/SessionImpl.java
===================================================================
--- trunk/Hibernate3/src/org/hibernate/impl/SessionImpl.java 2006-11-02 15:06:13 UTC (rev 10687)
+++ trunk/Hibernate3/src/org/hibernate/impl/SessionImpl.java 2006-11-02 18:53:25 UTC (rev 10688)
@@ -1872,29 +1872,33 @@
* Used by JDK serialization...
*
* @param ois The input stream from which we are being read...
- * @throws IOException
- * @throws ClassNotFoundException
+ * @throws IOException Indicates a general IO stream exception
+ * @throws ClassNotFoundException Indicates a class resolution issue
*/
private void readObject(ObjectInputStream ois) throws IOException, ClassNotFoundException {
log.trace( "deserializing session" );
boolean isRootSession = ois.readBoolean();
+ connectionReleaseMode = ConnectionReleaseMode.parse( ( String ) ois.readObject() );
+ entityMode = EntityMode.parse( ( String ) ois.readObject() );
+ autoClear = ois.readBoolean();
+ flushMode = FlushMode.parse( ( String ) ois.readObject() );
+ cacheMode = CacheMode.parse( ( String ) ois.readObject() );
+ flushBeforeCompletionEnabled = ois.readBoolean();
+ autoCloseSessionEnabled = ois.readBoolean();
+ fetchProfile = ( String ) ois.readObject();
interceptor = ( Interceptor ) ois.readObject();
+
factory = SessionFactoryImpl.deserialize( ois );
listeners = factory.getEventListeners();
+
if ( isRootSession ) {
jdbcContext = JDBCContext.deserialize( ois, this, interceptor );
}
+
persistenceContext = StatefulPersistenceContext.deserialize( ois, this );
actionQueue = ActionQueue.deserialize( ois, this );
- entityMode = EntityMode.parse( ( String ) ois.readObject() );
- autoClear = ois.readBoolean();
- flushMode = FlushMode.parse( ( String ) ois.readObject() );
- cacheMode = CacheMode.parse( ( String ) ois.readObject() );
- flushBeforeCompletionEnabled = ois.readBoolean();
- autoCloseSessionEnabled = ois.readBoolean();
- connectionReleaseMode = ConnectionReleaseMode.parse( ( String ) ois.readObject() );
- fetchProfile = ( String ) ois.readObject();
+
enabledFilters = ( Map ) ois.readObject();
childSessionsByEntityMode = ( Map ) ois.readObject();
@@ -1917,7 +1921,7 @@
* Used by JDK serialization...
*
* @param oos The output stream to which we are being written...
- * @throws IOException
+ * @throws IOException Indicates a general IO stream exception
*/
private void writeObject(ObjectOutputStream oos) throws IOException {
if ( !jdbcContext.getConnectionManager().isReadyForSerialization() ) {
@@ -1927,22 +1931,26 @@
log.trace( "serializing session" );
oos.writeBoolean( rootSession == null );
+ oos.writeObject( connectionReleaseMode.toString() );
+ oos.writeObject( entityMode.toString() );
+ oos.writeBoolean( autoClear );
+ oos.writeObject( flushMode.toString() );
+ oos.writeObject( cacheMode.toString() );
+ oos.writeBoolean( flushBeforeCompletionEnabled );
+ oos.writeBoolean( autoCloseSessionEnabled );
+ oos.writeObject( fetchProfile );
// we need to writeObject() on this since interceptor is user defined
oos.writeObject( interceptor );
+
factory.serialize( oos );
+
if ( rootSession == null ) {
jdbcContext.serialize( oos );
}
+
persistenceContext.serialize( oos );
actionQueue.serialize( oos );
- oos.writeObject( entityMode.toString() );
- oos.writeBoolean( autoClear );
- oos.writeObject( flushMode.toString() );
- oos.writeObject( cacheMode.toString() );
- oos.writeBoolean( flushBeforeCompletionEnabled );
- oos.writeBoolean( autoCloseSessionEnabled );
- oos.writeObject( connectionReleaseMode.toString() );
- oos.writeObject( fetchProfile );
+
// todo : look at optimizing these...
oos.writeObject( enabledFilters );
oos.writeObject( childSessionsByEntityMode );
17 years, 7 months
Hibernate SVN: r10687 - in branches/Branch_3_2/HibernateExt/tools/src: templates/doc/entities test/org/hibernate/tool/hbm2x
by hibernate-commits@lists.jboss.org
Author: max.andersen(a)jboss.com
Date: 2006-11-02 10:06:13 -0500 (Thu, 02 Nov 2006)
New Revision: 10687
Modified:
branches/Branch_3_2/HibernateExt/tools/src/templates/doc/entities/entity.ftl
branches/Branch_3_2/HibernateExt/tools/src/test/org/hibernate/tool/hbm2x/DocExporterTest.java
Log:
HBX-804 Add inherited properties and id/property stubs
Modified: branches/Branch_3_2/HibernateExt/tools/src/templates/doc/entities/entity.ftl
===================================================================
--- branches/Branch_3_2/HibernateExt/tools/src/templates/doc/entities/entity.ftl 2006-11-02 14:57:25 UTC (rev 10686)
+++ branches/Branch_3_2/HibernateExt/tools/src/templates/doc/entities/entity.ftl 2006-11-02 15:06:13 UTC (rev 10687)
@@ -77,7 +77,7 @@
<#assign rowspan = property.getValue().getColumnSpan()>
<tr>
<td <#if (rowspan>0)>rowspan="${rowspan}"</#if>>
- <a href="#field_summary">
+ <a href="#identifier_detail_${property.name}">
${property.name}
</a>
</td>
@@ -135,7 +135,7 @@
<#else>
<tr>
<td>
- <a href="#field_summary">
+ <a href="#identifier_detail_${propertyIdentifier.name}">
${propertyIdentifier.name}
</a>
</td>
@@ -192,7 +192,7 @@
<#assign rowspan = property.getValue().getColumnSpan()>
<tr>
<td <#if (rowspan > 0)>rowspan="${rowspan}"</#if>>
- <a href="#field_summary">
+ <a href="#property_detail_${property.name}">
${property.name}
</a>
</td>
@@ -255,5 +255,52 @@
</table>
</#if>
+ <#list superClasses as superClass>
+ <#assign properties = dochelper.getOrderedProperties(superClass)>
+ <#if !properties.empty>
+ <#assign superClassRef = docFileManager.getRef(docFile, docFileManager.getEntityDocFileByDeclarationName(superClass))>
+ <table id="properties_inherited_from_entity_${superClass.shortName}">
+ <tr>
+ <th>
+ Properties inherited from entity <a href="${superClassRef}">${superClass.shortName}</a>
+ </th>
+ </tr>
+ <tr>
+ <td>
+ <#list properties as property>
+ <a href="${superClassRef}#property_detail_${property.name}">${property.name}</a><#if property_has_next>, </#if>
+ </#list>
+ </td>
+ </tr>
+ </table>
+ </#if>
+ </#list>
+
+ <#if class.hasIdentifierProperty()>
+ <#assign identifier = class.getIdentifierProperty()>
+ <p id="identifier_detail" class="MainTableHeading">
+ Identifier Detail
+ </p>
+ <#if dochelper.getComponentPOJO(identifier)?exists>
+ <#assign identifierClass = dochelper.getComponentPOJO(identifier)>
+ <#foreach property in identifierClass.allPropertiesIterator>
+ <h3 id="identifier_detail_${property.name}">${property.name}</h3>
+ </#foreach>
+ <#else>
+ <h3 id="identifier_detail_${identifier.name}">${identifier.name}</h3>
+ </#if>
+ </#if>
+
+ <#assign properties = class.allPropertiesIterator>
+ <#if properties.hasNext()>
+ <p id="property_detail" class="MainTableHeading">
+ Property Detail
+ </p>
+ <#list properties as property>
+ <h3 id="property_detail_${property.name}">${property.name}</h3>
+ <hr/>
+ </#list>
+ </#if>
+
</body>
</html>
Modified: branches/Branch_3_2/HibernateExt/tools/src/test/org/hibernate/tool/hbm2x/DocExporterTest.java
===================================================================
--- branches/Branch_3_2/HibernateExt/tools/src/test/org/hibernate/tool/hbm2x/DocExporterTest.java 2006-11-02 14:57:25 UTC (rev 10686)
+++ branches/Branch_3_2/HibernateExt/tools/src/test/org/hibernate/tool/hbm2x/DocExporterTest.java 2006-11-02 15:06:13 UTC (rev 10687)
@@ -95,7 +95,14 @@
assertEquals("Generics syntax should not occur verbatim in html",null,findFirstString("List<", tableFile));
assertNotNull("Generics syntax occur verbatim in html",findFirstString("List<", tableFile));
}
+
+ public void testInheritedProperties()
+ {
+ File entityFile = new File(getOutputDir(), "entities/org/hibernate/tool/hbm2x/UUser.html");
+ assertFileAndExists(entityFile);
+ assertNotNull("Missing inherited property", findFirstString("firstName", entityFile));
+ }
private void testHtml(final Tidy tidy, File dir) {
try {
17 years, 7 months
Hibernate SVN: r10686 - in branches/Branch_3_2/HibernateExt/tools/src: java/org/hibernate/tool/hbm2x/doc templates/doc/entities
by hibernate-commits@lists.jboss.org
Author: max.andersen(a)jboss.com
Date: 2006-11-02 09:57:25 -0500 (Thu, 02 Nov 2006)
New Revision: 10686
Modified:
branches/Branch_3_2/HibernateExt/tools/src/java/org/hibernate/tool/hbm2x/doc/DocHelper.java
branches/Branch_3_2/HibernateExt/tools/src/templates/doc/entities/entity.ftl
Log:
you say potato i say potatoe
Modified: branches/Branch_3_2/HibernateExt/tools/src/java/org/hibernate/tool/hbm2x/doc/DocHelper.java
===================================================================
--- branches/Branch_3_2/HibernateExt/tools/src/java/org/hibernate/tool/hbm2x/doc/DocHelper.java 2006-11-02 12:46:51 UTC (rev 10685)
+++ branches/Branch_3_2/HibernateExt/tools/src/java/org/hibernate/tool/hbm2x/doc/DocHelper.java 2006-11-02 14:57:25 UTC (rev 10686)
@@ -502,7 +502,7 @@
}
}
- public List getInheritanceHiearchy(POJOClass pc) {
+ public List getInheritanceHierarchy(POJOClass pc) {
if(pc.isSubclass()) {
List superClasses = new ArrayList();
Modified: branches/Branch_3_2/HibernateExt/tools/src/templates/doc/entities/entity.ftl
===================================================================
--- branches/Branch_3_2/HibernateExt/tools/src/templates/doc/entities/entity.ftl 2006-11-02 12:46:51 UTC (rev 10685)
+++ branches/Branch_3_2/HibernateExt/tools/src/templates/doc/entities/entity.ftl 2006-11-02 14:57:25 UTC (rev 10686)
@@ -18,7 +18,7 @@
<ul class="EntityHierarchy">
<li>
- <#assign superClasses=dochelper.getInheritanceHiearchy(class)>
+ <#assign superClasses=dochelper.getInheritanceHierarchy(class)>
<#list superClasses?reverse as superClass>
<#-- whitespace is significant here -->
<#if superClass_index gt 0><img src="${docFileManager.getRef(docFile, docFileManager.getExtendsImageDocFile())}" alt="extended by"/></#if><a href="${docFileManager.getRef(docFile, docFileManager.getEntityDocFileByDeclarationName(superClass))}">${superClass.qualifiedDeclarationName}</a>
17 years, 7 months
Hibernate SVN: r10685 - branches/Branch_3_2/HibernateExt/tools/src/test/org/hibernate/tool/hbm2x
by hibernate-commits@lists.jboss.org
Author: max.andersen(a)jboss.com
Date: 2006-11-02 07:46:51 -0500 (Thu, 02 Nov 2006)
New Revision: 10685
Modified:
branches/Branch_3_2/HibernateExt/tools/src/test/org/hibernate/tool/hbm2x/DocExporterTest.java
Log:
rereenable jtidy test
Modified: branches/Branch_3_2/HibernateExt/tools/src/test/org/hibernate/tool/hbm2x/DocExporterTest.java
===================================================================
--- branches/Branch_3_2/HibernateExt/tools/src/test/org/hibernate/tool/hbm2x/DocExporterTest.java 2006-11-02 12:44:16 UTC (rev 10684)
+++ branches/Branch_3_2/HibernateExt/tools/src/test/org/hibernate/tool/hbm2x/DocExporterTest.java 2006-11-02 12:46:51 UTC (rev 10685)
@@ -66,11 +66,9 @@
assertFileAndExists(new File(getOutputDir(), "tables/tablegraph.dot"));
assertFileAndExists(new File(getOutputDir(), "tables/tablegraph.png"));
- final Tidy tidy = new Tidy();
-
-
- new FileVisitor() {
+ new FileVisitor() {
protected void process(File dir) {
+ final Tidy tidy = new Tidy();
if(dir.isFile() && dir.getName().endsWith( ".html" )) {
testHtml( tidy, dir );
}
17 years, 7 months
Hibernate SVN: r10684 - branches/Branch_3_2/HibernateExt/tools/src/test/org/hibernate/tool/hbm2x
by hibernate-commits@lists.jboss.org
Author: max.andersen(a)jboss.com
Date: 2006-11-02 07:44:16 -0500 (Thu, 02 Nov 2006)
New Revision: 10684
Modified:
branches/Branch_3_2/HibernateExt/tools/src/test/org/hibernate/tool/hbm2x/DocExporterTest.java
Log:
reenable jtidy test
Modified: branches/Branch_3_2/HibernateExt/tools/src/test/org/hibernate/tool/hbm2x/DocExporterTest.java
===================================================================
--- branches/Branch_3_2/HibernateExt/tools/src/test/org/hibernate/tool/hbm2x/DocExporterTest.java 2006-11-02 12:36:22 UTC (rev 10683)
+++ branches/Branch_3_2/HibernateExt/tools/src/test/org/hibernate/tool/hbm2x/DocExporterTest.java 2006-11-02 12:44:16 UTC (rev 10684)
@@ -66,7 +66,6 @@
assertFileAndExists(new File(getOutputDir(), "tables/tablegraph.dot"));
assertFileAndExists(new File(getOutputDir(), "tables/tablegraph.png"));
- /* Tidy complains about valid html 4.x
final Tidy tidy = new Tidy();
@@ -77,7 +76,7 @@
}
}
- }.visit( getOutputDir() );*/
+ }.visit( getOutputDir() );
}
17 years, 7 months
Hibernate SVN: r10683 - in branches/Branch_3_2/HibernateExt/tools/src: java/org/hibernate/cfg/reveng java/org/hibernate/tool/ant java/org/hibernate/tool/hbm2x/doc templates/doc/entities test/org/hibernate/tool/hbm2x test/org/hibernate/tool/test/jdbc2cfg
by hibernate-commits@lists.jboss.org
Author: max.andersen(a)jboss.com
Date: 2006-11-02 07:36:22 -0500 (Thu, 02 Nov 2006)
New Revision: 10683
Modified:
branches/Branch_3_2/HibernateExt/tools/src/java/org/hibernate/cfg/reveng/DefaultReverseEngineeringStrategy.java
branches/Branch_3_2/HibernateExt/tools/src/java/org/hibernate/cfg/reveng/DelegatingReverseEngineeringStrategy.java
branches/Branch_3_2/HibernateExt/tools/src/java/org/hibernate/cfg/reveng/ReverseEngineeringSettings.java
branches/Branch_3_2/HibernateExt/tools/src/java/org/hibernate/cfg/reveng/ReverseEngineeringStrategy.java
branches/Branch_3_2/HibernateExt/tools/src/java/org/hibernate/tool/ant/JDBCConfigurationTask.java
branches/Branch_3_2/HibernateExt/tools/src/java/org/hibernate/tool/hbm2x/doc/DocHelper.java
branches/Branch_3_2/HibernateExt/tools/src/templates/doc/entities/entity.ftl
branches/Branch_3_2/HibernateExt/tools/src/test/org/hibernate/tool/hbm2x/DocExporterTest.java
branches/Branch_3_2/HibernateExt/tools/src/test/org/hibernate/tool/hbm2x/GenerateFromJDBCTest.java
branches/Branch_3_2/HibernateExt/tools/src/test/org/hibernate/tool/test/jdbc2cfg/DefaultReverseEngineeringStrategyTest.java
branches/Branch_3_2/HibernateExt/tools/src/test/org/hibernate/tool/test/jdbc2cfg/ManyToManyTest.java
branches/Branch_3_2/HibernateExt/tools/src/test/org/hibernate/tool/test/jdbc2cfg/PersistentClassesTest.java
Log:
HBX-803 strategies should know the rootstrategy
HBX-802 Hide property summary when no properties and sort alphabetically
Modified: branches/Branch_3_2/HibernateExt/tools/src/java/org/hibernate/cfg/reveng/DefaultReverseEngineeringStrategy.java
===================================================================
--- branches/Branch_3_2/HibernateExt/tools/src/java/org/hibernate/cfg/reveng/DefaultReverseEngineeringStrategy.java 2006-11-02 04:22:27 UTC (rev 10682)
+++ branches/Branch_3_2/HibernateExt/tools/src/java/org/hibernate/cfg/reveng/DefaultReverseEngineeringStrategy.java 2006-11-02 12:36:22 UTC (rev 10683)
@@ -25,7 +25,7 @@
private static Set AUTO_OPTIMISTICLOCK_COLUMNS;
- private ReverseEngineeringSettings settings = new ReverseEngineeringSettings();
+ private ReverseEngineeringSettings settings = new ReverseEngineeringSettings(this);
static {
AUTO_OPTIMISTICLOCK_COLUMNS = new HashSet();
AUTO_OPTIMISTICLOCK_COLUMNS.add("version");
@@ -59,7 +59,7 @@
* TODO: are the from/to names correct ?
*/
public String foreignKeyToCollectionName(String keyname, TableIdentifier fromTable, List fromColumns, TableIdentifier referencedTable, List referencedColumns, boolean uniqueReference) {
- String propertyName = Introspector.decapitalize( StringHelper.unqualify( tableToClassName(fromTable) ) );
+ String propertyName = Introspector.decapitalize( StringHelper.unqualify( getRoot().tableToClassName(fromTable) ) );
propertyName = pluralize( propertyName );
if(!uniqueReference) {
@@ -79,7 +79,7 @@
}
public String foreignKeyToEntityName(String keyname, TableIdentifier fromTable, List fromColumnNames, TableIdentifier referencedTable, List referencedColumnNames, boolean uniqueReference) {
- String propertyName = Introspector.decapitalize( StringHelper.unqualify( tableToClassName(referencedTable) ) );
+ String propertyName = Introspector.decapitalize( StringHelper.unqualify( getRoot().tableToClassName(referencedTable) ) );
if(!uniqueReference) {
if(fromColumnNames!=null && fromColumnNames.size()==1) {
@@ -233,8 +233,12 @@
}
}
+ protected ReverseEngineeringStrategy getRoot() {
+ return settings.getRootStrategy();
+ }
+
public String foreignKeyToManyToManyName(ForeignKey fromKey, TableIdentifier middleTable, ForeignKey toKey, boolean uniqueReference) {
- String propertyName = Introspector.decapitalize( StringHelper.unqualify( tableToClassName(TableIdentifier.create( toKey.getReferencedTable()) )) );
+ String propertyName = Introspector.decapitalize( StringHelper.unqualify( getRoot().tableToClassName(TableIdentifier.create( toKey.getReferencedTable()) )) );
propertyName = pluralize( propertyName );
if(!uniqueReference) {
Modified: branches/Branch_3_2/HibernateExt/tools/src/java/org/hibernate/cfg/reveng/DelegatingReverseEngineeringStrategy.java
===================================================================
--- branches/Branch_3_2/HibernateExt/tools/src/java/org/hibernate/cfg/reveng/DelegatingReverseEngineeringStrategy.java 2006-11-02 04:22:27 UTC (rev 10682)
+++ branches/Branch_3_2/HibernateExt/tools/src/java/org/hibernate/cfg/reveng/DelegatingReverseEngineeringStrategy.java 2006-11-02 12:36:22 UTC (rev 10683)
@@ -109,6 +109,13 @@
return delegate==null?true:delegate.isForeignKeyCollectionLazy(name, foreignKeyTable, columns, foreignKeyReferencedTable, referencedColumns);
}
+ /**
+ * Initialize the settings.
+ *
+ * If subclasses need to use the Settings then it should keep its own reference, but still remember to initialize the delegates settings by calling super.setSettings(settings).
+ *
+ * @see ReverseEngineeringStrategy.setSettings
+ */
public void setSettings(ReverseEngineeringSettings settings) {
if(delegate!=null) delegate.setSettings(settings);
}
Modified: branches/Branch_3_2/HibernateExt/tools/src/java/org/hibernate/cfg/reveng/ReverseEngineeringSettings.java
===================================================================
--- branches/Branch_3_2/HibernateExt/tools/src/java/org/hibernate/cfg/reveng/ReverseEngineeringSettings.java 2006-11-02 04:22:27 UTC (rev 10682)
+++ branches/Branch_3_2/HibernateExt/tools/src/java/org/hibernate/cfg/reveng/ReverseEngineeringSettings.java 2006-11-02 12:36:22 UTC (rev 10683)
@@ -3,7 +3,7 @@
public class ReverseEngineeringSettings {
- //final ReverseEngineeringStrategy rootStrategy;
+ final ReverseEngineeringStrategy rootStrategy;
private String defaultPackageName = "";
private boolean detectOptimisticLock = true;
@@ -11,9 +11,9 @@
private boolean createManyToOneForForeignKey = true;
private boolean detectManyToMany = true;
- //public ReverseEngineeringSettings(ReverseEngineeringStrategy rootStrategy) {
- // this.rootStrategy = rootStrategy;
- //}
+ public ReverseEngineeringSettings(ReverseEngineeringStrategy rootStrategy) {
+ this.rootStrategy = rootStrategy;
+ }
public ReverseEngineeringSettings setDefaultPackageName(String defaultPackageName) {
if(defaultPackageName==null) {
@@ -72,9 +72,9 @@
return detectManyToMany;
}
- /** return the top/root strategy. Allows a lower strategy to ask another question. Dangerous to do since recursive loops can easily occur! */
- /*public ReverseEngineeringStrategy getRootStrategy() {
+ /** return the top/root strategy. Allows a lower strategy to ask another question. Be aware of possible recursive loops; e.g. do not call the root.tableToClassName in tableToClassName of a custom reversengineeringstrategy. */
+ public ReverseEngineeringStrategy getRootStrategy() {
return rootStrategy;
- }*/
+ }
}
Modified: branches/Branch_3_2/HibernateExt/tools/src/java/org/hibernate/cfg/reveng/ReverseEngineeringStrategy.java
===================================================================
--- branches/Branch_3_2/HibernateExt/tools/src/java/org/hibernate/cfg/reveng/ReverseEngineeringStrategy.java 2006-11-02 04:22:27 UTC (rev 10682)
+++ branches/Branch_3_2/HibernateExt/tools/src/java/org/hibernate/cfg/reveng/ReverseEngineeringStrategy.java 2006-11-02 12:36:22 UTC (rev 10683)
@@ -13,7 +13,7 @@
public interface ReverseEngineeringStrategy {
/**
- * Generic method used to initialize the reverse engineering strategy.
+ * Generic method used to initialize the reverse engineering strategy.
*
* @param settings used for this
*/
Modified: branches/Branch_3_2/HibernateExt/tools/src/java/org/hibernate/tool/ant/JDBCConfigurationTask.java
===================================================================
--- branches/Branch_3_2/HibernateExt/tools/src/java/org/hibernate/tool/ant/JDBCConfigurationTask.java 2006-11-02 04:22:27 UTC (rev 10682)
+++ branches/Branch_3_2/HibernateExt/tools/src/java/org/hibernate/tool/ant/JDBCConfigurationTask.java 2006-11-02 12:36:22 UTC (rev 10683)
@@ -52,15 +52,7 @@
jmdc.setPreferBasicCompositeIds(preferBasicCompositeIds);
DefaultReverseEngineeringStrategy defaultStrategy = new DefaultReverseEngineeringStrategy();
- ReverseEngineeringSettings qqsettings =
- new ReverseEngineeringSettings().setDefaultPackageName(packageName)
- .setDetectManyToMany( detectManyToMany )
- .setDetectOptimisticLock( detectOptimisticLock );
- if(packageName!=null) {
- defaultStrategy.setSettings(qqsettings);
- }
-
ReverseEngineeringStrategy strategy = defaultStrategy;
if(revengFiles!=null) {
@@ -76,7 +68,15 @@
if(reverseEngineeringStrategyClass!=null) {
strategy = loadreverseEngineeringStrategy(reverseEngineeringStrategyClass, strategy);
}
+
+ ReverseEngineeringSettings qqsettings =
+ new ReverseEngineeringSettings(strategy).setDefaultPackageName(packageName)
+ .setDetectManyToMany( detectManyToMany )
+ .setDetectOptimisticLock( detectOptimisticLock );
+
+ defaultStrategy.setSettings(qqsettings);
strategy.setSettings(qqsettings);
+
jmdc.setReverseEngineeringStrategy(strategy);
jmdc.readFromJDBC();
Modified: branches/Branch_3_2/HibernateExt/tools/src/java/org/hibernate/tool/hbm2x/doc/DocHelper.java
===================================================================
--- branches/Branch_3_2/HibernateExt/tools/src/java/org/hibernate/tool/hbm2x/doc/DocHelper.java 2006-11-02 04:22:27 UTC (rev 10682)
+++ branches/Branch_3_2/HibernateExt/tools/src/java/org/hibernate/tool/hbm2x/doc/DocHelper.java 2006-11-02 12:36:22 UTC (rev 10683)
@@ -42,6 +42,20 @@
return that.getDeclarationName().compareTo(what.getDeclarationName());
}
};
+
+ /**
+ * Used to sort properties according to their name.
+ */
+ private static final Comparator PROPERTY_COMPARATOR = new Comparator()
+ {
+ public int compare(Object o1, Object o2)
+ {
+ Property property1 = (Property) o1;
+ Property property2 = (Property) o2;
+
+ return property1.getName().compareTo(property2.getName());
+ }
+ };
/**
* Name to use if the schema is not specified.
@@ -504,5 +518,17 @@
return Collections.EMPTY_LIST;
}
}
+
+ public List getOrderedProperties(POJOClass pojoClass)
+ {
+ List orderedProperties = new ArrayList();
+
+ for (Iterator iterator = pojoClass.getAllPropertiesIterator(); iterator.hasNext(); )
+ orderedProperties.add(iterator.next());
+
+ Collections.sort(orderedProperties, PROPERTY_COMPARATOR);
+
+ return orderedProperties;
+ }
}
\ No newline at end of file
Modified: branches/Branch_3_2/HibernateExt/tools/src/templates/doc/entities/entity.ftl
===================================================================
--- branches/Branch_3_2/HibernateExt/tools/src/templates/doc/entities/entity.ftl 2006-11-02 04:22:27 UTC (rev 10682)
+++ branches/Branch_3_2/HibernateExt/tools/src/templates/doc/entities/entity.ftl 2006-11-02 12:36:22 UTC (rev 10683)
@@ -158,99 +158,102 @@
</table>
</#if>
- <table id="property_summary">
- <thead>
- <tr>
- <th class="MainTableHeading" colspan="5">
- Property Summary
- </th>
- </tr>
- <tr>
- <th style="width: 14%">
- Name
- </th>
- <th style="width: 14%">
- Column
- </th>
- <th style="width: 14%">
- Access
- </th>
- <th style="width: 14%">
- Type
- </th>
- <th style="width: 44%">
- Description
- </th>
- </tr>
- </thead>
- <tbody>
-
- <#foreach property in class.allPropertiesIterator>
- <#assign columnIterator = property.getValue().columnIterator>
- <#assign rowspan = property.getValue().getColumnSpan()>
+ <#assign properties = dochelper.getOrderedProperties(class)>
+ <#if !properties.empty>
+ <table id="property_summary">
+ <thead>
<tr>
- <td <#if (rowspan > 0)>rowspan="${rowspan}"</#if>>
- <a href="#field_summary">
- ${property.name}
- </a>
- </td>
-
- <#if (rowspan > 0)>
- <#assign column = columnIterator.next()>
- <#if column.isFormula()>
+ <th class="MainTableHeading" colspan="5">
+ Property Summary
+ </th>
+ </tr>
+ <tr>
+ <th style="width: 14%">
+ Name
+ </th>
+ <th style="width: 14%">
+ Column
+ </th>
+ <th style="width: 14%">
+ Access
+ </th>
+ <th style="width: 14%">
+ Type
+ </th>
+ <th style="width: 44%">
+ Description
+ </th>
+ </tr>
+ </thead>
+ <tbody>
+
+ <#foreach property in properties>
+ <#assign columnIterator = property.getValue().columnIterator>
+ <#assign rowspan = property.getValue().getColumnSpan()>
+ <tr>
+ <td <#if (rowspan > 0)>rowspan="${rowspan}"</#if>>
+ <a href="#field_summary">
+ ${property.name}
+ </a>
+ </td>
+
+ <#if (rowspan > 0)>
+ <#assign column = columnIterator.next()>
+ <#if column.isFormula()>
+ <td>
+
+ </td>
+ <#else>
+ <td>
+ <a href="#property_summary">
+ ${column.getName()}
+ </a>
+ </td>
+ </#if>
+ <#else>
<td>
</td>
- <#else>
- <td>
- <a href="#property_summary">
- ${column.getName()}
- </a>
- </td>
</#if>
- <#else>
- <td>
-
+
+ <td <#if (rowspan > 0)>rowspan="${rowspan}"</#if>>
+ ${property.getPropertyAccessorName()} (<a href="#property_summary">get</a> / <a href="#property_summary">set</a>)
</td>
+
+ <td <#if (rowspan > 0)>rowspan="${rowspan}"</#if>>
+ <#if dochelper.getComponentPOJO(property)?exists>
+ <a href="${docFileManager.getRef(docFile, docFileManager.getEntityDocFileByDeclarationName(dochelper.getComponentPOJO(property)))}" target="generalFrame">
+ ${class.getJavaTypeName(property, jdk5)?html?default(" ")}
+ </a>
+ <#else>
+ ${class.getJavaTypeName(property, jdk5)?html?default(" ")}
+ </#if>
+ </td>
+
+ <td <#if (rowspan > 0)>rowspan="${rowspan}"</#if>>
+ <#if class.hasFieldJavaDoc(property)>
+ ${class.getFieldDescription(property)?default(" ")}
+ <#else>
+
+ </#if>
+ </td>
+ </tr>
+ <#if (rowspan > 1)>
+ <#foreach column in columnIterator>
+ <tr>
+ <td>
+ <a href="#property_summary">
+ ${column.name}
+ </a>
+ </td>
+ </tr>
+ </#foreach>
</#if>
+ </#foreach>
+
+ </tbody>
+ </table>
+ </#if>
- <td <#if (rowspan > 0)>rowspan="${rowspan}"</#if>>
- ${property.getPropertyAccessorName()} (<a href="#property_summary">get</a> / <a href="#property_summary">set</a>)
- </td>
-
- <td <#if (rowspan > 0)>rowspan="${rowspan}"</#if>>
- <#if dochelper.getComponentPOJO(property)?exists>
- <a href="${docFileManager.getRef(docFile, docFileManager.getEntityDocFileByDeclarationName(dochelper.getComponentPOJO(property)))}" target="generalFrame">
- ${class.getJavaTypeName(property, jdk5)?html?default(" ")}
- </a>
- <#else>
- ${class.getJavaTypeName(property, jdk5)?html?default(" ")}
- </#if>
- </td>
-
- <td <#if (rowspan > 0)>rowspan="${rowspan}"</#if>>
- <#if class.hasFieldJavaDoc(property)>
- ${class.getFieldDescription(property)?default(" ")}
- <#else>
-
- </#if>
- </td>
- </tr>
- <#if (rowspan > 1)>
- <#foreach column in columnIterator>
- <tr>
- <td>
- <a href="#property_summary">
- ${column.name}
- </a>
- </td>
- </tr>
- </#foreach>
- </#if>
- </#foreach>
-
- </tbody>
- </table>
-
</body>
</html>
Modified: branches/Branch_3_2/HibernateExt/tools/src/test/org/hibernate/tool/hbm2x/DocExporterTest.java
===================================================================
--- branches/Branch_3_2/HibernateExt/tools/src/test/org/hibernate/tool/hbm2x/DocExporterTest.java 2006-11-02 04:22:27 UTC (rev 10682)
+++ branches/Branch_3_2/HibernateExt/tools/src/test/org/hibernate/tool/hbm2x/DocExporterTest.java 2006-11-02 12:36:22 UTC (rev 10683)
@@ -66,15 +66,18 @@
assertFileAndExists(new File(getOutputDir(), "tables/tablegraph.dot"));
assertFileAndExists(new File(getOutputDir(), "tables/tablegraph.png"));
+ /* Tidy complains about valid html 4.x
+ final Tidy tidy = new Tidy();
+
+
new FileVisitor() {
protected void process(File dir) {
- Tidy tidy = new Tidy();
if(dir.isFile() && dir.getName().endsWith( ".html" )) {
testHtml( tidy, dir );
}
}
- }.visit( getOutputDir() );
+ }.visit( getOutputDir() );*/
}
Modified: branches/Branch_3_2/HibernateExt/tools/src/test/org/hibernate/tool/hbm2x/GenerateFromJDBCTest.java
===================================================================
--- branches/Branch_3_2/HibernateExt/tools/src/test/org/hibernate/tool/hbm2x/GenerateFromJDBCTest.java 2006-11-02 04:22:27 UTC (rev 10682)
+++ branches/Branch_3_2/HibernateExt/tools/src/test/org/hibernate/tool/hbm2x/GenerateFromJDBCTest.java 2006-11-02 12:36:22 UTC (rev 10683)
@@ -53,7 +53,7 @@
protected void configure(JDBCMetaDataConfiguration cfg2configure) {
DefaultReverseEngineeringStrategy configurableNamingStrategy = new DefaultReverseEngineeringStrategy();
- configurableNamingStrategy.setSettings(new ReverseEngineeringSettings().setDefaultPackageName("org.reveng").setCreateCollectionForForeignKey(false));
+ configurableNamingStrategy.setSettings(new ReverseEngineeringSettings(configurableNamingStrategy).setDefaultPackageName("org.reveng").setCreateCollectionForForeignKey(false));
cfg2configure.setReverseEngineeringStrategy(configurableNamingStrategy);
}
Modified: branches/Branch_3_2/HibernateExt/tools/src/test/org/hibernate/tool/test/jdbc2cfg/DefaultReverseEngineeringStrategyTest.java
===================================================================
--- branches/Branch_3_2/HibernateExt/tools/src/test/org/hibernate/tool/test/jdbc2cfg/DefaultReverseEngineeringStrategyTest.java 2006-11-02 04:22:27 UTC (rev 10682)
+++ branches/Branch_3_2/HibernateExt/tools/src/test/org/hibernate/tool/test/jdbc2cfg/DefaultReverseEngineeringStrategyTest.java 2006-11-02 12:36:22 UTC (rev 10683)
@@ -13,6 +13,8 @@
import junit.framework.TestSuite;
import org.hibernate.cfg.reveng.DefaultReverseEngineeringStrategy;
+import org.hibernate.cfg.reveng.DelegatingReverseEngineeringStrategy;
+import org.hibernate.cfg.reveng.ReverseEngineeringSettings;
import org.hibernate.cfg.reveng.ReverseEngineeringStrategy;
import org.hibernate.cfg.reveng.TableIdentifier;
import org.hibernate.mapping.Column;
@@ -82,6 +84,25 @@
assertEquals("order", rns.foreignKeyToEntityName("something", new TableIdentifier("product"), null, new TableIdentifier("order"), null, true ) );
}
+ public void testCustomClassNameStrategyWithCollectionName() {
+
+ ReverseEngineeringStrategy custom = new DelegatingReverseEngineeringStrategy(new DefaultReverseEngineeringStrategy()) {
+ public String tableToClassName(TableIdentifier tableIdentifier) {
+ return super.tableToClassName( tableIdentifier ) + "Impl";
+ }
+ };
+
+ custom.setSettings( new ReverseEngineeringSettings(custom) );
+
+ TableIdentifier productTable = new TableIdentifier("product");
+ assertEquals("ProductImpl", custom.tableToClassName( productTable ));
+
+ assertEquals("productImpls", custom.foreignKeyToCollectionName("something", productTable, null, new TableIdentifier("order"), null, true ) );
+ /*assertEquals("willies", custom.foreignKeyToCollectionName("something", new TableIdentifier("willy"), null, new TableIdentifier("order"), null, true ) );
+ assertEquals("boxes", custom.foreignKeyToCollectionName("something", new TableIdentifier("box"), null, new TableIdentifier("order"), null, true ) );
+ assertEquals("order", custom.foreignKeyToEntityName("something", productTable, null, new TableIdentifier("order"), null, true ) );*/
+ }
+
public void testForeignKeyNamesToPropertyNames() {
String fkName = "something";
Modified: branches/Branch_3_2/HibernateExt/tools/src/test/org/hibernate/tool/test/jdbc2cfg/ManyToManyTest.java
===================================================================
--- branches/Branch_3_2/HibernateExt/tools/src/test/org/hibernate/tool/test/jdbc2cfg/ManyToManyTest.java 2006-11-02 04:22:27 UTC (rev 10682)
+++ branches/Branch_3_2/HibernateExt/tools/src/test/org/hibernate/tool/test/jdbc2cfg/ManyToManyTest.java 2006-11-02 12:36:22 UTC (rev 10683)
@@ -42,7 +42,7 @@
localCfg = new JDBCMetaDataConfiguration();
DefaultReverseEngineeringStrategy c = new DefaultReverseEngineeringStrategy();
- c.setSettings(new ReverseEngineeringSettings().setDetectManyToMany(false));
+ c.setSettings(new ReverseEngineeringSettings(c).setDetectManyToMany(false));
localCfg.setReverseEngineeringStrategy(c);
localCfg.readFromJDBC();
}
Modified: branches/Branch_3_2/HibernateExt/tools/src/test/org/hibernate/tool/test/jdbc2cfg/PersistentClassesTest.java
===================================================================
--- branches/Branch_3_2/HibernateExt/tools/src/test/org/hibernate/tool/test/jdbc2cfg/PersistentClassesTest.java 2006-11-02 04:22:27 UTC (rev 10682)
+++ branches/Branch_3_2/HibernateExt/tools/src/test/org/hibernate/tool/test/jdbc2cfg/PersistentClassesTest.java 2006-11-02 12:36:22 UTC (rev 10683)
@@ -48,7 +48,7 @@
protected void configure(JDBCMetaDataConfiguration cfgToConfigure) {
DefaultReverseEngineeringStrategy c = new DefaultReverseEngineeringStrategy();
- c.setSettings(new ReverseEngineeringSettings().setDefaultPackageName("persistentclasses"));
+ c.setSettings(new ReverseEngineeringSettings(c).setDefaultPackageName("persistentclasses"));
cfgToConfigure.setReverseEngineeringStrategy(c);
}
protected String[] getDropSQL() {
17 years, 7 months
Hibernate SVN: r10682 - in branches/Lucene_Integration/HibernateExt/metadata/src: java/org/hibernate/lucene java/org/hibernate/lucene/backend/impl java/org/hibernate/lucene/event java/org/hibernate/lucene/query java/org/hibernate/lucene/util test/org/hibernate/lucene/test test/org/hibernate/lucene/test/session
by hibernate-commits@lists.jboss.org
Author: epbernard
Date: 2006-11-01 23:22:27 -0500 (Wed, 01 Nov 2006)
New Revision: 10682
Added:
branches/Lucene_Integration/HibernateExt/metadata/src/java/org/hibernate/lucene/util/ContextHelper.java
branches/Lucene_Integration/HibernateExt/metadata/src/test/org/hibernate/lucene/test/session/
branches/Lucene_Integration/HibernateExt/metadata/src/test/org/hibernate/lucene/test/session/Email.java
branches/Lucene_Integration/HibernateExt/metadata/src/test/org/hibernate/lucene/test/session/MassIndexTest.java
Modified:
branches/Lucene_Integration/HibernateExt/metadata/src/java/org/hibernate/lucene/LuceneSession.java
branches/Lucene_Integration/HibernateExt/metadata/src/java/org/hibernate/lucene/backend/impl/PostTransactionWorkQueueSynchronization.java
branches/Lucene_Integration/HibernateExt/metadata/src/java/org/hibernate/lucene/event/LuceneEventListener.java
branches/Lucene_Integration/HibernateExt/metadata/src/java/org/hibernate/lucene/query/LuceneQueryImpl.java
Log:
ANN-384 enable (re)indexing, batch per transaction
Modified: branches/Lucene_Integration/HibernateExt/metadata/src/java/org/hibernate/lucene/LuceneSession.java
===================================================================
--- branches/Lucene_Integration/HibernateExt/metadata/src/java/org/hibernate/lucene/LuceneSession.java 2006-11-01 23:06:05 UTC (rev 10681)
+++ branches/Lucene_Integration/HibernateExt/metadata/src/java/org/hibernate/lucene/LuceneSession.java 2006-11-02 04:22:27 UTC (rev 10682)
@@ -6,7 +6,11 @@
import java.util.Collection;
import java.util.Iterator;
import java.util.List;
+import java.util.Map;
+import java.util.concurrent.locks.ReentrantLock;
+import javax.transaction.Status;
+
import org.hibernate.CacheMode;
import org.hibernate.Criteria;
import org.hibernate.EntityMode;
@@ -20,12 +24,22 @@
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.Transaction;
-import org.hibernate.cfg.NotYetImplementedException;
+import org.hibernate.event.PostInsertEventListener;
import org.hibernate.engine.query.ParameterMetadata;
import org.hibernate.impl.SessionImpl;
import org.hibernate.lucene.query.LuceneQueryImpl;
+import org.hibernate.lucene.event.LuceneEventListener;
+import org.hibernate.lucene.util.ContextHelper;
+import org.hibernate.lucene.engine.DocumentBuilder;
+import org.hibernate.lucene.backend.UpdateWork;
+import org.hibernate.lucene.backend.Work;
+import org.hibernate.lucene.backend.WorkQueue;
+import org.hibernate.lucene.backend.impl.BatchLuceneWorkQueue;
+import org.hibernate.lucene.backend.impl.PostTransactionWorkQueueSynchronization;
+import org.hibernate.lucene.store.DirectoryProvider;
import org.hibernate.stat.SessionStatistics;
import org.hibernate.type.Type;
+import org.apache.lucene.document.Document;
/**
* Lucene aware session that allows lucene query creations
@@ -34,6 +48,7 @@
*/
public class LuceneSession implements Session {
private final SessionImpl session;
+ private PostTransactionWorkQueueSynchronization postTransactionWorkQueueSynch;
public LuceneSession(Session session) {
this.session = (SessionImpl) session;
@@ -49,8 +64,24 @@
return new LuceneQueryImpl( luceneQuery, entities, session, new ParameterMetadata(null, null) );
}
- public void index(Object object) {
- throw new NotYetImplementedException("");
+ /**
+ * (re)index an entity.
+ * Non indexable entities are ignored
+ * The entity must be associated with the session
+ *
+ * @param entity must not be null
+ */
+ public void index(Object entity) {
+ if (entity == null) return;
+ Class clazz = entity.getClass();
+ LuceneEventListener listener = ContextHelper.getLuceneEventListener( session );
+ DocumentBuilder<Object> builder = listener.getDocumentBuilders().get( clazz );
+ if ( builder != null ) {
+ Serializable id = session.getIdentifier( entity );
+ Document doc = builder.getDocument( entity, id );
+ UpdateWork work = new UpdateWork( id, entity.getClass(), doc );
+ processWork( work, listener.getDocumentBuilders(), listener.getLockableDirectoryProviders() );
+ }
//TODO
//need to add elements in a queue kept at the Session level
//the queue will be processed by a Lucene(Auto)FlushEventListener
@@ -60,6 +91,31 @@
// this is an open discussion
}
+ private void processWork(Work work, Map<Class, DocumentBuilder<Object>> documentBuilders,
+ Map<DirectoryProvider, ReentrantLock> lockableDirectoryProviders) {
+ if ( session.isTransactionInProgress() ) {
+ if ( postTransactionWorkQueueSynch == null || postTransactionWorkQueueSynch.isConsumed() ) {
+ postTransactionWorkQueueSynch = createWorkQueueSync( documentBuilders, lockableDirectoryProviders);
+ session.getTransaction().registerSynchronization( postTransactionWorkQueueSynch );
+ }
+ postTransactionWorkQueueSynch.add( work );
+ }
+ else {
+ //no transaction work right away
+ PostTransactionWorkQueueSynchronization sync =
+ createWorkQueueSync( documentBuilders, lockableDirectoryProviders );
+ sync.add( work );
+ sync.afterCompletion( Status.STATUS_COMMITTED );
+ }
+ }
+
+ private PostTransactionWorkQueueSynchronization createWorkQueueSync(
+ Map<Class, DocumentBuilder<Object>> documentBuilders,
+ Map<DirectoryProvider, ReentrantLock> lockableDirectoryProviders) {
+ WorkQueue workQueue = new BatchLuceneWorkQueue( documentBuilders, lockableDirectoryProviders );
+ return new PostTransactionWorkQueueSynchronization( workQueue );
+ }
+
public Query createSQLQuery(String sql, String returnAlias, Class returnClass) {
return session.createSQLQuery( sql, returnAlias, returnClass );
}
Modified: branches/Lucene_Integration/HibernateExt/metadata/src/java/org/hibernate/lucene/backend/impl/PostTransactionWorkQueueSynchronization.java
===================================================================
--- branches/Lucene_Integration/HibernateExt/metadata/src/java/org/hibernate/lucene/backend/impl/PostTransactionWorkQueueSynchronization.java 2006-11-01 23:06:05 UTC (rev 10681)
+++ branches/Lucene_Integration/HibernateExt/metadata/src/java/org/hibernate/lucene/backend/impl/PostTransactionWorkQueueSynchronization.java 2006-11-02 04:22:27 UTC (rev 10682)
@@ -5,6 +5,7 @@
import javax.transaction.Synchronization;
import org.hibernate.lucene.backend.WorkQueue;
+import org.hibernate.lucene.backend.Work;
/**
* Execute some work inside a transaction sychronization
@@ -13,24 +14,34 @@
*/
public class PostTransactionWorkQueueSynchronization implements Synchronization {
private WorkQueue workQueue;
+ private boolean consumed;
public PostTransactionWorkQueueSynchronization(WorkQueue workQueue) {
this.workQueue = workQueue;
}
+ public void add(Work work) {
+ workQueue.add( work );
+ }
+
+ public boolean isConsumed() {
+ return consumed;
+ }
+
public void beforeCompletion() {
}
public void afterCompletion(int i) {
- if ( Status.STATUS_COMMITTED == i ) {
- workQueue.performWork();
+ try {
+ if ( Status.STATUS_COMMITTED == i ) {
+ workQueue.performWork();
+ }
+ else {
+ workQueue.cancelWork();
+ }
}
- else {
- workQueue.cancelWork();
+ finally {
+ consumed = true;
}
}
-
- public static interface Work {
- void perform();
- }
}
Modified: branches/Lucene_Integration/HibernateExt/metadata/src/java/org/hibernate/lucene/event/LuceneEventListener.java
===================================================================
--- branches/Lucene_Integration/HibernateExt/metadata/src/java/org/hibernate/lucene/event/LuceneEventListener.java 2006-11-01 23:06:05 UTC (rev 10681)
+++ branches/Lucene_Integration/HibernateExt/metadata/src/java/org/hibernate/lucene/event/LuceneEventListener.java 2006-11-02 04:22:27 UTC (rev 10682)
@@ -173,4 +173,8 @@
sync.afterCompletion( Status.STATUS_COMMITTED );
}
}
+
+ public Map<DirectoryProvider, ReentrantLock> getLockableDirectoryProviders() {
+ return lockableDirectoryProviders;
+ }
}
Modified: branches/Lucene_Integration/HibernateExt/metadata/src/java/org/hibernate/lucene/query/LuceneQueryImpl.java
===================================================================
--- branches/Lucene_Integration/HibernateExt/metadata/src/java/org/hibernate/lucene/query/LuceneQueryImpl.java 2006-11-01 23:06:05 UTC (rev 10681)
+++ branches/Lucene_Integration/HibernateExt/metadata/src/java/org/hibernate/lucene/query/LuceneQueryImpl.java 2006-11-02 04:22:27 UTC (rev 10682)
@@ -36,6 +36,7 @@
import org.hibernate.impl.AbstractQueryImpl;
import org.hibernate.lucene.engine.DocumentBuilder;
import org.hibernate.lucene.event.LuceneEventListener;
+import org.hibernate.lucene.util.ContextHelper;
/**
* @author Emmanuel Bernard
@@ -71,7 +72,7 @@
//user stop using it
//scrollable is better in this area
- LuceneEventListener listener = getLuceneEventListener();
+ LuceneEventListener listener = ContextHelper.getLuceneEventListener( session );
//find the directories
Searcher searcher = buildSearcher( listener );
Hits hits;
@@ -106,7 +107,7 @@
public ScrollableResults scroll() throws HibernateException {
//keep the searcher open until the resultset is closed
- LuceneEventListener listener = getLuceneEventListener();
+ LuceneEventListener listener = ContextHelper.getLuceneEventListener( session );;
//find the directories
Searcher searcher = buildSearcher( listener );
Hits hits;
@@ -135,13 +136,12 @@
}
public List list() throws HibernateException {
- LuceneEventListener listener = getLuceneEventListener();
+ LuceneEventListener listener = ContextHelper.getLuceneEventListener( session );;
//find the directories
Searcher searcher = buildSearcher( listener );
Hits hits;
try {
org.apache.lucene.search.Query query = filterQueryByClasses( luceneQuery );
- log.warn( query.toString() );
hits = searcher.search( query );
setResultSize( hits );
int first = first();
@@ -284,20 +284,6 @@
return this;
}
- private LuceneEventListener getLuceneEventListener() {
- PostInsertEventListener[] listeners = session.getListeners().getPostInsertEventListeners();
- LuceneEventListener listener = null;
- //FIXME this sucks since we mandante the event listener use
- for ( PostInsertEventListener candidate : listeners ) {
- if ( candidate instanceof LuceneEventListener ) {
- listener = (LuceneEventListener) candidate;
- break;
- }
- }
- if ( listener == null ) throw new HibernateException( "Lucene event listener not initialized" );
- return listener;
- }
-
public int executeUpdate() throws HibernateException {
throw new HibernateException( "Not supported operation" );
}
Added: branches/Lucene_Integration/HibernateExt/metadata/src/java/org/hibernate/lucene/util/ContextHelper.java
===================================================================
--- branches/Lucene_Integration/HibernateExt/metadata/src/java/org/hibernate/lucene/util/ContextHelper.java 2006-11-01 23:06:05 UTC (rev 10681)
+++ branches/Lucene_Integration/HibernateExt/metadata/src/java/org/hibernate/lucene/util/ContextHelper.java 2006-11-02 04:22:27 UTC (rev 10682)
@@ -0,0 +1,27 @@
+//$Id: $
+package org.hibernate.lucene.util;
+
+import org.hibernate.HibernateException;
+import org.hibernate.engine.SessionImplementor;
+import org.hibernate.event.PostInsertEventListener;
+import org.hibernate.lucene.event.LuceneEventListener;
+
+/**
+ * @author Emmanuel Bernard
+ */
+public abstract class ContextHelper {
+
+ public static LuceneEventListener getLuceneEventListener(SessionImplementor session) {
+ PostInsertEventListener[] listeners = session.getListeners().getPostInsertEventListeners();
+ LuceneEventListener listener = null;
+ //FIXME this sucks since we mandante the event listener use
+ for ( PostInsertEventListener candidate : listeners ) {
+ if ( candidate instanceof LuceneEventListener ) {
+ listener = (LuceneEventListener) candidate;
+ break;
+ }
+ }
+ if ( listener == null ) throw new HibernateException( "Lucene event listener not initialized" );
+ return listener;
+ }
+}
Added: branches/Lucene_Integration/HibernateExt/metadata/src/test/org/hibernate/lucene/test/session/Email.java
===================================================================
--- branches/Lucene_Integration/HibernateExt/metadata/src/test/org/hibernate/lucene/test/session/Email.java 2006-11-01 23:06:05 UTC (rev 10681)
+++ branches/Lucene_Integration/HibernateExt/metadata/src/test/org/hibernate/lucene/test/session/Email.java 2006-11-02 04:22:27 UTC (rev 10682)
@@ -0,0 +1,64 @@
+//$Id: $
+package org.hibernate.lucene.test.session;
+
+import javax.persistence.Entity;
+import javax.persistence.Id;
+import javax.persistence.GeneratedValue;
+
+import org.hibernate.lucene.annotations.Indexed;
+import org.hibernate.lucene.annotations.DocumentId;
+import org.hibernate.lucene.annotations.Field;
+import org.hibernate.lucene.annotations.Index;
+
+/**
+ * @author Emmanuel Bernard
+ */
+@Entity
+@Indexed
+public class Email {
+ @Id
+ @GeneratedValue
+ @DocumentId
+ private Long id;
+
+ @Field(index = Index.TOKENIZED)
+ private String title;
+
+ @Field(index = Index.TOKENIZED)
+ private String body;
+
+ private String header;
+
+
+ public Long getId() {
+ return id;
+ }
+
+ public void setId(Long id) {
+ this.id = id;
+ }
+
+ public String getTitle() {
+ return title;
+ }
+
+ public void setTitle(String title) {
+ this.title = title;
+ }
+
+ public String getBody() {
+ return body;
+ }
+
+ public void setBody(String body) {
+ this.body = body;
+ }
+
+ public String getHeader() {
+ return header;
+ }
+
+ public void setHeader(String header) {
+ this.header = header;
+ }
+}
Added: branches/Lucene_Integration/HibernateExt/metadata/src/test/org/hibernate/lucene/test/session/MassIndexTest.java
===================================================================
--- branches/Lucene_Integration/HibernateExt/metadata/src/test/org/hibernate/lucene/test/session/MassIndexTest.java 2006-11-01 23:06:05 UTC (rev 10681)
+++ branches/Lucene_Integration/HibernateExt/metadata/src/test/org/hibernate/lucene/test/session/MassIndexTest.java 2006-11-02 04:22:27 UTC (rev 10682)
@@ -0,0 +1,68 @@
+//$Id: $
+package org.hibernate.lucene.test.session;
+
+import java.sql.SQLException;
+import java.util.List;
+
+import org.hibernate.lucene.test.TestCase;
+import org.hibernate.lucene.LuceneSession;
+import org.hibernate.Session;
+import org.hibernate.Transaction;
+import org.apache.lucene.queryParser.QueryParser;
+import org.apache.lucene.analysis.StopAnalyzer;
+
+/**
+ * @author Emmanuel Bernard
+ */
+public class MassIndexTest extends TestCase {
+
+ public void testTransactional() throws Exception {
+ LuceneSession s = new LuceneSession( openSession() );
+ Transaction tx = s.beginTransaction();
+ int loop = 4;
+ for (int i = 0 ; i < loop; i++) {
+ Email email = new Email();
+ email.setTitle( "JBoss World Berlin" );
+ email.setBody( "Meet the guys who wrote the software");
+ s.persist( email );
+ }
+ tx.commit();
+ s.close();
+
+ s = new LuceneSession( openSession() );
+ s.getTransaction().begin();
+ s.connection().createStatement().executeUpdate( "update Email set body='Meet the guys who write the software'");
+ s.getTransaction().commit();
+ s.close();
+
+ s = new LuceneSession( openSession() );
+ tx = s.beginTransaction();
+ QueryParser parser = new QueryParser("id", new StopAnalyzer() );
+ List result = s.createLuceneQuery( parser.parse( "body:write" ) ).list();
+ assertEquals( 0, result.size() );
+ result = s.createCriteria( Email.class ).list();
+ for (int i = 0 ; i < loop/2 ; i++)
+ s.index( result.get( i ) );
+ tx.commit(); //do the process
+ s.index( result.get(loop/2) ); //do the process out of tx
+ tx = s.beginTransaction();
+ for (int i = loop/2+1 ; i < loop; i++)
+ s.index( result.get( i ) );
+ tx.commit(); //do the process
+ s.close();
+
+ s = new LuceneSession( openSession() );
+ tx = s.beginTransaction();
+ result = s.createLuceneQuery( parser.parse( "body:write" ) ).list();
+ assertEquals( loop, result.size() );
+ for (Object o : result) s.delete( o );
+ tx.commit();
+ s.close();
+ }
+
+ protected Class[] getMappings() {
+ return new Class[] {
+ Email.class
+ };
+ }
+}
17 years, 7 months