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/core MtoNBroker.java
Date Mon, 03 Oct 2005 17:35:25 GMT
arminw      2005/10/03 10:35:25

  Modified:    src/java/org/apache/ojb/broker/accesslayer/sql
                        SqlGenerator.java SqlGeneratorDefaultImpl.java
                        SqlProcedureFKStatement.java
                        SqlProcedureStatement.java SqlSelectStatement.java
                        SqlStatement.java
               src/java/org/apache/ojb/broker/accesslayer
                        JdbcAccessImpl.java ResultSetAndStatement.java
                        RowReaderDefaultImpl.java SqlBasedRsIterator.java
               src/java/org/apache/ojb/broker/core MtoNBroker.java
  Added:       src/java/org/apache/ojb/broker/accesslayer/sql
                        SelectStatement.java
  Removed:     src/java/org/apache/ojb/broker/accesslayer/sql
                        SelectStatementWrapper.java
  Log:
  use SqlStatement as return value in all SqlGenerator methods, remove SelectStatementWrapper
class
  
  Revision  Changes    Path
  1.16      +23 -14    db-ojb/src/java/org/apache/ojb/broker/accesslayer/sql/SqlGenerator.java
  
  Index: SqlGenerator.java
  ===================================================================
  RCS file: /home/cvs/db-ojb/src/java/org/apache/ojb/broker/accesslayer/sql/SqlGenerator.java,v
  retrieving revision 1.15
  retrieving revision 1.16
  diff -u -r1.15 -r1.16
  --- SqlGenerator.java	1 Oct 2005 13:56:13 -0000	1.15
  +++ SqlGenerator.java	3 Oct 2005 17:35:24 -0000	1.16
  @@ -40,70 +40,77 @@
        * @param table Name of the target table.
        * @param affectedColumns The columns to insert/update or the columns to select or
<em>null</em> for delete statements.
        * @param whereClauseColumns The columns to include in a where-clause for update/delete
