openjpa-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ppod...@apache.org
Subject svn commit: r880922 - in /openjpa/trunk: openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/ openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/meta/ openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/schema/ openjpa-jdbc/src/main/java/org/apach...
Date Mon, 16 Nov 2009 19:34:13 GMT
Author: ppoddar
Date: Mon Nov 16 19:34:11 2009
New Revision: 880922

URL: http://svn.apache.org/viewvc?rev=880922&view=rev
Log:
OPENJPA-1387: Revert unique colum related changes to before 880685 plus other changes after
that related to OPENJPA-1051 and OPENJPA-1381.

Modified:
    openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/TableJDBCSeq.java
    openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/meta/MappingTool.java
    openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/schema/Constraint.java
    openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/schema/LocalConstraint.java
    openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/schema/NameSet.java
    openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/schema/SchemaTool.java
    openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/schema/Table.java
    openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/schema/Unique.java
    openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/AbstractDB2Dictionary.java
    openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/DBDictionary.java
    openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/sqlcache/TestPreparedQueryCache.java
    openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/QueryImpl.java

Modified: openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/TableJDBCSeq.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/TableJDBCSeq.java?rev=880922&r1=880921&r2=880922&view=diff
==============================================================================
--- openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/TableJDBCSeq.java
(original)
+++ openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/TableJDBCSeq.java
Mon Nov 16 19:34:11 2009
@@ -260,7 +260,7 @@
             // importTable() does not import unique constraints
             Unique[] uniques = _pkColumn.getTable().getUniques();
             for (Unique u : uniques) {
-            	copy.importUnique(u, _conf.getDBDictionaryInstance());
+            	copy.importUnique(u);
             }
             // we need to reset the table name in the column with the
             // fully qualified name for matching the table name from the

Modified: openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/meta/MappingTool.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/meta/MappingTool.java?rev=880922&r1=880921&r2=880922&view=diff
==============================================================================
--- openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/meta/MappingTool.java
(original)
+++ openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/meta/MappingTool.java
Mon Nov 16 19:34:11 2009
@@ -46,7 +46,6 @@
 import org.apache.openjpa.jdbc.schema.SchemaSerializer;
 import org.apache.openjpa.jdbc.schema.SchemaTool;
 import org.apache.openjpa.jdbc.schema.Table;
-import org.apache.openjpa.jdbc.schema.Unique;
 import org.apache.openjpa.jdbc.schema.XMLSchemaSerializer;
 import org.apache.openjpa.jdbc.sql.DBDictionary;
 import org.apache.openjpa.kernel.Seq;
@@ -754,7 +753,6 @@
         Schema[] schemas = _schema.getSchemas();
         Table[] tables;
         Column[] cols;
-        Unique[] unqs;
         for (int i = 0; i < schemas.length; i++) {
             tables = schemas[i].getTables();
             for (int j = 0; j < tables.length; j++) {
@@ -763,17 +761,8 @@
 
                 tables[j].getPrimaryKey().setLogical(false);
                 cols = tables[j].getPrimaryKey().getColumns();
-                for (int k = 0; k < cols.length; k++) {
+                for (int k = 0; k < cols.length; k++)
                     cols[k].setNotNull(true);
-                }
-                unqs = tables[j].getUniques();
-                if (!_dict.supportsNullUniqueConlumn) {
-                    for (Unique u : unqs) {
-                        for (Column c : u.getColumns()) {
-                            c.setNotNull(true);
-                        }
-                    }
-                }
             }
         }
     }

Modified: openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/schema/Constraint.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/schema/Constraint.java?rev=880922&r1=880921&r2=880922&view=diff
==============================================================================
--- openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/schema/Constraint.java
(original)
+++ openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/schema/Constraint.java
Mon Nov 16 19:34:11 2009
@@ -24,7 +24,6 @@
  *
  * @author Abe White
  */
-@SuppressWarnings("serial")
 public abstract class Constraint
     extends ReferenceCounter {
 
@@ -181,6 +180,9 @@
     public String toString() {
         if (getName() != null)
             return getName();
-        return "<" + getClass().getSimpleName().toLowerCase() + ">";
+
+        String name = getClass().getName();
+        name = name.substring(name.lastIndexOf('.') + 1);
+        return "<" + name.toLowerCase() + ">";
     }
 }

Modified: openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/schema/LocalConstraint.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/schema/LocalConstraint.java?rev=880922&r1=880921&r2=880922&view=diff
==============================================================================
--- openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/schema/LocalConstraint.java
(original)
+++ openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/schema/LocalConstraint.java
Mon Nov 16 19:34:11 2009
@@ -21,6 +21,7 @@
 import java.util.ArrayList;
 import java.util.List;
 
+import org.apache.commons.lang.ObjectUtils;
 import org.apache.openjpa.lib.util.Localizer;
 import org.apache.openjpa.util.InvalidStateException;
 
