-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 6 posts ] 
Author Message
 Post subject: Use of close() in DelegatingReverseEngineeringStrategy
PostPosted: Tue Jan 26, 2010 11:08 am 
Newbie

Joined: Sat Mar 07, 2009 6:58 pm
Posts: 13
According to the javadocs DelegatingReverseEngineeringStrategy.close should be called after reverse engineering is complete, however when I override it it is called before tableToClassName is called, which is what I would consider to be part of the reverse engineering process.

I am doing some custom code generation (specifically generating a Spring IOC Bean definition which instantiates a generic service for a given database table) and I use information from calls like tableToClassName during generation. This all works a treat except I can't close my XML file correctly.

I had hoped I could close the spring config file by overriding close(), but close would appear to be called when reading of the schema is complete and not when the reverse engineering process as a whole is complete, could be it is designed for closing connections as early as possible and not for general resource cleanup at the end of the complete process.

Can someone comment on this and perhaps suggest an alternative, I've tried using finalize() on my derived Strategy, but this brings a whole string of other issues with it and I really don't want to go down that road if I can avoid it.


Top
 Profile  
 
 Post subject: Re: Use of close() in DelegatingReverseEngineeringStrategy
PostPosted: Tue Jan 26, 2010 12:54 pm 
Newbie

Joined: Sat Mar 07, 2009 6:58 pm
Posts: 13
Here's the output from my maven plugin
As you can see close() is being called a lot quicker than I would have expected, right in the middle of a seuence of tableToClassName() calls

