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 SequenceManagerMSSQLGuidImpl.java
Date Thu, 12 Feb 2004 16:09:01 GMT
arminw      2004/02/12 08:09:01

  Modified:    src/java/org/apache/ojb/broker/util/sequence
                        SequenceManagerMSSQLGuidImpl.java
  Log:
  make it work again
  
  Revision  Changes    Path
  1.2       +40 -16    db-ojb/src/java/org/apache/ojb/broker/util/sequence/SequenceManagerMSSQLGuidImpl.java
  
  Index: SequenceManagerMSSQLGuidImpl.java
  ===================================================================
  RCS file: /home/cvs/db-ojb/src/java/org/apache/ojb/broker/util/sequence/SequenceManagerMSSQLGuidImpl.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- SequenceManagerMSSQLGuidImpl.java	31 Jul 2003 19:13:20 -0000	1.1
  +++ SequenceManagerMSSQLGuidImpl.java	12 Feb 2004 16:09:01 -0000	1.2
  @@ -57,8 +57,11 @@
   import org.apache.commons.lang.SystemUtils;
   import org.apache.ojb.broker.PersistenceBroker;
   import org.apache.ojb.broker.PersistenceBrokerException;
  +import org.apache.ojb.broker.util.JdbcTypesHelper;
  +import org.apache.ojb.broker.util.logging.LoggerFactory;
   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.query.Query;
   
   import java.sql.SQLException;
  @@ -78,6 +81,7 @@
    */
   public class SequenceManagerMSSQLGuidImpl extends AbstractSequenceManager
   {
  +    private static final JdbcType JDBC_TYPE_VARCHAR = JdbcTypesHelper.getJdbcTypeByName("varchar");
       /**
        * Constructor used by
        * {@link org.apache.ojb.broker.util.sequence.SequenceManagerFactory}
  @@ -90,6 +94,21 @@
           super(broker);
       }
   
  +    public Object getUniqueValue(FieldDescriptor field) throws SequenceManagerException
  +    {
  +        // only works for VARCHAR fields
  +        if(!field.getJdbcType().equals(JDBC_TYPE_VARCHAR))
  +        {
  +            throw new SequenceManagerException("This implementation only works with fields
defined" +
  +                    " as VARCHAR, but given field was " + (field != null ? field.getJdbcType()
: null));
  +        }
  +        Object result = getUniqueString(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 given field.
        * the returned uid is unique accross all tables.
  @@ -97,17 +116,20 @@
       protected String getUniqueString(FieldDescriptor field) throws SequenceManagerException
       {
           ResultSetAndStatement rsStmt = null;
  +        String returnValue = null;
           try
           {
  -            rsStmt = getBrokerForClass().serviceJdbcAccess().executeSQL("select newid()",
field.getClassDescriptor(), Query.NOT_SCROLLABLE);
  -            String returnValue = null;
  +            rsStmt = getBrokerForClass().serviceJdbcAccess().executeSQL(
  +                    "select newid()", field.getClassDescriptor(), Query.NOT_SCROLLABLE);
               if (rsStmt.m_rs.next())
               {
                   returnValue = rsStmt.m_rs.getString(1);
               }
  -            rsStmt.m_rs.close();
  -            return returnValue;
  -
  +            else
  +            {
  +                LoggerFactory.getDefaultLogger().error(this.getClass()
  +                        + ": Can't lookup new oid for field " + field);
  +            }
           }
           catch (PersistenceBrokerException e)
           {
  @@ -120,9 +142,10 @@
   
           finally
           {
  -            if (rsStmt != null)
  -                rsStmt.close();
  +            // close the used resources
  +            if (rsStmt != null) rsStmt.close();
           }
  +        return returnValue;
       }
   
       /**
  @@ -145,13 +168,14 @@
                   "Failure attempting to retrieve a Guid for a field that is a long -- field
should be returned as a VARCHAR");
       }
   
  -    /**
  -     * 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);
  -    }
  +    // TODO: never used? remove?
  +//    /**
  +//     * 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