openjpa-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From hthom...@apache.org
Subject svn commit: r1484313 - in /openjpa/branches/2.1.x: ./ openjpa-persistence-jdbc/src/main/java/org/apache/openjpa/persistence/jdbc/
Date Sun, 19 May 2013 17:06:14 GMT
Author: hthomann
Date: Sun May 19 17:06:13 2013
New Revision: 1484313

URL: http://svn.apache.org/r1484313
Log:
OPENJPA-1979: Regression for non-standard joins with constant column values - back ported
to 2.1.x Pinaki Poddar's trunk changes.

Modified:
    openjpa/branches/2.1.x/   (props changed)
    openjpa/branches/2.1.x/openjpa-persistence-jdbc/src/main/java/org/apache/openjpa/persistence/jdbc/AnnotationPersistenceMappingParser.java
    openjpa/branches/2.1.x/openjpa-persistence-jdbc/src/main/java/org/apache/openjpa/persistence/jdbc/XMLPersistenceMappingParser.java

Propchange: openjpa/branches/2.1.x/
------------------------------------------------------------------------------
  Merged /openjpa/trunk:r1461833

Modified: openjpa/branches/2.1.x/openjpa-persistence-jdbc/src/main/java/org/apache/openjpa/persistence/jdbc/AnnotationPersistenceMappingParser.java
URL: http://svn.apache.org/viewvc/openjpa/branches/2.1.x/openjpa-persistence-jdbc/src/main/java/org/apache/openjpa/persistence/jdbc/AnnotationPersistenceMappingParser.java?rev=1484313&r1=1484312&r2=1484313&view=diff
==============================================================================
--- openjpa/branches/2.1.x/openjpa-persistence-jdbc/src/main/java/org/apache/openjpa/persistence/jdbc/AnnotationPersistenceMappingParser.java
(original)
+++ openjpa/branches/2.1.x/openjpa-persistence-jdbc/src/main/java/org/apache/openjpa/persistence/jdbc/AnnotationPersistenceMappingParser.java
Sun May 19 17:06:13 2013
@@ -490,7 +490,7 @@ public class AnnotationPersistenceMappin
         if (!StringUtils.isEmpty(join.columnDefinition()))
             col.setTypeIdentifier(DBIdentifier.newColumnDefinition(join.columnDefinition()));
         if (!StringUtils.isEmpty(join.referencedColumnName()))
-            col.setTargetIdentifier(DBIdentifier.newColumn(join.referencedColumnName(), delimit()));
+            setTargetIdentifier(col, join.referencedColumnName());
         return col;
     }
 
@@ -1713,13 +1713,32 @@ public class AnnotationPersistenceMappin
             col.setIdentifier(DBIdentifier.newColumn(join.name(), delimit()));
         if (!StringUtils.isEmpty(join.columnDefinition()))
             col.setTypeIdentifier(DBIdentifier.newColumnDefinition(join.columnDefinition()));

-        if (!StringUtils.isEmpty(join.referencedColumnName()))
-            col.setTargetIdentifier(DBIdentifier.newColumn(join.referencedColumnName(), delimit()));
+        String refColumnName = join.referencedColumnName();
+        if (!StringUtils.isEmpty(refColumnName)) {
+        	setTargetIdentifier(col, refColumnName);
+        }
         col.setNotNull(!join.nullable());
         col.setFlag(Column.FLAG_UNINSERTABLE, !join.insertable());
         col.setFlag(Column.FLAG_UNUPDATABLE, !join.updatable());
         return col;
     }
+    
+    /**
+     * Sets reference column name of the given column taking into account
+     * that the given reference name that begins with a single quote represents
+     * special meaning of a constant join column and hence not to be delimited.  
+     * @param col
+     * @param refColumnName
+     * @see <a href="http://issues.apache.org/jira/browse/OPENJPA-1979">OPENJPA-1979</a>
+     */
+    private static final char SINGLE_QUOTE = '\'';
+    protected void setTargetIdentifier(Column col, String refColumnName) {
+    	if (refColumnName.charAt(0) == SINGLE_QUOTE) {
+    		col.setTargetIdentifier(DBIdentifier.newConstant(refColumnName));
+    	} else {
+    		col.setTargetIdentifier(DBIdentifier.newColumn(refColumnName, delimit()));
+    	}
+    }
 
     /**
      * Parse @KeyColumn(s).
@@ -1796,14 +1815,14 @@ public class AnnotationPersistenceMappin
     /**
      * Create a new schema column with information from the given annotation.
      */
