You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@openjpa.apache.org by ht...@apache.org on 2013/05/19 19:53:36 UTC
svn commit: r1484322 - in /openjpa/branches/2.2.1.x: ./
openjpa-persistence-jdbc/src/main/java/org/apache/openjpa/persistence/jdbc/
Author: hthomann
Date: Sun May 19 17:53:36 2013
New Revision: 1484322
URL: http://svn.apache.org/r1484322
Log:
OPENJPA-1979: Regression for non-standard joins with constant column values - back ported to 2.2.1.x Pinaki Poddar's trunk changes.
Modified:
openjpa/branches/2.2.1.x/ (props changed)
openjpa/branches/2.2.1.x/openjpa-persistence-jdbc/src/main/java/org/apache/openjpa/persistence/jdbc/AnnotationPersistenceMappingParser.java
openjpa/branches/2.2.1.x/openjpa-persistence-jdbc/src/main/java/org/apache/openjpa/persistence/jdbc/XMLPersistenceMappingParser.java
Propchange: openjpa/branches/2.2.1.x/
------------------------------------------------------------------------------
Merged /openjpa/branches/2.1.x:r1484313
Merged /openjpa/trunk:r1461833
Modified: openjpa/branches/2.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.2.1.x/openjpa-persistence-jdbc/src/main/java/org/apache/openjpa/persistence/jdbc/AnnotationPersistenceMappingParser.java?rev=1484322&r1=1484321&r2=1484322&view=diff
==============================================================================
--- openjpa/branches/2.2.1.x/openjpa-persistence-jdbc/src/main/java/org/apache/openjpa/persistence/jdbc/AnnotationPersistenceMappingParser.java (original)
+++ openjpa/branches/2.2.1.x/openjpa-persistence-jdbc/src/main/java/org/apache/openjpa/persistence/jdbc/AnnotationPersistenceMappingParser.java Sun May 19 17:53:36 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;
}
@@ -1737,13 +1737,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).
@@ -1820,14 +1839,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());
@@ -1992,14 +2011,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());
@@ -2087,7 +2106,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.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.2.1.x/openjpa-persistence-jdbc/src/main/java/org/apache/openjpa/persistence/jdbc/XMLPersistenceMappingParser.java?rev=1484322&r1=1484321&r2=1484322&view=diff
==============================================================================
--- openjpa/branches/2.2.1.x/openjpa-persistence-jdbc/src/main/java/org/apache/openjpa/persistence/jdbc/XMLPersistenceMappingParser.java (original)
+++ openjpa/branches/2.2.1.x/openjpa-persistence-jdbc/src/main/java/org/apache/openjpa/persistence/jdbc/XMLPersistenceMappingParser.java Sun May 19 17:53:36 2013
@@ -1055,8 +1055,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));
@@ -1093,6 +1094,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)