or select statement.
  -     * @return String representation of the specified prepared statement.
  +     * @return Representation class of the sql statement.
        *
        * @see #TYPE_GENERIC_DELETE
        * @see #TYPE_GENERIC_INSERT
        * @see #TYPE_GENERIC_SELECT
        * @see #TYPE_GENERIC_UPDATE
        */
  -    public String getGenericPreparedStatement(int type, String table, String[] affectedColumns,
String[] whereClauseColumns);
  +    public SqlStatement getGenericPreparedStatement(int type, String table, String[] affectedColumns,
String[] whereClauseColumns);
   
       /**
        * generate a select-Statement according to query
        *
        * @param query The query to perform.
        * @param cld The {@link org.apache.ojb.broker.metadata.ClassDescriptor} of the target
class or object.
  +     * @return Representation class of the sql statement.
        */
  -    public SelectStatementWrapper getPreparedSelectStatement(Query query, ClassDescriptor
cld);
  +    public SelectStatement getPreparedSelectStatement(Query query, ClassDescriptor cld);
   
       /**
        * Generate a select-Statement according to query
        *
        * @param query The query to perform.
        * @param cld The {@link org.apache.ojb.broker.metadata.ClassDescriptor} of the target
class or object.
  +     * @return Representation class of the sql statement.
        */
  -    public String getSelectStatementDep(Query query, ClassDescriptor cld);
  +    public SelectStatement getSelectStatementDep(Query query, ClassDescriptor cld);
   
       /**
        * Generate a select pk-columns only statement according to query.
        *
        * @param query The query to perform.
        * @param cld the ClassDescriptor
  +     * @return Representation class of the sql statement.
        */
  -    public SelectStatementWrapper getPreparedSelectPkStatement(Query query, ClassDescriptor
cld);
  +    public SelectStatement getPreparedSelectPkStatement(Query query, ClassDescriptor cld);
   
       /**
        * Generate a prepared DELETE-Statement according to query
        *
        * @param query The query to perform.
        * @param cld The {@link org.apache.ojb.broker.metadata.ClassDescriptor} of the target
class or object.
  +     * @return Representation class of the sql statement.
        */
  -    public String getPreparedDeleteStatement(Query query, ClassDescriptor cld);
  +    public SqlStatement getPreparedDeleteStatement(Query query, ClassDescriptor cld);
   
       /**
        * Generate a prepared DELETE-Statement for the Class
        * described by the {@link org.apache.ojb.broker.metadata.ClassDescriptor}.
        *
        * @param cld The {@link org.apache.ojb.broker.metadata.ClassDescriptor} of the target
class or object.
  +     * @return Representation class of the sql statement.
        */
  -    public String getPreparedDeleteStatement(ClassDescriptor cld);
  +    public SqlStatement getPreparedDeleteStatement(ClassDescriptor cld);
   
       /**
        * Generate a prepared INSERT-Statement for the Class
        * described by the {@link org.apache.ojb.broker.metadata.ClassDescriptor}.
        *
        * @param cld The {@link org.apache.ojb.broker.metadata.ClassDescriptor} of the target
class or object.
  +     * @return Representation class of the sql statement.
        */
  -    public String getPreparedInsertStatement(ClassDescriptor cld);
  +    public SqlStatement getPreparedInsertStatement(ClassDescriptor cld);
   
       /**
        * Generate a prepared SELECT-Statement for the Class
        * described by the {@link org.apache.ojb.broker.metadata.ClassDescriptor}.
        *
        * @param cld The {@link org.apache.ojb.broker.metadata.ClassDescriptor} of the target
class or object.
  +     * @return Representation class of the sql statement.
        */
  -    public SelectStatementWrapper getPreparedSelectByPkStatement(ClassDescriptor cld);
  +    public SelectStatement getPreparedSelectByPkStatement(ClassDescriptor cld);
   
       /**
        * Generate a select-statement to check existence of an
  @@ -113,17 +120,18 @@
        * {@link #getPreparedSelectByPkStatement(org.apache.ojb.broker.metadata.ClassDescriptor)}.
        *
        * @param cld The {@link org.apache.ojb.broker.metadata.ClassDescriptor} of the target
class or object.
  -     * @return The sql string.
  +     * @return Representation class of the sql statement.
        */
  -    public String getPreparedExistsStatement(ClassDescriptor cld);
  +    public SqlStatement getPreparedExistsStatement(ClassDescriptor cld);
   
       /**
        * Generate a prepared UPDATE-Statement for the Class
        * described by the {@link org.apache.ojb.broker.metadata.ClassDescriptor}.
        *
        * @param cld The {@link org.apache.ojb.broker.metadata.ClassDescriptor} of the target
class or object.
  +     * @return Representation class of the sql statement.
        */
  -    public String getPreparedUpdateStatement(ClassDescriptor cld);
  +    public SqlStatement getPreparedUpdateStatement(ClassDescriptor cld);
   
       /**
        * Generate a prepared UPDATE-Statement for the Class
  @@ -132,6 +140,7 @@
        * @param cld The {@link org.apache.ojb.broker.metadata.ClassDescriptor} of the target
class or object.
        * @param fields Array of {@link org.apache.ojb.broker.metadata.FieldDescriptor} to
update.
        * <strong>Note:</strong> Only non-primary-key, read-write fields are allowed.
  +     * @return Representation class of the sql statement.
        */
  -    public String getPreparedUpdateStatement(ClassDescriptor cld, FieldDescriptor[] fields);
  +    public SqlStatement getPreparedUpdateStatement(ClassDescriptor cld, FieldDescriptor[]
fields);
   }
  
  
  
  1.35      +81 -98    db-ojb/src/java/org/apache/ojb/broker/accesslayer/sql/SqlGeneratorDefaultImpl.java
  
  Index: SqlGeneratorDefaultImpl.java
  ===================================================================
  RCS file: /home/cvs/db-ojb/src/java/org/apache/ojb/broker/accesslayer/sql/SqlGeneratorDefaultImpl.java,v
  retrieving revision 1.34
  retrieving revision 1.35
  diff -u -r1.34 -r1.35
  --- SqlGeneratorDefaultImpl.java	1 Oct 2005 13:56:13 -0000	1.34
  +++ SqlGeneratorDefaultImpl.java	3 Oct 2005 17:35:24 -0000	1.35
  @@ -57,9 +57,9 @@
       }
   
       /** @see SqlGenerator#getGenericPreparedStatement(int, String, String[], String[])
*/
  -    public String getGenericPreparedStatement(int type, String table, String[] affectedColumns,
String[] whereClauseColumns)
  +    public SqlStatement getGenericPreparedStatement(int type, String table, String[] affectedColumns,
String[] whereClauseColumns)
       {
  -        String result = null;
  +        SqlStatement result = null;
           switch(type)
           {
               case SqlGenerator.TYPE_GENERIC_DELETE:
  @@ -78,48 +78,43 @@
           return result;
       }
   
  -    private String buildGenericDelete(String table, String[] whereClauseColumns)
  +    private SqlStatement buildGenericDelete(String table, String[] whereClauseColumns)
       {
  -        String result = (new SqlGenericDeleteStatement(m_platform, m_logger, table, whereClauseColumns)).getStatement();
  +        SqlStatement result = (new SqlGenericDeleteStatement(m_platform, m_logger, table,
whereClauseColumns));
   
           if(m_logger.isDebugEnabled())
           {
  -            m_logger.debug("SQL:" + result);
  +            m_logger.debug("SQL:" + result.getStatement());
           }
           return result;
       }
   
  -    private String buildGenericInsert(String table, String[] affectedColumns)
  +    private SqlStatement buildGenericInsert(String table, String[] affectedColumns)
       {
           SqlStatement sql = new SqlGenericInsertStatement(m_platform, m_logger, table, affectedColumns);
  -        String result = sql.getStatement();
  -
           if(m_logger.isDebugEnabled())
           {
  -            m_logger.debug("SQL:" + result);
  +            m_logger.debug("SQL:" + sql.getStatement());
           }
  -        return result;
  +        return sql;
       }
   
  -    private String buildGenericSelect(String table, String[] affectedColumns, String[]
whereClauseColumns)
  +    private SqlStatement buildGenericSelect(String table, String[] affectedColumns, String[]
whereClauseColumns)
       {
           SqlStatement sql = new SqlGenericSelectStatement(m_platform, m_logger, table, affectedColumns,
whereClauseColumns);
  -        String result = sql.getStatement();
  -
           if(m_logger.isDebugEnabled())
           {
  -            m_logger.debug("SQL: " + result);
  +            m_logger.debug("SQL: " + sql.getStatement());
           }
  -        return result;
  +        return sql;
       }
   
  -    private String buildGenericUpdate(String table, String[] affectedColumns, String[]
whereClauseColumns)
  +    private SqlStatement buildGenericUpdate(String table, String[] affectedColumns, String[]
whereClauseColumns)
       {
  -        String result = (new SqlGenericUpdateStatement(m_platform, m_logger, table, affectedColumns,
whereClauseColumns)).getStatement();
  -
  +        SqlStatement result = (new SqlGenericUpdateStatement(m_platform, m_logger, table,
affectedColumns, whereClauseColumns));
           if(m_logger.isDebugEnabled())
           {
  -            m_logger.debug("SQL:" + result);
  +            m_logger.debug("SQL:" + result.getStatement());
           }
           return result;
       }
  @@ -130,14 +125,14 @@
        *
        * @param cld the ClassDescriptor
        */
  -    public String getPreparedDeleteStatement(ClassDescriptor cld)
  +    public SqlStatement getPreparedDeleteStatement(ClassDescriptor cld)
       {
  -        String result;
  +        SqlStatement sql;
           SqlForClass sfc = getSqlForClass(cld);
  -        result = sfc.getDeleteSql();
  -        if(result == null)
  +        sql = sfc.getDeleteSql();
  +        if(sql == null)
           {
  -            SqlStatement sql;
  +
               ProcedureDescriptor pd = cld.getDeleteProcedure();
   
               if(pd == null)
  @@ -148,16 +143,15 @@
               {
                   sql = new SqlProcedureStatement(pd, m_logger);
               }
  -            result = sql.getStatement();
               // set the sql string
  -            sfc.setDeleteSql(result);
  +            sfc.setDeleteSql(sql);
   
               if(m_logger.isDebugEnabled())
               {
  -                m_logger.debug("SQL:" + result);
  +                m_logger.debug("SQL:" + sql.getStatement());
               }
           }
  -        return result;
  +        return sql;
       }
   
       /**
  @@ -166,14 +160,13 @@
        *
        * @param cld the ClassDescriptor
        */
  -    public String getPreparedInsertStatement(ClassDescriptor cld)
  +    public SqlStatement getPreparedInsertStatement(ClassDescriptor cld)
       {
  -        String result;
  +        SqlStatement sql;
           SqlForClass sfc = getSqlForClass(cld);
  -        result = sfc.getInsertSql();
  -        if(result == null)
  +        sql = sfc.getInsertSql();
  +        if(sql == null)
           {
  -            SqlStatement sql;
               ProcedureDescriptor pd = cld.getInsertProcedure();
   
               if(pd == null)
  @@ -184,16 +177,15 @@
               {
                   sql = new SqlProcedureStatement(pd, m_logger);
               }
  -            result = sql.getStatement();
               // set the sql string
  -            sfc.setInsertSql(result);
  +            sfc.setInsertSql(sql);
   
               if(m_logger.isDebugEnabled())
               {
  -                m_logger.debug("SQL:" + result);
  +                m_logger.debug("SQL:" + sql.getStatement());
               }
           }
  -        return result;
  +        return sql;
       }
   
       /**
  @@ -201,52 +193,51 @@
        *
        * @param cld the ClassDescriptor
        */
  -    public SelectStatementWrapper getPreparedSelectByPkStatement(ClassDescriptor cld)
  +    public SelectStatement getPreparedSelectByPkStatement(ClassDescriptor cld)
       {
  +        SelectStatement sql;
           SqlForClass sfc = getSqlForClass(cld);
  -        SqlStatement result = sfc.getSelectByPKSql();
  -        if(result == null)
  +        sql = sfc.getSelectByPKSql();
  +        if(sql == null)
           {
               ProcedureDescriptor pd = cld.getSelectByPKProcedure();
  -
               if(pd == null)
               {
  -                result = new SqlSelectByPkStatement(m_platform, m_logger, cld);
  +                sql = new SqlSelectByPkStatement(m_platform, m_logger, cld);
               }
               else
               {
  -                result = new SqlProcedureStatement(pd, m_logger);
  +                sql = new SqlProcedureStatement(pd, m_logger);
               }
   
               // set the sql string
  -            sfc.setSelectByPKSql(result);
  +            sfc.setSelectByPKSql(sql);
   
               if(m_logger.isDebugEnabled())
               {
  -                m_logger.debug("SQL:" + result);
  +                m_logger.debug("SQL:" + sql.getStatement());
               }
           }
  -        return new SelectStatementWrapper(null, result);
  +        return sql;
       }
   
  -    public String getPreparedExistsStatement(ClassDescriptor cld)
  +    public SqlStatement getPreparedExistsStatement(ClassDescriptor cld)
       {
  -        String result;
  +        SqlStatement sql;
           SqlForClass sfc = getSqlForClass(cld);
  -        result = sfc.getSelectExists();
  -        if(result == null)
  +        sql = sfc.getSelectExists();
  +        if(sql == null)
           {
               // TODO: Should we support a procedure call for this too??
  -            SqlStatement sql = new SqlExistStatement(m_platform, m_logger, cld);
  -            result = sql.getStatement();
  +            sql = new SqlExistStatement(m_platform, m_logger, cld);
               // set the sql string
  -            sfc.setSelectExists(result);
  +            sfc.setSelectExists(sql);
               if(m_logger.isDebugEnabled())
               {
  -                m_logger.debug("SQL:" + result);
  +                m_logger.debug("SQL:" + sql.getStatement());
               }
           }
  -        return result;
  +        return sql;
       }
   
       /**
  @@ -255,10 +246,10 @@
        * @param query the Query
        * @param cld the ClassDescriptor
        */
  -    public SelectStatementWrapper getPreparedSelectStatement(Query query, ClassDescriptor
cld)
  +    public SelectStatement getPreparedSelectStatement(Query query, ClassDescriptor cld)
       {
           ProcedureDescriptor pd = cld.getSelectByFKProcedure();
  -        SqlStatement sql;
  +        SelectStatement sql;
   
           if((query instanceof QueryByExample) && (pd != null))
           {
  @@ -271,7 +262,7 @@
               sql = new SqlSelectStatement(m_platform, m_logger, cld, query);
           }
   
  -        return new SelectStatementWrapper(query, sql);
  +        return sql;
       }
   
       /**
  @@ -280,12 +271,9 @@
        * @param query the Query
        * @param cld the ClassDescriptor
        */
  -    public SelectStatementWrapper getPreparedSelectPkStatement(Query query, ClassDescriptor
cld)
  +    public SelectStatement getPreparedSelectPkStatement(Query query, ClassDescriptor cld)
       {
  -        SqlStatement sql;
  -        sql = new SqlSelectPkStatement(m_platform, m_logger, cld, query);
  -
  -        return new SelectStatementWrapper(query, sql);
  +        return new SqlSelectPkStatement(m_platform, m_logger, cld, query);
       }
   
       /**
  @@ -294,9 +282,9 @@
        * @param query the Query
        * @param cld the ClassDescriptor
        */
  -    public String getPreparedDeleteStatement(Query query, ClassDescriptor cld)
  +    public SqlStatement getPreparedDeleteStatement(Query query, ClassDescriptor cld)
       {
  -        return new SqlDeleteByQuery(m_platform, m_logger, cld, query).getStatement();
  +        return new SqlDeleteByQuery(m_platform, m_logger, cld, query);
       }
   
       /**
  @@ -305,39 +293,36 @@
        *
        * @param cld the ClassDescriptor
        */
  -    public String getPreparedUpdateStatement(ClassDescriptor cld)
  +    public SqlStatement getPreparedUpdateStatement(ClassDescriptor cld)
       {
  -        String result;
           SqlForClass sfc = getSqlForClass(cld);
  -        result = sfc.getUpdateSql();
  +        SqlStatement result = sfc.getUpdateSql();
           if(result == null)
           {
  -            SqlStatement sql;
               ProcedureDescriptor pd = cld.getUpdateProcedure();
   
               if(pd == null)
               {
  -                sql = new SqlUpdateStatement(m_platform, m_logger, cld);
  +                result = new SqlUpdateStatement(m_platform, m_logger, cld);
               }
               else
               {
  -                sql = new SqlProcedureStatement(pd, m_logger);
  +                result = new SqlProcedureStatement(pd, m_logger);
               }
  -            result = sql.getStatement();
               // set the sql string
               sfc.setUpdateSql(result);
   
               if(m_logger.isDebugEnabled())
               {
  -                m_logger.debug("SQL:" + result);
  +                m_logger.debug("SQL:" + result.getStatement());
               }
           }
           return result;
       }
   
  -    public String getPreparedUpdateStatement(ClassDescriptor cld, FieldDescriptor[] fields)
  +    public SqlStatement getPreparedUpdateStatement(ClassDescriptor cld, FieldDescriptor[]
fields)
       {
  -        String result;
  +        SqlStatement result;
           // TODO: Check this! Should we check if all fields non-PK fields or should we assume
           // that only non-PK fields will be specified?
           if(fields.length == cld.getNonPkRwFields().length)
  @@ -346,21 +331,19 @@
           }
           else
           {
  -            SqlStatement sql;
               ProcedureDescriptor pd = cld.getUpdateProcedure();
               if(pd == null)
               {
  -                sql = new SqlUpdateFieldsStatement(m_platform, m_logger, cld, fields);
  +                result = new SqlUpdateFieldsStatement(m_platform, m_logger, cld, fields);
               }
               else
               {
                   // when procedures are used we can't use changed fields information
                   // TODO: Is it possible to use stored procedures handling with different
numbers of fields??
  -                sql = new SqlProcedureStatement(pd, m_logger);
  +                result = new SqlProcedureStatement(pd, m_logger);
               }
  -            result = sql.getStatement();
           }
  -        if(m_logger.isDebugEnabled()) m_logger.debug("SQL:" + result);
  +        if(m_logger.isDebugEnabled()) m_logger.debug("SQL:" + result.getStatement());
           return result;
       }
   
  @@ -370,9 +353,9 @@
        * @param query the Query
        * @param cld the ClassDescriptor
        */
  -    public String getSelectStatementDep(Query query, ClassDescriptor cld)
  +    public SelectStatement getSelectStatementDep(Query query, ClassDescriptor cld)
       {
  -        return new SqlSelectStatement(m_platform, m_logger, cld, query).getStatement();
  +        return new SqlSelectStatement(m_platform, m_logger, cld, query);
       }
   
       /**
  @@ -608,58 +591,58 @@
        */
       public static class SqlForClass
       {
  -        private String deleteSql;
  -        private String insertSql;
  -        private String updateSql;
  -        private SqlStatement selectByPKSql;
  -        private String selectExists;
  +        private SqlStatement deleteSql;
  +        private SqlStatement insertSql;
  +        private SqlStatement updateSql;
  +        private SelectStatement selectByPKSql;
  +        private SqlStatement selectExists;
   
  -        public String getDeleteSql()
  +        public SqlStatement getDeleteSql()
           {
               return deleteSql;
           }
   
  -        public void setDeleteSql(String deleteSql)
  +        public void setDeleteSql(SqlStatement deleteSql)
           {
               this.deleteSql = deleteSql;
           }
   
  -        public String getInsertSql()
  +        public SqlStatement getInsertSql()
           {
               return insertSql;
           }
   
  -        public void setInsertSql(String insertSql)
  +        public void setInsertSql(SqlStatement insertSql)
           {
               this.insertSql = insertSql;
           }
   
  -        public String getUpdateSql()
  +        public SqlStatement getUpdateSql()
           {
               return updateSql;
           }
   
  -        public void setUpdateSql(String updateSql)
  +        public void setUpdateSql(SqlStatement updateSql)
           {
               this.updateSql = updateSql;
           }
   
  -        public SqlStatement getSelectByPKSql()
  +        public SelectStatement getSelectByPKSql()
           {
               return selectByPKSql;
           }
   
  -        public void setSelectByPKSql(SqlStatement selectByPKSql)
  +        public void setSelectByPKSql(SelectStatement selectByPKSql)
           {
               this.selectByPKSql = selectByPKSql;
           }
   
  -        public String getSelectExists()
  +        public SqlStatement getSelectExists()
           {
               return selectExists;
           }
   
  -        public void setSelectExists(String selectExists)
  +        public void setSelectExists(SqlStatement selectExists)
           {
               this.selectExists = selectExists;
           }
  
  
  
  1.2       +15 -2     db-ojb/src/java/org/apache/ojb/broker/accesslayer/sql/SqlProcedureFKStatement.java
  
  Index: SqlProcedureFKStatement.java
  ===================================================================
  RCS file: /home/cvs/db-ojb/src/java/org/apache/ojb/broker/accesslayer/sql/SqlProcedureFKStatement.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- SqlProcedureFKStatement.java	24 Apr 2005 16:29:10 -0000	1.1
  +++ SqlProcedureFKStatement.java	3 Oct 2005 17:35:24 -0000	1.2
  @@ -21,7 +21,10 @@
   import java.util.Iterator;
   
   import org.apache.ojb.broker.metadata.ArgumentDescriptor;
  +import org.apache.ojb.broker.metadata.FieldDescriptor;
  +import org.apache.ojb.broker.metadata.JdbcType;
   import org.apache.ojb.broker.metadata.ProcedureDescriptor;
  +import org.apache.ojb.broker.query.Query;
   import org.apache.ojb.broker.query.QueryByExample;
   import org.apache.ojb.broker.query.SelectionCriteria;
   import org.apache.ojb.broker.util.logging.Logger;
  @@ -35,7 +38,7 @@
    * @author <a href="mailto:vgritsenko@apache.org">Vadim Gritsenko</a>
    * @version $Id$
    */
  -public class SqlProcedureFKStatement implements SqlStatement
  +public class SqlProcedureFKStatement implements SelectStatement
   {
   
       /**
  @@ -116,4 +119,14 @@
           sb.append(") }");
           return sb.toString();
       }
  +
  +    public Query getQueryInstance()
  +    {
  +        return query;
  +    }
  +
  +    public int getColumnIndex(FieldDescriptor fld)
  +    {
  +        return JdbcType.MIN_INT;
  +    }
   }
  
  
  
  1.6       +15 -2     db-ojb/src/java/org/apache/ojb/broker/accesslayer/sql/SqlProcedureStatement.java
  
  Index: SqlProcedureStatement.java
  ===================================================================
  RCS file: /home/cvs/db-ojb/src/java/org/apache/ojb/broker/accesslayer/sql/SqlProcedureStatement.java,v
  retrieving revision 1.5
  retrieving revision 1.6
  diff -u -r1.5 -r1.6
  --- SqlProcedureStatement.java	4 Apr 2004 23:53:32 -0000	1.5
  +++ SqlProcedureStatement.java	3 Oct 2005 17:35:24 -0000	1.6
  @@ -16,7 +16,10 @@
    */
   
   import org.apache.ojb.broker.metadata.ProcedureDescriptor;
  +import org.apache.ojb.broker.metadata.FieldDescriptor;
  +import org.apache.ojb.broker.metadata.JdbcType;
   import org.apache.ojb.broker.util.logging.Logger;
  +import org.apache.ojb.broker.query.Query;
   
   /**
    * Model a call to a stored procedure based on ProcedureDescriptors
  @@ -27,7 +30,7 @@
    * @version $Id$
    */
   
  -public class SqlProcedureStatement implements SqlStatement
  +public class SqlProcedureStatement implements SelectStatement
   {
   
       /**
  @@ -88,4 +91,14 @@
           sb.append(") }");
           return sb.toString();
       }
  +
  +    public Query getQueryInstance()
  +    {
  +        return null;
  +    }
  +
  +    public int getColumnIndex(FieldDescriptor fld)
  +    {
  +        return JdbcType.MIN_INT;
  +    }
   }
  
  
  
  1.44      +25 -2     db-ojb/src/java/org/apache/ojb/broker/accesslayer/sql/SqlSelectStatement.java
  
  Index: SqlSelectStatement.java
  ===================================================================
  RCS file: /home/cvs/db-ojb/src/java/org/apache/ojb/broker/accesslayer/sql/SqlSelectStatement.java,v
  retrieving revision 1.43
  retrieving revision 1.44
  diff -u -r1.43 -r1.44
  --- SqlSelectStatement.java	29 Sep 2005 23:32:16 -0000	1.43
  +++ SqlSelectStatement.java	3 Oct 2005 17:35:24 -0000	1.44
  @@ -26,6 +26,7 @@
   import org.apache.ojb.broker.metadata.ClassDescriptor;
   import org.apache.ojb.broker.metadata.DescriptorRepository;
   import org.apache.ojb.broker.metadata.FieldDescriptor;
  +import org.apache.ojb.broker.metadata.JdbcType;
   import org.apache.ojb.broker.platforms.Platform;
   import org.apache.ojb.broker.query.Criteria;
   import org.apache.ojb.broker.query.Query;
  @@ -40,7 +41,7 @@
    * @author <a href="mailto:jbraeuchi@hotmail.com">Jakob Braeuchi</a>
    * @version $Id$
    */
  -public class SqlSelectStatement extends SqlQueryStatement
  +public class SqlSelectStatement extends SqlQueryStatement implements SelectStatement
   {
       private FieldDescriptor[] fieldsForSelect;
   
  @@ -440,4 +441,26 @@
               appendColumn(cldSuper.getFullTableName(), field.getColumnName(), buf);
           }
       }
  +
  +    public Query getQueryInstance()
  +    {
  +        return getQuery();
  +    }
  +
  +    public int getColumnIndex(FieldDescriptor fld)
  +    {
  +        int index = JdbcType.MIN_INT;
  +        if (fieldsForSelect != null)
  +        {
  +            for (int i = 0; i < fieldsForSelect.length; i++)
  +            {
  +                if (fieldsForSelect[i].equals(fld))
  +                {
  +                    index = i + 1;  // starts at 1
  +                    break;
  +                }
  +            }
  +        }
  +        return index;
  +    }
   }
  
  
  
  1.7       +1 -3      db-ojb/src/java/org/apache/ojb/broker/accesslayer/sql/SqlStatement.java
  
  Index: SqlStatement.java
  ===================================================================
  RCS file: /home/cvs/db-ojb/src/java/org/apache/ojb/broker/accesslayer/sql/SqlStatement.java,v
  retrieving revision 1.6
  retrieving revision 1.7
  diff -u -r1.6 -r1.7
  --- SqlStatement.java	4 Apr 2004 23:53:32 -0000	1.6
  +++ SqlStatement.java	3 Oct 2005 17:35:24 -0000	1.7
  @@ -25,10 +25,8 @@
    */
   public interface SqlStatement
   {
  - 
       /**
        * Answer the SELECT by primary key Sql for the Statement
        */
       public String getStatement();
  -    
   }
  
  
  
  1.1                  db-ojb/src/java/org/apache/ojb/broker/accesslayer/sql/SelectStatement.java
  
  Index: SelectStatement.java
  ===================================================================
  package org.apache.ojb.broker.accesslayer.sql;
  
  /* Copyright 2002-2004 The Apache Software Foundation
   *
   * Licensed under the Apache License, Version 2.0 (the "License");
   * you may not use this file except in compliance with the License.
   * You may obtain a copy of the License at
   *
   *     http://www.apache.org/licenses/LICENSE-2.0
   *
   * Unless required by applicable law or agreed to in writing, software
   * distributed under the License is distributed on an "AS IS" BASIS,
   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   * See the License for the specific language governing permissions and
   * limitations under the License.
   */
  
  import java.lang.Object;
  import java.sql.ResultSet;
  
  import org.apache.ojb.broker.query.Query;
  import org.apache.ojb.broker.metadata.FieldDescriptor;
  
  /**
   * This class
   *
   * @author <a href="mailto:arminw@apache.org">Armin Waibel</a>
   * @version $Id: SelectStatement.java,v 1.1 2005/10/03 17:35:24 arminw Exp $
   */
  public interface SelectStatement extends SqlStatement
  {   
      /**
       * Returns the {@link org.apache.ojb.broker.query.Query} instance
       * this statement based on.
       * @return The {@link org.apache.ojb.broker.query.Query} instance or <em>null</em>
       * if no query is used to generate the select string.
       */
      public Query getQueryInstance();
  
      /**
       * Returns the column index of the specified {@link org.apache.ojb.broker.metadata.FieldDescriptor}
       * in the {@link java.sql.ResultSet} after performing the query.
       *
       * @param fld The {@link org.apache.ojb.broker.metadata.FieldDescriptor}.
       * @return The column index or {@link org.apache.ojb.broker.metadata.JdbcType#MIN_INT}
if
       * column index is not supported.
       */
      public int getColumnIndex(FieldDescriptor fld);
  }
  
  
  
  1.39      +29 -12    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.38
  retrieving revision 1.39
  diff -u -r1.38 -r1.39
  --- JdbcAccessImpl.java	1 Oct 2005 13:56:13 -0000	1.38
  +++ JdbcAccessImpl.java	3 Oct 2005 17:35:25 -0000	1.39
  @@ -38,13 +38,14 @@
   import org.apache.ojb.broker.PersistenceBrokerSQLException;
   import org.apache.ojb.broker.accesslayer.batch.BatchInfo;
   import org.apache.ojb.broker.accesslayer.batch.BatchManager;
  -import org.apache.ojb.broker.accesslayer.sql.SelectStatementWrapper;
  +import org.apache.ojb.broker.accesslayer.sql.SelectStatement;
   import org.apache.ojb.broker.core.ValueContainer;
   import org.apache.ojb.broker.metadata.ArgumentDescriptor;
   import org.apache.ojb.broker.metadata.ClassDescriptor;
   import org.apache.ojb.broker.metadata.FieldDescriptor;
   import org.apache.ojb.broker.metadata.JdbcTypesHelper;
   import org.apache.ojb.broker.metadata.ProcedureDescriptor;
  +import org.apache.ojb.broker.metadata.JdbcType;
   import org.apache.ojb.broker.platforms.Platform;
   import org.apache.ojb.broker.query.BetweenCriteria;
   import org.apache.ojb.broker.query.Criteria;
  @@ -98,7 +99,7 @@
       {
           if(log.isDebugEnabled()) log.debug("executeDelete: " + obj);
           final StatementManager sm = broker.serviceStatementManager();
  -        final String sql = broker.serviceSqlGenerator().getPreparedDeleteStatement(cld);
  +        final String sql = broker.serviceSqlGenerator().getPreparedDeleteStatement(cld).getStatement();
           final boolean isStoredProcedure = useCallableDeleteStatement(cld);
           final ValueContainer[] values;
   
  @@ -181,7 +182,7 @@
       {
           if(log.isDebugEnabled()) log.debug("executeInsert: " + obj);
           final StatementManager sm = broker.serviceStatementManager();
  -        final String sql = broker.serviceSqlGenerator().getPreparedInsertStatement(cld);
  +        final String sql = broker.serviceSqlGenerator().getPreparedInsertStatement(cld).getStatement();
           final boolean isStoredProcedure = useCallableInsertStatement(cld);
           final ValueContainer[] values;
   
  @@ -328,7 +329,7 @@
           if(log.isDebugEnabled()) log.debug("executeUpdate fields for object: " + obj);
   
           final StatementManager sm = broker.serviceStatementManager();
  -        final String sql = broker.serviceSqlGenerator().getPreparedUpdateStatement(cld,
fieldsToUpdate);
  +        final String sql = broker.serviceSqlGenerator().getPreparedUpdateStatement(cld,
fieldsToUpdate).getStatement();
           final ValueContainer[] values;
           final boolean isStoredProcedure = useCallableUpdateStatement(cld);
           if(isStoredProcedure)
  @@ -410,7 +411,7 @@
       public boolean doesExist(ClassDescriptor cld, Identity oid)
       {
           boolean result = false;
  -        String sql = broker.serviceSqlGenerator().getPreparedExistsStatement(cld);
  +        String sql = broker.serviceSqlGenerator().getPreparedExistsStatement(cld).getStatement();
           StatementManager sm = broker.serviceStatementManager();
           PreparedStatement stmt = null;
           ResultSet rs = null;
  @@ -442,7 +443,7 @@
       public void executeDelete(Query query, ClassDescriptor cld) throws PersistenceBrokerException
       {
           if(log.isDebugEnabled()) log.debug("executeDelete (by Query): " + query);
  -        final String sql = this.broker.serviceSqlGenerator().getPreparedDeleteStatement(query,
cld);
  +        final String sql = this.broker.serviceSqlGenerator().getPreparedDeleteStatement(query,
cld).getStatement();
           StatementManager sm = broker.serviceStatementManager();
           PreparedStatement stmt = null;
           try
  @@ -497,7 +498,7 @@
           final StatementManager stmtManager = broker.serviceStatementManager();
           final boolean scrollable = isScrollable(query);
           ResultSetAndStatement retval = null;
  -        SelectStatementWrapper sql = null;
  +        SelectStatement sql = null;
   
           try
           {
  @@ -574,8 +575,8 @@
   
       /** performs a SQL SELECT statement against RDBMS. */
       public ResultSetAndStatement executeSQL(
  -            String sql,
  -            ValueContainer[] values,
  +            final String sql,
  +            final ValueContainer[] values,
               boolean scrollable)
               throws PersistenceBrokerException
       {
  @@ -607,7 +608,23 @@
   
               // as we return the resultset for further operations, we cannot release the
statement yet.
               // that has to be done by the JdbcAccess-clients (i.e. RsIterator, ProxyRsIterator
and PkEnumeration.)
  -            retval = new ResultSetAndStatement(broker.serviceStatementManager(), stmt,
rs, null);
  +            // arminw: use anonymous inner class to satisfy constructor of
  +            retval = new ResultSetAndStatement(broker.serviceStatementManager(), stmt,
rs, new SelectStatement(){
  +                public Query getQueryInstance()
  +                {
  +                    return null;
  +                }
  +
  +                public int getColumnIndex(FieldDescriptor fld)
  +                {
  +                    return JdbcType.MIN_INT;
  +                }
  +
  +                public String getStatement()
  +                {
  +                    return sql;
  +                }
  +            });
               return retval;
           }
           catch(PersistenceBrokerException e)
  @@ -657,7 +674,7 @@
               throws PersistenceBrokerException
       {
           final StatementManager sm = broker.serviceStatementManager();
  -        SelectStatementWrapper sql = null;
  +        SelectStatement sql = null;
           ValueContainer[] values = null;
           ResultSetAndStatement rs_stmt = null;
           try
  
  
  
  1.17      +4 -4      db-ojb/src/java/org/apache/ojb/broker/accesslayer/ResultSetAndStatement.java
  
  Index: ResultSetAndStatement.java
  ===================================================================
  RCS file: /home/cvs/db-ojb/src/java/org/apache/ojb/broker/accesslayer/ResultSetAndStatement.java,v
  retrieving revision 1.16
  retrieving revision 1.17
  diff -u -r1.16 -r1.17
  --- ResultSetAndStatement.java	30 Sep 2005 01:46:44 -0000	1.16
  +++ ResultSetAndStatement.java	3 Oct 2005 17:35:25 -0000	1.17
  @@ -18,7 +18,7 @@
   import java.sql.ResultSet;
   import java.sql.Statement;
   
  -import org.apache.ojb.broker.accesslayer.sql.SelectStatementWrapper;
  +import org.apache.ojb.broker.accesslayer.sql.SelectStatement;
   import org.apache.ojb.broker.util.logging.Logger;
   import org.apache.ojb.broker.util.logging.LoggerFactory;
   
  @@ -39,9 +39,9 @@
       */
   	public final ResultSet m_rs;
   	public final Statement m_stmt;
  -    public final SelectStatementWrapper m_sql;
  +    public final SelectStatement m_sql;
   
  -	public ResultSetAndStatement(StatementManager manager, Statement stmt, ResultSet rs, SelectStatementWrapper
sql)
  +	public ResultSetAndStatement(StatementManager manager, Statement stmt, ResultSet rs, SelectStatement
sql)
   	{
   		this.manager = manager;
           m_stmt = stmt;
  
  
  
  1.42      +2 -19     db-ojb/src/java/org/apache/ojb/broker/accesslayer/RowReaderDefaultImpl.java
  
  Index: RowReaderDefaultImpl.java
  ===================================================================
  RCS file: /home/cvs/db-ojb/src/java/org/apache/ojb/broker/accesslayer/RowReaderDefaultImpl.java,v
  retrieving revision 1.41
  retrieving revision 1.42
  diff -u -r1.41 -r1.42
  --- RowReaderDefaultImpl.java	30 Sep 2005 21:45:15 -0000	1.41
  +++ RowReaderDefaultImpl.java	3 Oct 2005 17:35:25 -0000	1.42
  @@ -25,17 +25,12 @@
   import org.apache.commons.beanutils.ConvertUtils;
   import org.apache.commons.collections.map.ListOrderedMap;
   import org.apache.ojb.broker.PersistenceBrokerException;
  -import org.apache.ojb.broker.accesslayer.sql.SelectStatementWrapper;
   import org.apache.ojb.broker.core.factory.ObjectFactory;
   import org.apache.ojb.broker.metadata.ClassDescriptor;
   import org.apache.ojb.broker.metadata.CreationDescriptor;
   import org.apache.ojb.broker.metadata.CreationParameter;
  -import org.apache.ojb.broker.metadata.EnclosingClassReferenceDescriptor;
   import org.apache.ojb.broker.metadata.FieldDescriptor;
  -import org.apache.ojb.broker.metadata.JdbcType;
   import org.apache.ojb.broker.metadata.MetadataException;
  -import org.apache.ojb.broker.metadata.ObjectReferenceDescriptor;
  -import org.apache.ojb.broker.util.ClassHelper;
   import org.apache.ojb.broker.util.SqlHelper;
   
   /**
  @@ -325,18 +320,6 @@
           readValuesFrom(rs_stmt, row, pkFields);
       }
   
  -    private int getColumnIndex(SelectStatementWrapper statementWrapper, FieldDescriptor
fld)
  -    {
  -        int index = JdbcType.MIN_INT;
  -        
  -        if (statementWrapper != null)
  -        {
  -            index = statementWrapper.getColumnIndex(fld);
  -        }
  -        
  -        return index;
  -    }
  -
       protected void readValuesFrom(ResultSetAndStatement rs_stmt, Map row, FieldDescriptor[]
fields)
       {
           int size = fields.length;
  @@ -349,7 +332,7 @@
                   fld = fields[j];
                   if(!row.containsKey(fld.getColumnName()))
                   {
  -                    int idx = getColumnIndex(rs_stmt.m_sql, fld);
  +                    int idx = rs_stmt.m_sql.getColumnIndex(fld);
                       val = fld.getJdbcType().getObjectFromColumn(rs_stmt.m_rs, null, fld.getColumnName(),
idx);
                       row.put(fld.getColumnName(), fld.getFieldConversion().sqlToJava(val));
                   }
  
  
  
  1.25      +1 -1      db-ojb/src/java/org/apache/ojb/broker/accesslayer/SqlBasedRsIterator.java
  
  
  
  
  1.20      +7 -7      db-ojb/src/java/org/apache/ojb/broker/core/MtoNBroker.java
  
  Index: MtoNBroker.java
  ===================================================================
  RCS file: /home/cvs/db-ojb/src/java/org/apache/ojb/broker/core/MtoNBroker.java,v
  retrieving revision 1.19
  retrieving revision 1.20
  diff -u -r1.19 -r1.20
  --- MtoNBroker.java	1 Oct 2005 13:56:14 -0000	1.19
  +++ MtoNBroker.java	3 Oct 2005 17:35:25 -0000	1.20
  @@ -98,7 +98,7 @@
   
           String[] cols = mergeColumns(pkColumns, otherPkColumns);
           String insertStmt = pb.serviceSqlGenerator()
  -                .getGenericPreparedStatement(SqlGenerator.TYPE_GENERIC_INSERT, table, cols,
null);
  +                .getGenericPreparedStatement(SqlGenerator.TYPE_GENERIC_INSERT, table, cols,
null).getStatement();
           ValueContainer[] values = mergeContainer(pkValues, otherPkValues);
           GenericObject gObj = new GenericObject(table, cols, values);
           if(! tempObjects.contains(gObj))
  @@ -126,7 +126,7 @@
           String table = cod.getIndirectionTable();
   
           String selectStmt = pb.serviceSqlGenerator()
  -                .getGenericPreparedStatement(SqlGenerator.TYPE_GENERIC_SELECT, table, fkColumns,
pkColumns);
  +                .getGenericPreparedStatement(SqlGenerator.TYPE_GENERIC_SELECT, table, fkColumns,
pkColumns).getStatement();
   
           ClassDescriptor itemCLD = cod.getItemClassDescriptor();
           Collection extents = pb.getDescriptorRepository().getAllConcreteSubclassDescriptors(itemCLD);
  @@ -180,7 +180,7 @@
           String[] pkColumns = cod.getFksToThisClass();
           String table = cod.getIndirectionTable();
           String deleteStmt = pb.serviceSqlGenerator()
  -                .getGenericPreparedStatement(SqlGenerator.TYPE_GENERIC_DELETE, table, null,
pkColumns);
  +                .getGenericPreparedStatement(SqlGenerator.TYPE_GENERIC_DELETE, table, null,
pkColumns).getStatement();
           pb.serviceJdbcAccess().executeUpdateSQL(deleteStmt, pkValues);
       }
   
  @@ -227,7 +227,7 @@
           {
               fkValues = ((MtoNBroker.Key) iter.next()).m_containers;
               deleteStmt = pb.serviceSqlGenerator()
  -                    .getGenericPreparedStatement(SqlGenerator.TYPE_GENERIC_DELETE, table,
null, columns);
  +                    .getGenericPreparedStatement(SqlGenerator.TYPE_GENERIC_DELETE, table,
null, columns).getStatement();
               pb.serviceJdbcAccess().executeUpdateSQL(deleteStmt, mergeContainer(pkValues,
fkValues));
           }
       }
  @@ -295,7 +295,7 @@
               if(insert)
               {
                   stmt = pb.serviceSqlGenerator()
  -                        .getGenericPreparedStatement(SqlGenerator.TYPE_GENERIC_INSERT,
table, cols, null);
  +                        .getGenericPreparedStatement(SqlGenerator.TYPE_GENERIC_INSERT,
table, cols, null).getStatement();
                   GenericObject gObj = new GenericObject(table, cols, values);
                   if(!tempObjects.contains(gObj))
                   {
  @@ -306,7 +306,7 @@
               else
               {
                   stmt = pb.serviceSqlGenerator()
  -                        .getGenericPreparedStatement(SqlGenerator.TYPE_GENERIC_DELETE,
table, null, cols);
  +                        .getGenericPreparedStatement(SqlGenerator.TYPE_GENERIC_DELETE,
table, null, cols).getStatement();
                   pb.serviceJdbcAccess().executeUpdateSQL(stmt, values);
               }
           }
  
  
  

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