cayenne-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From aadamc...@apache.org
Subject svn commit: r825594 - in /cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src: main/java/org/apache/cayenne/access/ main/java/org/apache/cayenne/dba/db2/ main/java/org/apache/cayenne/dba/derby/ main/java/org/apache/cayenne/dba/h2/ main/java/org...
Date Thu, 15 Oct 2009 18:03:47 GMT
Author: aadamchik
Date: Thu Oct 15 18:03:46 2009
New Revision: 825594

URL: http://svn.apache.org/viewvc?rev=825594&view=rev
Log:
CAY-1293 Beta 1 Test Failures

Modified:
    cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/access/FlattenedArcKey.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/derby/DerbyAdapter.java
    cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/dba/h2/H2MergerFactory.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/MySQLMergerFactory.java
    cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/dba/oracle/OracleQualifierTranslator.java
    cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/dba/oracle/OracleSelectTranslator.java
    cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/dba/sybase/SybaseAdapter.java
    cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/dba/sybase/SybaseMergerFactory.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/merge/MergeCase.java

Modified: cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/access/FlattenedArcKey.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/access/FlattenedArcKey.java?rev=825594&r1=825593&r2=825594&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/access/FlattenedArcKey.java
(original)
+++ cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/access/FlattenedArcKey.java
Thu Oct 15 18:03:46 2009
@@ -165,7 +165,9 @@
 
         int i = pk.size();
         for (DbAttribute attribute : joinEntity.getPrimaryKeys()) {
+            sql.append("#result('");
             sql.append(attribute.getName());
+            sql.append("')");
             if (--i > 0) {
                 sql.append(", ");
             }

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=825594&r1=825593&r2=825594&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
Thu Oct 15 18:03:46 2009
@@ -20,6 +20,8 @@
 package org.apache.cayenne.dba.db2;
 
 import java.sql.PreparedStatement;
+import java.sql.SQLException;
+import java.sql.Types;
 import java.util.Iterator;
 
 import org.apache.cayenne.CayenneRuntimeException;
@@ -37,28 +39,25 @@
 import org.apache.cayenne.map.DbEntity;
 import org.apache.cayenne.merge.MergerFactory;
 
-
 /**
  * DbAdapter implementation for the <a href="http://www.ibm.com/db2/"> DB2 RDBMS </a>.
  * Sample connection settings to use with DB2 are shown below:
  * 
  * <pre>
- *  
+ * 
  *       test-db2.cayenne.adapter = org.apache.cayenne.dba.db2.DB2Adapter
  *       test-db2.jdbc.username = test
  *       test-db2.jdbc.password = secret
  *       test-db2.jdbc.url = jdbc:db2://servername:50000/databasename
  *       test-db2.jdbc.driver = com.ibm.db2.jcc.DB2Driver
- *   
- * </pre>
  * 
+ * </pre>
  */
 public class DB2Adapter extends JdbcAdapter {
 
-    
     /**
-     * Creates a DB2 specific PK Generator.    
-     */   
+     * Creates a DB2 specific PK Generator.
+     */
     protected PkGenerator createPkGenerator() {
         return new DB2PkGenerator(this);
     }
@@ -83,16 +82,17 @@
     @Override
     public String createTable(DbEntity ent) {
         boolean status;
-        if(ent.getDataMap()!=null && ent.getDataMap().isQuotingSQLIdentifiers()){

-            status= true;
-        } else {
+        if (ent.getDataMap() != null && ent.getDataMap().isQuotingSQLIdentifiers())
{
+            status = true;
+        }
+        else {
             status = false;
         }
         QuotingStrategy context = getQuotingStrategy(status);
-        
+
         StringBuilder buf = new StringBuilder();
         buf.append("CREATE TABLE ");
-        buf.append(context.quoteFullyQualifiedName(ent)); 
+        buf.append(context.quoteFullyQualifiedName(ent));
 
         buf.append(" (");
 
@@ -206,8 +206,26 @@
             }
         }
     }
+
     @Override
     public MergerFactory mergerFactory() {
         return new DB2MergerFactory();
     }
+
+    @Override
+    public void bindParameter(
+            PreparedStatement statement,
+            Object object,
+            int pos,
+            int sqlType,
+            int precision) throws SQLException, Exception {
+
+        if (object == null && (sqlType == 0 || sqlType == Types.BOOLEAN)) {
+            statement.setNull(pos, Types.VARCHAR);
+        }
+        else {
+            super.bindParameter(statement, object, pos, sqlType, precision);
+        }
+    }
+
 }

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=825594&r1=825593&r2=825594&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
Thu Oct 15 18:03:46 2009
@@ -20,6 +20,8 @@
 
 package org.apache.cayenne.dba.derby;
 
