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
Date Mon, 20 Sep 2004 14:33:15 GMT
arminw      2004/09/20 07:33:14

  Modified:    src/java/org/apache/ojb/broker/accesslayer/batch
                        BatchManagerImpl.java
               src/java/org/apache/ojb/broker/accesslayer JdbcAccess.java
                        JdbcAccessImpl.java
               src/java/org/apache/ojb/broker/util BrokerHelper.java
  Log:
  move method from BrokerHelper to JdbcAccess
  
  Revision  Changes    Path
  1.3       +6 -1      db-ojb/src/java/org/apache/ojb/broker/accesslayer/batch/BatchManagerImpl.java
  
  Index: BatchManagerImpl.java
  ===================================================================
  RCS file: /home/cvs/db-ojb/src/java/org/apache/ojb/broker/accesslayer/batch/BatchManagerImpl.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- BatchManagerImpl.java	18 Sep 2004 17:36:32 -0000	1.2
  +++ BatchManagerImpl.java	20 Sep 2004 14:33:14 -0000	1.3
  @@ -483,6 +483,11 @@
           }
       }
   
  +    public boolean doesExist(ClassDescriptor cld, Identity oid)
  +    {
  +        return jdbcAccess.doesExist(cld, oid);
  +    }
  +
       public Object materializeObject(ClassDescriptor cld, Identity oid) throws PersistenceBrokerException
       {
           return jdbcAccess.materializeObject(cld, oid);
  
  
  
  1.36      +7 -1      db-ojb/src/java/org/apache/ojb/broker/accesslayer/JdbcAccess.java
  
  Index: JdbcAccess.java
  ===================================================================
  RCS file: /home/cvs/db-ojb/src/java/org/apache/ojb/broker/accesslayer/JdbcAccess.java,v
  retrieving revision 1.35
  retrieving revision 1.36
  diff -u -r1.35 -r1.36
  --- JdbcAccess.java	14 Sep 2004 16:03:33 -0000	1.35
  +++ JdbcAccess.java	20 Sep 2004 14:33:14 -0000	1.36
  @@ -105,6 +105,12 @@
       public void executeUpdate(ClassDescriptor cld, FieldDescriptor[] fieldsToUpdate, Object
obj) throws PersistenceBrokerException;
   
       /**
  +     * This method only checks if the requested object can be
  +     * found in database (without full object materialization).
  +     */
  +    public boolean doesExist(ClassDescriptor cld, Identity oid);
  +
  +    /**
        * performs a primary key lookup operation against RDBMS and materializes
        * an object from the resulting row. Only skalar attributes are filled from
        * the row, references are not resolved.
  
  
  
  1.24      +49 -1     db-ojb/src/java/org/apache/ojb/broker/accesslayer/JdbcAccessImpl.java
  
  Index: JdbcAccessImpl.java
  ===================================================================
  RCS file: /home/cvs/db-ojb/src/java/org/apache/ojb/broker/accesslayer/JdbcAccessImpl.java,v
  retrieving revision 1.23
  retrieving revision 1.24
  diff -u -r1.23 -r1.24
  --- JdbcAccessImpl.java	14 Sep 2004 16:03:33 -0000	1.23
  +++ JdbcAccessImpl.java	20 Sep 2004 14:33:14 -0000	1.24
  @@ -22,6 +22,7 @@
   import java.util.HashMap;
   import java.util.Iterator;
   import java.util.Map;
  +import java.util.WeakHashMap;
   
   import org.apache.ojb.broker.Identity;
   import org.apache.ojb.broker.KeyConstraintViolatedException;
  @@ -29,6 +30,7 @@
   import org.apache.ojb.broker.PersistenceBroker;
   import org.apache.ojb.broker.PersistenceBrokerException;
   import org.apache.ojb.broker.PersistenceBrokerSQLException;
  +import org.apache.ojb.broker.accesslayer.sql.SqlExistStatement;
   import org.apache.ojb.broker.core.ValueContainer;
   import org.apache.ojb.broker.metadata.ArgumentDescriptor;
   import org.apache.ojb.broker.metadata.ClassDescriptor;
  @@ -61,6 +63,13 @@
       protected PersistenceBroker broker;
   
       /**
  +     * This map contains {@link org.apache.ojb.broker.metadata.ClassDescriptor} as key
and a
  +     * {@link org.apache.ojb.broker.accesslayer.sql.SqlExistStatement} as value.
  +     * Use a WeakHashMap to allow reclaiming of no longer used ClassDescriptor instances.
  +     */
  +    private Map sqlSelectMap = new WeakHashMap();
  +
  +    /**
        * constructor is private, use getInstance to get
        * the singleton instance of this class
        */
  @@ -535,6 +544,45 @@
               broker.serviceStatementManager().closeResources(stmt, null);
           }
       }
  +
  +    /**
  +     * TODO: This method should be moved to {@link org.apache.ojb.broker.accesslayer.JdbcAccess}
  +     * before 1.1 release. This method only checks if the requested object can be
  +     * found in DB (without full object materialization).
  +     */
  +    public boolean doesExist(ClassDescriptor cld, Identity oid)
  +    {
  +        boolean result = false;
  +        String sql = (String) sqlSelectMap.get(cld);
  +        if(sql == null)
  +        {
  +            sql = new SqlExistStatement(cld, logger).getStatement();
  +            sqlSelectMap.put(cld, sql);
  +        }
  +        StatementManagerIF sm = broker.serviceStatementManager();
  +        PreparedStatement stmt = null;
  +        ResultSet rs = null;
  +        try
  +        {
  +            stmt = sm.getPreparedStatement(sql, false);
  +            sm.bindSelect(stmt, oid, cld);
  +            rs = stmt.executeQuery();
  +            result = rs.next();
  +        }
  +        catch(SQLException e)
  +        {
  +            logger.error("Can't check database for object existance", e);
  +            throw new PersistenceBrokerSQLException("Exist check failed for identity "
+ oid
  +                    + ", sql was " + sql, e);
  +        }
  +        finally
  +        {
  +            sm.closeResources(stmt, rs);
  +        }
  +
  +        return result;
  +    }
  +
   
       /**
        * performs a primary key lookup operation against RDBMS and materializes
  
  
  
  1.67      +1 -46     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.66
  retrieving revision 1.67
  diff -u -r1.66 -r1.67
  --- BrokerHelper.java	15 Sep 2004 17:18:45 -0000	1.66
  +++ BrokerHelper.java	20 Sep 2004 14:33:14 -0000	1.67
  @@ -649,51 +649,6 @@
           return m_broker.serviceConnectionManager().getSupportedPlatform();
       }
   
  -
  -    /*
  -    NOTE: use WeakHashMap to allow reclaiming of no longer used ClassDescriptor
  -    instances
  -    */
  -    private Map sqlSelectMap = new WeakHashMap();
  -
  -    /**
  -     * TODO: This method should be moved to {@link org.apache.ojb.broker.accesslayer.JdbcAccess}
  -     * before 1.1 release. This method only checks if the requested object can be
  -     * found in DB (without full object materialization).
  -     */
  -    public boolean doesExist(ClassDescriptor cld, Identity oid, Object obj)
  -    {
  -        boolean result = false;
  -        String sql = (String) sqlSelectMap.get(cld);
  -        if(sql == null)
  -        {
  -            sql = new SqlExistStatement(cld, LoggerFactory.getDefaultLogger()).getStatement();
  -            sqlSelectMap.put(cld, sql);
  -        }
  -        StatementManagerIF sm = m_broker.serviceStatementManager();
  -        PreparedStatement stmt = null;
  -        ResultSet rs = null;
  -        try
  -        {
  -            stmt = sm.getPreparedStatement(sql, false);
  -            sm.bindSelect(stmt, oid, cld);
  -            rs = stmt.executeQuery();
  -            result = rs.next();
  -        }
  -        catch(SQLException e)
  -        {
  -            throw new PersistenceBrokerSQLException("Exist check failed for identity "
+ oid
  -                    + ", sql was " + sql, e);
  -        }
  -        finally
  -        {
  -            sm.closeResources(stmt, rs);
  -        }
  -
  -        return result;
  -    }
  -
  -
       /**
        * This method concatenate the main object with all reference
        * objects (1:1, 1:n and m:n) by hand. This method is needed when
  
  
  

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