[INFO] Scanning for projects...
[INFO] ------------------------------------------------------------------------
[INFO] Building dbframework ucase-proto.mapping.hbm2java
[INFO] task-segment: [generate-sources]
[INFO] ------------------------------------------------------------------------
[INFO] Preparing hibernate3:hbm2java
[WARNING] Removing: hbm2java from forked lifecycle, to prevent recursive invocation.
[INFO] [resources:resources {execution: default-resources}]
[WARNING] Using platform encoding (Cp1252 actually) to copy filtered resources, i.e. build is platform dependent!
[INFO] Copying 10 resources
Downloading: http://repository.jboss.com/maven2/com/ ... .0.7.0.pom
[INFO] Unable to find resource 'com.oracle.ojdbc6:ojdbc6:pom:11.1.0.7.0' in repository jboss (http://repository.jboss.com/maven2)
Downloading: http://download.java.net/maven/2/com/or ... .0.7.0.pom
[INFO] Unable to find resource 'com.oracle.ojdbc6:ojdbc6:pom:11.1.0.7.0' in repository maven2-repository.dev.java.net (http://download.java.net/maven/2)
Downloading: http://download.java.net/maven/1/com.or ... .0.7.0.pom
[INFO] Unable to find resource 'com.oracle.ojdbc6:ojdbc6:pom:11.1.0.7.0' in repository maven-repository.dev.java.net (http://download.java.net/maven/1)
Downloading: http://repo1.maven.org/maven2/com/oracl ... .0.7.0.pom
[INFO] Unable to find resource 'com.oracle.ojdbc6:ojdbc6:pom:11.1.0.7.0' in repository central (http://repo1.maven.org/maven2)
[INFO] [hibernate3:hbm2java {execution: default}]
[INFO] using jdbcconfiguration task.
INFO Environment - Hibernate 3.3.2.GA
INFO Environment - hibernate.properties not found
INFO Environment - Bytecode provider name : javassist
INFO Environment - using JDK 1.4 java.sql.Timestamp handling
[INFO] Configuration XML file loaded: file:/D:/Development/ccmp/dbm/db-framework/develop/ucase-proto/ucase-mapping/ucase-hbm2java/src/main/resources/hbm2java.ucase-oracle.cfg.xml
INFO Configuration - configuring from url: file:/D:/Development/ccmp/dbm/db-framework/develop/ucase-proto/ucase-mapping/ucase-hbm2java/src/main/resources/hbm2java.ucase-oracle.cfg.xml
INFO Configuration - Configured SessionFactory: MCMDB
[INFO] No hibernate properties file loaded.
INFO OverrideRepository - Override file: D:\Development\ccmp\dbm\db-framework\develop\ucase-proto\ucase-mapping\ucase-hbm2java\src\main\resources\hibernate.ucase.reveng.xml
INFO McmdbRevengStrategy - McmdbRevengStrategy Activated
INFO McmdbRevengStrategy - BasicServiceGenerator Created
INFO DriverManagerConnectionProvider - Using Hibernate built-in connection pool (not for production use!)
INFO DriverManagerConnectionProvider - Hibernate connection pool size: 1
INFO DriverManagerConnectionProvider - autocommit mode: false
INFO DriverManagerConnectionProvider - using driver: oracle.jdbc.driver.OracleDriver at URL: jdbc:oracle:thin:@localhost:1521:mcm
INFO DriverManagerConnectionProvider - connection properties: {user=mcm, password=****}
INFO SettingsFactory - RDBMS: Oracle, version: Oracle Database 11g Enterprise Edition Release 11.1.0.6.0 - Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options
INFO SettingsFactory - JDBC driver: Oracle JDBC driver, version: 11.1.0.7.0-Production
INFO Dialect - Using dialect: org.hibernate.dialect.Oracle10gDialect
INFO TransactionFactoryFactory - Using default transaction strategy (direct JDBC transactions)
INFO TransactionManagerLookupFactory - No TransactionManagerLookup configured (in JTA environment, use of read-write or transactional second-level cache is not recommended)
INFO SettingsFactory - Automatic flush during beforeCompletion(): disabled
INFO SettingsFactory - Automatic session close at end of transaction: disabled
INFO SettingsFactory - JDBC batch size: 15
INFO SettingsFactory - JDBC batch updates for versioned data: disabled
INFO SettingsFactory - Scrollable result sets: enabled
INFO SettingsFactory - JDBC3 getGeneratedKeys(): disabled
INFO SettingsFactory - Connection release mode: auto
INFO SettingsFactory - Default batch fetch size: 1
INFO SettingsFactory - Generate SQL with comments: disabled
INFO SettingsFactory - Order SQL updates by primary key: disabled
INFO SettingsFactory - Order SQL inserts for batching: disabled
INFO SettingsFactory - Query translator: org.hibernate.hql.ast.ASTQueryTranslatorFactory
INFO ASTQueryTranslatorFactory - Using ASTQueryTranslatorFactory
INFO SettingsFactory - Query language substitutions: {}
INFO SettingsFactory - JPA-QL strict compliance: disabled
INFO SettingsFactory - Second-level cache: enabled
INFO SettingsFactory - Query cache: disabled
INFO SettingsFactory - Cache region factory : org.hibernate.cache.impl.NoCachingRegionFactory
INFO SettingsFactory - Optimize cache for minimal puts: disabled
INFO SettingsFactory - Structured second-level cache entries: disabled
INFO SettingsFactory - Statistics: disabled
INFO SettingsFactory - Deleted entity synthetic identifier rollback: disabled
INFO SettingsFactory - Default entity-mode: pojo
INFO SettingsFactory - Named query checking : enabled
INFO McmdbRevengStrategy - tableToClassName() called
INFO McmdbRevengStrategy - Generating DAO and Service for de.atlas.dbm.ucase.entities.LoadTestKindL id java.io.Serializable
INFO McmdbRevengStrategy - tableToClassName() called
INFO McmdbRevengStrategy - Generating DAO and Service for de.atlas.dbm.ucase.entities.Uc2Level1A id java.io.Serializable
INFO McmdbRevengStrategy - tableToClassName() called
INFO McmdbRevengStrategy - tableToClassName() called
INFO McmdbRevengStrategy - Generating DAO and Service for de.atlas.dbm.ucase.entities.Uc2Main id java.io.Serializable
INFO McmdbRevengStrategy - tableToClassName() called
INFO McmdbRevengStrategy - close() called
INFO McmdbRevengStrategy - tableToClassName() called
INFO McmdbRevengStrategy - Generating DAO and Service for de.atlas.dbm.ucase.entities.LoadTest id java.io.Serializable
INFO McmdbRevengStrategy - Modified column name from ldtId to id
INFO McmdbRevengStrategy - Modified column name from ldtSourceId to sourceId
INFO McmdbRevengStrategy - tableToClassName() called
INFO McmdbRevengStrategy - tableToClassName() called
INFO McmdbRevengStrategy - tableToClassName() called
INFO McmdbRevengStrategy - tableToClassName() called
INFO McmdbRevengStrategy - tableToClassName() called
INFO McmdbRevengStrategy - Generating DAO and Service for de.atlas.dbm.ucase.entities.Uc1Main id java.io.Serializable
INFO McmdbRevengStrategy - Modified column name from uc1Id to id
INFO McmdbRevengStrategy - Modified column name from uc1SourceId to sourceId
WARN McmdbRevengStrategy - No precision or scale specified? Defaulting to [Dd]ouble for UC_1_MAIN.COLUMN14
WARN McmdbRevengStrategy - No precision or scale specified? Defaulting to [Dd]ouble for UC_1_MAIN.COLUMN15
WARN McmdbRevengStrategy - No precision or scale specified? Defaulting to [Dd]ouble for UC_1_MAIN.COLUMN16
INFO McmdbRevengStrategy - tableToClassName() called
INFO McmdbRevengStrategy - Generating DAO and Service for de.atlas.dbm.ucase.entities.Uc1Small id java.io.Serializable
INFO McmdbRevengStrategy - tableToClassName() called
INFO McmdbRevengStrategy - tableToClassName() called
INFO McmdbRevengStrategy - tableToClassName() called
INFO McmdbRevengStrategy - Generating DAO and Service for de.atlas.dbm.ucase.entities.Uc2Level2Y id java.io.Serializable
INFO McmdbRevengStrategy - tableToClassName() called
INFO McmdbRevengStrategy - tableToClassName() called
INFO McmdbRevengStrategy - Generating DAO and Service for de.atlas.dbm.ucase.entities.Uc2Level2X id java.io.Serializable
INFO McmdbRevengStrategy - tableToClassName() called
INFO McmdbRevengStrategy - tableToClassName() called
INFO McmdbRevengStrategy - Generating DAO and Service for de.atlas.dbm.ucase.entities.Uc2Level1B id java.io.Serializable
INFO McmdbRevengStrategy - tableToClassName() called
INFO McmdbRevengStrategy - tableToClassName() called
INFO McmdbRevengStrategy - tableToClassName() called
INFO McmdbRevengStrategy - tableToClassName() called
INFO McmdbRevengStrategy - tableToClassName() called
INFO McmdbRevengStrategy - tableToClassName() called
INFO McmdbRevengStrategy - tableToClassName() called
INFO McmdbRevengStrategy - tableToClassName() called
INFO McmdbRevengStrategy - tableToClassName() called
INFO McmdbRevengStrategy - tableToClassName() called
INFO McmdbRevengStrategy - tableToClassName() called
INFO McmdbRevengStrategy - Generating DAO and Service for de.atlas.dbm.ucase.entities.UcBlobTest id java.io.Serializable
WARN McmdbRevengStrategy - No precision or scale specified? Defaulting to [Dd]ouble for UC_BLOB_TEST.UC_BLOB_TEST_ID
WARN McmdbRevengStrategy - A hibernate type of serializable could mean no suitable mapping found for UC_BLOB_TEST_BFILE
INFO McmdbRevengStrategy - tableToClassName() called
INFO McmdbRevengStrategy - Generating DAO and Service for de.atlas.dbm.ucase.entities.UcSimpleKey id java.io.Serializable
INFO DriverManagerConnectionProvider - cleaning up connection pool: jdbc:oracle:thin:@localhost:1521:mcm
INFO Version - Hibernate Tools 3.2.4.GA
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESSFUL
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 56 seconds
[INFO] Finished at: Tue Jan 26 17:49:30 CET 2010
[INFO] Final Memory: 10M/19M
[INFO] ------------------------------------------------------------------------
INFO DriverManagerConnectionProvider - cleaning up connection pool: jdbc:oracle:thin:@localhost:1521:mcm
WARN BasicServiceGenerator - finalize() called while spring configuration still open
INFO BasicServiceGenerator - closeSpringConfiguration() called checkError:true


Top
 Profile  
 
 Post subject: Re: Use of close() in DelegatingReverseEngineeringStrategy
PostPosted: Wed Jan 27, 2010 11:51 am 
Newbie

Joined: Sat Mar 07, 2009 6:58 pm
Posts: 13
I had already figured out where and why it was called: quote from my original post...

"but close would appear to be called when reading of the schema is complete and not when the reverse engineering process as a whole is complete, could be it is designed for closing connections as early as possible and not for general resource cleanup at the end of the complete process."

The javadoc of the close() interface is IMO misleading:

"Close any resources this strategy might have used. Called after reverse engineering has been completed."

Should read "Called when the reading the schema is complete."

IMHO there's a whole load of reverse engineering going on after that (not all the Pojos have been written yet) and it would be nice to have notification of the fact that reverse engineering is complete, as well as when reading the schema is complete.

Looks like I'll have to rely on the finalizer of my delegate to figure out when the last table has been processed.

Unless anyone has another idea?


Top
 Profile  
 
 Post subject: Re: Use of close() in DelegatingReverseEngineeringStrategy
PostPosted: Thu Feb 04, 2010 4:04 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
there is actually more than one phase, reverse engineering (reading from the schema), building the model (configuration) and then code generation from that model.

The .close() is for the first phase.

If you are generating files then that should be done in the code generation part and you can do that via templates or a programmatic exporter.

_________________
Max
Don't forget to rate


Top
 Profile  
 
 Post subject: Re: Use of close() in DelegatingReverseEngineeringStrategy
PostPosted: Thu Feb 04, 2010 4:58 am 
Newbie

Joined: Sat Mar 07, 2009 6:58 pm
Posts: 13
Ok Thanks Max, I mistakenly though the whole process was "reverse engineering", it didn't occur to me that it was synonymous with "read the schema". I am doing doing prototyping and thought I could simply hitch a ride from my Strategy class. I have been able to get the results I need for now, I will write the exporter when I get a quiet moment ;)


Top
 Profile  
 
 Post subject: Re: Use of close() in DelegatingReverseEngineeringStrategy
PostPosted: Thu Feb 04, 2010 6:10 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
sandymcp wrote:
Ok Thanks Max, I mistakenly though the whole process was "reverse engineering", it didn't occur to me that it was synonymous with "read the schema". I am doing doing prototyping and thought I could simply hitch a ride from my Strategy class. I have been able to get the results I need for now, I will write the exporter when I get a quiet moment ;)


be aware that in a Freemarker template you can do something like:

Code:
<#foreach item in ctx?keys>   
<#assign captured><#include "generic-content.ftl"/></#assign>
${templates.createFile(captured, "${item}.txt")}
</#foreach>


This basically assigns freemarker output to a variable "captured" which you then can "write" out via templates.createFile(...).

That allows you to create single or multiple files as you want it without writing an actual Exporter class.

_________________
Max
Don't forget to rate


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 6 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.