cayenne-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From aadamc...@apache.org
Subject svn commit: r740245 [1/2] - in /cayenne/main/trunk/framework: cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/ cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/access/jdbc/ cayenne-jdk1.5-unpublished/src/main/java/org/apache/caye...
Date Tue, 03 Feb 2009 08:29:06 GMT
Author: aadamchik
Date: Tue Feb  3 08:29:04 2009
New Revision: 740245

URL: http://svn.apache.org/viewvc?rev=740245&view=rev
Log:
CAY-289 Implement Quoting of identifiers

patch by Olga Tkacheva.. I changed the naming a bit and fixed a few things on the edges

Added:
    cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/dba/QuotingStrategy.java
Modified:
    cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/CayenneContextQueryAction.java
    cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/access/jdbc/ColumnDescriptor.java
    cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/access/trans/JoinStack.java
    cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/access/trans/QueryAssemblerHelper.java
    cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/access/trans/SelectTranslator.java
    cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/dba/AutoAdapter.java
    cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/dba/DbAdapter.java
    cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/dba/JdbcAdapter.java
    cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/dba/JdbcPkGenerator.java
    cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/dba/db2/DB2Adapter.java
    cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/dba/db2/DB2PkGenerator.java
    cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/dba/derby/DerbyAdapter.java
    cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/dba/derby/DerbyPkGenerator.java
    cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/dba/frontbase/FrontBaseAdapter.java
    cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/dba/frontbase/FrontBasePkGenerator.java
    cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/dba/hsqldb/HSQLDBAdapter.java
    cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/dba/ingres/IngresAdapter.java
    cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/dba/ingres/IngresPkGenerator.java
    cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/dba/mysql/MySQLAdapter.java
    cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/dba/mysql/MySQLPkGenerator.java
    cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/dba/openbase/OpenBaseAdapter.java
    cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/dba/openbase/OpenBasePkGenerator.java
    cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/dba/oracle/OracleAdapter.java
    cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/dba/oracle/OraclePkGenerator.java
    cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/dba/postgres/PostgresAdapter.java
    cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/dba/postgres/PostgresPkGenerator.java
    cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/dba/sybase/SybasePkGenerator.java
    cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/map/DataMap.java
    cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/CayenneContextSQLTemplateTest.java
    cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/access/DataContextCase.java
    cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/access/trans/SelectTranslatorTest.java
    cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/dba/JdbcAdapterTest.java
    cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/dba/MockDbAdapter.java
    cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/map/DataMapTest.java
    cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/unit/AbstractAccessStack.java
    cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/editor/DataMapView.java

Modified: cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/CayenneContextQueryAction.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/CayenneContextQueryAction.java?rev=740245&r1=740244&r2=740245&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/CayenneContextQueryAction.java (original)
+++ cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/CayenneContextQueryAction.java Tue Feb  3 08:29:04 2009
@@ -22,8 +22,8 @@
 import java.util.Collection;
 import java.util.Iterator;
 
-import org.apache.cayenne.cache.QueryCacheEntryFactory;
 import org.apache.cayenne.cache.QueryCache;
+import org.apache.cayenne.cache.QueryCacheEntryFactory;
 import org.apache.cayenne.map.EntityResolver;
 import org.apache.cayenne.query.Query;
 import org.apache.cayenne.query.RefreshQuery;

Modified: cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/access/jdbc/ColumnDescriptor.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/access/jdbc/ColumnDescriptor.java?rev=740245&r1=740244&r2=740245&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/access/jdbc/ColumnDescriptor.java (original)
+++ cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/access/jdbc/ColumnDescriptor.java Tue Feb  3 08:29:04 2009
@@ -197,6 +197,12 @@
     public String getQualifiedColumnName() {
         return (namePrefix != null) ? namePrefix + '.' + name : name;
     }
+    
+    public String getQualifiedColumnNameWithQuoteSqlIdentifiers(String charStart, String charEnd) {
+        String nameWithQuoteSqlIdentifiers = charStart + name + charEnd;
+        return (namePrefix != null) ? charStart + namePrefix + charEnd + '.' +
+                nameWithQuoteSqlIdentifiers: nameWithQuoteSqlIdentifiers;
+    }
 
     public int getJdbcType() {
         return jdbcType;

Modified: cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/access/trans/JoinStack.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/access/trans/JoinStack.java?rev=740245&r1=740244&r2=740245&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/access/trans/JoinStack.java (original)
+++ cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/access/trans/JoinStack.java Tue Feb  3 08:29:04 2009
@@ -21,6 +21,8 @@
 import java.io.IOException;
 import java.util.List;
 
+import org.apache.cayenne.dba.DbAdapter;
+import org.apache.cayenne.map.DataMap;
 import org.apache.cayenne.map.DbEntity;
 import org.apache.cayenne.map.DbJoin;
 import org.apache.cayenne.map.DbRelationship;
@@ -36,16 +38,37 @@
 public class JoinStack {
 
     protected JoinTreeNode rootNode;
-    protected JoinTreeNode topNode;
+    protected JoinTreeNode topNode;    
+    private String identifiersStartQuote;
+    private String identifiersEndQuote;
 
     private int aliasCounter;
     
+    /**
+     * @deprecated since 3.0
+     */   
     protected JoinStack() {
         this.rootNode = new JoinTreeNode(this);
         this.rootNode.setTargetTableAlias(newAlias());
+        
+        resetStack();
+    }
+    
+    protected JoinStack(DbAdapter dbAdapter, DataMap dataMap) {
+        this.rootNode = new JoinTreeNode(this);
+        this.rootNode.setTargetTableAlias(newAlias());
+        
+        if(dataMap.isQuotingSQLIdentifiers()){
+            this.identifiersStartQuote = dbAdapter.getIdentifiersStartQuote();
+            this.identifiersEndQuote = dbAdapter.getIdentifiersEndQuote();
+        } else {
+            this.identifiersStartQuote = "";
+            this.identifiersEndQuote = "";
+        }
         resetStack();
     }
     
+    
     String getCurrentAlias() {
         return topNode.getTargetTableAlias();
     }
@@ -62,6 +85,16 @@
         out.append(rootEntity.getFullyQualifiedName());
         out.append(' ').append(rootNode.getTargetTableAlias());
     }
+    
+    void appendRootWithQuoteSqlIdentifiers(Appendable out, DbEntity rootEntity) throws IOException {
+        if(rootEntity.getSchema() != null) { 
+            nameWithQuoteSqlIdentifiers(rootEntity.getSchema(),out);
+            out.append(".");
+        }
+        nameWithQuoteSqlIdentifiers(rootEntity.getName(),out);
+        out.append(' ');
+        nameWithQuoteSqlIdentifiers(rootNode.getTargetTableAlias(),out);       
+    }
 
     /**
      * Appends all configured joins to the provided output object.
@@ -94,26 +127,34 @@
                         + node.getJoinType());
         }
 
-        out.append(' ').append(targetEntity.getFullyQualifiedName()).append(' ').append(
-                targetAlias).append(" ON (");
+        out.append(' ');
+        
+        if(targetEntity.getSchema()!= null){
+            
+            nameWithQuoteSqlIdentifiers(targetEntity.getSchema(),out);
+            out.append(".");
+        }
+        nameWithQuoteSqlIdentifiers(targetEntity.getName(), out);
+ 
+        out.append(' ');
+        nameWithQuoteSqlIdentifiers(targetAlias, out);
+        out.append(" ON (");
 
         List<DbJoin> joins = relationship.getJoins();
         int len = joins.size();
         for (int i = 0; i < len; i++) {
             DbJoin join = joins.get(i);
-
             if (i > 0) {
                 out.append(" AND ");
-            }
-
-            out
-                    .append(srcAlias)
-                    .append('.')
-                    .append(join.getSourceName())
-                    .append(" = ")
-                    .append(targetAlias)
-                    .append('.')
-                    .append(join.getTargetName());
+            }            
+            
+            nameWithQuoteSqlIdentifiers(srcAlias, out);
+            out.append('.');
+            nameWithQuoteSqlIdentifiers(join.getSourceName(), out);
+            out.append(" = ");
+            nameWithQuoteSqlIdentifiers(targetAlias, out);
+            out.append('.');
+            nameWithQuoteSqlIdentifiers(join.getTargetName(), out);
         }
 
         out.append(')');
@@ -149,4 +190,8 @@
     protected String newAlias() {
         return "t" + aliasCounter++;
     }
+    
+    protected void nameWithQuoteSqlIdentifiers(String name, Appendable out) throws IOException{
+        out.append(identifiersStartQuote).append(name).append(identifiersEndQuote);        
+    }  
 }

Modified: cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/access/trans/QueryAssemblerHelper.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/access/trans/QueryAssemblerHelper.java?rev=740245&r1=740244&r2=740245&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/access/trans/QueryAssemblerHelper.java (original)
+++ cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/access/trans/QueryAssemblerHelper.java Tue Feb  3 08:29:04 2009
@@ -48,6 +48,8 @@
 
     protected QueryAssembler queryAssembler;
     protected Appendable out;
+    private String identifiersStartQuote;
+    private String identifiersEndQuote;
 
     /**
      * Creates QueryAssemblerHelper initializing with parent {@link QueryAssembler} and
@@ -55,6 +57,14 @@
      */
     public QueryAssemblerHelper(QueryAssembler queryAssembler) {
         this.queryAssembler = queryAssembler;
+        
+        if(queryAssembler.getQueryMetadata().getDataMap()!=null && queryAssembler.getQueryMetadata().getDataMap().isQuotingSQLIdentifiers()){
+            identifiersStartQuote = queryAssembler.getAdapter().getIdentifiersStartQuote();
+            identifiersEndQuote  = queryAssembler.getAdapter().getIdentifiersEndQuote();
+        } else {
+            identifiersStartQuote = "";
+            identifiersEndQuote = "";
+        }
     }
 
     public ObjEntity getObjEntity() {
@@ -160,7 +170,7 @@
                                 joinSplitAlias);
                     }
                     else if (pathPart instanceof DbAttribute) {
-                        processColumn((DbAttribute) pathPart);
+                        processColumnWithQuoteSqlIdentifiers((DbAttribute) pathPart);
                     }
                 }
 
