Class DbTypeHelper
java.lang.Object
org.ametys.plugins.forms.content.table.DbTypeHelper
Database abstraction helper.
-
Method Summary
Modifier and TypeMethodDescriptionstatic 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 toDatabaseMetaData
methods, such as getTables and getColumns.static String
getBinaryType
(String dbType) Get the binary type identifier corresponding to the database type.static String
getBooleanType
(String dbType) Get the boolean type identifier corresponding to the database type.static String
getCurrentDateFunction
(String dbType) Get the "now" function (NOW(), CURDATE, ...)static String
getDateTimeType
(String dbType) Get the date and time type identifier corresponding to the database type.static String
getIdentityMarker
(String dbType) Get the "identity" string marker (AUTO_INCREMENT, SERIAL...)static String
getIdentityType
(String dbType) Get the "identity" type (int, integer, number, ...)static String
getIdentityValue
(String dbType) Get the "identity" value (NULL, sequence next val call, ...)static String
getIntegerType
(String dbType) Get the integer type identifier corresponding to the database type.static String
getRenameColumnStatement
(String tableName, String columnName, String newName, String columnType, String dbType, SQLDatabaseTypeExtensionPoint sqlDatabaseTypeExtensionPoint) Get a SQL statement to rename a column.static String
getRenameColumnStatement
(String tableName, org.ametys.plugins.forms.content.table.FormTableManager.DbColumn column, String newName, String dbType, SQLDatabaseTypeExtensionPoint sqlDatabaseTypeExtensionPoint) Get a SQL statement to rename a column.static String
getTextType
(String dbType) Get the text type identifier corresponding to the database type.static String
getVarcharType
(String dbType) Get the varchar type identifier corresponding to the database type.static boolean
insertIdentity
(String dbType) Test if we have to include the identity column in INSERTs.static String
normalizeName
(String dbType, String str) Normalize a name (table name, column name, and so on) according to the database type.static void
setIdentity
(PreparedStatement stmt, int index, String dbType) Set the identity value into the statement.
-
Method Details
-
normalizeName
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
Filter a name (table name, column name, and so on) according to the database type so that it can be passed toDatabaseMetaData
methods, such as getTables and getColumns.- Parameters:
dbType
- the database type.str
- the string to filter.- Returns:
- the filtered string.
-
getVarcharType
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
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
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
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
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
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
Get the "identity" type (int, integer, number, ...)- Parameters:
dbType
- the database type.- Returns:
- the "identity" type
-
getIdentityMarker
Get the "identity" string marker (AUTO_INCREMENT, SERIAL...)- Parameters:
dbType
- the database type.- Returns:
- the "identity" string marker.
-
getIdentityValue
Get the "identity" value (NULL, sequence next val call, ...)- Parameters:
dbType
- the database type.- Returns:
- the "identity" value.
-
getCurrentDateFunction
Get the "now" function (NOW(), CURDATE, ...)- Parameters:
dbType
- the database type.- Returns:
- the "now" function.
-
insertIdentity
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.content.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.
-