db-ojb-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From arm...@apache.org
Subject svn commit: r463748 - /db/ojb/branches/OJB_1_0_RELEASE/src/java/org/apache/ojb/broker/util/sequence/
Date Fri, 13 Oct 2006 17:39:51 GMT
Author: arminw
Date: Fri Oct 13 10:39:49 2006
New Revision: 463748

URL: http://svn.apache.org/viewvc?view=rev&rev=463748
Log:
update sequence package to support per field-descriptor sequence manager declaration

Added:
    db/ojb/branches/OJB_1_0_RELEASE/src/java/org/apache/ojb/broker/util/sequence/PerFieldManager.java
Modified:
    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/HighLowSequence.java
    db/ojb/branches/OJB_1_0_RELEASE/src/java/org/apache/ojb/broker/util/sequence/SequenceManagerFactory.java
    db/ojb/branches/OJB_1_0_RELEASE/src/java/org/apache/ojb/broker/util/sequence/SequenceManagerHelper.java
    db/ojb/branches/OJB_1_0_RELEASE/src/java/org/apache/ojb/broker/util/sequence/SequenceManagerHighLowImpl.java
    db/ojb/branches/OJB_1_0_RELEASE/src/java/org/apache/ojb/broker/util/sequence/SequenceManagerMSSQLGuidImpl.java
    db/ojb/branches/OJB_1_0_RELEASE/src/java/org/apache/ojb/broker/util/sequence/SequenceManagerNextValImpl.java
    db/ojb/branches/OJB_1_0_RELEASE/src/java/org/apache/ojb/broker/util/sequence/SequenceManagerSeqHiLoImpl.java
    db/ojb/branches/OJB_1_0_RELEASE/src/java/org/apache/ojb/broker/util/sequence/SequenceManagerStoredProcedureImpl.java
    db/ojb/branches/OJB_1_0_RELEASE/src/java/org/apache/ojb/broker/util/sequence/SequenceManagerTransientImpl.java

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=463748&r1=463747&r2=463748
==============================================================================
--- 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
Fri Oct 13 10:39:49 2006
@@ -31,7 +31,6 @@
  * with a PersistenceBroker argument used by the
  * {@link org.apache.ojb.broker.util.sequence.SequenceManagerFactory}.
  *
- * @author <a href="mailto:armin@codeAuLait.de">Armin Waibel</a>
  * @version $Id$
  */
 public abstract class AbstractSequenceManager implements SequenceManager
@@ -49,6 +48,7 @@
      *
      * @param broker  PB instance to perform the
      * id generation.
+     * @deprecated
      */
     public AbstractSequenceManager(PersistenceBroker broker)
     {
@@ -60,6 +60,20 @@
         if (sd != null)
         {
             this.configurationProperties.putAll(sd.getConfigurationProperties());
+        }
+    }
+
+    /**
+     * Constructor used to create a new instance.
+     */
+    public AbstractSequenceManager(PersistenceBroker broker, SequenceDescriptor sequenceDescriptor)
+    {
+        this.brokerForClass = broker;
+        this.configurationProperties = new Properties();
+        this.platform = brokerForClass.serviceConnectionManager().getSupportedPlatform();
+        if (sequenceDescriptor != null)
+        {
+            this.configurationProperties.putAll(sequenceDescriptor.getConfigurationProperties());
         }
     }
 

Modified: db/ojb/branches/OJB_1_0_RELEASE/src/java/org/apache/ojb/broker/util/sequence/HighLowSequence.java
URL: http://svn.apache.org/viewvc/db/ojb/branches/OJB_1_0_RELEASE/src/java/org/apache/ojb/broker/util/sequence/HighLowSequence.java?view=diff&rev=463748&r1=463747&r2=463748
==============================================================================
--- db/ojb/branches/OJB_1_0_RELEASE/src/java/org/apache/ojb/broker/util/sequence/HighLowSequence.java
(original)
+++ db/ojb/branches/OJB_1_0_RELEASE/src/java/org/apache/ojb/broker/util/sequence/HighLowSequence.java
Fri Oct 13 10:39:49 2006
@@ -43,20 +43,19 @@
     {
         // make sure that version column in DB is never 'null'
         // to avoid problems with
-        this(null, 0, 0, new Integer(0));
+        this(null, 0, new Integer(0));
     }
 
-    public HighLowSequence(String tableName, long maxKey, int grabSize, Integer version)
+    public HighLowSequence(String tableName, long maxKey, Integer version)
     {
         this.name = tableName;
         this.maxKey = maxKey;
-        this.grabSize = grabSize;
         this.version = version;
     }
 
     public HighLowSequence getCopy()
     {
-        HighLowSequence result = new HighLowSequence(this.name, this.maxKey, this.grabSize,
this.version);
+        HighLowSequence result = new HighLowSequence(this.name, this.maxKey, this.version);
         result.curVal = this.curVal;
         return result;
     }
