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 SequenceManagerNativeImpl.java SequenceManagerInMemoryImpl.java SequenceManagerHighLowImpl.java AbstractSequenceManager.java
Date Wed, 13 Aug 2003 18:16:10 GMT
arminw      2003/08/13 11:16:10

  Modified:    src/java/org/apache/ojb/broker/util/sequence
                        SequenceManagerStoredProcedureImpl.java
                        SequenceManagerSeqHiLoImpl.java
                        SequenceManagerNextValImpl.java
                        SequenceManagerNativeImpl.java
                        SequenceManagerInMemoryImpl.java
                        SequenceManagerHighLowImpl.java
                        AbstractSequenceManager.java
  Log:
  - fix bug in database based SM
  implementation
  - all implementations now use SqlTypeHelper
  class to resolve sql/java type mappings
  - sequence name building centralized in
  abstract SM class
  
  Revision  Changes    Path
  1.6       +2 -2      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.5
  retrieving revision 1.6
  diff -u -r1.5 -r1.6
  --- SequenceManagerStoredProcedureImpl.java	11 Apr 2003 21:59:49 -0000	1.5
  +++ SequenceManagerStoredProcedureImpl.java	13 Aug 2003 18:16:10 -0000	1.6
  @@ -219,7 +219,7 @@
           try
           {
               // lookup sequence name
  -            String sequenceName = SequenceManagerHelper.buildSequenceName(targetBroker,
field, useAutoNaming());
  +            String sequenceName = calculateSequenceName(field);
               try
               {
                   result = buildNextSequence(targetBroker, field.getClassDescriptor(), sequenceName);
  
  
  
  1.6       +2 -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.5
  retrieving revision 1.6
  diff -u -r1.5 -r1.6
  --- SequenceManagerSeqHiLoImpl.java	11 Apr 2003 21:59:49 -0000	1.5
  +++ SequenceManagerSeqHiLoImpl.java	13 Aug 2003 18:16:10 -0000	1.6
  @@ -123,7 +123,7 @@
   
       protected long getUniqueLong(FieldDescriptor field) throws SequenceManagerException
       {
  -        String sequenceName = SequenceManagerHelper.buildSequenceName(getBrokerForClass(),
field, useAutoNaming());
  +        String sequenceName = calculateSequenceName(field);
           // we have to be threadsafe
           synchronized (hiLoMap)
           {
  
  
  
  1.10      +8 -6      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.9
  retrieving revision 1.10
  diff -u -r1.9 -r1.10
  --- SequenceManagerNextValImpl.java	11 Apr 2003 21:59:49 -0000	1.9
  +++ SequenceManagerNextValImpl.java	13 Aug 2003 18:16:10 -0000	1.10
  @@ -56,6 +56,8 @@
   
   import org.apache.commons.lang.SystemUtils;
   import org.apache.ojb.broker.PersistenceBroker;
  +import org.apache.ojb.broker.util.logging.Logger;
  +import org.apache.ojb.broker.util.logging.LoggerFactory;
   import org.apache.ojb.broker.metadata.ClassDescriptor;
   import org.apache.ojb.broker.metadata.FieldDescriptor;
   import org.apache.ojb.broker.query.Query;
  @@ -127,6 +129,7 @@
    */
   public class SequenceManagerNextValImpl extends AbstractSequenceManager
   {
  +    private Logger log = LoggerFactory.getLogger(SequenceManagerNextValImpl.class);
       /**
        *
        */
  @@ -153,18 +156,17 @@
       {
           long result = 0;
           // lookup sequence name
  -        String sequenceName = SequenceManagerHelper.buildSequenceName(getBrokerForClass(),
field, useAutoNaming());
  +        String sequenceName = calculateSequenceName(field);
           try
           {
               result = buildNextSequence(field.getClassDescriptor(), sequenceName);
           }
  -        catch (Exception e)
  +        catch (Throwable 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
               {
  +                log.info("Create DB sequence key '"+sequenceName+"'");
                   createSequence(field.getClassDescriptor(), sequenceName);
               }
               catch (Exception e1)
  @@ -181,7 +183,7 @@
               {
                   result = buildNextSequence(field.getClassDescriptor(), sequenceName);
               }
  -            catch (Exception e1)
  +            catch (Throwable e1)
               {
                   throw new SequenceManagerException("Could not grab next id, sequence seems
to exist", e);
               }
  
  
  
  1.7       +6 -120    db-ojb/src/java/org/apache/ojb/broker/util/sequence/SequenceManagerNativeImpl.java
  
  Index: SequenceManagerNativeImpl.java
  ===================================================================
  RCS file: /home/cvs/db-ojb/src/java/org/apache/ojb/broker/util/sequence/SequenceManagerNativeImpl.java,v
  retrieving revision 1.6
  retrieving revision 1.7
  diff -u -r1.6 -r1.7
  --- SequenceManagerNativeImpl.java	5 Aug 2003 07:21:26 -0000	1.6
  +++ SequenceManagerNativeImpl.java	13 Aug 2003 18:16:10 -0000	1.7
  @@ -63,15 +63,11 @@
   import org.apache.ojb.broker.metadata.ObjectReferenceDescriptor;
   import org.apache.ojb.broker.metadata.fieldaccess.PersistentField;
   import org.apache.ojb.broker.util.ProxyHelper;
  +import org.apache.ojb.broker.util.SqlTypeHelper;
   
  -import java.math.BigDecimal;
  -import java.sql.Date;
   import java.sql.ResultSet;
   import java.sql.SQLException;
   import java.sql.Statement;
  -import java.sql.Time;
  -import java.sql.Timestamp;
  -import java.sql.Types;
   import java.util.Iterator;
   import java.util.Vector;
   
  @@ -141,7 +137,7 @@
       public void afterStore(JdbcAccess dbAccess, ClassDescriptor cld, Object obj) throws
SequenceManagerException
       {
           FieldDescriptor fd = cld.getAutoIncrementField();
  -        long newId = getLastInsert(dbAccess, cld);
  +        long newId = getLastInsert(cld);
           setFieldValue(obj, fd, new Long(newId));
       }
   
  @@ -205,7 +201,7 @@
           }
       }
   
  -    private long getLastInsert(JdbcAccess dbAccess, ClassDescriptor cld) throws SequenceManagerException
  +    private long getLastInsert(ClassDescriptor cld) throws SequenceManagerException
       {
           FieldDescriptor fd = cld.getAutoIncrementField();
           long newId = 0;
  @@ -256,119 +252,9 @@
                   getSupportedPlatform().getLastInsertIdentityQuery(tableName);
       }
   
  -    private void setFieldValue(Object obj, FieldDescriptor field, Long identifier)
  -            throws SequenceManagerException
  +    private void setFieldValue(Object obj, FieldDescriptor field, Long identifier) throws
SequenceManagerException
       {
  -        Object result = null;
  -        switch (field.getColumnJdbcType())
  -        {
  -            case Types.ARRAY:
  -                {
  -                    Object[] arr = {identifier.toString()};
  -                    result = arr;
  -                    break;
  -                }
  -            case Types.BIGINT:
  -                {
  -                    result = identifier;
  -                    break;
  -                }
  -            case Types.BINARY:
  -                {
  -                    result = identifier.toString().getBytes();
  -                    break;
  -                }
  -            case Types.CHAR:
  -                {
  -                    result = identifier.toString();
  -                    break;
  -                }
  -            case Types.DATE:
  -                {
  -                    result = new Date(identifier.longValue());
  -                    break;
  -                }
  -            case Types.DECIMAL:
  -                {
  -                    result = new BigDecimal(identifier.longValue());
  -                    break;
  -                }
  -            case Types.DOUBLE:
  -                {
  -                    result = new Double(identifier.doubleValue());
  -                    break;
  -                }
  -            case Types.FLOAT:
  -                {
  -                    result = new Double(identifier.doubleValue());
  -                    break;
  -                }
  -            case Types.INTEGER:
  -                {
  -                    result = new Integer(identifier.intValue());
  -                    break;
  -                }
  -            case Types.JAVA_OBJECT:
  -                {
  -                    result = identifier;
  -                    break;
  -                }
  -            case Types.LONGVARBINARY:
  -                {
  -                    result = identifier.toString().getBytes();
  -                    break;
  -                }
  -            case Types.LONGVARCHAR:
  -                {
  -                    result = identifier.toString();
  -                    break;
  -                }
  -            case Types.NUMERIC:
  -                {
  -                    result = new BigDecimal(identifier.longValue());
  -                    break;
  -                }
  -            case Types.REAL:
  -                {
  -                    result = new Float(identifier.floatValue());
  -                    break;
  -                }
  -            case Types.SMALLINT:
  -                {
  -                    result = new Short(identifier.shortValue());
  -                    break;
  -                }
  -            case Types.TIME:
  -                {
  -                    result = new Time(identifier.longValue());
  -                    break;
  -                }
  -            case Types.TIMESTAMP:
  -                {
  -                    result = new Timestamp(identifier.longValue());
  -                    break;
  -                }
  -            case Types.TINYINT:
  -                {
  -                    result = new Byte(identifier.byteValue());
  -                    break;
  -                }
  -            case Types.VARBINARY:
  -                {
  -                    result = (byte[]) identifier.toString().getBytes();
  -                    break;
  -                }
  -            case Types.VARCHAR:
  -                {
  -                    result = identifier.toString();
  -                    break;
  -                }
  -            default:
  -                {
  -                    result = identifier;
  -                    break;
  -                }
  -        }
  +        Object result = SqlTypeHelper.sequenceKeyConversion(field.getColumnJdbcType(),
identifier);
           result = field.getFieldConversion().sqlToJava(result);
           PersistentField pf = field.getPersistentField();
           pf.set(obj, result);
  
  
  
  1.12      +2 -2      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.11
  retrieving revision 1.12
  diff -u -r1.11 -r1.12
  --- SequenceManagerInMemoryImpl.java	22 May 2003 22:24:09 -0000	1.11
  +++ SequenceManagerInMemoryImpl.java	13 Aug 2003 18:16:10 -0000	1.12
  @@ -118,7 +118,7 @@
   
       protected long getUniqueLong(FieldDescriptor field) throws SequenceManagerException
       {
  -        String seqName = SequenceManagerHelper.buildSequenceName(getBrokerForClass(), field,
useAutoNaming());
  +        String seqName = calculateSequenceName(field);
           // we have to be threadsafe
           synchronized (sequenceNameKeyMap)
           {
  
  
  
  1.20      +2 -11     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.19
  retrieving revision 1.20
  diff -u -r1.19 -r1.20
  --- SequenceManagerHighLowImpl.java	22 May 2003 22:24:09 -0000	1.19
  +++ SequenceManagerHighLowImpl.java	13 Aug 2003 18:16:10 -0000	1.20
  @@ -178,16 +178,7 @@
           }
           else
           {
  -            seqName = field.getSequenceName();
  -            /*
  -            if we found no sequence name for the given field, we try to
  -            assign a automatic generated sequence name.
  -            */
  -            if (seqName == null || seqName.trim().equals(""))
  -            {
  -                seqName = SequenceManagerHelper.buildSequenceName(getBrokerForClass(),
field, useAutoNaming());
  -                if(useAutoNaming()) field.setSequenceName(seqName);
  -            }
  +            seqName = calculateSequenceName(field);
           }
           synchronized (sequencesMap)
           {
  
  
  
  1.11      +20 -151   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.10
  retrieving revision 1.11
  diff -u -r1.10 -r1.11
  --- AbstractSequenceManager.java	15 Jun 2003 12:00:03 -0000	1.10
  +++ AbstractSequenceManager.java	13 Aug 2003 18:16:10 -0000	1.11
  @@ -6,15 +6,8 @@
   import org.apache.ojb.broker.metadata.FieldDescriptor;
   import org.apache.ojb.broker.metadata.SequenceDescriptor;
   import org.apache.ojb.broker.platforms.Platform;
  -import org.apache.ojb.broker.util.logging.Logger;
  -import org.apache.ojb.broker.util.logging.LoggerFactory;
  +import org.apache.ojb.broker.util.SqlTypeHelper;
   
  -import java.math.BigDecimal;
  -import java.math.BigInteger;
  -import java.sql.Date;
  -import java.sql.Time;
  -import java.sql.Timestamp;
  -import java.sql.Types;
   import java.util.Properties;
   
   
  @@ -30,13 +23,12 @@
    */
   public abstract class AbstractSequenceManager implements SequenceManager
   {
  -    private Logger log = LoggerFactory.getLogger(AbstractSequenceManager.class);
  +    // 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
  @@ -98,11 +90,23 @@
   
       public boolean useAutoNaming()
       {
  -        if (autoNaming == null)
  +        return (new Boolean(getConfigurationProperty(PROPERTY_AUTO_NAMING, "true"))).booleanValue();
  +    }
  +
  +    public String calculateSequenceName(FieldDescriptor field) throws SequenceManagerException
  +    {
  +        String seqName;
  +        seqName = field.getSequenceName();
  +        /*
  +        if we found no sequence name for the given field, we try to
  +        assign a automatic generated sequence name.
  +        */
  +        if(seqName == null)
           {
  -            autoNaming = new Boolean(getConfigurationProperty(PROPERTY_AUTO_NAMING, "true"));
  +            seqName = SequenceManagerHelper.buildSequenceName(getBrokerForClass(), field,
useAutoNaming());
  +            if(useAutoNaming()) field.setSequenceName(seqName);
           }
  -        return autoNaming.booleanValue();
  +        return seqName;
       }
   
   
  @@ -118,147 +122,12 @@
        */
       public Object getUniqueValue(FieldDescriptor field) throws SequenceManagerException
       {
  -        Object result = null;
  -        switch (field.getColumnJdbcType())
  -        {
  -            case Types.ARRAY:
  -                {
  -                    Object[] arr = {getUniqueString(field)};
  -                    result = arr;
  -                    break;
  -                }
  -            case Types.BIGINT:
  -                {
  -                    result = new Long(getUniqueLong(field));
  -                    break;
  -                }
  -            case Types.BINARY:
  -                {
  -                    result = (byte[]) getUniqueString(field).getBytes();
  -                    break;
  -                }
  -            case Types.CHAR:
  -                {
  -                    result = getUniqueString(field);
  -                    break;
  -                }
  -            case Types.DATE:
  -                {
  -                    result = new Date(getUniqueLong(field));
  -                    break;
  -                }
  -            case Types.DECIMAL:
  -                {
  -                    result = new BigDecimal(BigInteger.valueOf(getUniqueLong(field)));
  -                    break;
  -                }
  -            case Types.DOUBLE:
  -                {
  -                    result = new Double(getUniqueLong(field));
  -                    break;
  -                }
  -            case Types.FLOAT:
  -                {
  -                    result = new Double(getUniqueLong(field));
  -                    break;
  -                }
  -            case Types.INTEGER:
  -                {
  -                    result = new Integer(getUniqueId(field));
  -                    break;
  -                }
  -            case Types.JAVA_OBJECT:
  -                {
  -                    result = getUniqueObject(field);
  -                    break;
  -                }
  -            case Types.LONGVARBINARY:
  -                {
  -                    result = (byte[]) getUniqueString(field).getBytes();
  -                    break;
  -                }
  -            case Types.LONGVARCHAR:
  -                {
  -                    result = getUniqueString(field);
  -                    break;
  -                }
  -            case Types.NUMERIC:
  -                {
  -                    result = new BigDecimal(BigInteger.valueOf(getUniqueLong(field)));
  -                    break;
  -                }
  -            case Types.REAL:
  -                {
  -                    result = new Float(getUniqueLong(field));
  -                    break;
  -                }
  -            case Types.SMALLINT:
  -                {
  -                    result = new Short((short) getUniqueId(field));
  -                    break;
  -                }
  -            case Types.TIME:
  -                {
  -                    result = new Time(getUniqueLong(field));
  -                    break;
  -                }
  -            case Types.TIMESTAMP:
  -                {
  -                    result = new Timestamp(getUniqueLong(field));
  -                    break;
  -                }
  -            case Types.TINYINT:
  -                {
  -                    result = new Byte((byte) getUniqueId(field));
  -                    break;
  -                }
  -            case Types.VARBINARY:
  -                {
  -                    result = (byte[]) getUniqueString(field).getBytes();
  -                    break;
  -                }
  -            case Types.VARCHAR:
  -                {
  -                    result = getUniqueString(field);
  -                    break;
  -                }
  -            default:
  -                {
  -                    result = getUniqueString(field);
  -                    break;
  -                }
  -        }
  +        Object result = SqlTypeHelper.sequenceKeyConversion(
  +                field.getColumnJdbcType(), new Long(getUniqueLong(field)));
           // perform a sql to java conversion here, so that clients do
           // not see any db specific values
           result = field.getFieldConversion().sqlToJava(result);
           return result;
  -    }
  -
  -    /**
  -     * returns a unique String for class clazz and field fieldName.
  -     * the returned uid is unique accross all tables in the extent of clazz.
  -     *
  -     */
  -    protected String getUniqueString(FieldDescriptor field) throws SequenceManagerException
  -    {
  -        return Long.toString(getUniqueLong(field));
  -    }
  -
  -    /**
  -     * Returns a new unique int for the given Class and fieldname.
  -     */
  -    protected int getUniqueId(FieldDescriptor field) throws SequenceManagerException
  -    {
  -        return (int) getUniqueLong(field);
  -    }
  -
  -    /**
  -     * returns a unique Object for class clazz and field fieldName.
  -     * the returned Object is unique accross all tables in the extent of clazz.
  -     */
  -    protected Object getUniqueObject(FieldDescriptor field) throws SequenceManagerException
  -    {
  -        return getUniqueString(field);
       }
   
       /**
  
  
  

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