mirror of https://github.com/apache/openjpa.git
ClassMappingInfo.addUnique() accepts a Unique instance rather than an array of column names
git-svn-id: https://svn.apache.org/repos/asf/incubator/openjpa/trunk@495800 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
b7c7a47aac
commit
218a000b84
|
@ -322,22 +322,12 @@ public class ClassMappingInfo
|
||||||
_uniques = new ArrayList(cinfo._uniques);
|
_uniques = new ArrayList(cinfo._uniques);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void addUnique(String name, String[] columnNames) {
|
public void addUnique(Unique unique) {
|
||||||
if (columnNames == null || columnNames.length == 0)
|
if (unique == null)
|
||||||
return;
|
return;
|
||||||
if (_uniques == null)
|
if (_uniques == null)
|
||||||
_uniques = new ArrayList();
|
_uniques = new ArrayList();
|
||||||
Unique uniqueConstraint = new Unique();
|
_uniques.add(unique);
|
||||||
uniqueConstraint.setName(name);
|
|
||||||
for (int i=0; i<columnNames.length; i++) {
|
|
||||||
if (StringUtils.isEmpty(columnNames[i]))
|
|
||||||
throw new UserException(_loc.get("empty-unique-column",
|
|
||||||
getClassName()));
|
|
||||||
Column column = new Column();
|
|
||||||
column.setName(columnNames[i]);
|
|
||||||
uniqueConstraint.addColumn(column);
|
|
||||||
}
|
|
||||||
_uniques.add(uniqueConstraint);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public Unique[] getUniques(ClassMapping cm, boolean adapt) {
|
public Unique[] getUniques(ClassMapping cm, boolean adapt) {
|
||||||
|
|
|
@ -404,6 +404,3 @@ num-cols-path: Result path "{2}" in result type "{1}" of mapping "{0}" \
|
||||||
missing-unique-column: A unique constraint specified in mapping of class "{0}" \
|
missing-unique-column: A unique constraint specified in mapping of class "{0}" \
|
||||||
to table "{1}" includes a column "{2}". However, the column does not \
|
to table "{1}" includes a column "{2}". However, the column does not \
|
||||||
exist in "{1}" table.
|
exist in "{1}" table.
|
||||||
empty-unique-column: A unique constraint specified in mapping of class "{0}" \
|
|
||||||
includes an empty column "{2}".
|
|
||||||
|
|
|
@ -66,6 +66,7 @@ import org.apache.openjpa.jdbc.meta.strats.FlatClassStrategy;
|
||||||
import org.apache.openjpa.jdbc.meta.strats.FullClassStrategy;
|
import org.apache.openjpa.jdbc.meta.strats.FullClassStrategy;
|
||||||
import org.apache.openjpa.jdbc.meta.strats.VerticalClassStrategy;
|
import org.apache.openjpa.jdbc.meta.strats.VerticalClassStrategy;
|
||||||
import org.apache.openjpa.jdbc.schema.Column;
|
import org.apache.openjpa.jdbc.schema.Column;
|
||||||
|
import org.apache.openjpa.jdbc.schema.Unique;
|
||||||
import org.apache.openjpa.lib.log.Log;
|
import org.apache.openjpa.lib.log.Log;
|
||||||
import org.apache.openjpa.lib.util.Localizer;
|
import org.apache.openjpa.lib.util.Localizer;
|
||||||
import org.apache.openjpa.meta.ClassMetaData;
|
import org.apache.openjpa.meta.ClassMetaData;
|
||||||
|
@ -76,6 +77,7 @@ import static org.apache.openjpa.persistence.jdbc.MappingTag.*;
|
||||||
import org.apache.openjpa.util.InternalException;
|
import org.apache.openjpa.util.InternalException;
|
||||||
import org.apache.openjpa.util.MetaDataException;
|
import org.apache.openjpa.util.MetaDataException;
|
||||||
import org.apache.openjpa.util.UnsupportedException;
|
import org.apache.openjpa.util.UnsupportedException;
|
||||||
|
import org.apache.openjpa.util.UserException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Persistence annotation mapping parser.
|
* Persistence annotation mapping parser.
|
||||||
|
@ -460,9 +462,9 @@ public class AnnotationPersistenceMappingParser
|
||||||
if (tableName != null)
|
if (tableName != null)
|
||||||
cm.getMappingInfo().setTableName(tableName);
|
cm.getMappingInfo().setTableName(tableName);
|
||||||
|
|
||||||
for (UniqueConstraint unique:table.uniqueConstraints()) {
|
for (UniqueConstraint uniqueConstraint:table.uniqueConstraints()) {
|
||||||
((ClassMappingInfo)cm.getMappingInfo())
|
Unique unique = newUnique(cm, null, uniqueConstraint.columnNames());
|
||||||
.addUnique(null, unique.columnNames());
|
cm.getMappingInfo().addUnique(unique);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -682,7 +684,8 @@ public class AnnotationPersistenceMappingParser
|
||||||
/**
|
/**
|
||||||
* Set unique data on the given mapping info.
|
* Set unique data on the given mapping info.
|
||||||
*/
|
*/
|
||||||
private void parseUnique(FieldMapping fm, Unique anno) {
|
private void parseUnique(FieldMapping fm,
|
||||||
|
org.apache.openjpa.persistence.jdbc.Unique anno) {
|
||||||
ValueMappingInfo info = fm.getValueInfo();
|
ValueMappingInfo info = fm.getValueInfo();
|
||||||
if (!anno.enabled()) {
|
if (!anno.enabled()) {
|
||||||
info.setCanUnique(false);
|
info.setCanUnique(false);
|
||||||
|
@ -879,7 +882,8 @@ public class AnnotationPersistenceMappingParser
|
||||||
fm.getValueInfo().setStrategy(((Strategy) anno).value());
|
fm.getValueInfo().setStrategy(((Strategy) anno).value());
|
||||||
break;
|
break;
|
||||||
case UNIQUE:
|
case UNIQUE:
|
||||||
parseUnique(fm, (Unique) anno);
|
parseUnique(fm,
|
||||||
|
(org.apache.openjpa.persistence.jdbc.Unique) anno);
|
||||||
break;
|
break;
|
||||||
case X_JOIN_COL:
|
case X_JOIN_COL:
|
||||||
parseXJoinColumns(fm, fm.getValueInfo(), true,
|
parseXJoinColumns(fm, fm.getValueInfo(), true,
|
||||||
|
@ -1325,4 +1329,21 @@ public class AnnotationPersistenceMappingParser
|
||||||
col.setFlag (Column.FLAG_UNUPDATABLE, !join.updatable ());
|
col.setFlag (Column.FLAG_UNUPDATABLE, !join.updatable ());
|
||||||
return col;
|
return col;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static Unique newUnique(ClassMapping cm, String name,
|
||||||
|
String[] columnNames) {
|
||||||
|
if (columnNames == null || columnNames.length == 0)
|
||||||
|
return null;
|
||||||
|
Unique uniqueConstraint = new Unique();
|
||||||
|
uniqueConstraint.setName(name);
|
||||||
|
for (int i=0; i<columnNames.length; i++) {
|
||||||
|
if (StringUtils.isEmpty(columnNames[i]))
|
||||||
|
throw new UserException(_loc.get("empty-unique-column",
|
||||||
|
Arrays.toString(columnNames), cm));
|
||||||
|
Column column = new Column();
|
||||||
|
column.setName(columnNames[i]);
|
||||||
|
uniqueConstraint.addColumn(column);
|
||||||
|
}
|
||||||
|
return uniqueConstraint;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -43,3 +43,5 @@ second-version: Version property "{0}" cannot map to a secondary table column. \
|
||||||
Version columns must always be in the primary table of the class.
|
Version columns must always be in the primary table of the class.
|
||||||
not-embedded: Attempt to declare mapping overrides on non-embedded field "{0}".
|
not-embedded: Attempt to declare mapping overrides on non-embedded field "{0}".
|
||||||
no-gen-table: No generated table found at "{0}".
|
no-gen-table: No generated table found at "{0}".
|
||||||
|
empty-unique-column: A unique constraint "{0}" specified in mapping of class \
|
||||||
|
"{1}" includes an empty column.
|
Loading…
Reference in New Issue