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 BrokerHelper.java ObjectModificationDefaultImpl.java ClassHelper.java
Date Tue, 14 Sep 2004 16:36:14 GMT
arminw      2004/09/14 09:36:14

  Modified:    src/java/org/apache/ojb/broker MtoNImplementor.java OJB.java
                        PersistenceBroker.java
               src/java/org/apache/ojb/broker/util BrokerHelper.java
                        ObjectModificationDefaultImpl.java ClassHelper.java
  Log:
  - add new batch handling
  - update/refactoring Statement classes
  - add new PB.update(Object obj, String[] fields)
  - change insert order of m:n relations
  - change repository.dtd, add element 'batch', rename element
  'connection-pool' to 'connection-factory', remove implementation
  dependent attributes and add custom-attributes instead
  - remove unused classes
  
  Revision  Changes    Path
  1.8       +7 -2      db-ojb/src/java/org/apache/ojb/broker/MtoNImplementor.java
  
  Index: MtoNImplementor.java
  ===================================================================
  RCS file: /home/cvs/db-ojb/src/java/org/apache/ojb/broker/MtoNImplementor.java,v
  retrieving revision 1.7
  retrieving revision 1.8
  diff -u -r1.7 -r1.8
  --- MtoNImplementor.java	9 Apr 2004 13:22:30 -0000	1.7
  +++ MtoNImplementor.java	14 Sep 2004 16:36:14 -0000	1.8
  @@ -23,6 +23,7 @@
   import org.apache.ojb.broker.core.proxy.ProxyHelper;
   import org.apache.ojb.broker.metadata.ClassDescriptor;
   import org.apache.ojb.broker.metadata.CollectionDescriptor;
  +import org.apache.ojb.broker.accesslayer.sql.SqlGenerator;
   
   /**
    *
  @@ -101,7 +102,11 @@
   			return null;
   		}
   
  -		return _pb.serviceSqlGenerator().getInsertMNStatement(table, leftPkColumns, rightPkColumns);
  +        String[] cols = new String[leftPkColumns.length + rightPkColumns.length];
  +        System.arraycopy(leftPkColumns, 0, cols, 0, leftPkColumns.length);
  +        System.arraycopy(rightPkColumns, 0, cols, leftPkColumns.length, rightPkColumns.length);
  +
  +		return _pb.serviceSqlGenerator().getGenericPreparedStatement(SqlGenerator.TYPE_GENERIC_INSERT,
table, cols, null);
       }
   
   
  
  
  
  1.2       +41 -1     db-ojb/src/java/org/apache/ojb/broker/OJB.java
  
  Index: OJB.java
  ===================================================================
  RCS file: /home/cvs/db-ojb/src/java/org/apache/ojb/broker/OJB.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- OJB.java	11 Aug 2004 00:41:49 -0000	1.1
  +++ OJB.java	14 Sep 2004 16:36:14 -0000	1.2
  @@ -10,6 +10,7 @@
   import org.apache.ojb.broker.metadata.ObjectCacheDescriptor;
   import org.apache.ojb.broker.metadata.PersistenceConfigurationDescriptor;
   import org.apache.ojb.broker.util.BrokerHelper;
  +import org.apache.ojb.broker.util.ObjectModification;
   import org.apache.ojb.broker.util.logging.Logger;
   import org.apache.ojb.broker.util.logging.LoggerFactory;
   
  @@ -39,6 +40,9 @@
   {
       private Logger log = LoggerFactory.getLogger(OJB.class);
   
  +    public static final ObjectModification INSERT = ObjectModificationImpl.INSERT;
  +    public static final ObjectModification UPDATE = ObjectModificationImpl.UPDATE;
  +
       private Factories factories;
       private MetadataManager metadataManager;
       private HashMap configurationMap;
  @@ -229,5 +233,41 @@
       {
           PBKey key = new PBKey(alias, user, passwd);
           return lookupBroker(key);
  +    }
  +
  +    public static final class ObjectModificationImpl implements ObjectModification
  +    {
  +        public static final ObjectModification INSERT = new ObjectModificationImpl(true,
false);
  +        public static final ObjectModification UPDATE = new ObjectModificationImpl(false,
true);
  +
  +        private boolean needsInsert;
  +        private boolean needsUpdate;
  +
  +        /**
  +         * ObjectModificationImpl constructor comment.
  +         */
  +        protected ObjectModificationImpl(boolean pNeedsInsert, boolean pNeedsUpdate)
  +        {
  +            needsInsert = pNeedsInsert;
  +            needsUpdate = pNeedsUpdate;
  +        }
  +
  +        /**
  +         * returns true if the underlying Object needs an INSERT statement.
  +         * else Returns false.
  +         */
  +        public boolean needsInsert()
  +        {
  +            return needsInsert;
  +        }
  +
  +        /**
  +         * returns true if the underlying Object needs an UPDATE statement.
  +         * else Returns false.
  +         */
  +        public boolean needsUpdate()
  +        {
  +            return needsUpdate;
  +        }
       }
   }
  
  
  
  1.33      +11 -1     db-ojb/src/java/org/apache/ojb/broker/PersistenceBroker.java
  
  Index: PersistenceBroker.java
  ===================================================================
  RCS file: /home/cvs/db-ojb/src/java/org/apache/ojb/broker/PersistenceBroker.java,v
  retrieving revision 1.32
  retrieving revision 1.33
  diff -u -r1.32 -r1.33
  --- PersistenceBroker.java	11 Aug 2004 00:41:49 -0000	1.32
  +++ PersistenceBroker.java	14 Sep 2004 16:36:14 -0000	1.33
  @@ -312,6 +312,16 @@
       public void store(Object obj) throws PersistenceBrokerException;
   
       /**
  +     * Method to update specified persistent object fields. Only the specified fields will
  +     * be updated. In current version specified reference fields (1:1, 1:n, m:n) will
  +     * cause an exception.
  +     *
  +     * @param obj The modified persistent object.
  +     * @param fields The names of the modified fields.
  +     */
  +    public void update(Object obj, String[] fields);
  +
  +    /**
        * deletes the objects obj concrete representation in the underlying persistence system.
        * E.G. by DELETE FROM ... WHERE ... in an RDBMS
        */
  
  
  
  1.65      +2 -2      db-ojb/src/java/org/apache/ojb/broker/util/BrokerHelper.java
  
  Index: BrokerHelper.java
  ===================================================================
  RCS file: /home/cvs/db-ojb/src/java/org/apache/ojb/broker/util/BrokerHelper.java,v
  retrieving revision 1.64
  retrieving revision 1.65
  diff -u -r1.64 -r1.65
  --- BrokerHelper.java	18 Aug 2004 19:24:19 -0000	1.64
  +++ BrokerHelper.java	14 Sep 2004 16:36:14 -0000	1.65
  @@ -675,7 +675,7 @@
           ResultSet rs = null;
           try
           {
  -            stmt = sm.getPreparedStatement(cld, sql, false);
  +            stmt = sm.getPreparedStatement(sql, false);
               sm.bindSelect(stmt, oid, cld);
               rs = stmt.executeQuery();
               result = rs.next();
  
  
  
  1.6       +3 -1      db-ojb/src/java/org/apache/ojb/broker/util/ObjectModificationDefaultImpl.java
  
  Index: ObjectModificationDefaultImpl.java
  ===================================================================
  RCS file: /home/cvs/db-ojb/src/java/org/apache/ojb/broker/util/ObjectModificationDefaultImpl.java,v
  retrieving revision 1.5
  retrieving revision 1.6
  diff -u -r1.5 -r1.6
  --- ObjectModificationDefaultImpl.java	4 Apr 2004 23:53:37 -0000	1.5
  +++ ObjectModificationDefaultImpl.java	14 Sep 2004 16:36:14 -0000	1.6
  @@ -19,6 +19,8 @@
   /**
    * Insert the type's description here.
    *
  + * @deprecated Use {@link org.apache.ojb.broker.OJB#INSERT} and {@link org.apache.ojb.broker.OJB#UPDATE}
  + * instead 
    * @author Thomas Mahler
    * @version $Id$
    */
  
  
  
  1.12      +34 -1     db-ojb/src/java/org/apache/ojb/broker/util/ClassHelper.java
  
  Index: ClassHelper.java
  ===================================================================
  RCS file: /home/cvs/db-ojb/src/java/org/apache/ojb/broker/util/ClassHelper.java,v
  retrieving revision 1.11
  retrieving revision 1.12
  diff -u -r1.11 -r1.12
  --- ClassHelper.java	9 Jul 2004 15:37:32 -0000	1.11
  +++ ClassHelper.java	14 Sep 2004 16:36:14 -0000	1.12
  @@ -29,6 +29,7 @@
   import org.apache.ojb.broker.PersistenceBrokerException;
   import org.apache.ojb.broker.metadata.ClassDescriptor;
   import org.apache.ojb.broker.metadata.ClassNotPersistenceCapableException;
  +import org.apache.commons.lang.ClassUtils;
   
   /**
    * Helper class with static methods for java class, method, and field handling.
  @@ -439,5 +440,37 @@
               }
           }
           return result;
  +    }
  +
  +    /**
  +     * Use reflection to find a field with given int value and return
  +     * the name of the field.
  +     */
  +    public static String giveAsString(Class target, int value)
  +    {
  +        String fieldValue = " " + value;
  +        try
  +        {
  +            Field[] fields = target.getDeclaredFields();
  +            for (int i = 0; i < fields.length; i++)
  +            {
  +                try
  +                {
  +                    if (fields[i].getInt(null) == value)
  +                    {
  +                        fieldValue = value + " (="+ ClassUtils.getShortClassName(target)
+"."+fields[i].getName()+")";
  +                        break;
  +                    }
  +                }
  +                catch(Exception ignore)
  +                {
  +                }
  +            }
  +        }
  +        catch (Exception ignore)
  +        {
  +            // ignore
  +        }
  +        return fieldValue;
       }
   }
  
  
  

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