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-04-24 23:33:34
|
Author: epbernard Date: 2006-04-24 19:33:25 -0400 (Mon, 24 Apr 2006) New Revision: 9784 Added: trunk/HibernateExt/metadata/src/test/org/hibernate/test/annotations/interfaces/ trunk/HibernateExt/metadata/src/test/org/hibernate/test/annotations/interfaces/Contact.java trunk/HibernateExt/metadata/src/test/org/hibernate/test/annotations/interfaces/ContactImpl.java trunk/HibernateExt/metadata/src/test/org/hibernate/test/annotations/interfaces/InterfacesTest.java trunk/HibernateExt/metadata/src/test/org/hibernate/test/annotations/interfaces/User.java trunk/HibernateExt/metadata/src/test/org/hibernate/test/annotations/interfaces/UserImpl.java Log: some more tests on interface/implementations usage Added: trunk/HibernateExt/metadata/src/test/org/hibernate/test/annotations/interfaces/Contact.java =================================================================== --- trunk/HibernateExt/metadata/src/test/org/hibernate/test/annotations/interfaces/Contact.java 2006-04-24 15:59:01 UTC (rev 9783) +++ trunk/HibernateExt/metadata/src/test/org/hibernate/test/annotations/interfaces/Contact.java 2006-04-24 23:33:25 UTC (rev 9784) @@ -0,0 +1,10 @@ +//$Id: $ +package org.hibernate.test.annotations.interfaces; + +/** + * @author Emmanuel Bernard + */ +public interface Contact { + Integer getId(); + String getName(); +} Added: trunk/HibernateExt/metadata/src/test/org/hibernate/test/annotations/interfaces/ContactImpl.java =================================================================== --- trunk/HibernateExt/metadata/src/test/org/hibernate/test/annotations/interfaces/ContactImpl.java 2006-04-24 15:59:01 UTC (rev 9783) +++ trunk/HibernateExt/metadata/src/test/org/hibernate/test/annotations/interfaces/ContactImpl.java 2006-04-24 23:33:25 UTC (rev 9784) @@ -0,0 +1,32 @@ +//$Id: $ +package org.hibernate.test.annotations.interfaces; + +import javax.persistence.Id; +import javax.persistence.GeneratedValue; +import javax.persistence.Entity; + +/** + * @author Emmanuel Bernard + */ +@Entity +public class ContactImpl implements Contact { + private Integer id; + private String name; + + @Id @GeneratedValue + public Integer getId() { + return id; + } + + public void setId(Integer id) { + this.id = id; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } +} Added: trunk/HibernateExt/metadata/src/test/org/hibernate/test/annotations/interfaces/InterfacesTest.java =================================================================== --- trunk/HibernateExt/metadata/src/test/org/hibernate/test/annotations/interfaces/InterfacesTest.java 2006-04-24 15:59:01 UTC (rev 9783) +++ trunk/HibernateExt/metadata/src/test/org/hibernate/test/annotations/interfaces/InterfacesTest.java 2006-04-24 23:33:25 UTC (rev 9784) @@ -0,0 +1,19 @@ +//$Id: $ +package org.hibernate.test.annotations.interfaces; + +import org.hibernate.test.annotations.TestCase; + +/** + * @author Emmanuel Bernard + */ +public class InterfacesTest extends TestCase { + public void testInterface() { + + } + protected Class[] getMappings() { + return new Class[] { + ContactImpl.class, + UserImpl.class + }; + } +} Added: trunk/HibernateExt/metadata/src/test/org/hibernate/test/annotations/interfaces/User.java =================================================================== --- trunk/HibernateExt/metadata/src/test/org/hibernate/test/annotations/interfaces/User.java 2006-04-24 15:59:01 UTC (rev 9783) +++ trunk/HibernateExt/metadata/src/test/org/hibernate/test/annotations/interfaces/User.java 2006-04-24 23:33:25 UTC (rev 9784) @@ -0,0 +1,14 @@ +//$Id: $ +package org.hibernate.test.annotations.interfaces; + +import java.util.Collection; + +/** + * @author Emmanuel Bernard + */ +public interface User { + Integer getId(); + Collection<Contact> getContacts(); + + +} Added: trunk/HibernateExt/metadata/src/test/org/hibernate/test/annotations/interfaces/UserImpl.java =================================================================== --- trunk/HibernateExt/metadata/src/test/org/hibernate/test/annotations/interfaces/UserImpl.java 2006-04-24 15:59:01 UTC (rev 9783) +++ trunk/HibernateExt/metadata/src/test/org/hibernate/test/annotations/interfaces/UserImpl.java 2006-04-24 23:33:25 UTC (rev 9784) @@ -0,0 +1,35 @@ +//$Id: $ +package org.hibernate.test.annotations.interfaces; + +import java.util.Collection; +import javax.persistence.Id; +import javax.persistence.GeneratedValue; +import javax.persistence.OneToMany; +import javax.persistence.Entity; + +/** + * @author Emmanuel Bernard + */ +@Entity +public class UserImpl implements User { + private Collection<Contact> contacts; + private Integer id; + + @Id @GeneratedValue + public Integer getId() { + return id; + } + + public void setId(Integer id) { + this.id = id; + } + + @OneToMany(targetEntity = ContactImpl.class) + public Collection<Contact> getContacts() { + return contacts; + } + + public void setContacts(Collection<Contact> contacts) { + this.contacts = contacts; + } +} |
From: <hib...@li...> - 2006-04-24 15:59:11
|
Author: max...@jb... Date: 2006-04-24 11:59:01 -0400 (Mon, 24 Apr 2006) New Revision: 9783 Added: tags/TOOLS_3_1_0_BETA5/tools/ Log: tools beta 5 Copied: tags/TOOLS_3_1_0_BETA5/tools (from rev 9782, trunk/HibernateExt/tools) |
From: <hib...@li...> - 2006-04-24 15:58:19
|
Author: max...@jb... Date: 2006-04-24 11:58:05 -0400 (Mon, 24 Apr 2006) New Revision: 9782 Added: tags/TOOLS_3_1_0_BETA5/ Log: tools beta 5 |
From: <hib...@li...> - 2006-04-24 15:56:20
|
Author: max...@jb... Date: 2006-04-24 11:56:06 -0400 (Mon, 24 Apr 2006) New Revision: 9781 Added: tags/TOOLS_3_1_0_BETA4/TOOLS_3_1_0_BETA5/ Log: |
From: <hib...@li...> - 2006-04-24 14:24:43
|
Author: max...@jb... Date: 2006-04-24 10:24:33 -0400 (Mon, 24 Apr 2006) New Revision: 9780 Modified: trunk/HibernateExt/tools/build.xml Log: bump Modified: trunk/HibernateExt/tools/build.xml =================================================================== --- trunk/HibernateExt/tools/build.xml 2006-04-23 18:55:33 UTC (rev 9779) +++ trunk/HibernateExt/tools/build.xml 2006-04-24 14:24:33 UTC (rev 9780) @@ -7,7 +7,7 @@ <!-- Name of project and version, used to create filenames --> <property name="Name" value="Hibernate Tools"/> <property name="name" value="hibernate-tools"/> - <property name="version" value="3.1.0beta4"/> + <property name="version" value="3.1.0beta5"/> <property name="javadoc.packagenames" value="org.hibernate.tool"/> |
From: <hib...@li...> - 2006-04-23 18:55:42
|
Author: max...@jb... Date: 2006-04-23 14:55:33 -0400 (Sun, 23 Apr 2006) New Revision: 9779 Modified: trunk/HibernateExt/tools/doc/reference/en/images/codegenexporters.gif trunk/HibernateExt/tools/doc/reference/en/master.xml trunk/HibernateExt/tools/doc/reference/en/modules/ant.xml trunk/HibernateExt/tools/doc/reference/en/modules/plugins.xml trunk/HibernateExt/tools/doc/reference/en/modules/reverseengineering.xml Log: more docs Modified: trunk/HibernateExt/tools/doc/reference/en/images/codegenexporters.gif =================================================================== (Binary files differ) Modified: trunk/HibernateExt/tools/doc/reference/en/master.xml =================================================================== --- trunk/HibernateExt/tools/doc/reference/en/master.xml 2006-04-21 19:10:39 UTC (rev 9778) +++ trunk/HibernateExt/tools/doc/reference/en/master.xml 2006-04-23 18:55:33 UTC (rev 9779) @@ -14,7 +14,7 @@ <subtitle>Reference Guide</subtitle> - <releaseinfo>3.1.0.beta4</releaseinfo> + <releaseinfo>3.1.0.beta5</releaseinfo> <mediaobject> <imageobject> Modified: trunk/HibernateExt/tools/doc/reference/en/modules/ant.xml =================================================================== --- trunk/HibernateExt/tools/doc/reference/en/modules/ant.xml 2006-04-21 19:10:39 UTC (rev 9778) +++ trunk/HibernateExt/tools/doc/reference/en/modules/ant.xml 2006-04-23 18:55:33 UTC (rev 9779) @@ -349,11 +349,11 @@ <para><programlistingco> <areaspec> - <area coords="4 57" id="cfg1" /> + <area coords="4 57" id="xcfg1" /> - <area coords="5 57" id="cfg2" /> + <area coords="5 57" id="xcfg2" /> - <area coords="6 57" id="cfg3" /> + <area coords="6 57" id="xcfg3" /> </areaspec> @@ -367,18 +367,18 @@ </jdbcconfiguration>]]></programlisting> <calloutlist> - <callout arearefs="cfg1"> + <callout arearefs="xcfg1"> <para>packagename (optional): The default package name to use when mappings for classes is created</para> </callout> - <callout arearefs="cfg2"> + <callout arearefs="xcfg2"> <para><literal>revengfile</literal> (optional): name of reveng.xml that allows you to control varios aspects of the reverse engineering.</para> </callout> - <callout arearefs="cfg3"> + <callout arearefs="xcfg3"> <para><literal>reversestrategy</literal> (optional): name of a class that implements <literal>org.hibernate.cfg.reveng.ReverseEngineeringStrategy</literal>. @@ -432,19 +432,19 @@ <para><programlistingco> <areaspec> - <area coords="2 55" id="cfg1" /> + <area coords="2 55" id="ycfg1" /> - <area coords="3 55" id="cfg2" /> + <area coords="3 55" id="ycfg2" /> - <area coords="4 55" id="cfg3" /> + <area coords="4 55" id="ycfg3" /> - <area coords="5 55" id="cfg4" /> + <area coords="5 55" id="ycfg4" /> - <area coords="6 55" id="cfg6" /> + <area coords="6 55" id="ycfg5" /> - <area coords="7 55" id="cfg7" /> + <area coords="7 55" id="ycfg6" /> - <area coords="8 55" id="cfg8" /> + <area coords="8 55" id="ycfg7" /> </areaspec> <programlisting><![CDATA[<hbm2ddl @@ -458,12 +458,12 @@ >]]></programlisting> <calloutlist> - <callout arearefs="cfg1"> + <callout arearefs="ycfg1"> <para>export (default: true): Execute the generated statements against the database</para> </callout> - <callout arearefs="cfg2"> + <callout arearefs="ycfg2"> <para>update(default: false): Try and create an update script representing the "delta" between what is in the database and what the mappings specify. Ignores create/update attributes. @@ -473,27 +473,27 @@ operations</emphasis>)</para> </callout> - <callout arearefs="cfg3"> + <callout arearefs="ycfg3"> <para>drop (default: false): Output will contain drop statements for the tables, indices & constraints</para> </callout> - <callout arearefs="cfg4"> + <callout arearefs="ycfg4"> <para>create (default: true): Output will contain create statements for the tables, indices & constraints</para> </callout> - <callout arearefs="cfg5"> + <callout arearefs="ycfg5"> <para>outputfilename (Optional): If specified the statements will be dumped to this file.</para> </callout> - <callout arearefs="cfg6"> + <callout arearefs="ycfg6"> <para>delimiter (default: ";"): What delimter to use to separate statements</para> </callout> - <callout arearefs="cfg7"> + <callout arearefs="ycfg7"> <para>format (default: false): Apply basic formatting to the statements.</para> </callout> @@ -524,9 +524,9 @@ <para><programlistingco> <areaspec> - <area coords="2 55" id="cfg1" /> + <area coords="2 55" id="zcfg1" /> - <area coords="3 55" id="cfg2" /> + <area coords="3 55" id="zcfg2" /> </areaspec> <programlisting><![CDATA[<hbm2java @@ -535,12 +535,12 @@ >]]></programlisting> <calloutlist> - <callout arearefs="cfg1"> + <callout arearefs="zcfg1"> <para>jdk (default: false): Code will contain JDK 5 constructs such as generics and static imports</para> </callout> - <callout arearefs="cfg2"> + <callout arearefs="zcfg2"> <para>ejb3 (default: false): Code will contain EJB 3 features, e.g. using annotations from javax.persistence and org.hibernate.annotations</para> @@ -611,7 +611,7 @@ <para><programlistingco> <areaspec> - <area coords="2 55" id="cfg1" /> + <area coords="2 55" id="qcfg1" /> </areaspec> <programlisting><![CDATA[<hbm2cfgxml @@ -620,7 +620,7 @@ ]]></programlisting> <calloutlist> - <callout arearefs="cfg1"> + <callout arearefs="qcfg1"> <para>ejb3 (default: false): the generated cfg.xml will have <mapping class=".."/>, opposed to <mapping resource="..."/> for each mapping.</para> Modified: trunk/HibernateExt/tools/doc/reference/en/modules/plugins.xml =================================================================== --- trunk/HibernateExt/tools/doc/reference/en/modules/plugins.xml 2006-04-21 19:10:39 UTC (rev 9778) +++ trunk/HibernateExt/tools/doc/reference/en/modules/plugins.xml 2006-04-23 18:55:33 UTC (rev 9779) @@ -499,7 +499,7 @@ <tbody> <row> - <entry><para>Generate domain code</para></entry> + <entry><para>Domain code</para></entry> <entry><para>Generates POJO's for all the persistent classes and components found in the given Hibernate @@ -521,22 +521,21 @@ </row> <row> - <entry><para>Generate DAO code</para></entry> + <entry><para>DAO code</para></entry> <entry><para>Generates a set of DAO's for each entity found.</para></entry> </row> <row> - <entry><para>Generate Mappings</para></entry> + <entry><para>Hibernate XML Mappings</para></entry> <entry><para>Generate mapping (hbm.xml) files for each entity</para></entry> </row> <row> - <entry><para>Generate hibernate configuration - file</para></entry> + <entry><para>Hibernate XML Configuration</para></entry> <entry><para>Generate a hibernate.cfg.xml file. Used to keep the hibernate.cfg.xml uptodate with any new found mapping @@ -544,15 +543,14 @@ </row> <row> - <entry><para>Generate schema html-documentation</para></entry> + <entry><para>Schema Documentation (.html)</para></entry> <entry><para>Generates set of html pages that documents the database schema and some of the mappings.</para></entry> </row> <row> - <entry><para>Generate JBoss Seam skeleton app - (beta)</para></entry> + <entry><para>Generate JBoss Seam skeleton app [Beta]</para></entry> <entry><para>Generates a complete JBoss Seam skeleton app. The generation will include annotated POJO's, Seam controller beans @@ -698,8 +696,8 @@ <para>Note that not all the features of the .reveng.xml file is exposed or fully implemented in the editor, but the main functionallity is there. To - understand the full flexibility of the reveng.xml, please see <xlink - linkend="hibernaterevengxmlfile" /></para> + understand the full flexibility of the reveng.xml, please see <xref + linkend="hibernaterevengxmlfile"/></para> <para>The editor is activated as soon as an .reveng.xml file is opened. To get an initial reveng.xml file the reveng.xml wizard can be started via @@ -812,19 +810,22 @@ <title>Class Diagram</title> <para>A class diagram is available in the view named "Hibernate Entity - Model". It will show the model for any slected hibernate console - configuration.</para> + Model". It will show the model when the Configuration node in a Hibernate Console + Configuration is selected.</para> <mediaobject> <imageobject role="fo"> - <imagedata fileref="images/entitymodel_zoomout.png" /> + <imagedata fileref="images/entitymodel.gif" /> </imageobject> <imageobject role="html"> <imagedata align="center" - fileref="../shared/images/entitymodel_zoomout.png" /> + fileref="../shared/images/entitymodel.gif" /> </imageobject> </mediaobject> + + <para>This view supports zoom in/out and can also be printed. Zooming is done via the toolbar buttons in the view + and printing is done by selecting the view and choose File/Print or use the Print Icon.</para> </section> Modified: trunk/HibernateExt/tools/doc/reference/en/modules/reverseengineering.xml =================================================================== --- trunk/HibernateExt/tools/doc/reference/en/modules/reverseengineering.xml 2006-04-21 19:10:39 UTC (rev 9778) +++ trunk/HibernateExt/tools/doc/reference/en/modules/reverseengineering.xml 2006-04-23 18:55:33 UTC (rev 9779) @@ -45,6 +45,7 @@ <hibernate-reverse-engineering> +<schema-selection <type-mapping> <!-- jdbc-type is name fom java.sql.Types --> <sql-type jdbc-type="VARCHAR" length='20' hibernate-type="SomeUserType" /> @@ -69,12 +70,18 @@ are done for a specific table --> <table name="ORDERS"> <primary-key> + <!-- setting up a specific id generator for a table --> <generator class="sequence"> <param name="table">seq_table</param> </generator> - <column name="CUSTID" foreign-table="CUSTOMER" foreign-column="CUSTID" /> + <column name="CUSTID"/> </primary-key> <column name="NAME" property="orderName" type="string" /> + <!-- control many-to-one and set names for a specific named foreign key constraint --> + <foreign-key constraint-name="ORDER_CUST"> + <many-to-one property="customer"/> + <set property="orders"/> + </foreign-key> </table> </hibernate-reverse-engineering>]]></programlisting> @@ -82,6 +89,52 @@ <para></para> <section> + <title>Schema Selection (<schema-selection>)</title> + + <para><literal><schema-selection></literal> is used to drive which + schema's the reverse engineering will try and process.</para> + + <para>By default the reverse engineering will read all schemas and then + use <literal><table-filter></literal> to decide which tables get + reverse engineered and which do not; this makes it easy to get started + but can be inefficient on databases with many schemas.</para> + + <para>With <literal><schema-selection></literal> it is thus + possible to limit the actual processed schemas and thus significantly + speed-up the reverse engineering. + <literal><table-filter></literal> is still used to then decide + which tables will be included/excluded.</para> + + <para>Note: If no <literal><schema-selection></literal> is + specified, the reverse engineering works as if all schemas should be + processed. This is equal to:</para> + + <programlisting><![CDATA[<schema-selection/>]]></programlisting> + + <para>which in turn is equal to:</para> + + <programlisting><![CDATA[<schema-selection match-catalog=".*" match-schema=".*" match-table=".*"/>]]></programlisting> + + <section> + <title>Examples</title> + + <para>The following will process all tables from MY_SCHEMA.</para> + + <programlisting><![CDATA[<schema-selection match-schema="MY_SCHEMA"/>]]></programlisting> + + <para>It is possible to have multiple + <literal>schema-selection</literal>'s to support multi-schema reading + or simply to limit the processing to very specific tables. The + following example process all tables in MY_SCHEMA, a specific CITY + table plus all tables that starts with CODES_ in COMMON_SCHEMA.</para> + + <programlisting><![CDATA[<schema-selection match-schema="MY_SCHEMA"/> +<schema-selection match-schema="COMMON_SCHEMA" match-table="CITY"/> +<schema-selection match-schema="COMMON_SCHEMA" match-table="CODES_.*"/>]]></programlisting> + </section> + </section> + + <section> <title>Type mappings (<type-mapping>)</title> <para>The <literal><type-mapping></literal> section specifies how @@ -97,7 +150,8 @@ length="a numeric value" precision="a numeric value" scale="a numeric value" - not-null="true|false" + not-null="true|false" + hibernate-type="hibernate type name" /> </type-mapping>]]></programlisting> @@ -128,10 +182,10 @@ named CUSTOMER:</para> <table frame="topbot"> - <title>Supported meta tags</title> + <title>sql-type examples</title> <tgroup cols="7"> - <colspec colwidth="0.5*" /> + <colspec colwidth="0.5*" /> <colspec colwidth="0.5*" /> @@ -283,13 +337,54 @@ exclude specific tables based on the schema or even a specifc prefix.</para> - <programlisting><![CDATA[<table-filter + <programlistingco> + <areaspec> + <area coords="2 55" id="tablefilter-matchcatalog" /> + + <area coords="3 55" id="tablefilter-matchschema" /> + + <area coords="4 55" id="tablefilter-matchname" /> + + <area coords="5 55" id="tablefilter-exclude" /> + + <area coords="6 55" id="tablefilter-package" /> + </areaspec> + + <programlisting><![CDATA[<table-filter match-catalog="catalog_matching_rule" match-schema="schema_matching_rule" match-name="table_matching_rule" exclude="true|false" package="package.name" />]]></programlisting> + + <calloutlist> + <callout arearefs="tablefilter-matchcatalog"> + <para>match-catalog (default: .*): Pattern for matching catalog + part of the table</para> + </callout> + + <callout arearefs="tablefilter-matchschema"> + <para>match-schema (default: .*): Pattern for matching schema part + of the table</para> + </callout> + + <callout arearefs="tablefilter-matchname"> + <para>match-table (default: .*): Pattern for matching table part + of the table</para> + </callout> + + <callout arearefs="tablefilter-exclude"> + <para>exclude (default: false): if true the table will not be part + of the reverse engineering</para> + </callout> + + <callout arearefs="tablefilter-package"> + <para>package (default: ""): The default package name to use for + classes based on tables matched by this table-filter</para> + </callout> + </calloutlist> + </programlistingco> </section> <section> @@ -299,9 +394,23 @@ configuration on how a table should be reverse engineered. Amongst other things it allow control over the naming of a class for the table, specify which identifier generator should be used for the primary key - etc.</para> + etc. Note: many databases is case-sensitive with their names and thus if + you cannot make the table match and you are sure it is not excluded by a + <table-filter> then check if the case matches; most databases + stores table names in uppercase.</para> - <programlisting><![CDATA[<table + <programlistingco> + <areaspec> + <area coords="2 55" id="table-catalog" /> + + <area coords="3 55" id="table-schema" /> + + <area coords="4 55" id="table-name" /> + + <area coords="5 55" id="table-class" /> + </areaspec> + + <programlisting><![CDATA[<table catalog="catalog_name" schema="schema_name" name="table_name" @@ -312,6 +421,26 @@ <foreign-key...> </table>]]></programlisting> + <calloutlist> + <callout arearefs="tablefilter-matchcatalog"> + <para>catalog (Optional): Catalog name for table</para> + </callout> + + <callout arearefs="tablefilter-matchschema"> + <para>schema (Optionl): Schema name for table</para> + </callout> + + <callout arearefs="tablefilter-matchname"> + <para>name (Required): Name for table</para> + </callout> + + <callout arearefs="tablefilter-exclude"> + <para>clase (Optional): The class name for table. Default name is + camelcase version of the table name. </para> + </callout> + </calloutlist> + </programlistingco> + <section> <title><primary-key></title> @@ -321,7 +450,7 @@ <generator class="generatorname"> <param name="param_name">parameter value</param> </generator> - <column...> + <key-column...> </primary-key>]]></programlisting> </section> @@ -336,10 +465,6 @@ type="hibernate_type" property="propertyName" exclude="true|false" - foreign-catalog="catalogName" - foreign-schema="schemaName" - foreign-table="tableName" - foreign-column="columnName" />]]></programlisting> </section> @@ -349,7 +474,7 @@ <para></para> <programlisting><![CDATA[<foreign-key - name="foreignKeyName" + constraint-name="foreignKeyName" foreign-catalog="catalogName" foreign-schema="schemaName" foreign-table="tableName" @@ -389,4 +514,24 @@ } }]]></programlisting> </section> + + <section> + <title>Custom Database Metadata</title> + + <para>By default the reverse engineering is performed by reading using the + JDBC database metadata API. This is done via the class + <literal>org.hibernate.cfg.reveng.dialect.JDBCMetaDataDialect</literal> + which is an implementation of + <literal>org.hibernate.cfg.reveng.dialect.MetaDataDialect</literal>.</para> + + <para>The default implementation can be replaced with an alternative + implementation by setting the property + <literal>hibernatetool.metadatadialect</literal> to a fully qualified + classname for a class that implements + <literal>JDBCMetaDataDialect</literal>.</para> + + <para>This can be used to provide database specific optimized metadata + reading. If you create an optimized/better metadata reading for your + database it will be a very welcome contribution.</para> + </section> </chapter> \ No newline at end of file |
From: <hib...@li...> - 2006-04-21 19:10:44
|
Author: max...@jb... Date: 2006-04-21 15:10:39 -0400 (Fri, 21 Apr 2006) New Revision: 9778 Modified: trunk/HibernateExt/tools/src/java/org/hibernate/tool/hbm2x/QueryExporter.java Log: Reworked <hql> to allow for nested and be called <query> + revised ant docs Modified: trunk/HibernateExt/tools/src/java/org/hibernate/tool/hbm2x/QueryExporter.java =================================================================== --- trunk/HibernateExt/tools/src/java/org/hibernate/tool/hbm2x/QueryExporter.java 2006-04-21 19:03:03 UTC (rev 9777) +++ trunk/HibernateExt/tools/src/java/org/hibernate/tool/hbm2x/QueryExporter.java 2006-04-21 19:10:39 UTC (rev 9778) @@ -13,7 +13,7 @@ import org.hibernate.classic.Session; /** - * Placeholder exporter for query execution. + * exporter for query execution. * **/ public class QueryExporter extends AbstractExporter { |
Author: max...@jb... Date: 2006-04-21 15:03:03 -0400 (Fri, 21 Apr 2006) New Revision: 9777 Added: trunk/HibernateExt/tools/src/java/org/hibernate/tool/ant/QueryExporterTask.java trunk/HibernateExt/tools/src/java/org/hibernate/tool/hbm2x/QueryExporter.java Removed: trunk/HibernateExt/tools/src/java/org/hibernate/tool/ant/HQLExporterTask.java trunk/HibernateExt/tools/src/java/org/hibernate/tool/hbm2x/HQLExporter.java Modified: trunk/HibernateExt/tools/doc/reference/en/modules/ant.xml trunk/HibernateExt/tools/src/java/org/hibernate/tool/ant/HibernateToolTask.java trunk/HibernateExt/tools/src/java/org/hibernate/tool/hbm2x/pojo/ComponentPOJOClass.java trunk/HibernateExt/tools/src/testsupport/anttest-build.xml Log: HBX-648 ejb3 generation should generate the now required @Temporal for date/time's + revised ant docs Modified: trunk/HibernateExt/tools/doc/reference/en/modules/ant.xml =================================================================== --- trunk/HibernateExt/tools/doc/reference/en/modules/ant.xml 2006-04-20 21:35:09 UTC (rev 9776) +++ trunk/HibernateExt/tools/doc/reference/en/modules/ant.xml 2006-04-21 19:03:03 UTC (rev 9777) @@ -10,32 +10,41 @@ and the eclipse plugins both available from tools.hibernate.org The hibernate-tools.jar is located in your eclipse plugins directory at <literallayout>/plugins/org.hibernate.eclipse.x.x.x/lib/tools/hibernate-tools.jar</literallayout>. - This jar is 100% independent from the eclipse platform.</para> + This jar is 100% independent from the eclipse platform and can thus be + used independently of eclipse.</para> <section> <title>The <literal><hibernatetool></literal> ant Task</title> <para>To use the ant tasks you ned to have the hibernatetool task - defined. That is done in your build.xml by inserting the following xml: - <programlisting><![CDATA[ <taskdef - name="hibernatetool" - classname="org.hibernate.tool.ant.HibernateToolTask" - classpath="[location of hibernate-tools.jar, velocity.jar, - velocity-tools-generic.jar, jtidy.jar, - hibernate3.jar & jdbc drivers]"/> + defined. That is done in your build.xml by inserting the following xml + (assuming the jars are in the <literal>lib</literal> directory): + <programlisting><![CDATA[<path id="toolslib"> + <path location="lib/hibernate-tools.jar" /> + <path location="lib/hibernate3.jar" /> + <path location="lib/freemarker.jar" /> + <path location="${jdbc.driver.jar}" /> +</path> + +<taskdef name="hibernatetool" + classname="org.hibernate.tool.ant.HibernateToolTask" + classpathref="toolslib" /> ]]></programlisting></para> - <para>This <literal><taskdef></literal> defines a Ant task called + <para>his <literal><taskdef></literal> defines a Ant task called <literal><hibernatetool></literal> which now can be used anywhere in your ant build.xml files. It is important to include all the hibernate tools dependencies as well as the jdbc driver.</para> <para>Notice that to use the annotation based Configuration you must get a release from <link - linkend="???">http://annotations.hibernate.org</link>. When using the - <literal><hibernatetool> </literal>task you have to specify one or - more of the following:</para> + linkend="???">http://annotations.hibernate.org</link>.</para> + <para></para> + + <para>When using the <literal><hibernatetool> </literal>task you + have to specify one or more of the following:</para> + <para><programlistingco> <areaspec> <area coords="2 55" id="ht1" /> @@ -44,7 +53,9 @@ <area coords="5 55" id="ht3" /> - <area coords="6 55" id="ht4" /> + <area coords="7 55" id="ht4" /> + + <area coords="9 55" id="config" /> </areaspec> <programlisting><![CDATA[<hibernatetool @@ -54,8 +65,9 @@ <classpath ...> <property name="propertyName" value="value"/> <propertyset ...> - (<configuration ...>|<annotationconfiguration ...>|<jdbcconfiguration ...>) - (<hbm2java>,<hbm2cfgxml>,...*) + (<configuration ...>|<annotationconfiguration ...>| + <ejb3configuration ...>|<jdbcconfiguration ...>) + (<hbm2java>,<hbm2cfgxml>,<hbmtemplate>,...*) </hibernatetool>]]></programlisting> <calloutlist> @@ -81,32 +93,86 @@ properties to control the exporters. Mostly relevant for providing custom properties to user defined templates.</para> </callout> + + <callout arearefs="config"> + <para>One of 4 different ways of configuring the Hibernate Meta + Model must be specified.</para> + </callout> + + <callout arearefs="???"> + <para>One or more of the exporters must be specified</para> + </callout> </calloutlist> </programlistingco></para> + + <section> + <title>Basic examples</title> + + <para>The following example shows the most basic setup for generating + pojo's via <literal>hbm2java</literal> from a normal + <literal>hibernate.cfg.xml.</literal> The output will be put in the + <literal>${build.dir}/generated</literal> directory.</para> + + <para><programlisting><![CDATA[<hibernatetool destdir="${build.dir}/generated"> + <configuration configurationfile="hibernate.cfg.xml"/> + <hbm2java/> +</hibernatetool>]]></programlisting></para> + + <para>The following example is similar, but now we are performing + multiple exports from the same configuration. We are exporting the + schema via hbm2dll, generates some DAO code via <hbm2dao> and + finally runs a custom code generation via <hbmtemplate>. This is + again from a normal <literal>hibernate.cfg.xml and </literal>the + output is still put in the <literal>${build.dir}/generated</literal> + directory. Furthermore the example also shows where a classpath is + specified when you e.g. have custom usertypes or some mappings that is + needed to be looked up as a classpath resource.</para> + + <para><programlisting><![CDATA[<hibernatetool destdir="${build.dir}/generated"> + <classpath> + <path location="${build.dir}/classes"/> + </classpath> + + <configuration configurationfile="hibernate.cfg.xml"/> + <hbm2ddl/> + <hbm2dao/> + <hbmtemplate + filepattern="{package-name}/I{class-name}Constants.java" + templatepath="${etc.dir}/customtemplates" + template="myconstants.vm" + /> +</hibernatetool>]]></programlisting></para> + </section> </section> <section> <title>Hibernate Configurations</title> - <para><literal>hibernatetool</literal> supports three different - Hibernate configurations: A standard Hibernate configuration + <para><literal>hibernatetool</literal> supports four different Hibernate + configurations: A standard Hibernate configuration (<literal><configuration></literal>), Annotation based - configuration (<literal><annotationconfiguratioin></literal>) and - a JDBC based configuration - (<literal><jdbcconfiguration></literal>) for use when reverse - engineering.</para> + configuration (<literal><annotationconfiguration></literal>), EJB3 + persistence based configuration + (<literal><ejb3configuration></literal>) and a JDBC based + configuration (<literal><jdbcconfiguration></literal>) for use + when reverse engineering.</para> <para>Each have in common that they are able to build up a Hibernate <literal>Configuration</literal> object from which a set of exporters - can be run to generate various output.</para> + can be run to generate various output. Note: output can be anything, + e.g. specific files, statments execution against a database, error + reporting or anything else that can be done in java code.</para> + <para>The following section decribes what the the various configuration + can do, plus list the individual settings they have.</para> + <section> <title>Standard Hibernate Configuration (<configuration>)</title> <para>A <configuration> is used to define a standard Hibernate configuration. A standard Hibernate configuration reads the mappings - from the optional hbm.xml and the fileset.</para> + from a cfg.xml and/or a fileset.</para> <para><programlistingco> <areaspec> @@ -165,6 +231,30 @@ </callout> </calloutlist> </programlistingco></para> + + <section> + <title>Example</title> + + <para>This example shows an example where no + <literal>hibernate.cfg.xml</literal> exists, and a + <literal>hibernate.properties</literal> + fileset is used instead. + Note, that Hibernate will still read any global + <literal>/hibernate.properties</literal> available in the classpath, + but the specified properties file here will override those values + for any non-global property.</para> + + <para><programlisting><![CDATA[<hibernatetool destdir="${build.dir}/generated"> + <configuration propertyfile="{etc.dir}/hibernate.properties"> + <fileset dir="${src.dir}"> + <include name="**/*.hbm.xml"/> + <exclude name="**/*Test.hbm.xml"/> + </fileset> + </configuration> + + <!-- list exporters here --> + +</hibernatetool>]]></programlisting></para> + </section> </section> <section> @@ -177,43 +267,154 @@ hibernate annotations in the classpath of the <literal><taskdef></literal>.</para> - <para>The <annotationconfiguration> has the same attributes as - an <configuration> except that the configurationfile attribute - is now required as that is from where an AnnotationConfiguration gets - the list of classes/packages it should load.</para> + <para>The <annotationconfiguration> supports the same attributes + as an <configuration> except that the configurationfile + attribute is now required as that is from where an + <literal>AnnotationConfiguration</literal> gets the list of + classes/packages it should load.</para> <para>Thus the minimal usage is:</para> - <para><programlisting><![CDATA[<annotationconfiguration + <para><programlisting><![CDATA[<hibernatetool destdir="${build.dir}/generated"> + <annotationconfiguration configurationfile="hibernate.cfg.xml"/> + + <!-- list exporters here --> + +</hibernatetool> ]]></programlisting></para> </section> <section> + <title>EJB3 based configuration (<ejb3configuration>)</title> + + <para>An <ejb3configuration> is used when you want to read the + metamodel from EJB3/Hibernate Annotation where you want to use the + auto-scan configuration as defined in the EJB3 spec. In other words, + when you do not have a <literal>hibernate.cfg.xml</literal>, but + instead have a setup where you use a + <literal>persistence.xml</literal> packaged in an EJB3 compliant + manner.</para> + + <para>Note, in the current version there is no additional attribute + support on <ejb3configuration> like found on + <annotationconfiguration> and <configuration>. It will + simply just try and auto-configure it self based on the available + classpath, e.g. look for META-INF/persistence.xml.</para> + + <para>To use an <ejb3configuration> you will need to specify + some additional jars from Hibernate EntityManager in the + <taskdef> of the hibernatetool. The following shows a full + setup:</para> + + <programlisting><![CDATA[<path id="ejb3toolslib"> + <path refid="toolslib"/> <!-- ref to previously defined toolslib --> + <path location="lib/hibernate-annotations.jar" /> + <path location="lib/ejb3-persistence.jar" /> + <path location="lib/hibernate-entitymanager.jar" /> + <path location="lib/jboss-archive-browsing.jar" /> + <path location="lib/javaassist.jar" /> +</path> + +<taskdef name="hibernatetool" + classname="org.hibernate.tool.ant.HibernateToolTask" + classpathref="ejb3toolslib" /> + +<hibernatetool destdir="${build.dir}"> + <ejb3configuration /> + <classpath> + <!-- it is in this classpath you put your classes dir, + and/or ejb3 persistence compliant jar --> + <path location="${build.dir}/ejb3/classes" /> + </classpath> + + <!-- list exporters here --> + +</hibernatetool> +]]></programlisting> + </section> + + <section> <title>JDBC Configuration for reverse engineering (<jdbcconfiguration>)</title> <para>A <jdbcconfiguration> is used to perform reverse - engineering of the database from a JDBC connection. The - <jdbcconfiguration> has the same attributes as a + engineering of the database from a JDBC connection.</para> + + <para>This configuration works by reading the connection properties + from</para> + + <para>The <jdbcconfiguration> has the same attributes as a <configuration> plus the following additional attributes:</para> - <para><programlisting><![CDATA[<jdbcconfiguration + <para><programlistingco> + <areaspec> + <area coords="4 57" id="cfg1" /> + + <area coords="5 57" id="cfg2" /> + + <area coords="6 57" id="cfg3" /> + + </areaspec> + + <programlisting><![CDATA[<jdbcconfiguration ... packagename="package.name" + revengfile="hibernate.reveng.xml" reversestrategy="ReverseEngineeringStrategy classname" - revengfile="hibernate.reveng.xml" > ... -</jdbcconfiguration>]]></programlisting></para> +</jdbcconfiguration>]]></programlisting> + + <calloutlist> + <callout arearefs="cfg1"> + <para>packagename (optional): The default package name to use + when mappings for classes is created</para> + </callout> + + <callout arearefs="cfg2"> + <para><literal>revengfile</literal> (optional): name of + reveng.xml that allows you to control varios aspects of the + reverse engineering.</para> + </callout> + + <callout arearefs="cfg3"> + <para><literal>reversestrategy</literal> (optional): name of a + class that implements + <literal>org.hibernate.cfg.reveng.ReverseEngineeringStrategy</literal>. + Used for setting up the strategy the tools will use to control + the reverse engineering, e.g. naming of properties, which + tables to include/exclude etc. Using a class instead of (or as + addition to) a reveng.xml file gives you full programmatic + control of the reverse engineering.</para> + </callout> + </calloutlist> + </programlistingco></para> + + <section> + <title>Example</title> + + <para>Here is an example of using + <literal><jdbcconfiguration></literal> to generate Hibernate + xml mappings via <literal><hbm2hbmxml></literal>. The + connection settings is here read from a + <literal>hibernate.properties</literal> file but could just as well + have been read from a <literal>hibernate.cfg.xml.</literal></para> + + <programlisting><![CDATA[<hibernatetool> + <jdbcconfiguration propertyfile="etc/hibernate.properties" /> + <hbm2hbmxml destdir="${build.dir}/src" /> +</hibernatetool> +]]></programlisting> + </section> </section> </section> <section> - <title>Code Exporters</title> + <title>Exporters</title> - <para>Code exporters is the parts that does the actual job of converting - the hibernate metamodel into various code artifacts. The following + <para>Exporters is the parts that does the actual job of converting the + hibernate metamodel into various artifacts, mainly code. The following section describes the current supported set of exporters in the Hibernate Tool distribution. It is also possible for userdefined exporters, that is done through the @@ -225,19 +426,92 @@ <para><hbm2ddl> lets you run schemaexport and schemaupdate which generates the appropriate SQL DDL and allow you to store the result in - a file or export it directly to the database.</para> + a file or export it directly to the database. Remember that if a + custom naming strategy is needed it is placed on the configuration + element.</para> - <programlisting><![CDATA[<hbm2ddl + <para><programlistingco> + <areaspec> + <area coords="2 55" id="cfg1" /> + + <area coords="3 55" id="cfg2" /> + + <area coords="4 55" id="cfg3" /> + + <area coords="5 55" id="cfg4" /> + + <area coords="6 55" id="cfg6" /> + + <area coords="7 55" id="cfg7" /> + + <area coords="8 55" id="cfg8" /> + </areaspec> + + <programlisting><![CDATA[<hbm2ddl + export="true|false" + update="true|false" drop="true|false" create="true|false" - export="true|false" - update="true|false" outputfilename="filename.ddl" delimiter=";" format="true|false" >]]></programlisting> - <para></para> + <calloutlist> + <callout arearefs="cfg1"> + <para>export (default: true): Execute the generated statements + against the database</para> + </callout> + + <callout arearefs="cfg2"> + <para>update(default: false): Try and create an update script + representing the "delta" between what is in the database and + what the mappings specify. Ignores create/update attributes. + (<emphasis>Do *not* use against production databases, no + guarantees at all that the proper delta can be generated nor + that the underlying database can actually execute the needed + operations</emphasis>)</para> + </callout> + + <callout arearefs="cfg3"> + <para>drop (default: false): Output will contain drop + statements for the tables, indices & constraints</para> + </callout> + + <callout arearefs="cfg4"> + <para>create (default: true): Output will contain create + statements for the tables, indices & constraints</para> + </callout> + + <callout arearefs="cfg5"> + <para>outputfilename (Optional): If specified the statements + will be dumped to this file.</para> + </callout> + + <callout arearefs="cfg6"> + <para>delimiter (default: ";"): What delimter to use to + separate statements</para> + </callout> + + <callout arearefs="cfg7"> + <para>format (default: false): Apply basic formatting to the + statements.</para> + </callout> + </calloutlist> + </programlistingco></para> + + <section> + <title>Example</title> + + <para>Basic example of using <hbm2ddl>, which does not export + to the database but simply dumps the sql to a file named + sql.ddl.</para> + + <programlisting><![CDATA[<hibernatetool destdir="${build.dir}/generated"> + <configuration configurationfile="hibernate.cfg.xml"/> + <hbm2ddl export="false" outputfilename="sql.ddl"/> +</hibernatetool>]]></programlisting> + </section> </section> <section> @@ -248,12 +522,43 @@ controlling wether JDK 5 syntax can be used and wether the POJO should be annotated with EJB3/Hibernate Annotations.</para> - <programlisting><![CDATA[<hbm2java + <para><programlistingco> + <areaspec> + <area coords="2 55" id="cfg1" /> + + <area coords="3 55" id="cfg2" /> + </areaspec> + + <programlisting><![CDATA[<hbm2java jdk5="true|false" ejb3="true|false" >]]></programlisting> - <para></para> + <calloutlist> + <callout arearefs="cfg1"> + <para>jdk (default: false): Code will contain JDK 5 constructs + such as generics and static imports</para> + </callout> + + <callout arearefs="cfg2"> + <para>ejb3 (default: false): Code will contain EJB 3 features, + e.g. using annotations from javax.persistence and + org.hibernate.annotations</para> + </callout> + </calloutlist> + </programlistingco></para> + + <section> + <title>Example</title> + + <para>Basic example of using <hbm2java> to generate POJO's + that utilize jdk5 constructs.</para> + + <programlisting><![CDATA[<hibernatetool destdir="${build.dir}/generated"> + <configuration configurationfile="hibernate.cfg.xml"/> + <hbm2java jdk5="true"/> +</hibernatetool>]]></programlisting> + </section> </section> <section> @@ -264,12 +569,34 @@ used together with a <jdbcconfiguration> when performing reverse engineering, but can be used with any kind of configuration. e.g. to convert from annotation based pojo's to hbm.xml. Note that not every - possible mapping transformation is possible/implemented so some hand - editing might be necessary.</para> + possible mapping transformation is possible/implemented (contributions + welcome) so some hand editing might be necessary.</para> <programlisting><![CDATA[<hbm2hbmxml/>]]></programlisting> - <para></para> + <section> + <title>Example</title> + + <para>Basic usage of <hbm2hbmxml></para> + + <programlisting><![CDATA[<hibernatetool destdir="${build.dir}/generated"> + <configuration configurationfile="hibernate.cfg.xml"/> + <hbm2hbmxml/> +</hibernatetool>]]></programlisting> + + <para><hbm2hbmxml> is normally used with a + <jdbcconfiguration> like in the above example, but any other + configuration can also be used to convert between the different ways + of performing mappings. Here is an example of that, using an + <annotationconfiguration>. Note: not all conversions is + implemented (contributions welcome), so some hand editing might be + necessary.</para> + + <para><programlisting><![CDATA[<hibernatetool destdir="${build.dir}/generated"> + <annotaitonconfiguration configurationfile="hibernate.cfg.xml"/> + <hbm2hbmxml/> +</hibernatetool>]]></programlisting></para> + </section> </section> <section> @@ -280,14 +607,26 @@ used together with a <jdbcconfiguration> when performing reverse engineering, but can be used with any kind of configuration. The <hbm2cfgxml> will contain the properties used and adds mapping - entriies for each mapped class.</para> + entries for each mapped class.</para> - <programlisting><![CDATA[<hbm2cfgxml + <para><programlistingco> + <areaspec> + <area coords="2 55" id="cfg1" /> + </areaspec> + + <programlisting><![CDATA[<hbm2cfgxml ejb3="true|false" /> ]]></programlisting> - <para></para> + <calloutlist> + <callout arearefs="cfg1"> + <para>ejb3 (default: false): the generated cfg.xml will have + <mapping class=".."/>, opposed to <mapping + resource="..."/> for each mapping.</para> + </callout> + </calloutlist> + </programlistingco></para> </section> <section> @@ -298,8 +637,52 @@ the database schema et.al.</para> <programlisting><![CDATA[<hbm2doc/>]]></programlisting> + </section> + <section> + <title>Query exporter (<query>)</title> + + <para><query> is used to execute a HQL query statements and + optionally send the output to a file. Can be used for verifying the + mappings and for basic data extraction.</para> + + <programlisting><![CDATA[<query + destfile="filename"> + <hql>[a HQL query string]</hql> +</query> +]]></programlisting> + + <para>Currently one session is opened and used for all queries and the + query is executed via the list() method. In the future more options + might become available, like performing executeUpdate(), use named + queries etc.</para> + <para></para> + + <section> + <title>Examples</title> + + <para>Simplest usage of <query> will just execute the query + without dumping to a file. This can be used to verify that queries + can actually be performed.</para> + + <programlisting><![CDATA[<hibernatetool> + <configuration configurationfile="hibernate.cfg.xml"/> + <query>from java.lang.Object</query> +</hibernatetool>]]></programlisting> + + <para>Multiple queries can be executed by nested <hql> + elements. In this example we also let the output be dumped to + <literal>queryresult.txt</literal>. Note that currently the dump is + simply a call to toString on each element.</para> + + <para><programlisting><![CDATA[<hibernatetool> + <configuration configurationfile="hibernate.cfg.xml"/> + <query destfile="queryresult.txt"> + <hql>select c.name from Customer c where c.age > 42</hql> + <hql>from Cat</hql> +</hibernatetool>]]></programlisting></para> + </section> </section> <section id="hbmtemplate"> @@ -310,13 +693,14 @@ template or class.</para> <programlisting><![CDATA[<hbmtemplate - filepattern="{package-name}/{class-name}.vm" - template="somename.vm" + filepattern="{package-name}/{class-name}.ftl" + template="somename.ftl" exporterclass="Exporter classname" />]]></programlisting> - <para>NOTICE: This release uses Velocity for the templates. The next - release might move to an alternative template engine.</para> + <para>NOTICE: Previous versions of the tools used Velocity. We are now + using Freemarker which provides us much better exception and error + handling.</para> <section> <title>Seam Exporter via @@ -328,13 +712,17 @@ generate a Seam application skeleton.</para> <para><programlisting><![CDATA[ <hibernatetool destdir="${destdir}"> - <jdbcconfiguration configurationfile="hibernate.cfg.xml" packagename="x.y.z.seam.crud"/> + <jdbcconfiguration + configurationfile="hibernate.cfg.xml" + packagename="x.y.z.seam.crud"/> <!-- setup properties --> <property key="seam_appname" value="Registration"/> <property key="seam_shortname" value="crud"/> - <hbmtemplate exporterclass="org.hibernate.tool.hbm2x.seam.SeamExporter" filepattern="."/> + <hbmtemplate + exporterclass="org.hibernate.tool.hbm2x.seam.SeamExporter" + filepattern="."/> </hibernatetool> ]]></programlisting></para> @@ -351,8 +739,6 @@ access to them directly in the templates and via <literal>Exporter.setProperties()</literal>.</para> - <para></para> - <section> <title><literal><property></literal> and <literal><propertyset></literal></title> @@ -388,7 +774,27 @@ delegate logic and code generation to java code instead of placing such logic in the templates.</para> - <para></para> + <section> + <title>Example</title> + + <para>Here is an example that uses <hbmtemplate> together with + <property> which will be available to the templates/exporter. + Note: This example actually simulates what <hbm2java> actually + does.</para> + + <programlisting><![CDATA[<hibernatetool destdir="${build.dir}/generated"> +<configuration + configurationfile="etc/hibernate.cfg.xml"/> + <hbmtemplate + templateprefix="pojo/" + template="pojo/Pojo.ftl" + filepattern="{package-name}/{class-name}.java"> + <property key="jdk5" value="true" /> + <property key="ejb3" value="true" /> + </hbmtemplate> +</hibernatetool> +]]></programlisting> + </section> </section> </section> </section> Deleted: trunk/HibernateExt/tools/src/java/org/hibernate/tool/ant/HQLExporterTask.java =================================================================== --- trunk/HibernateExt/tools/src/java/org/hibernate/tool/ant/HQLExporterTask.java 2006-04-20 21:35:09 UTC (rev 9776) +++ trunk/HibernateExt/tools/src/java/org/hibernate/tool/ant/HQLExporterTask.java 2006-04-21 19:03:03 UTC (rev 9777) @@ -1,45 +0,0 @@ -package org.hibernate.tool.ant; - -import org.hibernate.tool.hbm2x.Exporter; -import org.hibernate.tool.hbm2x.HQLExporter; - -public class HQLExporterTask extends ExporterTask { - - private String query; - private String filename; - - public HQLExporterTask(HibernateToolTask parent) { - super( parent ); - } - - protected Exporter configureExporter(Exporter exp) { - HQLExporter exporter = (HQLExporter) exp; - exporter.setQuery(query); - exporter.setFilename(filename); - super.configureExporter( exp ); - return exporter; - } - - protected Exporter createExporter() { - HQLExporter exporter = new HQLExporter(); - return exporter; - } - - public void addText(String text) { - query = text; - } - - public void setDestFile(String filename) { - this.filename = filename; - } - - public void execute() { - parent.log("Executing: [" + query + "]"); - super.execute(); - } - public String getName() { - return "hql (Executes HQL queries)"; - } - - -} Modified: trunk/HibernateExt/tools/src/java/org/hibernate/tool/ant/HibernateToolTask.java =================================================================== --- trunk/HibernateExt/tools/src/java/org/hibernate/tool/ant/HibernateToolTask.java 2006-04-20 21:35:09 UTC (rev 9776) +++ trunk/HibernateExt/tools/src/java/org/hibernate/tool/ant/HibernateToolTask.java 2006-04-21 19:03:03 UTC (rev 9777) @@ -114,8 +114,8 @@ } - public HQLExporterTask createHql() { - HQLExporterTask generator = new HQLExporterTask(this); + public QueryExporterTask createQuery() { + QueryExporterTask generator = new QueryExporterTask(this); generators.add(generator); return generator; } @@ -147,18 +147,20 @@ Iterator iterator = generators.iterator(); AntClassLoader loader = getProject().createClassLoader(classPath); + ExporterTask generatorTask = null; + int count = 1; try { loader.setParent(this.getClass().getClassLoader() ); // if this is not set, classes from the taskdef cannot be found - which is crucial for e.g. annotations. loader.setThreadContextLoader(); - int count = 1; - while (iterator.hasNext() ) { - ExporterTask generatorTask = (ExporterTask) iterator.next(); + + while (iterator.hasNext() ) { + generatorTask = (ExporterTask) iterator.next(); log(count++ + ". task: " + generatorTask.getName() ); generatorTask.execute(); } } catch (RuntimeException re) { - reportException(re); + reportException(re, count, generatorTask); } finally { if (loader != null) { @@ -168,8 +170,9 @@ } } - private void reportException(Throwable re) { - log("An exception occurred. To get the full stack trace run ant with -verbose", Project.MSG_ERR); + private void reportException(Throwable re, int count, ExporterTask generatorTask) { + log("An exception occurred while running exporter #" + count + ":" + generatorTask.getName(), Project.MSG_ERR); + log("To get the full stack trace run ant with -verbose", Project.MSG_ERR); log(re.toString(), Project.MSG_ERR); String ex = new String(); Throwable cause = re.getCause(); Copied: trunk/HibernateExt/tools/src/java/org/hibernate/tool/ant/QueryExporterTask.java (from rev 9763, trunk/HibernateExt/tools/src/java/org/hibernate/tool/ant/HQLExporterTask.java) =================================================================== --- trunk/HibernateExt/tools/src/java/org/hibernate/tool/ant/HQLExporterTask.java 2006-04-19 00:36:18 UTC (rev 9763) +++ trunk/HibernateExt/tools/src/java/org/hibernate/tool/ant/QueryExporterTask.java 2006-04-21 19:03:03 UTC (rev 9777) @@ -0,0 +1,96 @@ +package org.hibernate.tool.ant; + +import java.util.ArrayList; +import java.util.Iterator; +import java.util.List; + +import org.apache.tools.ant.BuildException; +import org.hibernate.tool.hbm2x.Exporter; +import org.hibernate.tool.hbm2x.QueryExporter; +import org.hibernate.util.StringHelper; + +public class QueryExporterTask extends ExporterTask { + + private String query = ""; + private String filename; + List queries = new ArrayList(); + + public QueryExporterTask(HibernateToolTask parent) { + super( parent ); + } + + protected Exporter configureExporter(Exporter exp) { + QueryExporter exporter = (QueryExporter) exp; + List queryStrings = new ArrayList(); + if(StringHelper.isNotEmpty(query)) { + queryStrings.add(query); + } + for (Iterator iter = queries.iterator(); iter.hasNext();) { + HQL hql = (HQL) iter.next(); + if(StringHelper.isNotEmpty(hql.query)) { + queryStrings.add(query); + } + } + exporter.setQueries(queryStrings); + exporter.setFilename(filename); + super.configureExporter( exp ); + return exporter; + } + + public void validateParameters() { + super.validateParameters(); + if(StringHelper.isEmpty(query) && queries.isEmpty()) { + throw new BuildException("Need to specify at least one query."); + } + + for (Iterator iter = queries.iterator(); iter.hasNext();) { + HQL hql = (HQL) iter.next(); + if(StringHelper.isEmpty(hql.query)) { + throw new BuildException("Query must not be empty"); + } + } + } + protected Exporter createExporter() { + QueryExporter exporter = new QueryExporter(); + return exporter; + } + + public void addText(String text) { + if(StringHelper.isNotEmpty(text)) { + query += trim(text); + } + } + + static private String trim(String text) { + return text.trim(); + } + + public static class HQL { + String query = ""; + public void addText(String text) { + if(StringHelper.isNotEmpty(text)) { + query += trim(text); + } + } + } + + public HQL createHql() { + HQL hql = new HQL(); + queries.add(hql); + return hql; + } + + public void setDestFile(String filename) { + this.filename = filename; + } + + public void execute() { + parent.log("Executing: [" + query + "]"); + super.execute(); + } + public String getName() { + return "query (Executes queries)"; + } + + +} Deleted: trunk/HibernateExt/tools/src/java/org/hibernate/tool/hbm2x/HQLExporter.java =================================================================== --- trunk/HibernateExt/tools/src/java/org/hibernate/tool/hbm2x/HQLExporter.java 2006-04-20 21:35:09 UTC (rev 9776) +++ trunk/HibernateExt/tools/src/java/org/hibernate/tool/hbm2x/HQLExporter.java 2006-04-21 19:03:03 UTC (rev 9777) @@ -1,76 +0,0 @@ -package org.hibernate.tool.hbm2x; - -import java.io.File; -import java.io.FileWriter; -import java.io.IOException; -import java.io.PrintWriter; -import java.util.Iterator; -import java.util.List; - -import org.hibernate.SessionFactory; -import org.hibernate.classic.Session; - -/** - * Placeholder exporter for query execution. - * - **/ -public class HQLExporter extends AbstractExporter { - - private String query; - private String filename; - - public void doStart() { - Session session = null; - SessionFactory sessionFactory = null; - try { - sessionFactory = getConfiguration().buildSessionFactory(); - session = sessionFactory.openSession(); - - List list = session.createQuery(getQuery()).list(); - - if(getFileName()!=null) { - PrintWriter pw = null; - try { - File file = new File( getOutputDirectory(), getFileName() ); - getTemplateHelper().ensureExistence( file ); - pw = new PrintWriter( new FileWriter( file, true ) ); - getArtifactCollector().addFile( file, "query-output" ); - - for (Iterator iter = list.iterator(); iter.hasNext();) { - Object element = iter.next(); - pw.println(element); - } - - } - catch (IOException e) { - throw new ExporterException("Could not write query output",e); - } finally { - if(pw!=null) { - pw.flush(); - pw.close(); - } - } - } - } finally { - session.close(); - session.getSessionFactory().close(); - } - } - - private String getFileName() { - return filename; - } - - public void setFilename(String filename) { - this.filename = filename; - } - - private String getQuery() { - return query; - } - - public void setQuery(String query) { - this.query = query; - } - -} Copied: trunk/HibernateExt/tools/src/java/org/hibernate/tool/hbm2x/QueryExporter.java (from rev 9763, trunk/HibernateExt/tools/src/java/org/hibernate/tool/hbm2x/HQLExporter.java) =================================================================== --- trunk/HibernateExt/tools/src/java/org/hibernate/tool/hbm2x/HQLExporter.java 2006-04-19 00:36:18 UTC (rev 9763) +++ trunk/HibernateExt/tools/src/java/org/hibernate/tool/hbm2x/QueryExporter.java 2006-04-21 19:03:03 UTC (rev 9777) @@ -0,0 +1,84 @@ +package org.hibernate.tool.hbm2x; + +import java.io.File; +import java.io.FileWriter; +import java.io.IOException; +import java.io.PrintWriter; +import java.util.Iterator; +import java.util.List; + +import org.hibernate.HibernateException; +import org.hibernate.SessionFactory; +import org.hibernate.Transaction; +import org.hibernate.classic.Session; + +/** + * Placeholder exporter for query execution. + * + **/ +public class QueryExporter extends AbstractExporter { + + private String filename; + private List queryStrings; + + public void doStart() { + Session session = null; + SessionFactory sessionFactory = null; + Transaction transaction = null; + try { + sessionFactory = getConfiguration().buildSessionFactory(); + session = sessionFactory.openSession(); + transaction = session.beginTransaction(); + // TODO: this is not the most efficient loop (opening/closing file) + for (Iterator iter = queryStrings.iterator(); iter.hasNext();) { + String query = (String) iter.next(); + + List list = session.createQuery(query).list(); + + if(getFileName()!=null) { + PrintWriter pw = null; + try { + File file = new File( getOutputDirectory(), getFileName() ); + getTemplateHelper().ensureExistence( file ); + pw = new PrintWriter( new FileWriter( file, true ) ); + getArtifactCollector().addFile( file, "query-output" ); + + for (Iterator iter1 = list.iterator(); iter1.hasNext();) { + Object element = iter.next(); + pw.println(element); + } + + } + catch (IOException e) { + throw new ExporterException("Could not write query output",e); + } finally { + if(pw!=null) { + pw.flush(); + pw.close(); + } + } + } + } + transaction.commit(); + } catch(HibernateException he) { + if(transaction!=null) transaction.rollback(); + } finally { + session.close(); + session.getSessionFactory().close(); + + } + } + + private String getFileName() { + return filename; + } + + public void setFilename(String filename) { + this.filename = filename; + } + + public void setQueries(List queryStrings) { + this.queryStrings = queryStrings; + } + +} Modified: trunk/HibernateExt/tools/src/java/org/hibernate/tool/hbm2x/pojo/ComponentPOJOClass.java =================================================================== --- trunk/HibernateExt/tools/src/java/org/hibernate/tool/hbm2x/pojo/ComponentPOJOClass.java 2006-04-20 21:35:09 UTC (rev 9776) +++ trunk/HibernateExt/tools/src/java/org/hibernate/tool/hbm2x/pojo/ComponentPOJOClass.java 2006-04-21 19:03:03 UTC (rev 9777) @@ -88,15 +88,15 @@ } public String generateBasicAnnotation(Property property) { - return null; + return ""; } public String generateAnnIdGenerator() { - return null; + return ""; } public String generateAnnTableUniqueConstraint() { - return null; + return ""; } public Object getDecoratedObject() { Modified: trunk/HibernateExt/tools/src/testsupport/anttest-build.xml =================================================================== --- trunk/HibernateExt/tools/src/testsupport/anttest-build.xml 2006-04-20 21:35:09 UTC (rev 9776) +++ trunk/HibernateExt/tools/src/testsupport/anttest-build.xml 2006-04-21 19:03:03 UTC (rev 9777) @@ -334,9 +334,11 @@ <taskdef name="hibernatetool" classname="org.hibernate.tool.ant.HibernateToolTask" classpathref="tasks.classpath" /> <hibernatetool destdir="${build.dir}/querytest"> <configuration propertyfile="../../etc/hibernate.properties" configurationfile="querytest-hibernate.cfg.xml" /> - <hql>from java.lang.Object</hql> - <hql>from java.io.Serializable</hql> - <hql destfile="queryresult.txt">from java.io.Serializable</hql> + <query> + <hql>from java.lang.Object</hql> + <hql>from java.io.Serializable</hql> + </query> + <query destfile="queryresult.txt">from java.io.Serializable</query> </hibernatetool> </target> </project> |
From: <hib...@li...> - 2006-04-20 21:35:27
|
Author: ste...@jb... Date: 2006-04-20 17:35:09 -0400 (Thu, 20 Apr 2006) New Revision: 9776 Modified: branches/HQL_ANTLR_2/Hibernate3/test/org/hibernate/test/hql/HqlResolverTest.java Log: refactor to PersisterReference stuff Modified: branches/HQL_ANTLR_2/Hibernate3/test/org/hibernate/test/hql/HqlResolverTest.java =================================================================== --- branches/HQL_ANTLR_2/Hibernate3/test/org/hibernate/test/hql/HqlResolverTest.java 2006-04-20 21:32:07 UTC (rev 9775) +++ branches/HQL_ANTLR_2/Hibernate3/test/org/hibernate/test/hql/HqlResolverTest.java 2006-04-20 21:35:09 UTC (rev 9776) @@ -8,7 +8,6 @@ import org.hibernate.hql.antlr.HqlRTokenTypes; import org.hibernate.hql.ast.resolve.HqlResolver; import org.hibernate.hql.ast.resolve.StatementNode; -import org.hibernate.hql.ast.resolve.ResolverContextImpl; import org.hibernate.hql.ast.util.ASTPrinter; import org.hibernate.test.TestCase; import org.hibernate.engine.SessionFactoryImplementor; @@ -34,6 +33,10 @@ assertTrue(ast instanceof StatementNode); } + public void testSelectExpression() throws Throwable { + resolve( "select a from Animal a" ); + } + public void testSimpleImplicitJoin() throws Exception { AST ast = resolve("from Animal a where a.mother.name like '%mary%'"); // The root node should be a statement. @@ -44,13 +47,23 @@ assertTrue(ast instanceof StatementNode); } + public void testUnqualifiedPropertyReference() throws Exception { + AST ast = resolve("from Animal where name like '%mary%'"); + // The root node should be a statement. + assertTrue(ast instanceof StatementNode); + } + + public void testThetaJoins() throws Exception { + AST ast = resolve( "from Animal a, Animal b where a.mother.id = b.id and b.name like '%mary%'" ); + // The root node should be a statement. + assertTrue(ast instanceof StatementNode); + } + private AST resolve(String hql) throws RecognitionException, TokenStreamException { AST hqlAst = HqlParserTest.doParse(hql,false); // Now, pass it though the resolver phase, which yeilds // a processed HQL AST. - HqlResolver resolver = new HqlResolver(); - ResolverContextImpl context = new ResolverContextImpl(getSessionFactoryImplementor()); - resolver.initialize(context); // Give the resolver a fake context. + HqlResolver resolver = new HqlResolver( getSessionFactoryImplementor() ); resolver.statement(hqlAst); AST resolvedHql = resolver.getAST(); System.out.println(hqlrPrinter.showAsString(resolvedHql, |
From: <hib...@li...> - 2006-04-20 21:33:40
|
Author: ste...@jb... Date: 2006-04-20 17:32:07 -0400 (Thu, 20 Apr 2006) New Revision: 9775 Removed: branches/HQL_ANTLR_2/Hibernate3/src/org/hibernate/hql/ast/tree/EntityPersisterReference.java branches/HQL_ANTLR_2/Hibernate3/src/org/hibernate/hql/ast/tree/JoinNode.java branches/HQL_ANTLR_2/Hibernate3/src/org/hibernate/hql/ast/tree/JoinSource.java branches/HQL_ANTLR_2/Hibernate3/src/org/hibernate/hql/ast/tree/JoinType.java branches/HQL_ANTLR_2/Hibernate3/src/org/hibernate/hql/ast/tree/PersisterReference.java branches/HQL_ANTLR_2/Hibernate3/src/org/hibernate/hql/ast/tree/PropertyReference.java Log: refactor to PersisterReference stuff Deleted: branches/HQL_ANTLR_2/Hibernate3/src/org/hibernate/hql/ast/tree/EntityPersisterReference.java =================================================================== --- branches/HQL_ANTLR_2/Hibernate3/src/org/hibernate/hql/ast/tree/EntityPersisterReference.java 2006-04-20 21:31:04 UTC (rev 9774) +++ branches/HQL_ANTLR_2/Hibernate3/src/org/hibernate/hql/ast/tree/EntityPersisterReference.java 2006-04-20 21:32:07 UTC (rev 9775) @@ -1,40 +0,0 @@ -package org.hibernate.hql.ast.tree; - -import org.hibernate.type.AssociationType; -import org.hibernate.persister.entity.Queryable; - -/** - * @author Steve Ebersole - */ -public class EntityPersisterReference extends Node implements PersisterReference { - private String entityName; - private String alias; - private Queryable persister; - - public void initialize(String entityName, String alias) { - // todo : would much prefer this stuff to be constructor injection... - // todo : need a SF reference to resolve the persister... - this.entityName = entityName; - this.alias = alias; - } - - public String getName() { - return alias == null ? entityName : entityName + " (" + alias + ")"; - } - - public String getAlias() { - return alias; - } - - public AssociationType getPersisterType() { - return ( AssociationType ) persister.getType(); - } - - public PropertyReference retrievePropertyReference(String propertyName) { - return null; - } - - public String getDisplayText() { - return null; - } -} Deleted: branches/HQL_ANTLR_2/Hibernate3/src/org/hibernate/hql/ast/tree/JoinNode.java =================================================================== --- branches/HQL_ANTLR_2/Hibernate3/src/org/hibernate/hql/ast/tree/JoinNode.java 2006-04-20 21:31:04 UTC (rev 9774) +++ branches/HQL_ANTLR_2/Hibernate3/src/org/hibernate/hql/ast/tree/JoinNode.java 2006-04-20 21:32:07 UTC (rev 9775) @@ -1,58 +0,0 @@ -package org.hibernate.hql.ast.tree; - -import antlr.Token; - -/** - * Represents an HQL join. The coneptualization here is strictly that of - * the join in terms of the context of the HQL query which may or may not have - * direct correlation to any SQL join. - * - * @author Steve Ebersole - */ -public class JoinNode extends Node { - - // todo : we need to decide the tree structure of a join subtree. - // based on that decision, we may need to have references here - // to both the left-hand and right-hand persister references - - private JoinType joinType; - private JoinSource source; - private boolean fetch; - - public JoinNode() { - } - - public JoinNode(Token tok) { - super( tok ); - } - - public JoinNode(JoinType joinType, JoinSource source, boolean fetch) { - this.joinType = joinType; - this.source = source; - this.fetch = fetch; - } - - public JoinType getJoinType() { - return joinType; - } - - public void setJoinType(JoinType joinType) { - this.joinType = joinType; - } - - public JoinSource getSource() { - return source; - } - - public void setSource(JoinSource source) { - this.source = source; - } - - public boolean isFetch() { - return fetch; - } - - public void setFetch(boolean fetch) { - this.fetch = fetch; - } -} Deleted: branches/HQL_ANTLR_2/Hibernate3/src/org/hibernate/hql/ast/tree/JoinSource.java =================================================================== --- branches/HQL_ANTLR_2/Hibernate3/src/org/hibernate/hql/ast/tree/JoinSource.java 2006-04-20 21:31:04 UTC (rev 9774) +++ branches/HQL_ANTLR_2/Hibernate3/src/org/hibernate/hql/ast/tree/JoinSource.java 2006-04-20 21:32:07 UTC (rev 9775) @@ -1,52 +0,0 @@ -package org.hibernate.hql.ast.tree; - -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" ); - - 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 ); - } - - 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/tree/JoinType.java =================================================================== --- branches/HQL_ANTLR_2/Hibernate3/src/org/hibernate/hql/ast/tree/JoinType.java 2006-04-20 21:31:04 UTC (rev 9774) +++ branches/HQL_ANTLR_2/Hibernate3/src/org/hibernate/hql/ast/tree/JoinType.java 2006-04-20 21:32:07 UTC (rev 9775) @@ -1,62 +0,0 @@ -package org.hibernate.hql.ast.tree; - -import java.io.Serializable; -import java.util.HashMap; - -/** - * Represents a canonical join type. - * <p/> - * Note that currently HQL really only supports inner and left outer joins - * (though cross joins can also be achieved). This is because joins in HQL - * are always defined in relation to a mapped association. However, when we - * start allowing users to specify ad-hoc joins this may need to change to - * allow the full spectrum of join types. Thus the others are provided here - * currently just for completeness and for future expansion. - * - * @author Steve Ebersole - */ -public class JoinType implements Serializable { - /** - * Represents an inner join. - */ - public static final JoinType INNER = new JoinType( "inner" ); - /** - * Represents a left outer join. - */ - public static final JoinType LEFT = new JoinType( "left outer" ); - /** - * Represents a right outer join. - */ - public static final JoinType RIGHT = new JoinType( "right outer" ); - /** - * Represents a cross join (aka a cartesian product). - */ - public static final JoinType CROSS = new JoinType( "cross" ); - /** - * Represents a full join. - */ - public static final JoinType FULL = new JoinType( "full" ); - - private static final HashMap INSTANCES = new HashMap(); - static { - INSTANCES.put( INNER.name, INNER ); - INSTANCES.put( LEFT.name, LEFT ); - INSTANCES.put( RIGHT.name, RIGHT ); - INSTANCES.put( CROSS.name, CROSS ); - INSTANCES.put( FULL.name, FULL ); - } - - private final String name; - - private JoinType(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/tree/PersisterReference.java =================================================================== --- branches/HQL_ANTLR_2/Hibernate3/src/org/hibernate/hql/ast/tree/PersisterReference.java 2006-04-20 21:31:04 UTC (rev 9774) +++ branches/HQL_ANTLR_2/Hibernate3/src/org/hibernate/hql/ast/tree/PersisterReference.java 2006-04-20 21:32:07 UTC (rev 9775) @@ -1,17 +0,0 @@ -package org.hibernate.hql.ast.tree; - -import org.hibernate.type.AssociationType; - -/** - * Represents a reference to a persister (either entity or collection) within - * an HQL statement. - * - * @author Steve Ebersole - */ -public interface PersisterReference extends DisplayableNode { - public String getName(); - public String getAlias(); - public AssociationType getPersisterType(); - - public PropertyReference retrievePropertyReference(String propertyName); -} Deleted: branches/HQL_ANTLR_2/Hibernate3/src/org/hibernate/hql/ast/tree/PropertyReference.java =================================================================== --- branches/HQL_ANTLR_2/Hibernate3/src/org/hibernate/hql/ast/tree/PropertyReference.java 2006-04-20 21:31:04 UTC (rev 9774) +++ branches/HQL_ANTLR_2/Hibernate3/src/org/hibernate/hql/ast/tree/PropertyReference.java 2006-04-20 21:32:07 UTC (rev 9775) @@ -1,15 +0,0 @@ -package org.hibernate.hql.ast.tree; - -import org.hibernate.type.Type; - -/** - * Represents a reference to a particular persister-managed property; also - * some special cases such as a collection property reference (e.g., size). - * - * @author Steve Ebersole - */ -public interface PropertyReference extends DisplayableNode { - public String getPropertyName(); - public Type getPropertyType(); - public PersisterReference getPersisterReference(); -} |
From: <hib...@li...> - 2006-04-20 21:31:21
|
Author: ste...@jb... Date: 2006-04-20 17:31:04 -0400 (Thu, 20 Apr 2006) New Revision: 9774 Modified: branches/HQL_ANTLR_2/Hibernate3/grammar/hql-resolve.g Log: refactor to PersisterReference stuff Modified: branches/HQL_ANTLR_2/Hibernate3/grammar/hql-resolve.g =================================================================== --- branches/HQL_ANTLR_2/Hibernate3/grammar/hql-resolve.g 2006-04-20 21:26:31 UTC (rev 9773) +++ branches/HQL_ANTLR_2/Hibernate3/grammar/hql-resolve.g 2006-04-20 21:31:04 UTC (rev 9774) @@ -33,6 +33,8 @@ tokens { PROPERTY_REF; + ENTITY_PERSISTER_REF; + COLLECTION_PERSISTER_REF; BOGUS; } @@ -49,6 +51,25 @@ protected void defineRange(AST range,String path,AST alias, AST fetch) { } + protected AST buildEntityPersisterReference(String entityName, AST alias) { + return null; + } + + protected AST buildThetaJoinNode(AST persisterReference) { + return null; + } + + protected AST buildExplicitPropertyJoinNode(AST propertyReference, AST alias, AST joinType, AST fetch, AST propertyFetch, AST withClause) { + return null; + } + + protected AST buildAdHocJoinNode(AST persisterReference, AST joinType, AST onClause) { + return null; + } + + protected boolean isEntityName(String test) { + return false; + } } // The main statement rule. @@ -97,35 +118,55 @@ // -- Language sub-elements -- + fromClause - : #(f:FROM { pushContext(#fromClause,f); } ( range | join | filter ) * ) +// : #( f:FROM { pushContext(#fromClause, f); } entityPersisterReference ( thetaJoin | explicitJoin )* ) + : #( f:FROM { pushContext(#fromClause, f); } range ( thetaJoin | explicitJoin )* ) ; -// Antlr note: The '!' prevents the automatic creation of the output AST, so the semantic action can do it. -range - { - String p = ""; +range! + : #( RANGE e:entityPersisterReference) { + #range = #e; } - : #(RANGE p=pathAsString! (a:ALIAS!)? (f:FETCH!)? ) - { - defineRange(#range,p,a,f); // Set up the output tree. + ; + +entityPersisterReference! { + String p = ""; } + : p=pathAsString! (a:ALIAS!)? { + #entityPersisterReference = buildEntityPersisterReference( p, a ); + } ; -join - : #(JOIN (joinType )? (FETCH)? propertyRef [true] (ALIAS)? (FETCH)? (WITH)? ) +thetaJoin! +// : #( COMMA e:entityPersisterReference ) { +// #thetaJoin = buildThetaJoinNode( e ); +// } + : r:range { + #thetaJoin = buildThetaJoinNode( #r ); + } ; +explicitJoin! + : #(JOIN (jt:joinType)? joinRhs[jt] ) + ; + +joinRhs [AST joinType] + : { isEntityName( pathAsString( _t ) ) }? e:entityPersisterReference (on:ON)? { + buildAdHocJoinNode( #e, joinType, on ); + } + | (f:FETCH)? ref:propertyRef[true] (a:ALIAS)? (pf:FETCH)? (with:WITH)? { + buildExplicitPropertyJoinNode( #ref, a, joinType, f, pf, with ); + } + ; + +// TODO : need to add cross joins joinType : ( (LEFT | RIGHT) (OUTER)? ) | FULL | INNER ; -filter - : fe:FILTER_ENTITY a:ALIAS - ; - intoClause : #(i:INTO { pushContext(#intoClause,i); } (subtree)* ) ; |
From: <hib...@li...> - 2006-04-20 21:29:22
|
Author: ste...@jb... Date: 2006-04-20 17:26:31 -0400 (Thu, 20 Apr 2006) New Revision: 9773 Added: branches/HQL_ANTLR_2/Hibernate3/src/org/hibernate/hql/ast/resolve/CollectionPersisterReference.java branches/HQL_ANTLR_2/Hibernate3/src/org/hibernate/hql/ast/resolve/EntityPersisterReference.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/JoinSource.java branches/HQL_ANTLR_2/Hibernate3/src/org/hibernate/hql/ast/resolve/JoinType.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/PropertyReference.java branches/HQL_ANTLR_2/Hibernate3/src/org/hibernate/hql/ast/resolve/SessionFactoryAwareNode.java 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/HqlResolverASTFactory.java branches/HQL_ANTLR_2/Hibernate3/src/org/hibernate/hql/ast/resolve/RangeNode.java branches/HQL_ANTLR_2/Hibernate3/src/org/hibernate/hql/ast/resolve/ResolverContext.java branches/HQL_ANTLR_2/Hibernate3/src/org/hibernate/hql/ast/resolve/ResolverContextImpl.java Log: refactor to PersisterReference stuff Added: branches/HQL_ANTLR_2/Hibernate3/src/org/hibernate/hql/ast/resolve/CollectionPersisterReference.java =================================================================== --- branches/HQL_ANTLR_2/Hibernate3/src/org/hibernate/hql/ast/resolve/CollectionPersisterReference.java 2006-04-20 17:43:46 UTC (rev 9772) +++ branches/HQL_ANTLR_2/Hibernate3/src/org/hibernate/hql/ast/resolve/CollectionPersisterReference.java 2006-04-20 21:26:31 UTC (rev 9773) @@ -0,0 +1,34 @@ +package org.hibernate.hql.ast.resolve; + +import org.hibernate.type.AssociationType; +import org.hibernate.hql.ast.tree.Node; + +/** + * @author Steve Ebersole + */ +public class CollectionPersisterReference extends Node implements PersisterReference { + // TODO : implement + public String getName() { + return null; //To change body of implemented methods use File | Settings | File Templates. + } + + public String getAlias() { + return null; //To change body of implemented methods use File | Settings | File Templates. + } + + public AssociationType getPersisterType() { + return null; //To change body of implemented methods use File | Settings | File Templates. + } + + public boolean containsProperty(String propertyName) { + return false; //To change body of implemented methods use File | Settings | File Templates. + } + + public PropertyReference retrievePropertyReference(String propertyName) { + return null; //To change body of implemented methods use File | Settings | File Templates. + } + + public String getDisplayText() { + return null; //To change body of implemented methods use File | Settings | File Templates. + } +} Copied: branches/HQL_ANTLR_2/Hibernate3/src/org/hibernate/hql/ast/resolve/EntityPersisterReference.java (from rev 9747, branches/HQL_ANTLR_2/Hibernate3/src/org/hibernate/hql/ast/tree/EntityPersisterReference.java) =================================================================== --- branches/HQL_ANTLR_2/Hibernate3/src/org/hibernate/hql/ast/tree/EntityPersisterReference.java 2006-04-13 12:14:07 UTC (rev 9747) +++ branches/HQL_ANTLR_2/Hibernate3/src/org/hibernate/hql/ast/resolve/EntityPersisterReference.java 2006-04-20 21:26:31 UTC (rev 9773) @@ -0,0 +1,74 @@ +package org.hibernate.hql.ast.resolve; + +import org.hibernate.type.AssociationType; +import org.hibernate.persister.entity.Queryable; +import org.hibernate.hql.antlr.HqlRTokenTypes; +import org.hibernate.hql.ast.tree.Node; +import org.hibernate.engine.SessionFactoryImplementor; + +/** + * @author Steve Ebersole + */ +public class EntityPersisterReference extends Node implements PersisterReference, SessionFactoryAwareNode { + private String entityName; + private String alias; + private SessionFactoryImplementor sessionFactory; + private transient Queryable persister; + + public EntityPersisterReference() { + super(); + super.setType( HqlRTokenTypes.ENTITY_PERSISTER_REF ); + } + + public void initialize(String entityName, String alias) { + this.entityName = entityName; + this.alias = alias; + } + + public Queryable getPersister() { + if ( persister == null ) { + persister = ( Queryable ) sessionFactory.getEntityPersister( entityName ); + } + return persister; + } + + public String getName() { + return alias == null ? entityName : entityName + " (" + alias + ")"; + } + + public String getAlias() { + return alias; + } + + public AssociationType getPersisterType() { + return ( AssociationType ) persister.getType(); + } + + public boolean containsProperty(String propertyName) { + try { + return persister.getPropertyType( propertyName ) != null; + } + catch( Throwable t ) { + return false; + } + } + + public PropertyReference retrievePropertyReference(String propertyName) { + return null; + } + + public String getDisplayText() { + return "{" + + "entityName='" + entityName + '\'' + + ", alias='" + alias + '\'' + + '}'; + } + + public String toString() { + return "EntityPersisterReference" + getDisplayText(); + } + + public void setSessionFactory(SessionFactoryImplementor sessionFactory) { + this.sessionFactory = sessionFactory; + } +} 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-04-20 17:43:46 UTC (rev 9772) +++ branches/HQL_ANTLR_2/Hibernate3/src/org/hibernate/hql/ast/resolve/HqlResolver.java 2006-04-20 21:26:31 UTC (rev 9773) @@ -1,6 +1,8 @@ package org.hibernate.hql.ast.resolve; import org.hibernate.hql.antlr.HqlBaseResolver; +import org.hibernate.engine.SessionFactoryImplementor; +import org.hibernate.QueryException; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; @@ -18,14 +20,18 @@ public class HqlResolver extends HqlBaseResolver { private static Log log = LogFactory.getLog( HqlResolver.class ); + private final SessionFactoryImplementor sessionFactory; + private final ResolverContext resolverContext; + private int level = 0; private List inputContext = new ArrayList(); private List outputContext = new ArrayList(); - private ResolverContext context; // Provides acces to the session factory via an interface. - public HqlResolver() { + public HqlResolver(SessionFactoryImplementor sessionFactory) { super(); - setASTFactory(new HqlResolverASTFactory()); // Create nodes that track line and column number. + this.sessionFactory = sessionFactory; + setASTFactory( new HqlResolverASTFactory( sessionFactory ) ); + this.resolverContext = new ResolverContextImpl( sessionFactory, getASTFactory() ); } @@ -57,12 +63,74 @@ protected void defineRange(AST range, String path, AST alias, AST fetch) { RangeNode r = (RangeNode) range; r.setPath(path); - r.setPersister(context.lookupPersister(path)); + r.setPersisterReference( resolverContext.getEntityPersisterReference( path, alias == null ? null : alias.getText() ) ); r.setFetch(fetch != null); r.setAlias(alias != null ? alias.getText() : null); } - public void initialize(ResolverContext resolverContext) { - context = resolverContext; + protected AST buildEntityPersisterReference(String entityName, AST alias) { + return resolverContext.getEntityPersisterReference( entityName, alias == null ? null : alias.getText() ); } + + protected AST buildThetaJoinNode(AST persisterReference) { + JoinNode join = createJoinNode( JoinType.FULL, JoinSource.THETA, false ); + join.setFirstChild( persisterReference ); + return join; + } + + private JoinNode createJoinNode(JoinType type, JoinSource source, boolean fetch) { + JoinNode node = ( JoinNode ) getASTFactory().create( JOIN, "join" ); + node.initialize( type, source, fetch ); + return node; + } + + protected AST buildExplicitPropertyJoinNode( + AST propertyReference, + AST alias, + AST joinType, + AST fetch, + AST propertyFetch, + AST withClause) { + JoinNode join = createJoinNode( resolveJoinType( joinType ), JoinSource.EXPLICIT, fetch != null ); + join.setFirstChild( propertyReference ); + if ( withClause != null ) { + join.addChild( withClause ); + } + return join; + } + + protected AST buildAdHocJoinNode(AST persisterReference, AST joinType, AST onClause) { + JoinNode join = createJoinNode( resolveJoinType( joinType ), JoinSource.AD_HOC, false ); + join.setFirstChild( persisterReference ); + if ( onClause != null ) { + join.addChild( onClause ); + } + return join; + } + + private JoinType resolveJoinType(AST joinType) { + if ( joinType.getType() == LEFT ) { + return JoinType.LEFT; + } + else if ( joinType.getType() == RIGHT ) { + return JoinType.RIGHT; + } + else if ( joinType.getType() == FULL ) { + return JoinType.FULL; + } + else { + throw new QueryException( "Unrecognized join type [" + joinType.getText() + "]" ); + } + } + + protected boolean isEntityName(String test) { + try { + return sessionFactory.getEntityPersister( test ) != null; + } + catch( Throwable t ) { + // ignore it... + } + return false; + } + } 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-04-20 17:43:46 UTC (rev 9772) +++ branches/HQL_ANTLR_2/Hibernate3/src/org/hibernate/hql/ast/resolve/HqlResolverASTFactory.java 2006-04-20 21:26:31 UTC (rev 9773) @@ -2,6 +2,9 @@ import org.hibernate.hql.antlr.HqlRTokenTypes; import org.hibernate.hql.ast.HqlASTFactory; +import org.hibernate.engine.SessionFactoryImplementor; +import antlr.collections.AST; +import antlr.Token; /** * AST factory for the resolver phase. @@ -10,6 +13,12 @@ * Time: 7:58:16 AM */ public class HqlResolverASTFactory extends HqlASTFactory implements HqlRTokenTypes { + private final SessionFactoryImplementor factory; + + public HqlResolverASTFactory(SessionFactoryImplementor factory) { + this.factory = factory; + } + public Class getASTNodeType(int tokenType) { // Statement nodes: switch (tokenType) { @@ -20,7 +29,31 @@ return StatementNode.class; case RANGE: return RangeNode.class; + case ENTITY_PERSISTER_REF: + return EntityPersisterReference.class; + case COLLECTION_PERSISTER_REF: + return CollectionPersisterReference.class; + case JOIN: + return JoinNode.class; } return super.getASTNodeType(tokenType); } + + protected AST createUsingCtor(Token token, String string) { + AST node = super.createUsingCtor( token, string ); + prepare( node ); + return node; + } + + protected AST create(Class aClass) { + AST node = super.create( aClass ); + prepare( node ); + return node; + } + + private void prepare(AST node) { + if ( node instanceof SessionFactoryAwareNode ) { + ( ( SessionFactoryAwareNode ) node ).setSessionFactory( factory ); + } + } } Copied: branches/HQL_ANTLR_2/Hibernate3/src/org/hibernate/hql/ast/resolve/JoinNode.java (from rev 9747, branches/HQL_ANTLR_2/Hibernate3/src/org/hibernate/hql/ast/tree/JoinNode.java) =================================================================== --- branches/HQL_ANTLR_2/Hibernate3/src/org/hibernate/hql/ast/tree/JoinNode.java 2006-04-13 12:14:07 UTC (rev 9747) +++ branches/HQL_ANTLR_2/Hibernate3/src/org/hibernate/hql/ast/resolve/JoinNode.java 2006-04-20 21:26:31 UTC (rev 9773) @@ -0,0 +1,69 @@ +package org.hibernate.hql.ast.resolve; + +import antlr.Token; +import org.hibernate.hql.ast.tree.Node; +import org.hibernate.hql.ast.tree.DisplayableNode; + +/** + * Represents an HQL join. The coneptualization here is strictly that of + * the join in terms of the context of the HQL query which may or may not have + * direct correlation to any SQL join. + * + * @author Steve Ebersole + */ +public class JoinNode extends Node implements DisplayableNode { + + // todo : we need to decide the tree structure of a join subtree. + // based on that decision, we may need to have references here + // to both the left-hand and right-hand persister references + + private JoinType joinType; + private JoinSource source; + private boolean fetch; + + public JoinNode() { + } + + public JoinNode(Token tok) { + super( tok ); + } + + public void initialize(JoinType joinType, JoinSource source, boolean fetch) { + this.joinType = joinType; + this.source = source; + this.fetch = fetch; + super.setText( "join" ); + } + + public JoinType getJoinType() { + return joinType; + } + + public void setJoinType(JoinType joinType) { + this.joinType = joinType; + } + + public JoinSource getSource() { + return source; + } + + public void setSource(JoinSource source) { + this.source = source; + } + + public boolean isFetch() { + return fetch; + } + + public void setFetch(boolean fetch) { + this.fetch = fetch; + } + + public String getDisplayText() { + return "{" + "type=" + joinType + ", source=" + source + "fetch=" + fetch + "}"; + } + + public String toString() { + return "JoinNode" + getDisplayText(); + } +} Copied: branches/HQL_ANTLR_2/Hibernate3/src/org/hibernate/hql/ast/resolve/JoinSource.java (from rev 9747, branches/HQL_ANTLR_2/Hibernate3/src/org/hibernate/hql/ast/tree/JoinSource.java) =================================================================== --- branches/HQL_ANTLR_2/Hibernate3/src/org/hibernate/hql/ast/tree/JoinSource.java 2006-04-13 12:14:07 UTC (rev 9747) +++ branches/HQL_ANTLR_2/Hibernate3/src/org/hibernate/hql/ast/resolve/JoinSource.java 2006-04-20 21:26:31 UTC (rev 9773) @@ -0,0 +1,55 @@ +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 ); + } +} Copied: branches/HQL_ANTLR_2/Hibernate3/src/org/hibernate/hql/ast/resolve/JoinType.java (from rev 9747, branches/HQL_ANTLR_2/Hibernate3/src/org/hibernate/hql/ast/tree/JoinType.java) =================================================================== --- branches/HQL_ANTLR_2/Hibernate3/src/org/hibernate/hql/ast/tree/JoinType.java 2006-04-13 12:14:07 UTC (rev 9747) +++ branches/HQL_ANTLR_2/Hibernate3/src/org/hibernate/hql/ast/resolve/JoinType.java 2006-04-20 21:26:31 UTC (rev 9773) @@ -0,0 +1,62 @@ +package org.hibernate.hql.ast.resolve; + +import java.io.Serializable; +import java.util.HashMap; + +/** + * Represents a canonical join type. + * <p/> + * Note that currently HQL really only supports inner and left outer joins + * (though cross joins can also be achieved). This is because joins in HQL + * are always defined in relation to a mapped association. However, when we + * start allowing users to specify ad-hoc joins this may need to change to + * allow the full spectrum of join types. Thus the others are provided here + * currently just for completeness and for future expansion. + * + * @author Steve Ebersole + */ +public class JoinType implements Serializable { + /** + * Represents an inner join. + */ + public static final JoinType INNER = new JoinType( "inner" ); + /** + * Represents a left outer join. + */ + public static final JoinType LEFT = new JoinType( "left outer" ); + /** + * Represents a right outer join. + */ + public static final JoinType RIGHT = new JoinType( "right outer" ); + /** + * Represents a cross join (aka a cartesian product). + */ + public static final JoinType CROSS = new JoinType( "cross" ); + /** + * Represents a full join. + */ + public static final JoinType FULL = new JoinType( "full" ); + + private static final HashMap INSTANCES = new HashMap(); + static { + INSTANCES.put( INNER.name, INNER ); + INSTANCES.put( LEFT.name, LEFT ); + INSTANCES.put( RIGHT.name, RIGHT ); + INSTANCES.put( CROSS.name, CROSS ); + INSTANCES.put( FULL.name, FULL ); + } + + private final String name; + + private JoinType(String name) { + this.name = name; + } + + public String toString() { + return name; + } + + private Object readResolve() { + return INSTANCES.get( name ); + } +} Copied: branches/HQL_ANTLR_2/Hibernate3/src/org/hibernate/hql/ast/resolve/PersisterReference.java (from rev 9747, branches/HQL_ANTLR_2/Hibernate3/src/org/hibernate/hql/ast/tree/PersisterReference.java) =================================================================== --- branches/HQL_ANTLR_2/Hibernate3/src/org/hibernate/hql/ast/tree/PersisterReference.java 2006-04-13 12:14:07 UTC (rev 9747) +++ branches/HQL_ANTLR_2/Hibernate3/src/org/hibernate/hql/ast/resolve/PersisterReference.java 2006-04-20 21:26:31 UTC (rev 9773) @@ -0,0 +1,19 @@ +package org.hibernate.hql.ast.resolve; + +import org.hibernate.type.AssociationType; +import org.hibernate.hql.ast.tree.DisplayableNode; + +/** + * Represents a reference to a persister (either entity or collection) within + * an HQL statement. + * + * @author Steve Ebersole + */ +public interface PersisterReference extends DisplayableNode { + public String getName(); + public String getAlias(); + public AssociationType getPersisterType(); + + public boolean containsProperty(String propertyName); + public PropertyReference retrievePropertyReference(String propertyName); +} Copied: branches/HQL_ANTLR_2/Hibernate3/src/org/hibernate/hql/ast/resolve/PropertyReference.java (from rev 9747, branches/HQL_ANTLR_2/Hibernate3/src/org/hibernate/hql/ast/tree/PropertyReference.java) =================================================================== --- branches/HQL_ANTLR_2/Hibernate3/src/org/hibernate/hql/ast/tree/PropertyReference.java 2006-04-13 12:14:07 UTC (rev 9747) +++ branches/HQL_ANTLR_2/Hibernate3/src/org/hibernate/hql/ast/resolve/PropertyReference.java 2006-04-20 21:26:31 UTC (rev 9773) @@ -0,0 +1,16 @@ +package org.hibernate.hql.ast.resolve; + +import org.hibernate.type.Type; +import org.hibernate.hql.ast.tree.DisplayableNode; + +/** + * Represents a reference to a particular persister-managed property; also + * some special cases such as a collection property reference (e.g., size). + * + * @author Steve Ebersole + */ +public interface PropertyReference extends DisplayableNode { + public String getPropertyName(); + public Type getPropertyType(); + public PersisterReference getPersisterReference(); +} Modified: branches/HQL_ANTLR_2/Hibernate3/src/org/hibernate/hql/ast/resolve/RangeNode.java =================================================================== --- branches/HQL_ANTLR_2/Hibernate3/src/org/hibernate/hql/ast/resolve/RangeNode.java 2006-04-20 17:43:46 UTC (rev 9772) +++ branches/HQL_ANTLR_2/Hibernate3/src/org/hibernate/hql/ast/resolve/RangeNode.java 2006-04-20 21:26:31 UTC (rev 9773) @@ -2,18 +2,23 @@ import org.hibernate.hql.ast.tree.Node; import org.hibernate.hql.ast.tree.DisplayableNode; -import org.hibernate.persister.entity.EntityPersister; /** - * Represents an element of a FROM clause, e.g. "from Animal a" - * <br>User: Joshua Davis - * Date: Apr 12, 2006 - * Time: 7:31:17 AM + * Represents a "top-level" element in a FROM clause (e.g. "from Animal a"). These + * "top-level" nodes are then contained in a RANGE node within the FROM node. + * + * + * @author Joshua Davis */ public class RangeNode extends Node implements DisplayableNode { + // TODO : would like to remove this range concept; + // a "range" is really just a series of full joins (unless further + // qualified in the where-clause, in which case they'd become inner + // joins) specified using old "theta join" syntax from SQL, so + // represent them as join structures private String path; private String alias; - private EntityPersister persister; + private EntityPersisterReference persisterReference; private boolean fetch = false; public String getPath() { @@ -24,12 +29,12 @@ this.path = path; } - public EntityPersister getPersister() { - return persister; + public EntityPersisterReference getPersisterReference() { + return persisterReference; } - public void setPersister(EntityPersister persister) { - this.persister = persister; + public void setPersisterReference(EntityPersisterReference persisterReference) { + this.persisterReference = persisterReference; } public boolean isFetch() { @@ -51,11 +56,11 @@ public String toString() { return "RangeNode{" + - "path='" + path + '\'' + - ", alias='" + alias + '\'' + - ", persister=" + persister + - ", fetch=" + fetch + - '}'; + "path='" + path + '\'' + + ", alias='" + alias + '\'' + + ", reference=" + persisterReference + + ", fetch=" + fetch + + '}'; } public String getDisplayText() { Modified: branches/HQL_ANTLR_2/Hibernate3/src/org/hibernate/hql/ast/resolve/ResolverContext.java =================================================================== --- branches/HQL_ANTLR_2/Hibernate3/src/org/hibernate/hql/ast/resolve/ResolverContext.java 2006-04-20 17:43:46 UTC (rev 9772) +++ branches/HQL_ANTLR_2/Hibernate3/src/org/hibernate/hql/ast/resolve/ResolverContext.java 2006-04-20 21:26:31 UTC (rev 9773) @@ -2,6 +2,8 @@ import org.hibernate.persister.entity.EntityPersister; +import java.util.List; + /** * Looks up persisters and other things by name. * <br>User: Joshua Davis @@ -9,5 +11,9 @@ * Time: 7:34:11 AM */ public interface ResolverContext { - EntityPersister lookupPersister(String path); + public EntityPersister lookupPersister(String path); + public PersisterReference locatePersisterReferenceByAlias(String alias); + public List collectPersisterReferences(); + public EntityPersisterReference getEntityPersisterReference(String entityName, String alias); + public CollectionPersisterReference getCollectionPersisterReference(String collectionRole, String alias); } Modified: branches/HQL_ANTLR_2/Hibernate3/src/org/hibernate/hql/ast/resolve/ResolverContextImpl.java =================================================================== --- branches/HQL_ANTLR_2/Hibernate3/src/org/hibernate/hql/ast/resolve/ResolverContextImpl.java 2006-04-20 17:43:46 UTC (rev 9772) +++ branches/HQL_ANTLR_2/Hibernate3/src/org/hibernate/hql/ast/resolve/ResolverContextImpl.java 2006-04-20 21:26:31 UTC (rev 9773) @@ -2,8 +2,17 @@ import org.hibernate.engine.SessionFactoryImplementor; import org.hibernate.MappingException; +import org.hibernate.hql.antlr.HqlRTokenTypes; import org.hibernate.persister.entity.EntityPersister; +import java.util.Map; +import java.util.HashMap; +import java.util.List; +import java.util.ArrayList; +import java.util.Collections; + +import antlr.ASTFactory; + /** * Implements the resolver's context with a session factory. * <br>User: Joshua Davis @@ -11,26 +20,55 @@ * Time: 7:35:31 AM */ public class ResolverContextImpl implements ResolverContext { - private SessionFactoryImplementor sfi; + private Map persisterReferencesByAlias = new HashMap(); + private List persisterReferences = new ArrayList(); + private final SessionFactoryImplementor sessionFactory; + private final ASTFactory astFactory; - public ResolverContextImpl(SessionFactoryImplementor sfi) { - this.sfi = sfi; + public ResolverContextImpl(SessionFactoryImplementor sessionFactory, ASTFactory astFactory) { + this.sessionFactory = sessionFactory; + this.astFactory = astFactory; } public EntityPersister lookupPersister(String name) { // First, try to get the persister using the class name directly. try { - return sfi.getEntityPersister( name ); + return sessionFactory.getEntityPersister( name ); } catch ( MappingException ignore ) { // unable to locate it using this name } // If that didn't work, try using the 'import' name. - String importedClassName = sfi.getImportedClassName( name ); + String importedClassName = sessionFactory.getImportedClassName( name ); if ( importedClassName == null ) { return null; } - return sfi.getEntityPersister( importedClassName ); + return sessionFactory.getEntityPersister( importedClassName ); } + + public PersisterReference locatePersisterReferenceByAlias(String alias) { + return ( PersisterReference ) persisterReferencesByAlias.get( alias ); + } + + public List collectPersisterReferences() { + return Collections.unmodifiableList( persisterReferences ); + } + + public EntityPersisterReference getEntityPersisterReference(String entityName, String alias) { + EntityPersister persister = lookupPersister( entityName ); + EntityPersisterReference persisterReference = ( EntityPersisterReference ) astFactory.create( HqlRTokenTypes.ENTITY_PERSISTER_REF, persister.getEntityName() ); + persisterReference.initialize( persister.getEntityName(), alias ); + persisterReferences.add( persisterReference ); + if ( alias != null ) { + persisterReferencesByAlias.put( alias, persisterReference ); + } + return persisterReference; + } + + public CollectionPersisterReference getCollectionPersisterReference(String collectionRole, String alias) { + // TODO : implement; for now returns null... + return null; + } + } Added: branches/HQL_ANTLR_2/Hibernate3/src/org/hibernate/hql/ast/resolve/SessionFactoryAwareNode.java =================================================================== --- branches/HQL_ANTLR_2/Hibernate3/src/org/hibernate/hql/ast/resolve/SessionFactoryAwareNode.java 2006-04-20 17:43:46 UTC (rev 9772) +++ branches/HQL_ANTLR_2/Hibernate3/src/org/hibernate/hql/ast/resolve/SessionFactoryAwareNode.java 2006-04-20 21:26:31 UTC (rev 9773) @@ -0,0 +1,18 @@ +package org.hibernate.hql.ast.resolve; + +import org.hibernate.engine.SessionFactoryImplementor; + +/** + * Interface for nodes which wish to be injected with a reference to the + * current session factory. + * + * @author Steve Ebersole + */ +public interface SessionFactoryAwareNode { + /** + * Used to inject a reference to the current session factory. + * + * @param factory The session factory. + */ + public void setSessionFactory(SessionFactoryImplementor factory); +} |
Author: max...@jb... Date: 2006-04-20 13:43:46 -0400 (Thu, 20 Apr 2006) New Revision: 9772 Modified: trunk/HibernateExt/tools/src/java/org/hibernate/tool/hbm2x/pojo/BasicPOJOClass.java trunk/HibernateExt/tools/src/java/org/hibernate/tool/hbm2x/pojo/ComponentPOJOClass.java trunk/HibernateExt/tools/src/java/org/hibernate/tool/hbm2x/pojo/POJOClass.java trunk/HibernateExt/tools/src/templates/pojo/Ejb3PropertyGetAnnotation.ftl trunk/HibernateExt/tools/src/test/org/hibernate/tool/hbm2x/Bungalow.hbm.xml trunk/HibernateExt/tools/src/test5.0/org/hibernate/tool/hbm2x/Hbm2JavaEjb3ForJDK50Test.java Log: HBX-648 ejb3 generation should generate the now required @Temporal for date/time's Modified: trunk/HibernateExt/tools/src/java/org/hibernate/tool/hbm2x/pojo/BasicPOJOClass.java =================================================================== --- trunk/HibernateExt/tools/src/java/org/hibernate/tool/hbm2x/pojo/BasicPOJOClass.java 2006-04-19 23:12:27 UTC (rev 9771) +++ trunk/HibernateExt/tools/src/java/org/hibernate/tool/hbm2x/pojo/BasicPOJOClass.java 2006-04-20 17:43:46 UTC (rev 9772) @@ -15,6 +15,7 @@ import org.hibernate.mapping.Property; import org.hibernate.mapping.PropertyGeneration; import org.hibernate.mapping.Selectable; +import org.hibernate.mapping.SimpleValue; import org.hibernate.mapping.Value; import org.hibernate.tool.hbm2x.Cfg2JavaTool; import org.hibernate.tool.hbm2x.MetaAttributeConstants; @@ -22,7 +23,7 @@ import org.hibernate.util.StringHelper; /** - * Abstarct implementation of POJOClass. To be extended by ComponentPOJO and EntityPOJO + * Abstract implementation of POJOClass. To be extended by ComponentPOJO and EntityPOJO * @author max * @author <a href="mailto:abh...@jb...">Amit Bhayani</a> * @@ -293,6 +294,29 @@ return importContext.staticImport(fqcn, member); } + public String generateBasicAnnotation(Property property) { + StringBuffer annotations = new StringBuffer( " " ); + if(property.getValue() instanceof SimpleValue) { + String typeName = ((SimpleValue)property.getValue()).getTypeName(); + if("date".equals(typeName) || "java.sql.Date".equals(typeName)) { + buildTemporalAnnotation( annotations, "DATE" ); + } else if ("timestamp".equals(typeName) || "java.sql.Timestamp".equals(typeName)) { + //buildTemporalAnnotation( annotations, "TIMESTAMP" ); ..the default so don't generate + } else if ("time".equals(typeName) || "java.sql.Time".equals(typeName)) { + buildTemporalAnnotation(annotations, "TIME"); + } //TODO: calendar etc. ? + } + + return annotations.toString(); + } + + private StringBuffer buildTemporalAnnotation(StringBuffer annotations, String temporalTypeValue) { + String temporal = importType("javax.persistence.Temporal"); + String temporalType = importType("javax.persistence.TemporalType"); + + return annotations.append( "@" + temporal +"(" + temporalType + "." + temporalTypeValue + ")"); + } + public String generateAnnColumnAnnotation(Property property) { StringBuffer annotations = new StringBuffer( " " ); boolean insertable = property.isInsertable(); @@ -308,7 +332,7 @@ else { if ( property.getColumnSpan() == 1 ) { Selectable selectable = (Selectable) property.getColumnIterator().next(); - buildColumnAnnotation( selectable, annotations, insertable, updatable ); + buildColumnAnnotation( selectable, annotations, insertable, updatable ); } else { Iterator columns = property.getColumnIterator(); Modified: trunk/HibernateExt/tools/src/java/org/hibernate/tool/hbm2x/pojo/ComponentPOJOClass.java =================================================================== --- trunk/HibernateExt/tools/src/java/org/hibernate/tool/hbm2x/pojo/ComponentPOJOClass.java 2006-04-19 23:12:27 UTC (rev 9771) +++ trunk/HibernateExt/tools/src/java/org/hibernate/tool/hbm2x/pojo/ComponentPOJOClass.java 2006-04-20 17:43:46 UTC (rev 9772) @@ -87,6 +87,10 @@ return false; } + public String generateBasicAnnotation(Property property) { + return null; + } + public String generateAnnIdGenerator() { return null; } Modified: trunk/HibernateExt/tools/src/java/org/hibernate/tool/hbm2x/pojo/POJOClass.java =================================================================== --- trunk/HibernateExt/tools/src/java/org/hibernate/tool/hbm2x/pojo/POJOClass.java 2006-04-19 23:12:27 UTC (rev 9771) +++ trunk/HibernateExt/tools/src/java/org/hibernate/tool/hbm2x/pojo/POJOClass.java 2006-04-20 17:43:46 UTC (rev 9772) @@ -69,6 +69,7 @@ public String generateAnnColumnAnnotation(Property property); public String generateAnnIdGenerator(); public String generateAnnTableUniqueConstraint(); + public String generateBasicAnnotation(Property property); public Iterator getAllPropertiesIterator(); public String getPackageName(); Modified: trunk/HibernateExt/tools/src/templates/pojo/Ejb3PropertyGetAnnotation.ftl =================================================================== --- trunk/HibernateExt/tools/src/templates/pojo/Ejb3PropertyGetAnnotation.ftl 2006-04-19 23:12:27 UTC (rev 9771) +++ trunk/HibernateExt/tools/src/templates/pojo/Ejb3PropertyGetAnnotation.ftl 2006-04-20 17:43:46 UTC (rev 9772) @@ -16,6 +16,7 @@ <#elseif c2h.isCollection(property)> ${pojo.generateCollectionAnnotation(property, cfg)} <#else> +${pojo.generateBasicAnnotation(property)} ${pojo.generateAnnColumnAnnotation(property)} </#if> </#if> \ No newline at end of file Modified: trunk/HibernateExt/tools/src/test/org/hibernate/tool/hbm2x/Bungalow.hbm.xml =================================================================== --- trunk/HibernateExt/tools/src/test/org/hibernate/tool/hbm2x/Bungalow.hbm.xml 2006-04-19 23:12:27 UTC (rev 9771) +++ trunk/HibernateExt/tools/src/test/org/hibernate/tool/hbm2x/Bungalow.hbm.xml 2006-04-20 17:43:46 UTC (rev 9772) @@ -13,6 +13,11 @@ </id> <property name="name" type="string" not-null="true" length="100"/> + + <!-- test for various dates --> + <property name="lastModified" type="timestamp"/> + <property name="dayFree" type="date"/> + <property name="timeFree" type="time"/> </class> </hibernate-mapping> 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-04-19 23:12:27 UTC (rev 9771) +++ trunk/HibernateExt/tools/src/test5.0/org/hibernate/tool/hbm2x/Hbm2JavaEjb3ForJDK50Test.java 2006-04-20 17:43:46 UTC (rev 9772) @@ -37,6 +37,10 @@ exporter.start(); } + protected void tearDown() throws Exception { + //super.tearDown(); + } + public void testFileExistence() { assertFileAndExists( new File( getOutputDir().getAbsolutePath() + "/org/hibernate/tool/hbm2x/Train.java" ) ); assertFileAndExists( |
From: <hib...@li...> - 2006-04-19 23:12:30
|
Author: epbernard Date: 2006-04-19 19:12:27 -0400 (Wed, 19 Apr 2006) New Revision: 9771 Modified: trunk/HibernateExt/metadata/src/java/org/hibernate/type/AbstractLobType.java trunk/HibernateExt/metadata/src/java/org/hibernate/type/CharacterArrayClobType.java trunk/HibernateExt/metadata/src/java/org/hibernate/type/EnumType.java trunk/HibernateExt/metadata/src/java/org/hibernate/type/StringClobType.java Log: ANN-319 make types serializable and thread safe Modified: trunk/HibernateExt/metadata/src/java/org/hibernate/type/AbstractLobType.java =================================================================== --- trunk/HibernateExt/metadata/src/java/org/hibernate/type/AbstractLobType.java 2006-04-19 19:19:13 UTC (rev 9770) +++ trunk/HibernateExt/metadata/src/java/org/hibernate/type/AbstractLobType.java 2006-04-19 23:12:27 UTC (rev 9771) @@ -4,6 +4,7 @@ import java.sql.PreparedStatement; import java.sql.ResultSet; import java.sql.SQLException; +import java.io.Serializable; import org.hibernate.EntityMode; import org.hibernate.HibernateException; @@ -14,7 +15,7 @@ /** * @author Emmanuel Bernard */ -public abstract class AbstractLobType extends AbstractType { +public abstract class AbstractLobType extends AbstractType implements Serializable { public boolean isDirty(Object old, Object current, boolean[] checkable, SessionImplementor session) throws HibernateException { return checkable[0] ? ! isEqual( old, current, session.getEntityMode() ) : false; Modified: trunk/HibernateExt/metadata/src/java/org/hibernate/type/CharacterArrayClobType.java =================================================================== --- trunk/HibernateExt/metadata/src/java/org/hibernate/type/CharacterArrayClobType.java 2006-04-19 19:19:13 UTC (rev 9770) +++ trunk/HibernateExt/metadata/src/java/org/hibernate/type/CharacterArrayClobType.java 2006-04-19 23:12:27 UTC (rev 9771) @@ -1,10 +1,6 @@ //$Id$ package org.hibernate.type; -import org.hibernate.HibernateException; -import org.hibernate.util.ArrayHelper; -import org.hibernate.usertype.UserType; - import java.io.CharArrayReader; import java.io.IOException; import java.io.Reader; @@ -15,13 +11,17 @@ import java.sql.Types; import java.util.ArrayList; +import org.hibernate.HibernateException; +import org.hibernate.usertype.UserType; +import org.hibernate.util.ArrayHelper; + /** * Map a Character[] to a Clob * Experimental * * @author Emmanuel Bernard */ -public class CharacterArrayClobType implements UserType { +public class CharacterArrayClobType implements UserType, Serializable { public static final int BUFFER_SIZE = 4096; public int[] sqlTypes() { Modified: trunk/HibernateExt/metadata/src/java/org/hibernate/type/EnumType.java =================================================================== --- trunk/HibernateExt/metadata/src/java/org/hibernate/type/EnumType.java 2006-04-19 19:19:13 UTC (rev 9770) +++ trunk/HibernateExt/metadata/src/java/org/hibernate/type/EnumType.java 2006-04-19 23:12:27 UTC (rev 9771) @@ -2,6 +2,8 @@ package org.hibernate.type; import java.io.Serializable; +import java.io.ObjectInputStream; +import java.io.IOException; import java.lang.reflect.Method; import java.sql.PreparedStatement; import java.sql.ResultSet; @@ -15,6 +17,7 @@ import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.hibernate.HibernateException; +import org.hibernate.AssertionFailure; import org.hibernate.util.StringHelper; import org.hibernate.util.ReflectHelper; import org.hibernate.usertype.ParameterizedType; @@ -25,7 +28,8 @@ * Try and find the appropriate SQL type depending on column metadata * @author Emmanuel Bernard */ -public class EnumType implements UserType, ParameterizedType { +//TODO implements readobject/writeobject to recalculate the enumclasses +public class EnumType implements UserType, ParameterizedType, Serializable { private static Log log = LogFactory.getLog(EnumType.class); private static final boolean IS_TRACE_ENABLED; static { @@ -76,17 +80,7 @@ } if (object instanceof Number) { Object[] values = enumValues.get(enumClass); - if (values == null) { - try { - Method method = null; - method = enumClass.getDeclaredMethod( "values", new Class[0] ); - values = (Object[]) method.invoke(null, new Object[0] ); - enumValues.put( enumClass, values ); - } - catch (Exception e) { - throw new HibernateException("Error while accessing enum.values(): " + enumClass, e); - } - } + if (values == null) throw new AssertionFailure("enumValues not preprocessed: " + enumClass); int ordinal = ( (Number) object ).intValue(); if (ordinal < 0 || ordinal >= values.length) { throw new IllegalArgumentException("Unknown ordinal value for enum " + enumClass + ": " + ordinal); @@ -283,6 +277,8 @@ catch (ClassNotFoundException exception) { throw new HibernateException("Enum class not found", exception); } + //this is threadsafe to do it here, setParameterValues() is called sequencially + initEnumValue(); //nullify unnullified properties yuck! schema = parameters.getProperty(SCHEMA); if ( "".equals( schema ) ) schema = null; @@ -296,4 +292,25 @@ guessed = true; } } + + private void initEnumValue() { + Object[] values = enumValues.get(enumClass); + if (values == null) { + try { + Method method = null; + method = enumClass.getDeclaredMethod( "values", new Class[0] ); + values = (Object[]) method.invoke(null, new Object[0] ); + enumValues.put( enumClass, values ); + } + catch (Exception e) { + throw new HibernateException("Error while accessing enum.values(): " + enumClass, e); + } + } + } + + private void readObject(ObjectInputStream ois) throws IOException, ClassNotFoundException { + //FIXME Hum, I think I break the thread safety here + ois.defaultReadObject(); + initEnumValue(); + } } Modified: trunk/HibernateExt/metadata/src/java/org/hibernate/type/StringClobType.java =================================================================== --- trunk/HibernateExt/metadata/src/java/org/hibernate/type/StringClobType.java 2006-04-19 19:19:13 UTC (rev 9770) +++ trunk/HibernateExt/metadata/src/java/org/hibernate/type/StringClobType.java 2006-04-19 23:12:27 UTC (rev 9771) @@ -18,7 +18,7 @@ * * @author Emmanuel Bernard */ -public class StringClobType implements UserType { +public class StringClobType implements UserType, Serializable { public int[] sqlTypes() { return new int[] { Types.CLOB }; } |
From: <hib...@li...> - 2006-04-19 19:19:19
|
Author: epbernard Date: 2006-04-19 15:19:13 -0400 (Wed, 19 Apr 2006) New Revision: 9770 Modified: trunk/HibernateExt/metadata/src/java/org/hibernate/cfg/annotations/MapBinder.java Log: allow index to be null (useful for onetomany cas Modified: trunk/HibernateExt/metadata/src/java/org/hibernate/cfg/annotations/MapBinder.java =================================================================== --- trunk/HibernateExt/metadata/src/java/org/hibernate/cfg/annotations/MapBinder.java 2006-04-19 03:56:49 UTC (rev 9769) +++ trunk/HibernateExt/metadata/src/java/org/hibernate/cfg/annotations/MapBinder.java 2006-04-19 19:19:13 UTC (rev 9770) @@ -185,7 +185,7 @@ elementColumns = new Ejb3Column[1]; Ejb3Column column = new Ejb3Column(); column.setImplicit( false ); - column.setNullable( false ); + column.setNullable( true ); column.setLength( Ejb3Column.DEFAULT_COLUMN_LENGTH ); column.setLogicalColumnName( Collection.DEFAULT_KEY_COLUMN_NAME ); //TODO create an EMPTY_JOINS collection |
From: <hib...@li...> - 2006-04-19 03:56:50
|
Author: epbernard Date: 2006-04-18 23:56:49 -0400 (Tue, 18 Apr 2006) New Revision: 9769 Modified: trunk/HibernateExt/metadata/src/java/org/hibernate/cfg/annotations/MapBinder.java Log: ANN-1 <Element, Element>, <Element, @Component> <Element, Entity> work Modified: trunk/HibernateExt/metadata/src/java/org/hibernate/cfg/annotations/MapBinder.java =================================================================== --- trunk/HibernateExt/metadata/src/java/org/hibernate/cfg/annotations/MapBinder.java 2006-04-19 03:37:31 UTC (rev 9768) +++ trunk/HibernateExt/metadata/src/java/org/hibernate/cfg/annotations/MapBinder.java 2006-04-19 03:56:49 UTC (rev 9769) @@ -95,10 +95,10 @@ //TODO ugly copy/pastle from CollectionBinder.bindManyToManySecondPass String mapKeyType = property.getMapKey().getName(); PersistentClass collectionEntity = (PersistentClass) persistentClasses.get( mapKeyType ); - boolean isCollectionOfEntities = collectionEntity != null; + boolean isIndexOfEntities = collectionEntity != null; ManyToOne element = null; org.hibernate.mapping.Map mapValue = (org.hibernate.mapping.Map) this.collection; - if ( isCollectionOfEntities ) { + if ( isIndexOfEntities ) { element = new ManyToOne( mapValue.getCollectionTable() ); mapValue.setIndex( element ); @@ -187,7 +187,7 @@ column.setImplicit( false ); column.setNullable( false ); column.setLength( Ejb3Column.DEFAULT_COLUMN_LENGTH ); - column.setLogicalColumnName( Collection.DEFAULT_KEY_COLUMN_NAME ); //TODO inject column name here + column.setLogicalColumnName( Collection.DEFAULT_KEY_COLUMN_NAME ); //TODO create an EMPTY_JOINS collection column.setJoins( new HashMap<String, Join>() ); column.setMappings( mappings ); @@ -203,7 +203,10 @@ mapValue.setIndex( elementBinder.make() ); } } - + //FIXME pass the Index Entity JoinColumns + if ( isIndexOfEntities ) { + //bindManytoManyInverseFk( collectionEntity, indexJoinColumns, element, unique, mappings ); + } } } |
From: Steve E. <ste...@jb...> - 2006-04-19 03:53:17
|
lol -----Original Message----- From: hib...@li... [mailto:hib...@li...] On Behalf Of hib...@li... Sent: Tuesday, April 18, 2006 9:51 PM To: hib...@li... Subject: [Hibernate-commits] Hibernate Code SVN: r9767 - trunk/Hibernate3/src/org/hibernate/transaction Author: epbernard Date: 2006-04-18 22:50:37 -0400 (Tue, 18 Apr 2006) New Revision: 9767 Modified: =20 trunk/Hibernate3/src/org/hibernate/transaction/JTATransactionFactory.jav a Log: get rid of the Hip Hop exception Modified: trunk/Hibernate3/src/org/hibernate/transaction/JTATransactionFactory.jav a =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D --- trunk/Hibernate3/src/org/hibernate/transaction/JTATransactionFactory.jav a 2006-04-19 02:24:45 UTC (rev 9766) +++ trunk/Hibernate3/src/org/hibernate/transaction/JTATransactionFactory.jav a 2006-04-19 02:50:37 UTC (rev 9767) @@ -83,7 +83,7 @@ ut =3D ( UserTransaction ) context.lookup( utName ); } catch ( NamingException e ) { - throw new TransactionException( "Unable to locate UserTrasnaction to check status" ); + throw new TransactionException( "Unable to locate UserTransaction to check status" ); } } return ut !=3D null && JTAHelper.isInProgress( ut.getStatus() ); ------------------------------------------------------- This SF.Net email is sponsored by xPML, a groundbreaking scripting language that extends applications into web and mobile media. Attend the live webcast and join the prime developer group breaking into this new coding territory! http://sel.as-us.falkag.net/sel?cmd=3Dlnk&kid=3D110944&bid=3D241720&dat=3D= 121642 _______________________________________________ hibernate-commits mailing list hib...@li... https://lists.sourceforge.net/lists/listinfo/hibernate-commits |
Author: epbernard Date: 2006-04-18 23:37:31 -0400 (Tue, 18 Apr 2006) New Revision: 9768 Added: trunk/HibernateExt/metadata/src/test/org/hibernate/test/annotations/indexcoll/Atmosphere.java trunk/HibernateExt/metadata/src/test/org/hibernate/test/annotations/indexcoll/Gas.java Modified: trunk/HibernateExt/metadata/src/java/org/hibernate/cfg/annotations/MapBinder.java trunk/HibernateExt/metadata/src/test/org/hibernate/test/annotations/collectionelement/Boy.java trunk/HibernateExt/metadata/src/test/org/hibernate/test/annotations/collectionelement/CollectionElementTest.java trunk/HibernateExt/metadata/src/test/org/hibernate/test/annotations/indexcoll/IndexedCollectionTest.java Log: ANN-1 <Element, Element>, <Element, @Component> <Element, Entity> work Modified: trunk/HibernateExt/metadata/src/java/org/hibernate/cfg/annotations/MapBinder.java =================================================================== --- trunk/HibernateExt/metadata/src/java/org/hibernate/cfg/annotations/MapBinder.java 2006-04-19 02:50:37 UTC (rev 9767) +++ trunk/HibernateExt/metadata/src/java/org/hibernate/cfg/annotations/MapBinder.java 2006-04-19 03:37:31 UTC (rev 9768) @@ -3,17 +3,29 @@ import java.util.Iterator; import java.util.Map; +import java.util.HashMap; +import javax.persistence.AttributeOverride; +import javax.persistence.AttributeOverrides; +import javax.persistence.Embeddable; + import org.hibernate.AnnotationException; import org.hibernate.AssertionFailure; import org.hibernate.FetchMode; import org.hibernate.MappingException; +import org.hibernate.annotations.AccessType; import org.hibernate.cfg.BinderHelper; import org.hibernate.cfg.CollectionSecondPass; import org.hibernate.cfg.Ejb3Column; import org.hibernate.cfg.Ejb3JoinColumn; import org.hibernate.cfg.ExtendedMappings; import org.hibernate.cfg.SecondPass; +import org.hibernate.cfg.AnnotatedClassType; +import org.hibernate.cfg.PropertyHolder; +import org.hibernate.cfg.PropertyHolderBuilder; +import org.hibernate.cfg.PropertyData; +import org.hibernate.cfg.PropertyPreloadedData; +import org.hibernate.cfg.AnnotationBinder; import org.hibernate.mapping.Collection; import org.hibernate.mapping.Column; import org.hibernate.mapping.Component; @@ -22,7 +34,12 @@ import org.hibernate.mapping.Property; import org.hibernate.mapping.SimpleValue; import org.hibernate.mapping.Value; +import org.hibernate.mapping.ManyToOne; +import org.hibernate.mapping.Join; import org.hibernate.reflection.XProperty; +import org.hibernate.reflection.XClass; +import org.hibernate.reflection.ReflectionManager; +import org.hibernate.reflection.XAnnotatedElement; /** * Implementation to bind a Map @@ -52,26 +69,142 @@ persistentClasses, collType, fkJoinColumns, keyColumns, inverseColumns, elementColumns, isEmbedded, property, fetchMode, unique, assocTableBinder, ignoreNotFound, mappings ); - bindKeyFromAssociationTable( collType, persistentClasses, mapKeyPropertyName, mappings ); + bindKeyFromAssociationTable( collType, persistentClasses, mapKeyPropertyName, property, ignoreNotFound, isEmbedded, mappings ); } }; } private void bindKeyFromAssociationTable( - String collType, Map persistentClasses, String mapKeyPropertyName, ExtendedMappings mappings + String collType, Map persistentClasses, String mapKeyPropertyName, XProperty property, boolean ignoreNotFound, boolean isEmbedded, ExtendedMappings mappings ) { - if ( mapKeyPropertyName == null ) throw new AnnotationException( "A Map must declare a @MapKey element" ); - PersistentClass associatedClass = (PersistentClass) persistentClasses.get( collType ); - if ( associatedClass == null ) throw new AnnotationException( "Associated class not found: " + collType ); - Property property = BinderHelper.findPropertyByName( associatedClass, mapKeyPropertyName ); - if ( property == null ) { - throw new AnnotationException( - "Map key property not found: " + collType + "." + mapKeyPropertyName - ); + if ( mapKeyPropertyName != null ) { + PersistentClass associatedClass = (PersistentClass) persistentClasses.get( collType ); + if ( associatedClass == null ) throw new AnnotationException( "Associated class not found: " + collType ); + Property mapProperty = BinderHelper.findPropertyByName( associatedClass, mapKeyPropertyName ); + if ( mapProperty == null ) { + throw new AnnotationException( + "Map key property not found: " + collType + "." + mapKeyPropertyName + ); + } + org.hibernate.mapping.Map map = (org.hibernate.mapping.Map) this.collection; + Value indexValue = createFormulatedValue( mapProperty.getValue(), map ); + map.setIndex( indexValue ); } - org.hibernate.mapping.Map map = (org.hibernate.mapping.Map) this.collection; - Value indexValue = createFormulatedValue( property.getValue(), map ); - map.setIndex( indexValue ); + else { + //throw new AnnotationException( "A Map must declare a @MapKey element" ); + //TODO ugly copy/pastle from CollectionBinder.bindManyToManySecondPass + String mapKeyType = property.getMapKey().getName(); + PersistentClass collectionEntity = (PersistentClass) persistentClasses.get( mapKeyType ); + boolean isCollectionOfEntities = collectionEntity != null; + ManyToOne element = null; + org.hibernate.mapping.Map mapValue = (org.hibernate.mapping.Map) this.collection; + if ( isCollectionOfEntities ) { + element = + new ManyToOne( mapValue.getCollectionTable() ); + mapValue.setIndex( element ); + element.setReferencedEntityName( mapKeyType ); + //element.setFetchMode( fetchMode ); + //element.setLazy( fetchMode != FetchMode.JOIN ); + //make the second join non lazy + element.setFetchMode( FetchMode.JOIN ); + element.setLazy( false ); + element.setIgnoreNotFound( ignoreNotFound ); + } + else { + XClass elementClass; + AnnotatedClassType classType; + // Map<String, javax.persistence.Column[]> columnOverrides = PropertyHolderBuilder.buildColumnOverride( + // property, StringHelper.qualify( collValue.getRole(), "element" ) + // ); + //FIXME the "element" is lost + PropertyHolder holder = null; + if ( BinderHelper.PRIMITIVE_NAMES.contains( mapKeyType ) ) { + classType = AnnotatedClassType.NONE; + elementClass = null; + } + else { + try { + elementClass = ReflectionManager.INSTANCE.classForName( mapKeyType, MapBinder.class ); + } + catch (ClassNotFoundException e) { + throw new AnnotationException( "Unable to find class: " + mapKeyType, e ); + } + classType = mappings.getClassType( elementClass ); + + holder = PropertyHolderBuilder.buildPropertyHolder( + mapValue, + mapValue.getRole(), + elementClass, + property + ); + //force in case of attribute override + boolean attributeOverride = property.isAnnotationPresent( AttributeOverride.class) + || property.isAnnotationPresent( AttributeOverrides.class); + if ( isEmbedded || attributeOverride ) { + classType = AnnotatedClassType.EMBEDDABLE; + } + } + + if ( AnnotatedClassType.EMBEDDABLE.equals( classType ) ) { + EntityBinder entityBinder = new EntityBinder(); + Embeddable embeddable = (Embeddable) elementClass.getAnnotation( Embeddable.class ); + PersistentClass owner = mapValue.getOwner(); + boolean isPropertyAnnotated; + AccessType access = ( (XAnnotatedElement) elementClass).getAnnotation( AccessType.class ); + //FIXME support @Access for collection of elements + //String accessType = access != null ? access.value() : null; + if ( owner.getIdentifierProperty() != null) { + isPropertyAnnotated = owner.getIdentifierProperty().getPropertyAccessorName().equals( "property" ); + } + else if ( owner.getIdentifierMapper() != null && owner.getIdentifierMapper().getPropertySpan() > 0 ) { + Property prop = (Property) owner.getIdentifierMapper().getPropertyIterator().next(); + isPropertyAnnotated = prop.getPropertyAccessorName().equals("property"); + } + else { + throw new AssertionFailure( "Unable to guess collection property accessor name" ); + } + + //boolean propertyAccess = embeddable == null || AccessType.PROPERTY.equals( embeddable.access() ); + //FIXME "index" is it right? + PropertyData inferredData = new PropertyPreloadedData( "property", "index", elementClass ); + //TODO be smart with isNullable + Component component = AnnotationBinder.fillComponent( + holder, inferredData, isPropertyAnnotated, isPropertyAnnotated ? "property" : "field", true, + entityBinder, false, false, + mappings + ); + mapValue.setIndex( component ); + } + else { + SimpleValueBinder elementBinder = new SimpleValueBinder(); + elementBinder.setMappings( mappings ); + elementBinder.setReturnedClassName( mapKeyType ); + //FIXME get the columns from an annotation + Ejb3Column[] elementColumns = null; + if ( elementColumns == null || elementColumns.length == 0 ) { + elementColumns = new Ejb3Column[1]; + Ejb3Column column = new Ejb3Column(); + column.setImplicit( false ); + column.setNullable( false ); + column.setLength( Ejb3Column.DEFAULT_COLUMN_LENGTH ); + column.setLogicalColumnName( Collection.DEFAULT_KEY_COLUMN_NAME ); //TODO inject column name here + //TODO create an EMPTY_JOINS collection + column.setJoins( new HashMap<String, Join>() ); + column.setMappings( mappings ); + column.bind(); + elementColumns[0] = column; + } + //override the table + for ( Ejb3Column column : elementColumns ) { + column.setTable( mapValue.getCollectionTable() ); + } + elementBinder.setColumns( elementColumns ); + elementBinder.setType( property, elementClass ); + mapValue.setIndex( elementBinder.make() ); + } + } + + } } protected Value createFormulatedValue(Value value, Collection collection) { Modified: trunk/HibernateExt/metadata/src/test/org/hibernate/test/annotations/collectionelement/Boy.java =================================================================== --- trunk/HibernateExt/metadata/src/test/org/hibernate/test/annotations/collectionelement/Boy.java 2006-04-19 02:50:37 UTC (rev 9767) +++ trunk/HibernateExt/metadata/src/test/org/hibernate/test/annotations/collectionelement/Boy.java 2006-04-19 03:37:31 UTC (rev 9768) @@ -3,6 +3,8 @@ import java.util.HashSet; import java.util.Set; +import java.util.Map; +import java.util.HashMap; import javax.persistence.AttributeOverride; import javax.persistence.Column; import javax.persistence.Entity; @@ -25,6 +27,7 @@ private String firstName; private String lastName; private Set<String> nickNames = new HashSet<String>(); + private Map<String, Integer> scorePerNickName = new HashMap<String, Integer>(); private int[] favoriteNumbers; private Set<Toy> favoriteToys = new HashSet<Toy>(); private Set<Character> characters = new HashSet<Character>(); @@ -65,6 +68,17 @@ } @CollectionOfElements + @JoinTable(name="ScorePerNickName", joinColumns = @JoinColumn(name = "BoyId") ) + @Column(name="score", nullable = false) + public Map<String, Integer> getScorePerNickName() { + return scorePerNickName; + } + + public void setScorePerNickName(Map<String, Integer> scorePerNickName) { + this.scorePerNickName = scorePerNickName; + } + + @CollectionOfElements @JoinTable( name="BoyFavoriteNumbers", joinColumns = @JoinColumn(name="BoyId") Modified: trunk/HibernateExt/metadata/src/test/org/hibernate/test/annotations/collectionelement/CollectionElementTest.java =================================================================== --- trunk/HibernateExt/metadata/src/test/org/hibernate/test/annotations/collectionelement/CollectionElementTest.java 2006-04-19 02:50:37 UTC (rev 9767) +++ trunk/HibernateExt/metadata/src/test/org/hibernate/test/annotations/collectionelement/CollectionElementTest.java 2006-04-19 03:37:31 UTC (rev 9768) @@ -19,6 +19,8 @@ boy.setLastName( "Doe" ); boy.getNickNames().add("Johnny"); boy.getNickNames().add("Thing"); + boy.getScorePerNickName().put( "Johnny", new Integer(3) ) ; + boy.getScorePerNickName().put( "Thing", new Integer(5) ) ; int[] favNbrs = new int[4]; for (int index = 0 ; index < favNbrs.length - 1 ; index++) { favNbrs[index] = index * 3; @@ -33,6 +35,9 @@ boy = (Boy) s.get( Boy.class, boy.getId() ); assertNotNull( boy.getNickNames() ); assertTrue( boy.getNickNames().contains( "Thing" ) ); + assertNotNull( boy.getScorePerNickName() ); + assertTrue( boy.getScorePerNickName().containsKey( "Thing" ) ); + assertEquals( new Integer(5), boy.getScorePerNickName().get("Thing") ); assertNotNull( boy.getFavoriteNumbers() ); assertEquals( 3, boy.getFavoriteNumbers()[1] ); assertTrue( boy.getCharacters().contains( Character.CRAFTY ) ); @@ -95,6 +100,8 @@ } + + protected Class[] getMappings() { return new Class[] { Boy.class, Added: trunk/HibernateExt/metadata/src/test/org/hibernate/test/annotations/indexcoll/Atmosphere.java =================================================================== --- trunk/HibernateExt/metadata/src/test/org/hibernate/test/annotations/indexcoll/Atmosphere.java 2006-04-19 02:50:37 UTC (rev 9767) +++ trunk/HibernateExt/metadata/src/test/org/hibernate/test/annotations/indexcoll/Atmosphere.java 2006-04-19 03:37:31 UTC (rev 9768) @@ -0,0 +1,20 @@ +//$Id: $ +package org.hibernate.test.annotations.indexcoll; + +import java.util.HashMap; +import java.util.Map; +import javax.persistence.CascadeType; +import javax.persistence.Entity; +import javax.persistence.GeneratedValue; +import javax.persistence.Id; +import javax.persistence.ManyToMany; + +/** + * @author Emmanuel Bernard + */ +@Entity +public class Atmosphere { + @Id @GeneratedValue public Integer id; + @ManyToMany(cascade = CascadeType.ALL) + public Map<String, Gas> gases = new HashMap<String, Gas>(); +} Added: trunk/HibernateExt/metadata/src/test/org/hibernate/test/annotations/indexcoll/Gas.java =================================================================== --- trunk/HibernateExt/metadata/src/test/org/hibernate/test/annotations/indexcoll/Gas.java 2006-04-19 02:50:37 UTC (rev 9767) +++ trunk/HibernateExt/metadata/src/test/org/hibernate/test/annotations/indexcoll/Gas.java 2006-04-19 03:37:31 UTC (rev 9768) @@ -0,0 +1,16 @@ +//$Id: $ +package org.hibernate.test.annotations.indexcoll; + +import javax.persistence.Entity; +import javax.persistence.Id; +import javax.persistence.GeneratedValue; + +/** + * @author Emmanuel Bernard + */ +@Entity +public class Gas { + @Id @GeneratedValue public Integer id; + public String name; + +} Modified: trunk/HibernateExt/metadata/src/test/org/hibernate/test/annotations/indexcoll/IndexedCollectionTest.java =================================================================== --- trunk/HibernateExt/metadata/src/test/org/hibernate/test/annotations/indexcoll/IndexedCollectionTest.java 2006-04-19 02:50:37 UTC (rev 9767) +++ trunk/HibernateExt/metadata/src/test/org/hibernate/test/annotations/indexcoll/IndexedCollectionTest.java 2006-04-19 03:37:31 UTC (rev 9768) @@ -323,6 +323,27 @@ s.close(); } + public void testRealMap() throws Exception { + Session s = openSession(); + Transaction tx = s.beginTransaction(); + Atmosphere atm = new Atmosphere(); + Gas o2 = new Gas(); + o2.name = "oxygen"; + atm.gases.put( "100%", o2 ); + s.persist( atm ); + tx.commit(); + s.close(); + + s = openSession(); + tx = s.beginTransaction(); + atm = (Atmosphere) s.get(Atmosphere.class, atm.id); + assertEquals( 1, atm.gases.size() ); + assertEquals( o2.name, atm.gases.get("100%").name ); + s.delete( atm ); + tx.commit(); + s.close(); + } + public IndexedCollectionTest(String x) { super( x ); } @@ -341,7 +362,9 @@ News.class, PressReleaseAgency.class, Painter.class, - Painting.class + Painting.class, + Atmosphere.class, + Gas.class }; } } |
From: <hib...@li...> - 2006-04-19 02:50:40
|
Author: epbernard Date: 2006-04-18 22:50:37 -0400 (Tue, 18 Apr 2006) New Revision: 9767 Modified: trunk/Hibernate3/src/org/hibernate/transaction/JTATransactionFactory.java Log: get rid of the Hip Hop exception Modified: trunk/Hibernate3/src/org/hibernate/transaction/JTATransactionFactory.java =================================================================== --- trunk/Hibernate3/src/org/hibernate/transaction/JTATransactionFactory.java 2006-04-19 02:24:45 UTC (rev 9766) +++ trunk/Hibernate3/src/org/hibernate/transaction/JTATransactionFactory.java 2006-04-19 02:50:37 UTC (rev 9767) @@ -83,7 +83,7 @@ ut = ( UserTransaction ) context.lookup( utName ); } catch ( NamingException e ) { - throw new TransactionException( "Unable to locate UserTrasnaction to check status" ); + throw new TransactionException( "Unable to locate UserTransaction to check status" ); } } return ut != null && JTAHelper.isInProgress( ut.getStatus() ); |
Author: epbernard Date: 2006-04-18 22:24:45 -0400 (Tue, 18 Apr 2006) New Revision: 9766 Modified: trunk/HibernateExt/metadata/src/java/org/hibernate/reflection/java/EJB3OverridenAnnotationReader.java trunk/HibernateExt/metadata/src/java/org/hibernate/reflection/java/xml/XMLContext.java trunk/HibernateExt/metadata/src/test/org/hibernate/test/reflection/java/xml/EJB3OverridenAnnotationReaderTest.java trunk/HibernateExt/metadata/src/test/org/hibernate/test/reflection/java/xml/TennisMatch.java trunk/HibernateExt/metadata/src/test/org/hibernate/test/reflection/java/xml/orm.xml Log: Support xml overriding for attribute and association overriding Modified: trunk/HibernateExt/metadata/src/java/org/hibernate/reflection/java/EJB3OverridenAnnotationReader.java =================================================================== --- trunk/HibernateExt/metadata/src/java/org/hibernate/reflection/java/EJB3OverridenAnnotationReader.java 2006-04-19 01:45:07 UTC (rev 9765) +++ trunk/HibernateExt/metadata/src/java/org/hibernate/reflection/java/EJB3OverridenAnnotationReader.java 2006-04-19 02:24:45 UTC (rev 9766) @@ -10,45 +10,52 @@ import java.util.Iterator; import java.util.List; import java.util.Map; +import javax.persistence.AssociationOverride; +import javax.persistence.AssociationOverrides; +import javax.persistence.AttributeOverride; +import javax.persistence.AttributeOverrides; +import javax.persistence.Column; +import javax.persistence.ColumnResult; +import javax.persistence.DiscriminatorColumn; +import javax.persistence.DiscriminatorType; +import javax.persistence.DiscriminatorValue; import javax.persistence.Embeddable; import javax.persistence.Entity; +import javax.persistence.EntityResult; +import javax.persistence.ExcludeDefaultListeners; +import javax.persistence.ExcludeSuperclassListeners; +import javax.persistence.FieldResult; +import javax.persistence.IdClass; +import javax.persistence.Inheritance; +import javax.persistence.InheritanceType; +import javax.persistence.JoinColumn; import javax.persistence.MappedSuperclass; +import javax.persistence.NamedNativeQueries; +import javax.persistence.NamedNativeQuery; +import javax.persistence.NamedQueries; +import javax.persistence.NamedQuery; import javax.persistence.PrimaryKeyJoinColumn; +import javax.persistence.PrimaryKeyJoinColumns; +import javax.persistence.QueryHint; import javax.persistence.SecondaryTable; import javax.persistence.SecondaryTables; +import javax.persistence.SequenceGenerator; +import javax.persistence.SqlResultSetMapping; +import javax.persistence.SqlResultSetMappings; import javax.persistence.Table; -import javax.persistence.PrimaryKeyJoinColumns; -import javax.persistence.IdClass; -import javax.persistence.Inheritance; -import javax.persistence.DiscriminatorValue; -import javax.persistence.DiscriminatorColumn; -import javax.persistence.SequenceGenerator; import javax.persistence.TableGenerator; -import javax.persistence.NamedQuery; -import javax.persistence.NamedQueries; -import javax.persistence.QueryHint; -import javax.persistence.DiscriminatorType; -import javax.persistence.InheritanceType; import javax.persistence.UniqueConstraint; -import javax.persistence.NamedNativeQuery; -import javax.persistence.NamedNativeQueries; -import javax.persistence.SqlResultSetMapping; -import javax.persistence.SqlResultSetMappings; -import javax.persistence.EntityResult; -import javax.persistence.FieldResult; -import javax.persistence.ColumnResult; -import javax.persistence.ExcludeDefaultListeners; -import javax.persistence.ExcludeSuperclassListeners; +import org.dom4j.Attribute; import org.dom4j.Element; -import org.dom4j.Attribute; +import org.hibernate.AnnotationException; import org.hibernate.annotationfactory.AnnotationDescriptor; import org.hibernate.annotationfactory.AnnotationFactory; +import org.hibernate.annotations.AccessType; import org.hibernate.reflection.Filter; import org.hibernate.reflection.java.xml.XMLContext; -import org.hibernate.AnnotationException; +import org.hibernate.util.ReflectHelper; import org.hibernate.util.StringHelper; -import org.hibernate.util.ReflectHelper; /** * Encapsulates the overriding of Java annotations from an EJB 3.0 descriptor. @@ -94,11 +101,17 @@ annotationToXml.put( SqlResultSetMappings.class, "sql-result-set-mapping" ); annotationToXml.put( ExcludeDefaultListeners.class, "exclude-default-listeners" ); annotationToXml.put( ExcludeSuperclassListeners.class, "exclude-superclass-listeners" ); + annotationToXml.put( AccessType.class, "access" ); + annotationToXml.put( AttributeOverride.class, "attribute-override" ); + annotationToXml.put( AttributeOverrides.class, "attribute-override" ); + annotationToXml.put( AttributeOverride.class, "association-override" ); + annotationToXml.put( AttributeOverrides.class, "association-override" ); } private XMLContext xmlContext; private String className; private String propertyName; + private boolean isField; private boolean isFieldAccess; private transient Annotation[] annotations; private static final String WORD_SEPARATOR = "-"; @@ -112,7 +125,7 @@ } else if ( el instanceof Field ) { propertyName = ( (Field) el ).getName(); - isFieldAccess = true; + isField = true; } else if ( el instanceof Method ) { Method method = (Method) el; @@ -130,7 +143,7 @@ } throw new RuntimeException( "Method " + propertyName + " is not a property getter" ); } - isFieldAccess = true; + isField = true; } else { className = null; @@ -206,6 +219,12 @@ if ( current != null ) annotationList.add( current ); current = getExcludeSuperclassListeners( tree, defaults ); if ( current != null ) annotationList.add( current ); + current = getAccessType( tree, defaults ); + if ( current != null ) annotationList.add( current ); + current = getAttributeOverrides( tree, defaults ); + if ( current != null ) annotationList.add( current ); + current = getAssociationOverrides( tree, defaults ); + if ( current != null ) annotationList.add( current ); this.annotations = annotationList.toArray( new Annotation[ annotationList.size() ] ); } else if ( propertyName != null ) { @@ -218,6 +237,173 @@ } } + private AssociationOverrides getAssociationOverrides(Element tree, XMLContext.Default defaults) { + List<AssociationOverride> attributes = (List<AssociationOverride>) buildAssociationOverrides( tree ); + if ( defaults.canUseJavaAnnotations() ) { + AssociationOverride annotation = super.getAnnotation( AssociationOverride.class ); + addAssociationOverrideIfNeeded( annotation, attributes ); + AssociationOverrides annotations = super.getAnnotation( AssociationOverrides.class ); + if (annotations != null) { + for (AssociationOverride current : annotations.value() ) { + addAssociationOverrideIfNeeded( current, attributes ); + } + } + } + if (attributes.size() > 0) { + AnnotationDescriptor ad = new AnnotationDescriptor( AssociationOverrides.class ); + ad.setValue( "value", attributes.toArray( new AssociationOverride[ attributes.size() ] ) ); + return AnnotationFactory.create( ad ); + } + else { + return null; + } + } + + private List<AssociationOverride> buildAssociationOverrides(Element element) { + List<Element> subelements = element == null ? null : element.elements( "association-override" ); + List<AssociationOverride> overrides = new ArrayList<AssociationOverride>(); + if (subelements != null && subelements.size() > 0) { + for (Element current : subelements) { + AnnotationDescriptor override = new AnnotationDescriptor( AssociationOverride.class ); + copyStringAttribute( override, current, "name", true ); + override.setValue( "joinColumns", getJoinColumns( current ) ); + overrides.add( (AssociationOverride) AnnotationFactory.create( override ) ); + } + } + return overrides; + } + + private JoinColumn[] getJoinColumns(Element element) { + List<Element> subelements = element != null ? element.elements( "join-column" ) : null; + List<JoinColumn> joinColumns = new ArrayList<JoinColumn>(); + if ( subelements != null) { + for (Element subelement : subelements) { + AnnotationDescriptor column = new AnnotationDescriptor( JoinColumn.class ); + copyStringAttribute(column, subelement, "name", false); + copyStringAttribute(column, subelement, "referenced-column-name", false); + copyBooleanAttribute(column, subelement, "unique"); + copyBooleanAttribute(column, subelement, "nullable"); + copyBooleanAttribute(column, subelement, "insertable"); + copyBooleanAttribute(column, subelement, "updatable"); + copyStringAttribute(column, subelement, "column-definition", false); + copyStringAttribute(column, subelement, "table", false); + joinColumns.add( (JoinColumn) AnnotationFactory.create( column ) ); + } + } + return joinColumns.toArray( new JoinColumn[ joinColumns.size() ] ); + } + + private void addAssociationOverrideIfNeeded(AssociationOverride annotation, List<AssociationOverride> overrides) { + if (annotation != null) { + String overrideName = annotation.name(); + boolean present = false; + for (AssociationOverride current : overrides ) { + if ( current.name().equals( overrideName ) ) { + present = true; + break; + } + } + if (!present) overrides.add(annotation); + } + } + + private AttributeOverrides getAttributeOverrides(Element tree, XMLContext.Default defaults) { + List<AttributeOverride> attributes = (List<AttributeOverride>) buildAttributeOverrides( tree ); + if ( defaults.canUseJavaAnnotations() ) { + AttributeOverride annotation = super.getAnnotation( AttributeOverride.class ); + addAttributeOverrideIfNeeded( annotation, attributes ); + AttributeOverrides annotations = super.getAnnotation( AttributeOverrides.class ); + if (annotations != null) { + for (AttributeOverride current : annotations.value() ) { + addAttributeOverrideIfNeeded( current, attributes ); + } + } + } + if (attributes.size() > 0) { + AnnotationDescriptor ad = new AnnotationDescriptor( AttributeOverrides.class ); + ad.setValue( "value", attributes.toArray( new AttributeOverride[ attributes.size() ] ) ); + return AnnotationFactory.create( ad ); + } + else { + return null; + } + } + + private List<AttributeOverride> buildAttributeOverrides(Element element) { + List<Element> subelements = element == null ? null : element.elements( "attribute-override" ); + List<AttributeOverride> overrides = new ArrayList<AttributeOverride>(); + if (subelements != null && subelements.size() > 0) { + for (Element current : subelements) { + AnnotationDescriptor override = new AnnotationDescriptor( AttributeOverride.class ); + copyStringAttribute( override, current, "name", true ); + override.setValue( "column", getColumn( current, true ) ); + overrides.add( (AttributeOverride) AnnotationFactory.create( override ) ); + } + } + return overrides; + } + + private Column getColumn(Element element, boolean isMandatory) { + Element subelement = element != null ? element.element( "column" ) : null; + if ( subelement != null ) { + AnnotationDescriptor column = new AnnotationDescriptor( Column.class ); + copyStringAttribute(column, subelement, "name", false); + copyBooleanAttribute(column, subelement, "unique"); + copyBooleanAttribute(column, subelement, "nullable"); + copyBooleanAttribute(column, subelement, "insertable"); + copyBooleanAttribute(column, subelement, "updatable"); + copyStringAttribute(column, subelement, "column-definition", false); + copyStringAttribute(column, subelement, "table", false); + copyIntegerAttribute(column, subelement, "length"); + copyIntegerAttribute(column, subelement, "precision"); + copyIntegerAttribute(column, subelement, "scale"); + return (Column) AnnotationFactory.create( column ); + } + else { + if ( isMandatory ) throw new AnnotationException( element.getPath() + ".column is mandatory. " + SCHEMA_VALIDATION); + return null; + } + } + + private void addAttributeOverrideIfNeeded(AttributeOverride annotation, List<AttributeOverride> overrides) { + if (annotation != null) { + String overrideName = annotation.name(); + boolean present = false; + for (AttributeOverride current : overrides ) { + if ( current.name().equals( overrideName ) ) { + present = true; + break; + } + } + if (!present) overrides.add(annotation); + } + } + + private AccessType getAccessType(Element tree, XMLContext.Default defaults) { + String access = tree == null ? null : tree.attributeValue( "access" ); + if (access != null) { + AnnotationDescriptor ad = new AnnotationDescriptor(AccessType.class); + ad.setValue( "value", access ); + isFieldAccess = "field".equalsIgnoreCase( access ); + return AnnotationFactory.create(ad); + } + else if ( defaults.canUseJavaAnnotations() && super.isAnnotationPresent(AccessType.class) ) { + AccessType annotation = super.getAnnotation( AccessType.class ); + isFieldAccess = "field".equalsIgnoreCase( annotation != null ? annotation.value() : null ); + return annotation; + } + else if ( defaults.getAccess() != null ) { + AnnotationDescriptor ad = new AnnotationDescriptor(AccessType.class); + ad.setValue( "value", defaults.getAccess() ); + isFieldAccess = "field".equalsIgnoreCase( defaults.getAccess() ); + return AnnotationFactory.create(ad); + } + else { + isFieldAccess = false; + return null; + } + } + private ExcludeSuperclassListeners getExcludeSuperclassListeners(Element tree, XMLContext.Default defaults) { return (ExcludeSuperclassListeners) getMarkerAnnotation(ExcludeSuperclassListeners.class, tree, defaults); } @@ -866,14 +1052,8 @@ ) { String attribute = element.attributeValue( attributeName ); if (attribute != null) { - StringBuilder annotationAttributeName = new StringBuilder( attributeName ); - int index = annotationAttributeName.indexOf( WORD_SEPARATOR ); - while ( index != -1 ) { - annotationAttributeName.deleteCharAt( index ); - annotationAttributeName.setCharAt( index, Character.toUpperCase( annotationAttributeName.charAt( index ) ) ); - index = annotationAttributeName.indexOf( WORD_SEPARATOR ); - } - annotation.setValue( annotationAttributeName.toString(), attribute ); + String annotationAttributeName = getJavaAttributeNameFromXMLOne( attributeName ); + annotation.setValue( annotationAttributeName, attribute ); } else { if (mandatory) { @@ -885,26 +1065,39 @@ private void copyIntegerAttribute(AnnotationDescriptor annotation, Element element, String attributeName) { String attribute = element.attributeValue( attributeName ); if (attribute != null) { - StringBuilder annotationAttributeName = new StringBuilder( attributeName ); - int index = annotationAttributeName.indexOf( WORD_SEPARATOR ); - while ( index != -1 ) { - annotationAttributeName.deleteCharAt( index ); - annotationAttributeName.setCharAt( index, Character.toUpperCase( annotationAttributeName.charAt( index ) )); - index = annotationAttributeName.indexOf( WORD_SEPARATOR ); - } - annotation.setValue( annotationAttributeName.toString(), attribute ); + String annotationAttributeName = getJavaAttributeNameFromXMLOne( attributeName ); + annotation.setValue( annotationAttributeName, attribute ); try { int length = Integer.parseInt( attribute ); - annotation.setValue( annotationAttributeName.toString(), length ); + annotation.setValue( annotationAttributeName, length ); } catch (NumberFormatException e) { - throw new AnnotationException( attributeName + " not parseable: " + attribute + " (" + SCHEMA_VALIDATION + ")" ); + throw new AnnotationException( element.getPath() + attributeName + " not parseable: " + attribute + " (" + SCHEMA_VALIDATION + ")" ); } } } + private String getJavaAttributeNameFromXMLOne(String attributeName) { + StringBuilder annotationAttributeName = new StringBuilder( attributeName ); + int index = annotationAttributeName.indexOf( WORD_SEPARATOR ); + while ( index != -1 ) { + annotationAttributeName.deleteCharAt( index ); + annotationAttributeName.setCharAt( index, Character.toUpperCase( annotationAttributeName.charAt( index ) )); + index = annotationAttributeName.indexOf( WORD_SEPARATOR ); + } + return annotationAttributeName.toString(); + } + private void copyStringElement(Element element, AnnotationDescriptor ad, String annotationAttribute) { String discr = element.getTextTrim(); ad.setValue( annotationAttribute, discr ); } + + private void copyBooleanAttribute(AnnotationDescriptor descriptor, Element element, String attribute) { + String attributeValue = element.attributeValue( attribute ); + if ( StringHelper.isNotEmpty( attributeValue ) ) { + String javaAttribute = getJavaAttributeNameFromXMLOne( attribute ); + descriptor.setValue( javaAttribute, Boolean.parseBoolean( attributeValue ) ); + } + } } Modified: trunk/HibernateExt/metadata/src/java/org/hibernate/reflection/java/xml/XMLContext.java =================================================================== --- trunk/HibernateExt/metadata/src/java/org/hibernate/reflection/java/xml/XMLContext.java 2006-04-19 01:45:07 UTC (rev 9765) +++ trunk/HibernateExt/metadata/src/java/org/hibernate/reflection/java/xml/XMLContext.java 2006-04-19 02:24:45 UTC (rev 9766) @@ -87,6 +87,8 @@ localDefault.override( defaults ); attribute = element.attribute( "metadata-complete" ); if (attribute != null) localDefault.setMetadataComplete( (Boolean) attribute.getData() ); + String access = element.attributeValue( "access" ); + if (access != null) localDefault.setAccess( access ); defaultsOverriding.put( className, localDefault ); log.debug( "Adding XML overriding information for " + className); Modified: trunk/HibernateExt/metadata/src/test/org/hibernate/test/reflection/java/xml/EJB3OverridenAnnotationReaderTest.java =================================================================== --- trunk/HibernateExt/metadata/src/test/org/hibernate/test/reflection/java/xml/EJB3OverridenAnnotationReaderTest.java 2006-04-19 01:45:07 UTC (rev 9765) +++ trunk/HibernateExt/metadata/src/test/org/hibernate/test/reflection/java/xml/EJB3OverridenAnnotationReaderTest.java 2006-04-19 02:24:45 UTC (rev 9766) @@ -25,6 +25,8 @@ import javax.persistence.TableGenerator; import javax.persistence.ExcludeSuperclassListeners; import javax.persistence.ExcludeDefaultListeners; +import javax.persistence.AttributeOverrides; +import javax.persistence.AssociationOverrides; import junit.framework.TestCase; import org.dom4j.DocumentException; @@ -100,7 +102,16 @@ assertNull( "Mutualize PKJC into PKJCs", reader.getAnnotation( PrimaryKeyJoinColumn.class) ); assertNotNull( reader.getAnnotation( PrimaryKeyJoinColumns.class) ); assertEquals( "PrimaryKeyJoinColumn overrden", "id", reader.getAnnotation( PrimaryKeyJoinColumns.class).value()[0].name() ); + assertNotNull( reader.getAnnotation( AttributeOverrides.class ) ); + assertEquals( "Wrong deduplication", 3, reader.getAnnotation( AttributeOverrides.class ).value().length ); + assertEquals( "Wrong priority (XML vs java annotations)", "fld_net", reader.getAnnotation( AttributeOverrides.class ).value()[0].column().name() ); + assertEquals( "Column mapping", 2, reader.getAnnotation( AttributeOverrides.class ).value()[1].column().scale() ); + assertEquals( "Column mapping", true, reader.getAnnotation( AttributeOverrides.class ).value()[1].column().unique() ); + assertNotNull( reader.getAnnotation( AssociationOverrides.class ) ); + assertEquals( "no XML processing", 1, reader.getAnnotation( AssociationOverrides.class ).value().length ); + assertEquals( "wrong xml processing", "id", reader.getAnnotation( AssociationOverrides.class ).value()[0].joinColumns()[0].referencedColumnName() ); + reader = new EJB3OverridenAnnotationReader(SocialSecurityPhysicalAccount.class, context); assertNotNull( reader.getAnnotation( IdClass.class ) ); assertEquals( "id-class not used", SocialSecurityNumber.class, reader.getAnnotation( IdClass.class ).value() ); Modified: trunk/HibernateExt/metadata/src/test/org/hibernate/test/reflection/java/xml/TennisMatch.java =================================================================== --- trunk/HibernateExt/metadata/src/test/org/hibernate/test/reflection/java/xml/TennisMatch.java 2006-04-19 01:45:07 UTC (rev 9765) +++ trunk/HibernateExt/metadata/src/test/org/hibernate/test/reflection/java/xml/TennisMatch.java 2006-04-19 02:24:45 UTC (rev 9766) @@ -1,14 +1,21 @@ //$Id: $ package org.hibernate.test.reflection.java.xml; +import javax.persistence.AttributeOverride; +import javax.persistence.AttributeOverrides; import javax.persistence.Entity; import javax.persistence.PrimaryKeyJoinColumn; +import javax.persistence.Column; /** * @author Emmanuel Bernard */ @Entity -@PrimaryKeyJoinColumn(name="match_id") +@PrimaryKeyJoinColumn(name = "match_id") +@AttributeOverrides( + {@AttributeOverride(name = "net", column = @Column(name="net") ), + @AttributeOverride(name = "line", column = @Column(name="line") ) + } ) public class TennisMatch { } Modified: trunk/HibernateExt/metadata/src/test/org/hibernate/test/reflection/java/xml/orm.xml =================================================================== --- trunk/HibernateExt/metadata/src/test/org/hibernate/test/reflection/java/xml/orm.xml 2006-04-19 01:45:07 UTC (rev 9765) +++ trunk/HibernateExt/metadata/src/test/org/hibernate/test/reflection/java/xml/orm.xml 2006-04-19 02:24:45 UTC (rev 9766) @@ -58,6 +58,15 @@ </entity> <entity class="TennisMatch"> <primary-key-join-column name="id"/> + <attribute-override name="net"> + <column name="fld_net"/> + </attribute-override> + <attribute-override name="ground"> + <column name="fld_ground" unique="true" scale="2"/> + </attribute-override> + <association-override name="referer"> + <join-column name="referer_id" referenced-column-name="id"/> + </association-override> </entity> <entity class="SocialSecurityPhysicalAccount"> <id-class class="org.hibernate.test.reflection.java.xml.SocialSecurityNumber"/> |
From: <hib...@li...> - 2006-04-19 01:45:11
|
Author: max...@jb... Date: 2006-04-18 21:45:07 -0400 (Tue, 18 Apr 2006) New Revision: 9765 Modified: trunk/Hibernate3/src/org/hibernate/engine/FilterDefinition.java Log: HHH-1647 Missing serializable Modified: trunk/Hibernate3/src/org/hibernate/engine/FilterDefinition.java =================================================================== --- trunk/Hibernate3/src/org/hibernate/engine/FilterDefinition.java 2006-04-19 01:45:03 UTC (rev 9764) +++ trunk/Hibernate3/src/org/hibernate/engine/FilterDefinition.java 2006-04-19 01:45:07 UTC (rev 9765) @@ -3,6 +3,7 @@ import org.hibernate.type.Type; +import java.io.Serializable; import java.util.Map; import java.util.HashMap; import java.util.Set; @@ -13,7 +14,7 @@ * * @author Steve Ebersole */ -public class FilterDefinition { +public class FilterDefinition implements Serializable { private final String filterName; private final String defaultFilterCondition; private final Map parameterTypes = new HashMap(); |
From: <hib...@li...> - 2006-04-19 01:45:07
|
Author: max...@jb... Date: 2006-04-18 21:45:03 -0400 (Tue, 18 Apr 2006) New Revision: 9764 Modified: branches/Branch_3_1/Hibernate3/src/org/hibernate/engine/FilterDefinition.java Log: HHH-1647 Missing serializable Modified: branches/Branch_3_1/Hibernate3/src/org/hibernate/engine/FilterDefinition.java =================================================================== --- branches/Branch_3_1/Hibernate3/src/org/hibernate/engine/FilterDefinition.java 2006-04-19 00:36:18 UTC (rev 9763) +++ branches/Branch_3_1/Hibernate3/src/org/hibernate/engine/FilterDefinition.java 2006-04-19 01:45:03 UTC (rev 9764) @@ -3,6 +3,7 @@ import org.hibernate.type.Type; +import java.io.Serializable; import java.util.Map; import java.util.HashMap; import java.util.Set; @@ -13,7 +14,7 @@ * * @author Steve Ebersole */ -public class FilterDefinition { +public class FilterDefinition implements Serializable { private final String filterName; private final String defaultFilterCondition; private final Map parameterTypes = new HashMap(); |
Author: max...@jb... Date: 2006-04-18 20:36:18 -0400 (Tue, 18 Apr 2006) New Revision: 9763 Added: trunk/HibernateExt/tools/src/java/org/hibernate/tool/ant/HQLExporterTask.java trunk/HibernateExt/tools/src/java/org/hibernate/tool/hbm2x/HQLExporter.java trunk/HibernateExt/tools/src/testsupport/querytest-hibernate.cfg.xml Modified: trunk/HibernateExt/tools/src/java/org/hibernate/tool/ant/ExporterTask.java trunk/HibernateExt/tools/src/java/org/hibernate/tool/ant/HibernateToolTask.java trunk/HibernateExt/tools/src/test/org/hibernate/tool/ant/HibernateToolTest.java trunk/HibernateExt/tools/src/testsupport/anttest-build.xml Log: initial <hql> support (HBX-641) Modified: trunk/HibernateExt/tools/src/java/org/hibernate/tool/ant/ExporterTask.java =================================================================== --- trunk/HibernateExt/tools/src/java/org/hibernate/tool/ant/ExporterTask.java 2006-04-19 00:35:12 UTC (rev 9762) +++ trunk/HibernateExt/tools/src/java/org/hibernate/tool/ant/ExporterTask.java 2006-04-19 00:36:18 UTC (rev 9763) @@ -66,8 +66,7 @@ public void validateParameters() { if(getDestdir()==null) { throw new BuildException("destdir must be set, either locally or on <hibernatetool>"); - } - + } } public void addConfiguredPropertySet(PropertySet ps) { Added: trunk/HibernateExt/tools/src/java/org/hibernate/tool/ant/HQLExporterTask.java =================================================================== --- trunk/HibernateExt/tools/src/java/org/hibernate/tool/ant/HQLExporterTask.java 2006-04-19 00:35:12 UTC (rev 9762) +++ trunk/HibernateExt/tools/src/java/org/hibernate/tool/ant/HQLExporterTask.java 2006-04-19 00:36:18 UTC (rev 9763) @@ -0,0 +1,45 @@ +package org.hibernate.tool.ant; + +import org.hibernate.tool.hbm2x.Exporter; +import org.hibernate.tool.hbm2x.HQLExporter; + +public class HQLExporterTask extends ExporterTask { + + private String query; + private String filename; + + public HQLExporterTask(HibernateToolTask parent) { + super( parent ); + } + + protected Exporter configureExporter(Exporter exp) { + HQLExporter exporter = (HQLExporter) exp; + exporter.setQuery(query); + exporter.setFilename(filename); + super.configureExporter( exp ); + return exporter; + } + + protected Exporter createExporter() { + HQLExporter exporter = new HQLExporter(); + return exporter; + } + + public void addText(String text) { + query = text; + } + + public void setDestFile(String filename) { + this.filename = filename; + } + + public void execute() { + parent.log("Executing: [" + query + "]"); + super.execute(); + } + public String getName() { + return "hql (Executes HQL queries)"; + } + + +} Modified: trunk/HibernateExt/tools/src/java/org/hibernate/tool/ant/HibernateToolTask.java =================================================================== --- trunk/HibernateExt/tools/src/java/org/hibernate/tool/ant/HibernateToolTask.java 2006-04-19 00:35:12 UTC (rev 9762) +++ trunk/HibernateExt/tools/src/java/org/hibernate/tool/ant/HibernateToolTask.java 2006-04-19 00:36:18 UTC (rev 9763) @@ -113,6 +113,13 @@ return generator; } + + public HQLExporterTask createHql() { + HQLExporterTask generator = new HQLExporterTask(this); + generators.add(generator); + return generator; + } + /** * Set the classpath to be used when running the Java class * Added: trunk/HibernateExt/tools/src/java/org/hibernate/tool/hbm2x/HQLExporter.java =================================================================== --- trunk/HibernateExt/tools/src/java/org/hibernate/tool/hbm2x/HQLExporter.java 2006-04-19 00:35:12 UTC (rev 9762) +++ trunk/HibernateExt/tools/src/java/org/hibernate/tool/hbm2x/HQLExporter.java 2006-04-19 00:36:18 UTC (rev 9763) @@ -0,0 +1,76 @@ +package org.hibernate.tool.hbm2x; + +import java.io.File; +import java.io.FileWriter; +import java.io.IOException; +import java.io.PrintWriter; +import java.util.Iterator; +import java.util.List; + +import org.hibernate.SessionFactory; +import org.hibernate.classic.Session; + +/** + * Placeholder exporter for query execution. + * + **/ +public class HQLExporter extends AbstractExporter { + + private String query; + private String filename; + + public void doStart() { + Session session = null; + SessionFactory sessionFactory = null; + try { + sessionFactory = getConfiguration().buildSessionFactory(); + session = sessionFactory.openSession(); + + List list = session.createQuery(getQuery()).list(); + + if(getFileName()!=null) { + PrintWriter pw = null; + try { + File file = new File( getOutputDirectory(), getFileName() ); + getTemplateHelper().ensureExistence( file ); + pw = new PrintWriter( new FileWriter( file, true ) ); + getArtifactCollector().addFile( file, "query-output" ); + + for (Iterator iter = list.iterator(); iter.hasNext();) { + Object element = iter.next(); + pw.println(element); + } + + } + catch (IOException e) { + throw new ExporterException("Could not write query output",e); + } finally { + if(pw!=null) { + pw.flush(); + pw.close(); + } + } + } + } finally { + session.close(); + session.getSessionFactory().close(); + } + } + + private String getFileName() { + return filename; + } + + public void setFilename(String filename) { + this.filename = filename; + } + + private String getQuery() { + return query; + } + + public void setQuery(String query) { + this.query = query; + } + +} Modified: trunk/HibernateExt/tools/src/test/org/hibernate/tool/ant/HibernateToolTest.java =================================================================== --- trunk/HibernateExt/tools/src/test/org/hibernate/tool/ant/HibernateToolTest.java 2006-04-19 00:35:12 UTC (rev 9762) +++ trunk/HibernateExt/tools/src/test/org/hibernate/tool/ant/HibernateToolTest.java 2006-04-19 00:36:18 UTC (rev 9763) @@ -149,9 +149,16 @@ } catch(BuildException be) { // should happen! } + } + + public void testQuery() { + executeTarget("testquery"); + File baseDir = new File(project.getProperty("build.dir"), "querytest"); + + assertTrue(new File(baseDir, "queryresult.txt").exists()); + } - public static Test suite() { return new TestSuite(HibernateToolTest.class); } Modified: trunk/HibernateExt/tools/src/testsupport/anttest-build.xml =================================================================== --- trunk/HibernateExt/tools/src/testsupport/anttest-build.xml 2006-04-19 00:35:12 UTC (rev 9762) +++ trunk/HibernateExt/tools/src/testsupport/anttest-build.xml 2006-04-19 00:36:18 UTC (rev 9763) @@ -329,4 +329,14 @@ <jdbcconfiguration propertyfile="../../etc/hibernate.properties" packageName="org.h3.test" reversestrategy="org.hibernate.cfg.reveng.DefaultReverseEngineeringStrategy" /> </hibernatetool> </target> + + <target name="testquery" description="test the query tasks"> + <taskdef name="hibernatetool" classname="org.hibernate.tool.ant.HibernateToolTask" classpathref="tasks.classpath" /> + <hibernatetool destdir="${build.dir}/querytest"> + <configuration propertyfile="../../etc/hibernate.properties" configurationfile="querytest-hibernate.cfg.xml" /> + <hql>from java.lang.Object</hql> + <hql>from java.io.Serializable</hql> + <hql destfile="queryresult.txt">from java.io.Serializable</hql> + </hibernatetool> + </target> </project> Added: trunk/HibernateExt/tools/src/testsupport/querytest-hibernate.cfg.xml =================================================================== --- trunk/HibernateExt/tools/src/testsupport/querytest-hibernate.cfg.xml 2006-04-19 00:35:12 UTC (rev 9762) +++ trunk/HibernateExt/tools/src/testsupport/querytest-hibernate.cfg.xml 2006-04-19 00:36:18 UTC (rev 9763) @@ -0,0 +1,9 @@ +<!DOCTYPE hibernate-configuration PUBLIC + "-//Hibernate/Hibernate Configuration DTD 3.0//EN" + "http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd"> + +<hibernate-configuration> + <session-factory> + <property name="show_sql">true</property> + </session-factory> +</hibernate-configuration> \ No newline at end of file |
From: <hib...@li...> - 2006-04-19 00:35:22
|
Author: max...@jb... Date: 2006-04-18 20:35:12 -0400 (Tue, 18 Apr 2006) New Revision: 9762 Added: trunk/HibernateExt/tools/src/test/org/hibernate/tool/test/jdbc2cfg/badforeignkeytest.reveng.xml Log: missing add for foreignkeytest Added: trunk/HibernateExt/tools/src/test/org/hibernate/tool/test/jdbc2cfg/badforeignkeytest.reveng.xml =================================================================== --- trunk/HibernateExt/tools/src/test/org/hibernate/tool/test/jdbc2cfg/badforeignkeytest.reveng.xml 2006-04-18 16:45:06 UTC (rev 9761) +++ trunk/HibernateExt/tools/src/test/org/hibernate/tool/test/jdbc2cfg/badforeignkeytest.reveng.xml 2006-04-19 00:35:12 UTC (rev 9762) @@ -0,0 +1,12 @@ +<?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> + + <table name="WORKS_ON"> + <!-- defining a constraint that is already in the database --> + <foreign-key constraint-name="WORKSON_EMPLOYEE" foreign-table="EMPLOYEE"> + <column-ref local-column="employee_id" foreign-column="id"/> + </foreign-key> + </table> + +</hibernate-reverse-engineering> \ No newline at end of file |
Author: max...@jb... Date: 2006-04-18 12:45:06 -0400 (Tue, 18 Apr 2006) New Revision: 9761 Modified: trunk/HibernateExt/tools/src/java/org/hibernate/cfg/reveng/DefaultReverseEngineeringStrategy.java trunk/HibernateExt/tools/src/java/org/hibernate/cfg/reveng/ReverseEngineeringSettings.java trunk/HibernateExt/tools/src/test/org/hibernate/tool/JDBCMetaDataBinderTestCase.java trunk/HibernateExt/tools/src/test/org/hibernate/tool/hbm2x/GenerateFromJDBCTest.java trunk/HibernateExt/tools/src/test/org/hibernate/tool/test/jdbc2cfg/RevEngForeignKeyTests.java trunk/HibernateExt/tools/src/test/org/hibernate/tool/test/jdbc2cfg/foreignkeytest.reveng.xml Log: more tests for foreignkey handling introduce per-reverseengineering settings for some of the handling Modified: trunk/HibernateExt/tools/src/java/org/hibernate/cfg/reveng/DefaultReverseEngineeringStrategy.java =================================================================== --- trunk/HibernateExt/tools/src/java/org/hibernate/cfg/reveng/DefaultReverseEngineeringStrategy.java 2006-04-18 16:44:02 UTC (rev 9760) +++ trunk/HibernateExt/tools/src/java/org/hibernate/cfg/reveng/DefaultReverseEngineeringStrategy.java 2006-04-18 16:45:06 UTC (rev 9761) @@ -20,7 +20,7 @@ private static Set AUTO_OPTIMISTICLOCK_COLUMNS; - private ReverseEngineeringSettings settings; + private ReverseEngineeringSettings settings = new ReverseEngineeringSettings(); static { AUTO_OPTIMISTICLOCK_COLUMNS = new HashSet(); AUTO_OPTIMISTICLOCK_COLUMNS.add("version"); @@ -31,7 +31,7 @@ public DefaultReverseEngineeringStrategy() { super(); } - + public String columnToPropertyName(TableIdentifier table, String columnName) { String decapitalize = Introspector.decapitalize( toUpperCamelCase(columnName) ); @@ -155,7 +155,7 @@ } public boolean useColumnForOptimisticLock(TableIdentifier identifier, String column) { - if(settings.hasDefaultOptimisticLockDetection()) { + if(settings.hasAutoOptimisticLockDetection()) { return AUTO_OPTIMISTICLOCK_COLUMNS.contains(column.toLowerCase())?true:false; } else { return false; @@ -175,11 +175,11 @@ } public boolean excludeForeignKeyAsCollection(String keyname, TableIdentifier fromTable, List fromColumns, TableIdentifier referencedTable, List referencedColumns) { - return false; // TODO: default to true ? TODO: named include ? + return !settings.createCollectionForForeignKey(); } public boolean excludeForeignKeyAsManytoOne(String keyname, TableIdentifier fromTable, List fromColumns, TableIdentifier referencedTable, List referencedColumns) { - return false; + return !settings.createManyToOneForForeignKey(); } public boolean isForeignKeyCollectionInverse(String name, TableIdentifier foreignKeyTable, List columns, TableIdentifier foreignKeyReferencedTable, List referencedColumns) { Modified: trunk/HibernateExt/tools/src/java/org/hibernate/cfg/reveng/ReverseEngineeringSettings.java =================================================================== --- trunk/HibernateExt/tools/src/java/org/hibernate/cfg/reveng/ReverseEngineeringSettings.java 2006-04-18 16:44:02 UTC (rev 9760) +++ trunk/HibernateExt/tools/src/java/org/hibernate/cfg/reveng/ReverseEngineeringSettings.java 2006-04-18 16:45:06 UTC (rev 9761) @@ -5,8 +5,10 @@ //final ReverseEngineeringStrategy rootStrategy; - String defaultPackageName = ""; - private boolean defaultOptimisticLockDetection = true; + private String defaultPackageName = ""; + private boolean autoOptimisticLockDetection = true; + private boolean createCollectionForForeignKey = true; + private boolean createManyToOneForForeignKey = true; //public ReverseEngineeringSettings(ReverseEngineeringStrategy rootStrategy) { // this.rootStrategy = rootStrategy; @@ -26,16 +28,39 @@ return defaultPackageName; } - public boolean hasDefaultOptimisticLockDetection() { - return defaultOptimisticLockDetection ; + /** If true, reverse engineering strategy will try and autodetect columns for optimistc locking, e.g. VERSION and TIMESTAMP */ + public boolean hasAutoOptimisticLockDetection() { + return autoOptimisticLockDetection ; } - public void setDefaultOptimisticLockDetection( + public void setAutoOptimisticLockDetection( boolean optimisticLockSupportEnabled) { - this.defaultOptimisticLockDetection = optimisticLockSupportEnabled; + this.autoOptimisticLockDetection = optimisticLockSupportEnabled; } + + /** if true, a collection will be mapped for each foreignkey */ + public boolean createCollectionForForeignKey() { + return createCollectionForForeignKey; + } + public ReverseEngineeringSettings setCreateCollectionForForeignKey( + boolean createCollectionForForeignKey) { + this.createCollectionForForeignKey = createCollectionForForeignKey; + return this; + } + + /** if true, a many-to-one association will be created for each foreignkey found */ + public boolean createManyToOneForForeignKey() { + return createManyToOneForForeignKey; + } + + public ReverseEngineeringSettings setCreateManyToOneForForeignKey( + boolean createManyToOneForForeignKey) { + this.createManyToOneForForeignKey = createManyToOneForForeignKey; + return this; + } + /** 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 rootStrategy; Modified: trunk/HibernateExt/tools/src/test/org/hibernate/tool/JDBCMetaDataBinderTestCase.java =================================================================== --- trunk/HibernateExt/tools/src/test/org/hibernate/tool/JDBCMetaDataBinderTestCase.java 2006-04-18 16:44:02 UTC (rev 9760) +++ trunk/HibernateExt/tools/src/test/org/hibernate/tool/JDBCMetaDataBinderTestCase.java 2006-04-18 16:45:06 UTC (rev 9761) @@ -129,7 +129,7 @@ } protected void tearDown() throws Exception { - executeDDL(getDropSQL(), true ); + executeDDL(getDropSQL(), false); super.tearDown(); } /** Modified: trunk/HibernateExt/tools/src/test/org/hibernate/tool/hbm2x/GenerateFromJDBCTest.java =================================================================== --- trunk/HibernateExt/tools/src/test/org/hibernate/tool/hbm2x/GenerateFromJDBCTest.java 2006-04-18 16:44:02 UTC (rev 9760) +++ trunk/HibernateExt/tools/src/test/org/hibernate/tool/hbm2x/GenerateFromJDBCTest.java 2006-04-18 16:45:06 UTC (rev 9761) @@ -5,7 +5,9 @@ package org.hibernate.tool.hbm2x; import java.io.File; +import java.util.HashMap; import java.util.Iterator; +import java.util.Map; import org.dom4j.Document; import org.dom4j.DocumentException; @@ -16,6 +18,7 @@ import org.hibernate.cfg.Configuration; import org.hibernate.cfg.JDBCMetaDataConfiguration; import org.hibernate.cfg.reveng.DefaultReverseEngineeringStrategy; +import org.hibernate.cfg.reveng.ReverseEngineeringSettings; import org.hibernate.mapping.PersistentClass; import org.hibernate.tool.JDBCMetaDataBinderTestCase; import org.hibernate.tool.test.TestHelper; @@ -52,7 +55,7 @@ protected void configure(JDBCMetaDataConfiguration cfg2configure) { DefaultReverseEngineeringStrategy configurableNamingStrategy = new DefaultReverseEngineeringStrategy(); - configurableNamingStrategy.setPackageName("org.reveng"); + configurableNamingStrategy.setSettings(new ReverseEngineeringSettings().setDefaultPackageName("org.reveng").setCreateCollectionForForeignKey(false)); cfg2configure.setReverseEngineeringStrategy(configurableNamingStrategy); } @@ -136,7 +139,7 @@ // Validate the Generator and it has no arguments XPath xpath = DocumentHelper.createXPath("//hibernate-configuration/session-factory/mapping"); Element[] elements = (Element[]) xpath.selectNodes(document).toArray(new Element[0]); - assertEquals("Expected to get one mapping", elements.length , 2); + assertEquals(2, elements.length); for (int i = 0; i < elements.length; i++) { Element element = elements[i]; Modified: trunk/HibernateExt/tools/src/test/org/hibernate/tool/test/jdbc2cfg/RevEngForeignKeyTests.java =================================================================== --- trunk/HibernateExt/tools/src/test/org/hibernate/tool/test/jdbc2cfg/RevEngForeignKeyTests.java 2006-04-18 16:44:02 UTC (rev 9760) +++ trunk/HibernateExt/tools/src/test/org/hibernate/tool/test/jdbc2cfg/RevEngForeignKeyTests.java 2006-04-18 16:45:06 UTC (rev 9761) @@ -27,6 +27,7 @@ public class RevEngForeignKeyTests extends JDBCMetaDataBinderTestCase { private static final String OVERRIDETEST_FOREIGNKEY_XML = "org/hibernate/tool/test/jdbc2cfg/foreignkeytest.reveng.xml"; + private static final String BAD_FOREIGNKEY_XML = "org/hibernate/tool/test/jdbc2cfg/badforeignkeytest.reveng.xml";; public static Test suite() { return new TestSuite(RevEngForeignKeyTests.class); @@ -100,7 +101,26 @@ assertEquals("id", worksOn.getIdentifierProperty().getName()); } + + public void testDuplicateForeignKeyDefinition() { + + OverrideRepository or = buildOverrideRepository(); + + or.addResource(BAD_FOREIGNKEY_XML); + ReverseEngineeringStrategy repository = or.getReverseEngineeringStrategy(new DefaultReverseEngineeringStrategy()); + JDBCMetaDataConfiguration localCfg = new JDBCMetaDataConfiguration(); + localCfg.setReverseEngineeringStrategy(repository); + + try { + localCfg.readFromJDBC(); + fail("Should fail because foreign key is already defined in the database"); // maybe we should ignore the definition and only listen to what is overwritten ? For now we error. + } catch(MappingException me) { + assertTrue(me.getMessage().indexOf("already defined")>=0); + } + + } + private void assertPropertyNotExists(PersistentClass employee, String name, String msg) { try { employee.getProperty(name); @@ -124,7 +144,7 @@ return new String[] { "create table PROJECT ( project_id integer not null, name varchar(50), team_lead integer, primary key (project_id) )", "create table EMPLOYEE ( id integer not null, name varchar(50), manager_id integer, primary key (id), constraint employee_manager foreign key (manager_id) references EMPLOYEE)", - "create table WORKS_ON ( project_id integer not null, employee_id integer not null, start_date date, end_date date, primary key (project_id, employee_id), foreign key (employee_id) references EMPLOYEE, foreign key (project_id) references PROJECT )", + "create table WORKS_ON ( project_id integer not null, employee_id integer not null, start_date date, end_date date, primary key (project_id, employee_id), constraint workson_employee foreign key (employee_id) references EMPLOYEE, foreign key (project_id) references PROJECT )", "alter table PROJECT add constraint project_manager foreign key (team_lead) references EMPLOYEE" }; } Modified: trunk/HibernateExt/tools/src/test/org/hibernate/tool/test/jdbc2cfg/foreignkeytest.reveng.xml =================================================================== --- trunk/HibernateExt/tools/src/test/org/hibernate/tool/test/jdbc2cfg/foreignkeytest.reveng.xml 2006-04-18 16:44:02 UTC (rev 9760) +++ trunk/HibernateExt/tools/src/test/org/hibernate/tool/test/jdbc2cfg/foreignkeytest.reveng.xml 2006-04-18 16:45:06 UTC (rev 9761) @@ -15,6 +15,6 @@ <many-to-one exclude="true"/> <set property="managedProjects"/> </foreign-key> - </table> + </table> </hibernate-reverse-engineering> \ No newline at end of file |