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 JdbcAccessImpl.java
Date Thu, 25 Nov 2004 17:31:35 GMT
brj         2004/11/25 09:31:35

  Modified:    src/java/org/apache/ojb/broker/util JdbcTypesHelper.java
               src/java/org/apache/ojb/broker/platforms
                        PlatformDefaultImpl.java PlatformMySQLImpl.java
                        PlatformMsAccessImpl.java
                        PlatformMsSQLServerImpl.java
               src/java/org/apache/ojb/broker/accesslayer/sql
                        SqlQueryStatement.java SqlDeleteByQuery.java
               src/java/org/apache/ojb/broker/accesslayer
                        JdbcAccessImpl.java
  Log:
  fixed some problems in quoting
  
  Revision  Changes    Path
  1.12      +12 -5     db-ojb/src/java/org/apache/ojb/broker/util/JdbcTypesHelper.java
  
  Index: JdbcTypesHelper.java
  ===================================================================
  RCS file: /home/cvs/db-ojb/src/java/org/apache/ojb/broker/util/JdbcTypesHelper.java,v
  retrieving revision 1.11
  retrieving revision 1.12
  diff -u -r1.11 -r1.12
  --- JdbcTypesHelper.java	24 Jun 2004 09:38:34 -0000	1.11
  +++ JdbcTypesHelper.java	25 Nov 2004 17:31:34 -0000	1.12
  @@ -23,6 +23,7 @@
   import org.apache.commons.lang.BooleanUtils;
   import org.apache.ojb.broker.OJBRuntimeException;
   import org.apache.ojb.broker.metadata.JdbcType;
  +import org.apache.ojb.broker.platforms.PlatformDefaultImpl;
   import org.apache.ojb.broker.util.sequence.SequenceManagerException;
   
   /* Copyright 2003-2004 The Apache Software Foundation
  @@ -44,6 +45,8 @@
   {
       private static Map jdbcObjectTypesFromType = new HashMap();
       private static Map jdbcObjectTypesFromName = new HashMap();
  +    private static final char OJB_QUOTE_BEGIN_CHAR = '\'';
  +    private static final char OJB_QUOTE_END_CHAR = '\'';
   
       /*
       Hold out all JdbcType in a static maps
  @@ -286,8 +289,6 @@
           {
               if (stmt != null)
               {
  -//                return columnIndex == MIN_INT
  -//                        ? readValueFromStatement(stmt, columnName) : readValueFromStatement(stmt,
columnIndex);
                   if (columnIndex == MIN_INT)
                   {
                       throw new UnsupportedOperationException("Not implemented yet");
  @@ -299,11 +300,17 @@
               }
               else
               {
  -                return columnIndex == MIN_INT
  -                        ? readValueFromResultSet(rs, columnName) : readValueFromResultSet(rs,
columnIndex);
  +                if (columnIndex == MIN_INT)
  +                {
  +                    return readValueFromResultSet(rs, PlatformDefaultImpl.stripQuotes(columnName));
  +                }
  +                else
  +                {
  +                    return readValueFromResultSet(rs, columnIndex); 
  +                }
               }
           }
  -
  +       
           public String toString()
           {
               return super.toString() + "[" + getJdbcTypeAsString(getType()) + " JDBC TYPE]";
  
  
  
  1.30      +20 -3     db-ojb/src/java/org/apache/ojb/broker/platforms/PlatformDefaultImpl.java
  
  Index: PlatformDefaultImpl.java
  ===================================================================
  RCS file: /home/cvs/db-ojb/src/java/org/apache/ojb/broker/platforms/PlatformDefaultImpl.java,v
  retrieving revision 1.29
  retrieving revision 1.30
  diff -u -r1.29 -r1.30
  --- PlatformDefaultImpl.java	22 Nov 2004 20:55:24 -0000	1.29
  +++ PlatformDefaultImpl.java	25 Nov 2004 17:31:34 -0000	1.30
  @@ -429,7 +429,7 @@
        */
       protected String getQuotedName(String aString)
       {
  -        return "\"" + aString + "\""; 
  +        return '"' + aString + '"'; 
       }
       
       /**
  @@ -438,7 +438,7 @@
        * @param aString
        * @return
        */
  -    private boolean isQuoted(String aString)
  +    private static boolean isQuoted(String aString)
       {
           if (aString != null && 
                   aString.charAt(0) == OJB_QUOTE_BEGIN_CHAR && 
  @@ -451,4 +451,21 @@
               return false;
           }
       }
  +    
  +    /**
  +     * Remove the OJB-Quotes from the String.
  +     * @param aString
  +     * @return String withou OJB-Quotes
  +     */
  +    public static String stripQuotes(String aString)
  +    {
  +        String result = aString;
  +        
  +        if (isQuoted(aString))
  +        {
  +            result = aString.substring(1, aString.length() - 1);
  +        }
  +        return result;
  +    }
  +
   }
  
  
  
  1.17      +2 -2      db-ojb/src/java/org/apache/ojb/broker/platforms/PlatformMySQLImpl.java
  
  Index: PlatformMySQLImpl.java
  ===================================================================
  RCS file: /home/cvs/db-ojb/src/java/org/apache/ojb/broker/platforms/PlatformMySQLImpl.java,v
  retrieving revision 1.16
  retrieving revision 1.17
  diff -u -r1.16 -r1.17
  --- PlatformMySQLImpl.java	22 Nov 2004 20:55:24 -0000	1.16
  +++ PlatformMySQLImpl.java	25 Nov 2004 17:31:34 -0000	1.17
  @@ -169,6 +169,6 @@
        */
       protected String getQuotedName(String aString)
       {
  -        return "`" + aString + "`"; 
  +        return '`' + aString + '`'; 
       }
   }
  
  
  
  1.13      +2 -2      db-ojb/src/java/org/apache/ojb/broker/platforms/PlatformMsAccessImpl.java
  
  Index: PlatformMsAccessImpl.java
  ===================================================================
  RCS file: /home/cvs/db-ojb/src/java/org/apache/ojb/broker/platforms/PlatformMsAccessImpl.java,v
  retrieving revision 1.12
  retrieving revision 1.13
  diff -u -r1.12 -r1.13
  --- PlatformMsAccessImpl.java	22 Nov 2004 20:55:24 -0000	1.12
  +++ PlatformMsAccessImpl.java	25 Nov 2004 17:31:34 -0000	1.13
  @@ -128,6 +128,6 @@
        */
       protected String getQuotedName(String aString)
       {
  -        return "[" + aString + "]"; 
  +        return '[' + aString + ']'; 
       }
   }
  
  
  
  1.10      +2 -2      db-ojb/src/java/org/apache/ojb/broker/platforms/PlatformMsSQLServerImpl.java
  
  Index: PlatformMsSQLServerImpl.java
  ===================================================================
  RCS file: /home/cvs/db-ojb/src/java/org/apache/ojb/broker/platforms/PlatformMsSQLServerImpl.java,v
  retrieving revision 1.9
  retrieving revision 1.10
  diff -u -r1.9 -r1.10
  --- PlatformMsSQLServerImpl.java	22 Nov 2004 20:55:24 -0000	1.9
  +++ PlatformMsSQLServerImpl.java	25 Nov 2004 17:31:34 -0000	1.10
  @@ -80,6 +80,6 @@
        */
       protected String getQuotedName(String aString)
       {
  -        return "[" + aString + "]"; 
  +        return '[' + aString + ']'; 
       }
   }
  
  
  
  1.91      +30 -12    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.90
  retrieving revision 1.91
  diff -u -r1.90 -r1.91
  --- SqlQueryStatement.java	22 Nov 2004 20:55:23 -0000	1.90
  +++ SqlQueryStatement.java	25 Nov 2004 17:31:34 -0000	1.91
  @@ -200,10 +200,10 @@
        * @param translate
        * @return
        */
  -    protected String getColName(TableAlias aTableAlias, PathInfo aPathInfo, boolean translate)
  +    protected ColumnInfo getColName(TableAlias aTableAlias, PathInfo aPathInfo, boolean
translate)
       {
           FieldDescriptor fld = null;
  -        String result = null;
  +        ColumnInfo result = new ColumnInfo();
   
           if (translate)
           {
  @@ -221,35 +221,37 @@
                           Join join = (Join) itr.next();
                           if (join.right.table.equals(fld.getClassDescriptor().getFullTableName()))
                           {
  -                            result = join.right.alias + "." + fld.getColumnName();
  +                            result.alias = join.right.alias;
  +                            result.column = fld.getColumnName();
                               break;
                           }
                       }
   
                       if (result == null)
                       {
  -                        result = aPathInfo.column;
  +                        result.column = aPathInfo.column;
                       }
                   }
                   else
                   {
  -                    result = aTableAlias.alias + "." + fld.getColumnName();
  +                    result.alias = aTableAlias.alias;
  +                    result.column = fld.getColumnName();
                   }
               }
               else if ("*".equals(aPathInfo.column))
               {
  -                result = aPathInfo.column;
  +                result.column = aPathInfo.column;
               }
               else
               {
                   // throw new IllegalArgumentException("No Field found for : " + aPathInfo.column);
  -                result = aPathInfo.column;
  +                result.column = aPathInfo.column;
               }
           }
           else
           {
               // use attribute name
  -            result = aPathInfo.column;
  +            result.column = aPathInfo.column;
           }
   
           return result;
  @@ -268,21 +270,26 @@
       {
           String prefix = aPathInfo.prefix;
           String suffix = aPathInfo.suffix;
  -        String colName = getColName(aTableAlias, aPathInfo, translate);
  +        ColumnInfo colInfo = getColName(aTableAlias, aPathInfo, translate);
   
           if (prefix != null) // rebuild function contains (
           {
               buf.append(prefix);
           }
   
  -        appendColumn(colName, buf);
  +        if (colInfo.alias != null)
  +        {
  +            buf.append(colInfo.alias);
  +            buf.append(".");
  +        }
  +        appendColumn(colInfo.column, buf);
   
           if (suffix != null) // rebuild function
           {
               buf.append(suffix);
           }
   
  -        return true;
  +        return true;  //TODO : what for ??
       }
   
       /**
  @@ -1335,4 +1342,15 @@
           TableAlias tableAlias;
           PathInfo pathInfo;
       }
  +
  +    /**
  +	 * Helper Class to return an alias and a column<br>
  +	 * ie: A0.emp_firstname
  +	 */
  +	static final class ColumnInfo
  +	{
  +		String alias;
  +		String column;
  +	}
  +
   }
  
  
  
  1.18      +6 -6      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.17
  retrieving revision 1.18
  diff -u -r1.17 -r1.18
  --- SqlDeleteByQuery.java	22 Nov 2004 20:55:23 -0000	1.17
  +++ SqlDeleteByQuery.java	25 Nov 2004 17:31:35 -0000	1.18
  @@ -61,24 +61,24 @@
   	/* (non-Javadoc)
   	 * @see org.apache.ojb.broker.accesslayer.sql.SqlQueryStatement#getColName(org.apache.ojb.broker.accesslayer.sql.SqlQueryStatement.TableAlias,
org.apache.ojb.broker.util.SqlHelper.PathInfo, boolean)
   	 */
  -	protected String getColName(TableAliasHandler.TableAlias aTableAlias, PathInfo aPathInfo,
boolean translate)
  +	protected ColumnInfo getColName(TableAliasHandler.TableAlias aTableAlias, PathInfo aPathInfo,
boolean translate)
   	{
           FieldDescriptor fld = null;
  -        String result;
  +        ColumnInfo result = new ColumnInfo();
   
           if (translate)
           {
               fld = getFieldDescriptor(aTableAlias, aPathInfo);
           }
   
  +        // BRJ : No alias for delete
           if (fld != null)
           {
  -            // BRJ : No alias for delete
  -            result = fld.getColumnName();
  +            result.column = fld.getColumnName();
           }
           else
           {
  -            result = aPathInfo.column;
  +            result.column = aPathInfo.column;
           }
   
          return result;
  
  
  
  1.27      +13 -7     db-ojb/src/java/org/apache/ojb/broker/accesslayer/JdbcAccessImpl.java
  
  Index: JdbcAccessImpl.java
  ===================================================================
  RCS file: /home/cvs/db-ojb/src/java/org/apache/ojb/broker/accesslayer/JdbcAccessImpl.java,v
  retrieving revision 1.26
  retrieving revision 1.27
  diff -u -r1.26 -r1.27
  --- JdbcAccessImpl.java	22 Nov 2004 20:55:24 -0000	1.26
  +++ JdbcAccessImpl.java	25 Nov 2004 17:31:35 -0000	1.27
  @@ -37,6 +37,7 @@
   import org.apache.ojb.broker.metadata.FieldDescriptor;
   import org.apache.ojb.broker.metadata.ProcedureDescriptor;
   import org.apache.ojb.broker.metadata.fieldaccess.PersistentField;
  +import org.apache.ojb.broker.platforms.Platform;
   import org.apache.ojb.broker.query.Query;
   import org.apache.ojb.broker.util.logging.Logger;
   import org.apache.ojb.broker.util.logging.LoggerFactory;
  @@ -80,6 +81,14 @@
       }
   
       /**
  +     * Answer the Platform.
  +     */
  +    private Platform getPlatform()
  +    {
  +        return broker.serviceConnectionManager().getSupportedPlatform();
  +    }
  +    
  +    /**
        * performs a DELETE operation against RDBMS.
        * @param cld ClassDescriptor providing mapping information.
        * @param obj The object to be deleted.
  @@ -291,8 +300,7 @@
   
               ResultSet rs = stmt.executeQuery();
   
  -            retval = new ResultSetAndStatement(
  -                    broker.serviceConnectionManager().getSupportedPlatform(), stmt, rs);
  +            retval = new ResultSetAndStatement(getPlatform(), stmt, rs);
               return retval;
           }
           catch (PersistenceBrokerException e)
  @@ -356,8 +364,7 @@
               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.)
  -            retval = new ResultSetAndStatement(
  -                    broker.serviceConnectionManager().getSupportedPlatform(), stmt, rs);
  +            retval = new ResultSetAndStatement(getPlatform(), stmt, rs);
               return retval;
           }
           catch (PersistenceBrokerException e)
  @@ -411,7 +418,6 @@
               logger.debug("executeUpdateSQL: " + sqlStatement);
   
           int result;
  -        int index;
           PreparedStatement stmt = null;
           StatementManagerIF stmtMan = broker.serviceStatementManager();
           try
  @@ -556,7 +562,7 @@
           String sql = (String) sqlSelectMap.get(cld);
           if(sql == null)
           {
  -            sql = new SqlExistStatement(broker.serviceSqlGenerator().getPlatform(), logger,
cld).getStatement();
  +            sql = new SqlExistStatement(getPlatform(), logger, cld).getStatement();
               sqlSelectMap.put(cld, sql);
           }
           StatementManagerIF sm = broker.serviceStatementManager();
  
  
  

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