OPENJPA-1387: Remove non-nullable constraint from Unique column.

git-svn-id: https://svn.apache.org/repos/asf/openjpa/trunk@880686 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Pinaki Poddar 2009-11-16 09:19:24 +00:00
parent 6cf1ca1f63
commit 61f9b32a49
3 changed files with 11 additions and 32 deletions

View File

@ -24,6 +24,7 @@ package org.apache.openjpa.jdbc.schema;
* *
* @author Abe White * @author Abe White
*/ */
@SuppressWarnings("serial")
public abstract class Constraint public abstract class Constraint
extends ReferenceCounter { extends ReferenceCounter {
@ -180,9 +181,6 @@ public abstract class Constraint
public String toString() { public String toString() {
if (getName() != null) if (getName() != null)
return getName(); return getName();
return "<" + getClass().getSimpleName().toLowerCase() + ">";
String name = getClass().getName();
name = name.substring(name.lastIndexOf('.') + 1);
return "<" + name.toLowerCase() + ">";
} }
} }

View File

@ -21,7 +21,6 @@ package org.apache.openjpa.jdbc.schema;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import org.apache.commons.lang.ObjectUtils;
import org.apache.openjpa.lib.util.Localizer; import org.apache.openjpa.lib.util.Localizer;
import org.apache.openjpa.util.InvalidStateException; import org.apache.openjpa.util.InvalidStateException;
@ -32,13 +31,13 @@ import org.apache.openjpa.util.InvalidStateException;
* *
* @author Abe White * @author Abe White
*/ */
@SuppressWarnings("serial")
public abstract class LocalConstraint public abstract class LocalConstraint
extends Constraint { extends Constraint {
private static final Localizer _loc = Localizer.forPackage private static final Localizer _loc = Localizer.forPackage(LocalConstraint.class);
(LocalConstraint.class);
private List _colList = null; private List<Column> _colList = null;
private Column[] _cols = null; private Column[] _cols = null;
/** /**
@ -99,7 +98,7 @@ public abstract class LocalConstraint
col == null ? null : getTable())); col == null ? null : getTable()));
if (_colList == null) if (_colList == null)
_colList = new ArrayList(3); _colList = new ArrayList<Column>(3);
else if (_colList.contains(col)) else if (_colList.contains(col))
return; return;
@ -124,7 +123,7 @@ public abstract class LocalConstraint
} }
/** /**
* Return true if the pk includes the given column. * Return true if this constraint includes the given column.
*/ */
public boolean containsColumn(Column col) { public boolean containsColumn(Column col) {
if (col == null || _colList == null) if (col == null || _colList == null)
@ -133,7 +132,7 @@ public abstract class LocalConstraint
} }
/** /**
* Ref all columns in this constraint. * Reference all columns in this constraint.
*/ */
public void refColumns() { public void refColumns() {
Column[] cols = getColumns(); Column[] cols = getColumns();
@ -142,7 +141,7 @@ public abstract class LocalConstraint
} }
/** /**
* Deref all columns in this constraint. * Dereference all columns in this constraint.
*/ */
public void derefColumns() { public void derefColumns() {
Column[] cols = getColumns(); Column[] cols = getColumns();

View File

@ -24,6 +24,7 @@ package org.apache.openjpa.jdbc.schema;
* @author Abe White * @author Abe White
* @author Pinaki Poddar * @author Pinaki Poddar
*/ */
@SuppressWarnings("serial")
public class Unique public class Unique
extends LocalConstraint { extends LocalConstraint {
@ -46,26 +47,7 @@ public class Unique
} }
/** /**
* Adds the given column. * Return true if the structure of this constraint matches that of
* The added column is set to non-nullable because a unique constraint
* on the database requires that its constituent columns are NOT NULL.
* @see Column#setNotNull(boolean)
*/
public void addColumn(Column col) {
super.addColumn(col);
col.setNotNull(true);
}
/**
* Set the name of the constraint. This method cannot be called if the
* constraint already belongs to a table.
*/
public void setName(String name) {
super.setName(name);
}
/**
* Return true if the structure of this primary key matches that of
* the given one (same table, same columns). * the given one (same table, same columns).
*/ */
public boolean equalsUnique(Unique unq) { public boolean equalsUnique(Unique unq) {