Author: tomdz
Date: Tue Oct 10 10:58:29 2006
New Revision: 454854
URL: http://svn.apache.org/viewvc?view=rev&rev=454854
Log:
Enhanced handling of length restrictions for identifiers to give platforms more
control over them
Fixed DDLUTILS-123 by adding a new Db2v8 platform
Added tests for the length restrictions
Added:
db/ddlutils/trunk/src/java/org/apache/ddlutils/platform/db2/Db2v8Builder.java
db/ddlutils/trunk/src/java/org/apache/ddlutils/platform/db2/Db2v8Platform.java
db/ddlutils/trunk/src/test/org/apache/ddlutils/platform/TestSqlBuilder.java
Removed:
db/ddlutils/trunk/src/test/org/apache/ddlutils/SqlBuilderTest.java
Modified:
db/ddlutils/trunk/src/java/org/apache/ddlutils/PlatformFactory.java
db/ddlutils/trunk/src/java/org/apache/ddlutils/PlatformInfo.java
db/ddlutils/trunk/src/java/org/apache/ddlutils/platform/SqlBuilder.java
db/ddlutils/trunk/src/test/org/apache/ddlutils/RunAllTests.java
db/ddlutils/trunk/src/test/org/apache/ddlutils/TestPlatformBase.java
db/ddlutils/trunk/src/test/org/apache/ddlutils/io/RoundtripTestBase.java
db/ddlutils/trunk/src/test/org/apache/ddlutils/io/TestConstraints.java
db/ddlutils/trunk/src/test/org/apache/ddlutils/platform/TestPlatformImplBase.java
Modified: db/ddlutils/trunk/src/java/org/apache/ddlutils/PlatformFactory.java
URL:
http://svn.apache.org/viewvc/db/ddlutils/trunk/src/java/org/apache/ddlutils/PlatformFactory.java?view=diff&rev=454854&r1=454853&r2=454854
==============================================================================
--- db/ddlutils/trunk/src/java/org/apache/ddlutils/PlatformFactory.java
(original)
+++ db/ddlutils/trunk/src/java/org/apache/ddlutils/PlatformFactory.java Tue Oct
10 10:58:29 2006
@@ -22,6 +22,7 @@
import org.apache.ddlutils.platform.axion.AxionPlatform;
import org.apache.ddlutils.platform.cloudscape.CloudscapePlatform;
import org.apache.ddlutils.platform.db2.Db2Platform;
+import org.apache.ddlutils.platform.db2.Db2v8Platform;
import org.apache.ddlutils.platform.derby.DerbyPlatform;
import org.apache.ddlutils.platform.firebird.FirebirdPlatform;
import org.apache.ddlutils.platform.hsqldb.HsqlDbPlatform;
@@ -182,6 +183,7 @@
addPlatform(_platforms, AxionPlatform.DATABASENAME,
AxionPlatform.class);
addPlatform(_platforms, CloudscapePlatform.DATABASENAME,
CloudscapePlatform.class);
addPlatform(_platforms, Db2Platform.DATABASENAME,
Db2Platform.class);
+ addPlatform(_platforms, Db2v8Platform.DATABASENAME,
Db2v8Platform.class);
addPlatform(_platforms, DerbyPlatform.DATABASENAME,
DerbyPlatform.class);
addPlatform(_platforms, FirebirdPlatform.DATABASENAME,
FirebirdPlatform.class);
addPlatform(_platforms, HsqlDbPlatform.DATABASENAME,
HsqlDbPlatform.class);
Modified: db/ddlutils/trunk/src/java/org/apache/ddlutils/PlatformInfo.java
URL:
http://svn.apache.org/viewvc/db/ddlutils/trunk/src/java/org/apache/ddlutils/PlatformInfo.java?view=diff&rev=454854&r1=454853&r2=454854
==============================================================================
--- db/ddlutils/trunk/src/java/org/apache/ddlutils/PlatformInfo.java (original)
+++ db/ddlutils/trunk/src/java/org/apache/ddlutils/PlatformInfo.java Tue Oct 10
10:58:29 2006
@@ -100,9 +100,17 @@
shall be used. */
private boolean _autoCommitModeForLastIdentityValueReading = true;
- /** Specifies the maximum length that an identifier (name of a table,
column, constraint etc.)
- can have for this database; use -1 if there is no limit. */
- private int _maxIdentifierLength = -1;
+ /** Specifies the maximum length that a table name can have for this
database (-1 if there is no limit). */
+ private int _maxTableNameLength = -1;
+
+ /** Specifies the maximum length that a column name can have for this
database (-1 if there is no limit). */
+ private int _maxColumnNameLength = -1;
+
+ /** Specifies the maximum length that a constraint name can have for this
database (-1 if there is no limit). */
+ private int _maxConstraintNameLength = -1;
+
+ /** Specifies the maximum length that a foreign key name can have for this
database (-1 if there is no limit). */
+ private int _maxForeignKeyNameLength = -1;
/** The string used for delimiting SQL identifiers, eg. table names,
column names etc. */
private String _delimiterToken = "\"";
@@ -565,23 +573,97 @@
}
/**
- * Returns the maximum length of identifiers that this database allows.
+ * Returns the maximum number of characters that a table name can have.
+ *
+ * @return The number of characters, or -1 if not limited
+ */
+ public int getMaxTableNameLength()
+ {
+ return _maxTableNameLength;
+ }
+
+ /**
+ * Returns the maximum number of characters that a column name can have.
*
- * @return The maximum identifier length, -1 if unlimited
+ * @return The number of characters, or -1 if not limited
*/
- public int getMaxIdentifierLength()
+ public int getMaxColumnNameLength()
{
- return _maxIdentifierLength;
+ return _maxColumnNameLength;
}
/**
- * Sets the maximum length of identifiers that this database allows.
+ * Returns the maximum number of characters that a constraint name can
have.
+ *
+ * @return The number of characters, or -1 if not limited
+ */
+ public int getMaxConstraintNameLength()
+ {
+ return _maxConstraintNameLength;
+ }
+
+ /**
+ * Returns the maximum number of characters that a foreign key name can
have.
+ *
+ * @return The number of characters, or -1 if not limited
+ */
+ public int getMaxForeignKeyNameLength()
+ {
+ return _maxForeignKeyNameLength;
+ }
+
+ /**
+ * Sets the maximum length of all identifiers that this database allows.
+ * Use this method if the length limit is the same for all kinds of
identifiers.
*
* @param maxIdentifierLength The maximum identifier length, -1 if
unlimited
*/
public void setMaxIdentifierLength(int maxIdentifierLength)
{
- _maxIdentifierLength = maxIdentifierLength;
+ _maxTableNameLength = maxIdentifierLength;
+ _maxColumnNameLength = maxIdentifierLength;
+ _maxConstraintNameLength = maxIdentifierLength;
+ _maxForeignKeyNameLength = maxIdentifierLength;
+ }
+
+ /**
+ * Sets the maximum length of table names that this database allows.
+ *
+ * @param maxTableNameLength The maximum length, -1 if unlimited
+ */
+ public void setMaxTableNameLength(int maxTableNameLength)
+ {
+ _maxTableNameLength = maxTableNameLength;
+ }
+
+ /**
+ * Sets the maximum length of column names that this database allows.
+ *
+ * @param maxColumnNameLength The maximum length, -1 if unlimited
+ */
+ public void setMaxColumnNameLength(int maxColumnNameLength)
+ {
+ _maxColumnNameLength = maxColumnNameLength;
+ }
+
+ /**
+ * Sets the maximum length of constraint names that this database allows.
+ *
+ * @param maxConstraintNameLength The maximum length, -1 if unlimited
+ */
+ public void setMaxConstraintNameLength(int maxConstraintNameLength)
+ {
+ _maxConstraintNameLength = maxConstraintNameLength;
+ }
+
+ /**
+ * Sets the maximum length of foreign key names that this database allows.
+ *
+ * @param maxForeignKeyNameLength The maximum length, -1 if unlimited
+ */
+ public void setMaxForeignKeyNameLength(int maxForeignKeyNameLength)
+ {
+ _maxForeignKeyNameLength = maxForeignKeyNameLength;
}
/**
Modified:
db/ddlutils/trunk/src/java/org/apache/ddlutils/platform/SqlBuilder.java
URL:
http://svn.apache.org/viewvc/db/ddlutils/trunk/src/java/org/apache/ddlutils/platform/SqlBuilder.java?view=diff&rev=454854&r1=454853&r2=454854
==============================================================================
--- db/ddlutils/trunk/src/java/org/apache/ddlutils/platform/SqlBuilder.java
(original)
+++ db/ddlutils/trunk/src/java/org/apache/ddlutils/platform/SqlBuilder.java Tue
Oct 10 10:58:29 2006
@@ -287,7 +287,55 @@
{
_charSequencesToEscape.put(charSequence, escapedVersion);
}
-
+
+ /**
+ * Returns the maximum number of characters that a table name can have.
+ * This method is intended to give platform specific builder
implementations
+ * more control over the maximum length.
+ *
+ * @return The number of characters, or -1 if not limited
+ */
+ public int getMaxTableNameLength()
+ {
+ return getPlatformInfo().getMaxTableNameLength();
+ }
+
+ /**
+ * Returns the maximum number of characters that a column name can have.
+ * This method is intended to give platform specific builder
implementations
+ * more control over the maximum length.
+ *
+ * @return The number of characters, or -1 if not limited
+ */
+ public int getMaxColumnNameLength()
+ {
+ return getPlatformInfo().getMaxColumnNameLength();
+ }
+
+ /**
+ * Returns the maximum number of characters that a constraint name can
have.
+ * This method is intended to give platform specific builder
implementations
+ * more control over the maximum length.
+ *
+ * @return The number of characters, or -1 if not limited
+ */
+ public int getMaxConstraintNameLength()
+ {
+ return getPlatformInfo().getMaxConstraintNameLength();
+ }
+
+ /**
+ * Returns the maximum number of characters that a foreign key name can
have.
+ * This method is intended to give platform specific builder
implementations
+ * more control over the maximum length.
+ *
+ * @return The number of characters, or -1 if not limited
+ */
+ public int getMaxForeignKeyNameLength()
+ {
+ return getPlatformInfo().getMaxForeignKeyNameLength();
+ }
+
//
// public interface
//
@@ -1536,7 +1584,7 @@
* @param desiredLength The desired maximum length
* @return The shortened version
*/
- protected String shortenName(String name, int desiredLength)
+ public String shortenName(String name, int desiredLength)
{
// TODO: Find an algorithm that generates unique names
int originalLength = name.length();
@@ -1571,7 +1619,7 @@
*/
public String getTableName(Table table)
{
- return shortenName(table.getName(),
getPlatformInfo().getMaxIdentifierLength());
+ return shortenName(table.getName(), getMaxTableNameLength());
}
/**
@@ -1670,7 +1718,7 @@
*/
protected String getColumnName(Column column) throws IOException
{
- return shortenName(column.getName(),
getPlatformInfo().getMaxIdentifierLength());
+ return shortenName(column.getName(), getMaxColumnNameLength());
}
/**
@@ -1990,7 +2038,7 @@
name.append(fk.getForeignTableName());
fkName = getConstraintName(null, table, "FK", name.toString());
}
- fkName = shortenName(fkName,
getPlatformInfo().getMaxIdentifierLength());
+ fkName = shortenName(fkName, getMaxForeignKeyNameLength());
if (needsName)
{
@@ -2027,7 +2075,7 @@
result.append("_");
result.append(suffix);
}
- return shortenName(result.toString(),
getPlatformInfo().getMaxIdentifierLength());
+ return shortenName(result.toString(), getMaxConstraintNameLength());
}
/**
@@ -2107,7 +2155,7 @@
*/
public String getIndexName(Index index)
{
- return index.getName();
+ return shortenName(index.getName(), getMaxConstraintNameLength());
}
/**
Added:
db/ddlutils/trunk/src/java/org/apache/ddlutils/platform/db2/Db2v8Builder.java
URL:
http://svn.apache.org/viewvc/db/ddlutils/trunk/src/java/org/apache/ddlutils/platform/db2/Db2v8Builder.java?view=auto&rev=454854
==============================================================================
---
db/ddlutils/trunk/src/java/org/apache/ddlutils/platform/db2/Db2v8Builder.java
(added)
+++
db/ddlutils/trunk/src/java/org/apache/ddlutils/platform/db2/Db2v8Builder.java
Tue Oct 10 10:58:29 2006
@@ -0,0 +1,47 @@
+package org.apache.ddlutils.platform.db2;
+
+/*
+ * Copyright 2006 The Apache Software Foundation.
+ *
+ * Licensed 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.
+ */
+
+import org.apache.ddlutils.Platform;
+
+/**
+ * The SQL Builder for DB2 v8 and above.
+ *
+ * @version $Revision: $
+ */
+public class Db2v8Builder extends Db2Builder
+{
+ /**
+ * Creates a new builder instance.
+ *
+ * @param platform The plaftform this builder belongs to
+ */
+ public Db2v8Builder(Platform platform)
+ {
+ super(platform);
+ }
+
+ /**
+ * [EMAIL PROTECTED]
+ */
+ public int getMaxConstraintNameLength()
+ {
+ // In non-delimited identifier mode we can only use 18 characters
apparently
+ return getPlatform().isDelimitedIdentifierModeOn() ?
super.getMaxConstraintNameLength() : 18;
+ }
+
+}
Added:
db/ddlutils/trunk/src/java/org/apache/ddlutils/platform/db2/Db2v8Platform.java
URL:
http://svn.apache.org/viewvc/db/ddlutils/trunk/src/java/org/apache/ddlutils/platform/db2/Db2v8Platform.java?view=auto&rev=454854
==============================================================================
---
db/ddlutils/trunk/src/java/org/apache/ddlutils/platform/db2/Db2v8Platform.java
(added)
+++
db/ddlutils/trunk/src/java/org/apache/ddlutils/platform/db2/Db2v8Platform.java
Tue Oct 10 10:58:29 2006
@@ -0,0 +1,46 @@
+package org.apache.ddlutils.platform.db2;
+
+/*
+ * Copyright 2006 The Apache Software Foundation.
+ *
+ * Licensed 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.
+ */
+
+/**
+ * The DB2 platform implementation for DB2 v8 and above.
+ *
+ * @version $Revision: $
+ */
+public class Db2v8Platform extends Db2Platform
+{
+ /** Database name of this platform. */
+ public static final String DATABASENAME = "DB2v8";
+
+ /**
+ * Creates a new platform instance.
+ */
+ public Db2v8Platform()
+ {
+ super();
+ // DB2 v8 has a maximum identifier length of 128 bytes for things like
table names,
+ // stored procedure names etc., 30 bytes for column names and 18 bytes
for foreign key names
+ // Note that we optimistically assume that number of characters =
number of bytes
+ // If the name contains characters that are more than one byte in the
database's
+ // encoding, then the db will report an error anyway, but we cannot
really calculate
+ // the number of bytes
+ getPlatformInfo().setMaxIdentifierLength(128);
+ getPlatformInfo().setMaxColumnNameLength(30);
+ getPlatformInfo().setMaxForeignKeyNameLength(18);
+ setSqlBuilder(new Db2v8Builder(this));
+ }
+}
Modified: db/ddlutils/trunk/src/test/org/apache/ddlutils/RunAllTests.java
URL:
http://svn.apache.org/viewvc/db/ddlutils/trunk/src/test/org/apache/ddlutils/RunAllTests.java?view=diff&rev=454854&r1=454853&r2=454854
==============================================================================
--- db/ddlutils/trunk/src/test/org/apache/ddlutils/RunAllTests.java (original)
+++ db/ddlutils/trunk/src/test/org/apache/ddlutils/RunAllTests.java Tue Oct 10
10:58:29 2006
@@ -44,6 +44,7 @@
import org.apache.ddlutils.platform.TestPlatformUtils;
import org.apache.ddlutils.platform.TestPostgresqlPlatform;
import org.apache.ddlutils.platform.TestSapDbPlatform;
+import org.apache.ddlutils.platform.TestSqlBuilder;
import org.apache.ddlutils.platform.TestSybasePlatform;
import junit.framework.Test;
@@ -89,7 +90,7 @@
// tests that don't need a live database
suite.addTestSuite(TestArrayAccessAtTable.class);
- suite.addTestSuite(SqlBuilderTest.class);
+ suite.addTestSuite(TestSqlBuilder.class);
suite.addTestSuite(TestPlatformUtils.class);
suite.addTestSuite(TestDatabaseIO.class);
suite.addTestSuite(TestDataReader.class);
Modified: db/ddlutils/trunk/src/test/org/apache/ddlutils/TestPlatformBase.java
URL:
http://svn.apache.org/viewvc/db/ddlutils/trunk/src/test/org/apache/ddlutils/TestPlatformBase.java?view=diff&rev=454854&r1=454853&r2=454854
==============================================================================
--- db/ddlutils/trunk/src/test/org/apache/ddlutils/TestPlatformBase.java
(original)
+++ db/ddlutils/trunk/src/test/org/apache/ddlutils/TestPlatformBase.java Tue
Oct 10 10:58:29 2006
@@ -21,6 +21,7 @@
import java.io.StringWriter;
import org.apache.ddlutils.model.Database;
+import org.apache.ddlutils.platform.SqlBuilder;
import org.xml.sax.SAXException;
/**
@@ -166,6 +167,16 @@
protected PlatformInfo getPlatformInfo()
{
return getPlatform().getPlatformInfo();
+ }
+
+ /**
+ * Returns the SQL builder of the tested platform.
+ *
+ * @return The builder object
+ */
+ protected SqlBuilder getSqlBuilder()
+ {
+ return getPlatform().getSqlBuilder();
}
/**
Modified:
db/ddlutils/trunk/src/test/org/apache/ddlutils/io/RoundtripTestBase.java
URL:
http://svn.apache.org/viewvc/db/ddlutils/trunk/src/test/org/apache/ddlutils/io/RoundtripTestBase.java?view=diff&rev=454854&r1=454853&r2=454854
==============================================================================
--- db/ddlutils/trunk/src/test/org/apache/ddlutils/io/RoundtripTestBase.java
(original)
+++ db/ddlutils/trunk/src/test/org/apache/ddlutils/io/RoundtripTestBase.java
Tue Oct 10 10:58:29 2006
@@ -349,14 +349,14 @@
if (_useDelimitedIdentifiers)
{
assertEquals("Table names do not match.",
- expected.getName(),
- actual.getName());
+
getPlatform().getSqlBuilder().shortenName(expected.getName(),
getSqlBuilder().getMaxTableNameLength()),
+
getPlatform().getSqlBuilder().shortenName(actual.getName(),
getSqlBuilder().getMaxTableNameLength()));
}
else
{
assertEquals("Table names do not match (ignoring case).",
- expected.getName().toUpperCase(),
- actual.getName().toUpperCase());
+
getPlatform().getSqlBuilder().shortenName(expected.getName().toUpperCase(),
getSqlBuilder().getMaxTableNameLength()),
+
getPlatform().getSqlBuilder().shortenName(actual.getName().toUpperCase(),
getSqlBuilder().getMaxTableNameLength()));
}
assertEquals("Not the same number of columns in table
"+actual.getName()+".",
expected.getColumnCount(),
@@ -373,12 +373,12 @@
for (int expectedFkIdx = 0; expectedFkIdx <
expected.getForeignKeyCount(); expectedFkIdx++)
{
ForeignKey expectedFk = expected.getForeignKey(expectedFkIdx);
- String expectedName = expectedFk.getName();
+ String expectedName =
getPlatform().getSqlBuilder().shortenName(expectedFk.getName(),
getSqlBuilder().getMaxForeignKeyNameLength());
for (int actualFkIdx = 0; actualFkIdx <
actual.getForeignKeyCount(); actualFkIdx++)
{
ForeignKey actualFk = actual.getForeignKey(actualFkIdx);
- String actualName = actualFk.getName();
+ String actualName =
getPlatform().getSqlBuilder().shortenName(actualFk.getName(),
getSqlBuilder().getMaxForeignKeyNameLength());
if ((_useDelimitedIdentifiers &&
expectedName.equals(actualName)) ||
(!_useDelimitedIdentifiers &&
expectedName.equalsIgnoreCase(actualName)))
@@ -408,14 +408,14 @@
if (_useDelimitedIdentifiers)
{
assertEquals("Column names do not match.",
- expected.getName(),
- actual.getName());
+
getPlatform().getSqlBuilder().shortenName(expected.getName(),
getSqlBuilder().getMaxColumnNameLength()),
+
getPlatform().getSqlBuilder().shortenName(actual.getName(),
getSqlBuilder().getMaxColumnNameLength()));
}
else
{
assertEquals("Column names do not match (ignoring case).",
- expected.getName().toUpperCase(),
- actual.getName().toUpperCase());
+
getPlatform().getSqlBuilder().shortenName(expected.getName().toUpperCase(),
getSqlBuilder().getMaxColumnNameLength()),
+
getPlatform().getSqlBuilder().shortenName(actual.getName().toUpperCase(),
getSqlBuilder().getMaxColumnNameLength()));
}
assertEquals("Primary key status not the same for column
"+actual.getName()+".",
expected.isPrimaryKey(),
@@ -474,20 +474,20 @@
if (_useDelimitedIdentifiers)
{
assertEquals("Foreign key names do not match.",
- expected.getName(),
- actual.getName());
+
getPlatform().getSqlBuilder().shortenName(expected.getName(),
getSqlBuilder().getMaxForeignKeyNameLength()),
+
getPlatform().getSqlBuilder().shortenName(actual.getName(),
getSqlBuilder().getMaxForeignKeyNameLength()));
assertEquals("Referenced table names do not match.",
- expected.getForeignTableName(),
- actual.getForeignTableName());
+
getPlatform().getSqlBuilder().shortenName(expected.getForeignTableName(),
getSqlBuilder().getMaxTableNameLength()),
+
getPlatform().getSqlBuilder().shortenName(actual.getForeignTableName(),
getSqlBuilder().getMaxTableNameLength()));
}
else
{
assertEquals("Foreign key names do not match (ignoring case).",
- expected.getName().toUpperCase(),
- actual.getName().toUpperCase());
+
getPlatform().getSqlBuilder().shortenName(expected.getName().toUpperCase(),
getSqlBuilder().getMaxForeignKeyNameLength()),
+
getPlatform().getSqlBuilder().shortenName(actual.getName().toUpperCase(),
getSqlBuilder().getMaxForeignKeyNameLength()));
assertEquals("Referenced table names do not match (ignoring
case).",
- expected.getForeignTableName().toUpperCase(),
- actual.getForeignTableName().toUpperCase());
+
getPlatform().getSqlBuilder().shortenName(expected.getForeignTableName().toUpperCase(),
getSqlBuilder().getMaxTableNameLength()),
+
getPlatform().getSqlBuilder().shortenName(actual.getForeignTableName().toUpperCase(),
getSqlBuilder().getMaxTableNameLength()));
}
assertEquals("Not the same number of references in foreign key
"+actual.getName()+".",
expected.getReferenceCount(),
@@ -510,20 +510,20 @@
if (_useDelimitedIdentifiers)
{
assertEquals("Local column names do not match.",
- expected.getLocalColumnName(),
- actual.getLocalColumnName());
+
getPlatform().getSqlBuilder().shortenName(expected.getLocalColumnName(),
getSqlBuilder().getMaxColumnNameLength()),
+
getPlatform().getSqlBuilder().shortenName(actual.getLocalColumnName(),
getSqlBuilder().getMaxColumnNameLength()));
assertEquals("Foreign column names do not match.",
- expected.getForeignColumnName(),
- actual.getForeignColumnName());
+
getPlatform().getSqlBuilder().shortenName(expected.getForeignColumnName(),
getSqlBuilder().getMaxColumnNameLength()),
+
getPlatform().getSqlBuilder().shortenName(actual.getForeignColumnName(),
getSqlBuilder().getMaxColumnNameLength()));
}
else
{
assertEquals("Local column names do not match (ignoring case).",
- expected.getLocalColumnName().toUpperCase(),
- actual.getLocalColumnName().toUpperCase());
+
getPlatform().getSqlBuilder().shortenName(expected.getLocalColumnName().toUpperCase(),
getSqlBuilder().getMaxColumnNameLength()),
+
getPlatform().getSqlBuilder().shortenName(actual.getLocalColumnName().toUpperCase(),
getSqlBuilder().getMaxColumnNameLength()));
assertEquals("Foreign column names do not match (ignoring case).",
- expected.getForeignColumnName().toUpperCase(),
- actual.getForeignColumnName().toUpperCase());
+
getPlatform().getSqlBuilder().shortenName(expected.getForeignColumnName().toUpperCase(),
getSqlBuilder().getMaxColumnNameLength()),
+
getPlatform().getSqlBuilder().shortenName(actual.getForeignColumnName().toUpperCase(),
getSqlBuilder().getMaxColumnNameLength()));
}
}
@@ -538,14 +538,14 @@
if (_useDelimitedIdentifiers)
{
assertEquals("Index names do not match.",
- expected.getName(),
- actual.getName());
+
getPlatform().getSqlBuilder().shortenName(expected.getName(),
getSqlBuilder().getMaxConstraintNameLength()),
+
getPlatform().getSqlBuilder().shortenName(actual.getName(),
getSqlBuilder().getMaxConstraintNameLength()));
}
else
{
assertEquals("Index names do not match (ignoring case).",
- expected.getName().toUpperCase(),
- actual.getName().toUpperCase());
+
getPlatform().getSqlBuilder().shortenName(expected.getName().toUpperCase(),
getSqlBuilder().getMaxConstraintNameLength()),
+
getPlatform().getSqlBuilder().shortenName(actual.getName().toUpperCase(),
getSqlBuilder().getMaxConstraintNameLength()));
}
assertEquals("Unique status not the same for index
"+actual.getName()+".",
expected.isUnique(),
@@ -571,14 +571,14 @@
if (_useDelimitedIdentifiers)
{
assertEquals("Index column names do not match.",
- expected.getName(),
- actual.getName());
+
getPlatform().getSqlBuilder().shortenName(expected.getName(),
getSqlBuilder().getMaxColumnNameLength()),
+
getPlatform().getSqlBuilder().shortenName(actual.getName(),
getSqlBuilder().getMaxColumnNameLength()));
}
else
{
assertEquals("Index column names do not match (ignoring case).",
- expected.getName().toUpperCase(),
- actual.getName().toUpperCase());
+
getPlatform().getSqlBuilder().shortenName(expected.getName().toUpperCase(),
getSqlBuilder().getMaxColumnNameLength()),
+
getPlatform().getSqlBuilder().shortenName(actual.getName().toUpperCase(),
getSqlBuilder().getMaxColumnNameLength()));
}
assertEquals("Size not the same for index column
"+actual.getName()+".",
expected.getSize(),
Modified: db/ddlutils/trunk/src/test/org/apache/ddlutils/io/TestConstraints.java
URL:
http://svn.apache.org/viewvc/db/ddlutils/trunk/src/test/org/apache/ddlutils/io/TestConstraints.java?view=diff&rev=454854&r1=454853&r2=454854
==============================================================================
--- db/ddlutils/trunk/src/test/org/apache/ddlutils/io/TestConstraints.java
(original)
+++ db/ddlutils/trunk/src/test/org/apache/ddlutils/io/TestConstraints.java Tue
Oct 10 10:58:29 2006
@@ -16,6 +16,7 @@
* limitations under the License.
*/
+import org.apache.commons.lang.StringUtils;
import org.apache.ddlutils.model.Database;
import org.apache.ddlutils.platform.sybase.SybasePlatform;
@@ -64,6 +65,107 @@
assertTrue(alterTablesSql.length() == 0);
}
+ }
+
+ /**
+ * Tests a table name that is longer than the maximum allowed.
+ */
+ public void testLongTableName()
+ {
+ if (getSqlBuilder().getMaxTableNameLength() == -1)
+ {
+ return;
+ }
+
+ String tableName = StringUtils.repeat("Test",
(getSqlBuilder().getMaxTableNameLength() / 4) + 3);
+ final String modelXml =
+ "<?xml version='1.0' encoding='ISO-8859-1'?>\n"+
+ "<database name='roundtriptest'>\n"+
+ " <table name='" + tableName + "'>\n"+
+ " <column name='pk' type='INTEGER' primaryKey='true'
required='true'/>\n"+
+ " <column name='avalue' type='INTEGER' required='false'/>\n"+
+ " </table>\n"+
+ "</database>";
+
+ performConstraintsTest(modelXml, true);
+ }
+
+ /**
+ * Tests a column name that is longer than the maximum allowed.
+ */
+ public void testLongColumnName()
+ {
+ if (getPlatformInfo().getMaxColumnNameLength() == -1)
+ {
+ return;
+ }
+
+ String columnName = StringUtils.repeat("Test",
(getSqlBuilder().getMaxColumnNameLength() / 4) + 3);
+ final String modelXml =
+ "<?xml version='1.0' encoding='ISO-8859-1'?>\n"+
+ "<database name='roundtriptest'>\n"+
+ " <table name='lengthtest'>\n"+
+ " <column name='pk' type='INTEGER' primaryKey='true'
required='true'/>\n"+
+ " <column name='" + columnName + "' type='INTEGER'
required='false'/>\n"+
+ " </table>\n"+
+ "</database>";
+
+ performConstraintsTest(modelXml, true);
+ }
+
+ /**
+ * Tests a constraint name that is longer than the maximum allowed.
+ */
+ public void testLongConstraintName()
+ {
+ if (getSqlBuilder().getMaxConstraintNameLength() == -1)
+ {
+ return;
+ }
+
+ String constraintName = StringUtils.repeat("Test",
(getSqlBuilder().getMaxConstraintNameLength() / 4) + 3);
+ final String modelXml =
+ "<?xml version='1.0' encoding='ISO-8859-1'?>\n"+
+ "<database name='roundtriptest'>\n"+
+ " <table name='roundtrip'>\n"+
+ " <column name='pk' type='INTEGER' primaryKey='true'
required='true'/>\n"+
+ " <column name='avalue' type='DOUBLE'/>\n"+
+ " <index name='" + constraintName + "'>\n"+
+ " <index-column name='avalue'/>\n"+
+ " </index>\n"+
+ " </table>\n"+
+ "</database>";
+
+ performConstraintsTest(modelXml, true);
+ }
+
+ /**
+ * Tests a foreign key name that is longer than the maximum allowed.
+ */
+ public void testLongForeignKeyName()
+ {
+ if (getSqlBuilder().getMaxForeignKeyNameLength() == -1)
+ {
+ return;
+ }
+
+ String fkName = StringUtils.repeat("Test",
(getSqlBuilder().getMaxForeignKeyNameLength() / 4) + 3);
+ final String modelXml =
+ "<?xml version='1.0' encoding='ISO-8859-1'?>\n"+
+ "<database name='roundtriptest'>\n"+
+ " <table name='roundtrip_1'>\n"+
+ " <column name='pk' type='INTEGER' primaryKey='true'
required='true'/>\n"+
+ " </table>\n"+
+ " <table name='roundtrip_2'>\n"+
+ " <column name='pk' type='VARCHAR' size='32' primaryKey='true'
required='true'/>\n"+
+ " <column name='avalue' type='INTEGER' required='true'/>\n"+
+ " <foreign-key name='" + fkName + "'
foreignTable='roundtrip_1'>\n"+
+ " <reference local='avalue' foreign='pk'/>\n"+
+ " </foreign-key>\n"+
+ " </table>\n"+
+ "</database>";
+
+ performConstraintsTest(modelXml, true);
}
/**
Modified:
db/ddlutils/trunk/src/test/org/apache/ddlutils/platform/TestPlatformImplBase.java
URL:
http://svn.apache.org/viewvc/db/ddlutils/trunk/src/test/org/apache/ddlutils/platform/TestPlatformImplBase.java?view=diff&rev=454854&r1=454853&r2=454854
==============================================================================
---
db/ddlutils/trunk/src/test/org/apache/ddlutils/platform/TestPlatformImplBase.java
(original)
+++
db/ddlutils/trunk/src/test/org/apache/ddlutils/platform/TestPlatformImplBase.java
Tue Oct 10 10:58:29 2006
@@ -51,6 +51,14 @@
}
/**
+ * [EMAIL PROTECTED]
+ */
+ protected String getDatabaseName()
+ {
+ return null;
+ }
+
+ /**
* Test the toColumnValues method.
*/
public void testToColumnValues()
@@ -68,13 +76,5 @@
assertEquals("name",
map.get("name"));
assertTrue(map.containsKey("id"));
- }
-
- /**
- * [EMAIL PROTECTED]
- */
- protected String getDatabaseName()
- {
- return null;
}
}
Added:
db/ddlutils/trunk/src/test/org/apache/ddlutils/platform/TestSqlBuilder.java
URL:
http://svn.apache.org/viewvc/db/ddlutils/trunk/src/test/org/apache/ddlutils/platform/TestSqlBuilder.java?view=auto&rev=454854
==============================================================================
--- db/ddlutils/trunk/src/test/org/apache/ddlutils/platform/TestSqlBuilder.java
(added)
+++ db/ddlutils/trunk/src/test/org/apache/ddlutils/platform/TestSqlBuilder.java
Tue Oct 10 10:58:29 2006
@@ -0,0 +1,63 @@
+package org.apache.ddlutils.platform;
+
+/*
+ * Copyright 2005-2006 The Apache Software Foundation.
+ *
+ * Licensed 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.
+ */
+
+import java.util.HashMap;
+import java.util.Map;
+
+import org.apache.ddlutils.TestBase;
+import org.apache.ddlutils.model.Database;
+import org.apache.ddlutils.model.Table;
+
+/**
+ * Test the base SqlBuilder class.
+ *
+ * @author Martin van den Bemt
+ * @version $Revision: $
+ */
+public class TestSqlBuilder extends TestBase
+{
+ /**
+ * Tests the [EMAIL PROTECTED] SqlBuilder#getUpdateSql(Table, Map,
boolean)} method.
+ */
+ public void testUpdateSql()
+ {
+ final String modelXml =
+ "<?xml version='1.0' encoding='ISO-8859-1'?>\n"+
+ "<database name='ddlutils'>\n"+
+ " <table name='TestTable'>\n"+
+ " <column name='id' autoIncrement='true' type='INTEGER'
primaryKey='true'/>\n"+
+ " <column name='name' type='VARCHAR' size='15'/>\n"+
+ " </table>\n"+
+ "</database>";
+
+ TestPlatform platform = new TestPlatform();
+ SqlBuilder sqlBuilder = platform.getSqlBuilder();
+ Database database = parseDatabaseFromString(modelXml);
+ Map map = new HashMap();
+
+ map.put("name", "ddlutils");
+ map.put("id", new Integer(0));
+
+ platform.setDelimitedIdentifierModeOn(true);
+
+ String sql = sqlBuilder.getUpdateSql(database.getTable(0), map, false);
+
+ assertEquals("UPDATE \"TestTable\" SET \"name\" = 'ddlutils' WHERE
\"id\" = '0'",
+ sql);
+ }
+}