Package io.jmix.dynmodel.impl.db
Class DynamicModelDbSupport
java.lang.Object
io.jmix.dynmodel.impl.db.DynamicModelDbSupport
- Direct Known Subclasses:
DefaultDynamicModelDbSupport,MySqlDynamicModelDbSupport,OracleDynamicModelDbSupport,SqlServerDynamicModelDbSupport
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected static final intprotected static final intprotected static final intprotected static final Stringprotected static final intprotected intprotected MetadataTools -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected StringappendTrailingUnderscore(String identifier) applyPaging(String sql, int firstResult, int maxResults) protected StringcanonicalizeIdentifier(String value) voidconfigureIdentifierRules(Set<String> dbSpecificKeywords, int maxIdentifierLength) @Nullable StringextractUniqueConstraintName(Throwable exception) Extracts a physical unique-constraint name from a database exception.getAddColumnSql(String tableName, String columnName, String columnType) Returns SQL that adds a single column to an existing table.getAlterColumnTypeSql(String tableName, String columnName, String columnType) Returns SQL that changes the type/length of an existing column.protected Stringprotected Stringprotected StringgetBytesType(int length) getCreateUniqueConstraintSql(String tableName, String constraintName, List<String> columnNames) Returns SQL that creates a unique constraint for the given table.protected StringgetDropUniqueConstraintSql(String tableName, String constraintName) Returns SQL that drops a unique constraint for the given table.protected @Nullable Stringprotected Class<?> getEnumIdType(Class<?> enumClass) protected Stringprotected intgetLength(MetaProperty property, int defaultLength) Returns theESCAPEclause (including the leading space) appended to a raw-SQLLIKEpredicate that escapes wildcards with a backslash.protected Stringprotected Stringprotected Stringprotected Stringprotected Class<?> getReferenceJavaType(MetaProperty property) getSqlType(MetaProperty property) protected StringgetSqlTypeByJavaType(Class<?> javaType, MetaProperty property) protected Stringprotected StringgetStringType(int length) protected @Nullable StringgetUniqueDuplicateCheckPredicate(List<String> columnNames) Returns the WHERE predicate (without theWHEREkeyword) that excludes rows from the duplicate-data pre-check run before adding a unique constraint, reflecting how this DBMS treats NULLs in unique keys.protected abstract Stringprotected StringhashIdentifier(String identifier) booleanisDuplicateConstraintException(Throwable exception, String constraintName) Checks whether the given exception means the named unique constraint already exists.protected booleanisLob(MetaProperty property) booleanisReservedWord(String identifier) normalizeGeneratedIdentifier(String logicalName) protected StringresolveConstraintName(Matcher matcher) voidsetMetadataTools(MetadataTools metadataTools) protected StringshortenIdentifier(String identifier) protected Booleanprotected byte[]toByteArray(Object dbValue) protected ObjecttoDbBoolean(Boolean value) protected ObjecttoDbLocalTime(LocalTime value) protected ObjecttoDbOffsetDateTime(OffsetDateTime value) protected ObjecttoDbOffsetTime(OffsetTime value) protected Object@Nullable ObjecttoDbValue(@Nullable Object value, MetaProperty property) protected @Nullable ObjecttoEnumValue(Object dbValue, Class<?> enumClass) protected LocalDatetoLocalDate(Object dbValue) protected LocalDateTimetoLocalDateTime(Object dbValue) protected LocalTimetoLocalTime(Object dbValue) protected Numberprotected OffsetDateTimetoOffsetDateTime(Object dbValue) protected OffsetTimetoOffsetTime(Object dbValue) @Nullable ObjecttoPropertyValue(@Nullable Object dbValue, MetaProperty property) protected StringtoUnderscoreSeparated(String value) protected UUIDbooleanuniqueConstraintExists(org.springframework.jdbc.core.JdbcTemplate jdbcTemplate, String tableName, String constraintName) Checks whether the named unique constraint already exists on the given table.
-
Field Details
-
DEFAULT_STRING_LENGTH
protected static final int DEFAULT_STRING_LENGTH- See Also:
-
DEFAULT_URI_LENGTH
protected static final int DEFAULT_URI_LENGTH- See Also:
-
DEFAULT_BYTES_LENGTH
protected static final int DEFAULT_BYTES_LENGTH- See Also:
-
IDENTIFIER_HASH_LENGTH
protected static final int IDENTIFIER_HASH_LENGTH- See Also:
-
FALLBACK_IDENTIFIER
- See Also:
-
STANDARD_RESERVED_WORDS
-
metadataTools
-
reservedWords
-
maxIdentifierLength
protected int maxIdentifierLength
-
-
Constructor Details
-
DynamicModelDbSupport
public DynamicModelDbSupport()
-
-
Method Details
-
setMetadataTools
-
configureIdentifierRules
-
normalizeGeneratedIdentifier
-
getCreateUniqueConstraintSql
public String getCreateUniqueConstraintSql(String tableName, String constraintName, List<String> columnNames) Returns SQL that creates a unique constraint for the given table.- Parameters:
tableName- physical table nameconstraintName- physical constraint namecolumnNames- participating column names- Returns:
- DDL statement
-
getUniqueDuplicateCheckPredicate
Returns the WHERE predicate (without theWHEREkeyword) that excludes rows from the duplicate-data pre-check run before adding a unique constraint, reflecting how this DBMS treats NULLs in unique keys. The default treats NULLs as distinct, so a row with a NULL in any constrained column never collides and is ignored. Returns an empty string when no rows should be excluded. -
getAddColumnSql
Returns SQL that adds a single column to an existing table.- Parameters:
tableName- physical table namecolumnName- physical column namecolumnType- physical column type- Returns:
- DDL statement
-
getAlterColumnTypeSql
Returns SQL that changes the type/length of an existing column.- Parameters:
tableName- physical table namecolumnName- physical column namecolumnType- new physical column type- Returns:
- DDL statement
-
getDropUniqueConstraintSql
Returns SQL that drops a unique constraint for the given table.- Parameters:
tableName- physical table nameconstraintName- physical constraint name- Returns:
- DDL statement
-
uniqueConstraintExists
public boolean uniqueConstraintExists(org.springframework.jdbc.core.JdbcTemplate jdbcTemplate, String tableName, String constraintName) Checks whether the named unique constraint already exists on the given table.- Parameters:
jdbcTemplate- JDBC template for the target storetableName- physical table nameconstraintName- physical constraint name- Returns:
trueif the constraint already exists
-
isDuplicateConstraintException
Checks whether the given exception means the named unique constraint already exists.- Parameters:
exception- database exception raised by DDL executionconstraintName- physical constraint name- Returns:
trueif the exception indicates an existing constraint with the same name
-
applyPaging
-
getLikeEscapeClause
Returns theESCAPEclause (including the leading space) appended to a raw-SQLLIKEpredicate that escapes wildcards with a backslash. The default emits a single backslash; MySQL/MariaDB interpret backslashes inside string literals and override this to emit a doubled backslash. -
isReservedWord
-
extractUniqueConstraintName
Extracts a physical unique-constraint name from a database exception.- Parameters:
exception- database exception- Returns:
- extracted unique-constraint name, or
null
-
getSqlType
-
getSqlTypeByJavaType
-
getUniqueConstraintViolationPattern
-
getDuplicateConstraintPattern
-
resolveConstraintName
-
toDbValue
-
toPropertyValue
-
getReferenceJavaType
-
getUuidSqlType
-
canonicalizeIdentifier
-
toUnderscoreSeparated
-
shortenIdentifier
-
appendTrailingUnderscore
-
hashIdentifier
-
getStringType
-
getBytesType
-
getStringLobType
-
getBytesLobType
-
getBooleanType
-
getDoubleType
-
getFloatType
-
getLocalTimeType
-
getLocalDateTimeType
-
getOffsetTimeType
-
getOffsetDateTimeType
-
toDbUuid
-
toDbBoolean
-
toDbLocalTime
-
toDbOffsetTime
-
toDbOffsetDateTime
-
toUuid
-
isLob
-
getLength
-
getEnumIdType
-
toEnumValue
-
toNumber
-
toBoolean
-
toByteArray
-
toLocalDate
-
toLocalTime
-
toLocalDateTime
-
toOffsetTime
-
toOffsetDateTime
-