mirror of https://github.com/apache/openjpa.git
OPENJPA-664: Check for length of schema component name during generation of SQL DDL generation.
git-svn-id: https://svn.apache.org/repos/asf/openjpa/trunk@679442 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
388754a280
commit
315cc2d155
|
@ -3062,7 +3062,9 @@ public class DBDictionary
|
||||||
*/
|
*/
|
||||||
public String[] getCreateTableSQL(Table table) {
|
public String[] getCreateTableSQL(Table table) {
|
||||||
StringBuffer buf = new StringBuffer();
|
StringBuffer buf = new StringBuffer();
|
||||||
buf.append("CREATE TABLE ").append(getFullName(table, false));
|
String tableName = checkNameLength(getFullName(table, false),
|
||||||
|
maxTableNameLength, "long-table-name");
|
||||||
|
buf.append("CREATE TABLE ").append(tableName);
|
||||||
if (supportsComments && table.hasComment()) {
|
if (supportsComments && table.hasComment()) {
|
||||||
buf.append(" ");
|
buf.append(" ");
|
||||||
comment(buf, table.getComment());
|
comment(buf, table.getComment());
|
||||||
|
@ -3135,7 +3137,9 @@ public class DBDictionary
|
||||||
|
|
||||||
StringBuffer buf = new StringBuffer();
|
StringBuffer buf = new StringBuffer();
|
||||||
buf.append("CREATE SEQUENCE ");
|
buf.append("CREATE SEQUENCE ");
|
||||||
buf.append(getFullName(seq));
|
String seqName = checkNameLength(getFullName(seq), maxTableNameLength,
|
||||||
|
"long-seq-name");
|
||||||
|
buf.append(seqName);
|
||||||
if (seq.getInitialValue() != 0)
|
if (seq.getInitialValue() != 0)
|
||||||
buf.append(" START WITH ").append(seq.getInitialValue());
|
buf.append(" START WITH ").append(seq.getInitialValue());
|
||||||
if (seq.getIncrement() > 1)
|
if (seq.getIncrement() > 1)
|
||||||
|
@ -3162,8 +3166,9 @@ public class DBDictionary
|
||||||
if (index.isUnique())
|
if (index.isUnique())
|
||||||
buf.append("UNIQUE ");
|
buf.append("UNIQUE ");
|
||||||
buf.append("INDEX ").append(index.getName());
|
buf.append("INDEX ").append(index.getName());
|
||||||
|
String indexName = checkNameLength(getFullName(index.getTable(), false),
|
||||||
buf.append(" ON ").append(getFullName(index.getTable(), false));
|
maxIndexNameLength, "long-index-name");
|
||||||
|
buf.append(" ON ").append(indexName);
|
||||||
buf.append(" (").append(Strings.join(index.getColumns(), ", ")).
|
buf.append(" (").append(Strings.join(index.getColumns(), ", ")).
|
||||||
append(")");
|
append(")");
|
||||||
|
|
||||||
|
@ -3272,7 +3277,9 @@ public class DBDictionary
|
||||||
*/
|
*/
|
||||||
protected String getDeclareColumnSQL(Column col, boolean alter) {
|
protected String getDeclareColumnSQL(Column col, boolean alter) {
|
||||||
StringBuffer buf = new StringBuffer();
|
StringBuffer buf = new StringBuffer();
|
||||||
buf.append(col).append(" ");
|
String columnName = checkNameLength(col.getName(), maxColumnNameLength,
|
||||||
|
"long-column-name");
|
||||||
|
buf.append(columnName).append(" ");
|
||||||
buf.append(getTypeName(col));
|
buf.append(getTypeName(col));
|
||||||
|
|
||||||
// can't add constraints to a column we're adding after table
|
// can't add constraints to a column we're adding after table
|
||||||
|
@ -3459,11 +3466,11 @@ public class DBDictionary
|
||||||
if (!supportsUniqueConstraints
|
if (!supportsUniqueConstraints
|
||||||
|| (unq.isDeferred() && !supportsDeferredUniqueConstraints()))
|
|| (unq.isDeferred() && !supportsDeferredUniqueConstraints()))
|
||||||
return null;
|
return null;
|
||||||
|
|
||||||
StringBuffer buf = new StringBuffer();
|
StringBuffer buf = new StringBuffer();
|
||||||
if (unq.getName() != null
|
if (unq.getName() != null
|
||||||
&& CONS_NAME_BEFORE.equals(constraintNameMode))
|
&& CONS_NAME_BEFORE.equals(constraintNameMode))
|
||||||
buf.append("CONSTRAINT ").append(unq.getName()).append(" ");
|
buf.append("CONSTRAINT ").append(checkNameLength(unq.getName(),
|
||||||
|
maxConstraintNameLength, "long-constraint-name")).append(" ");
|
||||||
buf.append("UNIQUE ");
|
buf.append("UNIQUE ");
|
||||||
if (unq.getName() != null && CONS_NAME_MID.equals(constraintNameMode))
|
if (unq.getName() != null && CONS_NAME_MID.equals(constraintNameMode))
|
||||||
buf.append(unq.getName()).append(" ");
|
buf.append(unq.getName()).append(" ");
|
||||||
|
@ -4536,4 +4543,16 @@ public class DBDictionary
|
||||||
public void deleteStream(JDBCStore store, Select sel) throws SQLException {
|
public void deleteStream(JDBCStore store, Select sel) throws SQLException {
|
||||||
// Do nothing
|
// Do nothing
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Validate that the given name is no longer than given maximum length.
|
||||||
|
* If the given name is indeed longer then raises an UserException with the
|
||||||
|
* given message key otherwise returns the same name.
|
||||||
|
*/
|
||||||
|
final String checkNameLength(String name, int length, String msgKey) {
|
||||||
|
if (name.length() > length)
|
||||||
|
throw new UserException(_loc.get(msgKey, name, name.length(),
|
||||||
|
length));
|
||||||
|
return name;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -46,9 +46,11 @@ public class DerbyDictionary
|
||||||
stringLengthFunction = "LENGTH({0})";
|
stringLengthFunction = "LENGTH({0})";
|
||||||
substringFunctionName = "SUBSTR";
|
substringFunctionName = "SUBSTR";
|
||||||
|
|
||||||
maxConstraintNameLength = 18;
|
// Derby name length restriction has been relaxed
|
||||||
|
// http://www.archivum.info/derby-dev@db.apache.org/2004-12/msg00270.html
|
||||||
|
maxConstraintNameLength = 128;
|
||||||
maxIndexNameLength = 128;
|
maxIndexNameLength = 128;
|
||||||
maxColumnNameLength = 30;
|
maxColumnNameLength = 128;
|
||||||
maxTableNameLength = 128;
|
maxTableNameLength = 128;
|
||||||
|
|
||||||
useGetBytesForBlobs = true;
|
useGetBytesForBlobs = true;
|
||||||
|
|
|
@ -175,3 +175,14 @@ function-not-supported: The database dictionary in use ("{0}") \
|
||||||
batch-update-success-count: ExecuteBatch command returns update success count {0}
|
batch-update-success-count: ExecuteBatch command returns update success count {0}
|
||||||
connection-defaults: Initial connection autoCommit: {0}, holdability: {1}, \
|
connection-defaults: Initial connection autoCommit: {0}, holdability: {1}, \
|
||||||
TransactionIsolation: {2}
|
TransactionIsolation: {2}
|
||||||
|
long-table-name: Table name "{0}" is {1}-character long. The database allows \
|
||||||
|
maximum {2}-character for a table name.
|
||||||
|
long-column-name: Column name "{0}" is {1}-character long. The database allows \
|
||||||
|
maximum {2}-character for a column name.
|
||||||
|
long-index-name: Index name "{0}" is {1}-character long. The database allows \
|
||||||
|
maximum {2}-character for an index name.
|
||||||
|
long-constraint-name: Constraint name "{0}" is {1}-character long. The \
|
||||||
|
database allows maximum {2}-character for a constraint name.
|
||||||
|
long-seq-name: Sequence name "{0}" is {1}-character long. The database allows \
|
||||||
|
maximum {2}-character for a sequence name.
|
||||||
|
|
Loading…
Reference in New Issue