Class DynamicModelDbSupport

java.lang.Object
io.jmix.dynmodel.impl.db.DynamicModelDbSupport
Direct Known Subclasses:
DefaultDynamicModelDbSupport, MySqlDynamicModelDbSupport, OracleDynamicModelDbSupport, SqlServerDynamicModelDbSupport

public abstract class DynamicModelDbSupport extends Object
  • 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

      protected static final String FALLBACK_IDENTIFIER
      See Also:
    • STANDARD_RESERVED_WORDS

      protected static final Set<String> STANDARD_RESERVED_WORDS
    • metadataTools

      protected MetadataTools metadataTools
    • reservedWords

      protected Set<String> reservedWords
    • maxIdentifierLength

      protected int maxIdentifierLength
  • Constructor Details

    • DynamicModelDbSupport

      public DynamicModelDbSupport()
  • Method Details

    • setMetadataTools

      public void setMetadataTools(MetadataTools metadataTools)
    • configureIdentifierRules

      public void configureIdentifierRules(Set<String> dbSpecificKeywords, int maxIdentifierLength)
    • normalizeGeneratedIdentifier

      public String normalizeGeneratedIdentifier(String logicalName)
    • 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 name
      constraintName - physical constraint name
      columnNames - participating column names
      Returns:
      DDL statement
    • getUniqueDuplicateCheckPredicate

      public String getUniqueDuplicateCheckPredicate(List<String> columnNames)
      Returns the WHERE predicate (without the WHERE keyword) 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

      public String getAddColumnSql(String tableName, String columnName, String columnType)
      Returns SQL that adds a single column to an existing table.
      Parameters:
      tableName - physical table name
      columnName - physical column name
      columnType - physical column type
      Returns:
      DDL statement
    • getAlterColumnTypeSql

      public String getAlterColumnTypeSql(String tableName, String columnName, String columnType)
      Returns SQL that changes the type/length of an existing column.
      Parameters:
      tableName - physical table name
      columnName - physical column name
      columnType - new physical column type
      Returns:
      DDL statement
    • getDropUniqueConstraintSql

      public String getDropUniqueConstraintSql(String tableName, String constraintName)
      Returns SQL that drops a unique constraint for the given table.
      Parameters:
      tableName - physical table name
      constraintName - 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 store
      tableName - physical table name
      constraintName - physical constraint name
      Returns:
      true if the constraint already exists
    • isDuplicateConstraintException

      public boolean isDuplicateConstraintException(Throwable exception, String constraintName)
      Checks whether the given exception means the named unique constraint already exists.
      Parameters:
      exception - database exception raised by DDL execution
      constraintName - physical constraint name
      Returns:
      true if the exception indicates an existing constraint with the same name
    • applyPaging

      public String applyPaging(String sql, int firstResult, int maxResults)
    • getLikeEscapeClause

      public String getLikeEscapeClause()
      Returns the ESCAPE clause (including the leading space) appended to a raw-SQL LIKE predicate 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

      public boolean isReservedWord(String identifier)
    • extractUniqueConstraintName

      public @Nullable String extractUniqueConstraintName(Throwable exception)
      Extracts a physical unique-constraint name from a database exception.
      Parameters:
      exception - database exception
      Returns:
      extracted unique-constraint name, or null
    • getSqlType

      public String getSqlType(MetaProperty property)
    • getSqlTypeByJavaType

      protected String getSqlTypeByJavaType(Class<?> javaType, MetaProperty property)
    • getUniqueConstraintViolationPattern

      protected @Nullable String getUniqueConstraintViolationPattern()
    • getDuplicateConstraintPattern

      protected @Nullable String getDuplicateConstraintPattern()
    • resolveConstraintName

      protected String resolveConstraintName(Matcher matcher)
    • toDbValue

      public @Nullable Object toDbValue(@Nullable Object value, MetaProperty property)
    • toPropertyValue

      public @Nullable Object toPropertyValue(@Nullable Object dbValue, MetaProperty property)
    • getReferenceJavaType

      protected Class<?> getReferenceJavaType(MetaProperty property)
    • getUuidSqlType

      protected abstract String getUuidSqlType()
    • canonicalizeIdentifier

      protected String canonicalizeIdentifier(String value)
    • toUnderscoreSeparated

      protected String toUnderscoreSeparated(String value)
    • shortenIdentifier

      protected String shortenIdentifier(String identifier)
    • appendTrailingUnderscore

      protected String appendTrailingUnderscore(String identifier)
    • hashIdentifier

      protected String hashIdentifier(String identifier)
    • getStringType

      protected String getStringType(int length)
    • getBytesType

      protected String getBytesType(int length)
    • getStringLobType

      protected String getStringLobType()
    • getBytesLobType

      protected String getBytesLobType()
    • getBooleanType

      protected String getBooleanType()
    • getDoubleType

      protected String getDoubleType()
    • getFloatType

      protected String getFloatType()
    • getLocalTimeType

      protected String getLocalTimeType()
    • getLocalDateTimeType

      protected String getLocalDateTimeType()
    • getOffsetTimeType

      protected String getOffsetTimeType()
    • getOffsetDateTimeType

      protected String getOffsetDateTimeType()
    • toDbUuid

      protected Object toDbUuid(UUID uuid)
    • toDbBoolean

      protected Object toDbBoolean(Boolean value)
    • toDbLocalTime

      protected Object toDbLocalTime(LocalTime value)
    • toDbOffsetTime

      protected Object toDbOffsetTime(OffsetTime value)
    • toDbOffsetDateTime

      protected Object toDbOffsetDateTime(OffsetDateTime value)
    • toUuid

      protected UUID toUuid(Object value)
    • isLob

      protected boolean isLob(MetaProperty property)
    • getLength

      protected int getLength(MetaProperty property, int defaultLength)
    • getEnumIdType

      protected Class<?> getEnumIdType(Class<?> enumClass)
    • toEnumValue

      protected @Nullable Object toEnumValue(Object dbValue, Class<?> enumClass)
    • toNumber

      protected Number toNumber(Object dbValue)
    • toBoolean

      protected Boolean toBoolean(Object dbValue)
    • toByteArray

      protected byte[] toByteArray(Object dbValue)
    • toLocalDate

      protected LocalDate toLocalDate(Object dbValue)
    • toLocalTime

      protected LocalTime toLocalTime(Object dbValue)
    • toLocalDateTime

      protected LocalDateTime toLocalDateTime(Object dbValue)
    • toOffsetTime

      protected OffsetTime toOffsetTime(Object dbValue)
    • toOffsetDateTime

      protected OffsetDateTime toOffsetDateTime(Object dbValue)