@@ -65,7 +64,6 @@
     {
         ToStringBuilder buf = new ToStringBuilder(this, ToStringStyle.DEFAULT_STYLE);
         buf.append("name", name).
-                append("grabSize", grabSize).
                 append("version", version).
                 append("maxKey", maxKey).
                 append("currentKey", curVal);
@@ -96,6 +94,7 @@
      * Sets the grab size attribute of the HighLowSequence object
      *
      * @param grabSize  The new grabSize value
+     * @deprecated
      */
     public void setGrabSize(int grabSize)
     {
@@ -126,6 +125,7 @@
      * Gets the grabSize attribute of the HighLowSequence object
      *
      * @return   The grabSize value
+     * @deprecated
      */
     public int getGrabSize()
     {
@@ -164,7 +164,7 @@
     /**
      * Grabs the next key set, the sequence must be saved afterwards!!
      */
-    public void grabNextKeySet()
+    public void grabNextKeySet(int grabSize)
     {
         curVal = maxKey;
         maxKey = maxKey + grabSize;

Added: db/ojb/branches/OJB_1_0_RELEASE/src/java/org/apache/ojb/broker/util/sequence/PerFieldManager.java
URL: http://svn.apache.org/viewvc/db/ojb/branches/OJB_1_0_RELEASE/src/java/org/apache/ojb/broker/util/sequence/PerFieldManager.java?view=auto&rev=463748
==============================================================================
--- db/ojb/branches/OJB_1_0_RELEASE/src/java/org/apache/ojb/broker/util/sequence/PerFieldManager.java
(added)
+++ db/ojb/branches/OJB_1_0_RELEASE/src/java/org/apache/ojb/broker/util/sequence/PerFieldManager.java
Fri Oct 13 10:39:49 2006
@@ -0,0 +1,139 @@
+package org.apache.ojb.broker.util.sequence;
+
+/* Copyright 2002-2006 The Apache Software Foundation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+import java.lang.Object;
+import java.util.Map;
+
+import org.apache.ojb.broker.util.logging.Logger;
+import org.apache.ojb.broker.util.logging.LoggerFactory;
+import org.apache.ojb.broker.PersistenceBroker;
+import org.apache.ojb.broker.accesslayer.JdbcAccess;
+import org.apache.ojb.broker.metadata.SequenceDescriptor;
+import org.apache.ojb.broker.metadata.FieldDescriptor;
+import org.apache.ojb.broker.metadata.ClassDescriptor;
+import org.apache.commons.collections.map.ReferenceMap;
+
+/**
+ * A sequence manager implementation which handle per field sequence manager
+ * declarations.
+ *
+ * @version $Id: $
+ */
+public class PerFieldManager implements SequenceManager
+{
+    private Logger log = LoggerFactory.getLogger(this.getClass());
+
+    private Map fieldToManagerMap;
+    private SequenceManager defaultManager;
+    private PersistenceBroker broker;
+
+    /**
+     * Constructor.
+     * @param broker The associated broker instance.
+     * @param defaultManager The default sequence manager instance used if no specific
+     * sequence manager ({@link org.apache.ojb.broker.metadata.SequenceDescriptor}) is set
+     * for the {@link org.apache.ojb.broker.metadata.FieldDescriptor}.
+     */
+    public PerFieldManager(PersistenceBroker broker, SequenceManager defaultManager)
+    {
+        this.broker = broker;
+        setDefaultManager(defaultManager);
+        log.info("Init per field sequence manager. Current set default manager is " + defaultManager);
+        fieldToManagerMap = new ReferenceMap(ReferenceMap.WEAK, ReferenceMap.HARD);
+    }
+
+    /**
+     * Get the default manager.
+     */
+    public SequenceManager getDefaultManager()
+    {
+        return defaultManager;
+    }
+
+    /**
+     * Set the default manager instance used for all {@link org.apache.ojb.broker.metadata.FieldDescriptor}
+     * without specific {@link org.apache.ojb.broker.metadata.SequenceDescriptor}.
+     *
+     * @param defaultManager The default {@link SequenceManager} instance.
+     */
+    public void setDefaultManager(SequenceManager defaultManager)
+    {
+        if(log.isDebugEnabled()) log.debug("Set default sequence manager: " + defaultManager);
+        this.defaultManager = defaultManager;
+    }
+
+    public Object getUniqueValue(FieldDescriptor field) throws SequenceManagerException
+    {
+        SequenceManager sm = lookup(field);
+        return sm.getUniqueValue(field);
+    }
+
+    public void afterStore(JdbcAccess dbAccess, ClassDescriptor cld, Object obj) throws SequenceManagerException
+    {
+        FieldDescriptor[] pks = cld.getFieldDescriptor(false);
+        FieldDescriptor result;
+        for(int i = 0; i < pks.length; i++)
+        {
+            result = pks[i];
+            if(result.isAutoIncrement())
+            {
+                SequenceManager sm = lookup(result);
+                if(sm != null)
+                {
+                    sm.afterStore(dbAccess, cld, obj);
+                }
+            }
+        }
+    }
+
+    private SequenceManager lookup(FieldDescriptor field)
+    {
+        SequenceManager sm = (SequenceManager) fieldToManagerMap.get(field);
+        if(sm == null && field.isAutoIncrement())
+        {
+            SequenceDescriptor sd = field.getSequenceDescriptor();
+            if(sd != null)
+            {
+                if(log.isDebugEnabled())
+                {
+                    ClassDescriptor cld = field.getClassDescriptor();
+                    log.debug("Create field specific sequence manager for field '"
+                            + field.getPersistentField().getName()
+                            + "' of class '"
+                            + (cld != null ? cld.getClassNameOfObject() : "null")
+                            + "', using sequence descriptor=" + sd);
+                }
+                sm = SequenceManagerHelper.createManager(broker, sd);
+            }
+            else
+            {
+                if(log.isDebugEnabled())
+                {
+                    ClassDescriptor cld = field.getClassDescriptor();
+                    log.debug("Use default sequence manager for field '"
+                                + field.getPersistentField().getName()
+                                + "' of class '"
+                                + (cld != null ? cld.getClassNameOfObject() : "null")
+                                + "'");
+                }
+                sm = defaultManager;
+            }
+            fieldToManagerMap.put(field, sm);
+        }
+        return sm;
+    }
+}

Modified: db/ojb/branches/OJB_1_0_RELEASE/src/java/org/apache/ojb/broker/util/sequence/SequenceManagerFactory.java
URL: http://svn.apache.org/viewvc/db/ojb/branches/OJB_1_0_RELEASE/src/java/org/apache/ojb/broker/util/sequence/SequenceManagerFactory.java?view=diff&rev=463748&r1=463747&r2=463748
==============================================================================
--- db/ojb/branches/OJB_1_0_RELEASE/src/java/org/apache/ojb/broker/util/sequence/SequenceManagerFactory.java
(original)
+++ db/ojb/branches/OJB_1_0_RELEASE/src/java/org/apache/ojb/broker/util/sequence/SequenceManagerFactory.java
Fri Oct 13 10:39:49 2006
@@ -25,18 +25,16 @@
 /**
  * Threadsafe factory class, creates <code>SequenceManager</code> instances.
  * The implementation class is configured by the OJB.properties file.
+ * @deprecated use {@link org.apache.ojb.broker.metadata.SequenceDescriptor} to get the implementation
class
+ * and {@link org.apache.ojb.broker.util.ClassHelper} to create instance.
  */
 public class SequenceManagerFactory
 {
     private static Logger log = LoggerFactory.getLogger(SequenceManagerFactory.class);
     private static SequenceManagerFactory singleton;
 
-    private Class defaultSeqManagerClass;
-
     public SequenceManagerFactory()
     {
-        defaultSeqManagerClass = SequenceManagerHighLowImpl.class;
-        if(log.isDebugEnabled()) log.debug("Default sequence manager class was " + defaultSeqManagerClass.getName());
     }
 
     public synchronized static SequenceManager getSequenceManager(PersistenceBroker broker)
@@ -56,7 +54,7 @@
             try
             {
                 // first we use seqMan defined in the OJB.properties
-                Class seqManClass = defaultSeqManagerClass;
+                Class seqManClass = SequenceManagerInMemoryImpl.class;
                 SequenceDescriptor sd = broker.serviceConnectionManager().getConnectionDescriptor().getSequenceDescriptor();
                 if (sd != null && sd.getSequenceManagerClass() != null)
                 {

Modified: db/ojb/branches/OJB_1_0_RELEASE/src/java/org/apache/ojb/broker/util/sequence/SequenceManagerHelper.java
URL: http://svn.apache.org/viewvc/db/ojb/branches/OJB_1_0_RELEASE/src/java/org/apache/ojb/broker/util/sequence/SequenceManagerHelper.java?view=diff&rev=463748&r1=463747&r2=463748
==============================================================================
--- db/ojb/branches/OJB_1_0_RELEASE/src/java/org/apache/ojb/broker/util/sequence/SequenceManagerHelper.java
(original)
+++ db/ojb/branches/OJB_1_0_RELEASE/src/java/org/apache/ojb/broker/util/sequence/SequenceManagerHelper.java
Fri Oct 13 10:39:49 2006
@@ -22,12 +22,15 @@
 import java.util.Properties;
 import java.util.Vector;
 
+import org.apache.ojb.broker.OJBRuntimeException;
 import org.apache.ojb.broker.PersistenceBroker;
 import org.apache.ojb.broker.PersistenceBrokerException;
 import org.apache.ojb.broker.accesslayer.StatementManagerIF;
 import org.apache.ojb.broker.metadata.ClassDescriptor;
 import org.apache.ojb.broker.metadata.FieldDescriptor;
+import org.apache.ojb.broker.metadata.SequenceDescriptor;
 import org.apache.ojb.broker.query.Query;
+import org.apache.ojb.broker.util.ClassHelper;
 import org.apache.ojb.broker.util.logging.Logger;
 import org.apache.ojb.broker.util.logging.LoggerFactory;
 
@@ -47,6 +50,7 @@
     public static final String PROP_SEQ_AS = "seq.as";
     /**
      * Property name used to configure sequence manager implementations.
+     *
      * @deprecated use {@link #PROP_SEQ_START} instead.
      */
     public static final String PROP_SEQ_START_OLD = "sequenceStart";
@@ -105,6 +109,7 @@
      * using {@link org.apache.ojb.broker.metadata.FieldDescriptor#setSequenceName}
      * to speed up sequence name lookup in future calls.
      * </p>
+     *
      * @param brokerForClass current used PB instance
      * @param field target field
      * @param autoNaming if 'false' no auto sequence name was build and
@@ -119,11 +124,11 @@
         if we found a sequence name bound to the field descriptor
         via 'sequence-name' attribute we use that name
         */
-        if (seqName != null && seqName.trim().length() != 0)
+        if(seqName != null && seqName.trim().length() != 0)
         {
             return seqName;
         }
-        else if (!autoNaming)
+        else if(!autoNaming)
         {
             /*
             arminw:
@@ -158,7 +163,7 @@
          * the table name of the 'targetClass'.
          *
          */
-        if (cldTopLevel.isExtent())
+        if(cldTopLevel.isExtent())
         {
             /*
             arminw:
@@ -178,7 +183,7 @@
             seqName = cldTargetClass.getFullTableName();
         }
 //        log.info("* targetClass: "+targetClass +", toplevel: "+topLevel+ " seqName: "+seqName);
-        if (seqName == null)
+        if(seqName == null)
         {
             seqName = SEQ_UNASSIGNED;
             log.warn("Too complex structure, can not assign automatic sequence name for field
'" +
@@ -188,11 +193,11 @@
         }
 //        System.out.println("* targetClass: " + cldTargetClass.getClassNameOfObject() +
", toplevel: " + topLevel + " seqName: " + seqName);
         seqName = SEQ_PREFIX + seqName;
-        if (log.isDebugEnabled())
-                log.debug("Set automatic generated sequence-name for field '" +
-                        field.getAttributeName() + "' in class '" +
-                        field.getClassDescriptor().getClassNameOfObject() +
-                        "'.");
+        if(log.isDebugEnabled())
+            log.debug("Set automatic generated sequence-name for field '" +
+                    field.getAttributeName() + "' in class '" +
+                    field.getClassDescriptor().getClassNameOfObject() +
+                    "'.");
         field.setSequenceName(seqName);
         return seqName;
     }
@@ -220,18 +225,18 @@
     private static String firstFoundTableName(PersistenceBroker brokerForClass, ClassDescriptor
cld)
     {
         String name = null;
-        if (!cld.isInterface() && cld.getFullTableName() != null)
+        if(!cld.isInterface() && cld.getFullTableName() != null)
         {
             return cld.getFullTableName();
         }
-        if (cld.isExtent())
+        if(cld.isExtent())
         {
             Collection extentClasses = cld.getExtentClasses();
-            for (Iterator iterator = extentClasses.iterator(); iterator.hasNext();)
+            for(Iterator iterator = extentClasses.iterator(); iterator.hasNext();)
             {
                 name = firstFoundTableName(brokerForClass, brokerForClass.getClassDescriptor((Class)
iterator.next()));
                 // System.out.println("## " + cld.getClassNameOfObject()+" - name: "+name);
-                if (name != null) break;
+                if(name != null) break;
             }
         }
         return name;
@@ -241,13 +246,14 @@
      * Lookup all tables associated with given class (search all extent classes)
      * to find the current maximum value for the given field.
      * <br><b>Note:</b> Only works for <code>long</code> autoincrement
fields.
+     *
      * @param brokerForClass persistence broker instance match the database of the
      * given field/class
      * @param field the target field
      */
     public static long getMaxForExtent(PersistenceBroker brokerForClass, FieldDescriptor
field) throws PersistenceBrokerException
     {
-        if (field == null)
+        if(field == null)
         {
             log.error("Given FieldDescriptor was null, could not detect max value across
all extents");
             return 0;
@@ -269,22 +275,22 @@
         ClassDescriptor cld = brokerForClass.getClassDescriptor(topLevel);
 
         // if class is not an interface / not abstract we have to search its directly mapped
table
-        if (!cld.isInterface() && !cld.isAbstract())
+        if(!cld.isInterface() && !cld.isAbstract())
         {
             tmp = getMaxIdForClass(brokerForClass, cld, original);
-            if (tmp > max)
+            if(tmp > max)
             {
                 max = tmp;
             }
         }
         // if class is an extent we have to search through its subclasses
-        if (cld.isExtent())
+        if(cld.isExtent())
         {
             Vector extentClasses = cld.getExtentClasses();
-            for (int i = 0; i < extentClasses.size(); i++)
+            for(int i = 0; i < extentClasses.size(); i++)
             {
                 Class extentClass = (Class) extentClasses.get(i);
-                if (cld.getClassOfObject().equals(extentClass))
+                if(cld.getClassOfObject().equals(extentClass))
                 {
                     throw new PersistenceBrokerException("Circular extent in " + extentClass
+
                             ", please check the repository");
@@ -295,7 +301,7 @@
                     // Call recursive
                     tmp = getMaxId(brokerForClass, extentClass, original);
                 }
-                if (tmp > max)
+                if(tmp > max)
                 {
                     max = tmp;
                 }
@@ -313,10 +319,10 @@
             throws PersistenceBrokerException
     {
         FieldDescriptor field = null;
-        if (!original.getClassDescriptor().equals(cldForOriginalOrExtent))
+        if(!original.getClassDescriptor().equals(cldForOriginalOrExtent))
         {
             // check if extent match not the same table
-            if (!original.getClassDescriptor().getFullTableName().equals(
+            if(!original.getClassDescriptor().getFullTableName().equals(
                     cldForOriginalOrExtent.getFullTableName()))
             {
                 // we have to look for id's in extent class table
@@ -327,7 +333,7 @@
         {
             field = original;
         }
-        if (field == null)
+        if(field == null)
         {
             // if null skip this call
             return 0;
@@ -349,7 +355,7 @@
             rs.next();
             result = rs.getLong(1);
         }
-        catch (Exception e)
+        catch(Exception e)
         {
             log.warn("Cannot lookup max value from table " + table + " for column " + column
+
                     ", PB was " + brokerForClass + ", using jdbc-descriptor " +
@@ -361,10 +367,10 @@
             {
                 sm.closeResources(stmt, rs);
             }
-            catch (Exception ignore)
+            catch(Exception ignore)
             {
                 // ignore it
-           }
+            }
         }
         return result;
     }
@@ -531,5 +537,40 @@
     public static String getSeqAsValue(Properties prop)
     {
         return prop.getProperty(PROP_SEQ_AS, null);
+    }
+
+    /**
+     * Create a new {@link SequenceManager} instance.
+     *
+     * @param broker The broker instance.
+     * @param descriptor The {@link org.apache.ojb.broker.metadata.SequenceDescriptor}.
+     * @return The new instance.
+     */
+    public static SequenceManager createManager(PersistenceBroker broker, SequenceDescriptor
descriptor)
+    {
+        try
+        {
+            return (SequenceManager) ClassHelper.newInstance(
+                    descriptor.getSequenceManagerClass(),
+                    new Class[]{PersistenceBroker.class, SequenceDescriptor.class},
+                    new Object[]{broker, descriptor});
+        }
+        catch(Exception e)
+        {
+            // for backward compatibility try the deprecated constructor
+            try
+            {
+                return (SequenceManager) ClassHelper.newInstance(
+                        descriptor.getSequenceManagerClass(),
+                        new Class[]{PersistenceBroker.class},
+                        new Object[]{broker});
+            }
+            catch(Exception e1)
+            {
+                log.error("Can't instantiate sequence manager", e);
+                log.error("Can't instantiate sequence manager using deprecated constructor",
e1);
+                throw new OJBRuntimeException("Can't instantiate sequence manager", e);
+            }
+        }
     }
 }

Modified: db/ojb/branches/OJB_1_0_RELEASE/src/java/org/apache/ojb/broker/util/sequence/SequenceManagerHighLowImpl.java
URL: http://svn.apache.org/viewvc/db/ojb/branches/OJB_1_0_RELEASE/src/java/org/apache/ojb/broker/util/sequence/SequenceManagerHighLowImpl.java?view=diff&rev=463748&r1=463747&r2=463748
==============================================================================
--- db/ojb/branches/OJB_1_0_RELEASE/src/java/org/apache/ojb/broker/util/sequence/SequenceManagerHighLowImpl.java
(original)
+++ db/ojb/branches/OJB_1_0_RELEASE/src/java/org/apache/ojb/broker/util/sequence/SequenceManagerHighLowImpl.java
Fri Oct 13 10:39:49 2006
@@ -24,6 +24,7 @@
 import org.apache.ojb.broker.PersistenceBroker;
 import org.apache.ojb.broker.PersistenceBrokerFactory;
 import org.apache.ojb.broker.metadata.FieldDescriptor;
+import org.apache.ojb.broker.metadata.SequenceDescriptor;
 import org.apache.ojb.broker.util.ObjectModification;
 import org.apache.ojb.broker.util.logging.Logger;
 import org.apache.ojb.broker.util.logging.LoggerFactory;
@@ -107,10 +108,8 @@
  *
  *
  * @see org.apache.ojb.broker.util.sequence.SequenceManager
- * @see org.apache.ojb.broker.util.sequence.SequenceManagerFactory
  * @see org.apache.ojb.broker.util.sequence.SequenceManagerHelper
  *
- * @author <a href="mailto:armin@codeAuLait.de">Armin Waibel</a>
  * @version $Id$
  */
 public class SequenceManagerHighLowImpl extends AbstractSequenceManager
@@ -132,9 +131,23 @@
     protected long sequenceStart;
     protected int attempts;
 
+    /**
+     * @deprecated
+     */
     public SequenceManagerHighLowImpl(PersistenceBroker broker)
     {
         super(broker);
+        init();
+    }
+
+    public SequenceManagerHighLowImpl(PersistenceBroker broker, SequenceDescriptor descriptor)
+    {
+        super(broker, descriptor);
+        init();
+    }
+
+    void init()
+    {
         Long start = SequenceManagerHelper.getSeqStart(getConfigurationProperties());
         sequenceStart = start != null ? start.longValue() : 1;
         grabSize = Integer.parseInt(getConfigurationProperty(PROPERTY_GRAB_SIZE, "20"));
@@ -320,11 +333,8 @@
             newSequence.setMaxKey(sequenceStart);
         }
 
-        // set current grab size
-        newSequence.setGrabSize(grabSize);
-
         //grab the next key scope
-        newSequence.grabNextKeySet();
+        newSequence.grabNextKeySet(grabSize);
 
         //store the sequence to db
         try
@@ -334,14 +344,18 @@
         }
         catch (OptimisticLockException e)
         {
-            // we try five times to get a new sequence
-            if(attempts < 5)
+            // we try ten times to get a new sequence
+            if(attempts < 10)
             {
                 log.info("OptimisticLockException was thrown, will try again to store sequence.
Sequence was "+newSequence);
                 attempts++;
                 newSequence = lookupStoreSequence(broker, field, seqName);
             }
-            else throw e;
+            else
+            {
+                log.error("Tried 10 times to store sequence object " + newSequence + " without
success");
+                throw e;
+            }
         }
         return newSequence;
     }
@@ -351,7 +365,6 @@
     {
         HighLowSequence seq = new HighLowSequence();
         seq.setName(sequenceName);
-        seq.setGrabSize(grabSize);
         return seq;
     }
 
@@ -387,5 +400,35 @@
             seqName = calculateSequenceName(field);
         }
         return seqName;
+    }
+
+    public int getGrabSize()
+    {
+        return grabSize;
+    }
+
+    public void setGrabSize(int grabSize)
+    {
+        this.grabSize = grabSize;
+    }
+
+    public long getSequenceStart()
+    {
+        return sequenceStart;
+    }
+
+    public void setSequenceStart(long sequenceStart)
+    {
+        this.sequenceStart = sequenceStart;
+    }
+
+    public boolean isUseGlobalSequenceIdentities()
+    {
+        return useGlobalSequenceIdentities;
+    }
+
+    public void setUseGlobalSequenceIdentities(boolean useGlobalSequenceIdentities)
+    {
+        this.useGlobalSequenceIdentities = useGlobalSequenceIdentities;
     }
 }

Modified: db/ojb/branches/OJB_1_0_RELEASE/src/java/org/apache/ojb/broker/util/sequence/SequenceManagerMSSQLGuidImpl.java
URL: http://svn.apache.org/viewvc/db/ojb/branches/OJB_1_0_RELEASE/src/java/org/apache/ojb/broker/util/sequence/SequenceManagerMSSQLGuidImpl.java?view=diff&rev=463748&r1=463747&r2=463748
==============================================================================
--- db/ojb/branches/OJB_1_0_RELEASE/src/java/org/apache/ojb/broker/util/sequence/SequenceManagerMSSQLGuidImpl.java
(original)
+++ db/ojb/branches/OJB_1_0_RELEASE/src/java/org/apache/ojb/broker/util/sequence/SequenceManagerMSSQLGuidImpl.java
Fri Oct 13 10:39:49 2006
@@ -23,6 +23,7 @@
 import org.apache.ojb.broker.accesslayer.ResultSetAndStatement;
 import org.apache.ojb.broker.metadata.FieldDescriptor;
 import org.apache.ojb.broker.metadata.JdbcType;
+import org.apache.ojb.broker.metadata.SequenceDescriptor;
 import org.apache.ojb.broker.query.Query;
 
 import java.sql.SQLException;
@@ -37,7 +38,6 @@
  * This SequenceManager can be used for any classes that have their PK
  * defined as a 'uniqueidetifier'
  *
- * @author <a href="mailto:aclute825@hotmail.com">Andrew Clute</a>
  * @version $Id$
  */
 public class SequenceManagerMSSQLGuidImpl extends AbstractSequenceManager
@@ -49,10 +49,16 @@
      *
      * @param broker  PB instance to perform the
      * id generation.
+     * @deprecated
      */
     public SequenceManagerMSSQLGuidImpl(PersistenceBroker broker)
     {
         super(broker);
+    }
+
+    public SequenceManagerMSSQLGuidImpl(PersistenceBroker broker, SequenceDescriptor descriptor)
+    {
+        super(broker, descriptor);
     }
 
     public Object getUniqueValue(FieldDescriptor field) throws SequenceManagerException

Modified: db/ojb/branches/OJB_1_0_RELEASE/src/java/org/apache/ojb/broker/util/sequence/SequenceManagerNextValImpl.java
URL: http://svn.apache.org/viewvc/db/ojb/branches/OJB_1_0_RELEASE/src/java/org/apache/ojb/broker/util/sequence/SequenceManagerNextValImpl.java?view=diff&rev=463748&r1=463747&r2=463748
==============================================================================
--- db/ojb/branches/OJB_1_0_RELEASE/src/java/org/apache/ojb/broker/util/sequence/SequenceManagerNextValImpl.java
(original)
+++ db/ojb/branches/OJB_1_0_RELEASE/src/java/org/apache/ojb/broker/util/sequence/SequenceManagerNextValImpl.java
Fri Oct 13 10:39:49 2006
@@ -24,6 +24,7 @@
 import org.apache.ojb.broker.accesslayer.StatementManagerIF;
 import org.apache.ojb.broker.metadata.ClassDescriptor;
 import org.apache.ojb.broker.metadata.FieldDescriptor;
+import org.apache.ojb.broker.metadata.SequenceDescriptor;
 import org.apache.ojb.broker.query.Query;
 import org.apache.ojb.broker.util.logging.Logger;
 import org.apache.ojb.broker.util.logging.LoggerFactory;
@@ -81,12 +82,7 @@
  * </ul>
  * </p>
  * <br/>
- * <br/>
  *
- * @author Edson Carlos Ericksson Richter
- * @author Rajeev Kaul
- * @author Thomas Mahler
- * @author Armin Waibel
  * @version $Id$
  */
 public class SequenceManagerNextValImpl extends AbstractSequenceManager
@@ -94,11 +90,16 @@
     private Logger log = LoggerFactory.getLogger(SequenceManagerNextValImpl.class);
 
     /**
-     *
+     * @deprecated
      */
     public SequenceManagerNextValImpl(PersistenceBroker broker)
     {
         super(broker);
+    }
+
+    public SequenceManagerNextValImpl(PersistenceBroker broker, SequenceDescriptor descriptor)
+    {
+        super(broker, descriptor);
     }
 
     /**

Modified: db/ojb/branches/OJB_1_0_RELEASE/src/java/org/apache/ojb/broker/util/sequence/SequenceManagerSeqHiLoImpl.java
URL: http://svn.apache.org/viewvc/db/ojb/branches/OJB_1_0_RELEASE/src/java/org/apache/ojb/broker/util/sequence/SequenceManagerSeqHiLoImpl.java?view=diff&rev=463748&r1=463747&r2=463748
==============================================================================
--- db/ojb/branches/OJB_1_0_RELEASE/src/java/org/apache/ojb/broker/util/sequence/SequenceManagerSeqHiLoImpl.java
(original)
+++ db/ojb/branches/OJB_1_0_RELEASE/src/java/org/apache/ojb/broker/util/sequence/SequenceManagerSeqHiLoImpl.java
Fri Oct 13 10:39:49 2006
@@ -17,6 +17,7 @@
 
 import org.apache.ojb.broker.PersistenceBroker;
 import org.apache.ojb.broker.metadata.FieldDescriptor;
+import org.apache.ojb.broker.metadata.SequenceDescriptor;
 
 import java.util.HashMap;
 
@@ -64,9 +65,7 @@
  * </ul>
  * </p>
  * <br/>
- * <br/>
  *
- * @author <a href="mailto:armin@codeAuLait.de">Armin Waibel</a>
  * @version $Id$
  */
 public class SequenceManagerSeqHiLoImpl extends SequenceManagerNextValImpl
@@ -76,12 +75,21 @@
 
     protected int grabSize;
 
+    /**
+     * @deprecated
+     */
     public SequenceManagerSeqHiLoImpl(PersistenceBroker broker)
     {
         super(broker);
         grabSize = Integer.parseInt(getConfigurationProperty(PROPERTY_GRAB_SIZE, "20"));
     }
 
+    public SequenceManagerSeqHiLoImpl(PersistenceBroker broker, SequenceDescriptor descriptor)
+    {
+        super(broker, descriptor);
+        grabSize = Integer.parseInt(getConfigurationProperty(PROPERTY_GRAB_SIZE, "20"));
+    }
+
     protected long getUniqueLong(FieldDescriptor field) throws SequenceManagerException
     {
         String sequenceName = calculateSequenceName(field);
@@ -91,6 +99,7 @@
             HiLoEntry entry = (HiLoEntry) hiLoMap.get(sequenceName);
             if (entry == null)
             {
+                // start with exhausted entry object
                 entry = new HiLoEntry(grabSize, grabSize);
                 hiLoMap.put(sequenceName, entry);
             }
@@ -101,6 +110,16 @@
             }
             return entry.nextVal();
         }
+    }
+
+    public int getGrabSize()
+    {
+        return grabSize;
+    }
+
+    public void setGrabSize(int grabSize)
+    {
+        this.grabSize = grabSize;
     }
 
     class HiLoEntry

Modified: db/ojb/branches/OJB_1_0_RELEASE/src/java/org/apache/ojb/broker/util/sequence/SequenceManagerStoredProcedureImpl.java
URL: http://svn.apache.org/viewvc/db/ojb/branches/OJB_1_0_RELEASE/src/java/org/apache/ojb/broker/util/sequence/SequenceManagerStoredProcedureImpl.java?view=diff&rev=463748&r1=463747&r2=463748
==============================================================================
--- db/ojb/branches/OJB_1_0_RELEASE/src/java/org/apache/ojb/broker/util/sequence/SequenceManagerStoredProcedureImpl.java
(original)
+++ db/ojb/branches/OJB_1_0_RELEASE/src/java/org/apache/ojb/broker/util/sequence/SequenceManagerStoredProcedureImpl.java
Fri Oct 13 10:39:49 2006
@@ -20,6 +20,7 @@
 import org.apache.ojb.broker.platforms.PlatformException;
 import org.apache.ojb.broker.accesslayer.LookupException;
 import org.apache.ojb.broker.metadata.FieldDescriptor;
+import org.apache.ojb.broker.metadata.SequenceDescriptor;
 import org.apache.ojb.broker.query.Query;
 import org.apache.ojb.broker.util.logging.Logger;
 import org.apache.ojb.broker.util.logging.LoggerFactory;
@@ -126,13 +127,16 @@
     protected static final String SEQ_TABLE_NAME = "OJB_NEXTVAL_SEQ";
 
     /**
-     * Constructor
-     *
-     * @param broker
+     * @deprecated
      */
     public SequenceManagerStoredProcedureImpl(PersistenceBroker broker)
     {
         super(broker);
+    }
+
+    public SequenceManagerStoredProcedureImpl(PersistenceBroker broker, SequenceDescriptor
descriptor)
+    {
+        super(broker, descriptor);
     }
 
     /**

Modified: db/ojb/branches/OJB_1_0_RELEASE/src/java/org/apache/ojb/broker/util/sequence/SequenceManagerTransientImpl.java
URL: http://svn.apache.org/viewvc/db/ojb/branches/OJB_1_0_RELEASE/src/java/org/apache/ojb/broker/util/sequence/SequenceManagerTransientImpl.java?view=diff&rev=463748&r1=463747&r2=463748
==============================================================================
--- db/ojb/branches/OJB_1_0_RELEASE/src/java/org/apache/ojb/broker/util/sequence/SequenceManagerTransientImpl.java
(original)
+++ db/ojb/branches/OJB_1_0_RELEASE/src/java/org/apache/ojb/broker/util/sequence/SequenceManagerTransientImpl.java
Fri Oct 13 10:39:49 2006
@@ -17,6 +17,7 @@
 
 import org.apache.ojb.broker.PersistenceBroker;
 import org.apache.ojb.broker.metadata.FieldDescriptor;
+import org.apache.ojb.broker.metadata.SequenceDescriptor;
 
 /**
  * For internal use only!
@@ -33,10 +34,20 @@
      */
     private static volatile long tempKey = -1000;
 
+    /**
+     * @deprecated
+     */
     public SequenceManagerTransientImpl(PersistenceBroker broker)
     {
         super(broker);
     }
+
+    public SequenceManagerTransientImpl(PersistenceBroker broker, SequenceDescriptor descriptor)
+    {
+        super(broker, descriptor);
+    }
+
+
 
     protected long getUniqueLong(FieldDescriptor field) throws SequenceManagerException
     {



---------------------------------------------------------------------
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