You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@openjpa.apache.org by jr...@apache.org on 2010/01/15 20:38:26 UTC
svn commit: r899784 [5/11] - in /openjpa/trunk:
openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/conf/
openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/identifier/
openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/
openjpa-jdbc/src/main/jav...
Modified: openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/schema/Column.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/schema/Column.java?rev=899784&r1=899783&r2=899784&view=diff
==============================================================================
--- openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/schema/Column.java (original)
+++ openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/schema/Column.java Fri Jan 15 19:38:18 2010
@@ -27,6 +27,8 @@
import java.sql.Types;
import org.apache.commons.lang.StringUtils;
+import org.apache.openjpa.jdbc.identifier.DBIdentifier;
+import org.apache.openjpa.jdbc.identifier.QualifiedDBIdentifier;
import org.apache.openjpa.jdbc.meta.JavaSQLTypes;
import org.apache.openjpa.jdbc.meta.VersionStrategy;
import org.apache.openjpa.meta.JavaTypes;
@@ -39,6 +41,7 @@
* @author Abe White
* @author Stephen Kim
*/
+@SuppressWarnings("serial")
public class Column
extends ReferenceCounter {
@@ -50,13 +53,12 @@
public static final int FLAG_FK_UPDATE = 2 << 5;
public static final int FLAG_PK_JOIN = 2 << 6;
- private String _name = null;
- private String _fullName = null;
+ private DBIdentifier _name = DBIdentifier.NULL;
private Table _table = null;
- private String _tableName = null;
- private String _schemaName = null;
+ private DBIdentifier _tableName = DBIdentifier.NULL;
+ private DBIdentifier _schemaName = DBIdentifier.NULL;
private int _type = Types.OTHER;
- private String _typeName = null;
+ private DBIdentifier _typeName = DBIdentifier.NULL;
private int _javaType = JavaTypes.OBJECT;
private int _size = 0;
private int _decimals = 0;
@@ -66,9 +68,10 @@
private boolean _autoAssign = false;
private boolean _rel = false;
private boolean _implicitRelation = false;
- private String _target = null;
+ private DBIdentifier _target = DBIdentifier.NULL;
private String _targetField = null;
private int _flags = 0;
+ private QualifiedDBIdentifier _fullPath = null;
private int _index = 0;
private boolean _pk = false;
@@ -88,12 +91,17 @@
*
* @param name the name of the column
* @param table the column's table
+ * @deprecated
*/
public Column(String name, Table table) {
- setName(name);
+ this(DBIdentifier.newColumn(name), table);
+ }
+
+ public Column(DBIdentifier name, Table table) {
+ setIdentifier(name);
if (table != null) {
- setTableName(table.getName());
- setSchemaName(table.getSchemaName());
+ setTableIdentifier(table.getIdentifier());
+ setSchemaIdentifier(table.getSchemaIdentifier());
}
_table = table;
}
@@ -169,79 +177,118 @@
/**
* The column's table name.
+ * @deprecated
*/
public String getTableName() {
- return _tableName;
+ return getTableIdentifier().getName();
+ }
+
+ public DBIdentifier getTableIdentifier() {
+ return _tableName == null ? DBIdentifier.NULL : _tableName;
}
/**
* The column's table name. You can only call this method on columns
* whose table object is not set.
+ * @deprecated
*/
public void setTableName(String name) {
- if (getTable() != null)
- throw new IllegalStateException();
- _tableName = name;
- _fullName = null;
+ setTableIdentifier(DBIdentifier.newTable(name));
}
-
+
+ public void setTableIdentifier(DBIdentifier name) {
+ if (getTable() != null)
+ throw new IllegalStateException();
+ _tableName = name == null ? DBIdentifier.NULL : name;
+ _fullPath = null;
+ }
+
/**
* Reset the table name with the fully qualified table name which
* includes the schema name
+ * @deprecated
*/
public void resetTableName(String name) {
- _tableName = name;
+ _tableName = DBIdentifier.newTable(name);
+ }
+
+ public void resetTableIdentifier(DBIdentifier table) {
+ _tableName = table == null ? DBIdentifier.NULL : table;
}
/**
* The column's schema name.
+ * @deprecated
*/
public String getSchemaName() {
- return _schemaName;
+ return getSchemaIdentifier().getName();
+ }
+
+ public DBIdentifier getSchemaIdentifier() {
+ return _schemaName == null ? DBIdentifier.NULL : _schemaName;
}
/**
* The column's schema name. You can only call this method on columns
* whose table object is not set.
+ * @deprecated use setSchemaIdentifier(DBIdentifier name)
*/
public void setSchemaName(String name) {
+ setSchemaIdentifier(DBIdentifier.newSchema(name));
+ }
+
+ public void setSchemaIdentifier(DBIdentifier name) {
if (getTable() != null)
throw new IllegalStateException();
- _schemaName = name;
+ _schemaName = name == null ? DBIdentifier.NULL : name;
}
/**
* Return the column's name.
+ * @deprecated use getIdentifier()
*/
public String getName() {
- return _name;
+ return getIdentifier().getName();
}
+ public DBIdentifier getIdentifier() {
+ return _name == null ? DBIdentifier.NULL : _name;
+ }
+
+
/**
* Set the column's name. You can only call this method on columns
* whose table object is not set.
+ * @deprecated use setIdentifier(DBIdentifier name)
*/
public void setName(String name) {
+ setIdentifier(DBIdentifier.newColumn(name));
+ }
+
+ public void setIdentifier(DBIdentifier name) {
if (getTable() != null)
throw new IllegalStateException();
- _name = name;
- _fullName = null;
+ _name = name == null ? DBIdentifier.NULL : name;
+ _fullPath = null;
}
/**
* Return the column's full name, in the form <table>.<name>.
+ * @deprecated use getFullDBIdentifier()
*/
public String getFullName() {
- if (_fullName == null) {
- String name = getName();
- if (name == null)
- return null;
- String tname = getTableName();
- if (tname == null)
- return name;
- _fullName = tname + "." + name;
+ return getFullDBIdentifier().getName();
+ }
+
+ public DBIdentifier getFullDBIdentifier() {
+ return getQualifiedPath().getIdentifier();
+ }
+
+ public QualifiedDBIdentifier getQualifiedPath() {
+ if (_fullPath == null) {
+ _fullPath = QualifiedDBIdentifier.newPath(getTableIdentifier(), getIdentifier() );
}
- return _fullName;
+ return _fullPath;
}
/**
@@ -262,16 +309,26 @@
/**
* The database-specific SQL type of this column.
+ * @deprecated
*/
public String getTypeName() {
- return _typeName;
+ return getTypeIdentifier().getName();
+ }
+
+ public DBIdentifier getTypeIdentifier() {
+ return _typeName == null ? DBIdentifier.NULL : _typeName ;
}
/**
* The database-specific SQL type of this column.
+ * @deprecated
*/
public void setTypeName(String typeName) {
- _typeName = typeName;
+ setTypeIdentifier(DBIdentifier.newColumnDefinition(typeName));
+ }
+
+ public void setTypeIdentifier(DBIdentifier typeName) {
+ _typeName = typeName == null ? DBIdentifier.NULL : typeName;
}
/**
@@ -470,16 +527,26 @@
/**
* The name of the column this column joins to, if any. Used for mapping.
+ * @deprecated use getTargetIdentifier()
*/
public String getTarget() {
- return _target;
+ return getTargetIdentifier().getName();
+ }
+
+ public DBIdentifier getTargetIdentifier() {
+ return _target == null ? DBIdentifier.NULL : _target;
}
/**
* The name of the column this column joins to, if any. Used for mapping.
+ * @deprecated use setTargetIdentifier(DBIdentifier target)
*/
public void setTarget(String target) {
- _target = StringUtils.trimToNull(target);
+ setTargetIdentifier(DBIdentifier.newColumn(StringUtils.trimToNull(target)));
+ }
+
+ public void setTargetIdentifier(DBIdentifier target) {
+ _target = target == null ? DBIdentifier.NULL : DBIdentifier.trimToNull(target);
}
/**
@@ -661,7 +728,7 @@
* Returns the column name.
*/
public String toString() {
- return getName();
+ return getIdentifier().getName();
}
/**
@@ -687,9 +754,9 @@
if (col == null)
return false;
- if (!getFullName().equalsIgnoreCase(col.getFullName()))
+ if (!getQualifiedPath().equals(col.getQualifiedPath()))
return false;
- if (!isCompatible(col.getType(), col.getTypeName(), col.getSize(),
+ if (!isCompatible(col.getType(), col.getTypeIdentifier().getName(), col.getSize(),
col.getDecimalDigits()))
return false;
if (getType() == Types.VARCHAR && getSize() > 0 && col.getSize() > 0
@@ -704,12 +771,12 @@
public void copy(Column from) {
if (from == null)
return;
- if (getName() == null)
- setName(from.getName());
+ if (DBIdentifier.isNull(getIdentifier()))
+ setIdentifier(from.getIdentifier());
if (getType() == Types.OTHER)
setType(from.getType());
- if (getTypeName() == null)
- setTypeName(from.getTypeName());
+ if (DBIdentifier.isNull(getTypeIdentifier()))
+ setTypeIdentifier(from.getTypeIdentifier());
if (getJavaType() == JavaTypes.OBJECT)
setJavaType(from.getJavaType());
if (getSize() == 0)
@@ -726,8 +793,8 @@
setRelationId(from.isRelationId());
if (!isImplicitRelation())
setImplicitRelation(from.isRelationId());
- if (getTarget() == null)
- setTarget(from.getTarget());
+ if (DBIdentifier.isNull(getTargetIdentifier()))
+ setTargetIdentifier(from.getTargetIdentifier());
if (getTargetField() == null)
setTargetField(from.getTargetField());
if (_flags == 0)
@@ -761,7 +828,7 @@
}
public boolean hasComment() {
- return _comment != null && !_comment.equalsIgnoreCase(_name);
+ return _comment != null && !_comment.equalsIgnoreCase(_name.toString());
}
public String getComment() {
Modified: openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/schema/ColumnIO.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/schema/ColumnIO.java?rev=899784&r1=899783&r2=899784&view=diff
==============================================================================
--- openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/schema/ColumnIO.java (original)
+++ openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/schema/ColumnIO.java Fri Jan 15 19:38:18 2010
@@ -27,6 +27,7 @@
*
* @author Abe White
*/
+@SuppressWarnings("serial")
public class ColumnIO
implements Serializable {
Modified: openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/schema/Constraint.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/schema/Constraint.java?rev=899784&r1=899783&r2=899784&view=diff
==============================================================================
--- openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/schema/Constraint.java (original)
+++ openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/schema/Constraint.java Fri Jan 15 19:38:18 2010
@@ -18,21 +18,25 @@
*/
package org.apache.openjpa.jdbc.schema;
+import org.apache.openjpa.jdbc.identifier.DBIdentifier;
+import org.apache.openjpa.jdbc.identifier.QualifiedDBIdentifier;
+
/**
* A table constraint. This class is closely aligned with the constraint
* information available from {@link java.sql.DatabaseMetaData}.
*
* @author Abe White
*/
+@SuppressWarnings("serial")
public abstract class Constraint
extends ReferenceCounter {
- private String _name = null;
- private String _fullName = null;
+ private DBIdentifier _name = DBIdentifier.NULL;
+ private QualifiedDBIdentifier _fullPath = null;
private Table _table = null;
- private String _tableName = null;
- private String _schemaName = null;
- private String _columnName = null;
+ private DBIdentifier _tableName = DBIdentifier.NULL;
+ private DBIdentifier _schemaName = DBIdentifier.NULL;
+ private DBIdentifier _columnName = DBIdentifier.NULL;
private boolean _deferred = false;
/**
@@ -46,12 +50,17 @@
*
* @param name the name of the constraint, or null if none
* @param table the local table of the constraint
+ * @deprecated
*/
Constraint(String name, Table table) {
- setName(name);
+ this(DBIdentifier.newConstant(name), table);
+ }
+
+ Constraint(DBIdentifier name, Table table) {
+ setIdentifier(name);
if (table != null) {
- setTableName(table.getName());
- setSchemaName(table.getSchemaName());
+ setTableIdentifier(table.getIdentifier());
+ setSchemaIdentifier(table.getSchemaIdentifier());
}
_table = table;
}
@@ -73,34 +82,55 @@
/**
* Return the column's table name.
+ * @deprecated
*/
public String getTableName() {
- return _tableName;
+ return getTableIdentifier().getName();
+ }
+
+ public DBIdentifier getTableIdentifier() {
+ return _tableName == null ? DBIdentifier.NULL : _tableName;
}
/**
* Set the column's table name. You can only call this method on
* columns whose table object is not set.
+ * @deprecated
*/
public void setTableName(String name) {
- if (getTable() != null)
- throw new IllegalStateException();
- _tableName = name;
- _fullName = null;
+ setTableIdentifier(DBIdentifier.newTable(name));
}
+ public void setTableIdentifier(DBIdentifier name) {
+ if (getTable() != null)
+ throw new IllegalStateException();
+ _tableName = name;
+ _fullPath = null;
+ }
+
+
/**
* Return the column table's schema name.
+ * @deprecated
*/
public String getSchemaName() {
- return _schemaName;
+ return getSchemaIdentifier().getName();
+ }
+
+ public DBIdentifier getSchemaIdentifier() {
+ return _schemaName == null ? DBIdentifier.NULL : _schemaName;
}
/**
* Set the column table's schema name. You can only call this method on
- * columns whose tbale object is not set.
+ * columns whose table object is not set.
+ * @deprecated
*/
public void setSchemaName(String schema) {
+ setSchemaIdentifier(DBIdentifier.newSchema(schema));
+ }
+
+ public void setSchemaIdentifier(DBIdentifier schema) {
if (getTable() != null)
throw new IllegalStateException();
_schemaName = schema;
@@ -108,16 +138,26 @@
/**
* Return the column's name.
+ * @deprecated
*/
public String getColumnName() {
- return _columnName;
+ return getColumnIdentifier().getName();
+ }
+
+ public DBIdentifier getColumnIdentifier() {
+ return _columnName == null ? DBIdentifier.NULL : _columnName;
}
/**
* Set the column's name. You can only call this method on
* columns whose table object is not set.
+ * @deprecated
*/
public void setColumnName(String name) {
+ setColumnIdentifier(DBIdentifier.newColumn(name));
+ }
+
+ public void setColumnIdentifier(DBIdentifier name) {
if (getTable() != null)
throw new IllegalStateException();
_columnName = name;
@@ -125,38 +165,53 @@
/**
* Return the name of the constraint.
+ * @deprecated
*/
public String getName() {
- return _name;
+ return getIdentifier().getName();
+ }
+
+ public DBIdentifier getIdentifier() {
+ return _name == null ? DBIdentifier.NULL : _name;
}
+
/**
* Set the name of the constraint. This method cannot be called if the
* constraint already belongs to a table.
+ * @deprecated
*/
public void setName(String name) {
+ setIdentifier(DBIdentifier.newConstraint(name));
+ }
+
+ public void setIdentifier(DBIdentifier name) {
if (getTable() != null)
throw new IllegalStateException();
_name = name;
- _fullName = null;
+ _fullPath = null;
}
/**
* Return the full name of the constraint.
+ * @deprecated
*/
public String getFullName() {
- if (_fullName == null) {
- String name = getName();
- if (name == null)
- return null;
- String tname = getTableName();
- if (tname == null)
- return name;
- _fullName = tname + "." + name;
+ return getFullIdentifier().getName();
+ }
+
+ public QualifiedDBIdentifier getQualifiedPath() {
+ if (_fullPath == null) {
+ _fullPath = QualifiedDBIdentifier.newPath(getTableIdentifier(), getIdentifier());
}
- return _fullName;
+ return _fullPath;
}
+ public DBIdentifier getFullIdentifier() {
+ return getQualifiedPath().getIdentifier();
+ }
+
+
/**
* Return whether this constraint is a logical constraint only; i.e.
* if it does not exist in the database.
@@ -178,8 +233,8 @@
}
public String toString() {
- if (getName() != null)
- return getName();
+ if (!getIdentifier().isNull())
+ return getIdentifier().getName();
String name = getClass().getName();
name = name.substring(name.lastIndexOf('.') + 1);
Modified: openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/schema/DynamicSchemaFactory.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/schema/DynamicSchemaFactory.java?rev=899784&r1=899783&r2=899784&view=diff
==============================================================================
--- openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/schema/DynamicSchemaFactory.java (original)
+++ openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/schema/DynamicSchemaFactory.java Fri Jan 15 19:38:18 2010
@@ -21,6 +21,9 @@
import java.sql.Types;
import org.apache.openjpa.jdbc.conf.JDBCConfiguration;
+import org.apache.openjpa.jdbc.identifier.Normalizer;
+import org.apache.openjpa.jdbc.identifier.DBIdentifier;
+import org.apache.openjpa.jdbc.identifier.QualifiedDBIdentifier;
import org.apache.openjpa.jdbc.sql.DBDictionary;
import org.apache.openjpa.lib.conf.Configurable;
import org.apache.openjpa.lib.conf.Configuration;
@@ -34,17 +37,18 @@
*
* @author Abe White
*/
+@SuppressWarnings("serial")
public class DynamicSchemaFactory
extends SchemaGroup
implements SchemaFactory, Configurable {
private transient DBDictionary _dict = null;
- private String _schema = null;
+ private DBIdentifier _schema = DBIdentifier.NULL;
public void setConfiguration(Configuration conf) {
JDBCConfiguration jconf = (JDBCConfiguration) conf;
_dict = jconf.getDBDictionaryInstance();
- _schema = jconf.getSchema();
+ _schema = DBIdentifier.newSchema(jconf.getSchema());
}
public void startConfiguration() {
@@ -69,45 +73,67 @@
return super.findTable(name) != null;
}
+ public boolean isKnownTable(QualifiedDBIdentifier path) {
+ return super.findTable(path) != null;
+ }
+
public Table findTable(String name) {
+ return super.findTable(name);
+ }
+
+ public Table findTable(DBIdentifier name) {
if (name == null)
return null;
- Table table = super.findTable(name);
+ QualifiedDBIdentifier path = QualifiedDBIdentifier.getPath(name);
+ return findTable(path);
+ }
+
+ public Table findTable(QualifiedDBIdentifier path) {
+ if (DBIdentifier.isNull(path))
+ return null;
+
+ Table table = super.findTable(path);
if (table != null)
return table;
// if full name, split
- String schemaName = null;
- String tableName = name;
- int dotIdx = name.lastIndexOf('.');
- if (dotIdx != -1) {
- schemaName = name.substring(0, dotIdx);
- tableName = name.substring(dotIdx + 1);
- } else
+ DBIdentifier schemaName = DBIdentifier.NULL;
+ DBIdentifier tableName = path.getUnqualifiedName();
+ if (!DBIdentifier.isNull(path.getSchemaName())) {
+ schemaName = path.getSchemaName();
+ } else {
schemaName = _schema;
+ }
Schema schema = getSchema(schemaName);
if (schema == null) {
schema = addSchema(schemaName);
- // TODO: temp until a more global name scheme is implemented
- addDelimSchemaName(_dict.addDelimiters(schemaName), schema);
}
// Ensure only valid table name(s) are added to the schema
- if (tableName.length() > _dict.maxTableNameLength) {
+ if (tableName.getName().length() > _dict.maxTableNameLength) {
return schema.addTable(tableName,
_dict.getValidTableName(tableName, getSchema(schemaName)));
}
return schema.addTable(tableName);
}
+
+
+// protected Table newTable(String name, Schema schema) {
+// return new DynamicTable(name, schema);
+// }
- protected Table newTable(String name, Schema schema) {
+ protected Table newTable(DBIdentifier name, Schema schema) {
return new DynamicTable(name, schema);
}
- protected Column newColumn(String name, Table table) {
+// protected Column newColumn(String name, Table table) {
+// return new DynamicColumn(name, table);
+// }
+
+ protected Column newColumn(DBIdentifier name, Table table) {
return new DynamicColumn(name, table);
}
@@ -121,21 +147,42 @@
super(name, schema);
}
+ public DynamicTable(DBIdentifier name, Schema schema) {
+ super(name, schema);
+ }
+
+ /**
+ * @deprecated
+ */
public Column getColumn(String name) {
return getColumn(name, null);
}
+ public Column getColumn(DBIdentifier name) {
+ return getColumn(name, null);
+ }
+
+ /**
+ * @deprecated
+ */
public Column getColumn(String name, DBDictionary dict) {
if (name == null)
return null;
+ return getColumn(DBIdentifier.newColumn(name), dict);
+ }
+
+ public Column getColumn(DBIdentifier name, DBDictionary dict) {
+ if (DBIdentifier.isNull(name))
+ return null;
- Column col = super.getColumn(name, dict);
+ Column col = super.getColumn(name);
if (col != null)
return col;
// Ensure only valid column name(s) are added to the table
- if ((name.length() > _dict.maxColumnNameLength) ||
- _dict.getInvalidColumnWordSet().contains(name.toUpperCase())) {
+ if ((name.getName().length() > _dict.maxColumnNameLength) ||
+ _dict.getInvalidColumnWordSet().contains(
+ DBIdentifier.toUpper(name).getName())) {
return addColumn(name,
_dict.getValidColumnName(name, this));
}
@@ -150,10 +197,17 @@
private class DynamicColumn
extends Column {
+ /**
+ * @deprecated
+ */
public DynamicColumn(String name, Table table) {
super(name, table);
}
+ public DynamicColumn(DBIdentifier name, Table table) {
+ super(name, table);
+ }
+
public boolean isCompatible(int type, String typeName, int size,
int decimals) {
if (getType() != Types.OTHER)
@@ -164,7 +218,7 @@
setType(type);
setSize(size);
if (typeName != null)
- setTypeName(typeName);
+ setTypeIdentifier(DBIdentifier.newColumnDefinition(typeName));
if (decimals >= 0)
setDecimalDigits(decimals);
return true;
Modified: openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/schema/ForeignKey.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/schema/ForeignKey.java?rev=899784&r1=899783&r2=899784&view=diff
==============================================================================
--- openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/schema/ForeignKey.java (original)
+++ openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/schema/ForeignKey.java Fri Jan 15 19:38:18 2010
@@ -27,6 +27,8 @@
import org.apache.commons.lang.ObjectUtils;
import org.apache.commons.lang.StringUtils;
+import org.apache.openjpa.jdbc.identifier.Normalizer;
+import org.apache.openjpa.jdbc.identifier.DBIdentifier;
import org.apache.openjpa.jdbc.sql.DBDictionary;
import org.apache.openjpa.lib.log.Log;
import org.apache.openjpa.lib.util.Localizer;
@@ -40,6 +42,7 @@
*
* @author Abe White
*/
+@SuppressWarnings("serial")
public class ForeignKey
extends Constraint {
@@ -75,9 +78,9 @@
private static final Localizer _loc =
Localizer.forPackage(ForeignKey.class);
- private String _pkTableName = null;
- private String _pkSchemaName = null;
- private String _pkColumnName = null;
+ private DBIdentifier _pkTableName = DBIdentifier.NULL;
+ private DBIdentifier _pkSchemaName = DBIdentifier.NULL;
+ private DBIdentifier _pkColumnName = DBIdentifier.NULL;
private int _seq = 0;
private LinkedHashMap _joins = null;
@@ -160,11 +163,16 @@
*
* @param name the foreign key name, if any
* @param table the local table of the foreign key
+ * @deprecated
*/
public ForeignKey(String name, Table table) {
super(name, table);
}
+ public ForeignKey(DBIdentifier name, Table table) {
+ super(name, table);
+ }
+
public boolean isLogical() {
return _delAction == ACTION_NONE;
}
@@ -227,19 +235,29 @@
/**
* The name of the primary key table.
+ * @deprecated
*/
public String getPrimaryKeyTableName() {
+ return getPrimaryKeyTableIdentifier().getName();
+ }
+
+ public DBIdentifier getPrimaryKeyTableIdentifier() {
Table table = getPrimaryKeyTable();
if (table != null)
- return table.getName();
- return _pkTableName;
+ return table.getIdentifier();
+ return _pkTableName == null ? DBIdentifier.NULL : _pkTableName;
}
/**
* The name of the primary key table. You can only set the primary
* key table name on foreign keys that have not already been joined.
+ * @deprecated
*/
public void setPrimaryKeyTableName(String pkTableName) {
+ setPrimaryKeyTableIdentifier(DBIdentifier.newTable(pkTableName));
+ }
+
+ public void setPrimaryKeyTableIdentifier(DBIdentifier pkTableName) {
if (getPrimaryKeyTable() != null)
throw new IllegalStateException();
_pkTableName = pkTableName;
@@ -247,11 +265,16 @@
/**
* The name of the primary key table's schema.
+ * @deprecated
*/
public String getPrimaryKeySchemaName() {
+ return getPrimaryKeySchemaIdentifier().getName();
+ }
+
+ public DBIdentifier getPrimaryKeySchemaIdentifier() {
Table table = getPrimaryKeyTable();
if (table != null)
- return table.getSchemaName();
+ return table.getSchemaIdentifier();
return _pkSchemaName;
}
@@ -259,8 +282,13 @@
* The name of the primary key table's schema. You can only set the
* primary key schema name on foreign keys that have not already been
* joined.
+ * @deprecated
*/
public void setPrimaryKeySchemaName(String pkSchemaName) {
+ setPrimaryKeySchemaIdentifier(DBIdentifier.newSchema(pkSchemaName));
+ }
+
+ public void setPrimaryKeySchemaIdentifier(DBIdentifier pkSchemaName) {
if (getPrimaryKeyTable() != null)
throw new IllegalStateException();
_pkSchemaName = pkSchemaName;
@@ -268,17 +296,27 @@
/**
* The name of the primary key column.
+ * @deprecated
*/
public String getPrimaryKeyColumnName() {
- return _pkColumnName;
+ return getPrimaryKeyColumnIdentifier().getName();
+ }
+
+ public DBIdentifier getPrimaryKeyColumnIdentifier() {
+ return _pkColumnName == null ? DBIdentifier.NULL : _pkColumnName;
}
/**
* The name of the primary key column. You can only set the
* primary key column name on foreign keys that have not already been
* joined.
+ * @deprecated
*/
public void setPrimaryKeyColumnName(String pkColumnName) {
+ setPrimaryKeyColumnIdentifier(DBIdentifier.newColumn(pkColumnName));
+ }
+
+ public void setPrimaryKeyColumnIdentifier(DBIdentifier pkColumnName) {
if (getPrimaryKeyTable() != null)
throw new IllegalStateException();
_pkColumnName = pkColumnName;
@@ -729,7 +767,7 @@
private static boolean hasColumn(Column[] cols, Column col) {
for (int i = 0; i < cols.length; i++)
- if (cols[i].getFullName().equalsIgnoreCase(col.getFullName()))
+ if (cols[i].getQualifiedPath().equals(col.getQualifiedPath()))
return true;
return false;
}
@@ -745,36 +783,41 @@
/**
* Return the name of the foreignkey constraint as defined in the database.
+ * @deprecated
*/
public String loadNameFromDB(DBDictionary dbdict, Connection conn) {
+ return loadIdentifierFromDB(dbdict, conn).getName();
+ }
+
+ public DBIdentifier loadIdentifierFromDB(DBDictionary dbdict, Connection conn) {
if( isLogical() || getTable() == null)
- return null;
- String retVal = null;
+ return DBIdentifier.NULL;
+ DBIdentifier retVal = DBIdentifier.NULL;
try{
Schema schema = getTable().getSchema();
ForeignKey[] fks = dbdict.getImportedKeys(conn.getMetaData(),
- conn.getCatalog(), schema.getName(),
- getTable().getName(), conn, false);
+ DBIdentifier.newCatalog(conn.getCatalog()), schema.getIdentifier(),
+ getTable().getIdentifier(), conn, false);
for ( int i=0; i< fks.length; i++) {
- Table localtable = schema.getTable(fks[i].getTableName());
+ Table localtable = schema.getTable(fks[i].getTableIdentifier());
Table pkTable = schema.getTable(
- fks[i].getPrimaryKeyTableName());
+ fks[i].getPrimaryKeyTableIdentifier());
boolean addFK = false;
ForeignKey fkTemp = localtable.getForeignKey(
- fks[i].getName());
+ fks[i].getIdentifier());
if( fkTemp == null) {
addFK=true;
fkTemp = localtable.addForeignKey(
- fks[i].getName());
+ fks[i].getIdentifier());
fkTemp.setDeferred(fks[i].isDeferred());
fkTemp.setDeleteAction(fks[i].getDeleteAction());
}
if (fks[i].getColumns() == null || fks[i].getColumns().length == 0) {
// Singular column foreign key
if( ! fkTemp.containsColumn(
- localtable.getColumn(fks[i].getColumnName(), dbdict)))
- fkTemp.join(localtable.getColumn(fks[i].getColumnName(), dbdict),
- pkTable.getColumn(fks[i].getPrimaryKeyColumnName(), dbdict));
+ localtable.getColumn(fks[i].getColumnIdentifier())))
+ fkTemp.join(localtable.getColumn(fks[i].getColumnIdentifier()),
+ pkTable.getColumn(fks[i].getPrimaryKeyColumnIdentifier()));
} else {
// Add the multi-column foreign key, joining local and pk columns in
// the temporary key
@@ -790,9 +833,9 @@
}
for (int j = 0; j < locCols.length; j++) {
if( ! fkTemp.containsColumn(
- localtable.getColumn(locCols[j].getName(), dbdict))) {
- fkTemp.join(localtable.getColumn(locCols[j].getName(), dbdict),
- pkTable.getColumn(pkCols[j].getName(), dbdict));
+ localtable.getColumn(locCols[j].getIdentifier()))) {
+ fkTemp.join(localtable.getColumn(locCols[j].getIdentifier()),
+ pkTable.getColumn(pkCols[j].getIdentifier()));
}
}
}
@@ -800,7 +843,7 @@
{
if(addFK)
localtable.removeForeignKey(fkTemp);
- retVal = fks[i].getName();
+ retVal = fks[i].getIdentifier();
break;
}
if(addFK)
@@ -825,8 +868,8 @@
// If this FK is single column key, covert to a multi-column key
Column[] keyCols = createKeyColumns(this);
if (keyCols[0] != null && keyCols[1] != null) {
- setPrimaryKeyColumnName(null);
- setColumnName(null);
+ setPrimaryKeyColumnIdentifier(DBIdentifier.NULL);
+ setColumnIdentifier(DBIdentifier.NULL);
join(keyCols[0], keyCols[1]);
}
}
@@ -845,19 +888,19 @@
*/
private static Column[] createKeyColumns(ForeignKey fk) {
Column fkCol = null;
- if (!StringUtils.isEmpty(fk.getColumnName())) {
+ if (!DBIdentifier.isEmpty(fk.getColumnIdentifier())) {
fkCol = new Column();
- fkCol.setName(fk.getColumnName());
- fkCol.setTableName(fk.getTableName());
- fkCol.setSchemaName(fk.getSchemaName());
+ fkCol.setIdentifier(fk.getColumnIdentifier());
+ fkCol.setTableIdentifier(fk.getTableIdentifier());
+ fkCol.setSchemaIdentifier(fk.getSchemaIdentifier());
}
Column pkCol = null;
- if (!StringUtils.isEmpty(fk.getPrimaryKeyColumnName())) {
+ if (!DBIdentifier.isEmpty(fk.getPrimaryKeyColumnIdentifier())) {
pkCol = new Column();
- pkCol.setName(fk.getPrimaryKeyColumnName());
- pkCol.setTableName(fk.getPrimaryKeyTableName());
- pkCol.setSchemaName(fk.getPrimaryKeySchemaName());
+ pkCol.setIdentifier(fk.getPrimaryKeyColumnIdentifier());
+ pkCol.setTableIdentifier(fk.getPrimaryKeyTableIdentifier());
+ pkCol.setSchemaIdentifier(fk.getPrimaryKeySchemaIdentifier());
}
return new Column[] { fkCol, pkCol };
}
@@ -878,7 +921,7 @@
}
public int hashCode() {
- return getFk().getName() != null ? getFk().getName().hashCode() : getFk().hashCode();
+ return getFk().getIdentifier() != null ? getFk().getIdentifier().hashCode() : getFk().hashCode();
}
public boolean equals(Object fkObj) {
@@ -893,14 +936,14 @@
return false;
if (getFk().isDeferred() != fk.isDeferred())
return false;
- if (!getFk().getName().equals(fk.getName())) {
+ if (!getFk().getIdentifier().equals(fk.getIdentifier())) {
return false;
}
// Assert PK table name and schema
- if (!StringUtils.equals(getFk().getPrimaryKeySchemaName(), fk.getPrimaryKeySchemaName()) ||
- !StringUtils.equals(getFk().getPrimaryKeyTableName(), fk.getPrimaryKeyTableName()) ||
- !StringUtils.equals(getFk().getSchemaName(), fk.getSchemaName()) ||
- !StringUtils.equals(getFk().getTableName(), fk.getTableName())) {
+ if (!getFk().getPrimaryKeySchemaIdentifier().equals(fk.getPrimaryKeySchemaIdentifier()) ||
+ !getFk().getPrimaryKeyTableIdentifier().equals(fk.getPrimaryKeyTableIdentifier()) ||
+ !getFk().getSchemaIdentifier().equals(fk.getSchemaIdentifier()) ||
+ !getFk().getTableIdentifier().equals(fk.getTableIdentifier())) {
return false;
}
return true;
Modified: openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/schema/Index.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/schema/Index.java?rev=899784&r1=899783&r2=899784&view=diff
==============================================================================
--- openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/schema/Index.java (original)
+++ openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/schema/Index.java Fri Jan 15 19:38:18 2010
@@ -18,7 +18,7 @@
*/
package org.apache.openjpa.jdbc.schema;
-import org.apache.commons.lang.StringUtils;
+import org.apache.openjpa.jdbc.identifier.DBIdentifier;
/**
* Represents a database index. Can also represent a partial index,
@@ -27,6 +27,7 @@
* @author Abe White
* @author Stephen Kim
*/
+@SuppressWarnings("serial")
public class Index
extends LocalConstraint {
@@ -43,11 +44,16 @@
*
* @param name the name of the index
* @param table the table of the index
+ * @deprecated
*/
public Index(String name, Table table) {
super(name, table);
}
+ public Index(DBIdentifier name, Table table) {
+ super(name, table);
+ }
+
/**
* Return true if this is a UNIQUE index.
*/
@@ -67,6 +73,17 @@
}
/**
+ * @deprecated
+ */
+ public String getFullName() {
+ return getFullIdentifier().getName();
+ }
+
+ public DBIdentifier getFullIdentifier() {
+ return getQualifiedPath().getIdentifier();
+ }
+
+ /**
* Indexes are equal if they have the same name, the same columns, and
* are both unique/not unique.
*/
@@ -78,7 +95,7 @@
if (isUnique() != idx.isUnique())
return false;
- if (!StringUtils.equalsIgnoreCase(getFullName(), idx.getFullName()))
+ if (!getQualifiedPath().equals(idx.getQualifiedPath()))
return false;
return equalsLocalConstraint(idx);
}
Modified: openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/schema/LazySchemaFactory.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/schema/LazySchemaFactory.java?rev=899784&r1=899783&r2=899784&view=diff
==============================================================================
--- openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/schema/LazySchemaFactory.java (original)
+++ openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/schema/LazySchemaFactory.java Fri Jan 15 19:38:18 2010
@@ -23,9 +23,13 @@
import java.sql.SQLException;
import org.apache.openjpa.jdbc.conf.JDBCConfiguration;
+import org.apache.openjpa.jdbc.identifier.DBIdentifier;
+import org.apache.openjpa.jdbc.identifier.DBIdentifierUtil;
+import org.apache.openjpa.jdbc.identifier.QualifiedDBIdentifier;
import org.apache.openjpa.jdbc.sql.SQLExceptions;
import org.apache.openjpa.lib.conf.Configurable;
import org.apache.openjpa.lib.conf.Configuration;
+import org.apache.openjpa.lib.identifier.IdentifierRule;
/**
* Factory that uses database metadata to construct the system schema.
@@ -35,6 +39,7 @@
*
* @author Abe White
*/
+@SuppressWarnings("serial")
public class LazySchemaFactory
extends SchemaGroup
implements SchemaFactory, Configurable {
@@ -80,21 +85,51 @@
// nothing to do
}
+ /**
+ * @deprecated
+ */
public Table findTable(String name) {
if (name == null)
return null;
+ return findTable(DBIdentifier.newTable(name));
+ }
- Table table = super.findTable(name);
+ public Table findTable(DBIdentifier name) {
+ if (name == null)
+ return null;
+ return findTable(QualifiedDBIdentifier.getPath(name));
+ }
+
+ public Table findTable(QualifiedDBIdentifier path) {
+ if (path == null)
+ return null;
+
+ Table table = super.findTable(path);
if (table != null)
return table;
- generateSchemaObject(name, true);
- return super.findTable(name);
+ generateSchemaObject(path, true);
+ return super.findTable(path);
}
+ /**
+ * @deprecated
+ */
public Sequence findSequence(String name) {
if (name == null)
return null;
+ return findSequence(DBIdentifier.newSequence(name));
+ }
+
+ public Sequence findSequence(DBIdentifier name) {
+ if (name == null)
+ return null;
+ return findSequence(QualifiedDBIdentifier.getPath(name));
+ }
+
+ public Sequence findSequence(QualifiedDBIdentifier name) {
+ if (name == null)
+ return null;
Sequence seq = super.findSequence(name);
if (seq != null)
@@ -107,24 +142,10 @@
/**
* Generate the table or sequence with the given name.
*/
- private void generateSchemaObject(String name, boolean isTable) {
+ private void generateSchemaObject(QualifiedDBIdentifier name, boolean isTable) {
// if full name, split
- String schemaName = null;
- String objectName = name;
-
- // look for the standard schema separator...
- int dotIdx = name.indexOf('.');
- // ... or the dictionary schema separator
- if (dotIdx == -1) {
- String sep = _conf.getDBDictionaryInstance().catalogSeparator;
- if (!".".equals(sep))
- dotIdx = name.indexOf(sep);
- }
-
- if (dotIdx != -1) {
- schemaName = name.substring(0, dotIdx);
- objectName = name.substring(dotIdx + 1);
- }
+ DBIdentifier schemaName = name.getSchemaName();
+ DBIdentifier objectName = name.getIdentifier();
// we share a single connection across all schemas, so synch
// on the schema group
@@ -149,18 +170,18 @@
if (table != null) {
if (_pks)
- _gen.generatePrimaryKeys(table.getSchemaName(),
- table.getName(), _conn, _meta);
+ _gen.generatePrimaryKeys(table.getSchemaIdentifier(),
+ table.getIdentifier(), _conn, _meta);
if (_indexes)
- _gen.generateIndexes(table.getSchemaName(),
- table.getName(), _conn, _meta);
+ _gen.generateIndexes(table.getSchemaIdentifier(),
+ table.getIdentifier(), _conn, _meta);
// generate foreign keys from the table; this might
// end up re-calling this getTable method if the foreign
// key links to a table that hasn't been loaded yet
if (_fks)
- _gen.generateForeignKeys(table.getSchemaName(),
- table.getName(), _conn, _meta);
+ _gen.generateForeignKeys(table.getSchemaIdentifier(),
+ table.getIdentifier(), _conn, _meta);
}
} else
_gen.generateSequences(schemaName, objectName, _conn,
Modified: openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/schema/LocalConstraint.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/schema/LocalConstraint.java?rev=899784&r1=899783&r2=899784&view=diff
==============================================================================
--- openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/schema/LocalConstraint.java (original)
+++ openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/schema/LocalConstraint.java Fri Jan 15 19:38:18 2010
@@ -21,7 +21,7 @@
import java.util.ArrayList;
import java.util.List;
-import org.apache.commons.lang.ObjectUtils;
+import org.apache.openjpa.jdbc.identifier.DBIdentifier;
import org.apache.openjpa.lib.util.Localizer;
import org.apache.openjpa.util.InvalidStateException;
@@ -32,13 +32,14 @@
*
* @author Abe White
*/
+@SuppressWarnings("serial")
public abstract class LocalConstraint
extends Constraint {
private static final Localizer _loc = Localizer.forPackage
(LocalConstraint.class);
- private List _colList = null;
+ private List<Column> _colList = null;
private Column[] _cols = null;
/**
@@ -52,12 +53,16 @@
*
* @param name the name of the constraint, if any
* @param table the table of the constraint
+ * @deprecated
*/
public LocalConstraint(String name, Table table) {
super(name, table);
}
- /**
+ public LocalConstraint(DBIdentifier name, Table table) {
+ super(name, table);
+ }
+/**
* Called when the constraint is removed from its table.
*/
void remove() {
@@ -99,7 +104,7 @@
col == null ? null : getTable()));
if (_colList == null)
- _colList = new ArrayList(3);
+ _colList = new ArrayList<Column>(3);
else if (_colList.contains(col))
return;
@@ -168,7 +173,7 @@
*/
private static boolean hasColumn(Column[] cols, Column col) {
for (int i = 0; i < cols.length; i++)
- if (cols[i].getFullName().equalsIgnoreCase(col.getFullName()))
+ if (cols[i].getQualifiedPath().equals(col.getQualifiedPath()))
return true;
return false;
}
Modified: openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/schema/NameSet.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/schema/NameSet.java?rev=899784&r1=899783&r2=899784&view=diff
==============================================================================
--- openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/schema/NameSet.java (original)
+++ openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/schema/NameSet.java Fri Jan 15 19:38:18 2010
@@ -23,6 +23,8 @@
import java.util.Set;
import org.apache.commons.lang.StringUtils;
+import org.apache.openjpa.jdbc.identifier.DBIdentifier;
+import org.apache.openjpa.jdbc.identifier.DBIdentifier.DBIdentifierType;
import org.apache.openjpa.lib.util.Localizer;
/**
@@ -32,30 +34,47 @@
*
* @author Abe White
*/
+@SuppressWarnings("serial")
public class NameSet
implements Serializable {
private static final Localizer _loc = Localizer.forPackage(NameSet.class);
- private Set _names = null;
+ private Set<DBIdentifier> _names = null;
/**
* Return true if the given name is in use already.
+ * @deprecated
*/
public boolean isNameTaken(String name) {
- if (name == null)
+ return isNameTaken(DBIdentifier.toUpper(DBIdentifier.newDefault(name)));
+ }
+
+ public boolean isNameTaken(DBIdentifier name) {
+ if (DBIdentifier.isEmpty(name)) {
return true;
- return _names != null && _names.contains(name.toUpperCase());
+ }
+ if (_names == null) {
+ return false;
+ }
+ DBIdentifier sName = DBIdentifier.toUpper(name);
+ return _names.contains(sName);
}
/**
+ * @deprecated
+ */
+ protected void addName(String name, boolean validate) {
+ addName(DBIdentifier.newIdentifier(name, DBIdentifierType.DEFAULT, true), validate);
+ }
+ /**
* Attempt to add the given name to the set.
*
* @param name the name to add
* @param validate if true, null or empty names will not be accepted
*/
- protected void addName(String name, boolean validate) {
- if (StringUtils.isEmpty(name)) {
+ protected void addName(DBIdentifier name, boolean validate) {
+ if (DBIdentifier.isNull(name) || StringUtils.isEmpty(name.getName())) {
if (validate)
throw new IllegalArgumentException(_loc.get("bad-name", name)
.getMessage());
@@ -66,15 +85,27 @@
// DBs use different namespaces for components, and it would be
// difficult to find a scheme that fits all and is still useful
if (_names == null)
- _names = new HashSet();
- _names.add(name.toUpperCase());
+ _names = new HashSet<DBIdentifier>();
+ DBIdentifier sName = DBIdentifier.toUpper(name);
+ _names.add(sName);
}
/**
- * Remove the given name from the table.
+ * @deprecated
*/
protected void removeName(String name) {
- if (name != null && _names != null)
- _names.remove(name.toUpperCase());
+ if (name != null && _names != null) {
+ removeName(DBIdentifier.newIdentifier(name, DBIdentifierType.DEFAULT, true));
+ }
+ }
+ /**
+ * Remove the given name from the table.
+ */
+ protected void removeName(DBIdentifier name) {
+ if (!DBIdentifier.isNull(name) && _names != null) {
+ DBIdentifier sName = DBIdentifier.toUpper(name);
+ _names.remove(sName);
+ }
}
+
}
Modified: openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/schema/PrimaryKey.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/schema/PrimaryKey.java?rev=899784&r1=899783&r2=899784&view=diff
==============================================================================
--- openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/schema/PrimaryKey.java (original)
+++ openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/schema/PrimaryKey.java Fri Jan 15 19:38:18 2010
@@ -18,6 +18,8 @@
*/
package org.apache.openjpa.jdbc.schema;
+import org.apache.openjpa.jdbc.identifier.DBIdentifier;
+
/**
* Represents a table primary key. It can also represent a partial key,
* aligning with the key information available from
@@ -25,6 +27,7 @@
*
* @author Abe White
*/
+@SuppressWarnings("serial")
public class PrimaryKey
extends LocalConstraint {
@@ -41,11 +44,16 @@
*
* @param name the name of the primary key, if any
* @param table the table of the primary key
+ * @deprecated
*/
public PrimaryKey(String name, Table table) {
super(name, table);
}
+ public PrimaryKey(DBIdentifier name, Table table) {
+ super(name, table);
+ }
+
public boolean isLogical() {
return _logical;
}
Modified: openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/schema/Schema.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/schema/Schema.java?rev=899784&r1=899783&r2=899784&view=diff
==============================================================================
--- openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/schema/Schema.java (original)
+++ openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/schema/Schema.java Fri Jan 15 19:38:18 2010
@@ -22,22 +22,22 @@
import java.util.Map;
import java.util.TreeMap;
-import org.apache.commons.lang.StringUtils;
+import org.apache.openjpa.jdbc.identifier.DBIdentifier;
+import org.apache.openjpa.jdbc.identifier.DBIdentifier.DBIdentifierType;
/**
* Represents a database schema.
*
* @author Abe White
*/
+@SuppressWarnings("serial")
public class Schema
- implements Comparable, Serializable {
+ implements Comparable<Schema>, Serializable {
- private String _name = null;
+ private DBIdentifier _name = DBIdentifier.NULL;
private SchemaGroup _group = null;
- private Map _tableMap = null;
- private Map _seqMap = null;
- // TODO: temp until a more global solution is implemented
- private Map<String, Sequence> _delimSeqMap = null;
+ private Map<DBIdentifier, Table> _tableMap = null;
+ private Map<DBIdentifier, Sequence> _seqMap = null;
// cache
private Table[] _tables = null;
@@ -54,9 +54,14 @@
*
* @param name the schema name, if any
* @param group the schema's owning group
+ * @deprecated
*/
public Schema(String name, SchemaGroup group) {
- setName(name);
+ this(DBIdentifier.newSchema(name), group);
+ }
+
+ public Schema(DBIdentifier name, SchemaGroup group) {
+ setIdentifier(name);
_group = group;
}
@@ -83,21 +88,31 @@
/**
* Return the name of the schema, or null if none.
+ * @deprecated
*/
public String getName() {
+ return getIdentifier().getName();
+ }
+
+ public DBIdentifier getIdentifier() {
return _name;
}
/**
* Set the name of the schema. This method can only be used for schemas
* not attached to a group.
+ * @deprecated
*/
public void setName(String name) {
+ setIdentifier(DBIdentifier.trimToNull(DBIdentifier.newSchema(name)));
+ }
+
+ public void setIdentifier(DBIdentifier name) {
if (getSchemaGroup() != null)
throw new IllegalStateException();
- _name = StringUtils.trimToNull(name);
+ _name = DBIdentifier.trimToNull(name);
}
-
+
/**
* Return the schema's tables.
*/
@@ -110,35 +125,56 @@
/**
* Return the table with the given name, or null if none.
+ * @deprecated
*/
public Table getTable(String name) {
if (name == null || _tableMap == null)
return null;
- return (Table) _tableMap.get(name.toUpperCase());
+ return getTable(DBIdentifier.newIdentifier(name, DBIdentifierType.TABLE, true));
+ }
+
+ public Table getTable(DBIdentifier name) {
+ if (DBIdentifier.isNull(name) || _tableMap == null)
+ return null;
+ DBIdentifier sName = DBIdentifier.toUpper(name);
+ return (Table) _tableMap.get(sName);
}
/**
* Add a table to the schema.
+ * @deprecated
*/
public Table addTable(String name) {
+ return addTable(DBIdentifier.newTable(name));
+ }
+
+ public Table addTable(DBIdentifier name) {
SchemaGroup group = getSchemaGroup();
Table tab;
+ name = name.getUnqualifiedName();
if (group != null) {
group.addName(name, true);
tab = group.newTable(name, this);
} else
tab = new Table(name, this);
if (_tableMap == null)
- _tableMap = new TreeMap();
- _tableMap.put(name.toUpperCase(), tab);
+ _tableMap = new TreeMap<DBIdentifier, Table>();
+ DBIdentifier sName = DBIdentifier.toUpper(name);
+ _tableMap.put(sName, tab);
_tables = null;
return tab;
}
+
/**
* Add a table with a shortened (i.e., validated) name to the schema
+ * @deprecated
*/
public Table addTable(String name, String validName) {
+ return addTable(DBIdentifier.newTable(name), DBIdentifier.newTable(validName));
+ }
+
+ public Table addTable(DBIdentifier name, DBIdentifier validName) {
SchemaGroup group = getSchemaGroup();
Table tab;
if (group != null) {
@@ -147,8 +183,9 @@
} else
tab = new Table(validName, this);
if (_tableMap == null)
- _tableMap = new TreeMap();
- _tableMap.put(name.toUpperCase(), tab);
+ _tableMap = new TreeMap<DBIdentifier, Table>();
+ DBIdentifier sName = DBIdentifier.toUpper(name);
+ _tableMap.put(sName, tab);
_tables = null;
return tab;
}
@@ -162,15 +199,16 @@
if (tab == null || _tableMap == null)
return false;
- Table cur = (Table) _tableMap.get(tab.getName().toUpperCase());
+ DBIdentifier sName = DBIdentifier.toUpper(tab.getIdentifier());
+ Table cur = (Table) _tableMap.get(sName);
if (!cur.equals(tab))
return false;
- _tableMap.remove(tab.getName().toUpperCase());
+ _tableMap.remove(sName);
_tables = null;
SchemaGroup group = getSchemaGroup();
if (group != null)
- group.removeName(tab.getName());
+ group.removeName(tab.getIdentifier());
tab.remove();
return true;
}
@@ -183,7 +221,7 @@
if (table == null)
return null;
- Table copy = addTable(table.getName());
+ Table copy = addTable(table.getIdentifier());
Column[] cols = table.getColumns();
for (int i = 0; i < cols.length; i++)
copy.importColumn(cols[i]);
@@ -204,22 +242,32 @@
/**
* Return the sequence with the given name, or null if none.
+ * @deprecated
*/
public Sequence getSequence(String name) {
if (name == null || _seqMap == null)
return null;
- // TODO: temp until a more global solution is implemented
- Sequence seq = (Sequence) _seqMap.get(name.toUpperCase());
- if (seq == null && _delimSeqMap != null) {
- seq = _delimSeqMap.get(name.toUpperCase());
- }
+ return getSequence(DBIdentifier.newIdentifier(name, DBIdentifierType.SEQUENCE, true));
+ }
+
+ public Sequence getSequence(DBIdentifier name) {
+ if (DBIdentifier.isNull(name) || _seqMap == null)
+ return null;
+
+ DBIdentifier sName = DBIdentifier.toUpper(name);
+ Sequence seq = (Sequence) _seqMap.get(sName);
return seq;
}
/**
* Add a sequence to the schema.
+ * @deprecated
*/
public Sequence addSequence(String name) {
+ return addSequence(DBIdentifier.newIdentifier(name, DBIdentifierType.SEQUENCE, true));
+ }
+
+ public Sequence addSequence(DBIdentifier name) {
SchemaGroup group = getSchemaGroup();
Sequence seq;
if (group != null) {
@@ -228,22 +276,13 @@
} else
seq = new Sequence(name, this);
if (_seqMap == null)
- _seqMap = new TreeMap();
- _seqMap.put(name.toUpperCase(), seq);
+ _seqMap = new TreeMap<DBIdentifier, Sequence>();
+
+ DBIdentifier sName = DBIdentifier.toUpper(name);
+ _seqMap.put(sName, seq);
_seqs = null;
return seq;
}
-
- public void addDelimSequenceName(String name, Sequence seq) {
- SchemaGroup group = getSchemaGroup();
- if (group != null) {
- group.addName(name, true);
- }
- if (_delimSeqMap == null) {
- _delimSeqMap = new TreeMap<String, Sequence>();
- }
- _delimSeqMap.put(name.toUpperCase(), seq);
- }
/**
* Remove the given sequence from the schema.
@@ -254,15 +293,16 @@
if (seq == null || _seqMap == null)
return false;
- Sequence cur = (Sequence) _seqMap.get(seq.getName().toUpperCase());
+ DBIdentifier sName = DBIdentifier.toUpper(seq.getIdentifier());
+ Sequence cur = (Sequence) _seqMap.get(sName);
if (!cur.equals(seq))
return false;
- _seqMap.remove(seq.getName().toUpperCase());
+ _seqMap.remove(sName);
_seqs = null;
SchemaGroup group = getSchemaGroup();
if (group != null)
- group.removeName(seq.getName());
+ group.removeName(seq.getIdentifier());
seq.remove();
return true;
}
@@ -274,26 +314,27 @@
if (seq == null)
return null;
- Sequence copy = addSequence(seq.getName());
+ Sequence copy = addSequence(seq.getIdentifier());
copy.setInitialValue(seq.getInitialValue());
copy.setIncrement(seq.getIncrement());
copy.setAllocate(seq.getAllocate());
return copy;
}
- public int compareTo(Object other) {
- String name = getName();
- String otherName = ((Schema) other).getName();
- if (name == null && otherName == null)
+ public int compareTo(Schema other) {
+ DBIdentifier name = getIdentifier();
+ DBIdentifier otherName = ((Schema) other).getIdentifier();
+ if (DBIdentifier.isNull(name) && DBIdentifier.isNull(otherName)) {
return 0;
- if (name == null)
+ }
+ if (DBIdentifier.isNull(name))
return 1;
- if (otherName == null)
+ if (DBIdentifier.isNull(otherName))
return -1;
return name.compareTo(otherName);
}
public String toString() {
- return getName();
+ return getIdentifier().getName();
}
}