0 Replies Latest reply on Dec 26, 2002 3:40 AM by aloubyansky

    Optimistic locking support ported to JBoss-3.2

    aloubyansky

      To setup optimistic locking, container configuration element locking-policy should be set to
      <locking-policy>org.jboss.ejb.plugins.lock.JDBCOptimisticLock</locking-policy>
      and entity element in jbosscmp-jdbc.xml should have optimistic-locking element.

      Following are the possible configurations of optimistic-locking element:
      1. Fixed group of fields that will be used for optimistic locking.
      <optimistic-locking>
      <group-name>optimisticLockingGroup</group-name>
      </optimistic-locking>
      where optimisticLockingGroup is one of the entity's load-group-name's.

      2. Modified strategy. The fields that were modified during transaction will be used for optimistic locking.
      <optimistic-locking>
      <modified-strategy/>
      </optimistic-locking>

      3. Read strategy. The fields that were read during transaction will be used for optimistic locking.
      <optimistic-locking>
      <read-strategy/>
      </optimistic-locking>

      4. Version (counter) column strategy. Additional version (counter) field of type java.lang.Long will be added to entity which

      will be used for optimistic locking. Each update of the entity will increase the value of its version field by 1.
      <optimistic-locking>
      <version-column/>
      <field-name>versionField</field-name>
      <column-name>ol_version</column-name>
      <jdbc-type>INTEGER</jdbc-type>
      <sql-type>INTEGER(5)</sql-type>
      </optimistic-locking>

      5. Timestamp column strategy. Additional timestamp column field of type java.util.Date will be added to entity which will be

      used for optimistic locking. Each update of the entity will set the value of its timestamp field to the current time.
      <optimistic-locking>
      <timestamp-column/>
      <field-name>timestampField</field-name>
      <column-name>ol_timestamp</column-name>
      <jdbc-type>TIMESTAMP</jdbc-type>
      <sql-type>DATETIME</sql-type>
      </optimistic-locking>

      6. Version column generated by KeyGenerator. Additional field will be added to entity that will be used for optimistic

      locking. Each update of the entity will update its version column with value generated by KeyGenerator.
      <optimistic-locking>
      <key-generator-factory>UUIDKeyGeneratorFactory</key-generator-factory>
      <field-type>java.lang.String</field-type>
      <field-name>uuidField</field-name>
      <column-name>ol_uuid</column-name>
      <jdbc-type>VARCHAR</jdbc-type>
      <sql-type>VARCHAR(32)</sql-type>
      </optimistic-locking>