@@ -31,13 +32,13 @@
  *
  * @author Abe White
  */
-@SuppressWarnings("serial")
 public abstract class LocalConstraint
     extends Constraint {
 
-    private static final Localizer _loc = Localizer.forPackage(LocalConstraint.class);
+    private static final Localizer _loc = Localizer.forPackage
+        (LocalConstraint.class);
 
-    private List<Column> _colList = null;
+    private List _colList = null;
     private Column[] _cols = null;
 
     /**
@@ -98,7 +99,7 @@
                 col == null ? null : getTable()));
     	
         if (_colList == null)
-            _colList = new ArrayList<Column>(3);
+            _colList = new ArrayList(3);
         else if (_colList.contains(col))
             return;
 
@@ -123,7 +124,7 @@
     }
 
     /**
-     * Return true if this constraint includes the given column.
+     * Return true if the pk includes the given column.
      */
     public boolean containsColumn(Column col) {
         if (col == null || _colList == null)
@@ -132,7 +133,7 @@
     }
 
     /**
-     * Reference all columns in this constraint.
+     * Ref all columns in this constraint.
      */
     public void refColumns() {
         Column[] cols = getColumns();
@@ -141,7 +142,7 @@
     }
 
     /**
-     * Dereference all columns in this constraint.
+     * Deref all columns in this constraint.
      */
     public void derefColumns() {
         Column[] cols = getColumns();

Modified: openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/schema/NameSet.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/schema/NameSet.java?rev=880922&r1=880921&r2=880922&view=diff
==============================================================================
--- openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/schema/NameSet.java (original)
+++ openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/schema/NameSet.java Mon
Nov 16 19:34:11 2009
@@ -39,13 +39,17 @@
 
     private Set _names = null;
 
+    // an additional names Set for checking name duplication
+    private Set _subNames = null;
+
     /**
      * Return true if the given name is in use already.
      */
     public boolean isNameTaken(String name) {
         if (name == null)
             return true;
-        return _names != null && _names.contains(name.toUpperCase());
+        return (_names != null && _names.contains(name.toUpperCase())) ||
+            (_subNames != null && _subNames.contains(name.toUpperCase()));
     }
 
     /**
@@ -77,4 +81,20 @@
         if (name != null && _names != null)
             _names.remove(name.toUpperCase());
     }
+
+    /**
+    * Attempt to add the given name to the set.
+    *
+    * @param name the name to add
+    */
+    protected void addSubName(String name) {
+        if (_subNames == null) {
+            _subNames = new HashSet();
+        }
+        _subNames.add(name.toUpperCase());
+    }
+
+    protected void resetSubNames() {
+        _subNames = null;
+    }
 }

Modified: openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/schema/SchemaTool.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/schema/SchemaTool.java?rev=880922&r1=880921&r2=880922&view=diff
==============================================================================
--- openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/schema/SchemaTool.java
(original)
+++ openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/schema/SchemaTool.java
Mon Nov 16 19:34:11 2009
@@ -590,7 +590,7 @@
                 if (dbTable == null)
                     continue;
                 for (int k = 0; k < uniques.length; k++) {
-                    dbTable.importUnique(uniques[k], _dict);
+                    dbTable.importUnique(uniques[k]);
                 }
             }
         }
@@ -957,11 +957,7 @@
      */
     public boolean createTable(Table table)
         throws SQLException {
-        try {   
-            return executeSQL(_dict.getCreateTableSQL(table));
-        } catch (SQLException e) {
-            return false;
-        }
+        return executeSQL(_dict.getCreateTableSQL(table));
     }
 
     /**

Modified: openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/schema/Table.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/schema/Table.java?rev=880922&r1=880921&r2=880922&view=diff
==============================================================================
--- openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/schema/Table.java (original)
+++ openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/schema/Table.java Mon
Nov 16 19:34:11 2009
@@ -376,13 +376,6 @@
         return col;
     }
 
-    /**
-     * Add a name to this NameSet
-     */
-    public void addCorrectedColumnName(String name, boolean validate) {
-        addName(name, validate);
-    }
-
 
     /**
      * Remove the given column from the table.
@@ -737,7 +730,7 @@
     /**
      * Import a constraint; column names must match columns of this table.
      */
-    public Unique importUnique(Unique unq, DBDictionary dict) {
+    public Unique importUnique(Unique unq) {
         if (unq == null)
             return null;
 
@@ -747,10 +740,6 @@
         Column[] cols = unq.getColumns();
         for (int i = 0; i < cols.length; i++)
             copy.addColumn(getColumn(cols[i].getName()));
-        if (dict != null && !dict.supportsNullUniqueConlumn) {
-            for (Column col : copy.getColumns())
-                col.setNotNull(true);
-        }
         return copy;
     }
 
@@ -827,4 +816,15 @@
     public void setColNumber(int colNum) {
         _colNum = colNum;
     }
+
+    /**
+    * Add a column to the subNames set to avoid naming conflict.
+    */
+    public void addSubColumn(String name) {
+        addSubName(name);
+    }
+
+    public void resetSubColumns() {
+        resetSubNames();
+    }
 }

