db-ojb-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From arm...@apache.org
Subject svn commit: r465617 - in /db/ojb/branches/OJB_1_0_RELEASE/src/java/org/apache/ojb/broker: accesslayer/JdbcAccessImpl.java util/sequence/AbstractSequenceManager.java util/sequence/SequenceManagerIdentityImpl.java
Date Thu, 19 Oct 2006 13:22:03 GMT
Author: arminw
Date: Thu Oct 19 06:22:02 2006
New Revision: 465617

URL: http://svn.apache.org/viewvc?view=rev&rev=465617
Log:
sequence generation improvement

Modified:
    db/ojb/branches/OJB_1_0_RELEASE/src/java/org/apache/ojb/broker/accesslayer/JdbcAccessImpl.java
    db/ojb/branches/OJB_1_0_RELEASE/src/java/org/apache/ojb/broker/util/sequence/AbstractSequenceManager.java
    db/ojb/branches/OJB_1_0_RELEASE/src/java/org/apache/ojb/broker/util/sequence/SequenceManagerIdentityImpl.java

Modified: db/ojb/branches/OJB_1_0_RELEASE/src/java/org/apache/ojb/broker/accesslayer/JdbcAccessImpl.java
URL: http://svn.apache.org/viewvc/db/ojb/branches/OJB_1_0_RELEASE/src/java/org/apache/ojb/broker/accesslayer/JdbcAccessImpl.java?view=diff&rev=465617&r1=465616&r2=465617
==============================================================================
--- db/ojb/branches/OJB_1_0_RELEASE/src/java/org/apache/ojb/broker/accesslayer/JdbcAccessImpl.java
(original)
+++ db/ojb/branches/OJB_1_0_RELEASE/src/java/org/apache/ojb/broker/accesslayer/JdbcAccessImpl.java
Thu Oct 19 06:22:02 2006
@@ -785,12 +785,12 @@
     {
         // TODO: refactor auto-increment handling, auto-increment should only be supported
by PK fields?
         // FieldDescriptor[] fields = cld.getPkFields();
-        FieldDescriptor[] fields = cld.getFieldDescriptor(false);
+        FieldDescriptor[] fields = cld.getAutoIncrementFields();
         FieldDescriptor field;
         for(int i = 0; i < fields.length; i++)
         {
             field = fields[i];
-            if(field.isAutoIncrement() && !field.isAccessReadOnly())
+            if(!field.isAccessReadOnly())
             {
                 Object value = field.getPersistentField().get(target);
                 if(broker.serviceBrokerHelper().representsNull(field, value))
@@ -804,15 +804,9 @@
 
     protected void postSequenceProcess(final ClassDescriptor cld, final Object target) throws
SequenceManagerException
     {
-        // if database Identity Columns are used, query the id from database
-        // other SequenceManager implementations will ignore this call
-        if(cld.useIdentityColumnField())
-        {
-            // execute batch to ensure existance of new id
-            broker.serviceConnectionManager().executeBatch();
-            // lookup identity column PK value from DB and set PK in persistent object
-            broker.serviceSequenceManager().afterStore(this, cld, target);
-        }
+        // post insert sequence manager call, e.g. to lookup identity column PK value
+        // from DB and set PK in persistent object
+        broker.serviceSequenceManager().afterStore(this, cld, target);
     }
 
     /**

Modified: db/ojb/branches/OJB_1_0_RELEASE/src/java/org/apache/ojb/broker/util/sequence/AbstractSequenceManager.java
URL: http://svn.apache.org/viewvc/db/ojb/branches/OJB_1_0_RELEASE/src/java/org/apache/ojb/broker/util/sequence/AbstractSequenceManager.java?view=diff&rev=465617&r1=465616&r2=465617
==============================================================================
--- db/ojb/branches/OJB_1_0_RELEASE/src/java/org/apache/ojb/broker/util/sequence/AbstractSequenceManager.java
(original)
+++ db/ojb/branches/OJB_1_0_RELEASE/src/java/org/apache/ojb/broker/util/sequence/AbstractSequenceManager.java
Thu Oct 19 06:22:02 2006
@@ -28,9 +28,7 @@
 /**
  * A base class for sequence manager implementations.
  * <br/>
- * All sequence manager implementations need a constructor
- * with a PersistenceBroker argument used by the
- * {@link org.apache.ojb.broker.util.sequence.SequenceManagerFactory}.
+ * All sequence manager implementations need a specific non-default constructor.
  *
  * @version $Id$
  */
@@ -40,16 +38,12 @@
     public static final String PROPERTY_AUTO_NAMING_OLD = "autoNaming";
     public static final String PROPERTY_AUTO_NAMING = "seq.autoNaming";
 
-    private PersistenceBroker brokerForClass;
+    private final PersistenceBroker brokerForClass;
     private Platform platform;
     private Properties configurationProperties;
 
     /**
-     * Constructor used by
-     * {@link org.apache.ojb.broker.util.sequence.SequenceManagerFactory}
-     *
-     * @param broker  PB instance to perform the
-     * id generation.
+     * Constructor
      * @deprecated
      */
     public AbstractSequenceManager(PersistenceBroker broker)
@@ -83,7 +77,7 @@
      * returns a unique long value for field.
      * the returned number is unique accross all tables in the extent of clazz.
      */
-    abstract protected long getUniqueLong(FieldDescriptor field) throws SequenceManagerException;
+    abstract protected long getUniqueLong(final FieldDescriptor field) throws SequenceManagerException;
 
 
     public Platform getPlatform()
@@ -155,7 +149,7 @@
      * The returned object is unique accross all tables in the extent
      * of class the field belongs to.
      */
-    public Object getUniqueValue(FieldDescriptor field) throws SequenceManagerException
+    public Object getUniqueValue(final FieldDescriptor field) throws SequenceManagerException
     {
         Object result = field.getJdbcType().sequenceKeyConversion(new Long(getUniqueLong(field)));
         // perform a sql to java conversion here, so that clients do
@@ -167,7 +161,7 @@
     /**
      * noop
      */
-    public void afterStore(JdbcAccess dbAccess, ClassDescriptor cld, Object obj)
+    public void afterStore(final JdbcAccess dbAccess, final ClassDescriptor cld, Object obj)
             throws SequenceManagerException
     {
         // do nothing

Modified: db/ojb/branches/OJB_1_0_RELEASE/src/java/org/apache/ojb/broker/util/sequence/SequenceManagerIdentityImpl.java
URL: http://svn.apache.org/viewvc/db/ojb/branches/OJB_1_0_RELEASE/src/java/org/apache/ojb/broker/util/sequence/SequenceManagerIdentityImpl.java?view=diff&rev=465617&r1=465616&r2=465617
==============================================================================
--- db/ojb/branches/OJB_1_0_RELEASE/src/java/org/apache/ojb/broker/util/sequence/SequenceManagerIdentityImpl.java
(original)
+++ db/ojb/branches/OJB_1_0_RELEASE/src/java/org/apache/ojb/broker/util/sequence/SequenceManagerIdentityImpl.java
Thu Oct 19 06:22:02 2006
@@ -96,9 +96,6 @@
      */
     private static volatile long tempKey = -1;
 
-    /**
-     * @deprecated
-     */
     public SequenceManagerIdentityImpl(PersistenceBroker broker)
     {
         super(broker);
@@ -114,6 +111,9 @@
         FieldDescriptor identityField = extractIdentityColumnField(cld);
         if(identityField != null)
         {
+            // if database Identity Columns are used, query the id from database
+            // thus we have to execute batch entries before
+            getBrokerForClass().serviceConnectionManager().executeBatch();
             ifNotReadOnlyFail(identityField);
             long newId = getLastInsert(cld, identityField);
             setFieldValue(obj, identityField, new Long(newId));
@@ -129,12 +129,12 @@
      */
     private FieldDescriptor extractIdentityColumnField(ClassDescriptor cld)
     {
-        FieldDescriptor[] pkFields = cld.getPkFields();
+        FieldDescriptor[] pkFields = cld.getAutoIncrementFields();
         for(int i = 0; i < pkFields.length; i++)
         {
             // to find the identity column we search for a autoincrement
             // read-only field
-            if(pkFields[i].isAutoIncrement() && pkFields[i].isAccessReadOnly())
+            if(pkFields[i].isAccessReadOnly())
             {
                 return pkFields[i];
             }



---------------------------------------------------------------------
To unsubscribe, e-mail: ojb-dev-unsubscribe@db.apache.org
For additional commands, e-mail: ojb-dev-help@db.apache.org


Mime
View raw message