db-ojb-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From arm...@apache.org
Subject cvs commit: jakarta-ojb/src/java/org/apache/ojb/broker/util BrokerHelper.java
Date Thu, 16 Jan 2003 16:19:33 GMT
arminw      2003/01/16 08:19:33

  Modified:    src/java/org/apache/ojb/broker/util BrokerHelper.java
  Log:
  minor workaround for
  better compatibility with
  older versions
  
  Revision  Changes    Path
  1.7       +32 -95    jakarta-ojb/src/java/org/apache/ojb/broker/util/BrokerHelper.java
  
  Index: BrokerHelper.java
  ===================================================================
  RCS file: /home/cvs/jakarta-ojb/src/java/org/apache/ojb/broker/util/BrokerHelper.java,v
  retrieving revision 1.6
  retrieving revision 1.7
  diff -u -r1.6 -r1.7
  --- BrokerHelper.java	12 Jan 2003 14:29:08 -0000	1.6
  +++ BrokerHelper.java	16 Jan 2003 16:19:32 -0000	1.7
  @@ -54,6 +54,7 @@
    * <http://www.apache.org/>.
    */
   
  +import org.apache.commons.lang.SystemUtils;
   import org.apache.ojb.broker.OJBRuntimeException;
   import org.apache.ojb.broker.PBKey;
   import org.apache.ojb.broker.PersistenceBroker;
  @@ -68,6 +69,7 @@
   import org.apache.ojb.broker.singlevm.PersistenceBrokerConfiguration;
   import org.apache.ojb.broker.util.sequence.SequenceManagerException;
   
  +import java.lang.reflect.Field;
   import java.lang.reflect.Proxy;
   import java.util.StringTokenizer;
   
  @@ -93,7 +95,7 @@
        * user name and password and build a new PBKey
        * instance - the token '#' is used to separate
        * the substrings.
  -     * @throws
  +     * @throws PersistenceBrokerException if given name was <code>null</code>
        */
       public static PBKey extractAllTokens(String name)
       {
  @@ -108,19 +110,31 @@
           if (tok.hasMoreTokens())
           {
               user = tok.nextToken();
  -            if(user != null && user.trim().equals(""))
  +            if (user != null && user.trim().equals(""))
               {
                   user = null;
               }
           }
           if (tok.hasMoreTokens())
           {
  -            if(user != null) passwd = tok.nextToken();
  +            if (user != null) passwd = tok.nextToken();
           }
  -        if(user != null && passwd == null)
  +        if (user != null && passwd == null)
           {
               passwd = "";
           }
  +        /*
  +        allow ODMG-api database.open("myAlias") if 'myAlias' was
  +        declared as default-connection
  +        */
  +        if (user == null && passwd == null)
  +        {
  +            PBKey defKey = PersistenceBrokerFactory.getDefaultKey();
  +            if (defKey != null && defKey.getAlias().equals(dbName))
  +            {
  +                return defKey;
  +            }
  +        }
           PBKey key = new PBKey(dbName, user, passwd);
           return key;
       }
  @@ -348,94 +362,17 @@
           return result;
       }
   
  -
  -// Only used by StatementManager
  -//    /**
  -//     * returns an array containing values for all the Objects attribute
  -//     * @throws MetadataException if tehre is an erros accessing obj field values
  -//     */
  -//    public Object[] getAllValues(PersistenceBroker broker, ClassDescriptor cld,Object
obj) throws PersistenceBrokerException
  -//    {
  -//        FieldDescriptor[] allFields = cld.getFieldDescriptions();
  -//        Object[] result = new Object[allFields.length];
  -//
  -//        for (int i = 0; i < allFields.length; i++)
  -//        {
  -//            FieldDescriptor fmd = allFields[i];
  -//            PersistentField f = fmd.getPersistentField();
  -//            Object cv = f.get(obj);
  -//
  -//            // handle autoincrement attributes if not filled
  -//            if (fmd.isAutoIncrement())
  -//            {
  -//                cv = getAutoIncrementValue(broker, fmd, obj, cv);
  -//            }
  -//
  -//            // apply type and value mapping
  -//            cv = fmd.getFieldConversion().javaToSql(cv);
  -//            result[i] = cv;
  -//        }
  -//        return result;
  -//    }
  -
  -
  -//    /**
  -//     * returns an Array with an Objects PK VALUES
  -//     * if convertToSql is true, any associated java-to-sql conversions are applied
  -//     * @throws MetadataException if there is an erros accessing o field values
  -//     */
  -//    protected static Object[] getKeyValuesForObject(PersistenceBroker broker, ClassDescriptor
cld, Object o, boolean convertToSql) throws PersistenceBrokerException
  -//    {
  -//        FieldDescriptor[] pkFields = cld.getPkFields();
  -//        Object[] result = new Object[pkFields.length];
  -//
  -//        for (int i = 0; i < result.length; i++)
  -//        {
  -//            FieldDescriptor fmd = pkFields[i];
  -//            PersistentField f = fmd.getPersistentField();
  -//            Object cv = f.get(o);
  -//
  -//            // handle autoincrement attributes if not filled
  -//            if (fmd.isAutoIncrement())
  -//            {
  -//                cv = getAutoIncrementValue(broker, fmd, o, cv);
  -//            }
  -//
  -//            if (convertToSql)
  -//            {
  -//                // BRJ : apply type and value mapping
  -//                cv = fmd.getFieldConversion().javaToSql(cv);
  -//            }
  -//            result[i] = cv;
  -//        }
  -//        return result;
  -//    }
  -//
  -//    /**
  -//     * returns an Array with the Proxy's PK VALUES
  -//     * @param aProxy
  -//     * @return Object[]
  -//     * @throws PersistenceBrokerException
  -//     */
  -//    protected static Object[] getKeyValuesForProxy(Proxy aProxy) throws PersistenceBrokerException
  -//    {
  -//        IndirectionHandler handler;
  -//
  -//        handler = (IndirectionHandler) Proxy.getInvocationHandler(aProxy);
  -//        return handler.getIdentity().getPrimaryKeyValues();
  -//    }
  -//
  -//    /**
  -//     * returns an Array with the VirtualProxy's PK VALUES
  -//     * @param aProxy
  -//     * @return Object[]
  -//     * @throws PersistenceBrokerException
  -//     */
  -//    protected static Object[] getKeyValuesForProxy(VirtualProxy aProxy) throws PersistenceBrokerException
  -//    {
  -//        IndirectionHandler handler;
  -//
  -//        handler = (IndirectionHandler) VirtualProxy.getIndirectionHandler(aProxy);
  -//        return handler.getIdentity().getPrimaryKeyValues();
  -//    }
  +    public static String buildMessageString(Object obj, Object value, Field field)
  +    {
  +        String eol = SystemUtils.LINE_SEPARATOR;
  +        StringBuffer buf = new StringBuffer();
  +        buf.
  +                append(eol + "object class[ " + (obj != null ? obj.getClass().getName()
: null)).
  +                append(eol + "target field: " + field.getName()).
  +                append(eol + "target field type: " + (field != null ? field.getType() :
null)).
  +                append(eol + "object value class: " + (value != null ? value.getClass().getName()
: null)).
  +                append(eol + "object value: " + (value != null ? value : null)).
  +                append("]");
  +        return buf.toString();
  +    }
   }
  
  
  

Mime
View raw message