OPENJPA-1979: Regression for non-standard joins with constant column values - back ported to 2.1.x Pinaki Poddar's trunk changes.

git-svn-id: https://svn.apache.org/repos/asf/openjpa/branches/2.1.x@1484313 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Heath Thomann 2013-05-19 17:06:13 +00:00
parent f0fe24872b
commit 5b07fdfc52
2 changed files with 47 additions and 10 deletions

View File

@ -490,7 +490,7 @@ public class AnnotationPersistenceMappingParser
if (!StringUtils.isEmpty(join.columnDefinition())) if (!StringUtils.isEmpty(join.columnDefinition()))
col.setTypeIdentifier(DBIdentifier.newColumnDefinition(join.columnDefinition())); col.setTypeIdentifier(DBIdentifier.newColumnDefinition(join.columnDefinition()));
if (!StringUtils.isEmpty(join.referencedColumnName())) if (!StringUtils.isEmpty(join.referencedColumnName()))
col.setTargetIdentifier(DBIdentifier.newColumn(join.referencedColumnName(), delimit())); setTargetIdentifier(col, join.referencedColumnName());
return col; return col;
} }
@ -1713,14 +1713,33 @@ public class AnnotationPersistenceMappingParser
col.setIdentifier(DBIdentifier.newColumn(join.name(), delimit())); col.setIdentifier(DBIdentifier.newColumn(join.name(), delimit()));
if (!StringUtils.isEmpty(join.columnDefinition())) if (!StringUtils.isEmpty(join.columnDefinition()))
col.setTypeIdentifier(DBIdentifier.newColumnDefinition(join.columnDefinition())); col.setTypeIdentifier(DBIdentifier.newColumnDefinition(join.columnDefinition()));
if (!StringUtils.isEmpty(join.referencedColumnName())) String refColumnName = join.referencedColumnName();
col.setTargetIdentifier(DBIdentifier.newColumn(join.referencedColumnName(), delimit())); if (!StringUtils.isEmpty(refColumnName)) {
setTargetIdentifier(col, refColumnName);
}
col.setNotNull(!join.nullable()); col.setNotNull(!join.nullable());
col.setFlag(Column.FLAG_UNINSERTABLE, !join.insertable()); col.setFlag(Column.FLAG_UNINSERTABLE, !join.insertable());
col.setFlag(Column.FLAG_UNUPDATABLE, !join.updatable()); col.setFlag(Column.FLAG_UNUPDATABLE, !join.updatable());
return col; 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). * Parse @KeyColumn(s).
*/ */
@ -1796,14 +1815,14 @@ public class AnnotationPersistenceMappingParser
/** /**
* Create a new schema column with information from the given annotation. * 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(); Column col = new Column();
if (!StringUtils.isEmpty(join.name())) if (!StringUtils.isEmpty(join.name()))
col.setIdentifier(DBIdentifier.newColumn(join.name(), delimit)); col.setIdentifier(DBIdentifier.newColumn(join.name(), delimit));
if (!StringUtils.isEmpty(join.columnDefinition())) if (!StringUtils.isEmpty(join.columnDefinition()))
col.setTypeIdentifier(DBIdentifier.newColumnDefinition(join.columnDefinition())); col.setTypeIdentifier(DBIdentifier.newColumnDefinition(join.columnDefinition()));
if (!StringUtils.isEmpty(join.referencedColumnName())) if (!StringUtils.isEmpty(join.referencedColumnName()))
col.setTargetIdentifier(DBIdentifier.newColumn(join.referencedColumnName(), delimit)); setTargetIdentifier(col, join.referencedColumnName());
if (!StringUtils.isEmpty(join.referencedAttributeName())) if (!StringUtils.isEmpty(join.referencedAttributeName()))
col.setTargetField(join.referencedAttributeName()); col.setTargetField(join.referencedAttributeName());
col.setNotNull(!join.nullable()); col.setNotNull(!join.nullable());
@ -1968,14 +1987,14 @@ public class AnnotationPersistenceMappingParser
/** /**
* Create a new schema column with information from the given annotation. * 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(); Column col = new Column();
if (!StringUtils.isEmpty(join.name())) if (!StringUtils.isEmpty(join.name()))
col.setIdentifier(DBIdentifier.newColumn(join.name(), delimit)); col.setIdentifier(DBIdentifier.newColumn(join.name(), delimit));
if (!StringUtils.isEmpty(join.columnDefinition())) if (!StringUtils.isEmpty(join.columnDefinition()))
col.setTypeIdentifier(DBIdentifier.newColumnDefinition(join.columnDefinition())); col.setTypeIdentifier(DBIdentifier.newColumnDefinition(join.columnDefinition()));
if (!StringUtils.isEmpty(join.referencedColumnName())) if (!StringUtils.isEmpty(join.referencedColumnName()))
col.setTargetIdentifier(DBIdentifier.newColumn(join.referencedColumnName(), delimit)); setTargetIdentifier(col, join.referencedColumnName());
if (!StringUtils.isEmpty(join.referencedAttributeName())) if (!StringUtils.isEmpty(join.referencedAttributeName()))
col.setTargetField(join.referencedAttributeName()); col.setTargetField(join.referencedAttributeName());
col.setNotNull(!join.nullable()); col.setNotNull(!join.nullable());
@ -2063,7 +2082,7 @@ public class AnnotationPersistenceMappingParser
if (!StringUtils.isEmpty(join.columnDefinition())) if (!StringUtils.isEmpty(join.columnDefinition()))
col.setTypeIdentifier(DBIdentifier.newColumnDefinition(join.columnDefinition())); col.setTypeIdentifier(DBIdentifier.newColumnDefinition(join.columnDefinition()));
if (!StringUtils.isEmpty(join.referencedColumnName())) if (!StringUtils.isEmpty(join.referencedColumnName()))
col.setTargetIdentifier(DBIdentifier.newColumn(join.referencedColumnName(), delimit())); setTargetIdentifier(col, join.referencedColumnName());
col.setNotNull(!join.nullable()); col.setNotNull(!join.nullable());
col.setFlag(Column.FLAG_UNINSERTABLE, !join.insertable()); col.setFlag(Column.FLAG_UNINSERTABLE, !join.insertable());
col.setFlag(Column.FLAG_UNUPDATABLE, !join.updatable ()); col.setFlag(Column.FLAG_UNUPDATABLE, !join.updatable ());

View File

@ -1004,8 +1004,9 @@ public class XMLPersistenceMappingParser
if (val != null) if (val != null)
col.setIdentifier(DBIdentifier.newColumn(val, delimit())); col.setIdentifier(DBIdentifier.newColumn(val, delimit()));
val = attrs.getValue("referenced-column-name"); val = attrs.getValue("referenced-column-name");
if (val != null) if (val != null) {
col.setTargetIdentifier(DBIdentifier.newColumn(val, delimit())); setTargetIdentifier(col, val);
}
val = attrs.getValue("column-definition"); val = attrs.getValue("column-definition");
if (val != null) if (val != null)
col.setTypeIdentifier(DBIdentifier.newColumnDefinition(val)); col.setTypeIdentifier(DBIdentifier.newColumnDefinition(val));
@ -1041,6 +1042,23 @@ public class XMLPersistenceMappingParser
return col; 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 collectionTable. * Parse collectionTable.
*/ */