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 SqlPkStatement.java SqlQueryStatement.java SqlInsertStatement.java SqlSelectStatement.java SqlSelectByPkStatement.java TableAliasHandler.java SqlExistStatement.java
Date Wed, 13 Oct 2004 20:06:17 GMT
brj         2004/10/13 13:06:17

  Modified:    src/java/org/apache/ojb/broker/accesslayer/sql
                        SqlPkStatement.java SqlQueryStatement.java
                        SqlInsertStatement.java SqlSelectStatement.java
                        SqlSelectByPkStatement.java TableAliasHandler.java
                        SqlExistStatement.java
  Log:
  refactorings to prepare implementation of quoting for table and columns
  
  Revision  Changes    Path
  1.6       +11 -3     db-ojb/src/java/org/apache/ojb/broker/accesslayer/sql/SqlPkStatement.java
  
  Index: SqlPkStatement.java
  ===================================================================
  RCS file: /home/cvs/db-ojb/src/java/org/apache/ojb/broker/accesslayer/sql/SqlPkStatement.java,v
  retrieving revision 1.5
  retrieving revision 1.6
  diff -u -r1.5 -r1.6
  --- SqlPkStatement.java	4 Apr 2004 23:53:32 -0000	1.5
  +++ SqlPkStatement.java	13 Oct 2004 20:06:17 -0000	1.6
  @@ -49,6 +49,14 @@
           stmt.append(cld.getFullTableName());
       }
   
  +    /**
  +     * append field name
  +     */
  +    protected void appendField(FieldDescriptor fld, StringBuffer stmt)
  +    {
  +        stmt.append(fld.getColumnName());
  +    }
  +    
   	/**
   	 * Returns the logger.
   	 * @return Logger
  @@ -78,9 +86,9 @@
   
   		for (int i = 0; i < fields.length; i++)
   		{
  -			FieldDescriptor fmd = fields[i];
  +			FieldDescriptor fld = fields[i];
   
  -			stmt.append(fmd.getColumnName());
  +			appendField(fld, stmt);
   			stmt.append(" = ? ");
   			if (i < fields.length - 1)
   			{
  
  
  
  1.88      +53 -15    db-ojb/src/java/org/apache/ojb/broker/accesslayer/sql/SqlQueryStatement.java
  
  Index: SqlQueryStatement.java
  ===================================================================
  RCS file: /home/cvs/db-ojb/src/java/org/apache/ojb/broker/accesslayer/sql/SqlQueryStatement.java,v
  retrieving revision 1.87
  retrieving revision 1.88
  diff -u -r1.87 -r1.88
  --- SqlQueryStatement.java	10 Oct 2004 15:15:22 -0000	1.87
  +++ SqlQueryStatement.java	13 Oct 2004 20:06:17 -0000	1.88
  @@ -276,7 +276,7 @@
               buf.append(prefix);
           }
   
  -        buf.append(colName);
  +        appendColumn(colName, buf);
   
           if (suffix != null) // rebuild function
           {
  @@ -1093,6 +1093,47 @@
       }
   
       /**
  +     * Append a Column.
  +     * @param aColumn
  +     * @param buf
  +     */
  +    protected void appendColumn(String aColumn, StringBuffer buf)
  +    {
  +        //TODO quote column if necessary
  +        
  +        buf.append(aColumn);
  +    }
  +
  +    /**
  +     * Append a Column with alias: A0 name -> A0.name.
  +     * @param tableOrAlias A0
  +     * @param aColumn name
  +     * @param buf
  +     */
  +    protected void appendColumn(String tableOrAlias, String aColumn, StringBuffer buf)
  +    {
  +        //TODO quote column if necessary
  +        
  +        buf.append(tableOrAlias)
  +        	.append(".")
  +        	.append(aColumn);
  +    }
  +    
  +    /**
  +     * Append the TableAlias.
  +     * @param anAlias
  +     * @param buf
  +     */
  +    private void appendTableAlias(TableAliasHandler.TableAlias anAlias, StringBuffer buf)
  +    {
  +        //TODO quote table if necessary
  +        
  +        buf.append(anAlias.table)
  +        	.append(" ")
  +        	.append(anAlias.alias);
  +    }
  +    
  +    /**
        * Appends to the statement table and all tables joined to it.
        * @param alias the table alias
        * @param where append conditions for WHERE clause here
  @@ -1109,7 +1150,7 @@
   
           if (!(joinSyntax == SQL92_NOPAREN_JOIN_SYNTAX && alias != getRootAlias()))
           {
  -            buf.append(alias.getTableAndAlias());
  +            appendTableAlias(alias, buf);
   
               if (getQuery() instanceof MtoNQuery)
               {
  @@ -1159,7 +1200,7 @@
           {
               where.append(" AND ");
           }
  -        appendJoinEqualities(where,join);
  +        appendJoinEqualities(join,where);
       }
   
       /**
  @@ -1186,7 +1227,7 @@
               appendTableWithJoins(join.right, where, buf);
           }
           buf.append(" ON ");
  -        appendJoinEqualities(buf,join);
  +        appendJoinEqualities(join,buf);
       }
   
       /**
  @@ -1203,19 +1244,19 @@
               buf.append(" INNER JOIN ");
           }
   
  -        buf.append(join.right.getTableAndAlias());
  +        appendTableAlias(join.right, buf);
           buf.append(" ON ");
  -        appendJoinEqualities(buf, join);
  +        appendJoinEqualities(join, buf);
   
           appendTableWithJoins(join.right, where, buf);
       }
   
       /**
        * Append the Join-keys
  -     * @param buf
        * @param join
  +     * @param buf
        */
  -    private void appendJoinEqualities(StringBuffer buf, Join join)
  +    private void appendJoinEqualities(Join join, StringBuffer buf)
       {
           byte joinSyntax = getJoinSyntaxType();
   
  @@ -1225,9 +1266,7 @@
               {
                   buf.append(" AND ");
               }
  -            buf.append(join.left.alias);
  -            buf.append(".");
  -            buf.append(join.leftKeys[i]);
  +            appendColumn(join.left.alias, join.leftKeys[i], buf);
   
               if (join.isOuter && joinSyntax == SYBASE_JOIN_SYNTAX)
               {
  @@ -1238,9 +1277,7 @@
                   buf.append("=");
               }
   
  -            buf.append(join.right.alias);
  -            buf.append(".");
  -            buf.append(join.rightKeys[i]);
  +            appendColumn(join.right.alias, join.rightKeys[i], buf);
   
               if (join.isOuter && joinSyntax == ORACLE_JOIN_SYNTAX)
               {
  @@ -1312,6 +1349,7 @@
           return m_logger;
       }
   
  +    
       //-----------------------------------------------------------------
       // ------------------- Inner classes ------------------------------
       //-----------------------------------------------------------------
  
  
  
  1.8       +2 -2      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.7
  retrieving revision 1.8
  diff -u -r1.7 -r1.8
  --- SqlInsertStatement.java	4 Apr 2004 23:53:32 -0000	1.7
  +++ SqlInsertStatement.java	13 Oct 2004 20:06:17 -0000	1.8
  @@ -71,7 +71,7 @@
               {
                   buf.append(",");
               }
  -            buf.append(fields[i].getColumnName());
  +            appendField(fields[i], buf);
               columnList.add(fields[i].getAttributeName());
           }
           return columnList;
  
  
  
  1.29      +4 -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.28
  retrieving revision 1.29
  diff -u -r1.28 -r1.29
  --- SqlSelectStatement.java	10 Oct 2004 09:24:57 -0000	1.28
  +++ SqlSelectStatement.java	13 Oct 2004 20:06:17 -0000	1.29
  @@ -95,9 +95,7 @@
                   {
                       buf.append(",");
                   }
  -                buf.append(getSearchTable().alias);
  -                buf.append(".");
  -                buf.append(field.getColumnName());
  +                appendColumn(getSearchTable().alias, field.getColumnName(), buf);
                   columnList.add(field.getAttributeName());
                   i++;
               }
  @@ -278,9 +276,8 @@
               {
                   buf.append(",");
               }
  -            buf.append(cldSuper.getFullTableName());
  -            buf.append(".");
  -            buf.append(field.getColumnName());
  +            
  +            appendColumn(cldSuper.getFullTableName(), field.getColumnName(), buf);
           }
   
       }
  
  
  
  1.9       +2 -2      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.8
  retrieving revision 1.9
  diff -u -r1.8 -r1.9
  --- SqlSelectByPkStatement.java	4 Apr 2004 23:53:32 -0000	1.8
  +++ SqlSelectByPkStatement.java	13 Oct 2004 20:06:17 -0000	1.9
  @@ -74,7 +74,7 @@
                   {
                       buf.append(",");
                   }
  -                buf.append(field.getColumnName());
  +                appendField(field, buf);
                   columnList.add(field.getAttributeName());
                   i++;
               }
  
  
  
  1.3       +2 -7      db-ojb/src/java/org/apache/ojb/broker/accesslayer/sql/TableAliasHandler.java
  
  Index: TableAliasHandler.java
  ===================================================================
  RCS file: /home/cvs/db-ojb/src/java/org/apache/ojb/broker/accesslayer/sql/TableAliasHandler.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- TableAliasHandler.java	10 Oct 2004 15:15:22 -0000	1.2
  +++ TableAliasHandler.java	13 Oct 2004 20:06:17 -0000	1.3
  @@ -842,11 +842,6 @@
               return cld;
           }
   
  -        String getTableAndAlias()
  -        {
  -            return table + " " + alias;
  -        }
  -
           boolean hasExtents()
           {
               return (!extents.isEmpty());
  @@ -910,7 +905,7 @@
               StringBuffer sb = new StringBuffer(1024);
               boolean first = true;
   
  -            sb.append(getTableAndAlias());
  +            sb.append(table + " " + alias);
               if (joins != null)
               {
                   sb.append(" [");
  
  
  
  1.5       +4 -3      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.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- SqlExistStatement.java	4 Apr 2004 23:53:32 -0000	1.4
  +++ SqlExistStatement.java	13 Oct 2004 20:06:17 -0000	1.5
  @@ -53,10 +53,11 @@
           FieldDescriptor field = fieldDescriptors[0];
   
           stmt.append(SELECT);
  -        stmt.append(field.getColumnName());
  +        appendField(field, stmt);
           stmt.append(FROM);
  -        stmt.append(cld.getFullTableName());
  +        appendTable(cld, stmt);
           appendWhereClause(cld, false, stmt);
  +        
           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