From 61f9b32a496f538e89074b5edd563bc1f01fb532 Mon Sep 17 00:00:00 2001 From: Pinaki Poddar Date: Mon, 16 Nov 2009 09:19:24 +0000 Subject: [PATCH] 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 --- .../openjpa/jdbc/schema/Constraint.java | 6 ++--- .../openjpa/jdbc/schema/LocalConstraint.java | 15 ++++++------- .../apache/openjpa/jdbc/schema/Unique.java | 22 ++----------------- 3 files changed, 11 insertions(+), 32 deletions(-) diff --git a/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/schema/Constraint.java b/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/schema/Constraint.java index 3a6e7e6af..d9e8c2ac6 100644 --- a/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/schema/Constraint.java +++ b/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/schema/Constraint.java @@ -24,6 +24,7 @@ package org.apache.openjpa.jdbc.schema; * * @author Abe White */ +@SuppressWarnings("serial") public abstract class Constraint extends ReferenceCounter { @@ -180,9 +181,6 @@ public abstract class Constraint public String toString() { if (getName() != null) return getName(); - - String name = getClass().getName(); - name = name.substring(name.lastIndexOf('.') + 1); - return "<" + name.toLowerCase() + ">"; + return "<" + getClass().getSimpleName().toLowerCase() + ">"; } } diff --git a/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/schema/LocalConstraint.java b/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/schema/LocalConstraint.java index 57f0a74a2..69cc0624f 100644 --- a/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/schema/LocalConstraint.java +++ b/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/schema/LocalConstraint.java @@ -21,7 +21,6 @@ package org.apache.openjpa.jdbc.schema; import java.util.ArrayList; import java.util.List; -import org.apache.commons.lang.ObjectUtils; import org.apache.openjpa.lib.util.Localizer; import org.apache.openjpa.util.InvalidStateException; @@ -32,13 +31,13 @@ import org.apache.openjpa.util.InvalidStateException; * * @author Abe White */ +@SuppressWarnings("serial") public abstract class LocalConstraint extends Constraint { - private static final Localizer _loc = Localizer.forPackage - (LocalConstraint.class); + private static final Localizer _loc = Localizer.forPackage(LocalConstraint.class); - private List _colList = null; + private List _colList = null; private Column[] _cols = null; /** @@ -99,7 +98,7 @@ public abstract class LocalConstraint col == null ? null : getTable())); if (_colList == null) - _colList = new ArrayList(3); + _colList = new ArrayList(3); else if (_colList.contains(col)) 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) { 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() { 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() { Column[] cols = getColumns(); diff --git a/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/schema/Unique.java b/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/schema/Unique.java index b6ecfa5d2..12af3ed1c 100644 --- a/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/schema/Unique.java +++ b/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/schema/Unique.java @@ -24,6 +24,7 @@ package org.apache.openjpa.jdbc.schema; * @author Abe White * @author Pinaki Poddar */ +@SuppressWarnings("serial") public class Unique extends LocalConstraint { @@ -46,26 +47,7 @@ public class Unique } /** - * Adds the given column. - * 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 + * Return true if the structure of this constraint matches that of * the given one (same table, same columns). */ public boolean equalsUnique(Unique unq) {