openjpa-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jrba...@apache.org
Subject svn commit: r901362 - in /openjpa/trunk: openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/identifier/ openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/ openjpa-lib/src/main/java/org/apache/openjpa/lib/identifier/ openjpa-lib/src/test/java/org/a...
Date Wed, 20 Jan 2010 20:14:20 GMT
Author: jrbauer
Date: Wed Jan 20 20:14:19 2010
New Revision: 901362

URL: http://svn.apache.org/viewvc?rev=901362&view=rev
Log:
OPENJPA-1115 Enabled delimited id test on MySQL and fix identifier conversion related bugs.


Modified:
    openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/identifier/DBIdentifierUtilImpl.java
    openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/DBDictionary.java
    openjpa/trunk/openjpa-lib/src/main/java/org/apache/openjpa/lib/identifier/IdentifierUtil.java
    openjpa/trunk/openjpa-lib/src/main/java/org/apache/openjpa/lib/identifier/IdentifierUtilImpl.java
    openjpa/trunk/openjpa-lib/src/test/java/org/apache/openjpa/lib/identifier/TestIdentifiers.java
    openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/delimited/identifiers/noschema/EntityE.java
    openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/delimited/identifiers/noschema/EntityF.java
    openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/delimited/identifiers/noschema/TestNoSchemaManualDelimId.java

Modified: openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/identifier/DBIdentifierUtilImpl.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/identifier/DBIdentifierUtilImpl.java?rev=901362&r1=901361&r2=901362&view=diff
==============================================================================
--- openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/identifier/DBIdentifierUtilImpl.java
(original)
+++ openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/identifier/DBIdentifierUtilImpl.java
Wed Jan 20 20:14:19 2010
@@ -440,7 +440,9 @@
         String tableName = tbl.getIdentifier().getName();
         int len = Math.min(tableName.length(), 7);
         
