db-ojb-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From arm...@apache.org
Subject cvs commit: db-ojb/src/java/org/apache/ojb/broker/util/sequence SequenceManagerStoredProcedureImpl.java SequenceManagerSeqHiLoImpl.java SequenceManagerNextValImpl.java SequenceManagerInMemoryImpl.java SequenceManagerHighLowImpl.java SequenceManagerHelper.java AbstractSequenceManager.java
Date Fri, 11 Apr 2003 21:59:50 GMT
arminw      2003/04/11 14:59:50

  Modified:    xdocs    sequencemanager.xml
               src/test/org/apache/ojb repository_junit.xml
                        repository_database.xml
               src/test/org/apache/ojb/broker/sequence
                        SequenceManagerTest.java
               src/java/org/apache/ojb/broker/util/sequence
                        SequenceManagerStoredProcedureImpl.java
                        SequenceManagerSeqHiLoImpl.java
                        SequenceManagerNextValImpl.java
                        SequenceManagerInMemoryImpl.java
                        SequenceManagerHighLowImpl.java
                        SequenceManagerHelper.java
                        AbstractSequenceManager.java
  Log:
  add attribute 'autoNaming' to sequence manager,
  manage the auto sequence name creation of OJB
  
  Revision  Changes    Path
  1.10      +94 -22    db-ojb/xdocs/sequencemanager.xml
  
  Index: sequencemanager.xml
  ===================================================================
  RCS file: /home/cvs/db-ojb/xdocs/sequencemanager.xml,v
  retrieving revision 1.9
  retrieving revision 1.10
  diff -u -r1.9 -r1.10
  --- sequencemanager.xml	9 Apr 2003 09:28:18 -0000	1.9
  +++ sequencemanager.xml	11 Apr 2003 21:59:49 -0000	1.10
  @@ -28,6 +28,8 @@
       <li><a href="#questions">Questions</a></li>
           <ul>
               <li><a href="#whenUsing">When using sequence-name attribute in
field-descriptor?</a></li>
  +            <li><a href="#extentAware">What to hell does <i>extent aware</i>
mean?</a></li>
  +            <li><a href="#noAutoBuild">How could I prevent auto-build of the
sequence-name?</a></li>
               <li><a href="#sequenceManagerHandling">Sequence manager handling
using multiple databases</a></li>
               <li><a href="#oneSequenceManager">One sequence manager with multiple
databases?</a></li>
               <li><a href="#directAccess">Can I get direct access to the sequence
manager?</a></li>
  @@ -198,6 +200,8 @@
                                       attribute-value="false"/>
       <attribute attribute-name="globalSequenceStart"
                                       attribute-value="10000"/>
  +    <attribute attribute-name="autoNaming"
  +                                    attribute-value="true"/>
   </sequence-manager>
   ]]></source>
   
  @@ -209,6 +213,14 @@
   <br/>
   The attribute <code>globalSequenceStart</code> define the start value of the
   global id generation (default was 10000).
  +<br/>
  +The attribute <code>autoNaming</code> define if sequence names should be build
  +automatic if none found in <code>field-descriptor</code>.
  +If set 'true' OJB try to build a
  +sequence name automatic if none found in field-descriptor
  +and set this name as <code>sequence-name</code>
  +in field-descriptor. If set 'false' OJB throws an exception
  +if none sequence name was found in field-descriptor (default was 'true').
   </p>
   <p>
   This sequence manager implementation supports user defined <i>sequence-names</i>
  @@ -237,9 +249,11 @@
   <source><![CDATA[
   <sequence-manager className="org.apache.ojb.broker.util.
                                   sequence.SequenceManagerInMemoryImpl">
  +    <attribute attribute-name="autoNaming"
  +                                    attribute-value="true"/>
   </sequence-manager>
   ]]></source>
  -
  +For attribute <code>autoNaming</code> <a href="#High/Low sequence manager">see</a>
   </p>
   <p>
   This sequence manager implementation supports user defined <i>sequence-names</i>
  @@ -264,13 +278,26 @@
   <source><![CDATA[
   <sequence-manager className="org.apache.ojb.broker.util.
                                   sequence.SequenceManagerNextValImpl">
  +    <attribute attribute-name="autoNaming"
  +                                    attribute-value="true"/>
   </sequence-manager>
   ]]></source>
   <br/>
  +Attribute <code>autoNaming</code> default was 'true'. If set 'true' OJB try
to build a
  +sequence name automatic if none found in field-descriptor
  +and set this generated name as <code>sequence-name</code>
  +in field-descriptor.
  +<br/>
  +If set 'false' OJB throws an exception
  +if none sequence name was found in field-descriptor, ditto
  +OJB does NOT try to create a database sequence entry when
  +for given sequence name no database sequence could be found.
  +<br/>
  +<br/>
   <a name="sequenceName"/>
   When using this sequence manager it is possible
  -to define a <code>sequence-name</code> field-descriptor attribute
  -in the repository file for each autoincrement field. If you don't
  +to define a <b>sequence-name</b> <code>field-descriptor</code>
