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 [2/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...
Added: openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/identifier/DefaultIdentifierConfiguration.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/identifier/DefaultIdentifierConfiguration.java?rev=899784&view=auto
==============================================================================
--- openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/identifier/DefaultIdentifierConfiguration.java (added)
+++ openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/identifier/DefaultIdentifierConfiguration.java Fri Jan 15 19:38:18 2010
@@ -0,0 +1,81 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.openjpa.jdbc.identifier;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import org.apache.openjpa.lib.identifier.IdentifierConfiguration;
+import org.apache.openjpa.lib.identifier.IdentifierRule;
+import org.apache.openjpa.lib.identifier.IdentifierUtil;
+
+public class DefaultIdentifierConfiguration implements IdentifierConfiguration {
+
+ private DBIdentifierRule normalizingRule = new DBIdentifierRule();
+ private Map<String, IdentifierRule> normalizingRules = new HashMap<String, IdentifierRule>();
+
+ public DefaultIdentifierConfiguration() {
+ normalizingRules.put(IdentifierRule.DEFAULT_RULE, normalizingRule);
+ }
+
+ public boolean delimitAll() {
+ return false;
+ }
+
+ public IdentifierRule getDefaultIdentifierRule() {
+ return normalizingRule;
+ }
+
+ public String getDelimitedCase() {
+ return IdentifierUtil.CASE_PRESERVE;
+ }
+
+ public String getSchemaCase() {
+ return IdentifierUtil.CASE_PRESERVE;
+ }
+
+ public String getLeadingDelimiter() {
+ return IdentifierUtil.DOUBLE_QUOTE;
+ }
+
+ public String getIdentifierDelimiter() {
+ return IdentifierUtil.DOT;
+ }
+
+ public String getIdentifierConcatenator() {
+ return IdentifierUtil.UNDERSCORE;
+ }
+
+ public <T> IdentifierRule getIdentifierRule(T t) {
+ return normalizingRule;
+ }
+
+ @SuppressWarnings("unchecked")
+ public Map<String, IdentifierRule> getIdentifierRules() {
+ return normalizingRules;
+ }
+
+ public String getTrailingDelimiter() {
+ return IdentifierUtil.DOUBLE_QUOTE;
+ }
+
+ public boolean getSupportsDelimitedIdentifiers() {
+ return true;
+ }
+}
Propchange: openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/identifier/DefaultIdentifierConfiguration.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/identifier/Normalizer.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/identifier/Normalizer.java?rev=899784&view=auto
==============================================================================
--- openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/identifier/Normalizer.java (added)
+++ openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/identifier/Normalizer.java Fri Jan 15 19:38:18 2010
@@ -0,0 +1,311 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.openjpa.jdbc.identifier;
+
+import org.apache.commons.lang.StringUtils;
+import org.apache.openjpa.jdbc.sql.DBDictionary;
+import org.apache.openjpa.lib.identifier.IdentifierConfiguration;
+import org.apache.openjpa.lib.identifier.IdentifierRule;
+import org.apache.openjpa.lib.identifier.IdentifierUtil;
+
+/**
+ * Static utility class used for operating on string based identifiers.
+ */
+public class Normalizer {
+
+ private static IdentifierUtil normalizer =
+ new DBIdentifierUtilImpl(new DefaultIdentifierConfiguration());
+
+ private static IdentifierRule defaultRule;
+
+ static {
+ defaultRule = normalizer.getIdentifierConfiguration().getDefaultIdentifierRule();
+ }
+
+ public static IdentifierConfiguration getNamingConfiguration() {
+ return normalizer.getIdentifierConfiguration();
+ }
+
+ /**
+ * Normalizes a multi-part name
+ * @param name
+ * @return
+ */
+ public static String normalizeMulti(String name) {
+ if (StringUtils.isEmpty(name)) {
+ return name;
+ }
+ String[] names = normalizer.splitName(defaultRule, name);
+ return normalizer.joinNames(defaultRule, names);
+ }
+
+ /**
+ * Normalizes a single part name
+ * @param name
+ * @return
+ */
+ public static String normalizeString(String name) {
+ if (StringUtils.isEmpty(name)) {
+ return name;
+ }
+ if (!normalizer.isDelimited(defaultRule, name)) {
+ // If not delimited, delimit the string if necessary
+ return normalizer.delimit(defaultRule, name);
+ }
+ return name;
+ }
+
+ /**
+ * Returns true if the name is delimited with default delimiters
+ * @param name
+ * @return
+ */
+ public static boolean isDelimited(String name) {
+ if (StringUtils.isEmpty(name)) {
+ return false;
+ }
+ return normalizer.isDelimited(defaultRule, name);
+ }
+
+ /**
+ * Splits names into individual components and compares individually
+ * for equality
+ * @param name1
+ * @param name2
+ * @return
+ */
+ public static boolean fullNamesEqual(String name1, String name2) {
+ if (StringUtils.isEmpty(name1) && StringUtils.isEmpty(name2)) {
+ return true;
+ }
+ // Split multi-part names into individual components and compare
+ // each component. If delimited, do case compare.
+ String[] names1 = normalizer.splitName(defaultRule, name1);
+ String[] names2 = normalizer.splitName(defaultRule, name2);
+ if (names1.length != names2.length) {
+ return false;
+ }
+ for (int i = 0; i < names1.length; i++) {
+ if (normalizer.isDelimited(defaultRule, names1[i])) {
+ if (!StringUtils.equals(names1[i],names2[i])) {
+ return false;
+ }
+ } else {
+ if (!StringUtils.equalsIgnoreCase(names1[i],names2[i])) {
+ return false;
+ }
+ }
+ }
+ return true;
+ }
+
+ /**
+ * Compares two string names for equality. If delimited, does a
+ * case comparison. If not delimited, does a case insensitive
+ * comparison.
+ * @param name1
+ * @param name2
+ * @return
+ */
+ public static boolean namesEqual(String name1, String name2) {
+ if (StringUtils.isEmpty(name1) && StringUtils.isEmpty(name2)) {
+ return true;
+ }
+ if (normalizer.isDelimited(defaultRule, name1)) {
+ if (!StringUtils.equals(name1, name2)) {
+ return false;
+ }
+ } else {
+ if (!StringUtils.equalsIgnoreCase(name1, name2)) {
+ return false;
+ }
+ }
+ return true;
+ }
+
+ /**
+ * Normalizes a name, if not delimited, converts to uppercase.
+ * @param name
+ * @return
+ */
+ public static String normalizeUpper(String name) {
+ String nName = normalizeString(name);
+ // Do not convert delimited names to upper case. They may have
+ // been delimited to preserve case.
+ if (!isDelimited(nName)) {
+ nName = name.toUpperCase();
+ }
+ return nName;
+ }
+
+ /**
+ * Splits a name into normalized components
+ * @param name
+ * @return
+ */
+ public static String[] splitName(String name) {
+ return normalizer.splitName(defaultRule, name);
+ }
+
+
+ /**
+ * Splits a name into normalized components using the specified
+ * name delimiter (ex. schema:table, delim = : --> { schema, table }
+ * @param name
+ * @return
+ */
+ public static String[] splitName(String name, String delim) {
+ return normalizer.splitName(defaultRule, name, delim);
+ }
+
+ /**
+ * Joins multiple names using default identifier rules.
+ * @param names
+ * @return
+ */
+ public static String joinNames(String[] names) {
+ return normalizer.joinNames(defaultRule, names);
+ }
+
+ /**
+ * Joins multiple names using the specified delimiter.
+ * @param names
+ * @return
+ */
+ public static String joinNames(String[] names, String delimiter) {
+ return normalizer.joinNames(defaultRule, names, delimiter);
+ }
+
+ /**
+ * Joins two names using the default identifier rules.
+ * @param names
+ * @return
+ */
+ public static String joinNames(String name1, String name2) {
+ return joinNames(new String[] { name1, name2});
+ }
+
+
+ /**
+ * Truncates a name to the specified length while maintaining
+ * delimiters.
+ * @param name
+ * @param length
+ * @return
+ */
+ public static String truncate(String name, int length) {
+ return normalizer.truncateName(defaultRule, name, length);
+ }
+
+ /**
+ * Convert a normalized name to a name using the specified configuration and
+ * naming rule.
+ * Note: Currently only delimiters are converted.
+ * @param config
+ * @param rule
+ * @param name
+ * @return
+ */
+ public static String convert(IdentifierConfiguration config, String rule, String name) {
+ return normalizer.convert(config, rule, name);
+ }
+
+ /**
+ * Combines two names using default identifier rules.
+ * @param name1
+ * @param name2
+ * @return
+ */
+ public static String combine(String name1, String name2) {
+ return normalizer.combineNames(defaultRule, name1, name2);
+ }
+
+ /**
+ * Combines multiple names using default identifier rules.
+ * @param name1
+ * @param name2
+ * @return
+ */
+ public static String combine(String...names) {
+ return normalizer.combineNames(defaultRule, names);
+ }
+
+
+ /**
+ * Appends one string to another using default identifier rules.
+ * @param name1
+ * @param name2
+ * @return
+ */
+ public static String append(String name1, String name2) {
+ return normalizer.appendNames(defaultRule, name1, name2);
+ }
+
+ /**
+ * Removes Hungarian notation from a string.
+ * @param name1
+ * @param name2
+ * @return
+ */
+ public static String removeHungarianNotation(String name) {
+ return normalizer.removeHungarianNotation(defaultRule, name);
+ }
+
+ /**
+ * Removes default delimiters from a string.
+ * @param name1
+ * @param name2
+ * @return
+ */
+ public static String removeDelimiters(String name) {
+ return normalizer.removeDelimiters(defaultRule, name);
+ }
+
+ /**
+ * Delimits a string if necessary, optionally forcing it to be
+ * delimited.
+ * @param name1
+ * @param name2
+ * @return
+ */
+ public static String delimit(String name, boolean force) {
+ return normalizer.delimit(defaultRule, name, force);
+ }
+
+ /**
+ * Determines whether a name can be split into multiple components.
+ * @param name1
+ * @param name2
+ * @return
+ */
+ public static boolean canSplit(String name) {
+ return normalizer.canSplit(defaultRule, name);
+ }
+
+ /**
+ * Determines whether a name can be split into multiple components, taking
+ * into account the specified delimiter.
+ * @param name1
+ * @param name2
+ * @return
+ */
+ public static boolean canSplit(String name, String delim) {
+ return normalizer.canSplit(defaultRule, name, delim);
+ }
+}
Propchange: openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/identifier/Normalizer.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/identifier/QualifiedDBIdentifier.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/identifier/QualifiedDBIdentifier.java?rev=899784&view=auto
==============================================================================
--- openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/identifier/QualifiedDBIdentifier.java (added)
+++ openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/identifier/QualifiedDBIdentifier.java Fri Jan 15 19:38:18 2010
@@ -0,0 +1,359 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.openjpa.jdbc.identifier;
+
+import java.io.Serializable;
+import java.util.ArrayList;
+import java.util.List;
+
+import org.apache.openjpa.lib.identifier.Identifier;
+
+/**
+ * This class extends DBIdentifier to provide support for qualified identifiers
+ * such as schema qualified tables and table qualified columns. It provides methods
+ * to create qualified identifiers from individual identifiers.
+ *
+ */
+public class QualifiedDBIdentifier extends DBIdentifier implements Identifier, Cloneable, Serializable {
+
+ private DBIdentifier _schemaName = DBIdentifier.NULL; // The schema name
+ // The table name if the object (column, constraint) is qualified by a table name
+ private DBIdentifier _objectTableName = DBIdentifier.NULL;
+
+
+ protected QualifiedDBIdentifier(DBIdentifier... sNames) {
+ setPath(sNames);
+ }
+
+ /**
+ * Creates a qualified identifier based upon an array of DBIdentifiers. Identifiers
+ * must be specified in order.
+ * @param names
+ * @return
+ */
+ public static QualifiedDBIdentifier newPath(DBIdentifier...names) {
+ return new QualifiedDBIdentifier(names);
+ }
+
+ /**
+ * Set the identifiers that make up the path. Identifiers must be specified
+ * in path order. (ex. [ table, column ] )
+ * @param sNames
+ */
+ public void setPath(DBIdentifier...sNames) {
+ resetNames();
+ if (sNames == null || sNames.length == 0) {
+ return;
+ }
+
+ if (sNames.length == 1) {
+ DBIdentifier sName = sNames[0];
+ if (sName.getType() == DBIdentifierType.SCHEMA) {
+ setSchemaName(sName.clone());
+ }
+ setName(sName.clone());
+ setType(sName.getType());
+ return;
+ }
+
+ for (int i = (sNames.length - 1); i >= 0; i--) {
+ DBIdentifier sName = sNames[i];
+ if (DBIdentifier.isNull(sName)) {
+ continue;
+ }
+ if (i == (sNames.length - 1) && sNames.length != 1) {
+ setName(sName.clone());
+ } else {
+ if (sName.getType() == DBIdentifierType.SCHEMA) {
+ setSchemaName(sName.clone());
+ }
+ else if (sName.getType() == DBIdentifierType.TABLE) {
+ setObjectTableName(sName.clone());
+ }
+ }
+ }
+ }
+
+ // Reset the path names
+ private void resetNames() {
+ _schemaName = DBIdentifier.NULL;
+ _objectTableName = DBIdentifier.NULL;
+ }
+
+ /**
+ * Splits a qualified path into separate identifiers.
+ * @param sName
+ * @return
+ */
+ public static DBIdentifier[] splitPath(DBIdentifier sName) {
+ if (sName instanceof QualifiedDBIdentifier && sName.getType() != DBIdentifierType.SCHEMA) {
+ QualifiedDBIdentifier path = (QualifiedDBIdentifier)sName;
+ List<DBIdentifier> names = new ArrayList<DBIdentifier>();
+
+ if (!DBIdentifier.isNull(path.getSchemaName())) {
+ names.add(path.getSchemaName().clone());
+ }
+ if (!DBIdentifier.isNull(path.getObjectTableName())) {
+ names.add(path.getObjectTableName().clone());
+ }
+ if (!DBIdentifier.isNull(path.getIdentifier())) {
+ names.add(((DBIdentifier)path).clone());
+ }
+ return names.toArray(new DBIdentifier[names.size()]);
+ }
+ if (sName instanceof DBIdentifier) {
+ return new DBIdentifier[] { sName.clone() };
+ }
+ return new DBIdentifier[] {};
+ }
+
+ /**
+ * Creates a qualified path from an identifier.
+ * @param sName
+ * @return
+ */
+ public static QualifiedDBIdentifier getPath(DBIdentifier sName) {
+ if (sName instanceof QualifiedDBIdentifier) {
+ return (QualifiedDBIdentifier)sName.clone();
+ }
+ return QualifiedDBIdentifier.newPath(sName);
+ }
+
+ /**
+ *Sets the schema component of the path.
+ */
+ public void setSchemaName(DBIdentifier schemaName) {
+ _schemaName = schemaName;
+ }
+
+ /**
+ * Gets the schema component of the path.
+ * @return
+ */
+ public DBIdentifier getSchemaName() {
+ return _schemaName;
+ }
+
+ /**
+ * Sets the object table name component of the path, if the path
+ * is a table qualified identifier such as a constraint or column.
+ */
+ public void setObjectTableName(DBIdentifier objectName) {
+ _objectTableName = objectName;
+ }
+
+
+ /**
+ * Gets the object table name component of the path, if the path
+ * is a table qualified identifier such as a constraint or column.
+ */
+ public DBIdentifier getObjectTableName() {
+ return _objectTableName;
+ }
+
+ /**
+ * Returns true if this object is not qualified by a schema component.
+ * @return
+ */
+ public boolean isUnqualifiedObject() {
+ return DBIdentifier.isNull(getSchemaName());
+ }
+
+ /**
+ * Returns true if this object is not qualified by a table or schema
+ * component.
+ * @return
+ */
+ public boolean isUnqualifiedColumn() {
+ return DBIdentifier.isNull(getObjectTableName()) && DBIdentifier.isNull(getSchemaName());
+ }
+
+ /**
+ * Equality operator.
+ */
+ public boolean equals(Object obj) {
+ if (obj == null) {
+ return false;
+ }
+ if (obj instanceof QualifiedDBIdentifier) {
+ QualifiedDBIdentifier sPath = (QualifiedDBIdentifier)obj;
+ return DBIdentifier.equal(sPath.getSchemaName(), getSchemaName()) &&
+ DBIdentifier.equal(sPath.getObjectTableName(), getObjectTableName()) &&
+ DBIdentifier.equal(sPath, this);
+
+ }
+ else if (obj instanceof DBIdentifier) {
+ DBIdentifier sName = (DBIdentifier)obj;
+ return DBIdentifier.equal(sName, this);
+ } else if (obj instanceof String) {
+ return obj.equals(this.getName());
+ }
+ throw new IllegalArgumentException("Cannot compare to type: " + obj.getClass().getName());
+ }
+
+ /**
+ * Compares two qualified identifiers for equality.
+ * @param path1
+ * @param path2
+ * @return
+ */
+ public static boolean pathEqual(QualifiedDBIdentifier path1, QualifiedDBIdentifier path2) {
+ if (path1 == null && path2 == null) {
+ return true;
+ }
+ if (path1 == null) {
+ return false;
+ }
+ DBIdentifier[] names1 = QualifiedDBIdentifier.splitPath(path1);
+ DBIdentifier[] names2 = QualifiedDBIdentifier.splitPath(path2);
+ if (names1.length != names2.length) {
+ return false;
+ }
+ for (int i = 0; i < names1.length; i++) {
+ if (!DBIdentifier.equal(names1[i], names2[i])) {
+ return false;
+ }
+ }
+ return true;
+ }
+
+ /**
+ * Returns a fully qualified name as a string.
+ */
+ public String toString() {
+ return getName();
+ }
+
+ /**
+ * Returns the fully qualified name as a string
+ */
+ public String getName() {
+ // If no schema or object or table qualifier, return the base name
+ if (DBIdentifier.isEmpty(_schemaName) && DBIdentifier.isEmpty(_objectTableName)) {
+ return getBaseName();
+ }
+ DBIdentifier[] names = QualifiedDBIdentifier.splitPath(this);
+ return DBIdentifier.join(names);
+ }
+
+ /**
+ * Returns the base name of this qualified name. For example, if the
+ * qualified name is a schema qualified table, the table name is returned.
+ * @return
+ */
+ public String getBaseName() {
+ return super.getName();
+ }
+
+ /**
+ * Returns this object as a DBIdentifier.
+ * @return
+ */
+ public DBIdentifier getIdentifier() {
+ return this;
+ }
+
+ /**
+ * Set the name of this qualified identifier. Splits the string into
+ * multiple components. This method assumes the type does not change.
+ */
+ public void setName(String name) {
+ // Split apart name into components
+ DBIdentifier[] sNames = DBIdentifier.split(getType(), name);
+ setPath(sNames);
+ }
+
+ /**
+ * Set the base name component of this compound identifier
+ * @param name
+ */
+ protected void setBaseName(String name) {
+ super.setName(name);
+ }
+
+ /**
+ * Returns the length of the qualified identifier, including delimiters
+ * and name separators.
+ */
+ public int length() {
+ String name = getName();
+ if (name == null) {
+ return 0;
+ }
+ return name.length();
+ }
+
+ /**
+ * Compares this identifier with another identifier.
+ */
+ public int compareTo(Identifier o) {
+ if (o instanceof DBIdentifier) {
+ if (o == null || o == DBIdentifier.NULL)
+ return -1;
+ return super.compareTo(o);
+ }
+ return getName().compareTo(o.getName());
+ }
+
+ /**
+ * Returns true if all identifiers within this compound identifier are
+ * delimited. Otherwise, false.
+ */
+ @Override
+ public boolean isDelimited() {
+ if (DBIdentifier.isEmpty(this)) {
+ return false;
+ }
+ if (!DBIdentifier.isNull(getObjectTableName())) {
+ if (!Normalizer.isDelimited(getObjectTableName().getName())) {
+ return false;
+ }
+ }
+ if (!DBIdentifier.isNull(getSchemaName())) {
+ if (!Normalizer.isDelimited(getSchemaName().getName())) {
+ return false;
+ }
+ }
+ return super.isDelimited();
+ }
+
+ /**
+ * Returns a new unqualified name based on this instance.
+ */
+ @Override
+ public DBIdentifier getUnqualifiedName() {
+ QualifiedDBIdentifier newName = (QualifiedDBIdentifier)clone();
+ newName.setObjectTableName(DBIdentifier.NULL);
+ newName.setSchemaName(DBIdentifier.NULL);
+ return newName;
+ }
+
+ /**
+ * Creates a clone of this identifier.
+ */
+ public QualifiedDBIdentifier clone() {
+ QualifiedDBIdentifier sPath = new QualifiedDBIdentifier();
+ sPath.setObjectTableName(getObjectTableName().clone());
+ sPath.setSchemaName(getSchemaName().clone());
+ sPath.setBaseName(super.getName());
+ sPath.setType(getType());
+ return sPath;
+ }
+
+}
Propchange: openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/identifier/QualifiedDBIdentifier.java
------------------------------------------------------------------------------
svn:eol-style = native
Modified: openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/ClassTableJDBCSeq.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/ClassTableJDBCSeq.java?rev=899784&r1=899783&r2=899784&view=diff
==============================================================================
--- openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/ClassTableJDBCSeq.java (original)
+++ openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/ClassTableJDBCSeq.java Fri Jan 15 19:38:18 2010
@@ -50,7 +50,7 @@
private static final Localizer _loc = Localizer.forPackage
(ClassTableJDBCSeq.class);
- private final Map _stats = new HashMap();
+ private final Map<String, Status> _stats = new HashMap<String, Status>();
private boolean _ignore = false;
private boolean _aliases = false;
@@ -113,7 +113,7 @@
protected Column addPrimaryKeyColumn(Table table) {
DBDictionary dict = getConfiguration().getDBDictionaryInstance();
Column pkColumn = table.addColumn(dict.getValidColumnName(
- getPrimaryKeyColumn(), table));
+ getPrimaryKeyColumnIdentifier(), table));
pkColumn.setType(dict.getPreferredType(Types.VARCHAR));
pkColumn.setJavaType(JavaTypes.STRING);
pkColumn.setSize(dict.characterColumnSize);
@@ -223,7 +223,7 @@
ClassArgParser cap = conf.getMetaDataRepositoryInstance()
.getMetaDataFactory().newClassArgParser();
cap.setClassLoader(loader);
- Class cls = cap.parseTypes(args[0])[0];
+ Class<?> cls = cap.parseTypes(args[0])[0];
if (repos == null)
repos = conf.getMappingRepositoryInstance();
Modified: openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/MixedLockManager.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/MixedLockManager.java?rev=899784&r1=899783&r2=899784&view=diff
==============================================================================
--- openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/MixedLockManager.java (original)
+++ openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/MixedLockManager.java Fri Jan 15 19:38:18 2010
@@ -23,6 +23,7 @@
import java.util.List;
import java.util.Map;
+import org.apache.openjpa.jdbc.identifier.DBIdentifier;
import org.apache.openjpa.jdbc.meta.ClassMapping;
import org.apache.openjpa.jdbc.meta.FieldMapping;
import org.apache.openjpa.jdbc.sql.DBDictionary;
@@ -87,15 +88,15 @@
//
if(!dict.supportsLockingWithMultipleTables) {
// look for columns mapped to secondary tables which need to be locked
- Map<String,FieldMapping> colsMappedToSecTable = new HashMap<String,FieldMapping>();
+ Map<DBIdentifier,FieldMapping> colsMappedToSecTable = new HashMap<DBIdentifier,FieldMapping>();
FieldMapping fms[] = mapping.getFieldMappings();
for( FieldMapping fm : fms) {
- String secTableName = fm.getMappingInfo().getTableName();
- if( secTableName != null ) {
+ DBIdentifier secTableName = fm.getMappingInfo().getTableIdentifier();
+ if(!DBIdentifier.isNull(secTableName)) {
colsMappedToSecTable.put(secTableName, fm);
}
}
- for( String secTableName : colsMappedToSecTable.keySet()) {
+ for( DBIdentifier secTableName : colsMappedToSecTable.keySet()) {
FieldMapping fm = colsMappedToSecTable.get(secTableName);
// select only the PK columns, since we just want to lock
Select select = factory.newSelect();
Modified: openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/NativeJDBCSeq.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/NativeJDBCSeq.java?rev=899784&r1=899783&r2=899784&view=diff
==============================================================================
--- openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/NativeJDBCSeq.java (original)
+++ openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/NativeJDBCSeq.java Fri Jan 15 19:38:18 2010
@@ -27,6 +27,8 @@
import org.apache.openjpa.conf.OpenJPAConfiguration;
import org.apache.openjpa.jdbc.conf.JDBCConfiguration;
import org.apache.openjpa.jdbc.conf.JDBCConfigurationImpl;
+import org.apache.openjpa.jdbc.identifier.DBIdentifier;
+import org.apache.openjpa.jdbc.identifier.QualifiedDBIdentifier;
import org.apache.openjpa.jdbc.meta.ClassMapping;
import org.apache.openjpa.jdbc.schema.Schema;
import org.apache.openjpa.jdbc.schema.SchemaGroup;
@@ -69,7 +71,7 @@
private static Localizer _loc = Localizer.forPackage(NativeJDBCSeq.class);
private JDBCConfiguration _conf = null;
- private String _seqName = "OPENJPA_SEQUENCE";
+ private DBIdentifier _seqName = DBIdentifier.newSequence("OPENJPA_SEQUENCE");
private int _increment = 1;
private int _initial = 1;
private int _allocate = 0;
@@ -78,23 +80,24 @@
// for deprecated auto-configuration support
private String _format = null;
- private String _tableName = "DUAL";
+ private DBIdentifier _tableName = DBIdentifier.newTable("DUAL");
private boolean _subTable = false;
- private String _schema = null;
+ private DBIdentifier _schema = DBIdentifier.NULL;
/**
* The sequence name. Defaults to <code>OPENJPA_SEQUENCE</code>.
*/
+ // @GETTER
public String getSequence() {
- return _seqName;
+ return _seqName.getName();
}
/**
* The sequence name. Defaults to <code>OPENJPA_SEQUENCE</code>.
*/
public void setSequence(String seqName) {
- _seqName = seqName;
+ _seqName = DBIdentifier.newSequence(seqName);
}
/**
@@ -153,7 +156,7 @@
*/
@Deprecated
public void setTableName(String table) {
- _tableName = table;
+ _tableName = DBIdentifier.newTable(table);
}
/**
@@ -168,14 +171,15 @@
@Override
public void addSchema(ClassMapping mapping, SchemaGroup group) {
// sequence already exists?
- if (group.isKnownSequence(_seqName))
+ QualifiedDBIdentifier path = QualifiedDBIdentifier.getPath(_seqName);
+ if (group.isKnownSequence(path))
return;
- String schemaName = getSchema();
- if (schemaName == null || schemaName.length() == 0) {
- schemaName = Strings.getPackageName(_seqName);
- if (schemaName.length() == 0)
- schemaName = Schemas.getNewTableSchema(_conf);
+ DBIdentifier schemaName = getSchemaIdentifier();
+ if (DBIdentifier.isEmpty(schemaName)) {
+ schemaName = path.getSchemaName();
+ if (DBIdentifier.isEmpty(schemaName))
+ schemaName = Schemas.getNewTableSchemaIdentifier(_conf);
}
// create table in this group
@@ -183,8 +187,6 @@
if (schema == null)
schema = group.addSchema(schemaName);
schema.importSequence(_seq);
- // TODO: temp until a more global name solution is implemented
- schema.addDelimSequenceName(_conf.getDBDictionaryInstance().addDelimiters(_seqName), _seq);
}
@Override
@@ -208,8 +210,8 @@
if (_format == null)
throw new MetaDataException(_loc.get("no-seq-sql", _seqName));
}
- if (_tableName == null)
- _tableName = "DUAL";
+ if (DBIdentifier.isNull(_tableName))
+ _tableName = DBIdentifier.newTable("DUAL");
String name = dict.getFullName(_seq);
Object[] subs = (_subTable) ? new Object[]{ name, _tableName }
@@ -234,17 +236,18 @@
* Creates the sequence object.
*/
private void buildSequence() {
- String seqName = Strings.getClassName(_seqName);
+ QualifiedDBIdentifier path = QualifiedDBIdentifier.getPath(_seqName);
+ DBIdentifier seqName = path.getIdentifier();
// JPA 2 added schema as a configurable attribute on
// sequence generator. OpenJPA <= 1.x allowed this via
// schema.sequence on the sequence name. Specifying a schema
// name on the annotation or in the orm will override the old
// behavior.
- String schemaName = _schema;
- if (schemaName == null || schemaName.length() == 0) {
- schemaName = Strings.getPackageName(_seqName);
- if (schemaName.length() == 0)
- schemaName = Schemas.getNewTableSchema(_conf);
+ DBIdentifier schemaName = _schema;
+ if (DBIdentifier.isEmpty(schemaName)) {
+ schemaName = path.getSchemaName();
+ if (DBIdentifier.isEmpty(schemaName))
+ schemaName = Schemas.getNewTableSchemaIdentifier(_conf);
}
// build the sequence in one of the designated schemas
@@ -252,8 +255,6 @@
Schema schema = group.addSchema(schemaName);
_seq = schema.addSequence(seqName);
- // TODO: temp until a global name solution is implemented
- schema.addDelimSequenceName(_conf.getDBDictionaryInstance().addDelimiters(seqName), _seq);
_seq.setInitialValue(_initial);
_seq.setIncrement(_increment);
_seq.setAllocate(_allocate);
@@ -402,11 +403,22 @@
return true;
}
- public void setSchema(String _schema) {
- this._schema = _schema;
+ /**
+ * @deprecated
+ */
+ public void setSchema(String schema) {
+ _schema = DBIdentifier.newSchema(schema);
}
+ /**
+ * @deprecated
+ */
public String getSchema() {
+ return _schema.getName();
+ }
+
+ public DBIdentifier getSchemaIdentifier() {
return _schema;
}
+
}
Modified: openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/PreparedStatementManagerImpl.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/PreparedStatementManagerImpl.java?rev=899784&r1=899783&r2=899784&view=diff
==============================================================================
--- openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/PreparedStatementManagerImpl.java (original)
+++ openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/PreparedStatementManagerImpl.java Fri Jan 15 19:38:18 2010
@@ -29,6 +29,8 @@
import java.util.List;
import org.apache.openjpa.jdbc.conf.JDBCConfiguration;
+import org.apache.openjpa.jdbc.identifier.DBIdentifier;
+import org.apache.openjpa.jdbc.identifier.DBIdentifier.DBIdentifierType;
import org.apache.openjpa.jdbc.meta.ClassMapping;
import org.apache.openjpa.jdbc.meta.FieldMapping;
import org.apache.openjpa.jdbc.schema.Column;
@@ -167,10 +169,10 @@
* from the result set associated with the stmnt. If not, a separate
* sql to select the key will be issued from DBDictionary.
*/
- protected List populateAutoAssignCols(PreparedStatement stmnt,
- Column[] autoAssign, String[] autoAssignColNames, RowImpl row)
+ protected List<Object> populateAutoAssignCols(PreparedStatement stmnt,
+ Column[] autoAssign, DBIdentifier[] autoAssignColNames, RowImpl row)
throws SQLException {
- List vals = null;
+ List<Object> vals = null;
if (_dict.supportsGetGeneratedKeys) {
// set auto assign values to id col
vals = getGeneratedKeys(stmnt, autoAssignColNames);
@@ -179,9 +181,22 @@
return vals;
}
+ protected List<Object> populateAutoAssignCols(PreparedStatement stmnt,
+ Column[] autoAssign, String[] autoAssignColNames, RowImpl row)
+ throws SQLException {
+ return populateAutoAssignCols(stmnt, autoAssign,
+ DBIdentifier.toArray(autoAssignColNames, DBIdentifierType.COLUMN), row);
+ }
+
protected void setObjectId(List vals, Column[] autoAssign,
String[] autoAssignColNames, RowImpl row)
throws SQLException{
+ setObjectId(vals, autoAssign, DBIdentifier.toArray(autoAssignColNames, DBIdentifierType.COLUMN), row);
+ }
+
+ protected void setObjectId(List vals, Column[] autoAssign,
+ DBIdentifier[] autoAssignColNames, RowImpl row)
+ throws SQLException{
OpenJPAStateManager sm = row.getPrimaryKey();
ClassMapping mapping = (ClassMapping) sm.getMetaData();
Object val = null;
@@ -202,9 +217,15 @@
* This method will only be called when the database supports
* getGeneratedKeys.
*/
- protected List getGeneratedKeys(PreparedStatement stmnt,
+ protected List<Object> getGeneratedKeys(PreparedStatement stmnt,
String[] autoAssignColNames)
throws SQLException {
+ return getGeneratedKeys(stmnt, DBIdentifier.toArray(autoAssignColNames, DBIdentifierType.COLUMN));
+ }
+
+ protected List<Object> getGeneratedKeys(PreparedStatement stmnt,
+ DBIdentifier[] autoAssignColNames)
+ throws SQLException {
ResultSet rs = stmnt.getGeneratedKeys();
List<Object> vals = new ArrayList<Object>();
while (rs.next()) {
@@ -222,14 +243,22 @@
return autoAssign;
}
+ /**
+ * @deprecated
+ */
protected String[] getAutoAssignColNames(Column[] autoAssign, RowImpl row) {
- String[] autoAssignColNames = null;
+ DBIdentifier[] names = getAutoAssignColIdentifiers(autoAssign, row);
+ return DBIdentifier.toStringArray(names);
+ }
+
+ protected DBIdentifier[] getAutoAssignColIdentifiers(Column[] autoAssign, RowImpl row) {
+ DBIdentifier[] autoAssignColNames = null;
if (autoAssign != null && autoAssign.length > 0
&& row.getPrimaryKey() != null) {
- autoAssignColNames = new String[autoAssign.length];
+ autoAssignColNames = new DBIdentifier[autoAssign.length];
for (int i = 0; i < autoAssign.length; i++)
- autoAssignColNames[i] =
- _dict.convertSchemaCase(autoAssign[i].getName());
+ autoAssignColNames[i] = autoAssign[i].getIdentifier();
+// _dict.convertSchemaCase(.getName());
}
return autoAssignColNames;
}
Modified: openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/TableJDBCSeq.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/TableJDBCSeq.java?rev=899784&r1=899783&r2=899784&view=diff
==============================================================================
--- openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/TableJDBCSeq.java (original)
+++ openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/TableJDBCSeq.java Fri Jan 15 19:38:18 2010
@@ -31,6 +31,10 @@
import org.apache.commons.lang.StringUtils;
import org.apache.openjpa.jdbc.conf.JDBCConfiguration;
import org.apache.openjpa.jdbc.conf.JDBCConfigurationImpl;
+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.identifier.DBIdentifier.DBIdentifierType;
import org.apache.openjpa.jdbc.meta.ClassMapping;
import org.apache.openjpa.jdbc.schema.Column;
import org.apache.openjpa.jdbc.schema.PrimaryKey;
@@ -46,6 +50,7 @@
import org.apache.openjpa.lib.conf.Configurable;
import org.apache.openjpa.lib.conf.Configuration;
import org.apache.openjpa.lib.conf.Configurations;
+import org.apache.openjpa.lib.identifier.IdentifierUtil;
import org.apache.openjpa.lib.log.Log;
import org.apache.openjpa.lib.util.Localizer;
import org.apache.openjpa.lib.util.Options;
@@ -54,7 +59,6 @@
import org.apache.openjpa.util.UserException;
import serp.util.Numbers;
-import serp.util.Strings;
////////////////////////////////////////////////////////////
// NOTE: Do not change property names; see SequenceMetaData
@@ -88,11 +92,11 @@
private final HashMap<ClassMapping, Status> _stat =
new HashMap<ClassMapping, Status>();
- private String _table = DEFAULT_TABLE;
- private String _seqColumnName = "SEQUENCE_VALUE";
- private String _pkColumnName = "ID";
- private String[] _uniqueColumnNames;
- private String _uniqueConstraintName;
+ private DBIdentifier _table = DBIdentifier.newTable(DEFAULT_TABLE);
+ private DBIdentifier _seqColumnName = DBIdentifier.newColumn("SEQUENCE_VALUE");
+ private DBIdentifier _pkColumnName = DBIdentifier.newColumn("ID");
+ private DBIdentifier[] _uniqueColumnNames;
+ private DBIdentifier _uniqueConstraintName = DBIdentifier.NULL;
private Column _seqColumn = null;
private Column _pkColumn = null;
@@ -106,7 +110,7 @@
* will be used.
*/
public String getTable() {
- return _table;
+ return _table.getName();
}
/**
@@ -118,7 +122,10 @@
* will be used.
*/
public void setTable(String name) {
- _table = name;
+ // Split the name into its individual parts
+ String[] names = Normalizer.splitName(name);
+ // Join the name back together. This will delimit as appropriate.
+ _table = DBIdentifier.newTable(Normalizer.joinNames(names));
}
/**
@@ -134,7 +141,7 @@
* to <code>SEQUENCE_VALUE</code>.
*/
public String getSequenceColumn() {
- return _seqColumnName;
+ return _seqColumnName.getName();
}
/**
@@ -142,7 +149,7 @@
* to <code>SEQUENCE_VALUE</code>.
*/
public void setSequenceColumn(String sequenceColumn) {
- _seqColumnName = sequenceColumn;
+ _seqColumnName = DBIdentifier.newColumn(sequenceColumn);
}
/**
@@ -150,6 +157,10 @@
* <code>ID</code>.
*/
public String getPrimaryKeyColumn() {
+ return _pkColumnName.getName();
+ }
+
+ public DBIdentifier getPrimaryKeyColumnIdentifier() {
return _pkColumnName;
}
@@ -158,7 +169,7 @@
* <code>ID</code>.
*/
public void setPrimaryKeyColumn(String primaryKeyColumn) {
- _pkColumnName = primaryKeyColumn;
+ _pkColumnName = DBIdentifier.newColumn(primaryKeyColumn);
}
/**
@@ -186,7 +197,7 @@
* GeneratedValue.TABLE strategy to start with.
* @return an initial number
*/
- public int getInitialValue() {
+ public int getInitialValue() {
return _intValue;
}
@@ -206,11 +217,11 @@
*/
public void setUniqueColumns(String columnNames) {
_uniqueColumnNames = (StringUtils.isEmpty(columnNames))
- ? null : StringUtils.split(columnNames, '|');
+ ? null : DBIdentifier.split(columnNames, DBIdentifierType.COLUMN, IdentifierUtil.BAR);
}
public String getUniqueColumns() {
- return StringUtils.join(_uniqueColumnNames, '|');
+ return Normalizer.joinNames(DBIdentifier.toStringArray(_uniqueColumnNames), IdentifierUtil.BAR);
}
/**
@@ -245,16 +256,20 @@
Schema[] schemas = group.getSchemas();
for (int i = 0; i < schemas.length; i++) {
- String schemaName = Strings.getPackageName(_table);
- if (schemaName.length() == 0)
- schemaName = Schemas.getNewTableSchema(_conf);
- if (schemaName == null)
- schemaName = schemas[i].getName();
+ QualifiedDBIdentifier path = QualifiedDBIdentifier.getPath(_table);
+ DBIdentifier schemaName = path.getSchemaName();
+ if (DBIdentifier.isEmpty(schemaName)) {
+ schemaName = Schemas.getNewTableSchemaIdentifier(_conf);
+ }
+ if (DBIdentifier.isNull(schemaName)) {
+ schemaName = schemas[i].getIdentifier();
+ }
// create table in this group
Schema schema = group.getSchema(schemaName);
- if (schema == null)
+ if (schema == null) {
schema = group.addSchema(schemaName);
+ }
Table copy = schema.importTable(_pkColumn.getTable());
// importTable() does not import unique constraints
@@ -265,8 +280,7 @@
// we need to reset the table name in the column with the
// fully qualified name for matching the table name from the
// Column.
- _pkColumn.resetTableName(schemaName + "."
- + _pkColumn.getTableName());
+ _pkColumn.resetTableIdentifier(QualifiedDBIdentifier.newPath(schemaName, _pkColumn.getTableIdentifier()));
// some databases require to create an index for the sequence table
_conf.getDBDictionaryInstance().createIndexIfNecessary(schema,
_table, _pkColumn);
@@ -351,7 +365,7 @@
protected Column addPrimaryKeyColumn(Table table) {
DBDictionary dict = _conf.getDBDictionaryInstance();
Column pkColumn = table.addColumn(dict.getValidColumnName
- (getPrimaryKeyColumn(), table));
+ (getPrimaryKeyColumnIdentifier(), table));
pkColumn.setType(dict.getPreferredType(Types.TINYINT));
pkColumn.setJavaType(JavaTypes.INT);
return pkColumn;
@@ -368,20 +382,20 @@
* Creates the object-level representation of the sequence table.
*/
private void buildTable() {
- String tableName = null;
- String schemaName = "";
- if (StringUtils.contains(_table,'.')) {
- String[] tableParts = StringUtils.split(_table, '.');
- // TODO: do we need to check for length? Could we have xxx. or .xxx?
- schemaName = tableParts[0];
- tableName = tableParts[1];
+ DBIdentifier tableName = DBIdentifier.NULL;
+ DBIdentifier schemaName = DBIdentifier.NULL;
+ QualifiedDBIdentifier path = QualifiedDBIdentifier.getPath(_table);
+ if (!DBIdentifier.isEmpty(path.getSchemaName())) {
+ schemaName = path.getSchemaName();
+ tableName = path.getUnqualifiedName();
}
else {
tableName = _table;
}
- if (schemaName.length() == 0)
- schemaName = Schemas.getNewTableSchema(_conf);
+ if (DBIdentifier.isEmpty(schemaName)) {
+ schemaName = Schemas.getNewTableSchemaIdentifier(_conf);
+ }
SchemaGroup group = new SchemaGroup();
Schema schema = group.addSchema(schemaName);
@@ -398,17 +412,17 @@
_seqColumn.setJavaType(JavaTypes.LONG);
if (_uniqueColumnNames != null) {
- String uniqueName = _uniqueConstraintName;
- if (StringUtils.isEmpty(uniqueName)) {
- uniqueName = dict.getValidUniqueName("UNQ", table);
+ DBIdentifier uniqueName = _uniqueConstraintName;
+ if (DBIdentifier.isEmpty(uniqueName)) {
+ uniqueName = dict.getValidUniqueName(DBIdentifier.newConstraint("UNQ"), table);
}
Unique u = table.addUnique(uniqueName);
- for (String columnName : _uniqueColumnNames) {
+ for (DBIdentifier columnName : _uniqueColumnNames) {
if (!table.containsColumn(columnName, _conf.getDBDictionaryInstance()))
throw new UserException(_loc.get("unique-missing-column",
- columnName, table.getName(),
+ columnName, table.getIdentifier(),
table.getColumnNames()));
- Column col = table.getColumn(columnName, _conf.getDBDictionaryInstance());
+ Column col = table.getColumn(columnName);
u.addColumn(col);
}
}
@@ -469,7 +483,7 @@
getClass(), mapping));
DBDictionary dict = _conf.getDBDictionaryInstance();
- String tableName = resolveTableName(mapping, _pkColumn.getTable());
+ DBIdentifier tableName = resolveTableIdentifier(mapping, _pkColumn.getTable());
SQLBuffer insert = new SQLBuffer(dict).append("INSERT INTO ").
append(tableName).append(" (").
append(_pkColumn).append(", ").append(_seqColumn).
@@ -519,7 +533,7 @@
SQLBuffer sel = new SQLBuffer(dict).append(_seqColumn);
SQLBuffer where = new SQLBuffer(dict).append(_pkColumn).append(" = ").
appendValue(pk, _pkColumn);
- String tableName = resolveTableName(mapping, _seqColumn.getTable());
+ DBIdentifier tableName = resolveTableIdentifier(mapping, _seqColumn.getTable());
SQLBuffer tables = new SQLBuffer(dict).append(tableName);
SQLBuffer select = dict.toSelect(sel, null, tables, where, null, null,
@@ -577,7 +591,7 @@
// update the value
upd = new SQLBuffer(dict);
- String tableName = resolveTableName(mapping,
+ DBIdentifier tableName = resolveTableIdentifier(mapping,
_seqColumn.getTable());
upd.append("UPDATE ").append(tableName).
append(" SET ").append(_seqColumn).append(" = ").
@@ -612,19 +626,32 @@
*
* @param class
* mapping to get the schema name
+ * @deprecated
*/
public String resolveTableName(ClassMapping mapping, Table table) {
- String sName = mapping.getTable().getSchemaName();
- String tableName;
- if (sName == null)
- tableName = table.getFullName();
- else if (table.getSchemaName() != null)
- tableName = table.getFullName();
- else
- tableName = sName + "." + table.getName();
+ return resolveTableIdentifier(mapping, table).getName();
+ }
+
+ /**
+ * Resolve a fully qualified table name
+ *
+ * @param class
+ * mapping to get the schema name
+ */
+ public DBIdentifier resolveTableIdentifier(ClassMapping mapping, Table table) {
+ DBIdentifier sName = mapping.getTable().getSchemaIdentifier();
+ DBIdentifier tableName = DBIdentifier.NULL;
+ if (DBIdentifier.isNull(sName)) {
+ tableName = table.getFullIdentifier();
+ } else if (!DBIdentifier.isNull(table.getSchemaIdentifier())) {
+ tableName = table.getFullIdentifier();
+ } else {
+ tableName = QualifiedDBIdentifier.newPath(sName, table.getIdentifier());
+ }
return tableName;
}
+
/**
* Creates the sequence table in the DB.
*/
@@ -763,6 +790,7 @@
/**
* Helper struct to hold status information.
*/
+ @SuppressWarnings("serial")
protected static class Status
implements Serializable {
@@ -809,11 +837,19 @@
return dict.getLong(rs, 1);
}
- public void setUniqueConstraintName(String _uniqueConstraintName) {
- this._uniqueConstraintName = _uniqueConstraintName;
+ public void setUniqueConstraintName(String uniqueConstraintName) {
+ _uniqueConstraintName = DBIdentifier.newConstraint(uniqueConstraintName);
+ }
+
+ public void setUniqueConstraintName(DBIdentifier uniqueConstraintName) {
+ _uniqueConstraintName = uniqueConstraintName;
}
public String getUniqueConstraintName() {
+ return _uniqueConstraintName.getName();
+ }
+
+ public DBIdentifier getUniqueConstraintIdentifier() {
return _uniqueConstraintName;
}
Modified: openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/ValueTableJDBCSeq.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/ValueTableJDBCSeq.java?rev=899784&r1=899783&r2=899784&view=diff
==============================================================================
--- openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/ValueTableJDBCSeq.java (original)
+++ openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/ValueTableJDBCSeq.java Fri Jan 15 19:38:18 2010
@@ -78,7 +78,7 @@
protected Column addPrimaryKeyColumn(Table table) {
DBDictionary dict = getConfiguration().getDBDictionaryInstance();
Column pkColumn = table.addColumn(dict.getValidColumnName
- (getPrimaryKeyColumn(), table));
+ (getPrimaryKeyColumnIdentifier(), table));
pkColumn.setType(dict.getPreferredType(Types.VARCHAR));
pkColumn.setJavaType(JavaTypes.STRING);
pkColumn.setSize(dict.characterColumnSize);
Modified: openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/exps/PCPath.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/exps/PCPath.java?rev=899784&r1=899783&r2=899784&view=diff
==============================================================================
--- openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/exps/PCPath.java (original)
+++ openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/exps/PCPath.java Fri Jan 15 19:38:18 2010
@@ -979,7 +979,7 @@
// if select is null, it means we are not aliasing columns
// (e.g., during a bulk update)
if (sel == null)
- sql.append(col.getName());
+ sql.append(col.getIdentifier());
else if (_type == XPATH)
// if this is an xpath, append xpath string
sql.append(getXPath());
Modified: openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/meta/ClassMapping.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/meta/ClassMapping.java?rev=899784&r1=899783&r2=899784&view=diff
==============================================================================
--- openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/meta/ClassMapping.java (original)
+++ openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/meta/ClassMapping.java Fri Jan 15 19:38:18 2010
@@ -281,7 +281,7 @@
Joinable join = getJoinable(col);
if (join == null)
throw new MetaDataException(_loc.get("no-joinable",
- col.getFullName()));
+ col.getQualifiedPath().toString()));
return join;
}
Modified: openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/meta/ClassMappingInfo.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/meta/ClassMappingInfo.java?rev=899784&r1=899783&r2=899784&view=diff
==============================================================================
--- openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/meta/ClassMappingInfo.java (original)
+++ openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/meta/ClassMappingInfo.java Fri Jan 15 19:38:18 2010
@@ -29,7 +29,8 @@
import java.util.Map;
import java.util.Map.Entry;
-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.strats.FullClassStrategy;
import org.apache.openjpa.jdbc.schema.Column;
import org.apache.openjpa.jdbc.schema.ForeignKey;
@@ -51,6 +52,7 @@
*
* @author Abe White
*/
+@SuppressWarnings("serial")
public class ClassMappingInfo
extends MappingInfo
implements SourceTracker, Commentable {
@@ -59,10 +61,10 @@
(ClassMappingInfo.class);
private String _className = Object.class.getName();
- private String _tableName = null;
- private String _schemaName = null;
+ private DBIdentifier _tableName = DBIdentifier.NULL;
+ private DBIdentifier _schemaName = DBIdentifier.NULL;
private boolean _joined = false;
- private Map _seconds = null;
+ private Map<DBIdentifier, List<Column>> _seconds = null;
private String _subStrat = null;
private File _file = null;
private int _srcType = SRC_OTHER;
@@ -71,7 +73,7 @@
private int _colNum = 0;
// Unique constraints indexed by primary or secondary table name
- private Map<String,List<Unique>> _uniques;
+ private Map<DBIdentifier,List<Unique>> _uniques;
/**
* The described class name.
@@ -103,29 +105,49 @@
/**
* The given table name.
+ * @deprecated
*/
public String getTableName() {
- return _tableName;
+ return getTableIdentifier().getName();
+ }
+
+ public DBIdentifier getTableIdentifier() {
+ return _tableName == null ? DBIdentifier.NULL : _tableName;
}
/**
* The given table name.
+ * @deprecated
*/
public void setTableName(String table) {
+ setTableIdentifier(DBIdentifier.newTable(table));
+ }
+
+ public void setTableIdentifier(DBIdentifier table) {
_tableName = table;
}
/**
* The default schema name for unqualified tables.
+ * @deprecated
*/
public String getSchemaName() {
- return _schemaName;
+ return getSchemaIdentifier().getName();
+ }
+
+ public DBIdentifier getSchemaIdentifier() {
+ return _schemaName == null ? DBIdentifier.NULL : _schemaName;
}
/**
* The default schema name for unqualified tables.
+ * @deprecated
*/
public void setSchemaName(String schema) {
+ setSchemaIdentifier(DBIdentifier.newSchema(schema));
+ }
+
+ public void setSchemaIdentifier(DBIdentifier schema) {
_schemaName = schema;
}
@@ -145,11 +167,18 @@
/**
* Return the class-level joined tables.
+ * @deprecated
*/
public String[] getSecondaryTableNames() {
if (_seconds == null)
return new String[0];
- return (String[]) _seconds.keySet().toArray(new String[]{ });
+ return DBIdentifier.toStringArray(_seconds.keySet().toArray(new DBIdentifier[]{ }));
+ }
+
+ public DBIdentifier[] getSecondaryTableIdentifiers() {
+ if (_seconds == null)
+ return new DBIdentifier[0];
+ return (DBIdentifier[]) _seconds.keySet().toArray(new DBIdentifier[]{ });
}
/**
@@ -157,33 +186,38 @@
* name, whereas the class join might have schema, etc information.
* This method returns the name of the given table as listed in a
* class-level join, or the given name if no join exists.
+ * @deprecated
*/
public String getSecondaryTableName(String tableName) {
+ return getSecondaryTableIdentifier(DBIdentifier.newTable(tableName)).getName();
+ }
+
+ public DBIdentifier getSecondaryTableIdentifier(DBIdentifier tableName) {
// if no secondary table joins, bad table name, exact match,
// or an already-qualified table name, nothing to do
- if (_seconds == null || tableName == null
+ QualifiedDBIdentifier path = QualifiedDBIdentifier.getPath(tableName);
+ if (_seconds == null || DBIdentifier.isNull(tableName)
|| _seconds.containsKey(tableName)
- || tableName.indexOf('.') != -1)
+ || !DBIdentifier.isNull(path.getSchemaName()))
return tableName;
// decide which class-level join table is best match
- String best = tableName;
+ DBIdentifier best = tableName;
int pts = 0;
- String fullJoin;
- String join;
- int idx;
- for (Iterator itr = _seconds.keySet().iterator(); itr.hasNext();) {
+ DBIdentifier fullJoin = DBIdentifier.NULL;
+ DBIdentifier join = DBIdentifier.NULL;
+ for (Iterator<DBIdentifier> itr = _seconds.keySet().iterator(); itr.hasNext();) {
// award a caseless match without schema 2 points
- fullJoin = (String) itr.next();
- idx = fullJoin.lastIndexOf('.');
- if (idx == -1 && pts < 2 && fullJoin.equalsIgnoreCase(tableName)) {
+ fullJoin = (DBIdentifier) itr.next();
+ QualifiedDBIdentifier joinPath = QualifiedDBIdentifier.getPath(fullJoin);
+ if (joinPath.isUnqualifiedObject() && pts < 2 && fullJoin.equalsIgnoreCase(tableName)) {
best = fullJoin;
pts = 2;
- } else if (idx == -1)
+ } else if (joinPath.isUnqualifiedObject())
continue;
// immediately return an exact match with schema
- join = fullJoin.substring(idx + 1);
+ join = joinPath.getIdentifier();
if (join.equals(tableName))
return fullJoin;
@@ -199,48 +233,78 @@
/**
* Return any columns defined for the given class level join, or empty
* list if none.
+ * @deprecated
*/
- public List getSecondaryTableJoinColumns(String tableName) {
- if (_seconds == null || tableName == null)
- return Collections.EMPTY_LIST;
+ public List<Column> getSecondaryTableJoinColumns(String tableName) {
+ return getSecondaryTableJoinColumns(DBIdentifier.newTable(tableName));
+ }
+
+ public List<Column> getSecondaryTableJoinColumns(DBIdentifier tableName) {
+ if (_seconds == null || DBIdentifier.isNull(tableName)) {
+ return Collections.emptyList();
+ }
// get the columns for the join with the best match for table name
- List cols = (List) _seconds.get(getSecondaryTableName(tableName));
+ List<Column> cols = _seconds.get(getSecondaryTableIdentifier(tableName));
if (cols == null) {
// possible that given table has extra info the join table
// doesn't have; strip it
- int idx = tableName.lastIndexOf('.');
- if (idx != -1) {
- tableName = tableName.substring(idx + 1);
- cols = (List) _seconds.get(getSecondaryTableName(tableName));
+ QualifiedDBIdentifier path = QualifiedDBIdentifier.getPath(tableName);
+ if (!DBIdentifier.isNull(path.getSchemaName())) {
+ tableName = path.getIdentifier();
+ cols = _seconds.get(getSecondaryTableIdentifier(tableName));
}
}
- return (cols == null) ? Collections.EMPTY_LIST : cols;
+ if (cols == null) {
+ return Collections.emptyList();
+ }
+ return cols;
}
/**
* Adds a Secondary table of given name to this mapping. A secondary table
* must be known before unique constraints are added to a Secondary table.
+ * @deprecated
*/
public void addSecondaryTable(String second) {
- setSecondaryTableJoinColumns(second, null);
+ setSecondaryTableJoinColumns(DBIdentifier.newTable(second), null);
+ }
+
+ public void addSecondaryTable(DBIdentifier second) {
+ setSecondaryTableJoinColumns(second, null);
}
/**
* Declare the given class-level join to the named (secondary) table.
+ * @deprecated
*/
- public void setSecondaryTableJoinColumns(String tableName, List cols) {
+ public void setSecondaryTableJoinColumns(String tableName, List<Column> cols) {
+ if (cols == null)
+ cols = Collections.emptyList();
+ setSecondaryTableJoinColumns(DBIdentifier.newTable(tableName), cols);
+ }
+
+ public void setSecondaryTableJoinColumns(DBIdentifier tableName, List<Column> cols) {
if (cols == null)
- cols = Collections.EMPTY_LIST;
+ cols = Collections.emptyList();
if (_seconds == null)
- _seconds = new LinkedHashMap();
+ _seconds = new LinkedHashMap<DBIdentifier, List<Column>>();
_seconds.put(tableName, cols);
}
/**
* Return the named table for the given class.
+ * @deprecated
*/
public Table getTable(final ClassMapping cls, String tableName,
+ boolean adapt) {
+ return getTable(cls, DBIdentifier.newTable(tableName), adapt);
+ }
+
+ /**
+ * Return the named table for the given class.
+ */
+ public Table getTable(final ClassMapping cls, DBIdentifier tableName,
boolean adapt) {
Table t = createTable(cls, new TableDefaults() {
public String get(Schema schema) {
@@ -249,6 +313,10 @@
return cls.getMappingRepository().getMappingDefaults().
getTableName(cls, schema);
}
+ public DBIdentifier getIdentifier(Schema schema) {
+ return cls.getMappingRepository().getMappingDefaults().
+ getTableIdentifier(cls, schema);
+ }
}, _schemaName, tableName, adapt);
t.setComment(cls.getTypeAlias() == null
? cls.getDescribedType().getName()
@@ -312,7 +380,7 @@
if (cls.getTable() != null && (sup == null
|| sup.getTable() != cls.getTable()))
_tableName = cls.getMappingRepository().getDBDictionary().
- getFullName(cls.getTable(), true);
+ getFullIdentifier(cls.getTable(), true);
// set io before syncing cols
setColumnIO(cls.getColumnIO());
@@ -334,12 +402,12 @@
}
public boolean hasSchemaComponents() {
- return super.hasSchemaComponents() || _tableName != null;
+ return super.hasSchemaComponents() || !DBIdentifier.isNull(_tableName);
}
protected void clear(boolean canFlags) {
super.clear(canFlags);
- _tableName = null;
+ _tableName = DBIdentifier.NULL;
}
public void copy(MappingInfo info) {
@@ -348,15 +416,15 @@
return;
ClassMappingInfo cinfo = (ClassMappingInfo) info;
- if (_tableName == null)
- _tableName = cinfo.getTableName();
+ if (DBIdentifier.isNull(_tableName))
+ _tableName = cinfo.getTableIdentifier();
if (_subStrat == null)
_subStrat = cinfo.getHierarchyStrategy();
if (cinfo._seconds != null) {
if (_seconds == null)
- _seconds = new HashMap();
- Object key;
- for (Iterator itr = cinfo._seconds.keySet().iterator();
+ _seconds = new HashMap<DBIdentifier, List<Column>>();
+ DBIdentifier key;
+ for (Iterator<DBIdentifier> itr = cinfo._seconds.keySet().iterator();
itr.hasNext();) {
key = itr.next();
if (!_seconds.containsKey(key))
@@ -365,8 +433,8 @@
}
if (cinfo._uniques != null) {
if (_uniques == null)
- _uniques = new HashMap<String, List<Unique>>();
- for (Entry<String, List<Unique>> entry : cinfo._uniques.entrySet())
+ _uniques = new HashMap<DBIdentifier, List<Unique>>();
+ for (Entry<DBIdentifier, List<Unique>> entry : cinfo._uniques.entrySet())
if (!_uniques.containsKey(entry.getKey()))
_uniques.put(entry.getKey(), entry.getValue());
}
@@ -378,9 +446,20 @@
* @param table must be primary table or secondary table name added a
* priori to this receiver.
* @param unique the unique constraint. null means no-op.
+ * @deprecated
*/
public void addUnique(String table, Unique unique) {
- if (!StringUtils.equals(_tableName, table) &&
+ addUnique(DBIdentifier.newTable(table), unique);
+ }
+
+ /**
+ * Add a unique constraint for the given table.
+ * @param table must be primary table or secondary table name added a
+ * priori to this receiver.
+ * @param unique the unique constraint. null means no-op.
+ */
+ public void addUnique(DBIdentifier table, Unique unique) {
+ if (!DBIdentifier.equal(_tableName, table) &&
(_seconds == null || !_seconds.containsKey(table))) {
throw new UserException(_loc.get("unique-no-table",
new Object[]{table, _className, _tableName,
@@ -389,8 +468,8 @@
if (unique == null)
return;
if (_uniques == null)
- _uniques = new HashMap<String,List<Unique>>();
- unique.setTableName(table);
+ _uniques = new HashMap<DBIdentifier,List<Unique>>();
+ unique.setTableIdentifier(table);
List<Unique> uniques = _uniques.get(table);
if (uniques == null) {
uniques = new ArrayList<Unique>();
@@ -403,8 +482,16 @@
/**
* Get the unique constraints of the given primary or secondary table.
+ * @deprecated
*/
public Unique[] getUniques(String table) {
+ return getUniques(DBIdentifier.newTable(table));
+ }
+
+ /**
+ * Get the unique constraints of the given primary or secondary table.
+ */
+ public Unique[] getUniques(DBIdentifier table) {
if (_uniques == null || _uniques.isEmpty()
|| _uniques.containsKey(table))
return new Unique[0];
@@ -421,14 +508,14 @@
if (_uniques == null || _uniques.isEmpty())
return new Unique[0];
List<Unique> result = new ArrayList<Unique>();
- for (String tableName : _uniques.keySet()) {
+ for (DBIdentifier tableName : _uniques.keySet()) {
List<Unique> uniqueConstraints = _uniques.get(tableName);
for (Unique template : uniqueConstraints) {
Column[] templateColumns = template.getColumns();
Column[] uniqueColumns = new Column[templateColumns.length];
Table table = getTable((ClassMapping)cm, tableName, adapt);
for (int i=0; i<uniqueColumns.length; i++) {
- String columnName = templateColumns[i].getName();
+ DBIdentifier columnName = templateColumns[i].getIdentifier();
if (!table.containsColumn(columnName)) {
throw new UserException(_loc.get(
"unique-missing-column",
@@ -491,5 +578,4 @@
public void setColNumber(int colNum) {
_colNum = colNum;
}
-
}
Modified: openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/meta/ClassStrategy.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/meta/ClassStrategy.java?rev=899784&r1=899783&r2=899784&view=diff
==============================================================================
--- openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/meta/ClassStrategy.java (original)
+++ openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/meta/ClassStrategy.java Fri Jan 15 19:38:18 2010
@@ -107,7 +107,7 @@
/**
* Implement this method to customize loading from a {@link Result}
* into an instance. Return true if this mapping handles the
- * load; false if normal loading should procede after calling this method.
+ * load; false if normal loading should proceed after calling this method.
*/
public boolean customLoad(OpenJPAStateManager sm, JDBCStore store,
JDBCFetchConfiguration fetch, Result result)
Modified: openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/meta/DelegatingJoinable.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/meta/DelegatingJoinable.java?rev=899784&r1=899783&r2=899784&view=diff
==============================================================================
--- openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/meta/DelegatingJoinable.java (original)
+++ openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/meta/DelegatingJoinable.java Fri Jan 15 19:38:18 2010
@@ -41,6 +41,7 @@
*
* @author Abe White
*/
+@SuppressWarnings("serial")
public class DelegatingJoinable
implements Joinable {
@@ -68,7 +69,7 @@
_cols[i] = fk.getColumn(pks[i]);
if (_cols[i] == null)
throw new MetaDataException(_loc.get("incomplete-join",
- pks[i].getFullName()));
+ pks[i].getFullDBIdentifier()));
}
}
@@ -84,7 +85,7 @@
_cols = cols;
if (cols.length != join.getColumns().length)
throw new MetaDataException(_loc.get("bad-remap",
- join.getColumns()[0].getFullName()));
+ join.getColumns()[0].getFullDBIdentifier()));
}
public int getFieldIndex() {
Modified: openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/meta/Discriminator.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/meta/Discriminator.java?rev=899784&r1=899783&r2=899784&view=diff
==============================================================================
--- openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/meta/Discriminator.java (original)
+++ openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/meta/Discriminator.java Fri Jan 15 19:38:18 2010
@@ -33,7 +33,6 @@
import org.apache.openjpa.kernel.OpenJPAStateManager;
import org.apache.openjpa.lib.log.Log;
import org.apache.openjpa.lib.util.Localizer;
-import org.apache.openjpa.meta.JavaTypes;
import org.apache.openjpa.meta.MetaDataContext;
import org.apache.openjpa.meta.MetaDataModes;
import org.apache.openjpa.meta.MetaDataRepository;
@@ -44,6 +43,7 @@
*
* @author Abe White
*/
+@SuppressWarnings("serial")
public class Discriminator
implements DiscriminatorStrategy, MetaDataContext, MetaDataModes {
@@ -393,7 +393,7 @@
assertStrategy().loadSubclasses(store);
}
- public Class getClass(JDBCStore store, ClassMapping base, Result result)
+ public Class<?> getClass(JDBCStore store, ClassMapping base, Result result)
throws SQLException, ClassNotFoundException {
return assertStrategy().getClass(store, base, result);
}
Modified: openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/meta/DiscriminatorMappingInfo.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/meta/DiscriminatorMappingInfo.java?rev=899784&r1=899783&r2=899784&view=diff
==============================================================================
--- openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/meta/DiscriminatorMappingInfo.java (original)
+++ openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/meta/DiscriminatorMappingInfo.java Fri Jan 15 19:38:18 2010
@@ -28,9 +28,7 @@
import org.apache.openjpa.jdbc.schema.Index;
import org.apache.openjpa.jdbc.schema.SchemaGroup;
import org.apache.openjpa.jdbc.schema.Table;
-import org.apache.openjpa.lib.util.Localizer;
import org.apache.openjpa.meta.JavaTypes;
-import org.apache.openjpa.util.MetaDataException;
/**
* Information about the mapping from a discriminator to the schema, in
@@ -40,12 +38,10 @@
*
* @author Abe White
*/
+@SuppressWarnings("serial")
public class DiscriminatorMappingInfo
extends MappingInfo {
- private static final Localizer _loc = Localizer.forPackage
- (DiscriminatorMappingInfo.class);
-
private String _value = null;
/**
Modified: openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/meta/DiscriminatorStrategy.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/meta/DiscriminatorStrategy.java?rev=899784&r1=899783&r2=899784&view=diff
==============================================================================
--- openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/meta/DiscriminatorStrategy.java (original)
+++ openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/meta/DiscriminatorStrategy.java Fri Jan 15 19:38:18 2010
@@ -58,7 +58,7 @@
/**
* Return the class for the current result row.
*/
- public Class getClass(JDBCStore store, ClassMapping base, Result result)
+ public Class<?> getClass(JDBCStore store, ClassMapping base, Result result)
throws SQLException, ClassNotFoundException;
/**
Modified: openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/meta/FieldMapping.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/meta/FieldMapping.java?rev=899784&r1=899783&r2=899784&view=diff
==============================================================================
--- openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/meta/FieldMapping.java (original)
+++ openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/meta/FieldMapping.java Fri Jan 15 19:38:18 2010
@@ -23,6 +23,7 @@
import org.apache.openjpa.enhance.PersistenceCapable;
import org.apache.openjpa.enhance.Reflection;
+import org.apache.openjpa.jdbc.identifier.DBIdentifier;
import org.apache.openjpa.jdbc.kernel.JDBCFetchConfiguration;
import org.apache.openjpa.jdbc.kernel.JDBCStore;
import org.apache.openjpa.jdbc.meta.strats.NoneFieldStrategy;
@@ -58,6 +59,7 @@
*
* @author Abe White
*/
+@SuppressWarnings("serial")
public class FieldMapping
extends FieldMetaData
implements ValueMapping, FieldStrategy {
@@ -98,7 +100,7 @@
/**
* Constructor.
*/
- public FieldMapping(String name, Class type, ClassMapping owner) {
+ public FieldMapping(String name, Class<?> type, ClassMapping owner) {
super(name, type, owner);
_info = owner.getMappingRepository().newMappingInfo(this);
_val = (ValueMapping) getValue();
@@ -623,7 +625,7 @@
private void setPKValueFromMappedByIdField(OpenJPAStateManager sm) {
if (sm instanceof StateManagerImpl) {
- List mappedByIdFields = ((StateManagerImpl)sm).
+ List<FieldMetaData> mappedByIdFields = ((StateManagerImpl)sm).
getMappedByIdFields();
if (mappedByIdFields == null)
return;
@@ -1161,10 +1163,17 @@
_val.setPolymorphic(poly);
}
+ /**
+ * @deprecated
+ */
public void mapConstraints(String name, boolean adapt) {
_val.mapConstraints(name, adapt);
}
+ public void mapConstraints(DBIdentifier name, boolean adapt) {
+ _val.mapConstraints(name, adapt);
+ }
+
public void copyMappingInfo(ValueMapping vm) {
_val.copyMappingInfo(vm);
}
@@ -1326,7 +1335,7 @@
if (mapped != null) {
FieldMappingInfo info = getMappingInfo();
FieldMappingInfo mappedInfo = mapped.getMappingInfo();
- info.setTableName(mappedInfo.getTableName());
+ info.setTableIdentifier(mappedInfo.getTableIdentifier());
info.setColumns(mapped.getElementMapping().getValueInfo().getColumns());
getElementMapping().getValueInfo().setColumns(
mappedInfo.getColumns());
Modified: openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/meta/FieldMappingInfo.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/meta/FieldMappingInfo.java?rev=899784&r1=899783&r2=899784&view=diff
==============================================================================
--- openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/meta/FieldMappingInfo.java (original)
+++ openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/meta/FieldMappingInfo.java Fri Jan 15 19:38:18 2010
@@ -22,8 +22,7 @@
import java.util.Collection;
import java.util.List;
-import org.apache.openjpa.conf.Compatibility;
-import org.apache.openjpa.jdbc.meta.strats.MapTableFieldStrategy;
+import org.apache.openjpa.jdbc.identifier.DBIdentifier;
import org.apache.openjpa.jdbc.schema.Column;
import org.apache.openjpa.jdbc.schema.ColumnIO;
import org.apache.openjpa.jdbc.schema.ForeignKey;
@@ -47,6 +46,7 @@
* @author Abe White
* @author Pinaki Poddar
*/
+@SuppressWarnings("serial")
public class FieldMappingInfo
extends MappingInfo
implements Commentable {
@@ -54,7 +54,7 @@
private static final Localizer _loc = Localizer.forPackage
(FieldMappingInfo.class);
- private String _tableName = null;
+ private DBIdentifier _tableName = DBIdentifier.NULL;
private boolean _outer = false;
private Column _orderCol = null;
private boolean _canOrderCol = true;
@@ -63,15 +63,25 @@
/**
* The user-supplied name of the table for this field.
+ * @deprecated
*/
public String getTableName() {
- return _tableName;
+ return getTableIdentifier().getName();
+ }
+
+ public DBIdentifier getTableIdentifier() {
+ return _tableName == null ? DBIdentifier.NULL : _tableName;
}
/**
* The user-supplied name of the table for this field.
+ * @deprecated
*/
public void setTableName(String tableName) {
+ setTableIdentifier(DBIdentifier.newTable(tableName));
+ }
+
+ public void setTableIdentifier(DBIdentifier tableName) {
_tableName = tableName;
}
@@ -124,19 +134,19 @@
*/
public Table getTable(final FieldMapping field, boolean create,
boolean adapt) {
- if (_tableName == null && !create)
+ if (DBIdentifier.isNull(_tableName) && !create)
return null;
Table table = field.getDefiningMapping().getTable();
- String schemaName = (table == null) ? null
- : table.getSchema().getName();
+ DBIdentifier schemaName = (table == null) ? DBIdentifier.NULL
+ : table.getSchema().getIdentifier();
// if we have no join columns defined, there may be class-level join
// information with a more fully-qualified name for our table
- String tableName = _tableName;
- if (tableName != null && getColumns().isEmpty())
+ DBIdentifier tableName = _tableName;
+ if (!DBIdentifier.isNull(tableName) && getColumns().isEmpty())
tableName = field.getDefiningMapping().getMappingInfo().
- getSecondaryTableName(tableName);
+ getSecondaryTableIdentifier(tableName);
return createTable(field, new TableDefaults() {
public String get(Schema schema) {
@@ -145,13 +155,18 @@
return field.getMappingRepository().getMappingDefaults().
getTableName(field, schema);
}
+ public DBIdentifier getIdentifier(Schema schema) {
+ // TODO Auto-generated method stub
+ return field.getMappingRepository().getMappingDefaults().
+ getTableIdentifier(field, schema);
+ }
}, schemaName, tableName, adapt);
}
public ForeignKey getJoinForeignKey (final FieldMapping field, Table table,
boolean adapt) {
if (field.isUni1ToMFK()) {
- List cols = field.getElementMapping().getValueInfo().getColumns();
+ List<Column> cols = field.getElementMapping().getValueInfo().getColumns();
return getJoin(field, table, adapt, cols);
}
return null;
@@ -168,7 +183,7 @@
}
public ForeignKey getJoin(final FieldMapping field, Table table,
- boolean adapt, List cols) {
+ boolean adapt, List<Column> cols) {
if (cols.isEmpty()) {
ClassMapping mapping;
if (field.isEmbedded() &&
@@ -251,7 +266,7 @@
Column[] uniqueColumns = new Column[templateColumns.length];
Table table = getTable(field, true, adapt);
for (int i=0; i<uniqueColumns.length; i++) {
- String columnName = templateColumns[i].getName();
+ DBIdentifier columnName = templateColumns[i].getIdentifier();
Column uniqueColumn = table.getColumn(columnName);
uniqueColumns[i] = uniqueColumn;
}
@@ -302,12 +317,15 @@
Column tmplate = new Column();
// Compatibility option determines what should be used for
// the default order column name
+ boolean delimit = field.getMappingRepository().getDBDictionary().delimitAll();
if (field.getMappingRepository().getConfiguration()
.getCompatibilityInstance().getUseJPA2DefaultOrderColumnName()) {
// Use the same strategy as column to build the field name
- tmplate.setName(field.getName() + "_ORDER");
- } else {
- tmplate.setName("ordr");
+ DBIdentifier sName = DBIdentifier.newColumn(field.getName(), delimit);
+ sName = DBIdentifier.append(sName,"_ORDER");
+ tmplate.setIdentifier(sName);
+ } else {
+ tmplate.setIdentifier(DBIdentifier.newColumn("ordr", delimit));
}
tmplate.setJavaType(JavaTypes.INT);
@@ -337,7 +355,7 @@
if (field.getJoinForeignKey() != null)
_tableName = field.getMappingRepository().getDBDictionary().
- getFullName(field.getTable(), true);
+ getFullIdentifier(field.getTable(), true);
ClassMapping def = field.getDefiningMapping();
setColumnIO(field.getJoinColumnIO());
@@ -391,7 +409,7 @@
_joinTableUniques = new ArrayList<Unique>();
for (Unique unique:unqs) {
Unique copy = new Unique();
- copy.setName(unique.getName());
+ copy.setIdentifier(unique.getIdentifier());
copy.setDeferred(unique.isDeferred());
_joinTableUniques.add(unique);
}
@@ -399,13 +417,13 @@
public boolean hasSchemaComponents() {
- return super.hasSchemaComponents() || _tableName != null
+ return super.hasSchemaComponents() || !DBIdentifier.isNull(_tableName)
|| _orderCol != null;
}
protected void clear(boolean canFlags) {
super.clear(canFlags);
- _tableName = null;
+ _tableName = DBIdentifier.NULL;
_orderCol = null;
if (canFlags)
_canOrderCol = true;
@@ -417,8 +435,8 @@
return;
FieldMappingInfo finfo = (FieldMappingInfo) info;
- if (_tableName == null)
- _tableName = finfo.getTableName();
+ if (DBIdentifier.isNull(_tableName))
+ _tableName = finfo.getTableIdentifier();
if (!_outer)
_outer = finfo.isJoinOuter();
if (_canOrderCol && _orderCol == null)