@@ -223,7 +233,7 @@
                 }
             }
             else {
-                processColumn(component.getAttribute());
+                     processColumnWithQuoteSqlIdentifiers(component.getAttribute());
             }
         }
     }
@@ -231,9 +241,20 @@
     protected void processColumn(DbAttribute dbAttr) throws IOException {
         String alias = (queryAssembler.supportsTableAliases()) ? queryAssembler
                 .getCurrentAlias() : null;
-
         out.append(dbAttr.getAliasedName(alias));
     }
+    
+    protected void processColumnWithQuoteSqlIdentifiers(DbAttribute dbAttr) throws IOException {
+       
+        String alias =  (queryAssembler.supportsTableAliases()) ? queryAssembler
+                .getCurrentAlias() : null;
+      
+            if(alias != null){        
+                out.append(identifiersStartQuote).append(alias).append(identifiersEndQuote);
+                out.append(".");
+            }
+            out.append(identifiersStartQuote).append(dbAttr.getName()).append(identifiersEndQuote);                     
+    }
 
     /**
      * Appends SQL code to the query buffer to handle <code>val</code> as a parameter to

Modified: cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/access/trans/SelectTranslator.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/access/trans/SelectTranslator.java?rev=740245&r1=740244&r2=740245&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/access/trans/SelectTranslator.java (original)
+++ cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/access/trans/SelectTranslator.java Tue Feb  3 08:29:04 2009
@@ -58,7 +58,10 @@
  * SelectTranslator is stateful and thread-unsafe.
  */
 public class SelectTranslator extends QueryAssembler {
-
+    
+    private String identifiersStartQuote;
+    private String identifiersEndQuote;
+    
     protected static final int[] UNSUPPORTED_DISTINCT_TYPES = new int[] {
             Types.BLOB, Types.CLOB, Types.LONGVARBINARY, Types.LONGVARCHAR
     };
@@ -72,8 +75,7 @@
 
         return false;
     }
-
-    JoinStack joinStack = createJoinStack();
+    JoinStack joinStack;
 
     List<ColumnDescriptor> resultColumns;
     Map<ObjAttribute, ColumnDescriptor> attributeOverrides;
@@ -88,8 +90,8 @@
      */
     boolean forcingDistinct;
 