attribute
  +in the repository file for each autoincrement/pk field. If you don't
   specify a sequence name, the sequence manager try to
   build a extent-aware sequence name on its own.
   <br/>
  @@ -312,10 +339,13 @@
   <sequence-manager className="org.apache.ojb.broker.util.
                               sequence.SequenceManagerSeqHiLoImpl">
       <attribute attribute-name="grabSize" attribute-value="20"/>
  +    <attribute attribute-name="autoNaming"
  +                                    attribute-value="true"/>
   </sequence-manager>
   ]]></source>
   With the property
   <code>grabSize</code> you set the size of the assigned ids.
  +For attribute <code>autoNaming</code> <a href="#Database sequences based
implementation">see</a>.
   </p>
   <p>
   This sequence manager implementation supports user defined <i>sequence-names</i>
  @@ -387,8 +417,11 @@
   <source><![CDATA[
   <sequence-manager className="org.apache.ojb.broker.util.
                          sequence.SequenceManagerStoredProcedureImpl">
  +    <attribute attribute-name="autoNaming"
  +                                    attribute-value="true"/>
   </sequence-manager>
   ]]></source>
  +For attribute <code>autoNaming</code> <a href="#High/Low sequence manager">see</a>.
   </p>
   <p>
   This sequence manager implementation supports user defined <i>sequence-names</i>
  @@ -457,9 +490,37 @@
   If you want retain control of sequencing use your own <code>sequence-name</code>
attribute
   in the <code>field-descriptor</code>. In that case you are reponsible to use
the same name
   across extents (extent <a href="tutorial3.html#extents and polymorphism">see more
info</a>).
  -Per default the sequence manager build its own <i>extent aware</i> sequence
name if necessary.
  +Per default the sequence manager build its own <i>extent aware</i> sequence
