From e2be0960fd242d1aa36adac435a7f92569806a95 Mon Sep 17 00:00:00 2001 From: Gavin King Date: Tue, 14 Dec 2021 16:38:16 +0100 Subject: [PATCH] let's not use LONGVARCHAR to mean two different things --- .../dialect/SybaseAnywhereDialect.java | 6 +-- .../java/org/hibernate/dialect/Dialect.java | 33 +++++++++------ .../java/org/hibernate/dialect/H2Dialect.java | 6 +-- .../hibernate/dialect/PostgreSQLDialect.java | 7 ++-- .../java/org/hibernate/type/SqlTypes.java | 42 +++++++++++++++++++ 5 files changed, 71 insertions(+), 23 deletions(-) diff --git a/hibernate-community-dialects/src/main/java/org/hibernate/community/dialect/SybaseAnywhereDialect.java b/hibernate-community-dialects/src/main/java/org/hibernate/community/dialect/SybaseAnywhereDialect.java index 954d7c789a..bdd7763c34 100644 --- a/hibernate-community-dialects/src/main/java/org/hibernate/community/dialect/SybaseAnywhereDialect.java +++ b/hibernate-community-dialects/src/main/java/org/hibernate/community/dialect/SybaseAnywhereDialect.java @@ -66,11 +66,11 @@ public class SybaseAnywhereDialect extends SybaseDialect { return "timestamp with time zone"; //these types hold up to 2 GB - case LONGVARCHAR: + case LONG32VARCHAR: return "long varchar"; - case LONGNVARCHAR: + case LONG32NVARCHAR: return "long nvarchar"; - case LONGVARBINARY: + case LONG32VARBINARY: return "long binary"; case NCLOB: diff --git a/hibernate-core/src/main/java/org/hibernate/dialect/Dialect.java b/hibernate-core/src/main/java/org/hibernate/dialect/Dialect.java index be21f8dbc2..b224cba84a 100644 --- a/hibernate-core/src/main/java/org/hibernate/dialect/Dialect.java +++ b/hibernate-core/src/main/java/org/hibernate/dialect/Dialect.java @@ -264,19 +264,20 @@ public abstract class Dialect implements ConversionContext { * {@code Dialect} by calling {@link #registerColumnType(int,String)} * from the constructor. *