Modified: openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/schema/Unique.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/schema/Unique.java?rev=880922&r1=880921&r2=880922&view=diff
==============================================================================
--- openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/schema/Unique.java (original)
+++ openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/schema/Unique.java Mon
Nov 16 19:34:11 2009
@@ -24,7 +24,6 @@
  * @author Abe White
  * @author Pinaki Poddar
  */
-@SuppressWarnings("serial")
 public class Unique
     extends LocalConstraint {
 	
@@ -47,7 +46,26 @@
     }
     
     /**
-     * Return true if the structure of this constraint matches that of
+     * Adds the given column. 
+     * The added column is set to non-nullable because a unique constraint
+     * on the database requires that its constituent columns are NOT NULL. 
+     * @see Column#setNotNull(boolean)
+     */
+    public void addColumn(Column col) {
+    	super.addColumn(col);
+    	col.setNotNull(true);
+    }
+    
+    /**
+     * Set the name of the constraint. This method cannot be called if the
+     * constraint already belongs to a table. 
+     */
+    public void setName(String name) {
+        super.setName(name);
+    }
+    
+    /**
+     * Return true if the structure of this primary key matches that of
      * the given one (same table, same columns).
      */
     public boolean equalsUnique(Unique unq) {

Modified: openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/AbstractDB2Dictionary.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/AbstractDB2Dictionary.java?rev=880922&r1=880921&r2=880922&view=diff
==============================================================================
--- openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/AbstractDB2Dictionary.java
(original)
+++ openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/AbstractDB2Dictionary.java
Mon Nov 16 19:34:11 2009
@@ -69,8 +69,6 @@
         // the equivalent "X JOIN Y ON 1 = 1"
         crossJoinClause = "JOIN";
         requiresConditionForCrossJoin = true;
-        
-        supportsNullUniqueConlumn = false;
     }
 
     public void indexOf(SQLBuffer buf, FilterValue str, FilterValue find,

Modified: openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/DBDictionary.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/DBDictionary.java?rev=880922&r1=880921&r2=880922&view=diff
==============================================================================
--- openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/DBDictionary.java
(original)
+++ openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/DBDictionary.java
Mon Nov 16 19:34:11 2009
@@ -187,7 +187,6 @@
     public boolean supportsRestrictDeleteAction = true;
     public boolean supportsCascadeDeleteAction = true;
     public boolean supportsNullDeleteAction = true;
-    public boolean supportsNullUniqueConlumn = true;
     public boolean supportsDefaultDeleteAction = true;
     public boolean supportsRestrictUpdateAction = true;
     public boolean supportsCascadeUpdateAction = true;

Modified: openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/sqlcache/TestPreparedQueryCache.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/sqlcache/TestPreparedQueryCache.java?rev=880922&r1=880921&r2=880922&view=diff
==============================================================================
--- openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/sqlcache/TestPreparedQueryCache.java
(original)
+++ openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/sqlcache/TestPreparedQueryCache.java
Mon Nov 16 19:34:11 2009
@@ -751,7 +751,6 @@
         em.getTransaction().begin();
         Query q2 = em.createQuery(jpql);
         assertEquals(QueryLanguages.LANG_PREPARED_SQL, OpenJPAPersistence.cast(q2).getLanguage());
-        q2.getLockMode();
         q2.setLockMode(LockModeType.OPTIMISTIC);
         assertEquals(JPQLParser.LANG_JPQL, OpenJPAPersistence.cast(q2).getLanguage());
         List<Author> authors2 = q2.getResultList();

Modified: openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/QueryImpl.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/QueryImpl.java?rev=880922&r1=880921&r2=880922&view=diff
==============================================================================
--- openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/QueryImpl.java
(original)
+++ openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/QueryImpl.java
Mon Nov 16 19:34:11 2009
@@ -377,12 +377,9 @@
 	 */
 	void assertJPQLOrCriteriaQuery() {
         String language = getLanguage();
-        if (JPQLParser.LANG_JPQL.equals(language) 
-         || QueryLanguages.LANG_PREPARED_SQL.equals(language)
-         || CriteriaBuilderImpl.LANG_CRITERIA.equals(language)) {
-            return;
+        if (!(JPQLParser.LANG_JPQL.equals(language) || CriteriaBuilderImpl.LANG_CRITERIA.equals(language)))
{
+            throw new IllegalStateException(_loc.get("not-jpql-or-criteria-query").getMessage());
         }
-        throw new IllegalStateException(_loc.get("not-jpql-or-criteria-query").getMessage());
 	}
 
 	public OpenJPAQuery<X> closeAll() {



Mime
View raw message