+import java.sql.PreparedStatement;
+import java.sql.SQLException;
 import java.sql.Types;
 
 import org.apache.cayenne.CayenneRuntimeException;
@@ -191,5 +193,22 @@
     public MergerFactory mergerFactory() {
         return new DerbyMergerFactory();
     }
+    
+    @Override
+    public void bindParameter(
+        PreparedStatement statement,
+        Object object,
+        int pos,
+        int sqlType,
+        int precision)
+        throws SQLException, Exception {
+
+        if (object == null && sqlType==0) {
+            statement.setNull(pos, Types.VARCHAR);
+        }
+        else {
+            super.bindParameter(statement, object, pos, sqlType, precision);
+        }
+    }
 
 }

Modified: cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/dba/h2/H2MergerFactory.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/dba/h2/H2MergerFactory.java?rev=825594&r1=825593&r2=825594&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/dba/h2/H2MergerFactory.java
(original)
+++ cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/dba/h2/H2MergerFactory.java
Thu Oct 15 18:03:46 2009
@@ -19,6 +19,7 @@
 
 package org.apache.cayenne.dba.h2;
 
+import java.util.Collection;
 import java.util.Collections;
 import java.util.List;
 
@@ -30,6 +31,7 @@
 import org.apache.cayenne.merge.MergerToken;
 import org.apache.cayenne.merge.SetAllowNullToDb;
 import org.apache.cayenne.merge.SetColumnTypeToDb;
+import org.apache.cayenne.merge.SetPrimaryKeyToDb;
 
 /**
  * @since 3.0
@@ -73,4 +75,29 @@
 
         };
     }
+    
+    @Override
+    public MergerToken createSetPrimaryKeyToDb(
+            DbEntity entity,
+            Collection<DbAttribute> primaryKeyOriginal,
+            Collection<DbAttribute> primaryKeyNew,
+            String detectedPrimaryKeyName) {
+        return new SetPrimaryKeyToDb(
+                entity,
+                primaryKeyOriginal,
+                primaryKeyNew,
+                detectedPrimaryKeyName) {
+
+            @Override
+            protected void appendDropOriginalPrimaryKeySQL(
+                    DbAdapter adapter,
+                    List<String> sqls) {
+                sqls.add("ALTER TABLE "
+                        + getQuotingStrategy(adapter)
+                                .quoteFullyQualifiedName(getEntity())
+                        + " DROP PRIMARY KEY");
+            }
+
+        };
+    }
 }

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=825594&r1=825593&r2=825594&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
Thu Oct 15 18:03:46 2009
@@ -45,8 +45,8 @@
 import org.apache.cayenne.query.SQLAction;
 
 /**
- * DbAdapter implementation for <a href="http://www.mysql.com">MySQL RDBMS</a>.
- * <h3>Foreign Key Constraint Handling</h3>
+ * DbAdapter implementation for <a href="http://www.mysql.com">MySQL RDBMS</a>.
<h3>
+ * Foreign Key Constraint Handling</h3>
  * <p>
  * Foreign key constraints are supported by InnoDB engine and NOT supported by MyISAM
  * engine. This adapter by default assumes MyISAM, so
@@ -54,41 +54,40 @@
  * Users can manually change this by calling <em>setSupportsFkConstraints(true)</em>
or
  * better by using an {@link org.apache.cayenne.dba.AutoAdapter}, i.e. not entering the
  * adapter name at all for the DataNode, letting Cayenne guess it in runtime. In the later
- * case Cayenne will check the <em>table_type</em> MySQL variable to detect whether
- * InnoDB is the default, and configure the adapter accordingly.
+ * case Cayenne will check the <em>table_type</em> MySQL variable to detect whether
InnoDB
+ * is the default, and configure the adapter accordingly.
  * <h3>Sample Connection Settings</h3>
  * <ul>
  * <li>Adapter name: org.apache.cayenne.dba.mysql.MySQLAdapter</li>
  * <li>DB URL: jdbc:mysql://serverhostname/dbname</li>
  * <li>Driver Class: com.mysql.jdbc.Driver</li>
  * </ul>
- * 
  */
 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); 