-        String str = combineNames(rule, new String[] { prefix == null ? "" : prefix, 
+        // Combine the names using the normalized configuration.  
+        String str = combineNames(Normalizer.getNamingConfiguration(), rule, 
+            new String[] { prefix == null ? "" : prefix, 
             shorten(tableName, len), sName.getName() });
         sName.setName(str);
         return sName;

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=901362&r1=901361&r2=901362&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
Wed Jan 20 20:14:19 2010
@@ -5227,7 +5227,9 @@
     public void setSupportsDelimitedIdentifiers(DatabaseMetaData metaData) {
         try {
             supportsDelimitedIdentifiers = 
-                metaData.supportsMixedCaseQuotedIdentifiers();
+                metaData.supportsMixedCaseQuotedIdentifiers() ||
+                metaData.storesLowerCaseQuotedIdentifiers() ||
+                metaData.storesUpperCaseQuotedIdentifiers();
         } catch (SQLException e) {
             supportsDelimitedIdentifiers = false;
             getLog().warn(_loc.get("unknown-delim-support", e));

Modified: openjpa/trunk/openjpa-lib/src/main/java/org/apache/openjpa/lib/identifier/IdentifierUtil.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-lib/src/main/java/org/apache/openjpa/lib/identifier/IdentifierUtil.java?rev=901362&r1=901361&r2=901362&view=diff
==============================================================================
--- openjpa/trunk/openjpa-lib/src/main/java/org/apache/openjpa/lib/identifier/IdentifierUtil.java
(original)
+++ openjpa/trunk/openjpa-lib/src/main/java/org/apache/openjpa/lib/identifier/IdentifierUtil.java
Wed Jan 20 20:14:19 2010
@@ -99,6 +99,13 @@
      * @param the rule to use for removing delimiters
      * @param name the name from which to remove delimiters
      */
+    public String removeDelimiters(IdentifierConfiguration config, String rule, String name);
+
+    /**
+     * Remove delimiters from a delimited name 
+     * @param the rule to use for removing delimiters
+     * @param name the name from which to remove delimiters
+     */
     public String removeDelimiters(IdentifierRule rule, String name);
     
     /**

Modified: openjpa/trunk/openjpa-lib/src/main/java/org/apache/openjpa/lib/identifier/IdentifierUtilImpl.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-lib/src/main/java/org/apache/openjpa/lib/identifier/IdentifierUtilImpl.java?rev=901362&r1=901361&r2=901362&view=diff
==============================================================================
--- openjpa/trunk/openjpa-lib/src/main/java/org/apache/openjpa/lib/identifier/IdentifierUtilImpl.java
(original)
+++ openjpa/trunk/openjpa-lib/src/main/java/org/apache/openjpa/lib/identifier/IdentifierUtilImpl.java
Wed Jan 20 20:14:19 2010
@@ -52,62 +52,80 @@
         return _config;
     }    
 
-    public String combineNames(IdentifierRule rule, IdentifierRule[] rules, String[] names)
{
+    public String combineNames(String rule, String name1, String name2) {
+        return combineNames(getNamingRule(rule), name1, name2);
+    }
+
+    public String combineNames(String rule, String[] names) {
+        return combineNames(getNamingRule(rule), names);
+    }
+
+    public String combineNames(IdentifierConfiguration config, String rule, String[] names)
{
+        return combineNames(config, getNamingRule(rule), names);
+    }
+
+    public String combineNames(IdentifierRule rule, 
+        IdentifierRule[] rules, String[] names) {
+        return combineNames(_config, rule, rules, names);
+    }
+
+    public String combineNames(IdentifierConfiguration config, IdentifierRule rule, 
+        IdentifierRule[] rules, String[] names) {
         boolean delimited = false;
         String combined = null;
         for (int i = 0; i < names.length; i++) {
             String name = names[i];
             if (isDelimited(rules[i], name)) {
                 delimited = true;
-                name = removeDelimiters(rules[i], name);
+                name = removeDelimiters(config, rules[i], name);
             }
             if (i == 0) {
                 combined = name;
             }
             else {
-                combined = combined + _config.getIdentifierConcatenator() + name;
+                combined = combined + config.getIdentifierConcatenator() + name;
             }
         }
         
         if (delimited) {
-            combined = delimit(rule, combined.toString()).toString();
+            combined = delimit(config, rule, combined.toString()).toString();
         }
         
         return combined;
     }
     
-    public String combineNames(IdentifierRule rule, String name1, String name2) {
+    public String combineNames(IdentifierConfiguration config, IdentifierRule rule, String
name1, String name2) {
         boolean delimit = false;
         if (isDelimited(rule, name1)) {
-            name1 = removeDelimiters(rule, name1);
+            name1 = removeDelimiters(config, rule, name1);
             delimit = true;
         }
         if (isDelimited(rule, name2)) {
-            name2 = removeDelimiters(rule, name2);
+            name2 = removeDelimiters(config, rule, name2);
             delimit = true;
         }
-        String name = name1 + _config.getIdentifierConcatenator() + name2;
-        return delimit(rule, name, delimit).toString();
+        String name = name1 + config.getIdentifierConcatenator() + name2;
+        return delimit(config, rule, name, delimit).toString();
     }
 
-    public String combineNames(IdentifierRule namingRule, String[] names) {
+    public String combineNames(IdentifierConfiguration config, IdentifierRule namingRule,
String[] names) {
         boolean delimited = false;
         String combined = null;
         for (int i = 0; i < names.length; i++) {
             String name = names[i];
-            if (isDelimited(namingRule, name)) {
+            if (isDelimited(config, namingRule, name)) {
                 delimited = true;
-                name = removeDelimiters(namingRule, name);
+                name = removeDelimiters(config, namingRule, name);
             }
             if (i == 0) {
                 combined = name;
             }
             else {
-                combined = combined + _config.getIdentifierConcatenator() + name;
+                combined = combined + config.getIdentifierConcatenator() + name;
             }
         }
         if (delimited) {
-            combined = delimit(namingRule, combined.toString()).toString();
+            combined = delimit(config, namingRule, combined.toString()).toString();
         }
         
         return combined;
@@ -188,10 +206,14 @@
         return combinedName.toString();
     }
 
+    public String[] splitName(IdentifierConfiguration config, IdentifierRule nrule, String
name) {
+        return splitName(nrule, name, config.getIdentifierDelimiter());
+    }
+
     public String[] splitName(IdentifierRule nrule, String name) {
         return splitName(nrule, name, _config.getIdentifierDelimiter());
     }
-    
+
     
     /**
      * Splits names using single naming rule and appropriate separators
@@ -272,6 +294,10 @@
                name.endsWith(DOUBLE_QUOTE);
     }
 
+    public String delimit(IdentifierConfiguration config, IdentifierRule rule, String name)
{
+        return delimit(config, rule, name, false);
+    }
+
     
     public String delimit(IdentifierRule rule, String name) {
         return delimit(_config, rule, name, false);
@@ -304,8 +330,19 @@
             name.endsWith(config.getTrailingDelimiter());
     }
 
+    public String removeDelimiters(IdentifierConfiguration config, String rule,
+        String name) {
+        return removeDelimiters(_config, getNamingRule(rule), name, _config.getLeadingDelimiter(),
+            _config.getTrailingDelimiter());
+    }
+
     public String removeDelimiters(IdentifierRule rule, String name) {
-        return removeDelimiters(rule, name, _config.getLeadingDelimiter(),
+        return removeDelimiters(_config, rule, name, _config.getLeadingDelimiter(),
+            _config.getTrailingDelimiter());
+    }
+
+    public String removeDelimiters(IdentifierConfiguration config, IdentifierRule rule, String
name) {
+        return removeDelimiters(config, rule, name, _config.getLeadingDelimiter(),
             _config.getTrailingDelimiter());
     }
 
@@ -345,12 +382,12 @@
     }
     
 
-    protected String removeDelimiters(IdentifierRule rule, String name, String leading,
+    protected String removeDelimiters(IdentifierConfiguration config, IdentifierRule rule,
String name, String leading,
         String trailing) {
         if (name == null) {
             return null;
         }
-        if (isDelimited(rule, name)) {
+        if (isDelimited(config, rule, name)) {
             String id = name.substring(leading.length(),
                 (name.length() - trailing.length()));
             return id;
@@ -402,8 +439,12 @@
         return requiresDelimiters(getNamingRule(rule), name);
     }
 
+    public String[] splitName(IdentifierConfiguration config, String rule, String name) {
+        return splitName(config, getNamingRule(rule), name);
+    }
+
     public String[] splitName(String rule, String name) {
-        return splitName(getNamingRule(rule), name);
+        return splitName(_config, getNamingRule(rule), name);
     }
 
     public String joinNames(String[] rules, String[] names) {
@@ -414,14 +455,6 @@
         return _config.getIdentifierRule(rule);
     }
     
-    public String combineNames(String rule, String name1, String name2) {
-        return combineNames(getNamingRule(rule), name1, name2);
-    }
-
-    public String combineNames(String rule, String[] names) {
-        return combineNames(getNamingRule(rule), names);
-    }
-    
     public String appendNames(String rule, String name1, String name2) {
         return appendNames(getNamingRule(rule), name1, name2);
     }
@@ -456,7 +489,7 @@
     public String[] splitName(String nrule, String name, String nameDelim) {
         return splitName(getNamingRule(nrule), name, nameDelim);
     }
-        
+
     public String convert(IdentifierConfiguration config, String rule, String name) {
         // Already using same delimiter, no need to convert
         if (!needsConversion(config)) {
@@ -465,11 +498,11 @@
         // Otherwise, remove delimiters and add appropriate delimiters
         IdentifierRule orule = getIdentifierConfiguration().getIdentifierRule(rule);
         IdentifierRule nrule = config.getIdentifierRule(rule);
-        boolean delimit = isDelimited(orule, name);
+        boolean delimit = isDelimited(config, orule, name);
         if (delimit) {
-            name = removeDelimiters(orule, name, config.getLeadingDelimiter(), 
+            name = removeDelimiters(config, orule, name, config.getLeadingDelimiter(), 
                 config.getTrailingDelimiter());
-            return delimit(config, nrule, name, delimit).toString();
+            return delimit(getIdentifierConfiguration(), nrule, name, delimit).toString();
         }
         return name;
     }
@@ -479,13 +512,18 @@
             return fullName;
         }
         // Split
-        String[] names = splitName(rule, fullName);
+        String[] names = splitName(config, rule, fullName);
         // Convert
         for (int i = 0; i < names.length; i++) {
             names[i] = convert(config, rule, names[i]);
         }
-        // Join
-        return joinNames(config, config.getIdentifierRule(rule), names, config.getIdentifierDelimiter());
+        // If a single part name, return it.
+        if (names.length == 1) {
+            return names[0];
+        }
+        // Join if multiple names
+        return joinNames(getIdentifierConfiguration(), config.getIdentifierRule(rule), names,

+            getIdentifierConfiguration().getIdentifierDelimiter());
     }    
 
     public String combineFull(IdentifierConfiguration config, String rule, String fullName)
{
@@ -493,7 +531,7 @@
             return fullName;
         }
         // Split
-        String[] names = splitName(rule, fullName);
+        String[] names = splitName(config, rule, fullName);
         // Convert
         for (int i = 0; i < names.length; i++) {
             names[i] = convert(config, rule, names[i]);
@@ -543,4 +581,11 @@
         return name.contains(delim);
     }
 
+    public String combineNames(IdentifierRule rule, String[] names) {
+        return combineNames(_config, rule, names);
+    }
+
+    public String combineNames(IdentifierRule rule, String name1, String name2) {
+        return combineNames(_config, rule, name1, name2);
+    }
 }

Modified: openjpa/trunk/openjpa-lib/src/test/java/org/apache/openjpa/lib/identifier/TestIdentifiers.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-lib/src/test/java/org/apache/openjpa/lib/identifier/TestIdentifiers.java?rev=901362&r1=901361&r2=901362&view=diff
==============================================================================
--- openjpa/trunk/openjpa-lib/src/test/java/org/apache/openjpa/lib/identifier/TestIdentifiers.java
(original)
+++ openjpa/trunk/openjpa-lib/src/test/java/org/apache/openjpa/lib/identifier/TestIdentifiers.java
Wed Jan 20 20:14:19 2010
@@ -34,9 +34,9 @@
         IdentifierUtil nu = new IdentifierUtilImpl(defConfig);
         
         // Test basic name conversion with single name converter
-        String n0 = "`TABLE`";
+        String n0 = "\"TABLE\"";
         String cn0 = nu.convert(newConfig, "DEFAULT", n0);
-        assertEquals("\"TABLE\"", cn0);
+        assertEquals("`TABLE`", cn0);
         
         // Test basic name conversion with single name converter - no 
         // conversion
@@ -45,13 +45,13 @@
         assertEquals("TABLE", cn1);
 
         // Test basic name separator conversion with compound name converter
-        String n2 = "TABLE:SCHEMA";
+        String n2 = "TABLE.SCHEMA";
         String cn2 = nu.convertFull(newConfig, "DEFAULT", n2);
-        assertEquals("TABLE.SCHEMA", cn2);
+        assertEquals("TABLE:SCHEMA", cn2);
 
-        String n3 = "`TABLE`:`SCHEMA`";
+        String n3 = "\"TABLE\".\"SCHEMA\"";
         String cn3 = nu.convertFull(newConfig, "DEFAULT", n3);
-        assertEquals("\"TABLE\".\"SCHEMA\"", cn3);
+        assertEquals("`TABLE`:`SCHEMA`", cn3);
     }
     
     

Modified: openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/delimited/identifiers/noschema/EntityE.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/delimited/identifiers/noschema/EntityE.java?rev=901362&r1=901361&r2=901362&view=diff
==============================================================================
--- openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/delimited/identifiers/noschema/EntityE.java
(original)
+++ openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/delimited/identifiers/noschema/EntityE.java
Wed Jan 20 20:14:19 2010
@@ -31,11 +31,11 @@
 public class EntityE {
     @Id
     @SequenceGenerator(name="entityE_seq_gen_name", 
-        sequenceName="\"entityE_seq_gen\"")
+        sequenceName="\"entityE seq gen\"")
     @GeneratedValue(strategy=GenerationType.SEQUENCE, 
         generator="entityE_seq_gen_name")
     private int id;
-    @Column(name="nse_name")
+    @Column(name="nse name")
     private String name;
     
     public EntityE(String name) {

Modified: openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/delimited/identifiers/noschema/EntityF.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/delimited/identifiers/noschema/EntityF.java?rev=901362&r1=901361&r2=901362&view=diff
==============================================================================
--- openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/delimited/identifiers/noschema/EntityF.java
(original)
+++ openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/delimited/identifiers/noschema/EntityF.java
Wed Jan 20 20:14:19 2010
@@ -42,11 +42,11 @@
         @UniqueConstraint(columnNames={"\"nsf name\"", "nsf_nonDelimName"}))
 @SecondaryTable(name="\"nssecondary entityF\"",
     uniqueConstraints=
-        @UniqueConstraint(name="\"nssec_unq\"", 
+        @UniqueConstraint(name="\"nssec unq\"", 
             columnNames={"\"nssecondary name\""}))         
 public class EntityF {
-    @TableGenerator(name = "f_id_gen", table = "\"nsf_id_gen\"", 
-        pkColumnName = "\"nsgen_pk\"", valueColumnName = "\"nsgen_value\"")
+    @TableGenerator(name = "f_id_gen", table = "\"nsf id gen\"", 
+        pkColumnName = "\"nsgen pk\"", valueColumnName = "\"nsgen value\"")
     @GeneratedValue(strategy = GenerationType.TABLE, generator = "f_id_gen")
     @Id
     private int id;
@@ -65,7 +65,7 @@
     private Set<String> nscs = new HashSet<String>();
     
     @ElementCollection
-    @CollectionTable(name="\"nscDelSet\"")
+    @CollectionTable(name="\"nsc DelSet\"")
     private Set<String> nscds = new HashSet<String>();
     
     @ElementCollection

Modified: openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/delimited/identifiers/noschema/TestNoSchemaManualDelimId.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/delimited/identifiers/noschema/TestNoSchemaManualDelimId.java?rev=901362&r1=901361&r2=901362&view=diff
==============================================================================
--- openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/delimited/identifiers/noschema/TestNoSchemaManualDelimId.java
(original)
+++ openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/delimited/identifiers/noschema/TestNoSchemaManualDelimId.java
Wed Jan 20 20:14:19 2010
@@ -39,10 +39,6 @@
     @Override
     public void setUp() throws Exception {
 
-        setUnsupportedDatabases(MySQLDictionary.class);
-        if (isTestsDisabled())
-            return;
-
         super.setUp(
             org.apache.openjpa.persistence.delimited.identifiers.noschema.EntityF.class,
             DROP_TABLES);



Mime
View raw message