NEW FEATURE: new ways to create entity beans
aloubyansky Sep 20, 2002 1:33 PMHello folks!
JBossCMP now provides some new ways to setup and create entity beans.
It is based on so called entity commands.
First some working examples (snippet from jbosscmp-jdbc.xml):
<ejb-name>MyCMPBean</ejb-name>
<table-name>mycmp_table</table-name>
<!-- auto-incremented primary key (jdk1.3/1.4) for now supported only for MySQL. -->
<cmp-field>
<field-name>id</field-name>
<column-name>knownid</column-name>
<jdbc-type>INTEGER</jdbc-type>
<sql-type>INTEGER(11)</sql-type>
<auto-increment/>
</cmp-field>
<!-- entity command to create the entity -->
<entity-command name="mysql-get-generated-keys"/>
<!-- unknown primary key generated with SQL statement -->
<unknown-pk>
<unknown-pk-class>java.lang.Integer</unknown-pk-class>
<column-name>genid</column-name>
<jdbc-type>TIMESTAMP</jdbc-type>
<sql-type>DATETIME</sql-type>
</unknown-pk>
<entity-command name="pk-sql"/>
-->
<!-- pk-sql generated unknown-pk; overriding default sql
<unknown-pk>
<unknown-pk-class>java.lang.Integer</unknown-pk-class>
<column-name>genid</column-name>
<jdbc-type>INTEGER</jdbc-type>
<sql-type>INTEGER</sql-type>
</unknown-pk>
<entity-command name="pk-sql">
SELECT SEQ_2279_1.nextval FROM DUAL
</entity-command>
-->
<!-- mysql generated unknown-pk
<unknown-pk>
<unknown-pk-class>java.lang.Integer</unknown-pk-class>
<column-name>genid</column-name>
<jdbc-type>INTEGER</jdbc-type>
<sql-type>INTEGER(11)</sql-type>
<auto-increment/>
</unknown-pk>
<entity-command name="mysql-get-generated-keys"
class="org.jboss.ejb.plugins.cmp.jdbc.mysql.MySQLCreateEntityCommand"/>
-->
<!-- the use of key generator for unknown-pk
<unknown-pk>
<unknown-pk-class>java.lang.String</unknown-pk-class>
<column-name>genid</column-name>
<jdbc-type>VARCHAR</jdbc-type>
<sql-type>VARCHAR(32)</sql-type>
</unknown-pk>
<entity-command name="key-generator"
class="org.jboss.ejb.plugins.cmp.jdbc.JDBCKeyGeneratorCreateCommand">
UUIDKeyGeneratorFactory
</entity-command>
-->
The general syntax of entity-command is:
<entity-command name="CommandName"
class="ComandClass">
value1
value2
</entity-command>
Only the 'name' is required.
You can check the list of available commands in
standardjbosscmp-jdbc.xml in entity-commands element.
The default entity command is specified in 'defaults' element and can
be overriden in each entity element as above.
If entity-command in the entity provides 'class' or 'attribute' it
overrides the corresponding element of in the known command.
For now the feature is available in HEAD version.
PS: templates for non-MySQL auto-increment SQL statements are welcome!!!
alex