db-ojb-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From olegn...@apache.org
Subject cvs commit: jakarta-ojb/src/java/org/apache/ojb/broker/util SqlHelper.java
Date Sun, 19 Jan 2003 17:20:17 GMT
olegnitz    2003/01/19 09:20:17

  Modified:    src/java/org/apache/ojb/broker/accesslayer JdbcAccess.java
                        JdbcAccessImpl.java StatementManager.java
                        StatementManagerIF.java
               src/java/org/apache/ojb/broker/accesslayer/sql
                        SqlDeleteMNStatement.java SqlGenerator.java
                        SqlGeneratorDefaultImpl.java
                        SqlInsertMNStatement.java SqlMNStatement.java
                        SqlSelectMNStatement.java
               src/java/org/apache/ojb/broker/metadata
                        CollectionDescriptor.java
               src/java/org/apache/ojb/broker/singlevm
                        PersistenceBrokerImpl.java
               src/java/org/apache/ojb/broker/util SqlHelper.java
  Log:
  SQL Statements for M:N indirection table are now true PreparedStatements
  with separated parameters which allows to gather them into bigger batches
  
  Revision  Changes    Path
  1.29      +19 -1     jakarta-ojb/src/java/org/apache/ojb/broker/accesslayer/JdbcAccess.java
  
  Index: JdbcAccess.java
  ===================================================================
  RCS file: /home/cvs/jakarta-ojb/src/java/org/apache/ojb/broker/accesslayer/JdbcAccess.java,v
  retrieving revision 1.28
  retrieving revision 1.29
  diff -u -r1.28 -r1.29
  --- JdbcAccess.java	15 Jan 2003 10:43:28 -0000	1.28
  +++ JdbcAccess.java	19 Jan 2003 17:20:16 -0000	1.29
  @@ -100,6 +100,14 @@
       public ResultSetAndStatement executeSQL(String sqlStatement, ClassDescriptor cld) throws PersistenceBrokerException;
   
       /**
  +     * performs a SQL SELECT statement against RDBMS.
  +     * @param sqlStatement the query string.
  +     * @param cld ClassDescriptor providing meta-information.
  +     * @param values The set of values to bind to the statement (may be null)
  +     */
  +    public ResultSetAndStatement executeSQL(String sqlStatement, ClassDescriptor cld, Object[] values) throws PersistenceBrokerException;
  +
  +    /**
        * performs a SQL UPDTE, INSERT or DELETE statement against RDBMS.
        * @param sqlStatement the query string.
        * @param cld ClassDescriptor providing meta-information.
  @@ -108,6 +116,16 @@
       public int executeUpdateSQL(String sqlStatement, ClassDescriptor cld)
               throws PersistenceBrokerException;
   
  +    /**
  +     * performs a SQL UPDTE, INSERT or DELETE statement against RDBMS.
  +     * @param sqlStatement the query string.
  +     * @param cld ClassDescriptor providing meta-information.
  +     * @param values1 The first set of values to bind to the statement (may be null)
  +     * @param values2 The second set of values to bind to the statement (may be null)
  +     * @return int returncode
  +     */
  +    public int executeUpdateSQL(String sqlStatement, ClassDescriptor cld, Object[] values1, Object[] values2)
  +            throws PersistenceBrokerException;
       /**
        * performs an UPDATE operation against RDBMS.
        * @param obj The Object to be updated in the underlying table.
  
  
  
  1.3       +30 -13    jakarta-ojb/src/java/org/apache/ojb/broker/accesslayer/JdbcAccessImpl.java
  
  Index: JdbcAccessImpl.java
  ===================================================================
  RCS file: /home/cvs/jakarta-ojb/src/java/org/apache/ojb/broker/accesslayer/JdbcAccessImpl.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- JdbcAccessImpl.java	16 Jan 2003 22:16:15 -0000	1.2
  +++ JdbcAccessImpl.java	19 Jan 2003 17:20:16 -0000	1.3
  @@ -291,19 +291,26 @@
   
       }
   
  +    public ResultSetAndStatement executeSQL(String sqlStatement, ClassDescriptor cld) throws PersistenceBrokerException
  +    {
  +        return executeSQL(sqlStatement, cld, null);
  +    }
  +
       /**
        * performs a SQL SELECT statement against RDBMS.
        * @param sqlStatement the query string.
        * @param cld ClassDescriptor providing meta-information.
        */
  -    public ResultSetAndStatement executeSQL(String sqlStatement, ClassDescriptor cld) throws PersistenceBrokerException
  +    public ResultSetAndStatement executeSQL(String sqlStatement, ClassDescriptor cld, Object[] values) throws PersistenceBrokerException
       {
           if (logger.isDebugEnabled()) logger.debug("executeSQL: " + sqlStatement);
   
           ResultSetAndStatement retval = new ResultSetAndStatement();
  +        StatementManagerIF stmtMan = broker.serviceStatementManager();
           try
           {
  -            PreparedStatement stmt = broker.serviceStatementManager().getPreparedStatement(cld, sqlStatement, Query.SCROLLABLE);
  +            PreparedStatement stmt = stmtMan.getPreparedStatement(cld, sqlStatement, Query.SCROLLABLE);
  +            stmtMan.bindValues(stmt, values, 1);
               ResultSet rs = stmt.executeQuery();
               // 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.)
  @@ -323,40 +330,50 @@
           }
       }
   
  +    public int executeUpdateSQL(String sqlStatement, ClassDescriptor cld)
  +        throws PersistenceBrokerException
  +    {
  +        return executeUpdateSQL(sqlStatement, cld, null, null);
  +    }
  +
       /**
        * performs a SQL UPDTE, INSERT or DELETE statement against RDBMS.
        * @param sqlStatement the query string.
        * @param cld ClassDescriptor providing meta-information.
        * @return int returncode
        */
  -    public int executeUpdateSQL(String sqlStatement, ClassDescriptor cld)
  +    public int executeUpdateSQL(String sqlStatement, ClassDescriptor cld, Object[] values1, Object[] values2)
           throws PersistenceBrokerException
       {
           if (logger.isDebugEnabled()) logger.debug("executeUpdateSQL: " + sqlStatement);
           int result;
  +        int index;
           PreparedStatement stmt = null;
  +        StatementManagerIF stmtMan = broker.serviceStatementManager();
           try
           {
  -             stmt = broker.serviceStatementManager().getPreparedStatement(cld, sqlStatement, Query.SCROLLABLE);
  -             result = stmt.executeUpdate();
  +            stmt = stmtMan.getPreparedStatement(cld, sqlStatement, Query.SCROLLABLE);
  +            index = stmtMan.bindValues(stmt, values1, 1);
  +            index = stmtMan.bindValues(stmt, values2, index);
  +            result = stmt.executeUpdate();
           }
           catch (PersistenceBrokerException e)
           {
  -			logger.error("PersistenceBrokerException during the execution of the Update SQL query: " + e.getMessage(), e);
  +            logger.error("PersistenceBrokerException during the execution of the Update SQL query: " + e.getMessage(), e);
               throw e;
           }
           catch (SQLException e)
           {
  -			logger.error("SQLException during the execution of the Update SQL query (for a " + cld.getClassOfObject().getName() + "): " + e.getMessage(), e);
  -			if (SQL_STATE_KEY_VIOLATED.equals(e.getSQLState()))
  -			{
  -				throw new KeyConstraintViolatedException(e);
  -			}
  +            logger.error("SQLException during the execution of the Update SQL query (for a " + cld.getClassOfObject().getName() + "): " + e.getMessage(), e);
  +            if (SQL_STATE_KEY_VIOLATED.equals(e.getSQLState()))
  +            {
  +                throw new KeyConstraintViolatedException(e);
  +            }
               throw new PersistenceBrokerSQLException(e);
           }
           finally
           {
  -			broker.serviceStatementManager().closeResources(stmt, null);
  +            stmtMan.closeResources(stmt, null);
           }
           return result;
       }
  
  
  
  1.20      +21 -2     jakarta-ojb/src/java/org/apache/ojb/broker/accesslayer/StatementManager.java
  
  Index: StatementManager.java
  ===================================================================
  RCS file: /home/cvs/jakarta-ojb/src/java/org/apache/ojb/broker/accesslayer/StatementManager.java,v
  retrieving revision 1.19
  retrieving revision 1.20
  diff -u -r1.19 -r1.20
  --- StatementManager.java	19 Jan 2003 11:50:58 -0000	1.19
  +++ StatementManager.java	19 Jan 2003 17:20:16 -0000	1.20
  @@ -90,7 +90,7 @@
   import java.util.WeakHashMap;
   
   /**
  - * manages JDBC Connection and Statement ressources.
  + * manages JDBC Connection and Statement resources.
    *
    * @author: Thomas Mahler
    * @version $Id$
  @@ -605,6 +605,25 @@
   
               index++;
           }
  +    }
  +
  +    /**
  +     * binds the given array of values (if not null) starting from the given
  +     * parameter index
  +     * @return the next parameter index
  +     */
  +    public int bindValues(PreparedStatement stmt, Object[] values, int index) 
  +            throws SQLException
  +    {
  +        if (values != null)
  +        {
  +            for (int i = 0; i < values.length; i++)
  +            {
  +                platform.setObjectForStatement(stmt, index, values[i], SqlHelper.getSqlTypeByValue(values[i]));
  +                index++;
  +            }
  +        }
  +        return index;
       }
   
       /**
  
  
  
  1.6       +66 -25    jakarta-ojb/src/java/org/apache/ojb/broker/accesslayer/StatementManagerIF.java
  
  Index: StatementManagerIF.java
  ===================================================================
  RCS file: /home/cvs/jakarta-ojb/src/java/org/apache/ojb/broker/accesslayer/StatementManagerIF.java,v
  retrieving revision 1.5
  retrieving revision 1.6
  diff -u -r1.5 -r1.6
  --- StatementManagerIF.java	19 Jan 2003 12:18:44 -0000	1.5
  +++ StatementManagerIF.java	19 Jan 2003 17:20:16 -0000	1.6
  @@ -70,37 +70,78 @@
    */
   public interface StatementManagerIF
   {
  -    /**
     * Binds the Identities Primary key values to the statement.
  +    /**
  +     * Binds the Identities Primary key values to the statement.
        * @param stmt
        * @param oid
  -     * @param cld ClassDescriptor for the Object, if <i>null</i> will be lookup automatic
     */
  +     * @param cld ClassDescriptor for the Object, if <i>null</i> will be lookup automatic
  +     */
       void bindDelete(PreparedStatement stmt, Identity oid, ClassDescriptor cld) throws java.sql.SQLException;
  -    /**
     * binds the objects primary key and locking values to the statement, BRJ
     */
  -    void bindDelete(PreparedStatement stmt, ClassDescriptor cld, Object obj)
        throws java.sql.SQLException;
  -    /**
     * bind a Query based Select Statement
     */
  -    int bindStatement(PreparedStatement stmt, Criteria crit, ClassDescriptor cld, int param)
        throws SQLException;
  -    /**
     * binds the values of the object obj to the statements parameters
     */
  -    void bindInsert(PreparedStatement stmt, ClassDescriptor cld, Object obj)
		throws SQLException;
  -    /**
     * binds the Identities Primary key values to the statement
  +    /**
  +     * binds the objects primary key and locking values to the statement, BRJ
  +     */
  +    void bindDelete(PreparedStatement stmt, ClassDescriptor cld, Object obj)
  +        throws java.sql.SQLException;
  +    /**
  +     * bind a Query based Select Statement
  +     */
  +    int bindStatement(PreparedStatement stmt, Criteria crit, ClassDescriptor cld, int param)
  +        throws SQLException;
  +    /**
  +     * binds the values of the object obj to the statements parameters
  +     */
  +    void bindInsert(PreparedStatement stmt, ClassDescriptor cld, Object obj)
  +		throws SQLException;
  +    /**
  +     * binds the Identities Primary key values to the statement
        * @param stmt
        * @param oid
  -     * @param cld ClassDescriptor for the Object, if <i>null</i> will be lookup automatic
     */
  +     * @param cld ClassDescriptor for the Object, if <i>null</i> will be lookup automatic
  +     */
       void bindSelect(PreparedStatement stmt, Identity oid, ClassDescriptor cld) throws SQLException;
  -    /**
     * binds the values of the object obj to the statements parameters
     */
  -    void bindUpdate(PreparedStatement stmt, ClassDescriptor cld, Object obj)
        throws SQLException;
  -    /**
     * return a prepared DELETE Statement fitting for the given ClassDescriptor
     */
  -    PreparedStatement getDeleteStatement(ClassDescriptor cds)
        throws PersistenceBrokerSQLException;
  -    /**
     * return a generic Statement for the given ClassDescriptor
     */
  +    /**
  +     * binds the values of the object obj to the statements parameters
  +     */
  +    void bindUpdate(PreparedStatement stmt, ClassDescriptor cld, Object obj)
  +        throws SQLException;
  +
  +    /**
  +     * binds the given array of values (if not null) starting from the given
  +     * parameter index
  +     * @return the next parameter index
  +     */
  +    int bindValues(PreparedStatement stmt, Object[] values, int index) throws SQLException;
  +
  +    /**
  +     * return a prepared DELETE Statement fitting for the given ClassDescriptor
  +     */
  +    PreparedStatement getDeleteStatement(ClassDescriptor cds)
  +        throws PersistenceBrokerSQLException;
  +    /**
  +     * return a generic Statement for the given ClassDescriptor
  +     */
       Statement getGenericStatement(ClassDescriptor cds, boolean scrollable) throws PersistenceBrokerException;
  -    /**
     * return a prepared Insert Statement fitting for the given ClassDescriptor
     */
  -    PreparedStatement getInsertStatement(ClassDescriptor cds)
        throws PersistenceBrokerSQLException;
  -    /**
     * return a generic Statement for the given ClassDescriptor
     */
  -    PreparedStatement getPreparedStatement(ClassDescriptor cds, String sql, boolean scrollable)
        throws PersistenceBrokerException;
  -    /**
     * return a prepared Select Statement for the given ClassDescriptor
     */
  -    PreparedStatement getSelectByPKStatement(ClassDescriptor cds)
        throws PersistenceBrokerSQLException;
  -    /**
     * return a prepared Update Statement fitting to the given ClassDescriptor
     */
  -    PreparedStatement getUpdateStatement(ClassDescriptor cds)
        throws PersistenceBrokerSQLException;
  +    /**
  +     * return a prepared Insert Statement fitting for the given ClassDescriptor
  +     */
  +    PreparedStatement getInsertStatement(ClassDescriptor cds)
  +        throws PersistenceBrokerSQLException;
  +    /**
  +     * return a generic Statement for the given ClassDescriptor
  +     */
  +    PreparedStatement getPreparedStatement(ClassDescriptor cds, String sql, boolean scrollable)
  +        throws PersistenceBrokerException;
  +    /**
  +     * return a prepared Select Statement for the given ClassDescriptor
  +     */
  +    PreparedStatement getSelectByPKStatement(ClassDescriptor cds)
  +        throws PersistenceBrokerSQLException;
  +    /**
  +     * return a prepared Update Statement fitting to the given ClassDescriptor
  +     */
  +    PreparedStatement getUpdateStatement(ClassDescriptor cds)
  +        throws PersistenceBrokerSQLException;
   
  -	public void closeResources(Statement stmt, ResultSet rs);
  +    public void closeResources(Statement stmt, ResultSet rs);
   
   }
  
  
  
  1.5       +21 -22    jakarta-ojb/src/java/org/apache/ojb/broker/accesslayer/sql/SqlDeleteMNStatement.java
  
  Index: SqlDeleteMNStatement.java
  ===================================================================
  RCS file: /home/cvs/jakarta-ojb/src/java/org/apache/ojb/broker/accesslayer/sql/SqlDeleteMNStatement.java,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- SqlDeleteMNStatement.java	12 Dec 2002 22:57:36 -0000	1.4
  +++ SqlDeleteMNStatement.java	19 Jan 2003 17:20:16 -0000	1.5
  @@ -64,28 +64,27 @@
    */
   public class SqlDeleteMNStatement extends SqlMNStatement
   {
  -	/**
  -	 * Constructor for SqlInsertMNStatement.
  -	 * @param table
  -	 * @param columns
  -	 */
  -	public SqlDeleteMNStatement(String table, String[] columns, Object[] values, Logger logger)
  -	{
  -		super(table, columns, values, logger);
  -	}
  +    /**
  +     * Constructor for SqlInsertMNStatement.
  +     * @param table
  +     * @param columns
  +     */
  +    public SqlDeleteMNStatement(String table, String[] columns, Logger logger)
  +    {
  +        super(table, columns, logger);
  +    }
   
  -	/**
  -	 * @see org.apache.ojb.broker.accesslayer.SqlStatement#getStatement()
  -	 */
  -	public String getStatement()
  -	{
  -		StringBuffer stmt = new StringBuffer(1024);
  +    /**
  +     * @see org.apache.ojb.broker.accesslayer.SqlStatement#getStatement()
  +     */
  +    public String getStatement()
  +    {
  +        StringBuffer stmt = new StringBuffer(1024);
   
  -		stmt.append("DELETE FROM ");
  -		appendTable(getTable(), stmt);
  -		appendWhereClause(getValues(), stmt, getColumns());
  -
  -		return stmt.toString();
  -	}
  +        stmt.append("DELETE FROM ");
  +        appendTable(getTable(), stmt);
  +        appendWhereClause(stmt, getColumns());
  +        return stmt.toString();
  +    }
   
   }
  
  
  
  1.5       +71 -76    jakarta-ojb/src/java/org/apache/ojb/broker/accesslayer/sql/SqlGenerator.java
  
  Index: SqlGenerator.java
  ===================================================================
  RCS file: /home/cvs/jakarta-ojb/src/java/org/apache/ojb/broker/accesslayer/sql/SqlGenerator.java,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- SqlGenerator.java	8 Dec 2002 13:28:17 -0000	1.4
  +++ SqlGenerator.java	19 Jan 2003 17:20:16 -0000	1.5
  @@ -66,91 +66,86 @@
    */
   public interface SqlGenerator
   {
  -	/**
  -	 * generate an INSERT-Statement for M:N indirection table
  -	 * 
  -	 * @param table
  -	 * @param pkColumns1
  -	 * @param pkValues1
  -	 * @param pkColumns2
  -	 * @param pkValues2
  -	 * @return String
  -	 */
  -	public String getInsertStatement(String table, Object[] pkColumns1, Object[] pkValues1, Object[] pkColumns2, Object[] pkValues2);
  -
  -	/**
  -	 * generate a SELECT-Statement for M:N indirection table
  -	 * @param table the indirection table
  +    /**
  +    * generate an INSERT-Statement for M:N indirection table
  +     *
  +     * @param table
  +     * @param pkColumns1
  +     * @param pkColumns2
  +     * @return String
  +     */
  +    public String getInsertMNStatement(String table, String[] pkColumns1, String[] pkColumns2);
  +
  +    /**
  +     * generate a SELECT-Statement for M:N indirection table
  +     * @param table the indirection table
        * @param selectColumns selected columns
        * @param columns for where
  -	 * @param values for where
  -	 */
  -	public String getSelectStatement(String table, Object[] selectColumns, Object[] columns, Object[] values);
  +     */
  +    public String getSelectMNStatement(String table, String[] selectColumns, String[] columns);
   
       /**
        * generate a DELETE-Statement for M:N indirection table
        *
        * @param table
        * @param pkColumns1
  -     * @param pkValues1
        * @param pkColumns2
  -     * @param pkValues2
        * @return String
        */
  -    public String getDeleteStatement(String table, Object[] pkColumns1, Object[] pkValues1, Object[] pkColumns2, Object[] pkValues2);
  -	
  -	/**
  -	 * generate a select-Statement according to query
  -	 * @param query the Query
  -	 * @param cld the ClassDescriptor
  -	 */
  -	public String getPreparedSelectStatement(Query query, ClassDescriptor cld);
  -
  -	/**
  -	 * generate a select-Statement according to query
  -	 * @param query the Query
  -	 * @param cld the ClassDescriptor
  -	 */
  -	public String getSelectStatementDep(Query query, ClassDescriptor cld);
  -
  -	/**
  -	 * generate a prepared DELETE-Statement according to query
  -	 * @param query the Query
  -	 * @param cld the ClassDescriptor
  -	 */
  -	public String getPreparedDeleteStatement(Query query, ClassDescriptor cld);
  -	
  -	/**
  -	 * generate a prepared DELETE-Statement for the Class
  -	 * described by cld.
  -	 * @param cld the ClassDescriptor
  -	 */
  -	public String getPreparedDeleteStatement(ClassDescriptor cld);
  -	
  -	/**
  -	 * generate a prepared INSERT-Statement for the Class
  -	 * described by mif.
  -	 * @param cld the ClassDescriptor
  -	 */
  -	public String getPreparedInsertStatement(ClassDescriptor cld);
  -	
  -	/**
  -	 * generate a prepared SELECT-Statement for the Class
  -	 * described by cld
  -	 * @param cld the ClassDescriptor
  -	 */
  -	public String getPreparedSelectByPkStatement(ClassDescriptor cld);
  -	
  -	/**
  -	 * generate a prepared UPDATE-Statement for the Class
  -	 * described by cld
  -	 * @param cld the ClassDescriptor
  -	 */
  -	public String getPreparedUpdateStatement(ClassDescriptor cld);
  -	
  -	
  -	
  -	
  -	
  +    public String getDeleteMNStatement(String table, String[] pkColumns1, String[] pkColumns2);
  +
  +    /**
  +     * generate a select-Statement according to query
  +     * @param query the Query
  +     * @param cld the ClassDescriptor
  +     */
  +    public String getPreparedSelectStatement(Query query, ClassDescriptor cld);
  +
  +    /**
  +     * generate a select-Statement according to query
  +     * @param query the Query
  +     * @param cld the ClassDescriptor
  +     */
  +    public String getSelectStatementDep(Query query, ClassDescriptor cld);
  +
  +    /**
  +     * generate a prepared DELETE-Statement according to query
  +     * @param query the Query
  +     * @param cld the ClassDescriptor
  +     */
  +    public String getPreparedDeleteStatement(Query query, ClassDescriptor cld);
  +    
  +    /**
  +     * generate a prepared DELETE-Statement for the Class
  +     * described by cld.
  +     * @param cld the ClassDescriptor
  +     */
  +    public String getPreparedDeleteStatement(ClassDescriptor cld);
  +    
  +    /**
  +     * generate a prepared INSERT-Statement for the Class
  +     * described by mif.
  +     * @param cld the ClassDescriptor
  +     */
  +    public String getPreparedInsertStatement(ClassDescriptor cld);
  +    
  +    /**
  +     * generate a prepared SELECT-Statement for the Class
  +     * described by cld
  +     * @param cld the ClassDescriptor
  +     */
  +    public String getPreparedSelectByPkStatement(ClassDescriptor cld);
  +
  +    /**
  +     * generate a prepared UPDATE-Statement for the Class
  +     * described by cld
  +     * @param cld the ClassDescriptor
  +     */
  +    public String getPreparedUpdateStatement(ClassDescriptor cld);
  +
  +
  +
  +
  +
   
   }
  
  
  
  1.14      +14 -34    jakarta-ojb/src/java/org/apache/ojb/broker/accesslayer/sql/SqlGeneratorDefaultImpl.java
  
  Index: SqlGeneratorDefaultImpl.java
  ===================================================================
  RCS file: /home/cvs/jakarta-ojb/src/java/org/apache/ojb/broker/accesslayer/sql/SqlGeneratorDefaultImpl.java,v
  retrieving revision 1.13
  retrieving revision 1.14
  diff -u -r1.13 -r1.14
  --- SqlGeneratorDefaultImpl.java	28 Dec 2002 10:55:12 -0000	1.13
  +++ SqlGeneratorDefaultImpl.java	19 Jan 2003 17:20:16 -0000	1.14
  @@ -196,25 +196,18 @@
        *
        * @param table
        * @param pkColumns1
  -     * @param pkValues1
        * @param pkColumns2
  -     * @param pkValues2
        */
  -    public String getInsertStatement(String table, Object[] pkColumns1, Object[] pkValues1, Object[] pkColumns2, Object[] pkValues2)
  +    public String getInsertMNStatement(String table, String[] pkColumns1, String[] pkColumns2)
       {
           SqlStatement sql;
           String result;
   
           String[] cols = new String[pkColumns1.length + pkColumns2.length];
  -        Object[] values = new Object[pkColumns1.length + pkColumns2.length];
  -
           System.arraycopy(pkColumns1, 0, cols, 0, pkColumns1.length);
  -        System.arraycopy(pkValues1, 0, values, 0, pkValues1.length);
  -
           System.arraycopy(pkColumns2, 0, cols, pkColumns1.length, pkColumns2.length);
  -        System.arraycopy(pkValues2, 0, values, pkValues1.length, pkValues2.length);
   
  -        sql = new SqlInsertMNStatement(table, cols, values, logger);
  +        sql = new SqlInsertMNStatement(table, cols, logger);
           result = sql.getStatement();
   
           logger.debug("SQL: " + result);
  @@ -227,18 +220,13 @@
        * @param table the indirection table
        * @param selectColumns selected columns
        * @param columns for where
  -     * @param values for where
        */
  -    public String getSelectStatement(String table, Object[] selectColumns, Object[] columns, Object[] values)
  +    public String getSelectMNStatement(String table, String[] selectColumns, String[] columns)
       {
           SqlStatement sql;
           String result;
  -        String[] cols = new String[columns.length];
  -        String[] selCols = new String[selectColumns.length];
   
  -        System.arraycopy(columns, 0, cols, 0, cols.length);
  -        System.arraycopy(selectColumns, 0, selCols, 0, selCols.length);
  -        sql = new SqlSelectMNStatement(table, selCols, cols, values, logger);
  +        sql = new SqlSelectMNStatement(table, selectColumns, columns, logger);
           result = sql.getStatement();
   
           logger.debug("SQL: " + result);
  @@ -250,35 +238,27 @@
        *
        * @param table
        * @param pkColumns1
  -     * @param pkValues1
        * @param pkColumns2
  -     * @param pkValues2
        */
  -    public String getDeleteStatement(String table, Object[] pkColumns1, Object[] pkValues1, Object[] pkColumns2, Object[] pkValues2)
  +    public String getDeleteMNStatement(String table, String[] pkColumns1, String[] pkColumns2)
       {
           SqlStatement sql;
           String result;
           int paramCount;
  +        String[] cols;
   
  -        paramCount = pkColumns1.length;
  -        if (pkValues2 != null)
  +        if (pkColumns2 == null)
           {
  -            paramCount = paramCount + pkColumns2.length;
  +            cols = pkColumns1;
           }
  -
  -        String[] cols = new String[paramCount];
  -        Object[] values = new Object[paramCount];
  -
  -        System.arraycopy(pkColumns1, 0, cols, 0, pkColumns1.length);
  -        System.arraycopy(pkValues1, 0, values, 0, pkValues1.length);
  -
  -        if (pkValues2 != null)
  +        else
           {
  +            cols = new String[pkColumns1.length + pkColumns2.length];
  +            System.arraycopy(pkColumns1, 0, cols, 0, pkColumns1.length);
               System.arraycopy(pkColumns2, 0, cols, pkColumns1.length, pkColumns2.length);
  -            System.arraycopy(pkValues2, 0, values, pkValues1.length, pkValues2.length);
           }
   
  -        sql = new SqlDeleteMNStatement(table, cols, values, logger);
  +        sql = new SqlDeleteMNStatement(table, cols, logger);
           result = sql.getStatement();
   
           logger.debug("SQL: " + result);
  @@ -559,4 +539,4 @@
           return result;
       }
   
  -}
  \ No newline at end of file
  +}
  
  
  
  1.5       +27 -35    jakarta-ojb/src/java/org/apache/ojb/broker/accesslayer/sql/SqlInsertMNStatement.java
  
  Index: SqlInsertMNStatement.java
  ===================================================================
  RCS file: /home/cvs/jakarta-ojb/src/java/org/apache/ojb/broker/accesslayer/sql/SqlInsertMNStatement.java,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- SqlInsertMNStatement.java	12 Dec 2002 22:57:36 -0000	1.4
  +++ SqlInsertMNStatement.java	19 Jan 2003 17:20:16 -0000	1.5
  @@ -57,57 +57,50 @@
   import org.apache.ojb.broker.util.logging.Logger;
   
   /**
  - * Model an INSERT Statement for M:N indirection table 
  - * 
  + * Model an INSERT Statement for M:N indirection table
  + *
    * @author <a href="mailto:jbraeuchi@hotmail.com">Jakob Braeuchi</a>
    * @version $Id$
    */
   public class SqlInsertMNStatement extends SqlMNStatement
   {
   
  -	/**
  -	 * Constructor for SqlInsertMNStatement.
  -	 * @param table
  -	 * @param columns
  -	 */
  -	public SqlInsertMNStatement(String table, String[] columns, Object[] values, Logger logger)
  -	{
  -		super (table, columns, values, logger);
  -	}
  +    /**
  +     * Constructor for SqlInsertMNStatement.
  +     * @param table
  +     * @param columns
  +     */
  +    public SqlInsertMNStatement(String table, String[] columns, Logger logger)
  +    {
  +        super (table, columns, logger);
  +    }
   
       /**
        * generates a values(?,) for a prepared insert statement.
  -     * returns null if there are no fields
        * @param stmt the StringBuffer
        */
       private void appendListOfValues(StringBuffer stmt)
       {
  - 		Object[] values = getValues();
  - 		Object val;
  - 		
  -        stmt.append(" VALUES ( ");
  -        for (int i = 0; i < values.length; i++)
  -        {
  -        	val = values[i];
  -        	if (!(val instanceof Number))
  -			{
  -                val = "'" + val + "'";
  -			}
  +        int cnt = getColumns().length;
  +
  +        stmt.append(" VALUES (");
   
  +        for (int i = 0; i < cnt; i++)
  +        {
               if (i > 0)
               {
  -                stmt.append(",");
  +                stmt.append(',');
               }
  -            stmt.append(val);
  +            stmt.append('?');
           }
  -        stmt.append(" ) ");
  +        stmt.append(')');
       }
   
  -	/**
  -	 * @see org.apache.ojb.broker.accesslayer.SqlStatement#getStatement()
  -	 */
  -	public String getStatement()
  -	{
  +    /**
  +     * @see org.apache.ojb.broker.accesslayer.SqlStatement#getStatement()
  +     */
  +    public String getStatement()
  +    {
           StringBuffer stmt = new StringBuffer(1024);
   
           stmt.append("INSERT INTO ");
  @@ -116,9 +109,8 @@
           appendListOfColumns(getColumns(),stmt);
           stmt.append(")");
           appendListOfValues(stmt);
  -        
  -        return stmt.toString();      
  -	}
  +        return stmt.toString();
  +    }
   
   }
   
  
  
  
  1.5       +83 -163   jakarta-ojb/src/java/org/apache/ojb/broker/accesslayer/sql/SqlMNStatement.java
  
  Index: SqlMNStatement.java
  ===================================================================
  RCS file: /home/cvs/jakarta-ojb/src/java/org/apache/ojb/broker/accesslayer/sql/SqlMNStatement.java,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- SqlMNStatement.java	12 Dec 2002 22:57:36 -0000	1.4
  +++ SqlMNStatement.java	19 Jan 2003 17:20:16 -0000	1.5
  @@ -60,10 +60,10 @@
    * information on the Apache Software Foundation, please see
    * <http://www.apache.org/>.
    */
  - 
  +
   /**
    * Model a MN-Statement based on Table, Columns and Values
  - * 
  + *
    * @author <a href="mailto:jbraeuchi@hotmail.com">Jakob Braeuchi</a>
    * @version $Id$
    */
  @@ -71,21 +71,19 @@
   {
       private String m_table;
       private String[] m_columns;
  -    private Object[] m_values;
  - 	private Logger m_logger;
  -  
  -
  -	/**
  -	 * Constructor for SqlMNStatement.
  -	 */
  -	public SqlMNStatement(String table, String[] columns, Object[] values, Logger logger)
  -	{
  -		super();
  +    private Logger m_logger;
  +
  +
  +    /**
  +     * Constructor for SqlMNStatement.
  +     */
  +    public SqlMNStatement(String table, String[] columns, Logger logger)
  +    {
  +        super();
           this.m_table = table;
           this.m_columns = columns;
  -        this.m_values = values;
           this.m_logger = logger;
  -	}
  +    }
   
       /**
        * append table name
  @@ -94,154 +92,76 @@
       {
           stmt.append(table);
       }
  -    
  -	/**
  -	 * Returns the columns.
  -	 * @return String[]
  -	 */
  -	protected String[] getColumns()
  -	{
  -		return m_columns;
  -	}
  -
  -	/**
  -	 * Returns the table.
  -	 * @return String
  -	 */
  -	protected String getTable()
  -	{
  -		return m_table;
  -	}
  -
  -	/**
  -	 * Returns the values.
  -	 * @return Object[]
  -	 */
  -	protected Object[] getValues()
  -	{
  -		return m_values;
  -	}
  -
  -	/**
  -	 * Returns the logger.
  -	 * @return Logger
  -	 */
  -	protected Logger getLogger()
  -	{
  -		return m_logger;
  -	}
  -
  -	/**
  -	 * applies single quotes to DATE, TIME, CHAR, or STRING columns
  -	 */
  -	protected static String quoteIfNeeded(String str, String dbtype)
  -	{
  -		String[] quotables = { "DATE", "TIME", "CHAR", "STRING" };
  -		boolean test = false;
  -		for (int i = 0; i < quotables.length; i++)
  -		{
  -			if (dbtype.startsWith(quotables[i]))
  -			{
  -				test = true;
  -				break;
  -			}
  -		}
  -		if (test)
  -		{
  -			str = escapeSingleQuotes(str);
  -			return "'" + str + "'";
  -		}
  -		else
  -		{
  -			return str;
  -		}
  -	}
  -
  -	/**
  -	 * replace single quotes (') by an escape sequence (\')
  -	 *
  -	 */
  -	private static String escapeSingleQuotes(String str)
  -	{
  -		String result = str;
  -		if (str.indexOf("'") != -1)
  -		{
  -			StringBuffer buf = new StringBuffer();
  -			char c;
  -			for (int i = 0; i < str.length(); i++)
  -			{
  -				c = str.charAt(i);
  -				if (c == '\'')
  -				{
  -					buf.append("\\'");
  -				}
  -				else
  -				{
  -					buf.append(c);
  -				}
  -			}
  -			result = buf.toString();
  -		}
  -		return result;
  -	}
  -
  -	/**
  -	 * Generate a sql where-clause matching the contraints defined by the vector of
  -	 * Values given for the vector of fields
  -	 *
  -	 * @param vecFields vector containing all columns used in WHERE clause
  -	 * @param vecValues vector containing the Values for the above columns,
  -	 *          if vecValues == null, a prepared Statement clause is generated
  -	 */
  -	protected void appendWhereClause(Object[] values, StringBuffer stmt, Object[] columns)
  -	{
  -		stmt.append(" WHERE ");
  -	
  -		for (int i = 0; i < columns.length; i++)
  -		{
  -			Class c = values[i].getClass();
  -			String ct = "noquote";
  -			if (c == String.class || c == char.class || c == Date.class || c == Time.class)
  -			{
  -				ct = "STRING";
  -			}
  -	
  -			Object val = SqlMNStatement.quoteIfNeeded(values[i].toString(), ct);
  -	
  -			if (i > 0)
  -			{
  -				stmt.append(" AND ");
  -			}
  -			stmt.append("(");
  -			stmt.append(columns[i]);
  -			stmt.append(" = ");
  -			stmt.append(val);
  -			stmt.append(")");
  -		}
  -	}
  -
  -	/**
  -	 * 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
  -	 */
  -	protected List appendListOfColumns(String[] columns, StringBuffer stmt)
  -	{
  -	    ArrayList columnList = new ArrayList();
  -	
  -	    for (int i = 0; i < columns.length; i++)
  -	    {
  -	        if (i > 0)
  -	        {
  -	            stmt.append(",");
  -	        }
  -	        stmt.append(columns[i]);
  -	        columnList.add(columns[i]);
  -	    }
  -	    return columnList;
  -	
  -	}    
  +
  +    /**
  +     * Returns the columns.
  +     * @return String[]
  +     */
  +    protected String[] getColumns()
  +    {
  +        return m_columns;
  +    }
  +
  +    /**
  +     * Returns the table.
  +     * @return String
  +     */
  +    protected String getTable()
  +    {
  +        return m_table;
  +    }
  +
  +    /**
  +     * Returns the logger.
  +     * @return Logger
  +     */
  +    protected Logger getLogger()
  +    {
  +        return m_logger;
  +    }
  +
  +    /**
  +     * Generate a sql where-clause matching the contraints defined by the array of fields
  +     *
  +     * @param columns array containing all columns used in WHERE clause
  +     */
  +    protected void appendWhereClause(StringBuffer stmt, Object[] columns)
  +    {
  +        stmt.append(" WHERE ");
  +
  +        for (int i = 0; i < columns.length; i++)
  +        {
  +            if (i > 0)
  +            {
  +                stmt.append(" AND ");
  +            }
  +            stmt.append(columns[i]);
  +            stmt.append("=?");
  +        }
  +    }
  +
  +    /**
  +    * 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
  +    */
  +    protected List appendListOfColumns(String[] columns, StringBuffer stmt)
  +    {
  +        ArrayList columnList = new ArrayList();
  +
  +        for (int i = 0; i < columns.length; i++)
  +        {
  +            if (i > 0)
  +            {
  +                stmt.append(",");
  +            }
  +            stmt.append(columns[i]);
  +            columnList.add(columns[i]);
  +        }
  +        return columnList;
  +
  +    }
   
   
   }
  
  
  
  1.3       +23 -23    jakarta-ojb/src/java/org/apache/ojb/broker/accesslayer/sql/SqlSelectMNStatement.java
  
  Index: SqlSelectMNStatement.java
  ===================================================================
  RCS file: /home/cvs/jakarta-ojb/src/java/org/apache/ojb/broker/accesslayer/sql/SqlSelectMNStatement.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- SqlSelectMNStatement.java	12 Dec 2002 22:57:35 -0000	1.2
  +++ SqlSelectMNStatement.java	19 Jan 2003 17:20:16 -0000	1.3
  @@ -57,8 +57,8 @@
   import org.apache.ojb.broker.util.logging.Logger;
   
   /**
  - * Model a SELECT Statement for M:N indirection table 
  - * 
  + * Model a SELECT Statement for M:N indirection table
  + *
    * @author <a href="mailto:jbraeuchi@hotmail.com">Jakob Braeuchi</a>
    * @version $Id$
    */
  @@ -66,31 +66,31 @@
   {
       private String[] m_selectColumns;
   
  -	/**
  -	 * Constructor for SqlSelectMNStatement.
  -	 * @param table
  -	 * @param columns
  -	 */
  -	public SqlSelectMNStatement(String table, String[] selectColumns, String[] columns, Object[] values, Logger logger)
  -	{
  -		super(table, columns, values, logger);
  +    /**
  +     * Constructor for SqlSelectMNStatement.
  +     * @param table
  +     * @param columns
  +     */
  +    public SqlSelectMNStatement(String table, String[] selectColumns, String[] columns, Logger logger)
  +    {
  +        super(table, columns, logger);
           m_selectColumns = selectColumns;
  -	}
  +    }
   
  -	/**
  -	 * @see org.apache.ojb.broker.accesslayer.SqlStatement#getStatement()
  -	 */
  -	public String getStatement()
  -	{
  -		StringBuffer stmt = new StringBuffer(1024);
  +    /**
  +     * @see org.apache.ojb.broker.accesslayer.SqlStatement#getStatement()
  +     */
  +    public String getStatement()
  +    {
  +        StringBuffer stmt = new StringBuffer(1024);
   
  -		stmt.append("SELECT ");
  +        stmt.append("SELECT ");
           appendListOfColumns(m_selectColumns,stmt);
           stmt.append(" FROM ");
  -		appendTable(getTable(), stmt);
  -		appendWhereClause(getValues(), stmt, getColumns());
  +        appendTable(getTable(), stmt);
  +        appendWhereClause(stmt, getColumns());
   
  -		return stmt.toString();
  -	}
  +        return stmt.toString();
  +    }
   
   }
  
  
  
  1.16      +153 -137  jakarta-ojb/src/java/org/apache/ojb/broker/metadata/CollectionDescriptor.java
  
  Index: CollectionDescriptor.java
  ===================================================================
  RCS file: /home/cvs/jakarta-ojb/src/java/org/apache/ojb/broker/metadata/CollectionDescriptor.java,v
  retrieving revision 1.15
  retrieving revision 1.16
  diff -u -r1.15 -r1.16
  --- CollectionDescriptor.java	2 Jan 2003 21:27:19 -0000	1.15
  +++ CollectionDescriptor.java	19 Jan 2003 17:20:16 -0000	1.16
  @@ -89,34 +89,42 @@
       private String indirectionTable = null;
       private Vector fksToItemClass = null;
       private Vector fksToThisClass = null;
  +    private String[] fksToItemClassAry;
  +    private String[] fksToThisClassAry;
   //    /**
   //     * define the order of the resulting collection BRJ
   //     */
   //    private String orderBy;
  -//	private boolean ascending = true;
  +//    private boolean ascending = true;
       /**
        * define loading strategy of the resulting collection BRJ
        */
  -	private boolean lazy = false;
  +    private boolean lazy = false;
   
       /**
        * if true relationship is refreshed when owner is found in cache
        */
  -	private boolean refresh = false;
  +    private boolean refresh = false;
   
       public CollectionDescriptor(ClassDescriptor descriptor)
       {
           super(descriptor);
       }
   
  -    public Object[] getFksToThisClass()
  +    public String[] getFksToThisClass()
       {
  -        return fksToThisClass.toArray();
  +        if (fksToThisClassAry == null)
  +        {
  +            fksToThisClassAry = (String[]) fksToThisClass.toArray(
  +                    new String[fksToThisClass.size()]);
  +        }
  +        return fksToThisClassAry;
       }
   
       public void setFksToThisClass(Vector fksToThisClass)
       {
           this.fksToThisClass = fksToThisClass;
  +        fksToThisClassAry = null;
       }
   
       /**
  @@ -124,11 +132,12 @@
        */
       public void addFkToThisClass(String column)
       {
  -      	if (fksToThisClass == null)
  -      	{
  -      	 	fksToThisClass = new Vector();
  -      	}
  -      	fksToThisClass.add(column);
  +        if (fksToThisClass == null)
  +        {
  +            fksToThisClass = new Vector();
  +        }
  +        fksToThisClass.add(column);
  +        fksToThisClassAry = null;
       }
   
       /**
  @@ -136,11 +145,12 @@
        */
       public void addFkToItemClass(String column)
       {
  -      	if (fksToItemClass == null)
  -      	{
  -      	 	fksToItemClass = new Vector();
  -      	}
  -      	fksToItemClass.add(column);
  +        if (fksToItemClass == null)
  +        {
  +            fksToItemClass = new Vector();
  +        }
  +        fksToItemClass.add(column);
  +        fksToItemClassAry = null;
       }
   
       /**
  @@ -179,14 +189,20 @@
           this.indirectionTable = indirectionTable;
       }
   
  -    public Object[] getFksToItemClass()
  +    public String[] getFksToItemClass()
       {
  -        return fksToItemClass.toArray();
  +        if (fksToItemClassAry == null)
  +        {
  +            fksToItemClassAry = (String[]) fksToItemClass.toArray(
  +                    new String[fksToItemClass.size()]);
  +        }
  +        return fksToItemClassAry;
       }
   
       public void setFksToItemClass(Vector fksToItemClass)
       {
           this.fksToItemClass = fksToItemClass;
  +        fksToItemClassAry = null;
       }
   
       public boolean isMtoNRelation()
  @@ -216,41 +232,41 @@
           return m_orderby;
       }
   
  -	/**
  -	 * returns true if this is a lazy Collection.
  -	 * @return Returns a boolean
  -	 */
  -	public boolean isLazy()
  -	{
  -		return lazy;
  -	}
  -
  -	/**
  -	 * Sets the lazy flag.
  -	 * @param boolean lazy The value to set
  -	 */
  -	public void setLazy(boolean lazy)
  -	{
  -		this.lazy = lazy;
  -	}
  -
  -	/**
  -	 * Gets the refresh.
  -	 * @return Returns a boolean
  -	 */
  -	public boolean isRefresh()
  -	{
  -		return refresh;
  -	}
  -
  -	/**
  -	 * Sets the refresh.
  -	 * @param refresh The refresh to set
  -	 */
  -	public void setRefresh(boolean refresh)
  -	{
  -		this.refresh = refresh;
  -	}
  +    /**
  +     * returns true if this is a lazy Collection.
  +     * @return Returns a boolean
  +     */
  +    public boolean isLazy()
  +    {
  +        return lazy;
  +    }
  +
  +    /**
  +     * Sets the lazy flag.
  +     * @param boolean lazy The value to set
  +     */
  +    public void setLazy(boolean lazy)
  +    {
  +        this.lazy = lazy;
  +    }
  +
  +    /**
  +     * Gets the refresh.
  +     * @return Returns a boolean
  +     */
  +    public boolean isRefresh()
  +    {
  +        return refresh;
  +    }
  +
  +    /**
  +     * Sets the refresh.
  +     * @param refresh The refresh to set
  +     */
  +    public void setRefresh(boolean refresh)
  +    {
  +        this.refresh = refresh;
  +    }
   
       /*
        * @see XmlCapable#toXML()
  @@ -261,101 +277,101 @@
           String eol = SystemUtils.LINE_SEPARATOR;
   
           // write opening tag
  -		String result = "      " + tags.getOpeningTagNonClosingById(COLLECTION_DESCRIPTOR) + eol;
  +        String result = "      " + tags.getOpeningTagNonClosingById(COLLECTION_DESCRIPTOR) + eol;
   
  -		// write attributes
  -		// name
  -		result       += "        " + tags.getAttribute(FIELD_NAME,this.getAttributeName()) + eol;
  -
  -		// collection class is optional
  -		if (getCollectionClassName() != null)
  -		{
  -			result       += "        " + tags.getAttribute(COLLECTION_CLASS,this.getCollectionClassName()) + eol;
  -		}
  -
  -		// element-class-ref
  - 		result       += "        " + tags.getAttribute(ITEMS_CLASS,this.getItemClassName()) + eol;
  -
  -		// indirection-table is optional
  -		if (isMtoNRelation())
  -		{
  -		 	result += "        " + tags.getAttribute(INDIRECTION_TABLE,getIndirectionTable()) + eol;
  -		}
  -
  -		// proxyReference is optional, disabled by default
  -		if (isLazy())
  -		{
  -			result       += "        " + tags.getAttribute(PROXY_REFERENCE,"true") + eol;
  -		}
  -
  -		//reference refresh is optional, disabled by default
  -		if (isRefresh())
  -		{
  -		 	result       += "        " + tags.getAttribute(REFRESH_REFERENCE,"true") + eol;
  -		}
  -
  -		//auto retrieve is optional, enabled by default
  -		if (!getCascadeRetrieve())
  -		{
  -		 	result       += "        " + tags.getAttribute(AUTO_RETRIEVE,"false") + eol;
  -		}
  -
  -		//auto update is optional, disabled by default
  -		if (getCascadeStore())
  -		{
  -		 	result       += "        " + tags.getAttribute(AUTO_UPDATE,"true") + eol;
  -		}
  -
  -		//auto delete is optional, disabled by default
  -		if (getCascadeDelete())
  -		{
  -		 	result       += "        " + tags.getAttribute(AUTO_DELETE,"true") + eol;
  -		}
  +        // write attributes
  +        // name
  +        result       += "        " + tags.getAttribute(FIELD_NAME,this.getAttributeName()) + eol;
   
  -		// close opening tag
  -		result       += "      >" + eol;
  +        // collection class is optional
  +        if (getCollectionClassName() != null)
  +        {
  +            result       += "        " + tags.getAttribute(COLLECTION_CLASS,this.getCollectionClassName()) + eol;
  +        }
  +
  +        // element-class-ref
  +         result       += "        " + tags.getAttribute(ITEMS_CLASS,this.getItemClassName()) + eol;
  +
  +        // indirection-table is optional
  +        if (isMtoNRelation())
  +        {
  +             result += "        " + tags.getAttribute(INDIRECTION_TABLE,getIndirectionTable()) + eol;
  +        }
  +
  +        // proxyReference is optional, disabled by default
  +        if (isLazy())
  +        {
  +            result       += "        " + tags.getAttribute(PROXY_REFERENCE,"true") + eol;
  +        }
  +
  +        //reference refresh is optional, disabled by default
  +        if (isRefresh())
  +        {
  +             result       += "        " + tags.getAttribute(REFRESH_REFERENCE,"true") + eol;
  +        }
  +
  +        //auto retrieve is optional, enabled by default
  +        if (!getCascadeRetrieve())
  +        {
  +             result       += "        " + tags.getAttribute(AUTO_RETRIEVE,"false") + eol;
  +        }
   
  -		// write elements
  - 		// inverse fk elements
  +        //auto update is optional, disabled by default
  +        if (getCascadeStore())
  +        {
  +             result       += "        " + tags.getAttribute(AUTO_UPDATE,"true") + eol;
  +        }
  +
  +        //auto delete is optional, disabled by default
  +        if (getCascadeDelete())
  +        {
  +             result       += "        " + tags.getAttribute(AUTO_DELETE,"true") + eol;
  +        }
  +
  +        // close opening tag
  +        result       += "      >" + eol;
  +
  +        // write elements
  +         // inverse fk elements
           for (int i=0;i<getForeignKeyFields().size();i++)
           {
  -	    Object obj = getForeignKeyFields().get(i);
  -	    if (obj instanceof Integer)
  -	    {
  +        Object obj = getForeignKeyFields().get(i);
  +        if (obj instanceof Integer)
  +        {
                   String fkId = obj.toString();
  -	        result += "        " + tags.getOpeningTagNonClosingById(INVERSE_FK) + " ";
  -    	        result += tags.getAttribute(FIELD_ID_REF, fkId) + "/>" + eol;
  -	    }
  -	    else
  -	    {
  +            result += "        " + tags.getOpeningTagNonClosingById(INVERSE_FK) + " ";
  +                result += tags.getAttribute(FIELD_ID_REF, fkId) + "/>" + eol;
  +        }
  +        else
  +        {
                   String fk = (String) obj;
  -	        result += "        " + tags.getOpeningTagNonClosingById(INVERSE_FK) + " ";
  -    	        result += tags.getAttribute(FIELD_REF, fk) + "/>" + eol;
  -	    }
  +            result += "        " + tags.getOpeningTagNonClosingById(INVERSE_FK) + " ";
  +                result += tags.getAttribute(FIELD_REF, fk) + "/>" + eol;
  +        }
           }
   
           // write optional M:N elements
  -		// m:n relationship settings, optional
  -		if (isMtoNRelation())
  -		{
  -			// foreign keys to this class
  - 			for (int i=0;i<getFksToThisClass().length;i++)
  - 			{
  -	            String fkId = getFksToThisClass()[i].toString();
  -	            result += "        " + tags.getOpeningTagNonClosingById(FK_POINTING_TO_THIS_CLASS) + " ";
  -	            result += tags.getAttribute(COLUMN_NAME, fkId) + "/>" + eol;
  - 			}
  -
  -			// foreign keys to item class
  - 			for (int i=0;i<getFksToItemClass().length;i++)
  - 			{
  -	            String fkId = getFksToItemClass()[i].toString();
  -	            result += "        " + tags.getOpeningTagNonClosingById(FK_POINTING_TO_ITEMS_CLASS) + " ";
  -	            result += tags.getAttribute(COLUMN_NAME, fkId) + "/>" + eol;
  - 			}
  -		}
  +        // m:n relationship settings, optional
  +        if (isMtoNRelation())
  +        {
  +            // foreign keys to this class
  +             for (int i=0;i<getFksToThisClass().length;i++)
  +             {
  +                String fkId = getFksToThisClass()[i].toString();
  +                result += "        " + tags.getOpeningTagNonClosingById(FK_POINTING_TO_THIS_CLASS) + " ";
  +                result += tags.getAttribute(COLUMN_NAME, fkId) + "/>" + eol;
  +             }
  +
  +            // foreign keys to item class
  +             for (int i=0;i<getFksToItemClass().length;i++)
  +             {
  +                String fkId = getFksToItemClass()[i].toString();
  +                result += "        " + tags.getOpeningTagNonClosingById(FK_POINTING_TO_ITEMS_CLASS) + " ";
  +                result += tags.getAttribute(COLUMN_NAME, fkId) + "/>" + eol;
  +             }
  +        }
   
  -		// closing tag
  +        // closing tag
           result       += "      " + tags.getClosingTagById(COLLECTION_DESCRIPTOR) + eol;
           return result;
       }
  
  
  
  1.115     +16 -18    jakarta-ojb/src/java/org/apache/ojb/broker/singlevm/PersistenceBrokerImpl.java
  
  Index: PersistenceBrokerImpl.java
  ===================================================================
  RCS file: /home/cvs/jakarta-ojb/src/java/org/apache/ojb/broker/singlevm/PersistenceBrokerImpl.java,v
  retrieving revision 1.114
  retrieving revision 1.115
  diff -u -r1.114 -r1.115
  --- PersistenceBrokerImpl.java	19 Jan 2003 11:51:24 -0000	1.114
  +++ PersistenceBrokerImpl.java	19 Jan 2003 17:20:16 -0000	1.115
  @@ -813,10 +813,10 @@
           otherObj = ProxyHelper.getRealObject(otherObj);
           ClassDescriptor cld = getDescriptorRepository().getDescriptorFor(obj.getClass());
           Object[] pkValues = brokerHelper.getKeyValues(cld, obj);
  -        Object[] pkColumns = cod.getFksToThisClass();
  +        String[] pkColumns = cod.getFksToThisClass();
           ClassDescriptor otherCld = getDescriptorRepository().getDescriptorFor(otherObj.getClass());
           Object[] otherPkValues = brokerHelper.getKeyValues(otherCld, otherObj);
  -        Object[] otherPkColumns = cod.getFksToItemClass();
  +        String[] otherPkColumns = cod.getFksToItemClass();
           String table = cod.getIndirectionTable();
           Key key = new Key(otherPkValues);
   
  @@ -825,9 +825,8 @@
               return;
           }
   
  -        String insertStmt = sqlGenerator.getInsertStatement(
  -                table, pkColumns, pkValues ,otherPkColumns ,otherPkValues);
  -        dbAccess.executeUpdateSQL(insertStmt, cld);
  +        String insertStmt = sqlGenerator.getInsertMNStatement(table, pkColumns, otherPkColumns);
  +        dbAccess.executeUpdateSQL(insertStmt, cld, pkValues, otherPkValues);
       }
   
       /**
  @@ -842,14 +841,14 @@
           List result = new ArrayList();
           ClassDescriptor cld = getDescriptorRepository().getDescriptorFor(obj.getClass());
           Object[] pkValues = brokerHelper.getKeyValues(cld, obj);
  -        Object[] pkColumns = cod.getFksToThisClass();
  -        Object[] fkColumns = cod.getFksToItemClass();
  +        String[] pkColumns = cod.getFksToThisClass();
  +        String[] fkColumns = cod.getFksToItemClass();
           String table = cod.getIndirectionTable();
  -        String selectStmt = sqlGenerator.getSelectStatement(table, fkColumns, pkColumns, pkValues);
  +        String selectStmt = sqlGenerator.getSelectMNStatement(table, fkColumns, pkColumns);
   
           try
           {
  -            rs = dbAccess.executeSQL(selectStmt, cld);
  +            rs = dbAccess.executeSQL(selectStmt, cld, pkValues);
               while (rs.m_rs.next())
               {
                   Object[] row = new Object[fkColumns.length];
  @@ -879,10 +878,10 @@
       {
           ClassDescriptor cld = getDescriptorRepository().getDescriptorFor(obj.getClass());
           Object[] pkValues = brokerHelper.getKeyValues(cld, obj);
  -        Object[] pkColumns = cod.getFksToThisClass();
  +        String[] pkColumns = cod.getFksToThisClass();
           String table = cod.getIndirectionTable();
  -        String deleteStmt = sqlGenerator.getDeleteStatement(table, pkColumns, pkValues, null ,null);
  -        dbAccess.executeUpdateSQL(deleteStmt, cld);
  +        String deleteStmt = sqlGenerator.getDeleteMNStatement(table, pkColumns, null);
  +        dbAccess.executeUpdateSQL(deleteStmt, cld, pkValues, null);
       }
   
       /**
  @@ -918,9 +917,9 @@
           // delete all remaining keys in workList
           ClassDescriptor cld = getDescriptorRepository().getDescriptorFor(obj.getClass());
           Object[] pkValues = brokerHelper.getKeyValues(cld, obj);
  -        Object[] pkColumns = cod.getFksToThisClass();
  +        String[] pkColumns = cod.getFksToThisClass();
           Object[] fkValues;
  -        Object[] fkColumns = cod.getFksToItemClass();
  +        String[] fkColumns = cod.getFksToItemClass();
           String table = cod.getIndirectionTable();
           String deleteStmt;
   
  @@ -928,8 +927,8 @@
           while (iter.hasNext())
           {
               fkValues = ((Key)iter.next()).m_key;
  -            deleteStmt = sqlGenerator.getDeleteStatement(table, pkColumns, pkValues, fkColumns, fkValues);
  -            dbAccess.executeUpdateSQL(deleteStmt, cld);
  +            deleteStmt = sqlGenerator.getDeleteMNStatement(table, pkColumns, fkColumns);
  +            dbAccess.executeUpdateSQL(deleteStmt, cld, pkValues, fkValues);
           }
       }
   
  @@ -1240,7 +1239,6 @@
               }
               int numberOfObjectsToFetch = endAt - startAt;
               int retrievedCount = 0;
  -            boolean hasProjectionAttribute = true;
               /**
                * keep retrieving objects while retrievedCount is less than the retrievalCount, or the
                * retrievalCount is -1 meaning get all results.
  
  
  
  1.5       +64 -1     jakarta-ojb/src/java/org/apache/ojb/broker/util/SqlHelper.java
  
  Index: SqlHelper.java
  ===================================================================
  RCS file: /home/cvs/jakarta-ojb/src/java/org/apache/ojb/broker/util/SqlHelper.java,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- SqlHelper.java	15 Jan 2003 10:43:30 -0000	1.4
  +++ SqlHelper.java	19 Jan 2003 17:20:17 -0000	1.5
  @@ -494,4 +494,67 @@
           FieldDescriptor fld = cld.getLockingFields()[index];
           return fld.getColumnJdbcType();
       }
  +
  +    /**
  +     * @return SQL type for the given value, Types.OTHER if not found.
  +     */
  +     public static int getSqlTypeByValue(Object value)
  +     {
  +        if (value instanceof Integer)
  +        {
  +            return Types.INTEGER;
  +        }
  +        else if (value instanceof java.math.BigDecimal)
  +        {
  +            return Types.NUMERIC;
  +        }
  +        else if (value instanceof String)
  +        {
  +            return Types.VARCHAR;
  +        }
  +        else if (value instanceof Byte)
  +        {
  +            return Types.TINYINT;
  +        }
  +        else if (value instanceof Short)
  +        {
  +            return Types.SMALLINT;
  +        }
  +        else if (value instanceof Long)
  +        {
  +            return Types.BIGINT;
  +        }
  +        else if (value instanceof Float)
  +        {
  +            return Types.REAL;
  +        }
  +        else if (value instanceof Double)
  +        {
  +            return Types.DOUBLE;
  +        }
  +        else if (value instanceof byte[])
  +        {
  +            return Types.VARBINARY;
  +        }
  +        else if (value instanceof java.sql.Date)
  +        {
  +            return Types.DATE;
  +        }
  +        else if (value instanceof java.sql.Time)
  +        {
  +            return Types.TIME;
  +        }
  +        else if (value instanceof java.sql.Timestamp)
  +        {
  +            return Types.TIMESTAMP;
  +        }
  +        else if (value instanceof Boolean)
  +        {
  +            return Types.BIT;
  +        }
  +        else
  +        {
  +            return Types.OTHER;
  +        }
  +     }
   }
  
  
  

Mime
View raw message