-    private static Column newColumn(XJoinColumn join, boolean delimit) {
+    private Column newColumn(XJoinColumn join, boolean delimit) {
         Column col = new Column();
         if (!StringUtils.isEmpty(join.name()))
             col.setIdentifier(DBIdentifier.newColumn(join.name(), delimit));
         if (!StringUtils.isEmpty(join.columnDefinition()))
             col.setTypeIdentifier(DBIdentifier.newColumnDefinition(join.columnDefinition()));
         if (!StringUtils.isEmpty(join.referencedColumnName()))
-            col.setTargetIdentifier(DBIdentifier.newColumn(join.referencedColumnName(), delimit));
+            setTargetIdentifier(col, join.referencedColumnName());
         if (!StringUtils.isEmpty(join.referencedAttributeName()))
             col.setTargetField(join.referencedAttributeName());
         col.setNotNull(!join.nullable());
@@ -1968,14 +1987,14 @@ public class AnnotationPersistenceMappin
     /**
      * Create a new schema column with information from the given annotation.
      */
-    private static Column newColumn(ElementJoinColumn join, boolean delimit) {
+    private Column newColumn(ElementJoinColumn join, boolean delimit) {
         Column col = new Column();
         if (!StringUtils.isEmpty(join.name()))
             col.setIdentifier(DBIdentifier.newColumn(join.name(), delimit));
         if (!StringUtils.isEmpty(join.columnDefinition()))
             col.setTypeIdentifier(DBIdentifier.newColumnDefinition(join.columnDefinition()));
         if (!StringUtils.isEmpty(join.referencedColumnName()))
-            col.setTargetIdentifier(DBIdentifier.newColumn(join.referencedColumnName(), delimit));
+            setTargetIdentifier(col, join.referencedColumnName());
         if (!StringUtils.isEmpty(join.referencedAttributeName()))
             col.setTargetField(join.referencedAttributeName());
         col.setNotNull(!join.nullable());
@@ -2063,7 +2082,7 @@ public class AnnotationPersistenceMappin
         if (!StringUtils.isEmpty(join.columnDefinition()))
             col.setTypeIdentifier(DBIdentifier.newColumnDefinition(join.columnDefinition()));

         if (!StringUtils.isEmpty(join.referencedColumnName()))
-            col.setTargetIdentifier(DBIdentifier.newColumn(join.referencedColumnName(), delimit()));

+            setTargetIdentifier(col, join.referencedColumnName()); 
         col.setNotNull(!join.nullable());
         col.setFlag(Column.FLAG_UNINSERTABLE, !join.insertable());
         col.setFlag(Column.FLAG_UNUPDATABLE, !join.updatable ());

Modified: openjpa/branches/2.1.x/openjpa-persistence-jdbc/src/main/java/org/apache/openjpa/persistence/jdbc/XMLPersistenceMappingParser.java
URL: http://svn.apache.org/viewvc/openjpa/branches/2.1.x/openjpa-persistence-jdbc/src/main/java/org/apache/openjpa/persistence/jdbc/XMLPersistenceMappingParser.java?rev=1484313&r1=1484312&r2=1484313&view=diff
==============================================================================
--- openjpa/branches/2.1.x/openjpa-persistence-jdbc/src/main/java/org/apache/openjpa/persistence/jdbc/XMLPersistenceMappingParser.java
(original)
+++ openjpa/branches/2.1.x/openjpa-persistence-jdbc/src/main/java/org/apache/openjpa/persistence/jdbc/XMLPersistenceMappingParser.java
Sun May 19 17:06:13 2013
@@ -1004,8 +1004,9 @@ public class XMLPersistenceMappingParser
         if (val != null)
             col.setIdentifier(DBIdentifier.newColumn(val, delimit()));
         val = attrs.getValue("referenced-column-name");
-        if (val != null)
-            col.setTargetIdentifier(DBIdentifier.newColumn(val, delimit()));
+        if (val != null) {
+            setTargetIdentifier(col, val);
+        }
         val = attrs.getValue("column-definition");
         if (val != null)
             col.setTypeIdentifier(DBIdentifier.newColumnDefinition(val));
@@ -1042,6 +1043,23 @@ public class XMLPersistenceMappingParser
     }
 
     /**
+     * Sets reference column name of the given column taking into account
+     * that the given reference name that begins with a single quote represents
+     * special meaning of a constant join column and hence not to be delimited.  
+     * @param col
+     * @param refColumnName
+     * @see <a href="http://issues.apache.org/jira/browse/OPENJPA-1979">OPENJPA-1979</a>
+     */
+    private static final char SINGLE_QUOTE = '\'';
+    protected void setTargetIdentifier(Column col, String refColumnName) {
+    	if (refColumnName.charAt(0) == SINGLE_QUOTE) {
+    		col.setTargetIdentifier(DBIdentifier.newConstant(refColumnName));
+    	} else {
+    		col.setTargetIdentifier(DBIdentifier.newColumn(refColumnName, delimit()));
+    	}
+    }
+    
+    /**
      * Parse collectionTable.
      */
     private boolean startCollectionTable(Attributes attrs)



Mime
View raw message