Class DbTypeHelper

java.lang.Object
org.ametys.plugins.forms.table.DbTypeHelper

public final class DbTypeHelper extends Object
Database abstraction helper.
  • Method Details

    • normalizeName

      public static String normalizeName(String dbType, String str)
      Normalize a name (table name, column name, and so on) according to the database type.
      Parameters:
      dbType - the database type.
      str - the string to normalize.
      Returns:
      the normalized string.
    • filterName

      public static String filterName(String dbType, String str)
      Filter a name (table name, column name, and so on) according to the database type so that it can be passed to DatabaseMetaData methods, such as getTables and getColumns.
      Parameters:
      dbType - the database type.
      str - the string to filter.
      Returns:
      the filtered string.
    • getVarcharType

      public static String getVarcharType(String dbType)
      Get the varchar type identifier corresponding to the database type.
      Parameters:
      dbType - the database type.
      Returns:
      the real varchar type identifier (to be included in CREATE statement).
    • getTextType

      public static String getTextType(String dbType)
      Get the text type identifier corresponding to the database type.
      Parameters:
      dbType - the database type.
      Returns:
      the real text type identifier (to be included in CREATE statement).
    • getBooleanType

      public static String getBooleanType(String dbType)
      Get the boolean type identifier corresponding to the database type.
      Parameters:
      dbType - the database type.
      Returns:
      the real boolean type identifier (to be included in CREATE statement).
    • getBinaryType

      public static String getBinaryType(String dbType)
      Get the binary type identifier corresponding to the database type.
      Parameters:
      dbType - the database type.
      Returns:
      the real binary type identifier (to be included in CREATE statement).
    • getIntegerType

      public static String getIntegerType(String dbType)
      Get the integer type identifier corresponding to the database type.
      Parameters:
      dbType - the database type.
      Returns:
      the integer type identifier (to be included in CREATE statement).
    • getDateTimeType

      public static String getDateTimeType(String dbType)
      Get the date and time type identifier corresponding to the database type.
      Parameters:
      dbType - the database type.
      Returns:
      the real date and time type identifier (to be included in CREATE statement).
    • getIdentityType

      public static String getIdentityType(String dbType)
      Get the "identity" type (int, integer, number, ...)
      Parameters:
      dbType - the database type.
      Returns:
      the "identity" type
    • getIdentityMarker

      public static String getIdentityMarker(String dbType)
      Get the "identity" string marker (AUTO_INCREMENT, SERIAL...)
      Parameters:
      dbType - the database type.
      Returns:
      the "identity" string marker.
    • getIdentityValue

      public static String getIdentityValue(String dbType)
      Get the "identity" value (NULL, sequence next val call, ...)
      Parameters:
      dbType - the database type.
      Returns:
      the "identity" value.
    • getCurrentDateFunction

      public static String getCurrentDateFunction(String dbType)
      Get the "now" function (NOW(), CURDATE, ...)
      Parameters:
      dbType - the database type.
      Returns:
      the "now" function.
    • insertIdentity

      public static boolean insertIdentity(String dbType)
      Test if we have to include the identity column in INSERTs.
      Parameters:
      dbType - the database type.
      Returns:
      true if the identity is to be included in INSERT statements, false otherwise.
    • setIdentity

      public static void setIdentity(PreparedStatement stmt, int index, String dbType) throws SQLException
      Set the identity value into the statement.
      Parameters:
      stmt - the prepared statement.
      index - the column index.
      dbType - the database type.
      Throws:
      SQLException - if a SQL exception occurs.
    • getRenameColumnStatement

      public static String getRenameColumnStatement(String tableName, org.ametys.plugins.forms.table.FormTableManager.DbColumn column, String newName, String dbType, SQLDatabaseTypeExtensionPoint sqlDatabaseTypeExtensionPoint)
      Get a SQL statement to rename a column.
      Parameters:
      tableName - the table name.
      column - the column to rename.
      newName - the new column name.
      dbType - the database type.
      sqlDatabaseTypeExtensionPoint - SQLDatabaseTypeExtensionPoint
      Returns:
      the SQL rename query.
    • getRenameColumnStatement

      public static String getRenameColumnStatement(String tableName, String columnName, String newName, String columnType, String dbType, SQLDatabaseTypeExtensionPoint sqlDatabaseTypeExtensionPoint)
      Get a SQL statement to rename a column.
      Parameters:
      tableName - the table name.
      columnName - the current column name.
      newName - the new column name.
      columnType - the full column type string (i.e TEXT, VARCHAR(255), INT(1), and so on).
      dbType - the database type.
      sqlDatabaseTypeExtensionPoint - SQLDatabaseTypeExtensionPoint
      Returns:
      the SQL rename query.