0 Replies Latest reply on Oct 7, 2002 2:12 PM by hchirino

    Chaning the Interceptor stack of an Aspect on the fly

    hchirino

      Hi Magnus,

      Here is a guide on how to implement auto-increment with xdoclet. I did get this to work on SQL Server 2000, but adjusted the entries for mysql. It should work for you. Let me know if you have any questions... and good luck :)

      1.
      You need jboss 3.2.x and xdoclet 1.2b2 - earlier versions of jboss may not and earlier versions of xdoclet do not support auto-increment


      2.
      Write a class level tag in your bean

      * @jboss.entity-command name="mysql-get-generated-keys"
      *
      **/
      public abstract class OrderEntityBean implements EntityBean



      3.Write a method level tag in your bean (for primary key field)

      /***************************************************************************
      * Retrieve the id
      *
      * @return Returns an int representing the order id
      *
      * @ejb.persistence
      * @ejb.pk-field
      *
      * @jboss.column-name name="OrderId"
      * @jboss.persistence auto-increment="true"

      **/
      public abstract int getOrderId();

      /**
      * Set the order's id
      *
      * @param pOrderId The id of this OrderEntity. Is set at creation time.
      **/
      public abstract void setOrderId( int pOrderId );


      4. Adjust build.xml

      - Make sure you include all jars in xdoclet1.2b2/lib in your fileset for the ejbdoclet task
      - The class in the classname attribute in the ejbdoclet task is in a different package from older xdoclet versions
      - Some attributes in the ejbdoclet tag are not supported anymore (The example below does work however)
      - Replace the dtd version for jbosscmp-jdbc.xml in build.xml - xdoclet 1.2b2 can only handle up to jboss 3.0

















      ...


      <!-- =================================================================== -->
      <!-- Replaces old dtds - xdoclet1.2b2 can only handle up to jboss 3.0, -->
      <!-- so it uses old dtd - this task can be removed in future versions -->
      <!-- =================================================================== -->



















      That's about it. This should generate the following entries in jbosscmp-jdbc.xml



      <cmp-field>
      <field-name>orderId</field-name>
      <column-name>OrderId</column-name>

      <auto-increment/>
      </cmp-field>


      ...


      <entity-command name="get-mssql-generated-keys" class="org.jboss.ejb.plugins.cmp.jdbc.mssql.JDBCMsSQLCreateCommand">



      If you want to know where the details are configured, take a look at standardjbosscmp-jdbc.xml on the server:


      <type-mapping>
      mySQL
      <row-locking-template>SELECT ?1 FROM ?2 WHERE ?3 FOR UPDATE</row-locking-template>
      <pk-constraint-template>CONSTRAINT ?1 PRIMARY KEY (?2)</pk-constraint-template>
      <fk-constraint-template>ALTER TABLE ?1 ADD INDEX ind_?3 (?3), ADD CONSTRAINT ?2 FOREIGN KEY (?3) REFERENCES ?4 (?5)</fk-constraint-template>
      <auto-increment-template>?1 auto_increment</auto-increment-template>


      ...


      <!-- this command requires auto-increment element for unknown-pk -->
      <entity-command name="mysql-get-generated-keys"
      class="org.jboss.ejb.plugins.cmp.jdbc.mysql.JDBCMySQLCreateCommand"/>




      Daniel