name with an
  +simple algorithm
  +(see <code>org.apache.ojb.broker.util.sequence.SequenceManagerHelper#buildSequenceName</code>)
  +if necessary.
   <br/>
  -In most cases
  +In most cases this should be sufficient. If you have a very complex data model and you
  +will do many metadata changes in the repository file in future, then it could be better
  +to explicit use <code>sequence-names</code> in the <code>field-descriptor</code>.
See
  +more <a href="#pitfalls">avoid pitfals</a>.
  +</p>
  +
  +
  +<p>
  +<a name="extentAware"/>
  +<br/><b>What to hell does <i>extent aware</i> mean?</b><br/>
  +Say we have a abstract base class <code>animals</code> and two classes <code>dogs</code>
and <code>cats</code>
  +(with e.g. two different tables in database) which extend <code>animals</code>.
  +We will be able to do a query like <i>give me all animals</i>. Thus
  +the uid's of <code>dogs</code> and <code>cats</code> must be unique
across the
  +tables of both classes or else you never get a vaild query result.
  +</p>
  +
  +
  +<p>
  +<a name="noAutoBuild"/>
  +<br/><b>How could I prevent auto-build of the sequence-name?</b><br/>
  +Most of the shipped <code>SequenceManager</code> implementations support by
default
  +auto-build (autoNaming) of the sequence names if none was found in the <code>field-descriptor</code>.
  +To prevent this all relevant implementations (see docs here and javadocs)
  +support a <code>autoNaming</code> attribute. If set <code>false</code>
OJB doesn't
  +try to build sequence names automatic.
   </p>
   
   
  @@ -467,7 +528,8 @@
   <a name="sequenceManagerHandling"/>
   <br/><b>Sequence manager handling using multiple databases</b><br/>
   If you use multiple databases you have to declare a sequence manager in each
  -<code>jdbc-connection-descriptor</code>.
  +<code>jdbc-connection-descriptor</code>. If you don't specify a sequence manager
  +OJB use the default one (currently <code>ojb.broker.util.sequence.SequenceManagerHighLowImpl</code>).
   </p>
   
   
  @@ -494,28 +556,38 @@
   If you use <code>autoincrement=true</code> in your <code>field-descriptor</code>,
   there is no reason to obtain UID directly from the sequence manager or to handle
   UID in your object model.
  +<br/>
  +[NOTE: Don't use SequenceManagerFactory#getSequenceManager(PersistenceBroker broker), this
  +returns a new sequence manager instance for the given broker instance, not the current
  +used of the given broker instance]
   </p>
   
   
   <p>
   <a name="pitfalls"/>
   <br/><b>Any known pitfalls?</b><br/>
  -- When enable a sequence manager implementation based on <i>sequence-name</i>
attributes
  -and if the name was not set as an attribute in the <code>field-descriptor</code>
  -(<a href="sequenceName">see</a>), an simple algorithm was used to build the
sequence name.
  -<br/>
  -The algorithm try to get the top-level class of the field's enclosing class,
  -if no top-level class was found, the table name of the field's enclosing class was used.
  -If a top-level class was found, the first found extent class table name was used as sequence
name.
  -<br/>
  -When using base classes/interfaces with extent classes based on different database tables
  -and the <code>extent-class</code> entries in repository often change, the algorithm
could be
  -corrupted, because the first found extent class's table name could be change.
  -<br/>
  -To avoid this, remove the implementation internal sequence name entry (e.g. OJB_HL_SEQ
table
  -entry when using the Hi/Lo implementation, or remove the database sequence entry when using
  -the 'Nextval' implementation) in that case, or use custom sequence name attributes in the
  -field descriptor.
  +
  +<ul>
  +    <li>
  +    When enable a sequence manager implementation based on <i>sequence-name</i>
attributes
  +    and if the name was not set as an attribute in the <code>field-descriptor</code>
  +    (<a href="#sequenceName">see</a>), an simple algorithm was used to build
the sequence name.
  +    <br/>
  +    The algorithm try to get the top-level class of the field's enclosing class,
  +    if no top-level class was found, the table name of the field's enclosing class was
used.
  +    If a top-level class was found, the first found extent class table name was used as
sequence name.
  +    <br/>
  +    When using base classes/interfaces with extent classes based on different database
tables
  +    and the <code>extent-class</code> entries in repository often change, the
algorithm could be
  +    corrupted, because the first found extent class's table name could be change.
  +    <br/>
  +    To avoid this, remove the implementation internal sequence name entry (e.g. OJB_HL_SEQ
table
  +    entry when using the Hi/Lo implementation, or remove the database sequence entry when
using
  +    the 'Nextval' implementation) in that case, or use custom sequence name attributes
in the
  +    field descriptor.
  +    </li>
  +</ul>
  +
   </p>
   
   </subsection>
  
  
  
  1.59      +48 -0     db-ojb/src/test/org/apache/ojb/repository_junit.xml
  
  Index: repository_junit.xml
  ===================================================================
  RCS file: /home/cvs/db-ojb/src/test/org/apache/ojb/repository_junit.xml,v
  retrieving revision 1.58
  retrieving revision 1.59
  diff -u -r1.58 -r1.59
  --- repository_junit.xml	9 Apr 2003 20:45:20 -0000	1.58
  +++ repository_junit.xml	11 Apr 2003 21:59:49 -0000	1.59
  @@ -3125,6 +3125,54 @@
       </class-descriptor>
   
   
  +    <class-descriptor
  +      class="org.apache.ojb.broker.sequence.SequenceManagerTest$AbstractSMObject"
  +    >
  +        <extent-class class-ref="org.apache.ojb.broker.sequence.SequenceManagerTest$SMObjectTwo"
/>
  +        <extent-class class-ref="org.apache.ojb.broker.sequence.SequenceManagerTest$SMObjectOne"
/>
  +    </class-descriptor>
  +
  +    <!-- NOTE: Here we use a table from other test -->
  +    <class-descriptor
  +      class="org.apache.ojb.broker.sequence.SequenceManagerTest$SMObjectOne"
  +      table="SM_SAME_TAB"
  +    >
  +        <field-descriptor
  +         name="objectId"
  +         column="SM_ID"
  +         jdbc-type="INTEGER"
  +         primarykey="true"
  +         autoincrement="true"
  +
  +        />
  +
  +        <field-descriptor
  +         name="name"
  +         column="NAME"
  +         jdbc-type="VARCHAR"
  +        />
  +    </class-descriptor>
  +
  +    <!-- NOTE: Here we use a table from other test -->
  +    <class-descriptor
  +      class="org.apache.ojb.broker.sequence.SequenceManagerTest$SMObjectTwo"
  +      table="SM_TAB_A"
  +    >
  +        <field-descriptor
  +         name="objectId"
  +         column="SM_ID"
  +         jdbc-type="INTEGER"
  +         primarykey="true"
  +         autoincrement="true"
  +
  +        />
  +
  +        <field-descriptor
  +         name="name"
  +         column="NAME"
  +         jdbc-type="VARCHAR"
  +        />
  +    </class-descriptor>
   
   
   
  
  
  
  1.11      +2 -1      db-ojb/src/test/org/apache/ojb/repository_database.xml
  
  Index: repository_database.xml
  ===================================================================
  RCS file: /home/cvs/db-ojb/src/test/org/apache/ojb/repository_database.xml,v
  retrieving revision 1.10
  retrieving revision 1.11
  diff -u -r1.10 -r1.11
  --- repository_database.xml	1 Apr 2003 14:06:11 -0000	1.10
  +++ repository_database.xml	11 Apr 2003 21:59:49 -0000	1.11
  @@ -38,6 +38,7 @@
   
           <sequence-manager className="org.apache.ojb.broker.util.sequence.SequenceManagerHighLowImpl">
               <attribute attribute-name="grabSize" attribute-value="20"/>
  +            <attribute attribute-name="autoNaming" attribute-value="true"/>
               <attribute attribute-name="globalSequenceId" attribute-value="false"/>
               <attribute attribute-name="globalSequenceStart" attribute-value="10000"/>
           </sequence-manager>
  @@ -58,7 +59,7 @@
           ignoreAutoCommitExceptions="false"
      >
           <sequence-manager className="org.apache.ojb.broker.util.sequence.SequenceManagerNextValImpl">
  -            <attribute attribute-name="grabSize" attribute-value="20"/>
  +            <attribute attribute-name="autoNaming" attribute-value="true"/>
           </sequence-manager>
   
      </jdbc-connection-descriptor -->
  
  
  
  1.19      +167 -7    db-ojb/src/test/org/apache/ojb/broker/sequence/SequenceManagerTest.java
  
  Index: SequenceManagerTest.java
  ===================================================================
  RCS file: /home/cvs/db-ojb/src/test/org/apache/ojb/broker/sequence/SequenceManagerTest.java,v
  retrieving revision 1.18
  retrieving revision 1.19
  diff -u -r1.18 -r1.19
  --- SequenceManagerTest.java	1 Apr 2003 14:06:12 -0000	1.18
  +++ SequenceManagerTest.java	11 Apr 2003 21:59:49 -0000	1.19
  @@ -4,6 +4,7 @@
   import java.util.Iterator;
   import java.util.List;
   import java.util.TreeSet;
  +import java.util.Collection;
   
   import junit.framework.TestCase;
   import org.apache.ojb.broker.*;
  @@ -57,7 +58,7 @@
       testSequenceGeneration
       testForLostKeys
       */
  -    private int loops = 2000;
  +    private int loops = 1000;
       private int instances = 10;
       private Class targetClass = SMSameTableA.class;
       // end
  @@ -173,13 +174,13 @@
        * Test the use of the 'sequence-name' field descriptor
        * attribute.
        */
  -    public void testSequenceNameAttribute()
  +    public void testSequenceNameAttribute() throws Exception
       {
           // sequence name used in the repository
           String fieldName = "stringKey";
           PersistenceBroker broker = PersistenceBrokerFactory.defaultPersistenceBroker();
           FieldDescriptor field = broker.getClassDescriptor(SMKey.class).getFieldDescriptorByName(fieldName);
  -        String result = SequenceManagerHelper.buildSequenceName(broker, field);
  +        String result = SequenceManagerHelper.buildSequenceName(broker, field, true);
   
           assertEquals(TEST_SEQUENCE_NAME, result);
           broker.close();
  @@ -540,9 +541,10 @@
               sm.getUniqueValue(field);
   
               generatedKeys.clear();
  -            testSequenceGeneration();
  -            testMultipleAutoincrement();
  -            testSequenceNameAttribute();
  +// comment in
  +//            testSequenceGeneration();
  +//            testMultipleAutoincrement();
  +//            testSequenceNameAttribute();
               broker.close();
           }
           finally
  @@ -618,4 +620,162 @@
       {
           ++keyCount;
       }
  +
  +
  +
  +    public void testObjectsFromAbstractBaseClass1() throws Exception
  +    {
  +        PersistenceBroker broker = PersistenceBrokerFactory.defaultPersistenceBroker();
  +        try
  +        {
  +            SequenceManager sm = broker.serviceSequenceManager();
  +            FieldDescriptor fld_1 = broker.getClassDescriptor(SMObjectOne.class).getAutoIncrementField();
  +            FieldDescriptor fld_2 = broker.getClassDescriptor(SMObjectTwo.class).getAutoIncrementField();
  +
  +            Object result_1 = sm.getUniqueValue(fld_1);
  +            Object result_2 = sm.getUniqueValue(fld_2);
  +
  +            assertNotNull(result_1);
  +            assertNotNull(result_2);
  +            assertTrue(result_1 instanceof Integer);
  +            assertTrue(result_2 instanceof Integer);
  +
  +            result_1 = sm.getUniqueValue(fld_1);
  +            result_2 = sm.getUniqueValue(fld_2);
  +
  +            assertNotNull(result_1);
  +            assertNotNull(result_2);
  +            assertTrue(result_1 instanceof Integer);
  +            assertTrue(result_2 instanceof Integer);
  +
  +            assertFalse("Should not have same ids", result_2.equals(result_1));
  +        }
  +        finally
  +        {
  +            if(broker != null) broker.close();
  +        }
  +    }
  +
  +    public void testObjectsFromAbstractBaseClass2() throws Exception
  +    {
  +        long stamp = System.currentTimeMillis();
  +        String objectName_One = "testObjectsFromAbstractBaseClass2_objOne_"+stamp;
  +        String objectName_Two = "testObjectsFromAbstractBaseClass2_objTwo_"+stamp;
  +
  +        PersistenceBroker broker = PersistenceBrokerFactory.defaultPersistenceBroker();
  +
  +        SMSameTableBB dummy1 = new SMSameTableBB();
  +        SMInterfaceExtendA dummy2 = new SMInterfaceExtendA();
  +
  +        SMObjectOne smOne_1 = new SMObjectOne(objectName_One);
  +        SMObjectOne smOne_2 = new SMObjectOne(objectName_One);
  +
  +        SMObjectTwo smTwo_2 = new SMObjectTwo(objectName_Two);
  +        SMObjectTwo smTwo_1 = new SMObjectTwo(objectName_Two);
  +        try
  +        {
  +            broker.beginTransaction();
  +
  +            broker.store(dummy1);
  +            broker.store(dummy2);
  +
  +            broker.store(smOne_1);
  +            broker.store(smOne_2);
  +// broker.clearCache();
  +            broker.store(smTwo_2);
  +            broker.store(smTwo_1);
  +
  +            broker.commitTransaction();
  +
  +            // now check if store was successful
  +            broker.clearCache();
  +
  +            Criteria cr = new Criteria();
  +            cr.addEqualTo("name", objectName_One);
  +            Query query = new QueryByCriteria(SMObjectOne.class, cr);
  +            Collection result = (Collection) broker.getCollectionByQuery(query);
  +
  +            broker.clearCache();
  +
  +            Criteria cr_2 = new Criteria();
  +            cr_2.addEqualTo("name", objectName_Two);
  +            Query query_2 = new QueryByCriteria(SMObjectTwo.class, cr_2);
  +            Collection result_2 = (Collection) broker.getCollectionByQuery(query_2);
  +
  +            assertEquals("We have to found 2 SMObjectOne objects", 2, result.size());
  +            assertEquals("We have to found 2 SMObjectTwo objects", 2, result_2.size());
  +        }
  +        finally
  +        {
  +            if(broker != null) broker.close();
  +        }
  +    }
  +
  +
  +    // ******************************************************************************
  +    // inner class
  +    // ******************************************************************************
  +    public static class AbstractSMObject
  +    {
  +        private Integer objectId;
  +
  +        public Integer getObjectId()
  +        {
  +            return objectId;
  +        }
  +
  +        public void setObjectId(Integer objectId)
  +        {
  +            this.objectId = objectId;
  +        }
  +    }
  +
  +    public static class SMObjectOne extends AbstractSMObject
  +    {
  +        private String name;
  +
  +        public SMObjectOne()
  +        {
  +        }
  +
  +        public SMObjectOne(String name)
  +        {
  +            this.name = name;
  +        }
  +
  +        public String getName()
  +        {
  +            return name;
  +        }
  +
  +        public void setName(String name)
  +        {
  +            this.name = name;
  +        }
  +    }
  +
  +    public static class SMObjectTwo extends AbstractSMObject
  +    {
  +        private String name;
  +
  +        public SMObjectTwo()
  +        {
  +        }
  +
  +        public SMObjectTwo(String name)
  +        {
  +            this.name = name;
  +        }
  +
  +        public String getName()
  +        {
  +            return name;
  +        }
  +
  +        public void setName(String name)
  +        {
  +            this.name = name;
  +        }
  +    }
  +
   }
  
  
  
  1.5       +8 -4      db-ojb/src/java/org/apache/ojb/broker/util/sequence/SequenceManagerStoredProcedureImpl.java
  
  Index: SequenceManagerStoredProcedureImpl.java
  ===================================================================
  RCS file: /home/cvs/db-ojb/src/java/org/apache/ojb/broker/util/sequence/SequenceManagerStoredProcedureImpl.java,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- SequenceManagerStoredProcedureImpl.java	3 Apr 2003 19:07:59 -0000	1.4
  +++ SequenceManagerStoredProcedureImpl.java	11 Apr 2003 21:59:49 -0000	1.5
  @@ -134,9 +134,13 @@
    *     <td><strong>Property Values</strong></td>
    * </tr>
    * <tr>
  - *     <td>none</td>
  + *     <td>autoNaming</td>
    *     <td>
  - *
  + *          Default was 'true'. If set 'true' OJB try to build a
  + *          sequence name automatic if none found in field-descriptor
  + *          and set this generated name as <code>sequence-name</code>
  + *          in field-descriptor. If set 'false' OJB throws an exception
  + *          if none sequence name was found in field-descriptor.
    *    </td>
    * </tr>
    * </table>
  @@ -215,7 +219,7 @@
           try
           {
               // lookup sequence name
  -            String sequenceName = SequenceManagerHelper.buildSequenceName(targetBroker,
field);
  +            String sequenceName = SequenceManagerHelper.buildSequenceName(targetBroker,
field, useAutoNaming());
               try
               {
                   result = buildNextSequence(targetBroker, field.getClassDescriptor(), sequenceName);
  
  
  
  1.5       +12 -2     db-ojb/src/java/org/apache/ojb/broker/util/sequence/SequenceManagerSeqHiLoImpl.java
  
  Index: SequenceManagerSeqHiLoImpl.java
  ===================================================================
  RCS file: /home/cvs/db-ojb/src/java/org/apache/ojb/broker/util/sequence/SequenceManagerSeqHiLoImpl.java,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- SequenceManagerSeqHiLoImpl.java	1 Apr 2003 14:09:39 -0000	1.4
  +++ SequenceManagerSeqHiLoImpl.java	11 Apr 2003 21:59:49 -0000	1.5
  @@ -84,6 +84,16 @@
    *         Default was '20'.
    *    </td>
    * </tr>
  + * <tr>
  + *     <td>autoNaming</td>
  + *     <td>
  + *          Default was 'true'. If set 'true' OJB try to build a
  + *          sequence name automatic if none found in field-descriptor
  + *          and set this generated name as <code>sequence-name</code>
  + *          in field-descriptor. If set 'false' OJB throws an exception
  + *          if none sequence name was found in field-descriptor.
  + *    </td>
  + * </tr>
    * </table>
    * <br/>
    * <p>
  @@ -113,7 +123,7 @@
   
       protected long getUniqueLong(FieldDescriptor field) throws SequenceManagerException
       {
  -        String sequenceName = SequenceManagerHelper.buildSequenceName(getBrokerForClass(),
field);
  +        String sequenceName = SequenceManagerHelper.buildSequenceName(getBrokerForClass(),
field, useAutoNaming());
           // we have to be threadsafe
           synchronized (hiLoMap)
           {
  
  
  
  1.9       +14 -4     db-ojb/src/java/org/apache/ojb/broker/util/sequence/SequenceManagerNextValImpl.java
  
  Index: SequenceManagerNextValImpl.java
  ===================================================================
  RCS file: /home/cvs/db-ojb/src/java/org/apache/ojb/broker/util/sequence/SequenceManagerNextValImpl.java,v
  retrieving revision 1.8
  retrieving revision 1.9
  diff -u -r1.8 -r1.9
  --- SequenceManagerNextValImpl.java	1 Apr 2003 14:09:39 -0000	1.8
  +++ SequenceManagerNextValImpl.java	11 Apr 2003 21:59:49 -0000	1.9
  @@ -93,9 +93,17 @@
    *     <td><strong>Property Values</strong></td>
    * </tr>
    * <tr>
  - *     <td>none</td>
  + *     <td>autoNaming</td>
    *     <td>
  - *
  + *          Default was 'true'. If set 'true' OJB try to build a
  + *          sequence name automatic if none found in field-descriptor
  + *          and set this generated name as <code>sequence-name</code>
  + *          in field-descriptor.
  + *          <br/>
  + *          If set 'false' OJB throws an exception
  + *          if none sequence name was found in field-descriptor, ditto
  + *          OJB does NOT try to create a database sequence entry when
  + *          for given sequence name no database sequence could be found.
    *    </td>
    * </tr>
    * </table>
  @@ -145,13 +153,15 @@
       {
           long result = 0;
           // lookup sequence name
  -        String sequenceName = SequenceManagerHelper.buildSequenceName(getBrokerForClass(),
field);
  +        String sequenceName = SequenceManagerHelper.buildSequenceName(getBrokerForClass(),
field, useAutoNaming());
           try
           {
               result = buildNextSequence(field.getClassDescriptor(), sequenceName);
           }
           catch (Exception e)
           {
  +            // if we shoudn't do build a sequence automatic, re-throw exception
  +            if(!useAutoNaming()) throw new SequenceManagerException(e);
               // maybe the sequence was not created
               try
               {
  
  
  
  1.10      +8 -4      db-ojb/src/java/org/apache/ojb/broker/util/sequence/SequenceManagerInMemoryImpl.java
  
  Index: SequenceManagerInMemoryImpl.java
  ===================================================================
  RCS file: /home/cvs/db-ojb/src/java/org/apache/ojb/broker/util/sequence/SequenceManagerInMemoryImpl.java,v
  retrieving revision 1.9
  retrieving revision 1.10
  diff -u -r1.9 -r1.10
  --- SequenceManagerInMemoryImpl.java	1 Apr 2003 14:09:39 -0000	1.9
  +++ SequenceManagerInMemoryImpl.java	11 Apr 2003 21:59:49 -0000	1.10
  @@ -84,9 +84,13 @@
    *     <td><strong>Property Values</strong></td>
    * </tr>
    * <tr>
  - *     <td>none</td>
  + *     <td>autoNaming</td>
    *     <td>
  - *
  + *          Default was 'true'. If set 'true' OJB try to build a
  + *          sequence name automatic if none found in field-descriptor
  + *          and set this generated name as <code>sequence-name</code>
  + *          in field-descriptor. If set 'false' OJB throws an exception
  + *          if none sequence name was found in field-descriptor.
    *    </td>
    * </tr>
    * </table>
  @@ -113,7 +117,7 @@
   
       protected long getUniqueLong(FieldDescriptor field) throws SequenceManagerException
       {
  -        String seqName = SequenceManagerHelper.buildSequenceName(getBrokerForClass(), field);
  +        String seqName = SequenceManagerHelper.buildSequenceName(getBrokerForClass(), field,
useAutoNaming());
           // we have to be threadsafe
           synchronized (sequenceNameKeyMap)
           {
  
  
  
  1.18      +15 -3     db-ojb/src/java/org/apache/ojb/broker/util/sequence/SequenceManagerHighLowImpl.java
  
  Index: SequenceManagerHighLowImpl.java
  ===================================================================
  RCS file: /home/cvs/db-ojb/src/java/org/apache/ojb/broker/util/sequence/SequenceManagerHighLowImpl.java,v
  retrieving revision 1.17
  retrieving revision 1.18
  diff -u -r1.17 -r1.18
  --- SequenceManagerHighLowImpl.java	3 Apr 2003 19:07:59 -0000	1.17
  +++ SequenceManagerHighLowImpl.java	11 Apr 2003 21:59:49 -0000	1.18
  @@ -105,6 +105,16 @@
    *         generation (e.g. set 100000, id generation starts with 100001)
    *    </td>
    * </tr>
  + * <tr>
  + *     <td>autoNaming</td>
  + *     <td>
  + *          Default was 'true'. If set 'true' OJB try to build a
  + *          sequence name automatic if none found in field-descriptor
  + *          and set this generated name as <code>sequence-name</code>
  + *          in field-descriptor. If set 'false' OJB throws an exception
  + *          if none sequence name was found in field-descriptor.
  + *    </td>
  + * </tr>
    * </table>
    *
    * <br/>
  @@ -141,6 +151,7 @@
       public static final String PROPERTY_GLOBAL_SEQUENCE_ID = "globalSequenceId";
       public static final String PROPERTY_GLOBAL_SEQUENCE_START = "globalSequenceStart";
   
  +
       private static Map sequencesMap = new HashMap();
   
       protected boolean useGlobalSequenceIdentities;
  @@ -175,8 +186,8 @@
               */
               if (seqName == null || seqName.trim().equals(""))
               {
  -                seqName = SequenceManagerHelper.buildSequenceName(getBrokerForClass(),
field);
  -                field.setSequenceName(seqName);
  +                seqName = SequenceManagerHelper.buildSequenceName(getBrokerForClass(),
field, useAutoNaming());
  +                if(useAutoNaming()) field.setSequenceName(seqName);
               }
           }
           synchronized (sequencesMap)
  @@ -283,6 +294,7 @@
                   we could found an object in cache although it is not
                   in the second database, it was used in the first database.
                   If we not remove it PB try to update instead of insert.
  +                TODO: Find a better solution
                   */
                   internBroker.removeFromCache(newSequence);
                   internBroker.store(newSequence);
  
  
  
  1.10      +24 -16    db-ojb/src/java/org/apache/ojb/broker/util/sequence/SequenceManagerHelper.java
  
  Index: SequenceManagerHelper.java
  ===================================================================
  RCS file: /home/cvs/db-ojb/src/java/org/apache/ojb/broker/util/sequence/SequenceManagerHelper.java,v
  retrieving revision 1.9
  retrieving revision 1.10
  diff -u -r1.9 -r1.10
  --- SequenceManagerHelper.java	1 Apr 2003 14:09:39 -0000	1.9
  +++ SequenceManagerHelper.java	11 Apr 2003 21:59:49 -0000	1.10
  @@ -30,7 +30,6 @@
       /**
        * Prefix for global sequence names.
        */
  -    //private static final String GLOBAL_SEQUENCE_NAME = "global - default sequence name";
   
       /**
        * Returns a unique sequence name (unique across all extents).
  @@ -43,10 +42,15 @@
        * sequence name.
        * <br>
        * Else we take the table name of the target class.
  +     * @param brokerForClass current used PB instance
  +     * @param field target field
  +     * @param autoNaming if 'false' no auto sequence name was build and
  +     * a exception was throw if none could be found in field.
        */
  -    public static String buildSequenceName(PersistenceBroker brokerForClass, FieldDescriptor
field)
  +    public static String buildSequenceName(PersistenceBroker brokerForClass,
  +                                           FieldDescriptor field, boolean autoNaming)
  +                                            throws SequenceManagerException
       {
  -        ClassDescriptor cldTargetClass = field.getClassDescriptor();
           String seqName = field.getSequenceName();
           /*
           if we found a sequence name bound to the field descriptor
  @@ -56,7 +60,18 @@
           {
               return seqName;
           }
  +        else if(!autoNaming)
  +        {
  +            /*
  +            arminw:
  +            we don't found a sequence name and we should not automatic build one,
  +            thus we throw an exception
  +            */
  +            throw new SequenceManagerException("Could not found sequence-name for "+
  +                            field+" property 'autoNaming' in sequence-manager element in
repository was "+autoNaming);
  +        }
   
  +        ClassDescriptor cldTargetClass = field.getClassDescriptor();
           Class topLevel = brokerForClass.getTopLevelClass(cldTargetClass.getClassOfObject());
           ClassDescriptor cldTopLevel = brokerForClass.getClassDescriptor(topLevel);
           /**
  @@ -76,12 +91,13 @@
           if (cldTopLevel.isExtent())
           {
               /*
  -            TODO
               arminw:
               this is a little critical, because we do not know if the extent classes
               will change by and by and the first found extent class may change, thus the
               returned table name could change!
  -            But I don't know a way to resolve this problem. I put a comment to the docs
  +            But I don't know a way to resolve this problem. I put a comment to the
  +            sequence manager docs
  +            TODO: find better solution
               */
               seqName = brokerForClass.getClassDescriptor(((Class) cldTopLevel.getExtentClasses().
                       get(0))).getFullTableName();
  @@ -94,14 +110,6 @@
           return SEQ_PREFIX + seqName;
       }
   
  -//    /**
  -//     * Build a global sequence name unique across all tables.
  -//     */
  -//    public static String buildSequenceNameGlobal()
  -//    {
  -//        return GLOBAL_SEQUENCE_NAME;
  -//    }
  -
       /**
        * Lookup all tables associated with given class (search all extent classes)
        * to find the current maximum value for the given field.
  @@ -133,8 +141,8 @@
           long tmp = 0;
           ClassDescriptor cld = brokerForClass.getClassDescriptor(topLevel);
   
  -        // if class is no Interface we have to search its directly mapped table
  -        if (!cld.isInterface())
  +        // if class is not an interface / not abstract we have to search its directly mapped
table
  +        if (!cld.isInterface() && !cld.isAbstract())
           {
               tmp = getMaxIdForClass(brokerForClass, cld, original);
               if (tmp > max)
  
  
  
  1.8       +10 -1     db-ojb/src/java/org/apache/ojb/broker/util/sequence/AbstractSequenceManager.java
  
  Index: AbstractSequenceManager.java
  ===================================================================
  RCS file: /home/cvs/db-ojb/src/java/org/apache/ojb/broker/util/sequence/AbstractSequenceManager.java,v
  retrieving revision 1.7
  retrieving revision 1.8
  diff -u -r1.7 -r1.8
  --- AbstractSequenceManager.java	1 Apr 2003 14:09:39 -0000	1.7
  +++ AbstractSequenceManager.java	11 Apr 2003 21:59:49 -0000	1.8
  @@ -30,10 +30,12 @@
   public abstract class AbstractSequenceManager implements SequenceManager
   {
       private Logger log = LoggerFactory.getLogger(AbstractSequenceManager.class);
  +    public static final String PROPERTY_AUTO_NAMING = "autoNaming";
   
       private PersistenceBroker brokerForClass;
       private Platform platform;
       private Properties configurationProperties;
  +    private boolean autoNaming;
   
       /**
        * Constructor used by
  @@ -56,6 +58,8 @@
           {
               this.configurationProperties = sd.getConfigurationProperties();
           }
  +        autoNaming =
  +                new Boolean(getConfigurationProperty(PROPERTY_AUTO_NAMING, "true")).booleanValue();
       }
   
       /**
  @@ -94,6 +98,11 @@
       public void setConfigurationProperty(String key, String value)
       {
           this.configurationProperties.setProperty(key, value);
  +    }
  +
  +    public boolean useAutoNaming()
  +    {
  +        return autoNaming;
       }
   
   
  
  
  

Mime
View raw message