-    protected JoinStack createJoinStack() {
-        return new JoinStack();
+    protected JoinStack createJoinStack() {        
+        return new JoinStack(getAdapter(), queryMetadata.getDataMap());
     }
 
     /**
@@ -98,19 +100,29 @@
      */
     @Override
     public String createSqlString() throws Exception {
+        
+        joinStack = createJoinStack();
+        
+        if(queryMetadata.getDataMap().isQuotingSQLIdentifiers()){
+            this.identifiersStartQuote = getAdapter().getIdentifiersStartQuote();
+            this.identifiersEndQuote = getAdapter().getIdentifiersEndQuote();
+        } else {
+            this.identifiersStartQuote = "";
+            this.identifiersEndQuote = "";
+        }
         forcingDistinct = false;
-
+       
         // build column list
         this.resultColumns = buildResultColumns();
-
+        
         // build qualifier
         StringBuilder qualifierBuffer = adapter.getQualifierTranslator(this).appendPart(
                 new StringBuilder());
 
-        // build ORDER BY
+         // build ORDER BY
         OrderingTranslator orderingTranslator = new OrderingTranslator(this);
         StringBuilder orderingBuffer = orderingTranslator.appendPart(new StringBuilder());
-
+        
         // assemble
         StringBuilder queryBuf = new StringBuilder();
         queryBuf.append("SELECT ");
@@ -118,7 +130,6 @@
         // check if DISTINCT is appropriate
         // side effect: "suppressingDistinct" flag may end up being flipped here
         if (forcingDistinct || getSelectQuery().isDistinct()) {
-
             suppressingDistinct = false;
 
             for (ColumnDescriptor column : resultColumns) {
@@ -136,7 +147,8 @@
         // convert ColumnDescriptors to column names
         List<String> selectColumnExpList = new ArrayList<String>();
         for (ColumnDescriptor column : resultColumns) {
-            selectColumnExpList.add(column.getQualifiedColumnName());
+            selectColumnExpList.add(
+                        column.getQualifiedColumnNameWithQuoteSqlIdentifiers(identifiersStartQuote, identifiersEndQuote));
         }
 
         // append any column expressions used in the order by if this query
@@ -145,32 +157,34 @@
             List<String> orderByColumnList = orderingTranslator.getOrderByColumnList();
             for (String orderByColumnExp : orderByColumnList) {
                 // Convert to ColumnDescriptors??
-                if (!selectColumnExpList.contains(orderByColumnExp)) {
+                if (!selectColumnExpList.contains(orderByColumnExp)) {                    
                     selectColumnExpList.add(orderByColumnExp);
                 }
             }
         }
-
+      
         // append columns (unroll the loop's first element)
         int columnCount = selectColumnExpList.size();
         queryBuf.append(selectColumnExpList.get(0));
+        
         // assume there is at least 1 element
         for (int i = 1; i < columnCount; i++) {
             queryBuf.append(", ");
-            queryBuf.append(selectColumnExpList.get(i));
+            queryBuf.append(selectColumnExpList.get(i));            
         }
 
         // append from clause
         queryBuf.append(" FROM ");
 
         // append tables and joins
-        joinStack.appendRoot(queryBuf, getRootDbEntity());
+        joinStack.appendRootWithQuoteSqlIdentifiers(queryBuf, getRootDbEntity());
+        
         joinStack.appendJoins(queryBuf);
         joinStack.appendQualifier(qualifierBuffer, qualifierBuffer.length() == 0);
 
         // append qualifier
         if (qualifierBuffer.length() > 0) {
-            queryBuf.append(" WHERE ");
+            queryBuf.append(" WHERE ");            
             queryBuf.append(qualifierBuffer);
         }
 
@@ -598,7 +612,10 @@
      */
     @Override
     public void resetJoinStack() {
-        joinStack.resetStack();
+        if(joinStack==null){
+            joinStack = createJoinStack();
+        }
+        joinStack.resetStack();           
     }
 
     /**
@@ -623,4 +640,4 @@
     public boolean supportsTableAliases() {
         return true;
     }
-}
+ }

Modified: cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/dba/AutoAdapter.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/dba/AutoAdapter.java?rev=740245&r1=740244&r2=740245&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/dba/AutoAdapter.java (original)
+++ cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/dba/AutoAdapter.java Tue Feb  3 08:29:04 2009
@@ -64,6 +64,9 @@
  */
 public class AutoAdapter implements DbAdapter {
 
+    final static String DEFAULT_QUOTE_SQL_IDENTIFIERS_CHAR_START = "\"";
+    final static String DEFAULT_QUOTE_SQL_IDENTIFIERS_CHAR_END = "\"";
+    
     static final List<DbAdapterFactory> defaultFactories;
     static {
         defaultFactories = new ArrayList<DbAdapterFactory>();
@@ -317,4 +320,15 @@
         getAdapter().createTableAppendColumn(sqlBuffer, column);
     }
 
+    public void setDefaultQuoteSqlIdentifiersChars(boolean isQuoteSqlIdentifiers) {
+    }
+
+    public String getIdentifiersStartQuote() {
+        return  DEFAULT_QUOTE_SQL_IDENTIFIERS_CHAR_START;
+    }
+
+    public String getIdentifiersEndQuote() {
+        return  DEFAULT_QUOTE_SQL_IDENTIFIERS_CHAR_END;
+    }
+
 }

Modified: cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/dba/DbAdapter.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/dba/DbAdapter.java?rev=740245&r1=740244&r2=740245&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/dba/DbAdapter.java (original)
+++ cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/dba/DbAdapter.java Tue Feb  3 08:29:04 2009
@@ -41,7 +41,6 @@
  * <li>Make Cayenne code independent from SQL syntax differences between different RDBMS.
  * <li>Allow for vendor-specific tuning of JDBC access.
  * </ul>
- * 
  */
 public interface DbAdapter {
 
@@ -128,8 +127,8 @@
     String createFkConstraint(DbRelationship rel);
 
     /**
-     * Returns an array of RDBMS types that can be used with JDBC <code>type</code>.
-     * Valid JDBC types are defined in java.sql.Types.
+     * Returns an array of RDBMS types that can be used with JDBC <code>type</code>. Valid
+     * JDBC types are defined in java.sql.Types.
      */
     String[] externalTypesForJdbcType(int type);
 
@@ -191,7 +190,7 @@
      * @since 3.0
      */
     MergerFactory mergerFactory();
-    
+
     /**
      * Append the column type part of a "create table" to the given {@link StringBuffer}
      * 
@@ -199,6 +198,16 @@
      * @param column the {@link DbAttribute} defining the column to append type for
      * @since 3.0
      */
-    public void createTableAppendColumn(StringBuffer sqlBuffer, DbAttribute column);
-    
+    void createTableAppendColumn(StringBuffer sqlBuffer, DbAttribute column);
+
+    /**
+     * @since 3.0
+     */
+    String getIdentifiersStartQuote();
+
+    /**
+     * @since 3.0
+     */
+    String getIdentifiersEndQuote();
+
 }

Modified: cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/dba/JdbcAdapter.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/dba/JdbcAdapter.java?rev=740245&r1=740244&r2=740245&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/dba/JdbcAdapter.java (original)
+++ cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/dba/JdbcAdapter.java Tue Feb  3 08:29:04 2009
@@ -43,6 +43,7 @@
 import org.apache.cayenne.access.types.ExtendedTypeMap;
 import org.apache.cayenne.access.types.UtilDateType;
 import org.apache.cayenne.conf.ClasspathResourceFinder;
+import org.apache.cayenne.map.DataMap;
 import org.apache.cayenne.map.DbAttribute;
 import org.apache.cayenne.map.DbEntity;
 import org.apache.cayenne.map.DbJoin;
@@ -55,10 +56,12 @@
 /**
  * A generic DbAdapter implementation. Can be used as a default adapter or as a superclass
  * of a concrete adapter implementation.
- * 
  */
 public class JdbcAdapter implements DbAdapter {
 
+    final static String DEFAULT_IDENTIFIERS_START_QUOTE = "\"";
+    final static String DEFAULT_IDENTIFIERS_END_QUOTE = "\"";
+
     protected PkGenerator pkGenerator;
     protected TypesHandler typesHandler;
     protected ExtendedTypeMap extendedTypes;
@@ -68,6 +71,23 @@
     protected boolean supportsGeneratedKeys;
     protected EJBQLTranslatorFactory ejbqlTranslatorFactory;
 
+    protected String identifiersStartQuote;
+    protected String identifiersEndQuote;
+
+    /**
+     * @since 3.0
+     */
+    public String getIdentifiersStartQuote() {
+        return identifiersStartQuote;
+    }
+
+    /**
+     * @since 3.0
+     */
+    public String getIdentifiersEndQuote() {
+        return identifiersEndQuote;
+    }
+
     /**
      * Creates new JdbcAdapter with a set of default parameters.
      */
@@ -82,6 +102,8 @@
         this.extendedTypes = new ExtendedTypeMap();
         this.configureExtendedTypes(extendedTypes);
         this.ejbqlTranslatorFactory = createEJBQLTranslatorFactory();
+        initIdentifiersQuotes();
+
     }
 
     /**
@@ -172,7 +194,7 @@
      * PKGenerator.
      */
     protected PkGenerator createPkGenerator() {
-        return new JdbcPkGenerator();
+        return new JdbcPkGenerator(this);
     }
 
     /**
@@ -245,7 +267,12 @@
      * @since 3.0
      */
     public Collection<String> dropTableStatements(DbEntity table) {
-        return Collections.singleton("DROP TABLE " + table.getFullyQualifiedName());
+        QuotingStrategy context = getContextQuoteStrategy(table.getDataMap());
+
+        StringBuffer buf = new StringBuffer("DROP TABLE ");
+        buf.append(context.quoteFullyQualifiedName(table));
+
+        return Collections.singleton(buf.toString());
     }
 
     /**
@@ -253,11 +280,12 @@
      * <code>ent</code> parameter.
      */
     public String createTable(DbEntity entity) {
-
+        QuotingStrategy context = getContextQuoteStrategy(entity.getDataMap());
         StringBuffer sqlBuffer = new StringBuffer();
-        sqlBuffer.append("CREATE TABLE ").append(entity.getFullyQualifiedName()).append(
-                " (");
+        sqlBuffer.append("CREATE TABLE ");
+        sqlBuffer.append(context.quoteFullyQualifiedName(entity));
 
+        sqlBuffer.append(" (");
         // columns
         Iterator<?> it = entity.getAttributes().iterator();
         if (it.hasNext()) {
@@ -295,6 +323,7 @@
      * @since 1.2
      */
     protected void createTableAppendPKClause(StringBuffer sqlBuffer, DbEntity entity) {
+        QuotingStrategy context = getContextQuoteStrategy(entity.getDataMap());
         Iterator<DbAttribute> pkit = entity.getPrimaryKeys().iterator();
         if (pkit.hasNext()) {
             sqlBuffer.append(", PRIMARY KEY (");
@@ -306,7 +335,8 @@
                     sqlBuffer.append(", ");
 
                 DbAttribute at = pkit.next();
-                sqlBuffer.append(at.getName());
+
+                sqlBuffer.append(context.quoteString(at.getName()));
             }
             sqlBuffer.append(')');
         }
@@ -318,6 +348,8 @@
      * @since 1.2
      */
     public void createTableAppendColumn(StringBuffer sqlBuffer, DbAttribute column) {
+        QuotingStrategy context = getContextQuoteStrategy(((DbEntity) column.getEntity())
+                .getDataMap());
         String[] types = externalTypesForJdbcType(column.getType());
         if (types == null || types.length == 0) {
             String entityName = column.getEntity() != null ? ((DbEntity) column
@@ -331,9 +363,10 @@
         }
 
         String type = types[0];
-        sqlBuffer.append(column.getName()).append(' ').append(type);
+        sqlBuffer.append(context.quoteString(column.getName()));
+        sqlBuffer.append(' ').append(type);
 
-        // append size and precision (if applicable)
+        // append size and precision (if applicable)s
         if (TypesMapping.supportsLength(column.getType())) {
             int len = column.getMaxLength();
             int scale = TypesMapping.isDecimal(column.getType()) ? column.getScale() : -1;
@@ -363,6 +396,8 @@
      * @since 1.1
      */
     public String createUniqueConstraint(DbEntity source, Collection<DbAttribute> columns) {
+        QuotingStrategy context = getContextQuoteStrategy(source.getDataMap());
+
         if (columns == null || columns.isEmpty()) {
             throw new CayenneRuntimeException(
                     "Can't create UNIQUE constraint - no columns specified.");
@@ -370,17 +405,18 @@
 
         StringBuilder buf = new StringBuilder();
 
-        buf.append("ALTER TABLE ").append(source.getFullyQualifiedName()).append(
-                " ADD UNIQUE (");
+        buf.append("ALTER TABLE ");
+        buf.append(context.quoteFullyQualifiedName(source));
+        buf.append(" ADD UNIQUE (");
 
         Iterator<DbAttribute> it = columns.iterator();
         DbAttribute first = it.next();
-        buf.append(first.getName());
+        buf.append(context.quoteString(first.getName()));
 
         while (it.hasNext()) {
             DbAttribute next = it.next();
             buf.append(", ");
-            buf.append(next.getName());
+            buf.append(context.quoteString(next.getName()));
         }
 
         buf.append(")");
@@ -393,12 +429,16 @@
      * relationship.
      */
     public String createFkConstraint(DbRelationship rel) {
+
+        DbEntity source = (DbEntity) rel.getSourceEntity();
+        QuotingStrategy context = getContextQuoteStrategy(source.getDataMap());
         StringBuilder buf = new StringBuilder();
         StringBuilder refBuf = new StringBuilder();
 
-        buf.append("ALTER TABLE ").append(
-                ((DbEntity) rel.getSourceEntity()).getFullyQualifiedName()).append(
-                " ADD FOREIGN KEY (");
+        buf.append("ALTER TABLE ");
+
+        buf.append(context.quoteFullyQualifiedName(source));
+        buf.append(" ADD FOREIGN KEY (");
 
         boolean first = true;
 
@@ -410,16 +450,15 @@
             else
                 first = false;
 
-            buf.append(join.getSourceName());
-            refBuf.append(join.getTargetName());
+            buf.append(context.quoteString(join.getSourceName()));
+            refBuf.append(context.quoteString(join.getTargetName()));
         }
 
-        buf
-                .append(") REFERENCES ")
-                .append(((DbEntity) rel.getTargetEntity()).getFullyQualifiedName())
-                .append(" (")
-                .append(refBuf.toString())
-                .append(')');
+        buf.append(") REFERENCES ");
+
+        buf.append(context.quoteFullyQualifiedName((DbEntity) rel.getTargetEntity()));
+
+        buf.append(" (").append(refBuf.toString()).append(')');
         return buf.toString();
     }
 
@@ -542,7 +581,32 @@
         this.ejbqlTranslatorFactory = ejbqlTranslatorFactory;
     }
 
+    /**
+     * @since 3.0
+     */
     public MergerFactory mergerFactory() {
         return new MergerFactory();
     }
+
+    /**
+     * @since 3.0
+     */
+    protected void initIdentifiersQuotes() {
+        this.identifiersStartQuote = DEFAULT_IDENTIFIERS_START_QUOTE;
+        this.identifiersEndQuote = DEFAULT_IDENTIFIERS_END_QUOTE;
+    }
+
+    /**
+     * @since 3.0
+     */
+    protected QuotingStrategy getContextQuoteStrategy(DataMap dm) {
+        if (dm != null && dm.isQuotingSQLIdentifiers()) {
+            return new QuoteStrategy(
+                    getIdentifiersStartQuote(),
+                    getIdentifiersEndQuote());
+        }
+        else {
+            return new NoQuoteStrategy();
+        }
+    }
 }

Modified: cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/dba/JdbcPkGenerator.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/dba/JdbcPkGenerator.java?rev=740245&r1=740244&r2=740245&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/dba/JdbcPkGenerator.java (original)
+++ cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/dba/JdbcPkGenerator.java Tue Feb  3 08:29:04 2009
@@ -38,6 +38,7 @@
 import org.apache.cayenne.access.OperationObserver;
 import org.apache.cayenne.access.QueryLogger;
 import org.apache.cayenne.access.ResultIterator;
+import org.apache.cayenne.map.DataMap;
 import org.apache.cayenne.map.DbAttribute;
 import org.apache.cayenne.map.DbEntity;
 import org.apache.cayenne.map.DbKeyGenerator;
@@ -52,11 +53,28 @@
  */
 public class JdbcPkGenerator implements PkGenerator {
 
+    private JdbcAdapter adapter;
+    
+    public JdbcAdapter getAdapter() {
+        return adapter;
+    }
+
+    protected JdbcPkGenerator(JdbcAdapter adapter){
+        super();
+        this.adapter = adapter;
+    }
+   
+    /**
+     * @deprecated since 3.0
+     */
+    public JdbcPkGenerator() {
+    }
+
     public static final int DEFAULT_PK_CACHE_SIZE = 20;
 
     protected Map<String, LongPkRange> pkCache = new HashMap<String, LongPkRange>();
-    protected int pkCacheSize = DEFAULT_PK_CACHE_SIZE;
-
+    protected int pkCacheSize = DEFAULT_PK_CACHE_SIZE;    
+   
     public void createAutoPk(DataNode node, List<DbEntity> dbEntities) throws Exception {
         // check if a table exists
 
@@ -486,4 +504,12 @@
                     + entityName, ex);
         }
     }
+    
+    protected QuotingStrategy getContextQuoteStrategy(DataMap dm) {
+        if(dm!=null && dm.isQuotingSQLIdentifiers()){
+            return new QuoteStrategy(getAdapter().getIdentifiersStartQuote(), getAdapter().getIdentifiersEndQuote());
+        } else {
+            return new NoQuoteStrategy();           
+       }    
+   } 
 }

Added: cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/dba/QuotingStrategy.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/dba/QuotingStrategy.java?rev=740245&view=auto
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/dba/QuotingStrategy.java (added)
+++ cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/dba/QuotingStrategy.java Tue Feb  3 08:29:04 2009
@@ -0,0 +1,66 @@
+/*****************************************************************
+ *   Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you under the Apache License, Version 2.0 (the
+ *  "License"); you may not use this file except in compliance
+ *  with the License.  You may obtain a copy of the License at
+ *
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing,
+ *  software distributed under the License is distributed on an
+ *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ *  KIND, either express or implied.  See the License for the
+ *  specific language governing permissions and limitations
+ *  under the License.
+ ****************************************************************/
+package org.apache.cayenne.dba;
+
+import org.apache.cayenne.map.DbEntity;
+
+/**
+ * @since 3.0
+ */
+public interface QuotingStrategy {
+
+    String quoteString(String name);
+
+    String quoteFullyQualifiedName(DbEntity entity);
+}
+
+class QuoteStrategy implements QuotingStrategy {
+
+    private String endQuote;
+    private String startQuote;
+
+    public QuoteStrategy(String startQuote, String endQuote) {
+        this.startQuote = startQuote;
+        this.endQuote = endQuote;
+    }
+
+    public String quoteString(String name) {
+        return startQuote + name + endQuote;
+    }
+
+    public String quoteFullyQualifiedName(DbEntity entity) {
+        StringBuilder buf = new StringBuilder();
+        if (entity.getSchema() != null) {
+            buf.append(quoteString(entity.getSchema())).append(".");
+        }
+        buf.append(quoteString(entity.getName()));
+        return buf.toString();
+    }
+}
+
+class NoQuoteStrategy implements QuotingStrategy {
+
+    public String quoteString(String name) {
+        return name;
+    }
+
+    public String quoteFullyQualifiedName(DbEntity entity) {
+        return entity.getFullyQualifiedName();
+    }
+}

Modified: cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/dba/db2/DB2Adapter.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/dba/db2/DB2Adapter.java?rev=740245&r1=740244&r2=740245&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/dba/db2/DB2Adapter.java (original)
+++ cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/dba/db2/DB2Adapter.java Tue Feb  3 08:29:04 2009
@@ -31,10 +31,12 @@
 import org.apache.cayenne.access.types.ExtendedTypeMap;
 import org.apache.cayenne.dba.JdbcAdapter;
 import org.apache.cayenne.dba.PkGenerator;
+import org.apache.cayenne.dba.QuotingStrategy;
 import org.apache.cayenne.dba.TypesMapping;
 import org.apache.cayenne.map.DbAttribute;
 import org.apache.cayenne.map.DbEntity;
 
+
 /**
  * DbAdapter implementation for the <a href="http://www.ibm.com/db2/"> DB2 RDBMS </a>.
  * Sample connection settings to use with DB2 are shown below:
@@ -52,12 +54,12 @@
  */
 public class DB2Adapter extends JdbcAdapter {
 
+    
     /**
-     * Creates a DB2 specific PK Generator.
-     */
-    @Override
+     * Creates a DB2 specific PK Generator.    
+     */   
     protected PkGenerator createPkGenerator() {
-        return new DB2PkGenerator();
+        return new DB2PkGenerator(this);
     }
 
     @Override
@@ -79,9 +81,13 @@
      */
     @Override
     public String createTable(DbEntity ent) {
-
+        QuotingStrategy context = getContextQuoteStrategy(ent.getDataMap());
+        
         StringBuilder buf = new StringBuilder();
-        buf.append("CREATE TABLE ").append(ent.getFullyQualifiedName()).append(" (");
+        buf.append("CREATE TABLE ");
+        buf.append(context.quoteFullyQualifiedName(ent)); 
+
+        buf.append(" (");
 
         // columns
         Iterator<DbAttribute> it = ent.getAttributes().iterator();
@@ -114,7 +120,7 @@
             }
 
             String type = types[0];
-            buf.append(at.getName()).append(' ').append(type);
+            buf.append(context.quoteString(at.getName())).append(' ').append(type);
 
             // append size and precision (if applicable)
             if (TypesMapping.supportsLength(at.getType())) {
@@ -159,7 +165,7 @@
                     buf.append(", ");
 
                 DbAttribute at = pkit.next();
-                buf.append(at.getName());
+                buf.append(context.quoteString(at.getName()));
             }
             buf.append(')');
         }

Modified: cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/dba/db2/DB2PkGenerator.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/dba/db2/DB2PkGenerator.java?rev=740245&r1=740244&r2=740245&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/dba/db2/DB2PkGenerator.java (original)
+++ cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/dba/db2/DB2PkGenerator.java Tue Feb  3 08:29:04 2009
@@ -30,7 +30,9 @@
 import org.apache.cayenne.CayenneRuntimeException;
 import org.apache.cayenne.access.DataNode;
 import org.apache.cayenne.access.QueryLogger;
+import org.apache.cayenne.dba.JdbcAdapter;
 import org.apache.cayenne.dba.JdbcPkGenerator;
+import org.apache.cayenne.dba.QuotingStrategy;
 import org.apache.cayenne.map.DbEntity;
 
 /**
@@ -39,6 +41,17 @@
  */
 public class DB2PkGenerator extends JdbcPkGenerator {
 
+    /**
+     * @deprecated since 3.0
+     */
+    protected DB2PkGenerator() {
+        super();
+    }
+    
+    DB2PkGenerator(JdbcAdapter adapter) {
+        super(adapter);
+    }
+
     private static final String _SEQUENCE_PREFIX = "S_";
 
     /**
@@ -212,12 +225,17 @@
      * Returns default sequence name for DbEntity.
      */
     protected String sequenceName(DbEntity entity) {
-
+        QuotingStrategy context = getContextQuoteStrategy(entity.getDataMap());
         String entName = entity.getName();
         String seqName = _SEQUENCE_PREFIX + entName;
 
         if (entity.getSchema() != null && entity.getSchema().length() > 0) {
-            seqName = entity.getSchema() + "." + seqName;
+            if(getAdapter()!=null){
+                seqName = context.quoteString(entity.getSchema()) +
+                 "." + context.quoteString(seqName);
+           } else {
+                seqName = entity.getSchema() + "." + seqName;
+           }
         }
         return seqName;
     }
@@ -226,6 +244,7 @@
      * Returns DROP SEQUENCE statement.
      */
     protected String dropSequenceString(DbEntity entity) {
+         
         return "DROP SEQUENCE " + sequenceName(entity) + " RESTRICT ";
     }
 

Modified: cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/dba/derby/DerbyAdapter.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/dba/derby/DerbyAdapter.java?rev=740245&r1=740244&r2=740245&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/dba/derby/DerbyAdapter.java (original)
+++ cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/dba/derby/DerbyAdapter.java Tue Feb  3 08:29:04 2009
@@ -32,6 +32,7 @@
 import org.apache.cayenne.access.types.ShortType;
 import org.apache.cayenne.dba.JdbcAdapter;
 import org.apache.cayenne.dba.PkGenerator;
+import org.apache.cayenne.dba.QuotingStrategy;
 import org.apache.cayenne.dba.TypesMapping;
 import org.apache.cayenne.map.DbAttribute;
 import org.apache.cayenne.map.DbEntity;
@@ -96,7 +97,8 @@
      */
     @Override
     public void createTableAppendColumn(StringBuffer sqlBuffer, DbAttribute column) {
-
+        QuotingStrategy context = getContextQuoteStrategy(((DbEntity) column
+                .getEntity()).getDataMap());
         String[] types = externalTypesForJdbcType(column.getType());
         if (types == null || types.length == 0) {
             String entityName = column.getEntity() != null ? ((DbEntity) column
@@ -138,7 +140,9 @@
         // note that max length for types like XYZ FOR BIT DATA must be entered in the
         // middle of type name, e.g. VARCHAR (100) FOR BIT DATA.
 
-        sqlBuffer.append(column.getName()).append(' ');
+        sqlBuffer.append(context.quoteString(column.getName()));
+       
+        sqlBuffer.append(' ');
         if (length.length() > 0 && type.endsWith(FOR_BIT_DATA_SUFFIX)) {
             sqlBuffer.append(type.substring(0, type.length()
                     - FOR_BIT_DATA_SUFFIX.length()));

Modified: cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/dba/derby/DerbyPkGenerator.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/dba/derby/DerbyPkGenerator.java?rev=740245&r1=740244&r2=740245&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/dba/derby/DerbyPkGenerator.java (original)
+++ cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/dba/derby/DerbyPkGenerator.java Tue Feb  3 08:29:04 2009
@@ -27,6 +27,7 @@
 import org.apache.cayenne.CayenneException;
 import org.apache.cayenne.access.DataNode;
 import org.apache.cayenne.access.QueryLogger;
+import org.apache.cayenne.dba.JdbcAdapter;
 import org.apache.cayenne.dba.JdbcPkGenerator;
 import org.apache.cayenne.map.DbEntity;
 
@@ -37,6 +38,16 @@
  * @since 1.2
  */
 public class DerbyPkGenerator extends JdbcPkGenerator {
+    
+    /**
+     * @deprecated since 3.0
+     */
+    DerbyPkGenerator(){        
+    }
+    
+    DerbyPkGenerator(JdbcAdapter adapter){
+        super(adapter);
+    }
 
     static final String SELECT_QUERY = "SELECT NEXT_ID FROM AUTO_PK_SUPPORT"
             + " WHERE TABLE_NAME = ? FOR UPDATE";

Modified: cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/dba/frontbase/FrontBaseAdapter.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/dba/frontbase/FrontBaseAdapter.java?rev=740245&r1=740244&r2=740245&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/dba/frontbase/FrontBaseAdapter.java (original)
+++ cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/dba/frontbase/FrontBaseAdapter.java Tue Feb  3 08:29:04 2009
@@ -29,6 +29,7 @@
 import org.apache.cayenne.access.types.ExtendedTypeMap;
 import org.apache.cayenne.dba.JdbcAdapter;
 import org.apache.cayenne.dba.PkGenerator;
+import org.apache.cayenne.dba.QuotingStrategy;
 import org.apache.cayenne.dba.TypesMapping;
 import org.apache.cayenne.map.DbAttribute;
 import org.apache.cayenne.map.DbEntity;
@@ -89,9 +90,11 @@
      */
     @Override
     public String createTable(DbEntity ent) {
-
+        QuotingStrategy context = getContextQuoteStrategy(ent.getDataMap());
         StringBuilder buf = new StringBuilder();
-        buf.append("CREATE TABLE ").append(ent.getFullyQualifiedName()).append(" (");
+        buf.append("CREATE TABLE ");
+        buf.append(context.quoteFullyQualifiedName(ent));
+        buf.append(" (");
 
         // columns
         Iterator<DbAttribute> it = ent.getAttributes().iterator();
@@ -124,7 +127,7 @@
             }
 
             String type = types[0];
-            buf.append(at.getName()).append(' ').append(type);
+            buf.append(context.quoteString(at.getName())).append(' ').append(type);
 
             // Mapping LONGVARCHAR without length creates a column with lenght "1" which
             // is defintely not what we want...so just use something very large (1Gb seems
@@ -184,7 +187,7 @@
                     buf.append(", ");
 
                 DbAttribute at = pkit.next();
-                buf.append(at.getName());
+                buf.append(context.quoteString(at.getName()));
             }
             buf.append(')');
         }
@@ -197,9 +200,12 @@
      */
     @Override
     public Collection<String> dropTableStatements(DbEntity table) {
-        return Collections.singleton("DROP TABLE "
-                + table.getFullyQualifiedName()
-                + " CASCADE");
+        QuotingStrategy context = getContextQuoteStrategy(table.getDataMap());
+        StringBuffer buf = new StringBuffer("DROP TABLE ");
+        buf.append(context.quoteFullyQualifiedName(table));            
+
+        buf.append(" CASCADE");
+        return Collections.singleton(buf.toString());
     }
 
     @Override

Modified: cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/dba/frontbase/FrontBasePkGenerator.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/dba/frontbase/FrontBasePkGenerator.java?rev=740245&r1=740244&r2=740245&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/dba/frontbase/FrontBasePkGenerator.java (original)
+++ cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/dba/frontbase/FrontBasePkGenerator.java Tue Feb  3 08:29:04 2009
@@ -27,6 +27,7 @@
 import org.apache.cayenne.CayenneRuntimeException;
 import org.apache.cayenne.access.DataNode;
 import org.apache.cayenne.access.QueryResult;
+import org.apache.cayenne.dba.JdbcAdapter;
 import org.apache.cayenne.dba.JdbcPkGenerator;
 import org.apache.cayenne.map.DbEntity;
 import org.apache.cayenne.query.Query;
@@ -37,9 +38,16 @@
  */
 public class FrontBasePkGenerator extends JdbcPkGenerator {
 
+    /**
+     * @deprecated since 3.0
+     */
     public FrontBasePkGenerator() {
         super();
     }
+    
+    public FrontBasePkGenerator(JdbcAdapter adapter) {
+        super(adapter);
+    }
 
     /**
      * Retruns zero as PK caching is not supported by FrontBaseAdapter.

Modified: cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/dba/hsqldb/HSQLDBAdapter.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/dba/hsqldb/HSQLDBAdapter.java?rev=740245&r1=740244&r2=740245&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/dba/hsqldb/HSQLDBAdapter.java (original)
+++ cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/dba/hsqldb/HSQLDBAdapter.java Tue Feb  3 08:29:04 2009
@@ -30,6 +30,7 @@
 import org.apache.cayenne.access.types.DefaultType;
 import org.apache.cayenne.access.types.ExtendedTypeMap;
 import org.apache.cayenne.dba.JdbcAdapter;
+import org.apache.cayenne.dba.QuotingStrategy;
 import org.apache.cayenne.map.DbAttribute;
 import org.apache.cayenne.map.DbEntity;
 import org.apache.cayenne.map.DbJoin;
@@ -66,7 +67,8 @@
      * @since 1.2
      */
     protected String getTableName(DbEntity entity) {
-        return entity.getFullyQualifiedName();
+        QuotingStrategy context = getContextQuoteStrategy(entity.getDataMap());
+        return context.quoteFullyQualifiedName(entity);
     }
 
     /**
@@ -76,7 +78,8 @@
      */
     protected String getSchemaName(DbEntity entity) {
         if (entity.getSchema() != null && entity.getSchema().length() > 0) {
-            return entity.getSchema() + ".";
+            QuotingStrategy context = getContextQuoteStrategy(entity.getDataMap());
+            return context.quoteString(entity.getSchema()) + ".";
         }
 
         return "";
@@ -100,6 +103,7 @@
      */
     @Override
     public String createUniqueConstraint(DbEntity source, Collection<DbAttribute> columns) {
+        QuotingStrategy context = getContextQuoteStrategy(source.getDataMap());
         if (columns == null || columns.isEmpty()) {
             throw new CayenneRuntimeException(
                     "Can't create UNIQUE constraint - no columns specified.");
@@ -109,24 +113,23 @@
 
         StringBuilder buf = new StringBuilder();
 
-        buf.append("ALTER TABLE ").append(srcName);
+        buf.append("ALTER TABLE ").append(context.quoteString(srcName));
         buf.append(" ADD CONSTRAINT ");
 
-        buf.append(getSchemaName(source));
-        buf.append("U_");
-        buf.append(source.getName());
-        buf.append("_");
-        buf.append((long) (System.currentTimeMillis() / (Math.random() * 100000)));
+        buf.append(context.quoteString(getSchemaName(source)));
+        String name = "U_" + source.getName() + "_" + (long) (System.currentTimeMillis() / (Math.random() * 100000));
+
+        buf.append(context.quoteString(name));
         buf.append(" UNIQUE (");
 
         Iterator<DbAttribute> it = columns.iterator();
         DbAttribute first = it.next();
-        buf.append(first.getName());
+        buf.append(context.quoteString(first.getName()));
 
         while (it.hasNext()) {
             DbAttribute next = it.next();
             buf.append(", ");
-            buf.append(next.getName());
+            buf.append(context.quoteString(next.getName()));
         }
 
         buf.append(")");
@@ -141,6 +144,7 @@
      */
     @Override
     public String createFkConstraint(DbRelationship rel) {
+        QuotingStrategy context = getContextQuoteStrategy(((DbEntity)rel.getSourceEntity()).getDataMap());
         StringBuilder buf = new StringBuilder();
         StringBuilder refBuf = new StringBuilder();
 
@@ -153,11 +157,9 @@
         // hsqldb requires the ADD CONSTRAINT statement
         buf.append(" ADD CONSTRAINT ");
         buf.append(getSchemaName((DbEntity) rel.getSourceEntity()));
-        buf.append("C_");
-        buf.append(rel.getSourceEntity().getName());
-        buf.append("_");
-        buf.append((long) (System.currentTimeMillis() / (Math.random() * 100000)));
-
+        String name = "U_" + rel.getSourceEntity().getName() + "_" + (long) (System.currentTimeMillis() / (Math.random() * 100000));
+        
+        buf.append(context.quoteString(name));
         buf.append(" FOREIGN KEY (");
 
         boolean first = true;
@@ -169,8 +171,8 @@
             else
                 first = false;
 
-            buf.append(join.getSourceName());
-            refBuf.append(join.getTargetName());
+            buf.append(context.quoteString(join.getSourceName()));
+            refBuf.append(context.quoteString(join.getTargetName()));
         }
 
         buf.append(") REFERENCES ");

Modified: cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/dba/ingres/IngresAdapter.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/dba/ingres/IngresAdapter.java?rev=740245&r1=740244&r2=740245&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/dba/ingres/IngresAdapter.java (original)
+++ cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/dba/ingres/IngresAdapter.java Tue Feb  3 08:29:04 2009
@@ -28,6 +28,7 @@
 import org.apache.cayenne.access.types.ExtendedTypeMap;
 import org.apache.cayenne.dba.JdbcAdapter;
 import org.apache.cayenne.dba.PkGenerator;
+import org.apache.cayenne.dba.QuotingStrategy;
 import org.apache.cayenne.dba.TypesMapping;
 import org.apache.cayenne.map.DbAttribute;
 import org.apache.cayenne.map.DbEntity;
@@ -59,8 +60,11 @@
      */
     @Override
     public String createTable(DbEntity ent) {
+        QuotingStrategy context = getContextQuoteStrategy(ent.getDataMap());
         StringBuilder buf = new StringBuilder();
-        buf.append("CREATE TABLE ").append(ent.getFullyQualifiedName()).append(" (");
+        buf.append("CREATE TABLE ");
+        buf.append(context.quoteFullyQualifiedName(ent));
+        buf.append(" (");
 
         // columns
         Iterator<DbAttribute> it = ent.getAttributes().iterator();
@@ -93,7 +97,7 @@
             }
 
             String type = types[0];
-            buf.append(at.getName()).append(' ').append(type);
+            buf.append(context.quoteString(at.getName())).append(' ').append(type);
 
             // append size and precision (if applicable)
             if (TypesMapping.supportsLength(at.getType())) {
@@ -139,7 +143,7 @@
                     buf.append(", ");
 
                 DbAttribute at = pkit.next();
-                buf.append(at.getName());
+                buf.append(context.quoteString(at.getName()));
             }
             buf.append(')');
         }
@@ -158,7 +162,7 @@
      */
     @Override
     protected PkGenerator createPkGenerator() {
-        return new IngresPkGenerator();
+        return new IngresPkGenerator(this);
     }
 
 }

Modified: cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/dba/ingres/IngresPkGenerator.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/dba/ingres/IngresPkGenerator.java?rev=740245&r1=740244&r2=740245&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/dba/ingres/IngresPkGenerator.java (original)
+++ cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/dba/ingres/IngresPkGenerator.java Tue Feb  3 08:29:04 2009
@@ -30,6 +30,7 @@
 import org.apache.cayenne.CayenneRuntimeException;
 import org.apache.cayenne.access.DataNode;
 import org.apache.cayenne.access.QueryLogger;
+import org.apache.cayenne.dba.JdbcAdapter;
 import org.apache.cayenne.dba.oracle.OraclePkGenerator;
 import org.apache.cayenne.map.DbEntity;
 import org.apache.cayenne.map.DbKeyGenerator;
@@ -41,6 +42,17 @@
  */
 public class IngresPkGenerator extends OraclePkGenerator {
     
+    /**
+     * @deprecated since 3.0
+     */
+    protected IngresPkGenerator() {
+        super();
+    }
+    
+    protected IngresPkGenerator(JdbcAdapter adapter) {
+        super(adapter);
+    }
+    
     @Override
     protected long longPkFromDatabase(DataNode node, DbEntity entity) throws Exception {
 

Modified: cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/dba/mysql/MySQLAdapter.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/dba/mysql/MySQLAdapter.java?rev=740245&r1=740244&r2=740245&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/dba/mysql/MySQLAdapter.java (original)
+++ cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/dba/mysql/MySQLAdapter.java Tue Feb  3 08:29:04 2009
@@ -35,6 +35,7 @@
 import org.apache.cayenne.access.types.ExtendedTypeMap;
 import org.apache.cayenne.dba.JdbcAdapter;
 import org.apache.cayenne.dba.PkGenerator;
+import org.apache.cayenne.dba.QuotingStrategy;
 import org.apache.cayenne.map.DbAttribute;
 import org.apache.cayenne.map.DbEntity;
 import org.apache.cayenne.map.DbRelationship;
@@ -66,18 +67,28 @@
 public class MySQLAdapter extends JdbcAdapter {
     
     final static String DEFAULT_STORAGE_ENGINE = "InnoDB";
+    final static String MYSQL_QUOTE_SQL_IDENTIFIERS_CHAR_START = "`";
+    final static String MYSQL_QUOTE_SQL_IDENTIFIERS_CHAR_END = "`";
 
     protected String storageEngine;
-
+ 
     public MySQLAdapter() {
 
         // init defaults
         this.storageEngine = DEFAULT_STORAGE_ENGINE;
+        
         setSupportsFkConstraints(true);
         setSupportsUniqueConstraints(true);
-        setSupportsGeneratedKeys(true);
+        setSupportsGeneratedKeys(true); 
+        initIdentifiersQuotes(); 
     }
-
+ 
+    @Override
+    public void initIdentifiersQuotes(){
+        this.identifiersStartQuote = MYSQL_QUOTE_SQL_IDENTIFIERS_CHAR_START;
+        this.identifiersEndQuote = MYSQL_QUOTE_SQL_IDENTIFIERS_CHAR_END;
+    }
+    
     /**
      * Uses special action builder to create the right action.
      * 
@@ -94,7 +105,11 @@
      */
     @Override
     public String dropTable(DbEntity table) {
-        return "DROP TABLE IF EXISTS " + table.getFullyQualifiedName() + " CASCADE";
+        QuotingStrategy context = getContextQuoteStrategy(table.getDataMap()); 
+        StringBuffer buf = new StringBuffer("DROP TABLE IF EXISTS ");
+        buf.append(context.quoteFullyQualifiedName(table));            
+        buf.append(" CASCADE");
+        return buf.toString();
     }
 
     /**
@@ -104,8 +119,12 @@
     public Collection<String> dropTableStatements(DbEntity table) {
         // note that CASCADE is a noop as of MySQL 5.0, so we have to use FK checks
         // statement
+        StringBuffer buf = new StringBuffer();
+        QuotingStrategy context = getContextQuoteStrategy(table.getDataMap());
+        buf.append(context.quoteFullyQualifiedName(table));            
+        
         return Arrays.asList("SET FOREIGN_KEY_CHECKS=0", "DROP TABLE IF EXISTS "
-                + table.getFullyQualifiedName()
+                + buf.toString()
                 + " CASCADE", "SET FOREIGN_KEY_CHECKS=1");
     }
 
@@ -224,7 +243,7 @@
     // See CAY-358 for details of the InnoDB problem
     @Override
     protected void createTableAppendPKClause(StringBuffer sqlBuffer, DbEntity entity) {
-
+        QuotingStrategy context = getContextQuoteStrategy(entity.getDataMap());
         // must move generated to the front...
         List<DbAttribute> pkList = new ArrayList<DbAttribute>(entity.getPrimaryKeys());
         Collections.sort(pkList, new PKComparator());
@@ -241,7 +260,7 @@
                     sqlBuffer.append(", ");
 
                 DbAttribute at = pkit.next();
-                sqlBuffer.append(at.getName());
+                sqlBuffer.append(context.quoteString(at.getName()));
             }
             sqlBuffer.append(')');
         }
@@ -262,11 +281,11 @@
                             .getSourceAttributes()
                             .iterator();
                     DbAttribute column = columns.next();
-                    sqlBuffer.append(column.getName());
+                    sqlBuffer.append(context.quoteString(column.getName()));
 
                     while (columns.hasNext()) {
                         column = columns.next();
-                        sqlBuffer.append(", ").append(column.getName());
+                        sqlBuffer.append(", ").append( context.quoteString(column.getName()));
                     }
 
                     sqlBuffer.append(")");

Modified: cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/dba/mysql/MySQLPkGenerator.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/dba/mysql/MySQLPkGenerator.java?rev=740245&r1=740244&r2=740245&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/dba/mysql/MySQLPkGenerator.java (original)
+++ cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/dba/mysql/MySQLPkGenerator.java Tue Feb  3 08:29:04 2009
@@ -27,6 +27,7 @@
 
 import org.apache.cayenne.access.DataNode;
 import org.apache.cayenne.access.QueryLogger;
+import org.apache.cayenne.dba.JdbcAdapter;
 import org.apache.cayenne.dba.JdbcPkGenerator;
 import org.apache.cayenne.map.DbEntity;
 
@@ -34,6 +35,17 @@
  */
 public class MySQLPkGenerator extends JdbcPkGenerator {
 
+    /**
+     * @deprecated since 3.0
+     */
+    MySQLPkGenerator(){     
+        super();
+    }
+    
+    MySQLPkGenerator(JdbcAdapter adapter){
+        super(adapter);
+    }
+    
     @Override
     protected String dropAutoPkString() {
         return "DROP TABLE IF EXISTS AUTO_PK_SUPPORT";

Modified: cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/dba/openbase/OpenBaseAdapter.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/dba/openbase/OpenBaseAdapter.java?rev=740245&r1=740244&r2=740245&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/dba/openbase/OpenBaseAdapter.java (original)
+++ cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/dba/openbase/OpenBaseAdapter.java Tue Feb  3 08:29:04 2009
@@ -33,6 +33,7 @@
 import org.apache.cayenne.access.types.ExtendedTypeMap;
 import org.apache.cayenne.dba.JdbcAdapter;
 import org.apache.cayenne.dba.PkGenerator;
+import org.apache.cayenne.dba.QuotingStrategy;
 import org.apache.cayenne.dba.TypesMapping;
 import org.apache.cayenne.map.DbAttribute;
 import org.apache.cayenne.map.DbEntity;
@@ -136,7 +137,7 @@
       */
     @Override
     protected PkGenerator createPkGenerator() {
-        return new OpenBasePkGenerator();
+        return new OpenBasePkGenerator(this);
     }
 
     /**
@@ -145,9 +146,12 @@
       */
     @Override
     public String createTable(DbEntity ent) {
-
+        QuotingStrategy context = getContextQuoteStrategy(ent.getDataMap());
         StringBuilder buf = new StringBuilder();
-        buf.append("CREATE TABLE ").append(ent.getFullyQualifiedName()).append(" (");
+
+        buf.append("CREATE TABLE ");
+        buf.append(context.quoteFullyQualifiedName(ent));
+        buf.append(" (");
 
         // columns
         Iterator<DbAttribute> it = ent.getAttributes().iterator();
@@ -184,7 +188,7 @@
             }
 
             String type = types[0];
-            buf.append(at.getName()).append(' ').append(type);
+            buf.append(context.quoteString(at.getName())).append(' ').append(type);
 
             // append size and precision (if applicable)
             if (TypesMapping.supportsLength(at.getType())) {

Modified: cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/dba/openbase/OpenBasePkGenerator.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/dba/openbase/OpenBasePkGenerator.java?rev=740245&r1=740244&r2=740245&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/dba/openbase/OpenBasePkGenerator.java (original)
+++ cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/dba/openbase/OpenBasePkGenerator.java Tue Feb  3 08:29:04 2009
@@ -32,7 +32,9 @@
 import org.apache.cayenne.CayenneRuntimeException;
 import org.apache.cayenne.access.DataNode;
 import org.apache.cayenne.access.QueryLogger;
+import org.apache.cayenne.dba.JdbcAdapter;
 import org.apache.cayenne.dba.JdbcPkGenerator;
+import org.apache.cayenne.dba.QuotingStrategy;
 import org.apache.cayenne.map.DbAttribute;
 import org.apache.cayenne.map.DbEntity;
 import org.apache.cayenne.util.IDUtil;
@@ -42,6 +44,18 @@
  */
 public class OpenBasePkGenerator extends JdbcPkGenerator {
 
+ 
+    /**
+     * @deprecated since 3.0
+     */
+    protected OpenBasePkGenerator() {
+        super();
+    }
+    
+    protected OpenBasePkGenerator(JdbcAdapter adapter) {
+        super(adapter);
+    }
+
     /**
      * Returns a non-repeating primary key for a given entity. Since OpenBase-specific
      * mechanism is used, key caching is disabled. Instead a database operation is
@@ -277,18 +291,23 @@
                     + "' has no PK defined.");
         }
 
-        StringBuilder buffer = new StringBuilder();
-        buffer.append("CREATE PRIMARY KEY ").append(entity.getName()).append(" (");
+        StringBuilder buffer = new StringBuilder();        
+        buffer.append("CREATE PRIMARY KEY ");
+        QuotingStrategy context = getContextQuoteStrategy(entity.getDataMap());
+        buffer.append(context.quoteString(entity.getName()));
+
+        buffer.append(" (");
 
         Iterator<DbAttribute> it = pk.iterator();
 
         // at this point we know that there is at least on PK column
         DbAttribute firstColumn = it.next();
-        buffer.append(firstColumn.getName());
+        buffer.append(context.quoteString(firstColumn.getName()));
 
         while (it.hasNext()) {
             DbAttribute column = it.next();
-            buffer.append(", ").append(column.getName());
+            buffer.append(", ");
+            buffer.append(context.quoteString(column.getName()));
         }
 
         buffer.append(")");
@@ -301,7 +320,7 @@
      */
     protected String createUniquePKIndexString(DbEntity entity) {
         Collection<DbAttribute> pk = entity.getPrimaryKeys();
-
+        QuotingStrategy context = getContextQuoteStrategy(entity.getDataMap());
         if (pk == null || pk.size() == 0) {
             throw new CayenneRuntimeException("Entity '"
                     + entity.getName()
@@ -312,18 +331,21 @@
 
         // compound PK doesn't work well with UNIQUE index...
         // create a regular one in this case
-        buffer.append(pk.size() == 1 ? "CREATE UNIQUE INDEX " : "CREATE INDEX ").append(
-                entity.getName()).append(" (");
+        buffer.append(pk.size() == 1 ? "CREATE UNIQUE INDEX " : "CREATE INDEX ");
+ 
+        buffer.append(context.quoteString(entity.getName()));
+        buffer.append(" (");
 
         Iterator<DbAttribute> it = pk.iterator();
 
         // at this point we know that there is at least on PK column
         DbAttribute firstColumn = it.next();
-        buffer.append(firstColumn.getName());
+        buffer.append(context.quoteString(firstColumn.getName()));
 
         while (it.hasNext()) {
             DbAttribute column = it.next();
-            buffer.append(", ").append(column.getName());
+            buffer.append(", ");
+            buffer.append(context.quoteString(column.getName()));
         }
         buffer.append(")");
         return buffer.toString();
@@ -347,5 +369,5 @@
     public void setPkCacheSize(int pkCacheSize) {
         // noop, no PK caching
     }
-
+ 
 }

Modified: cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/dba/oracle/OracleAdapter.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/dba/oracle/OracleAdapter.java?rev=740245&r1=740244&r2=740245&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/dba/oracle/OracleAdapter.java (original)
+++ cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/dba/oracle/OracleAdapter.java Tue Feb  3 08:29:04 2009
@@ -43,6 +43,7 @@
 import org.apache.cayenne.access.types.ExtendedType;
 import org.apache.cayenne.access.types.ExtendedTypeMap;
 import org.apache.cayenne.access.types.ShortType;
+import org.apache.cayenne.dba.QuotingStrategy;
 import org.apache.cayenne.dba.JdbcAdapter;
 import org.apache.cayenne.dba.PkGenerator;
 import org.apache.cayenne.map.DbAttribute;
@@ -228,7 +229,7 @@
      */
     @Override
     protected PkGenerator createPkGenerator() {
-        return new OraclePkGenerator();
+        return new OraclePkGenerator(this);
     }
 
     /**
@@ -239,9 +240,12 @@
      */
     @Override
     public Collection<String> dropTableStatements(DbEntity table) {
-        return Collections.singleton("DROP TABLE "
-                + table.getFullyQualifiedName()
-                + " CASCADE CONSTRAINTS");
+        QuotingStrategy context = getContextQuoteStrategy(table.getDataMap());
+        StringBuffer buf = new StringBuffer("DROP TABLE ");
+        buf.append(context.quoteFullyQualifiedName(table));            
+
+        buf.append(" CASCADE CONSTRAINTS");
+        return Collections.singleton(buf.toString() );
     }
 
     @Override

Modified: cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/dba/oracle/OraclePkGenerator.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/dba/oracle/OraclePkGenerator.java?rev=740245&r1=740244&r2=740245&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/dba/oracle/OraclePkGenerator.java (original)
+++ cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/dba/oracle/OraclePkGenerator.java Tue Feb  3 08:29:04 2009
@@ -31,6 +31,8 @@
 import org.apache.cayenne.CayenneRuntimeException;
 import org.apache.cayenne.access.DataNode;
 import org.apache.cayenne.access.QueryLogger;
+import org.apache.cayenne.dba.QuotingStrategy;
+import org.apache.cayenne.dba.JdbcAdapter;
 import org.apache.cayenne.dba.JdbcPkGenerator;
 import org.apache.cayenne.map.DbEntity;
 import org.apache.cayenne.map.DbKeyGenerator;
@@ -53,6 +55,17 @@
  */
 public class OraclePkGenerator extends JdbcPkGenerator {
 
+    /**
+     * @deprecated since 3.0
+     */
+    protected OraclePkGenerator() {
+        super();
+    }
+    
+    protected OraclePkGenerator(JdbcAdapter adapter) {
+        super(adapter);
+    }
+    
     private static final String _SEQUENCE_PREFIX = "pk_";
 
     @Override
@@ -123,6 +136,7 @@
      * primary key generation process for a specific DbEntity.
      */
     protected String dropSequenceString(DbEntity ent) {
+       
         StringBuilder buf = new StringBuilder();
         buf.append("DROP SEQUENCE ").append(sequenceName(ent));
         return buf.toString();
@@ -247,7 +261,7 @@
 
     /** Returns expected primary key sequence name for a DbEntity. */
     protected String sequenceName(DbEntity entity) {
-
+        QuotingStrategy context = getContextQuoteStrategy(entity.getDataMap());
         // use custom generator if possible
         DbKeyGenerator keyGenerator = entity.getPrimaryKeyGenerator();
         if (keyGenerator != null
@@ -261,8 +275,10 @@
             String seqName = _SEQUENCE_PREFIX + entName.toLowerCase();
 
             if (entity.getSchema() != null && entity.getSchema().length() > 0) {
-                seqName = entity.getSchema() + "." + seqName;
-            }
+
+                seqName = context.quoteString(entity.getSchema()) + "." + 
+                context.quoteString(seqName);
+             }
             return seqName;
         }
     }

Modified: cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/dba/postgres/PostgresAdapter.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/dba/postgres/PostgresAdapter.java?rev=740245&r1=740244&r2=740245&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/dba/postgres/PostgresAdapter.java (original)
+++ cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/dba/postgres/PostgresAdapter.java Tue Feb  3 08:29:04 2009
@@ -30,6 +30,7 @@
 import org.apache.cayenne.access.trans.QueryAssembler;
 import org.apache.cayenne.access.types.CharType;
 import org.apache.cayenne.access.types.ExtendedTypeMap;
+import org.apache.cayenne.dba.QuotingStrategy;
 import org.apache.cayenne.dba.JdbcAdapter;
 import org.apache.cayenne.dba.PkGenerator;
 import org.apache.cayenne.dba.TypesMapping;
@@ -120,9 +121,14 @@
      */
     @Override
     public String createTable(DbEntity ent) {
-
+       
+        QuotingStrategy context = getContextQuoteStrategy(ent.getDataMap());
         StringBuilder buf = new StringBuilder();
-        buf.append("CREATE TABLE ").append(ent.getFullyQualifiedName()).append(" (");
+        buf.append("CREATE TABLE ");
+        
+        buf.append(context.quoteFullyQualifiedName(ent)); 
+      
+        buf.append(" (");
 
         // columns
         Iterator<DbAttribute> it = ent.getAttributes().iterator();
@@ -155,7 +161,7 @@
             }
 
             String type = types[0];
-            buf.append(at.getName()).append(' ').append(type);
+            buf.append(context.quoteString(at.getName())).append(' ').append(type);
 
             // append size and precision (if applicable)
             if (typeSupportsLength(at.getType())) {
@@ -203,7 +209,7 @@
                     buf.append(", ");
 
                 DbAttribute at = pkit.next();
-                buf.append(at.getName());
+                buf.append(context.quoteString(at.getName()));
             }
             buf.append(')');
         }
@@ -230,9 +236,11 @@
      */
     @Override
     public Collection<String> dropTableStatements(DbEntity table) {
-        return Collections.singleton("DROP TABLE "
-                + table.getFullyQualifiedName()
-                + " CASCADE");
+        QuotingStrategy context = getContextQuoteStrategy(table.getDataMap());
+        StringBuffer buf = new StringBuffer("DROP TABLE ");
+        buf.append(context.quoteFullyQualifiedName(table));            
+        buf.append(" CASCADE");
+        return Collections.singleton(buf.toString());
     }
 
     /**
@@ -248,7 +256,7 @@
      */
     @Override
     protected PkGenerator createPkGenerator() {
-        return new PostgresPkGenerator();
+        return new PostgresPkGenerator(this);
     }
 
     @Override

Modified: cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/dba/postgres/PostgresPkGenerator.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/dba/postgres/PostgresPkGenerator.java?rev=740245&r1=740244&r2=740245&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/dba/postgres/PostgresPkGenerator.java (original)
+++ cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/dba/postgres/PostgresPkGenerator.java Tue Feb  3 08:29:04 2009
@@ -30,6 +30,7 @@
 import org.apache.cayenne.CayenneRuntimeException;
 import org.apache.cayenne.access.DataNode;
 import org.apache.cayenne.access.QueryLogger;
+import org.apache.cayenne.dba.JdbcAdapter;
 import org.apache.cayenne.dba.oracle.OraclePkGenerator;
 import org.apache.cayenne.map.DbEntity;
 import org.apache.cayenne.map.DbKeyGenerator;
@@ -39,6 +40,17 @@
  */
 public class PostgresPkGenerator extends OraclePkGenerator {
 
+    /**
+     * @deprecated since 3.0
+     */
+    protected PostgresPkGenerator() {
+        super();
+    }
+    
+    protected PostgresPkGenerator(JdbcAdapter adapter) {
+        super(adapter);
+    }
+    
     @Override
     protected String createSequenceString(DbEntity ent) {
         // note that PostgreSQL 7.4 and newer supports INCREMENT BY and START WITH

Modified: cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/dba/sybase/SybasePkGenerator.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/dba/sybase/SybasePkGenerator.java?rev=740245&r1=740244&r2=740245&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/dba/sybase/SybasePkGenerator.java (original)
+++ cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/dba/sybase/SybasePkGenerator.java Tue Feb  3 08:29:04 2009
@@ -28,6 +28,7 @@
 import org.apache.cayenne.CayenneRuntimeException;
 import org.apache.cayenne.access.DataNode;
 import org.apache.cayenne.access.Transaction;
+import org.apache.cayenne.dba.JdbcAdapter;
 import org.apache.cayenne.dba.JdbcPkGenerator;
 import org.apache.cayenne.map.DbEntity;
 
@@ -39,6 +40,17 @@
  */
 public class SybasePkGenerator extends JdbcPkGenerator {
     
+    /**
+     * @deprecated since 3.0
+     */
+    protected SybasePkGenerator() {
+        super();
+    }
+    
+    protected SybasePkGenerator(JdbcAdapter adapter) {
+        super(adapter);
+    }
+    
     @Override
     protected String pkTableCreateString() {
         StringBuilder buf = new StringBuilder();

Modified: cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/map/DataMap.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/map/DataMap.java?rev=740245&r1=740244&r2=740245&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/map/DataMap.java (original)
+++ cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/map/DataMap.java Tue Feb  3 08:29:04 2009
@@ -99,13 +99,18 @@
      * @since 1.1
      */
     public static final String DEFAULT_LOCK_TYPE_PROPERTY = "defaultLockType";
+    
+    public static final String DEFAULT_QUOTE_SQL_IDENTIFIERS_PROPERTY = "quoteSqlIdentifiers";
 
     protected String name;
     protected String location;
     protected MappingNamespace namespace;
 
+    protected Boolean quotingSQLIdentifiers;
+    
     protected String defaultSchema;
     protected String defaultPackage;
+ 
     protected String defaultSuperclass;
     protected int defaultLockType;
 
@@ -123,6 +128,20 @@
     private List<EntityListener> defaultEntityListeners;
 
     /**
+     * @since 3.0
+     */
+    public boolean isQuotingSQLIdentifiers() {
+        return quotingSQLIdentifiers;
+    }
+
+    /**
+     * @since 3.0
+     */
+    public void setQuotingSQLIdentifiers(boolean quotingSqlIdentifiers) {
+        this.quotingSQLIdentifiers = quotingSqlIdentifiers;        
+    }
+    
+    /**
      * Creates a new unnamed DataMap.
      */
     public DataMap() {
@@ -144,7 +163,6 @@
         queryMap = new TreeMap<String, Query>();
         defaultEntityListeners = new ArrayList<EntityListener>(3);
         results = new TreeMap<String, SQLResult>();
-
         setName(mapName);
         initWithProperties(properties);
     }
@@ -168,12 +186,15 @@
         Object clientEntities = properties.get(CLIENT_SUPPORTED_PROPERTY);
         Object clientPackageName = properties.get(DEFAULT_CLIENT_PACKAGE_PROPERTY);
         Object clientSuperclass = properties.get(DEFAULT_CLIENT_SUPERCLASS_PROPERTY);
+        Object quoteSqlIdentifier = properties.get(DEFAULT_QUOTE_SQL_IDENTIFIERS_PROPERTY);
 
         this.defaultLockType = "optimistic".equals(lockType)
                 ? ObjEntity.LOCK_TYPE_OPTIMISTIC
                 : ObjEntity.LOCK_TYPE_NONE;
 
         this.defaultPackage = (packageName != null) ? packageName.toString() : null;
+        this.quotingSQLIdentifiers = (quoteSqlIdentifier!=null) ? "true"
+                .equalsIgnoreCase(quoteSqlIdentifier.toString()) : false;
         this.defaultSchema = (schema != null) ? schema.toString() : null;
         this.defaultSuperclass = (superclass != null) ? superclass.toString() : null;
         this.clientSupported = (clientEntities != null) ? "true"
@@ -239,7 +260,7 @@
      */
     public void encodeAsXML(XMLEncoder encoder) {
         encoder.print("<data-map project-version=\"");
-        encoder.print(String.valueOf(Project.CURRENT_PROJECT_VERSION));
+        encoder.print(String.valueOf(Project.CURRENT_PROJECT_VERSION));        
         encoder.println("\">");
 
         encoder.indent(1);
@@ -260,6 +281,10 @@
         if (!Util.isEmptyString(defaultSuperclass)) {
             encoder.printProperty(DEFAULT_SUPERCLASS_PROPERTY, defaultSuperclass);
         }
+        
+        if (quotingSQLIdentifiers) {
+            encoder.printProperty(DEFAULT_QUOTE_SQL_IDENTIFIERS_PROPERTY, quotingSQLIdentifiers);
+        }
 
         if (clientSupported) {
             encoder.printProperty(CLIENT_SUPPORTED_PROPERTY, "true");

Modified: cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/CayenneContextSQLTemplateTest.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/CayenneContextSQLTemplateTest.java?rev=740245&r1=740244&r2=740245&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/CayenneContextSQLTemplateTest.java (original)
+++ cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/CayenneContextSQLTemplateTest.java Tue Feb  3 08:29:04 2009
@@ -20,7 +20,6 @@
 
 import org.apache.cayenne.access.ClientServerChannel;
 import org.apache.cayenne.query.SQLTemplate;
-import org.apache.cayenne.query.SelectQuery;
 import org.apache.cayenne.remote.ClientChannel;
 import org.apache.cayenne.remote.service.LocalConnection;
 import org.apache.cayenne.testdo.mt.ClientMtTable1;
@@ -31,11 +30,20 @@
 public class CayenneContextSQLTemplateTest extends CayenneCase {
 
     @Override
+    protected void setUp() throws Exception {
+        super.setUp();
+        getDomain().getSharedSnapshotCache().clear();
+        getDomain().getQueryCache().clear();
+        deleteTestData();
+    }
+
+    @Override
     protected AccessStack buildAccessStack() {
         return CayenneResources.getResources().getAccessStack(MULTI_TIER_ACCESS_STACK);
     }
 
     private CayenneContext createClientContext() {
+
         ClientServerChannel serverChannel = new ClientServerChannel(getDomain());
         LocalConnection connection = new LocalConnection(
                 serverChannel,
@@ -46,8 +54,6 @@
 
     public void testObjectRoot() throws Exception {
 
-        deleteTestData();
-
         CayenneContext context = createClientContext();
 
         assertNull(DataObjectUtils.objectForPK(context, ClientMtTable1.class, 1));



Mime
View raw message