This is an automated email from the ASF dual-hosted git repository. asf-gitbox-commits pushed a commit to branch past-M2 in repository https://gitbox.apache.org/repos/asf/cayenne.git
commit c1ac549f05597c3e726bb0fc7d397348cbf46d67 Author: Andrus Adamchik <[email protected]> AuthorDate: Sun Jun 14 16:09:17 2026 -0400 CAY-2962 Allow unconstrained VARCHAR --- .../dbsync/merge/token/db/AddColumnToDb.java | 4 +- .../dbsync/merge/token/db/SetColumnTypeToDb.java | 4 +- .../java/org/apache/cayenne/dba/AutoAdapter.java | 4 +- .../java/org/apache/cayenne/dba/DbAdapter.java | 40 +++++- .../java/org/apache/cayenne/dba/JdbcAdapter.java | 141 ++++++++------------- .../java/org/apache/cayenne/dba/TypesMapping.java | 4 + .../org/apache/cayenne/dba/db2/DB2Adapter.java | 30 ++--- .../org/apache/cayenne/dba/derby/DerbyAdapter.java | 6 +- .../cayenne/dba/firebird/FirebirdAdapter.java | 6 +- .../cayenne/dba/frontbase/FrontBaseAdapter.java | 2 +- .../java/org/apache/cayenne/dba/h2/H2Adapter.java | 2 +- .../apache/cayenne/dba/hsqldb/HSQLDBAdapter.java | 2 +- .../apache/cayenne/dba/ingres/IngresAdapter.java | 18 +-- .../org/apache/cayenne/dba/mysql/MySQLAdapter.java | 4 +- .../apache/cayenne/dba/oracle/OracleAdapter.java | 4 +- .../cayenne/dba/postgres/PostgresAdapter.java | 16 +-- .../apache/cayenne/dba/sqlite/SQLiteAdapter.java | 2 +- .../cayenne/dba/sqlserver/SQLServerAdapter.java | 2 +- .../apache/cayenne/dba/sybase/SybaseAdapter.java | 2 +- 19 files changed, 143 insertions(+), 150 deletions(-) diff --git a/cayenne-dbsync/src/main/java/org/apache/cayenne/dbsync/merge/token/db/AddColumnToDb.java b/cayenne-dbsync/src/main/java/org/apache/cayenne/dbsync/merge/token/db/AddColumnToDb.java index 2f42b98d1..c5b6dd86f 100644 --- a/cayenne-dbsync/src/main/java/org/apache/cayenne/dbsync/merge/token/db/AddColumnToDb.java +++ b/cayenne-dbsync/src/main/java/org/apache/cayenne/dbsync/merge/token/db/AddColumnToDb.java @@ -54,8 +54,8 @@ public class AddColumnToDb extends AbstractToDbToken.EntityAndColumn { QuotingStrategy context = adapter.getQuotingStrategy(); appendPrefix(sqlBuffer, context); - sqlBuffer.append(JdbcAdapter.getType(adapter, getColumn())); - sqlBuffer.append(JdbcAdapter.sizeAndPrecision(adapter, getColumn())); + sqlBuffer.append(adapter.preferredNativeColumnType(getColumn()).nativeType()); + sqlBuffer.append(JdbcAdapter.sizeAndScale(adapter, getColumn())); return Collections.singletonList(sqlBuffer.toString()); } diff --git a/cayenne-dbsync/src/main/java/org/apache/cayenne/dbsync/merge/token/db/SetColumnTypeToDb.java b/cayenne-dbsync/src/main/java/org/apache/cayenne/dbsync/merge/token/db/SetColumnTypeToDb.java index a83da363b..4e5535406 100644 --- a/cayenne-dbsync/src/main/java/org/apache/cayenne/dbsync/merge/token/db/SetColumnTypeToDb.java +++ b/cayenne-dbsync/src/main/java/org/apache/cayenne/dbsync/merge/token/db/SetColumnTypeToDb.java @@ -62,8 +62,8 @@ public class SetColumnTypeToDb extends AbstractToDbToken.Entity { StringBuffer sqlBuffer = new StringBuffer(); appendPrefix(sqlBuffer, adapter.getQuotingStrategy()); - sqlBuffer.append(JdbcAdapter.getType(adapter, columnNew)); - sqlBuffer.append(JdbcAdapter.sizeAndPrecision(adapter, columnNew)); + sqlBuffer.append(adapter.preferredNativeColumnType(columnNew).nativeType()); + sqlBuffer.append(JdbcAdapter.sizeAndScale(adapter, columnNew)); return Collections.singletonList(sqlBuffer.toString()); } diff --git a/cayenne/src/main/java/org/apache/cayenne/dba/AutoAdapter.java b/cayenne/src/main/java/org/apache/cayenne/dba/AutoAdapter.java index ad2c21bd0..9bb3e7c1c 100644 --- a/cayenne/src/main/java/org/apache/cayenne/dba/AutoAdapter.java +++ b/cayenne/src/main/java/org/apache/cayenne/dba/AutoAdapter.java @@ -175,8 +175,8 @@ public class AutoAdapter implements DbAdapter { * @since 5.0 */ @Override - public int defaultCharLength() { - return getAdapter().defaultCharLength(); + public int defaultCharColumnLength() { + return getAdapter().defaultCharColumnLength(); } @Override diff --git a/cayenne/src/main/java/org/apache/cayenne/dba/DbAdapter.java b/cayenne/src/main/java/org/apache/cayenne/dba/DbAdapter.java index 3e32f9690..57fa0a289 100644 --- a/cayenne/src/main/java/org/apache/cayenne/dba/DbAdapter.java +++ b/cayenne/src/main/java/org/apache/cayenne/dba/DbAdapter.java @@ -18,6 +18,7 @@ ****************************************************************/ package org.apache.cayenne.dba; +import org.apache.cayenne.CayenneRuntimeException; import org.apache.cayenne.access.DataNode; import org.apache.cayenne.access.sqlbuilder.sqltree.SQLTreeProcessor; import org.apache.cayenne.access.translator.ParameterBinding; @@ -30,9 +31,9 @@ import org.apache.cayenne.map.DbEntity; import org.apache.cayenne.map.DbRelationship; import org.apache.cayenne.map.EntityResolver; import org.apache.cayenne.query.ProcedureQuery; -import org.apache.cayenne.query.Select; import org.apache.cayenne.query.Query; import org.apache.cayenne.query.SQLAction; +import org.apache.cayenne.query.Select; import java.sql.PreparedStatement; import java.util.Collection; @@ -125,21 +126,46 @@ public interface DbAdapter { /** * Returns true if supplied type can have a scale attribute as a part of column definition. * - * @param type sql type code - * @return <code>true</code> if a given type supports scale - * * @since 5.0 */ boolean typeSupportsScale(int type); /** * Returns the length to use for an unconstrained character column (a CHAR/VARCHAR-family column with no max - * length) when this database requires a length. Adapters whose database accepts a length-free character type - * instead declare an {@link NativeColumnType#asUnconstrained() unconstrained} native type. + * length) when this database requires a length. * * @since 5.0 */ - int defaultCharLength(); + int defaultCharColumnLength(); + + /** + * @since 5.0 + */ + default NativeColumnType preferredNativeColumnType(DbAttribute column) { + NativeColumnType[] variants = nativeColumnTypes(column.getType()); + if (variants == null || variants.length == 0) { + String entityName = column.getEntity() != null + ? column.getEntity().getFullyQualifiedName() + : "<null>"; + throw new CayenneRuntimeException("Undefined type for attribute '%s.%s': %s." + , entityName, column.getName(), column.getType()); + } + + if (column.isGenerated()) { + for (NativeColumnType variant : variants) { + if (variant.autoIncrement()) { + return variant; + } + } + } else if (TypesMapping.isCharacterWithMaxLengthSupport(column.getType()) && column.getMaxLength() <= 0) { + for (NativeColumnType variant : variants) { + if (variant.unconstrained()) { + return variant; + } + } + } + return variants[0]; + } /** * Returns a collection of SQL statements needed to drop a database table. diff --git a/cayenne/src/main/java/org/apache/cayenne/dba/JdbcAdapter.java b/cayenne/src/main/java/org/apache/cayenne/dba/JdbcAdapter.java index 1b05fea64..7ef8c8713 100644 --- a/cayenne/src/main/java/org/apache/cayenne/dba/JdbcAdapter.java +++ b/cayenne/src/main/java/org/apache/cayenne/dba/JdbcAdapter.java @@ -68,7 +68,7 @@ public class JdbcAdapter implements DbAdapter { private PkGenerator pkGenerator; protected QuotingStrategy quotingStrategy; - protected int defaultCharLength = 255; + protected int defaultCharColumnLength; protected Map<Integer, NativeColumnType[]> nativeColumnTypes; protected ExtendedTypeMap extendedTypes; @@ -92,6 +92,7 @@ public class JdbcAdapter implements DbAdapter { @Inject ValueObjectTypeRegistry valueObjectTypeRegistry) { // init defaults + this.defaultCharColumnLength = 255; this.setSupportsBatchUpdates(false); this.setSupportsUniqueConstraints(true); this.caseInsensitiveCollations = runtimeProperties.getBoolean(Constants.CI_PROPERTY, false); @@ -99,7 +100,7 @@ public class JdbcAdapter implements DbAdapter { this.quotingStrategy = createQuotingStrategy(); this.ejbqlTranslator = createEJBQLTranslator(); - this.nativeColumnTypes = indexBySqlType(createExternalTypes()); + this.nativeColumnTypes = indexBySqlType(createNativeTypes()); this.extendedTypes = new ExtendedTypeMap(); initExtendedTypes(defaultExtendedTypes, userExtendedTypes, extendedTypeFactories, valueObjectTypeRegistry); } @@ -126,42 +127,42 @@ public class JdbcAdapter implements DbAdapter { * * @since 5.0 */ - protected NativeColumnType[] createExternalTypes() { + protected NativeColumnType[] createNativeTypes() { return new NativeColumnType[]{ - NativeColumnType.of(Types.ARRAY, "ARRAY"), - NativeColumnType.of(Types.BIGINT, "BIGINT"), - NativeColumnType.of(Types.ROWID, "ROWID"), - NativeColumnType.of(Types.BINARY, "BINARY"), - NativeColumnType.of(Types.BIT, "BIT"), - NativeColumnType.of(Types.BLOB, "BLOB"), - NativeColumnType.of(Types.BOOLEAN, "BOOLEAN"), - NativeColumnType.of(Types.CHAR, "CHAR"), - NativeColumnType.of(Types.NCHAR, "NCHAR"), - NativeColumnType.of(Types.CLOB, "CLOB"), - NativeColumnType.of(Types.NCLOB, "NCLOB"), - NativeColumnType.of(Types.DATALINK, "DATALINK"), - NativeColumnType.of(Types.DATE, "DATE"), - NativeColumnType.of(Types.DECIMAL, "DECIMAL"), - NativeColumnType.of(Types.DOUBLE, "DOUBLE"), - NativeColumnType.of(Types.FLOAT, "FLOAT"), - NativeColumnType.of(Types.INTEGER, "INTEGER"), - NativeColumnType.of(Types.JAVA_OBJECT, "JAVA_OBJECT"), - NativeColumnType.of(Types.LONGVARBINARY, "LONGVARBINARY"), - NativeColumnType.of(Types.LONGVARCHAR, "LONGVARCHAR"), - NativeColumnType.of(Types.LONGNVARCHAR, "LONGNVARCHAR"), - NativeColumnType.of(Types.NUMERIC, "NUMERIC"), - NativeColumnType.of(Types.OTHER, "OTHER"), - NativeColumnType.of(Types.REAL, "REAL"), - NativeColumnType.of(Types.REF, "REF"), - NativeColumnType.of(Types.SMALLINT, "SMALLINT"), - NativeColumnType.of(Types.STRUCT, "STRUCT"), - NativeColumnType.of(Types.TIME, "TIME"), - NativeColumnType.of(Types.TIMESTAMP, "TIMESTAMP"), - NativeColumnType.of(Types.TINYINT, "TINYINT"), - NativeColumnType.of(Types.VARBINARY, "VARBINARY"), - NativeColumnType.of(Types.VARCHAR, "VARCHAR"), - NativeColumnType.of(Types.NVARCHAR, "NVARCHAR"), - NativeColumnType.of(Types.SQLXML, "SQLXML"), + NativeColumnType.of(Types.ARRAY, "ARRAY"), + NativeColumnType.of(Types.BIGINT, "BIGINT"), + NativeColumnType.of(Types.ROWID, "ROWID"), + NativeColumnType.of(Types.BINARY, "BINARY"), + NativeColumnType.of(Types.BIT, "BIT"), + NativeColumnType.of(Types.BLOB, "BLOB"), + NativeColumnType.of(Types.BOOLEAN, "BOOLEAN"), + NativeColumnType.of(Types.CHAR, "CHAR"), + NativeColumnType.of(Types.NCHAR, "NCHAR"), + NativeColumnType.of(Types.CLOB, "CLOB"), + NativeColumnType.of(Types.NCLOB, "NCLOB"), + NativeColumnType.of(Types.DATALINK, "DATALINK"), + NativeColumnType.of(Types.DATE, "DATE"), + NativeColumnType.of(Types.DECIMAL, "DECIMAL"), + NativeColumnType.of(Types.DOUBLE, "DOUBLE"), + NativeColumnType.of(Types.FLOAT, "FLOAT"), + NativeColumnType.of(Types.INTEGER, "INTEGER"), + NativeColumnType.of(Types.JAVA_OBJECT, "JAVA_OBJECT"), + NativeColumnType.of(Types.LONGVARBINARY, "LONGVARBINARY"), + NativeColumnType.of(Types.LONGVARCHAR, "LONGVARCHAR"), + NativeColumnType.of(Types.LONGNVARCHAR, "LONGNVARCHAR"), + NativeColumnType.of(Types.NUMERIC, "NUMERIC"), + NativeColumnType.of(Types.OTHER, "OTHER"), + NativeColumnType.of(Types.REAL, "REAL"), + NativeColumnType.of(Types.REF, "REF"), + NativeColumnType.of(Types.SMALLINT, "SMALLINT"), + NativeColumnType.of(Types.STRUCT, "STRUCT"), + NativeColumnType.of(Types.TIME, "TIME"), + NativeColumnType.of(Types.TIMESTAMP, "TIMESTAMP"), + NativeColumnType.of(Types.TINYINT, "TINYINT"), + NativeColumnType.of(Types.VARBINARY, "VARBINARY"), + NativeColumnType.of(Types.VARCHAR, "VARCHAR"), + NativeColumnType.of(Types.NVARCHAR, "NVARCHAR"), + NativeColumnType.of(Types.SQLXML, "SQLXML"), }; } @@ -284,7 +285,6 @@ public class JdbcAdapter implements DbAdapter { * * @param type sql type code * @return <code>true</code> if a given type supports scale - * * @since 5.0 */ @Override @@ -297,8 +297,8 @@ public class JdbcAdapter implements DbAdapter { * @since 5.0 */ @Override - public int defaultCharLength() { - return defaultCharLength; + public int defaultCharColumnLength() { + return defaultCharColumnLength; } /** @@ -383,52 +383,27 @@ public class JdbcAdapter implements DbAdapter { @Override public void createTableAppendColumn(StringBuffer sqlBuffer, DbAttribute column) { sqlBuffer.append(quotingStrategy.quotedName(column)); - sqlBuffer.append(' ').append(getType(this, column)); + sqlBuffer.append(' ').append(preferredNativeColumnType(column).nativeType()); - sqlBuffer.append(sizeAndPrecision(this, column)); + sqlBuffer.append(sizeAndScale(this, column)); sqlBuffer.append(column.isMandatory() ? " NOT NULL" : " NULL"); } /** - * Selects the native type variant to use for a column: the auto-increment variant for a generated column, - * the {@link NativeColumnType#unconstrained() unconstrained} variant for a character column with no max length, - * otherwise the primary variant. - * - * @since 5.0 + * @deprecated in favor of {@link #sizeAndScale(DbAdapter, DbAttribute)} */ - public static NativeColumnType selectNativeType(DbAdapter adapter, DbAttribute column) { - NativeColumnType[] variants = adapter.nativeColumnTypes(column.getType()); - if (variants == null || variants.length == 0) { - String entityName = column.getEntity() != null - ? column.getEntity().getFullyQualifiedName() - : "<null>"; - throw new CayenneRuntimeException("Undefined type for attribute '%s.%s': %s." - , entityName, column.getName(), column.getType()); - } - - if (column.isGenerated()) { - for (NativeColumnType variant : variants) { - if (variant.autoIncrement()) { - return variant; - } - } - } else if (isLengthBearingCharacter(column.getType()) && column.getMaxLength() <= 0) { - for (NativeColumnType variant : variants) { - if (variant.unconstrained()) { - return variant; - } - } - } - return variants[0]; + @Deprecated(since = "5.0", forRemoval = true) + public static String sizeAndPrecision(DbAdapter adapter, DbAttribute column) { + return sizeAndScale(adapter, column); } - public static String sizeAndPrecision(DbAdapter adapter, DbAttribute column) { + public static String sizeAndScale(DbAdapter adapter, DbAttribute column) { int type = column.getType(); // an unconstrained character column either uses a length-free native type, or falls back to the // adapter's default length for databases that require one - if (isLengthBearingCharacter(type) && column.getMaxLength() <= 0) { - return selectNativeType(adapter, column).unconstrained() ? "" : "(" + adapter.defaultCharLength() + ")"; + if (TypesMapping.isCharacterWithMaxLengthSupport(type) && column.getMaxLength() <= 0) { + return adapter.preferredNativeColumnType(column).unconstrained() ? "" : "(" + adapter.defaultCharColumnLength() + ")"; } if (!adapter.typeSupportsLength(type) && !adapter.typeSupportsScale(type)) { @@ -437,7 +412,7 @@ public class JdbcAdapter implements DbAdapter { int len = column.getMaxLength(); int scale = TypesMapping.isDateTime(column.getType()) - || TypesMapping.isDecimal(column.getType()) && column.getType() != Types.FLOAT + || TypesMapping.isDecimal(column.getType()) && column.getType() != Types.FLOAT ? column.getScale() : -1; if (len > 0) { @@ -451,13 +426,12 @@ public class JdbcAdapter implements DbAdapter { return ""; } + /** + * @deprecated in favor of {@link #preferredNativeColumnType(DbAttribute)} + */ + @Deprecated(since = "5.0", forRemoval = true) public static String getType(DbAdapter adapter, DbAttribute column) { - if (column.getType() == Types.OTHER) { - // TODO: warn that this is unsupported yet - return "OTHER"; - } - - return selectNativeType(adapter, column).nativeType(); + return adapter.preferredNativeColumnType(column).nativeType(); } /** @@ -513,7 +487,7 @@ public class JdbcAdapter implements DbAdapter { // sort joins in the order PK are set in target, to avoid errors on some DBs List<DbJoin> joins = rel.getJoins(); - if(rel.isToPK()) { + if (rel.isToPK()) { List<DbAttribute> pks = rel.getTargetEntity().getPrimaryKeys(); joins.sort(Comparator.comparingInt(join -> pks.indexOf(join.getTarget()))); } @@ -726,7 +700,4 @@ public class JdbcAdapter implements DbAdapter { return this; } - private static boolean isLengthBearingCharacter(int type) { - return type == Types.CHAR || type == Types.NCHAR || type == Types.VARCHAR || type == Types.NVARCHAR; - } } diff --git a/cayenne/src/main/java/org/apache/cayenne/dba/TypesMapping.java b/cayenne/src/main/java/org/apache/cayenne/dba/TypesMapping.java index 3f1b62f31..99639bab2 100644 --- a/cayenne/src/main/java/org/apache/cayenne/dba/TypesMapping.java +++ b/cayenne/src/main/java/org/apache/cayenne/dba/TypesMapping.java @@ -286,6 +286,10 @@ public class TypesMapping { || type == Types.CLOB || type == Types.NCLOB || type == Types.LONGVARCHAR || type == Types.LONGNVARCHAR; } + static boolean isCharacterWithMaxLengthSupport(int type) { + return type == CHAR || type == NCHAR || type == VARCHAR || type == NVARCHAR; + } + /** * Returns true if supplied type is a binary type. * diff --git a/cayenne/src/main/java/org/apache/cayenne/dba/db2/DB2Adapter.java b/cayenne/src/main/java/org/apache/cayenne/dba/db2/DB2Adapter.java index 7270d8b16..cb36c17cd 100644 --- a/cayenne/src/main/java/org/apache/cayenne/dba/db2/DB2Adapter.java +++ b/cayenne/src/main/java/org/apache/cayenne/dba/db2/DB2Adapter.java @@ -52,8 +52,6 @@ public class DB2Adapter extends JdbcAdapter { private static final String FOR_BIT_DATA_SUFFIX = " FOR BIT DATA"; - private static final String TRIM_FUNCTION = "RTRIM"; - public DB2Adapter(@Inject RuntimeProperties runtimeProperties, @Inject(Constants.DEFAULT_TYPES_LIST) List<ExtendedType> defaultExtendedTypes, @Inject(Constants.USER_TYPES_LIST) List<ExtendedType> userExtendedTypes, @@ -64,7 +62,7 @@ public class DB2Adapter extends JdbcAdapter { } @Override - protected NativeColumnType[] createExternalTypes() { + protected NativeColumnType[] createNativeTypes() { return new NativeColumnType[]{ NativeColumnType.of(Types.ARRAY, "ARRAY"), NativeColumnType.of(Types.BIGINT, "BIGINT"), @@ -120,7 +118,7 @@ public class DB2Adapter extends JdbcAdapter { */ @Override public void createTableAppendColumn(StringBuffer sqlBuffer, DbAttribute column) { - String type = getType(this, column); + String type = preferredNativeColumnType(column).nativeType(); sqlBuffer.append(quotingStrategy.quotedName(column)).append(' '); @@ -130,7 +128,7 @@ public class DB2Adapter extends JdbcAdapter { if(column.getType() == Types.NCHAR) { column.setMaxLength(maxLength / 2); } - String length = sizeAndPrecision(this, column); + String length = sizeAndScale(this, column); column.setMaxLength(maxLength); // assemble... @@ -210,22 +208,16 @@ public class DB2Adapter extends JdbcAdapter { */ @Override public int preferredBindingType(int jdbcType) { - switch (jdbcType) { - case Types.NCHAR: - return Types.CHAR; - case Types.NVARCHAR: - return Types.VARCHAR; - case Types.LONGNVARCHAR: - return Types.LONGVARCHAR; - case Types.NCLOB: - return Types.CLOB; - - default: - return jdbcType; - } + return switch (jdbcType) { + case Types.NCHAR -> Types.CHAR; + case Types.NVARCHAR -> Types.VARCHAR; + case Types.LONGNVARCHAR -> Types.LONGVARCHAR; + case Types.NCLOB -> Types.CLOB; + default -> jdbcType; + }; } - final class DB2BooleanType extends BooleanType { + static final class DB2BooleanType extends BooleanType { @Override public void setJdbcObject(PreparedStatement st, Boolean val, int pos, int type, int precision) throws Exception { if (val != null) { diff --git a/cayenne/src/main/java/org/apache/cayenne/dba/derby/DerbyAdapter.java b/cayenne/src/main/java/org/apache/cayenne/dba/derby/DerbyAdapter.java index f6713f4d1..ce17daf32 100644 --- a/cayenne/src/main/java/org/apache/cayenne/dba/derby/DerbyAdapter.java +++ b/cayenne/src/main/java/org/apache/cayenne/dba/derby/DerbyAdapter.java @@ -70,7 +70,7 @@ public class DerbyAdapter extends JdbcAdapter { } @Override - protected NativeColumnType[] createExternalTypes() { + protected NativeColumnType[] createNativeTypes() { return new NativeColumnType[]{ NativeColumnType.of(Types.ARRAY, "ARRAY"), NativeColumnType.of(Types.BIGINT, "BIGINT"), @@ -146,8 +146,8 @@ public class DerbyAdapter extends JdbcAdapter { */ @Override public void createTableAppendColumn(StringBuffer sqlBuffer, DbAttribute column) { - String type = getType(this, column); - String length = sizeAndPrecision(this, column); + String type = preferredNativeColumnType(column).nativeType(); + String length = sizeAndScale(this, column); sqlBuffer.append(quotingStrategy.quotedName(column)); sqlBuffer.append(' '); diff --git a/cayenne/src/main/java/org/apache/cayenne/dba/firebird/FirebirdAdapter.java b/cayenne/src/main/java/org/apache/cayenne/dba/firebird/FirebirdAdapter.java index 466d0112d..43044ddc1 100644 --- a/cayenne/src/main/java/org/apache/cayenne/dba/firebird/FirebirdAdapter.java +++ b/cayenne/src/main/java/org/apache/cayenne/dba/firebird/FirebirdAdapter.java @@ -62,7 +62,7 @@ public class FirebirdAdapter extends JdbcAdapter { } @Override - protected NativeColumnType[] createExternalTypes() { + protected NativeColumnType[] createNativeTypes() { return new NativeColumnType[]{ NativeColumnType.of(Types.ARRAY, "BLOB"), NativeColumnType.of(Types.BIGINT, "BIGINT"), @@ -110,8 +110,8 @@ public class FirebirdAdapter extends JdbcAdapter { } public void createTableAppendColumn(StringBuffer sqlBuffer, DbAttribute column) { - String type = getType(this, column); - String length = sizeAndPrecision(this, column); + String type = preferredNativeColumnType(column).nativeType(); + String length = sizeAndScale(this, column); sqlBuffer.append(quotingStrategy.quotedName(column)); sqlBuffer.append(' '); diff --git a/cayenne/src/main/java/org/apache/cayenne/dba/frontbase/FrontBaseAdapter.java b/cayenne/src/main/java/org/apache/cayenne/dba/frontbase/FrontBaseAdapter.java index b44daf5a8..ff841b9e7 100644 --- a/cayenne/src/main/java/org/apache/cayenne/dba/frontbase/FrontBaseAdapter.java +++ b/cayenne/src/main/java/org/apache/cayenne/dba/frontbase/FrontBaseAdapter.java @@ -68,7 +68,7 @@ public class FrontBaseAdapter extends JdbcAdapter { } @Override - protected NativeColumnType[] createExternalTypes() { + protected NativeColumnType[] createNativeTypes() { return new NativeColumnType[]{ NativeColumnType.of(Types.BIGINT, "LONGINT"), NativeColumnType.of(Types.BINARY, "BIT"), diff --git a/cayenne/src/main/java/org/apache/cayenne/dba/h2/H2Adapter.java b/cayenne/src/main/java/org/apache/cayenne/dba/h2/H2Adapter.java index 2f9de43b7..657a4dc31 100644 --- a/cayenne/src/main/java/org/apache/cayenne/dba/h2/H2Adapter.java +++ b/cayenne/src/main/java/org/apache/cayenne/dba/h2/H2Adapter.java @@ -56,7 +56,7 @@ public class H2Adapter extends JdbcAdapter { } @Override - protected NativeColumnType[] createExternalTypes() { + protected NativeColumnType[] createNativeTypes() { return new NativeColumnType[]{ NativeColumnType.of(Types.ARRAY, "ARRAY"), NativeColumnType.of(Types.BIGINT, "BIGINT"), diff --git a/cayenne/src/main/java/org/apache/cayenne/dba/hsqldb/HSQLDBAdapter.java b/cayenne/src/main/java/org/apache/cayenne/dba/hsqldb/HSQLDBAdapter.java index 0e031871c..f5ca77d79 100644 --- a/cayenne/src/main/java/org/apache/cayenne/dba/hsqldb/HSQLDBAdapter.java +++ b/cayenne/src/main/java/org/apache/cayenne/dba/hsqldb/HSQLDBAdapter.java @@ -68,7 +68,7 @@ public class HSQLDBAdapter extends JdbcAdapter { } @Override - protected NativeColumnType[] createExternalTypes() { + protected NativeColumnType[] createNativeTypes() { return new NativeColumnType[]{ NativeColumnType.of(Types.ARRAY, "ARRAY"), NativeColumnType.of(Types.BIGINT, "BIGINT"), diff --git a/cayenne/src/main/java/org/apache/cayenne/dba/ingres/IngresAdapter.java b/cayenne/src/main/java/org/apache/cayenne/dba/ingres/IngresAdapter.java index 3de597ef8..08cb738d4 100644 --- a/cayenne/src/main/java/org/apache/cayenne/dba/ingres/IngresAdapter.java +++ b/cayenne/src/main/java/org/apache/cayenne/dba/ingres/IngresAdapter.java @@ -56,7 +56,7 @@ public class IngresAdapter extends JdbcAdapter { } @Override - protected NativeColumnType[] createExternalTypes() { + protected NativeColumnType[] createNativeTypes() { return new NativeColumnType[]{ NativeColumnType.of(Types.ARRAY, "ARRAY"), NativeColumnType.of(Types.BIGINT, "BIGINT"), @@ -125,14 +125,14 @@ public class IngresAdapter extends JdbcAdapter { } @Override - public void createTableAppendColumn(StringBuffer buf, DbAttribute at) { - String type = getType(this, at); - buf.append(quotingStrategy.quotedName(at)).append(' ').append(type); + public void createTableAppendColumn(StringBuffer buf, DbAttribute column) { + String type = preferredNativeColumnType(column).nativeType(); + buf.append(quotingStrategy.quotedName(column)).append(' ').append(type); // append size and precision (if applicable) - if (typeSupportsLength(at.getType())) { - int len = at.getMaxLength(); - int scale = TypesMapping.isDecimal(at.getType()) ? at.getScale() : -1; + if (typeSupportsLength(column.getType())) { + int len = column.getMaxLength(); + int scale = TypesMapping.isDecimal(column.getType()) ? column.getScale() : -1; // sanity check if (scale > len) { @@ -150,12 +150,12 @@ public class IngresAdapter extends JdbcAdapter { } } - if (at.isGenerated()) { + if (column.isGenerated()) { buf.append(" GENERATED BY DEFAULT AS IDENTITY "); } // Ingres does not like "null" for non mandatory fields - if (at.isMandatory()) { + if (column.isMandatory()) { buf.append(" NOT NULL"); } } diff --git a/cayenne/src/main/java/org/apache/cayenne/dba/mysql/MySQLAdapter.java b/cayenne/src/main/java/org/apache/cayenne/dba/mysql/MySQLAdapter.java index 7a5edb83d..06a851668 100644 --- a/cayenne/src/main/java/org/apache/cayenne/dba/mysql/MySQLAdapter.java +++ b/cayenne/src/main/java/org/apache/cayenne/dba/mysql/MySQLAdapter.java @@ -83,7 +83,7 @@ public class MySQLAdapter extends JdbcAdapter { } @Override - protected NativeColumnType[] createExternalTypes() { + protected NativeColumnType[] createNativeTypes() { return new NativeColumnType[]{ NativeColumnType.of(Types.BIGINT, "BIGINT"), NativeColumnType.of(Types.BINARY, "BINARY"), @@ -337,7 +337,7 @@ public class MySQLAdapter extends JdbcAdapter { @Override public void createTableAppendColumn(StringBuffer sqlBuffer, DbAttribute column) { - String type = getType(this, column); + String type = preferredNativeColumnType(column).nativeType(); sqlBuffer.append(quotingStrategy.quotedName(column)); sqlBuffer.append(' ').append(type); diff --git a/cayenne/src/main/java/org/apache/cayenne/dba/oracle/OracleAdapter.java b/cayenne/src/main/java/org/apache/cayenne/dba/oracle/OracleAdapter.java index 4f7da00be..0f020db24 100644 --- a/cayenne/src/main/java/org/apache/cayenne/dba/oracle/OracleAdapter.java +++ b/cayenne/src/main/java/org/apache/cayenne/dba/oracle/OracleAdapter.java @@ -164,11 +164,11 @@ public class OracleAdapter extends JdbcAdapter { setSupportsBatchUpdates(true); // VARCHAR2 standard maximum, used for an unconstrained character column - this.defaultCharLength = 4000; + this.defaultCharColumnLength = 4000; } @Override - protected NativeColumnType[] createExternalTypes() { + protected NativeColumnType[] createNativeTypes() { return new NativeColumnType[]{ NativeColumnType.of(Types.BIGINT, "NUMBER"), NativeColumnType.of(Types.BINARY, "RAW"), diff --git a/cayenne/src/main/java/org/apache/cayenne/dba/postgres/PostgresAdapter.java b/cayenne/src/main/java/org/apache/cayenne/dba/postgres/PostgresAdapter.java index 90dc06fdb..905995265 100644 --- a/cayenne/src/main/java/org/apache/cayenne/dba/postgres/PostgresAdapter.java +++ b/cayenne/src/main/java/org/apache/cayenne/dba/postgres/PostgresAdapter.java @@ -69,7 +69,7 @@ public class PostgresAdapter extends JdbcAdapter { } @Override - protected NativeColumnType[] createExternalTypes() { + protected NativeColumnType[] createNativeTypes() { return new NativeColumnType[]{ NativeColumnType.of(Types.BIGINT, "bigint"), NativeColumnType.of(Types.BIGINT, "bigserial").asAutoIncrement(), @@ -235,19 +235,19 @@ public class PostgresAdapter extends JdbcAdapter { return buf.toString(); } - private void createAttribute(DbEntity ent, QuotingStrategy context, StringBuilder buf, DbAttribute at) { + private void createAttribute(DbEntity ent, QuotingStrategy context, StringBuilder buf, DbAttribute column) { // attribute may not be fully valid, do a simple check - if (at.getType() == TypesMapping.NOT_DEFINED) { + if (column.getType() == TypesMapping.NOT_DEFINED) { throw new CayenneRuntimeException("Undefined type for attribute '%s.%s'" - , ent.getFullyQualifiedName(), at.getName()); + , ent.getFullyQualifiedName(), column.getName()); } // getType / sizeAndPrecision pick the right variant (auto-increment serial, unconstrained "text", ...) - buf.append(context.quotedName(at)) + buf.append(context.quotedName(column)) .append(' ') - .append(getType(this, at)) - .append(sizeAndPrecision(this, at)) - .append(at.isMandatory() ? " NOT" : "") + .append(preferredNativeColumnType(column).nativeType()) + .append(sizeAndScale(this, column)) + .append(column.isMandatory() ? " NOT" : "") .append(" NULL"); } diff --git a/cayenne/src/main/java/org/apache/cayenne/dba/sqlite/SQLiteAdapter.java b/cayenne/src/main/java/org/apache/cayenne/dba/sqlite/SQLiteAdapter.java index 70b193d92..7a1013a0f 100644 --- a/cayenne/src/main/java/org/apache/cayenne/dba/sqlite/SQLiteAdapter.java +++ b/cayenne/src/main/java/org/apache/cayenne/dba/sqlite/SQLiteAdapter.java @@ -65,7 +65,7 @@ public class SQLiteAdapter extends JdbcAdapter { } @Override - protected NativeColumnType[] createExternalTypes() { + protected NativeColumnType[] createNativeTypes() { return new NativeColumnType[]{ NativeColumnType.of(Types.ARRAY, "ARRAY"), NativeColumnType.of(Types.BIGINT, "BIGINT"), diff --git a/cayenne/src/main/java/org/apache/cayenne/dba/sqlserver/SQLServerAdapter.java b/cayenne/src/main/java/org/apache/cayenne/dba/sqlserver/SQLServerAdapter.java index a93235110..682ecbc95 100644 --- a/cayenne/src/main/java/org/apache/cayenne/dba/sqlserver/SQLServerAdapter.java +++ b/cayenne/src/main/java/org/apache/cayenne/dba/sqlserver/SQLServerAdapter.java @@ -82,7 +82,7 @@ public class SQLServerAdapter extends JdbcAdapter { } @Override - protected NativeColumnType[] createExternalTypes() { + protected NativeColumnType[] createNativeTypes() { return new NativeColumnType[]{ NativeColumnType.of(Types.BIGINT, "bigint"), NativeColumnType.of(Types.BINARY, "binary"), diff --git a/cayenne/src/main/java/org/apache/cayenne/dba/sybase/SybaseAdapter.java b/cayenne/src/main/java/org/apache/cayenne/dba/sybase/SybaseAdapter.java index 29b49abb1..30d64e194 100644 --- a/cayenne/src/main/java/org/apache/cayenne/dba/sybase/SybaseAdapter.java +++ b/cayenne/src/main/java/org/apache/cayenne/dba/sybase/SybaseAdapter.java @@ -59,7 +59,7 @@ public class SybaseAdapter extends JdbcAdapter { } @Override - protected NativeColumnType[] createExternalTypes() { + protected NativeColumnType[] createNativeTypes() { return new NativeColumnType[]{ NativeColumnType.of(Types.BIGINT, "decimal(19,0)"), NativeColumnType.of(Types.BINARY, "binary"),
