db-ojb-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From b..@apache.org
Subject cvs commit: db-ojb/src/java/org/apache/ojb/broker/accesslayer/sql SqlGenericUpdateStatement.java SqlGenericSelectStatement.java SqlGenericDeleteStatement.java AbstractSqlStatement.java SqlInsertStatement.java SqlDeleteByPkStatement.java SqlUpdateStatement.java SqlSelectStatement.java SqlDeleteByQuery.java SqlSelectByPkStatement.java SqlGenericInsertStatement.java SqlExistStatement.java
Date Mon, 10 Oct 2005 18:21:14 GMT
brj         2005/10/10 11:21:14

  Modified:    src/java/org/apache/ojb/broker/accesslayer/sql
                        SqlGenericUpdateStatement.java
                        SqlGenericSelectStatement.java
                        SqlGenericDeleteStatement.java
                        AbstractSqlStatement.java SqlInsertStatement.java
                        SqlDeleteByPkStatement.java SqlUpdateStatement.java
                        SqlSelectStatement.java SqlDeleteByQuery.java
                        SqlSelectByPkStatement.java
                        SqlGenericInsertStatement.java
                        SqlExistStatement.java
  Log:
  store generated sql-string in instvar
  
  Revision  Changes    Path
  1.3       +3 -4      db-ojb/src/java/org/apache/ojb/broker/accesslayer/sql/SqlGenericUpdateStatement.java
  
  Index: SqlGenericUpdateStatement.java
  ===================================================================
  RCS file: /home/cvs/db-ojb/src/java/org/apache/ojb/broker/accesslayer/sql/SqlGenericUpdateStatement.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- SqlGenericUpdateStatement.java	22 Nov 2004 20:55:23 -0000	1.2
  +++ SqlGenericUpdateStatement.java	10 Oct 2005 18:21:14 -0000	1.3
  @@ -68,9 +68,9 @@
       }
   
       /**
  -     * @see SqlStatement#getStatement()
  +     * @see org.apache.ojb.broker.accesslayer.sql.AbstractSqlStatement#buildSqlString()
        */
  -    public String getStatement()
  +    protected String buildSqlString()
       {
           StringBuffer stmt = new StringBuffer(1024);
   
  @@ -84,5 +84,4 @@
   
           return stmt.toString();
       }
  -
   }
  
  
  
  1.3       +8 -5      db-ojb/src/java/org/apache/ojb/broker/accesslayer/sql/SqlGenericSelectStatement.java
  
  Index: SqlGenericSelectStatement.java
  ===================================================================
  RCS file: /home/cvs/db-ojb/src/java/org/apache/ojb/broker/accesslayer/sql/SqlGenericSelectStatement.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- SqlGenericSelectStatement.java	22 Nov 2004 20:55:23 -0000	1.2
  +++ SqlGenericSelectStatement.java	10 Oct 2005 18:21:14 -0000	1.3
  @@ -29,7 +29,7 @@
       private String[] m_selectColumns;
   
       /**
  -     *
  +     * Constructor.
        * @param aPlatform TODO
        * @param aLogger
        * @param aTable
  @@ -43,9 +43,9 @@
       }
   
       /**
  -     * @see SqlStatement#getStatement()
  +     * @see org.apache.ojb.broker.accesslayer.sql.AbstractSqlStatement#buildSqlString()
        */
  -    public String getStatement()
  +    protected String buildSqlString()
       {
           StringBuffer stmt = new StringBuffer(1024);
   
  @@ -53,7 +53,10 @@
           appendListOfColumns(m_selectColumns,stmt);
           stmt.append(FROM);
           appendTable(getTable(), stmt);
  -        if(getColumns() != null && getColumns().length > 0) appendWhereClause(stmt,
getColumns());
  +        if(getColumns() != null && getColumns().length > 0)
  +        {
  +            appendWhereClause(stmt, getColumns());
  +        }    
   
           return stmt.toString();
       }
  
  
  
  1.3       +8 -5      db-ojb/src/java/org/apache/ojb/broker/accesslayer/sql/SqlGenericDeleteStatement.java
  
  Index: SqlGenericDeleteStatement.java
  ===================================================================
  RCS file: /home/cvs/db-ojb/src/java/org/apache/ojb/broker/accesslayer/sql/SqlGenericDeleteStatement.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- SqlGenericDeleteStatement.java	22 Nov 2004 20:55:23 -0000	1.2
  +++ SqlGenericDeleteStatement.java	10 Oct 2005 18:21:14 -0000	1.3
  @@ -38,15 +38,18 @@
       }
   
       /**
  -     * @see SqlStatement#getStatement()
  +     * @see org.apache.ojb.broker.accesslayer.sql.AbstractSqlStatement#buildSqlString()
        */
  -    public String getStatement()
  +    protected String buildSqlString()
       {
           StringBuffer stmt = new StringBuffer(1024);
   
           stmt.append(DELETE_FROM);
           appendTable(getTable(), stmt);
  -        if(getColumns() != null && getColumns().length > 0) appendWhereClause(stmt,
getColumns());
  +        if(getColumns() != null && getColumns().length > 0)
  +        {
  +            appendWhereClause(stmt, getColumns());
  +        }    
           return stmt.toString();
  -    }
  +    }    
   }
  
  
  
  1.3       +19 -1     db-ojb/src/java/org/apache/ojb/broker/accesslayer/sql/AbstractSqlStatement.java
  
  Index: AbstractSqlStatement.java
  ===================================================================
  RCS file: /home/cvs/db-ojb/src/java/org/apache/ojb/broker/accesslayer/sql/AbstractSqlStatement.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- AbstractSqlStatement.java	27 Aug 2005 12:05:04 -0000	1.2
  +++ AbstractSqlStatement.java	10 Oct 2005 18:21:14 -0000	1.3
  @@ -31,6 +31,7 @@
   {
       private Logger m_logger;
       private Platform m_platform;
  +    private String m_sqlString;
   
       /**
        * @param logger
  @@ -102,5 +103,22 @@
           buf.append(m_platform.quoteName(aColumn));
       }
   
  +    /**
  +     * Build the SQL-String.
  +     * @return the SQL-String
  +     */
  +    protected abstract String buildSqlString();
  +    
  +    /**
  +     * @see SqlStatement#getStatement()
  +     */
  +    public String getStatement()
  +    {
  +        if (m_sqlString == null)
  +        {
  +            m_sqlString = buildSqlString();
  +        }
   
  +        return m_sqlString;
  +    }
   }
  
  
  
  1.11      +14 -21    db-ojb/src/java/org/apache/ojb/broker/accesslayer/sql/SqlInsertStatement.java
  
  Index: SqlInsertStatement.java
  ===================================================================
  RCS file: /home/cvs/db-ojb/src/java/org/apache/ojb/broker/accesslayer/sql/SqlInsertStatement.java,v
  retrieving revision 1.10
  retrieving revision 1.11
  diff -u -r1.10 -r1.11
  --- SqlInsertStatement.java	7 Oct 2005 14:34:11 -0000	1.10
  +++ SqlInsertStatement.java	10 Oct 2005 18:21:14 -0000	1.11
  @@ -31,8 +31,6 @@
    */
   public class SqlInsertStatement extends SqlPkStatement
   {
  -    private String sql;
  -
       /**
   	 * Constructor for SqlInsertStatement.
   	 * @param aPlatform 
  @@ -44,26 +42,22 @@
   		super(aPlatform, aLogger, aCld);
   	}
   
  -	/**
  -	 * @see org.apache.ojb.broker.accesslayer.sql.SqlStatement#getStatement()
  -	 */
  -	public String getStatement()
  +    /**
  +     * @see org.apache.ojb.broker.accesslayer.sql.AbstractSqlStatement#buildSqlString()
  +     */
  +    protected String buildSqlString()
   	{
  -        if(sql == null)
  -        {
  -            StringBuffer stmt = new StringBuffer(1024);
  -            ClassDescriptor cld = getClassDescriptor();
  +        StringBuffer stmt = new StringBuffer(1024);
  +        ClassDescriptor cld = getClassDescriptor();
   
  -            stmt.append("INSERT INTO ");
  -            appendTable(cld, stmt);
  -            stmt.append(" (");
  -            appendListOfColumns(cld, stmt);
  -            stmt.append(")");
  -            appendListOfValues(cld, stmt);
  +        stmt.append("INSERT INTO ");
  +        appendTable(cld, stmt);
  +        stmt.append(" (");
  +        appendListOfColumns(cld, stmt);
  +        stmt.append(")");
  +        appendListOfValues(cld, stmt);
   
  -            sql = stmt.toString();
  -        }
  -        return sql;
  +        return stmt.toString();
       }
   
       private List appendListOfColumns(ClassDescriptor cld, StringBuffer buf)
  @@ -109,6 +103,5 @@
           }
           stmt.append(") ");
       }
  -
   }
   
  
  
  
  1.10      +13 -20    db-ojb/src/java/org/apache/ojb/broker/accesslayer/sql/SqlDeleteByPkStatement.java
  
  Index: SqlDeleteByPkStatement.java
  ===================================================================
  RCS file: /home/cvs/db-ojb/src/java/org/apache/ojb/broker/accesslayer/sql/SqlDeleteByPkStatement.java,v
  retrieving revision 1.9
  retrieving revision 1.10
  diff -u -r1.9 -r1.10
  --- SqlDeleteByPkStatement.java	7 Oct 2005 14:34:11 -0000	1.9
  +++ SqlDeleteByPkStatement.java	10 Oct 2005 18:21:14 -0000	1.10
  @@ -32,8 +32,6 @@
    */
   public class SqlDeleteByPkStatement extends SqlPkStatement
   {
  -    private String sql;
  -
       /**
   	 * Constructor for SqlDeleteByPkStatement.
   	 * @param aPlatform 
  @@ -45,23 +43,19 @@
           super(aPlatform, aLogger, aCld);
   	}
   
  -	/**
  -	 * @see org.apache.ojb.broker.accesslayer.sql.SqlStatement#getStatement()
  -	 */
  -	public String getStatement()
  +    /**
  +     * @see org.apache.ojb.broker.accesslayer.sql.AbstractSqlStatement#buildSqlString()
  +     */
  +    protected String buildSqlString()
   	{
  -        if(sql == null)
  -        {
  -            StringBuffer stmt = new StringBuffer(1024);
  -            ClassDescriptor cld = getClassDescriptor();
  -
  -            stmt.append("DELETE FROM ");
  -            appendTable(cld,stmt);
  -            appendWhereClause(cld, true, stmt); //use Locking
  -
  -            sql = stmt.toString();
  -        }
  -        return sql;
  +        StringBuffer stmt = new StringBuffer(1024);
  +        ClassDescriptor cld = getClassDescriptor();
  +
  +        stmt.append("DELETE FROM ");
  +        appendTable(cld, stmt);
  +        appendWhereClause(cld, true, stmt); //use Locking
  +
  +        return stmt.toString();
       }
   
   	/**
  @@ -98,6 +92,5 @@
   		fldColl.toArray(fields);
   		appendWhereClause(fields, stmt);
   	}
  -
   }
   
  
  
  
  1.10      +15 -22    db-ojb/src/java/org/apache/ojb/broker/accesslayer/sql/SqlUpdateStatement.java
  
  Index: SqlUpdateStatement.java
  ===================================================================
  RCS file: /home/cvs/db-ojb/src/java/org/apache/ojb/broker/accesslayer/sql/SqlUpdateStatement.java,v
  retrieving revision 1.9
  retrieving revision 1.10
  diff -u -r1.9 -r1.10
  --- SqlUpdateStatement.java	7 Oct 2005 14:34:11 -0000	1.9
  +++ SqlUpdateStatement.java	10 Oct 2005 18:21:14 -0000	1.10
  @@ -28,8 +28,6 @@
    */
   public class SqlUpdateStatement extends SqlPkStatement
   {
  -    protected String sql;
  -
       /**
   	 * Constructor for SqlUpdateStatement.
   	 * @param aPlatform 
  @@ -71,24 +69,19 @@
           return getClassDescriptor().getNonPkRwFields();
       }
   
  -	/**
  -	 * @see SqlStatement#getStatement()
  -	 */
  -	public String getStatement()
  -	{
  -        if(sql == null)
  -        {
  -            StringBuffer stmt = new StringBuffer(1024);
  -            ClassDescriptor cld = getClassDescriptor();
  -
  -            stmt.append("UPDATE ");
  -            appendTable(cld, stmt);
  -            appendSetClause(stmt);
  -            appendWhereClause(cld, true, stmt); //use Locking
  -
  -            sql = stmt.toString();
  -        }
  -        return sql;
  -    }
  +    /**
  +     * @see org.apache.ojb.broker.accesslayer.sql.AbstractSqlStatement#buildSqlString()
  +     */
  +    protected String buildSqlString()
  +    {
  +        StringBuffer stmt = new StringBuffer(1024);
  +        ClassDescriptor cld = getClassDescriptor();
   
  +        stmt.append("UPDATE ");
  +        appendTable(cld, stmt);
  +        appendSetClause(stmt);
  +        appendWhereClause(cld, true, stmt); //use Locking
  +
  +        return stmt.toString();
  +    }
   }
  
  
  
  1.46      +10 -7     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.45
  retrieving revision 1.46
  diff -u -r1.45 -r1.46
  --- SqlSelectStatement.java	8 Oct 2005 12:07:33 -0000	1.45
  +++ SqlSelectStatement.java	10 Oct 2005 18:21:14 -0000	1.46
  @@ -39,7 +39,7 @@
   /**
    * Model a SELECT Statement
    *
  - * @author <a href="mailto:jbraeuchi@hotmail.com">Jakob Braeuchi</a>
  + * @author <a href="mailto:jbraeuchi@gmx.ch">Jakob Braeuchi</a>
    * @version $Id$
    */
   public class SqlSelectStatement extends SqlQueryStatement implements SelectStatement
  @@ -169,7 +169,6 @@
   
       /**
        * Return the Fields to be selected.
  -     *
        * @return the Fields to be selected
        */
       protected FieldDescriptor[] getFieldsForSelect()
  @@ -183,7 +182,6 @@
   
       /**
        * Return the Fields to be selected.
  -     *
        * @param cld the ClassDescriptor
        * @return the Fields to be selected
        */
  @@ -228,7 +226,6 @@
       
       /**
        * Appends to the statement a comma separated list of column names.
  -     *
        * @param columns defines the columns to be selected (for reports)
        * @return list of column names
        */
  @@ -249,9 +246,9 @@
       }
   
       /**
  -     * Answer the SELECT-Sql for the Statement
  +     * @see org.apache.ojb.broker.accesslayer.sql.AbstractSqlStatement#buildSqlString()
        */
  -    public String getStatement()
  +    protected String buildSqlString()
       {
           StringBuffer stmt = new StringBuffer(1024);
           QueryByCriteria query = getQuery();
  @@ -423,11 +420,17 @@
           }
       }
   
  +    /**
  +     * @see org.apache.ojb.broker.accesslayer.sql.SelectStatement#getQueryInstance()
  +     */
       public Query getQueryInstance()
       {
           return getQuery();
       }
   
  +    /**
  +     * @see org.apache.ojb.broker.accesslayer.sql.SelectStatement#getColumnIndex(org.apache.ojb.broker.metadata.FieldDescriptor)
  +     */
       public int getColumnIndex(FieldDescriptor fld)
       {
           int index = JdbcType.MIN_INT;
  
  
  
  1.21      +14 -16    db-ojb/src/java/org/apache/ojb/broker/accesslayer/sql/SqlDeleteByQuery.java
  
  Index: SqlDeleteByQuery.java
  ===================================================================
  RCS file: /home/cvs/db-ojb/src/java/org/apache/ojb/broker/accesslayer/sql/SqlDeleteByQuery.java,v
  retrieving revision 1.20
  retrieving revision 1.21
  diff -u -r1.20 -r1.21
  --- SqlDeleteByQuery.java	8 Jun 2005 20:35:09 -0000	1.20
  +++ SqlDeleteByQuery.java	10 Oct 2005 18:21:14 -0000	1.21
  @@ -31,7 +31,6 @@
    */
   public class SqlDeleteByQuery extends SqlQueryStatement
   {
  -
   	/**
   	 * Constructor for SqlDeleteByQuery.
   	 * @param aCld
  @@ -41,22 +40,22 @@
   		super(aPlatform, aLogger, aCld, aQuery);
   	}
   
  -	/**
  -	 * @see org.apache.ojb.broker.accesslayer.sql.SqlStatement#getStatement()
  -	 */
  -	public String getStatement()
  -	{
  -		StringBuffer stmt = new StringBuffer();
  -		StringBuffer where = new StringBuffer();
  +    /**
  +     * @see org.apache.ojb.broker.accesslayer.sql.AbstractSqlStatement#buildSqlString()
  +     */
  +    protected String buildSqlString()
  +    {
  +        StringBuffer stmt = new StringBuffer();
  +        StringBuffer where = new StringBuffer();
   
  -		Criteria crit = this.getQuery().getCriteria();
  +        Criteria crit = this.getQuery().getCriteria();
   
  -		stmt.append("DELETE FROM ");
  -		stmt.append(getSearchClassDescriptor().getFullTableName());
  -		appendWhereClause(where, crit, stmt);
  +        stmt.append("DELETE FROM ");
  +        stmt.append(getSearchClassDescriptor().getFullTableName());
  +        appendWhereClause(where, crit, stmt);
   
  -		return stmt.toString();
  -	}
  +        return stmt.toString();
  +    }
   
   	/**
        * @see org.apache.ojb.broker.accesslayer.sql.SqlQueryStatement#getColName()
  @@ -83,5 +82,4 @@
   
          return result;
      }
  -
   }
  
  
  
  1.13      +1 -13     db-ojb/src/java/org/apache/ojb/broker/accesslayer/sql/SqlSelectByPkStatement.java
  
  Index: SqlSelectByPkStatement.java
  ===================================================================
  RCS file: /home/cvs/db-ojb/src/java/org/apache/ojb/broker/accesslayer/sql/SqlSelectByPkStatement.java,v
  retrieving revision 1.12
  retrieving revision 1.13
  diff -u -r1.12 -r1.13
  --- SqlSelectByPkStatement.java	7 Oct 2005 14:34:11 -0000	1.12
  +++ SqlSelectByPkStatement.java	10 Oct 2005 18:21:14 -0000	1.13
  @@ -29,11 +29,8 @@
    * @author <a href="mailto:jbraeuchi@gmx.ch">Jakob Braeuchi</a>
    * @version $Id$
    */
  -
   public class SqlSelectByPkStatement extends SqlSelectStatement
   {
  -    private String sql;
  -
       /**
        * Constructor for SqlSelectByPkStatement.
        * @param cld
  @@ -61,13 +58,4 @@
           // TODO: should use broker.getQueryFactory().newQuery()
           return QueryFactory.newQuery(cld.getClassOfObject(), crit);
       }
  -
  -    public String getStatement()
  -    {
  -        if(sql == null)
  -        {
  -            sql = super.getStatement();
  -        }
  -        return sql;
  -    }
   }
  
  
  
  1.3       +4 -7      db-ojb/src/java/org/apache/ojb/broker/accesslayer/sql/SqlGenericInsertStatement.java
  
  Index: SqlGenericInsertStatement.java
  ===================================================================
  RCS file: /home/cvs/db-ojb/src/java/org/apache/ojb/broker/accesslayer/sql/SqlGenericInsertStatement.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- SqlGenericInsertStatement.java	22 Nov 2004 20:55:23 -0000	1.2
  +++ SqlGenericInsertStatement.java	10 Oct 2005 18:21:14 -0000	1.3
  @@ -21,12 +21,11 @@
   /**
    * Model an generic INSERT Statement for specified table.
    *
  - * @author <a href="mailto:jbraeuchi@hotmail.com">Jakob Braeuchi</a>
  + * @author <a href="mailto:jbraeuchi@gmx.ch">Jakob Braeuchi</a>
    * @version $Id$
    */
   public class SqlGenericInsertStatement extends SqlGenericStatement
   {
  -
       /**
        * Constructor for SqlInsertMNStatement.
        * @param aPlatform TODO
  @@ -47,7 +46,6 @@
           int cnt = getColumns().length;
   
           stmt.append(VALUES);
  -
           for (int i = 0; i < cnt; i++)
           {
               if (i > 0)
  @@ -60,9 +58,9 @@
       }
   
       /**
  -     * @see SqlStatement#getStatement()
  +     * @see org.apache.ojb.broker.accesslayer.sql.AbstractSqlStatement#buildSqlString()
        */
  -    public String getStatement()
  +    protected String buildSqlString()
       {
           StringBuffer stmt = new StringBuffer(1024);
   
  @@ -74,6 +72,5 @@
           appendListOfValues(stmt);
           return stmt.toString();
       }
  -
   }
   
  
  
  
  1.8       +17 -23    db-ojb/src/java/org/apache/ojb/broker/accesslayer/sql/SqlExistStatement.java
  
  Index: SqlExistStatement.java
  ===================================================================
  RCS file: /home/cvs/db-ojb/src/java/org/apache/ojb/broker/accesslayer/sql/SqlExistStatement.java,v
  retrieving revision 1.7
  retrieving revision 1.8
  diff -u -r1.7 -r1.8
  --- SqlExistStatement.java	7 Oct 2005 14:34:11 -0000	1.7
  +++ SqlExistStatement.java	10 Oct 2005 18:21:14 -0000	1.8
  @@ -33,38 +33,32 @@
       private static final String SELECT = "SELECT ";
       private static final String FROM = " FROM ";
   
  -    private String sql;
  -
       public SqlExistStatement(Platform aPlatform, Logger aLogger, ClassDescriptor aCld)
       {
           super(aPlatform, aLogger, aCld);
       }
   
       /**
  -     * Return SELECT clause for object existence call
  +     * @see org.apache.ojb.broker.accesslayer.sql.AbstractSqlStatement#buildSqlString()
        */
  -    public String getStatement()
  +    protected String buildSqlString()
       {
  -        if(sql == null)
  -        {
  -            StringBuffer stmt = new StringBuffer(128);
  -            ClassDescriptor cld = getClassDescriptor();
  +        StringBuffer stmt = new StringBuffer(128);
  +        ClassDescriptor cld = getClassDescriptor();
   
  -            FieldDescriptor[] fieldDescriptors = cld.getPkFields();
  -            if (fieldDescriptors == null || fieldDescriptors.length == 0)
  -            {
  -                throw new OJBRuntimeException("No PK fields defined in metadata for " +
cld.getClassNameOfObject());
  -            }
  -            FieldDescriptor field = fieldDescriptors[0];
  +        FieldDescriptor[] fieldDescriptors = cld.getPkFields();
  +        if (fieldDescriptors == null || fieldDescriptors.length == 0)
  +        {
  +            throw new OJBRuntimeException("No PK fields defined in metadata for " + cld.getClassNameOfObject());
  +        }
  +        FieldDescriptor field = fieldDescriptors[0];
   
  -            stmt.append(SELECT);
  -            appendField(field, stmt);
  -            stmt.append(FROM);
  -            appendTable(cld, stmt);
  -            appendWhereClause(cld, false, stmt);
  +        stmt.append(SELECT);
  +        appendField(field, stmt);
  +        stmt.append(FROM);
  +        appendTable(cld, stmt);
  +        appendWhereClause(cld, false, stmt);
   
  -            sql = stmt.toString();
  -        }
  -        return sql;
  +        return stmt.toString();
       }
   }
  
  
  

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