-        initIdentifiersQuotes(); 
+        setSupportsGeneratedKeys(true);
+        initIdentifiersQuotes();
     }
- 
+
     @Override
-    public void initIdentifiersQuotes(){
+    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.
      * 
@@ -105,9 +104,11 @@
      */
     @Override
     public String dropTable(DbEntity table) {
-        QuotingStrategy context = getQuotingStrategy(table.getDataMap().isQuotingSQLIdentifiers());

+        QuotingStrategy context = getQuotingStrategy(table
+                .getDataMap()
+                .isQuotingSQLIdentifiers());
         StringBuffer buf = new StringBuffer("DROP TABLE IF EXISTS ");
-        buf.append(context.quoteFullyQualifiedName(table));            
+        buf.append(context.quoteFullyQualifiedName(table));
         buf.append(" CASCADE");
         return buf.toString();
     }
@@ -120,9 +121,11 @@
         // 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 = getQuotingStrategy(table.getDataMap().isQuotingSQLIdentifiers());
-        buf.append(context.quoteFullyQualifiedName(table));            
-        
+        QuotingStrategy context = getQuotingStrategy(table
+                .getDataMap()
+                .isQuotingSQLIdentifiers());
+        buf.append(context.quoteFullyQualifiedName(table));
+
         return Arrays.asList("SET FOREIGN_KEY_CHECKS=0", "DROP TABLE IF EXISTS "
                 + buf.toString()
                 + " CASCADE", "SET FOREIGN_KEY_CHECKS=1");
@@ -225,7 +228,7 @@
     @Override
     public String createTable(DbEntity entity) {
         String ddlSQL = super.createTable(entity);
-        
+
         if (storageEngine != null) {
             ddlSQL += " ENGINE=" + storageEngine;
         }
@@ -244,11 +247,12 @@
     @Override
     protected void createTableAppendPKClause(StringBuffer sqlBuffer, DbEntity entity) {
         boolean status;
-            if(entity.getDataMap()!=null && entity.getDataMap().isQuotingSQLIdentifiers()){

-                status= true;
-            } else {
-                status = false;
-            }
+        if (entity.getDataMap() != null && entity.getDataMap().isQuotingSQLIdentifiers())
{
+            status = true;
+        }
+        else {
+            status = false;
+        }
         QuotingStrategy context = getQuotingStrategy(status);
         // must move generated to the front...
         List<DbAttribute> pkList = new ArrayList<DbAttribute>(entity.getPrimaryKeys());
@@ -291,7 +295,8 @@
 
                     while (columns.hasNext()) {
                         column = columns.next();
-                        sqlBuffer.append(", ").append( context.quoteString(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/MySQLMergerFactory.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/dba/mysql/MySQLMergerFactory.java?rev=825594&r1=825593&r2=825594&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/dba/mysql/MySQLMergerFactory.java
(original)
+++ cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/dba/mysql/MySQLMergerFactory.java
Thu Oct 15 18:03:46 2009
@@ -18,6 +18,7 @@
  ****************************************************************/
 package org.apache.cayenne.dba.mysql;
 
+import java.util.Collection;
 import java.util.Collections;
 import java.util.List;
 
@@ -32,6 +33,7 @@
 import org.apache.cayenne.merge.SetAllowNullToDb;
 import org.apache.cayenne.merge.SetColumnTypeToDb;
 import org.apache.cayenne.merge.SetNotNullToDb;
+import org.apache.cayenne.merge.SetPrimaryKeyToDb;
 
 public class MySQLMergerFactory extends MergerFactory {
 
@@ -138,4 +140,29 @@
             }
         };
     }
+    
+    @Override
+    public MergerToken createSetPrimaryKeyToDb(
+            DbEntity entity,
+            Collection<DbAttribute> primaryKeyOriginal,
+            Collection<DbAttribute> primaryKeyNew,
+            String detectedPrimaryKeyName) {
+        return new SetPrimaryKeyToDb(
+                entity,
+                primaryKeyOriginal,
+                primaryKeyNew,
+                detectedPrimaryKeyName) {
+
+            @Override
+            protected void appendDropOriginalPrimaryKeySQL(
+                    DbAdapter adapter,
+                    List<String> sqls) {
+                sqls.add("ALTER TABLE "
+                        + getQuotingStrategy(adapter)
+                                .quoteFullyQualifiedName(getEntity())
+                        + " DROP PRIMARY KEY");
+            }
+
+        };
+    }
 }

Modified: cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/dba/oracle/OracleQualifierTranslator.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/dba/oracle/OracleQualifierTranslator.java?rev=825594&r1=825593&r2=825594&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/dba/oracle/OracleQualifierTranslator.java
(original)
+++ cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/dba/oracle/OracleQualifierTranslator.java
Thu Oct 15 18:03:46 2009
@@ -1,99 +1,111 @@
-/*****************************************************************
- *   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.oracle;
-
-import java.io.IOException;
-import java.util.ArrayList;
-import java.util.List;
-
-import org.apache.cayenne.access.trans.QueryAssembler;
-import org.apache.cayenne.access.trans.TrimmingQualifierTranslator;
-import org.apache.cayenne.exp.Expression;
-import org.apache.cayenne.exp.parser.ASTIn;
-import org.apache.cayenne.exp.parser.ASTList;
-import org.apache.cayenne.exp.parser.ASTNegate;
-import org.apache.cayenne.exp.parser.ASTNotIn;
-import org.apache.cayenne.exp.parser.ASTPath;
-import org.apache.commons.collections.Transformer;
-
-/**
- * Oracle qualifier translator. In particular, trims INs with more than 1000 elements 
- * to an OR-set of INs with <= 1000 elements 
- */
-public class OracleQualifierTranslator extends TrimmingQualifierTranslator {
-
-    public OracleQualifierTranslator(QueryAssembler queryAssembler) {
-        super(queryAssembler, OracleAdapter.TRIM_FUNCTION);
-    }
-
-    @Override
-    protected void doAppendPart(Expression rootNode) throws IOException {
-        if (rootNode == null) {
-            return;
-        }
-        
-        //trimming INs
-        rootNode = rootNode.transform(new INTrimmer());
-        
-        rootNode.traverse(this);
-    }
-    
-    public static class INTrimmer implements Transformer {
-        public Expression trimmedInExpression(Expression exp, int maxInSize) {
-            Expression list = (Expression) exp.getOperand(1);
-            Object[] objects = (Object[]) list.evaluate(null);
-            
-            if (objects.length <= maxInSize) {
-                return exp;
-            }
-            
-            Expression trimmed = trimmedInExpression((ASTPath) exp.getOperand(0), objects,
maxInSize);
-            if (exp instanceof ASTNotIn) {
-                return new ASTNegate(trimmed);
-            }
-            return trimmed;
-        }
-        
-        Expression trimmedInExpression(ASTPath path, Object[] values, int maxInSize) {
-            Expression res = null;
-            
-            List<Object> in = new ArrayList<Object>(maxInSize);
-            for (Object v : values) {
-                in.add(v);
-                if (in.size() == maxInSize) {
-                    Expression inExp = new ASTIn(path, new ASTList(in));
-                    res = res != null ? res.orExp(inExp) : inExp;
-                    in = new ArrayList<Object>(maxInSize);
-                }
-            }
-            if (in.size() > 0) {
-                Expression inExp = new ASTIn(path, new ASTList(in));
-                res = res != null ? res.orExp(inExp) : inExp;
-            }
-            return res;
-        }
-
-        public Object transform(Object input) {
-            if (input instanceof ASTIn || input instanceof ASTNotIn) {
-                return trimmedInExpression((Expression) input, 1000);
-            }
-            return input;
-        }
-    }
-}
+/*****************************************************************
+ *   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.oracle;
+
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.List;
+
+import org.apache.cayenne.access.trans.QueryAssembler;
+import org.apache.cayenne.access.trans.TrimmingQualifierTranslator;
+import org.apache.cayenne.exp.Expression;
+import org.apache.cayenne.exp.parser.ASTIn;
+import org.apache.cayenne.exp.parser.ASTList;
+import org.apache.cayenne.exp.parser.ASTNegate;
+import org.apache.cayenne.exp.parser.ASTNot;
+import org.apache.cayenne.exp.parser.ASTNotIn;
+import org.apache.cayenne.exp.parser.ASTPath;
+import org.apache.commons.collections.Transformer;
+
+/**
+ * Oracle qualifier translator. In particular, trims INs with more than 1000 elements 
+ * to an OR-set of INs with <= 1000 elements 
+ */
+public class OracleQualifierTranslator extends TrimmingQualifierTranslator {
+
+    public OracleQualifierTranslator(QueryAssembler queryAssembler) {
+        super(queryAssembler, OracleAdapter.TRIM_FUNCTION);
+    }
+
+    @Override
+    protected void doAppendPart(Expression rootNode) throws IOException {
+        if (rootNode == null) {
+            return;
+        }
+
+        boolean isNot = false;
+        if (rootNode instanceof ASTNot) {
+            if (rootNode.getOperandCount() == 1) {
+                rootNode = ((Expression) rootNode.getOperand(0));
+                isNot = true;
+            }
+        }
+
+        rootNode = rootNode.transform(new INTrimmer());
+
+        if (isNot) {
+            rootNode = rootNode.notExp();
+        }
+
+        rootNode.traverse(this);
+    }
+    
+    public static class INTrimmer implements Transformer {
+        public Expression trimmedInExpression(Expression exp, int maxInSize) {
+            Expression list = (Expression) exp.getOperand(1);
+            Object[] objects = (Object[]) list.evaluate(null);
+            
+            if (objects.length <= maxInSize) {
+                return exp;
+            }
+            
+            Expression trimmed = trimmedInExpression((ASTPath) exp.getOperand(0), objects,
maxInSize);
+            if (exp instanceof ASTNotIn) {
+                return new ASTNegate(trimmed);
+            }
+            return trimmed;
+        }
+        
+        Expression trimmedInExpression(ASTPath path, Object[] values, int maxInSize) {
+            Expression res = null;
+            
+            List<Object> in = new ArrayList<Object>(maxInSize);
+            for (Object v : values) {
+                in.add(v);
+                if (in.size() == maxInSize) {
+                    Expression inExp = new ASTIn(path, new ASTList(in));
+                    res = res != null ? res.orExp(inExp) : inExp;
+                    in = new ArrayList<Object>(maxInSize);
+                }
+            }
+            if (in.size() > 0) {
+                Expression inExp = new ASTIn(path, new ASTList(in));
+                res = res != null ? res.orExp(inExp) : inExp;
+            }
+            return res;
+        }
+
+        public Object transform(Object input) {
+            if (input instanceof ASTIn || input instanceof ASTNotIn) {
+                return trimmedInExpression((Expression) input, 1000);
+            }
+            return input;
+        }
+    }
+}

Modified: cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/dba/oracle/OracleSelectTranslator.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/dba/oracle/OracleSelectTranslator.java?rev=825594&r1=825593&r2=825594&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/dba/oracle/OracleSelectTranslator.java
(original)
+++ cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/dba/oracle/OracleSelectTranslator.java
Thu Oct 15 18:03:46 2009
@@ -23,7 +23,6 @@
 
 import org.apache.cayenne.access.QueryLogger;
 import org.apache.cayenne.access.trans.SelectTranslator;
-import org.apache.cayenne.query.QueryMetadata;
 
 /**
  * Select translator that implements Oracle-specific optimizations.

Modified: cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/dba/sybase/SybaseAdapter.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/dba/sybase/SybaseAdapter.java?rev=825594&r1=825593&r2=825594&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/dba/sybase/SybaseAdapter.java
(original)
+++ cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/dba/sybase/SybaseAdapter.java
Thu Oct 15 18:03:46 2009
@@ -117,8 +117,13 @@
                 sqlType = Types.VARBINARY;
             }
         }
-
-        super.bindParameter(statement, object, pos, sqlType, precision);
+        
+        if (object == null && sqlType==0) {
+            statement.setNull(pos, Types.VARCHAR);
+        }
+        else {
+            super.bindParameter(statement, object, pos, sqlType, precision);
+        }
     }
     
     @Override

Modified: cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/dba/sybase/SybaseMergerFactory.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/dba/sybase/SybaseMergerFactory.java?rev=825594&r1=825593&r2=825594&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/dba/sybase/SybaseMergerFactory.java
(original)
+++ cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/dba/sybase/SybaseMergerFactory.java
Thu Oct 15 18:03:46 2009
@@ -55,8 +55,12 @@
                 sqlBuffer.append("ALTER TABLE ");
                 sqlBuffer.append(context.quoteFullyQualifiedName(getEntity()));
                 sqlBuffer.append(" ADD ");
-
+                boolean magnatory = column.isMandatory();
+                column.setMandatory(false);
                 adapter.createTableAppendColumn(sqlBuffer, column);
+                if(magnatory){
+                    column.setMandatory(magnatory);
+                }
                 return Collections.singletonList(sqlBuffer.toString());
             }
 

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=825594&r1=825593&r2=825594&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
Thu Oct 15 18:03:46 2009
@@ -191,14 +191,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);
+        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"
+        this.quotingSQLIdentifiers = (quoteSqlIdentifier != null) ? "true"
                 .equalsIgnoreCase(quoteSqlIdentifier.toString()) : false;
         this.defaultSchema = (schema != null) ? schema.toString() : null;
         this.defaultSuperclass = (superclass != null) ? superclass.toString() : null;
@@ -264,9 +265,14 @@
      * @since 1.1
      */
     public void encodeAsXML(XMLEncoder encoder) {
-        encoder.println("<data-map xmlns=\"http://cayenne.apache.org/schema/3.0/modelMap\"");
+        encoder
+                .println("<data-map xmlns=\"http://cayenne.apache.org/schema/3.0/modelMap\"");
         encoder.println("  xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"");
-        encoder.println("  xsi:schemaLocation=\"" + SCHEMA_XSD + " " + SCHEMA_XSD + ".xsd\"");
+        encoder.println("  xsi:schemaLocation=\""
+                + SCHEMA_XSD
+                + " "
+                + SCHEMA_XSD
+                + ".xsd\"");
         encoder.println("  project-version=\"" + Project.CURRENT_PROJECT_VERSION + "\">");
 
         encoder.indent(1);
@@ -287,9 +293,11 @@
         if (!Util.isEmptyString(defaultSuperclass)) {
             encoder.printProperty(DEFAULT_SUPERCLASS_PROPERTY, defaultSuperclass);
         }
-        
+
         if (quotingSQLIdentifiers) {
-            encoder.printProperty(DEFAULT_QUOTE_SQL_IDENTIFIERS_PROPERTY, quotingSQLIdentifiers);
+            encoder.printProperty(
+                    DEFAULT_QUOTE_SQL_IDENTIFIERS_PROPERTY,
+                    quotingSQLIdentifiers);
         }
 
         if (clientSupported) {
@@ -904,11 +912,16 @@
 
             // Remove all obj relationships referencing removed DbRelationships.
             for (ObjEntity objEnt : this.getObjEntities()) {
-                if (objEnt.getDbEntity() == dbEntityToDelete) {
+                if (dbEntityToDelete.getName().equals(objEnt.getDbEntityName())) {
                     objEnt.clearDbMapping();
                 }
                 else {
                     for (Relationship rel : objEnt.getRelationships()) {
+                                               
+                        if (getObjEntity(rel.getTargetEntityName()).getDbEntityName() ==
null) {
+                            objEnt.clearDbMapping();
+                            break;
+                        }
                         for (DbRelationship dbRel : ((ObjRelationship) rel)
                                 .getDbRelationships()) {
                             if (dbRel.getTargetEntity() == dbEntityToDelete) {

Modified: cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/merge/MergeCase.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/merge/MergeCase.java?rev=825594&r1=825593&r2=825594&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/merge/MergeCase.java
(original)
+++ cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/merge/MergeCase.java
Thu Oct 15 18:03:46 2009
@@ -117,18 +117,15 @@
      */
     private void filterDataMap(DataNode node, DataMap map) {
         // copied from AbstractAccessStack.dbEntitiesInInsertOrder
-        boolean excludeLOB = !getAccessStackAdapter().supportsLobs();
-        boolean excludeBinPK = !getAccessStackAdapter().supportsBinaryPK();
+        boolean excludeBinPK = getAccessStackAdapter().supportsBinaryPK();
 
-        if (!(excludeLOB || excludeBinPK)) {
+        if (!excludeBinPK) { 
             return;
         }
 
         List<DbEntity> entitiesToRemove = new ArrayList<DbEntity>();
 
         for (DbEntity ent : map.getDbEntities()) {
-
-            if (excludeBinPK) {
                 for (DbAttribute attr : ent.getAttributes()) {
                     // check for BIN PK or FK to BIN Pk
                     if (attr.getType() == Types.BINARY
@@ -140,8 +137,6 @@
                             break;
                         }
                     }
-                }
-
             }
         }
 



Mime
View raw message