- * This method is aware of the notion of a maximum length for each of - * the types {@link Types#VARCHAR}, {@link Types#NVARCHAR}, and - * {@link Types#VARBINARY}, usually the limits defined by - * {@link #getMaxVarcharLength()}, {@link #getMaxNVarcharLength()}, - * and {@link #getMaxVarbinaryLength()}, and registers "long" types - * for lengths exceeding the limits. - *

* The "long" types {@link Types#LONGVARCHAR}, {@link Types#LONGNVARCHAR} * and {@link Types#LONGVARBINARY} are considered synonyms for their * non-{@code LONG} counterparts, with the only difference being that * a different default length is used: {@link org.hibernate.Length#LONG} * instead of {@link org.hibernate.Length#DEFAULT}. *

+ * This method is aware of the notion of a maximum length for each of + * the types {@link Types#VARCHAR}, {@link Types#NVARCHAR}, and + * {@link Types#VARBINARY}, usually the limits defined by + * {@link #getMaxVarcharLength()}, {@link #getMaxNVarcharLength()}, + * and {@link #getMaxVarbinaryLength()}, and registers "long32" types, + * that is, {@link org.hibernate.Length#LONG32} types, for lengths + * exceeding the limits. + *

* Any registrations made by this method may be overridden by calling * {@link #registerColumnType(int, String)} explicitly. Alternatively, * the registrations may be customized by overriding @@ -291,15 +292,21 @@ public abstract class Dialect implements ConversionContext { switch (typeCode) { case VARCHAR: registerColumnType( typeCode, maxVarcharLength, columnType(typeCode) ); - registerColumnType( typeCode, columnType(LONGVARCHAR) ); + // we look up the "long" type under the code LONG32VARCHAR + // which by default returns the CLOB type + registerColumnType( typeCode, columnType(LONG32VARCHAR) ); break; case NVARCHAR: registerColumnType( typeCode, maxNVarcharLength, columnType(typeCode) ); - registerColumnType( typeCode, columnType(LONGNVARCHAR) ); + // we look up the "long" type under the code LONG32NVARCHAR + // which by default returns the NCLOB type + registerColumnType( typeCode, columnType(LONG32NVARCHAR) ); break; case VARBINARY: registerColumnType( typeCode, maxVarBinaryLength, columnType(typeCode) ); - registerColumnType( typeCode, columnType(LONGVARBINARY) ); + // we look up the "long" type under the code LONG32VARBINARY + // which by default returns the BLOB type + registerColumnType( typeCode, columnType(LONG32VARBINARY) ); break; default: registerColumnType( typeCode, columnType(typeCode) ); @@ -429,11 +436,11 @@ public abstract class Dialect implements ConversionContext { return "blob"; // by default use the LOB mappings for the "long" types - case LONGVARCHAR: + case LONG32VARCHAR: return columnType(CLOB); - case LONGNVARCHAR: + case LONG32NVARCHAR: return columnType(NCLOB); - case LONGVARBINARY: + case LONG32VARBINARY: return columnType(BLOB); default: diff --git a/hibernate-core/src/main/java/org/hibernate/dialect/H2Dialect.java b/hibernate-core/src/main/java/org/hibernate/dialect/H2Dialect.java index 7e9243cb91..34942b1d1d 100644 --- a/hibernate-core/src/main/java/org/hibernate/dialect/H2Dialect.java +++ b/hibernate-core/src/main/java/org/hibernate/dialect/H2Dialect.java @@ -158,10 +158,10 @@ public class H2Dialect extends Dialect { } switch (jdbcTypeCode) { - case LONGVARCHAR: - case LONGNVARCHAR: + case LONG32VARCHAR: + case LONG32NVARCHAR: return "varchar"; - case LONGVARBINARY: + case LONG32VARBINARY: return "varbinary"; case ARRAY: return "array"; diff --git a/hibernate-core/src/main/java/org/hibernate/dialect/PostgreSQLDialect.java b/hibernate-core/src/main/java/org/hibernate/dialect/PostgreSQLDialect.java index 537d8fe8c4..8958f90a2b 100644 --- a/hibernate-core/src/main/java/org/hibernate/dialect/PostgreSQLDialect.java +++ b/hibernate-core/src/main/java/org/hibernate/dialect/PostgreSQLDialect.java @@ -68,7 +68,6 @@ import org.hibernate.sql.ast.spi.StandardSqlAstTranslatorFactory; import org.hibernate.sql.ast.tree.Statement; import org.hibernate.sql.exec.spi.JdbcOperation; import org.hibernate.type.JavaObjectType; -import org.hibernate.type.SqlTypes; import org.hibernate.type.StandardBasicTypes; import org.hibernate.type.descriptor.java.PrimitiveByteArrayJavaTypeDescriptor; import org.hibernate.type.descriptor.jdbc.BlobJdbcType; @@ -149,12 +148,12 @@ public class PostgreSQLDialect extends Dialect { // since there's no real difference between TEXT and VARCHAR, // except for the length limit, we can just use 'text' for the // "long" string types - case LONGVARCHAR: - case LONGNVARCHAR: + case LONG32VARCHAR: + case LONG32NVARCHAR: return "text"; // use bytea as the "long" binary type (that there is no // real VARBINARY type in Postgres, so we always use this) - case LONGVARBINARY: + case LONG32VARBINARY: return "bytea"; case INET: diff --git a/hibernate-core/src/main/java/org/hibernate/type/SqlTypes.java b/hibernate-core/src/main/java/org/hibernate/type/SqlTypes.java index 8f24a06751..1df8982ae9 100644 --- a/hibernate-core/src/main/java/org/hibernate/type/SqlTypes.java +++ b/hibernate-core/src/main/java/org/hibernate/type/SqlTypes.java @@ -129,11 +129,25 @@ public class SqlTypes { *

The constant in the Java programming language, sometimes referred * to as a type code, that identifies the generic SQL type * {@code LONGVARCHAR}. + *

+ * Interpreted by Hibernate as a {@link #VARCHAR}-like type large enough + * to hold a string of maximum length {@link org.hibernate.Length#LONG}. + * + * @see org.hibernate.Length#LONG * * @see Types#LONGVARCHAR */ public final static int LONGVARCHAR = Types.LONGVARCHAR; + /** + * A type code used internally by the Hibernate + * {@link org.hibernate.dialect.Dialect} to identify a + * {@link #VARCHAR}-like type large enough to hold any Java string. + * + * @see org.hibernate.Length#LONG32 + */ + public final static int LONG32VARCHAR = 4001; + /** *

The constant in the Java programming language, sometimes referred * to as a type code, that identifies the generic SQL type @@ -183,11 +197,25 @@ public class SqlTypes { *

The constant in the Java programming language, sometimes referred * to as a type code, that identifies the generic SQL type * {@code LONGVARBINARY}. + *

+ * Interpreted by Hibernate as a {@link #VARBINARY}-like type large enough + * to hold a byte array of maximum length {@link org.hibernate.Length#LONG}. + * + * @see org.hibernate.Length#LONG * * @see Types#LONGVARBINARY */ public final static int LONGVARBINARY = Types.LONGVARBINARY; + /** + * A type code used internally by the Hibernate + * {@link org.hibernate.dialect.Dialect} to identify a + * {@link #VARBINARY}-like type large enough to hold any Java byte array. + * + * @see org.hibernate.Length#LONG32 + */ + public final static int LONG32VARBINARY = 4003; + /** *

The constant in the Java programming language * that identifies the generic SQL value @@ -313,11 +341,25 @@ public class SqlTypes { /** * The constant in the Java programming language, sometimes referred to * as a type code, that identifies the generic SQL type {@code LONGNVARCHAR}. + *

+ * Interpreted by Hibernate as an {@link #NVARCHAR}-like type large enough + * to hold a string of maximum length {@link org.hibernate.Length#LONG}. + * + * @see org.hibernate.Length#LONG * * @see Types#LONGNVARCHAR */ public static final int LONGNVARCHAR = Types.LONGNVARCHAR; + /** + * A type code used internally by the Hibernate + * {@link org.hibernate.dialect.Dialect} to identify an + * {@link #NVARCHAR}-like type large enough to hold any Java string. + * + * @see org.hibernate.Length#LONG32 + */ + public final static int LONG32NVARCHAR = 4002; + /** * The constant in the Java programming language, sometimes referred to * as a type code, that identifies the generic SQL type {@code NCLOB}.