public class DBAccessorImpl extends Object implements DBAccessor
DBAccessor.DBColumnInfo, DBAccessor.DbType| Modifier and Type | Field and Description |
|---|---|
static String |
NULL_CATALOG_MEANS_CURRENT |
static String |
PASSWORD |
static int |
SUPPORT_CONNECTOR_VERSION |
static String |
TRUE |
static String |
USER |
| Constructor and Description |
|---|
DBAccessorImpl(Configuration configuration) |
| Modifier and Type | Method and Description |
|---|---|
void |
addColumn(String tableName,
DBAccessor.DBColumnInfo columnInfo)
Adds a column to an existing table.
|
void |
addDefaultConstraint(String tableName,
DBAccessor.DBColumnInfo column)
Adds a default constraint to an existing column.
|
void |
addFKConstraint(String tableName,
String constraintName,
String[] keyColumns,
String referenceTableName,
String[] referenceColumns,
boolean ignoreFailure)
Add foreign key for a relation
|
void |
addFKConstraint(String tableName,
String constraintName,
String[] keyColumns,
String referenceTableName,
String[] referenceColumns,
boolean shouldCascadeOnDelete,
boolean ignoreFailure)
Add foreign key for a relation
|
void |
addFKConstraint(String tableName,
String constraintName,
String keyColumn,
String referenceTableName,
String referenceColumn,
boolean ignoreFailure)
Add foreign key for a relation
|
void |
addFKConstraint(String tableName,
String constraintName,
String keyColumn,
String referenceTableName,
String referenceColumn,
boolean shouldCascadeOnDelete,
boolean ignoreFailure) |
void |
addPKConstraint(String tableName,
String constraintName,
boolean ignoreErrors,
String... columnName) |
void |
addPKConstraint(String tableName,
String constraintName,
String... columnName) |
void |
addUniqueConstraint(String tableName,
String constraintName,
String... columnNames)
Add unique table constraint
|
void |
alterColumn(String tableName,
DBAccessor.DBColumnInfo columnInfo)
Alter column from existing table, only supports varchar extension
Use following sequence for more complex stuff: DBAccessor.addColumn(String, org.apache.ambari.server.orm.DBAccessor.DBColumnInfo)
DBAccessor.updateTable(String, String, Object, String)
DBAccessor.dropColumn(String, String)
DBAccessor.renameColumn(String, String, org.apache.ambari.server.orm.DBAccessor.DBColumnInfo) |
protected String |
buildQuery(String tableName,
String[] requestedColumnNames,
String[] conditionColumnNames,
String[] conditionValues)
Build a SELECT statement using the supplied table name, request columns and conditional column/value pairs.
|
void |
changeColumnType(String tableName,
String columnName,
Class fromType,
Class toType)
Alter column wrapper, which handle DB specific type conversion
|
void |
clearTable(String tableName)
Remove all rows from the table
|
void |
clearTableColumn(String tableName,
String columnName,
Object value)
Reset all rows with
value for columnName column |
void |
copyColumnToAnotherTable(String sourceTableName,
DBAccessor.DBColumnInfo sourceColumn,
String sourceIDFieldName1,
String sourceIDFieldName2,
String sourceIDFieldName3,
String targetTableName,
DBAccessor.DBColumnInfo targetColumn,
String targetIDFieldName1,
String targetIDFieldName2,
String targetIDFieldName3,
String sourceConditionFieldName,
String condition,
Object initialValue)
Copy column from
targetTable by matching
table keys sourceIDColumnName and targetIDColumnName
and condition sourceConditionFieldName = condition |
void |
createIndex(String indexName,
String tableName,
boolean isUnique,
String... columnNames)
Create new index
|
void |
createIndex(String indexName,
String tableName,
String... columnNames)
Create new index
|
void |
createTable(String tableName,
List<DBAccessor.DBColumnInfo> columnInfo,
String... primaryKeyColumns)
Create new table
|
void |
dropColumn(String tableName,
String columnName)
Drop a column from table
|
void |
dropFKConstraint(String tableName,
String constraintName)
Drops a FK constraint from a table.
|
void |
dropFKConstraint(String tableName,
String constraintName,
boolean ignoreFailure)
Drop a FK constraint from table
|
void |
dropPKConstraint(String tableName,
String defaultConstraintName)
Attempts to drop the discovered PRIMARY KEY constraint on the specified
table, defaulting to the specified default if not found.
|
void |
dropPKConstraint(String tableName,
String constraintName,
boolean cascade)
Drop a PK constraint from table
|
void |
dropPKConstraint(String tableName,
String constraintName,
boolean ignoreFailure,
boolean cascade)
Drop a PK constraint from table
|
void |
dropPKConstraint(String tableName,
String constraintName,
String columnName,
boolean cascade)
Drop a PK constraint from table
|
void |
dropSequence(String sequenceName)
Drop sequence
|
void |
dropTable(String tableName)
Drop table from schema
|
void |
dropUniqueConstraint(String tableName,
String constraintName)
Drop a unique constraint from table
|
void |
dropUniqueConstraint(String tableName,
String constraintName,
boolean ignoreFailure)
Drop a unique constraint from table
|
static String |
escapeParameter(Object value,
org.eclipse.persistence.platform.database.DatabasePlatform databasePlatform) |
void |
executePreparedQuery(String query,
boolean ignoreFailure,
Object... arguments)
Execute prepared update statements
|
void |
executePreparedQuery(String query,
Object... arguments)
Execute prepared statements
|
void |
executePreparedUpdate(String query,
boolean ignoreFailure,
Object... arguments)
Execute prepared statements which will not ignore failures
|
void |
executePreparedUpdate(String query,
Object... arguments)
Execute prepared update statements
|
void |
executeQuery(String query)
Execute ad-hoc query on DB.
|
void |
executeQuery(String query,
boolean ignoreFailure)
Execute query on DB
|
protected <T> T |
executeQuery(String tableName,
String[] requestedColumnNames,
String[] conditionColumnNames,
String[] conditionValues,
boolean ignoreFailure,
org.apache.ambari.server.orm.DBAccessorImpl.ResultGetter<T> resultGetter)
Executes a query returning data as specified by the
ResultGetter implementation. |
void |
executeQuery(String query,
String tableName,
String hasColumnName)
Conditional ad-hoc query on DB
|
void |
executeScript(String filePath)
Execute script with autocommit and error tolerance, like psql and sqlplus
do by default
|
int |
executeUpdate(String query) |
int |
executeUpdate(String query,
boolean ignoreErrors) |
String |
getCheckedForeignKey(String rawTableName,
String rawForeignKeyName) |
Class |
getColumnClass(String tableName,
String columnName)
Get type class of the column
|
DBAccessor.DBColumnInfo |
getColumnInfo(String tableName,
String columnName)
Obtain column metadata information by given table and column name.
|
int |
getColumnType(String tableName,
String columnName)
Gets the column's SQL type
|
Connection |
getConnection() |
protected DatabaseMetaData |
getDatabaseMetaData() |
String |
getDbSchema()
Get database schema name
|
DBAccessor.DbType |
getDbType()
Get type of database platform
|
List<String> |
getIndexesList(String tableName,
boolean unique)
Gets list of index names from database metadata
|
List<Integer> |
getIntColumnValues(String tableName,
String columnName,
String[] conditionColumnNames,
String[] values,
boolean ignoreFailure)
Execute select
columnName from tableName
where columnNames values = values |
Map<Long,String> |
getKeyToStringColumnMap(String tableName,
String keyColumnName,
String valueColumnName,
String[] conditionColumnNames,
String[] values,
boolean ignoreFailure)
Execute select
keyColumnName, valueColumnName from tableName
where columnNames values = values |
Connection |
getNewConnection() |
org.eclipse.persistence.sessions.DatabaseSession |
getNewDatabaseSession()
Get a new DB session
|
String |
getPrimaryKeyConstraintName(String tableName)
Queries the database to determine the name of the primary key constraint on
the specified table.
|
boolean |
insertRow(String tableName,
String[] columnNames,
String[] values,
boolean ignoreFailure)
Insert row into table
|
boolean |
insertRowIfMissing(String tableName,
String[] columnNames,
String[] values,
boolean ignoreFailure)
Conditionally insert row into table if it does not already exist
|
boolean |
isColumnNullable(String tableName,
String columnName)
Check if column could be nullable
|
protected DbmsHelper |
loadHelper(org.eclipse.persistence.platform.database.DatabasePlatform databasePlatform) |
void |
moveColumnToAnotherTable(String sourceTableName,
DBAccessor.DBColumnInfo sourceColumn,
String sourceIDFieldName,
String targetTableName,
DBAccessor.DBColumnInfo targetColumn,
String targetIDFieldName,
Object initialValue)
Move column data from
sourceTableName to targetTableName using sourceIDFieldName and
targetIDFieldName keys to match right rows |
String |
quoteObjectName(String name)
Wraps object name with dbms-specific quotes
|
void |
renameColumn(String tableName,
String oldColumnName,
DBAccessor.DBColumnInfo columnInfo)
Rename existing column
|
void |
setColumnNullable(String tableName,
DBAccessor.DBColumnInfo columnInfo,
boolean nullable)
Sets the specified column to either allow or prohibit
NULL. |
void |
setColumnNullable(String tableName,
String columnName,
boolean nullable) |
boolean |
tableExists(String tableName)
Verify if table exists by looking at metadata.
|
boolean |
tableHasColumn(String tableName,
String... columnName)
Verify if table already has a column defined.
|
boolean |
tableHasColumn(String tableName,
String columnName)
Verify if table already has a column defined.
|
boolean |
tableHasConstraint(String tableName,
String constraintName) |
boolean |
tableHasData(String tableName)
Verify if table has any data
|
boolean |
tableHasForeignKey(String tableName,
String fkName)
Verify if table has a FK constraint.
|
boolean |
tableHasForeignKey(String tableName,
String referenceTableName,
String[] keyColumns,
String[] referenceColumns)
Verify if table already has a FK constraint.
|
boolean |
tableHasForeignKey(String tableName,
String refTableName,
String columnName,
String refColumnName)
Verify if table already has a FK constraint.
|
boolean |
tableHasIndex(String tableName,
boolean unique,
String indexName)
Check if index is already in scheme
|
boolean |
tableHasPrimaryKey(String tableName,
String columnName)
Table has primary key
|
void |
truncateTable(String tableName)
Delete all table data
|
void |
updateTable(String tableName,
DBAccessor.DBColumnInfo columnNameFrom,
DBAccessor.DBColumnInfo columnNameTo)
Simple update operation on table
|
int |
updateTable(String tableName,
String columnName,
Object value,
String whereClause)
Simple update operation on table
|
void |
updateUniqueConstraint(String tableName,
String constraintName,
String... columnNames)
Add unique table constraint
|
public static final String USER
public static final String PASSWORD
public static final String NULL_CATALOG_MEANS_CURRENT
public static final String TRUE
public static final int SUPPORT_CONNECTOR_VERSION
@Inject public DBAccessorImpl(Configuration configuration)
protected DbmsHelper loadHelper(org.eclipse.persistence.platform.database.DatabasePlatform databasePlatform)
public Connection getConnection()
getConnection in interface DBAccessorpublic Connection getNewConnection()
getNewConnection in interface DBAccessorpublic String quoteObjectName(String name)
DBAccessorquoteObjectName in interface DBAccessorname - object name without quotespublic void createTable(String tableName, List<DBAccessor.DBColumnInfo> columnInfo, String... primaryKeyColumns) throws SQLException
DBAccessorcreateTable in interface DBAccessorSQLExceptionprotected DatabaseMetaData getDatabaseMetaData() throws SQLException
SQLExceptionpublic boolean tableExists(String tableName) throws SQLException
DBAccessortableExists in interface DBAccessortableName - name of the tableSQLExceptionpublic DBAccessor.DbType getDbType()
DBAccessorgetDbType in interface DBAccessorpublic String getDbSchema()
DBAccessorgetDbSchema in interface DBAccessorpublic boolean tableHasData(String tableName) throws SQLException
DBAccessortableHasData in interface DBAccessorSQLExceptionpublic boolean tableHasColumn(String tableName, String columnName) throws SQLException
DBAccessortableHasColumn in interface DBAccessorSQLExceptionpublic boolean tableHasColumn(String tableName, String... columnName) throws SQLException
DBAccessortableHasColumn in interface DBAccessortableName - name of the tablecolumnName - name of the column to checkSQLExceptionpublic boolean tableHasForeignKey(String tableName, String fkName) throws SQLException
DBAccessortableHasForeignKey in interface DBAccessorSQLExceptionpublic String getCheckedForeignKey(String rawTableName, String rawForeignKeyName) throws SQLException
SQLExceptionpublic boolean tableHasForeignKey(String tableName, String refTableName, String columnName, String refColumnName) throws SQLException
DBAccessortableHasForeignKey in interface DBAccessorSQLExceptionpublic boolean tableHasForeignKey(String tableName, String referenceTableName, String[] keyColumns, String[] referenceColumns) throws SQLException
DBAccessortableHasForeignKey in interface DBAccessorSQLExceptionpublic boolean tableHasIndex(String tableName, boolean unique, String indexName) throws SQLException
DBAccessortableHasIndex in interface DBAccessortableName - the name of the table (not null).unique - list only unique indexes (not null).indexName - name of the index to checkSQLExceptionpublic void createIndex(String indexName, String tableName, String... columnNames) throws SQLException
DBAccessorcreateIndex in interface DBAccessorSQLExceptionpublic void createIndex(String indexName, String tableName, boolean isUnique, String... columnNames) throws SQLException
DBAccessorcreateIndex in interface DBAccessorindexName - The name of the index to be createdtableName - The database table the index to be created onisUnique - Specifies whether unique index is to be created.columnNames - The columns included into the indexSQLException - Exception in case the index creation fails.public void addFKConstraint(String tableName, String constraintName, String keyColumn, String referenceTableName, String referenceColumn, boolean ignoreFailure) throws SQLException
DBAccessoraddFKConstraint in interface DBAccessorSQLExceptionpublic void addFKConstraint(String tableName, String constraintName, String keyColumn, String referenceTableName, String referenceColumn, boolean shouldCascadeOnDelete, boolean ignoreFailure) throws SQLException
addFKConstraint in interface DBAccessorSQLExceptionpublic void addFKConstraint(String tableName, String constraintName, String[] keyColumns, String referenceTableName, String[] referenceColumns, boolean ignoreFailure) throws SQLException
DBAccessoraddFKConstraint in interface DBAccessorSQLExceptionpublic void addFKConstraint(String tableName, String constraintName, String[] keyColumns, String referenceTableName, String[] referenceColumns, boolean shouldCascadeOnDelete, boolean ignoreFailure) throws SQLException
DBAccessoraddFKConstraint in interface DBAccessorSQLExceptionpublic boolean tableHasConstraint(String tableName, String constraintName) throws SQLException
SQLExceptionpublic void addUniqueConstraint(String tableName, String constraintName, String... columnNames) throws SQLException
DBAccessoraddUniqueConstraint in interface DBAccessortableName - name of the tableconstraintName - name of the constraintcolumnNames - list of columnsSQLExceptionpublic void updateUniqueConstraint(String tableName, String constraintName, String... columnNames) throws SQLException
DBAccessorupdateUniqueConstraint in interface DBAccessortableName - name of the tableconstraintName - name of the constraintcolumnNames - list of columnsSQLExceptionpublic void addPKConstraint(String tableName, String constraintName, boolean ignoreErrors, String... columnName) throws SQLException
addPKConstraint in interface DBAccessortableName - name of the tableconstraintName - name of the constraintignoreErrors - true to ignore database errorscolumnName - name of the columnSQLExceptionpublic void addPKConstraint(String tableName, String constraintName, String... columnName) throws SQLException
addPKConstraint in interface DBAccessortableName - name of the tableconstraintName - name of the constraintcolumnName - name of the columnSQLExceptionpublic void renameColumn(String tableName, String oldColumnName, DBAccessor.DBColumnInfo columnInfo) throws SQLException
DBAccessorrenameColumn in interface DBAccessorSQLExceptionpublic void addColumn(String tableName, DBAccessor.DBColumnInfo columnInfo) throws SQLException
DBAccessor.DBColumnInfo.isNullable and DBAccessor.DBColumnInfo.getDefaultValue()
methods and create a new column that has a DEFAULT constraint.
Oracle is, of course, the exception here since their syntax doesn't conform
to widely accepted SQL standards. Because they switch the order of the
NULL constraint and the DEFAULT constraint, we need to
create the table in a non-atomic fashion. This is because the EclipseLink
FieldDeclaration class hard codes the order of the constraints. In
the case of Oracle, we alter the nullability of the table after its
creation.
No work is performed if the column already exists.addColumn in interface DBAccessorSQLExceptionpublic void alterColumn(String tableName, DBAccessor.DBColumnInfo columnInfo) throws SQLException
DBAccessorDBAccessor.addColumn(String, org.apache.ambari.server.orm.DBAccessor.DBColumnInfo)
DBAccessor.updateTable(String, String, Object, String)
DBAccessor.dropColumn(String, String)
DBAccessor.renameColumn(String, String, org.apache.ambari.server.orm.DBAccessor.DBColumnInfo)alterColumn in interface DBAccessorSQLExceptionpublic void updateTable(String tableName, DBAccessor.DBColumnInfo columnNameFrom, DBAccessor.DBColumnInfo columnNameTo) throws SQLException
DBAccessorupdateTable in interface DBAccessorSQLExceptionpublic boolean insertRow(String tableName, String[] columnNames, String[] values, boolean ignoreFailure) throws SQLException
DBAccessorinsertRow in interface DBAccessorSQLExceptionpublic boolean insertRowIfMissing(String tableName, String[] columnNames, String[] values, boolean ignoreFailure) throws SQLException
DBAccessorinsertRowIfMissing in interface DBAccessorSQLExceptionpublic int updateTable(String tableName, String columnName, Object value, String whereClause) throws SQLException
DBAccessorupdateTable in interface DBAccessorSQLExceptionpublic int executeUpdate(String query) throws SQLException
executeUpdate in interface DBAccessorquery - update queryjava.sql.StatementSQLExceptionpublic int executeUpdate(String query, boolean ignoreErrors) throws SQLException
executeUpdate in interface DBAccessorquery - update queryignoreErrors - true to ignore errorsjava.sql.StatementSQLExceptionpublic void executeQuery(String query, String tableName, String hasColumnName) throws SQLException
DBAccessorexecuteQuery in interface DBAccessorSQLExceptionpublic void executeQuery(String query) throws SQLException
DBAccessorexecuteQuery in interface DBAccessorSQLExceptionpublic void executeQuery(String query, boolean ignoreFailure) throws SQLException
DBAccessorexecuteQuery in interface DBAccessorSQLExceptionpublic void executePreparedQuery(String query, Object... arguments) throws SQLException
executePreparedQuery in interface DBAccessorquery - query to executearguments - list of arguments for prepared statementSQLExceptionpublic void executePreparedQuery(String query, boolean ignoreFailure, Object... arguments) throws SQLException
executePreparedQuery in interface DBAccessorquery - query to executeignoreFailure - determines if exceptions during query execution should be ignoredarguments - list of arguments for prepared statementSQLExceptionpublic void executePreparedUpdate(String query, Object... arguments) throws SQLException
executePreparedUpdate in interface DBAccessorquery - query to executearguments - list of arguments for prepared statementSQLExceptionpublic void executePreparedUpdate(String query, boolean ignoreFailure, Object... arguments) throws SQLException
executePreparedUpdate in interface DBAccessorSQLExceptionpublic void dropTable(String tableName) throws SQLException
DBAccessordropTable in interface DBAccessorSQLExceptionpublic void truncateTable(String tableName) throws SQLException
DBAccessortruncateTable in interface DBAccessorSQLExceptionpublic void dropColumn(String tableName, String columnName) throws SQLException
DBAccessordropColumn in interface DBAccessorSQLExceptionpublic void dropSequence(String sequenceName) throws SQLException
DBAccessordropSequence in interface DBAccessorSQLExceptionpublic void dropFKConstraint(String tableName, String constraintName) throws SQLException
DBAccessorConfiguration.DatabaseType.MYSQL, this will also ensure that any associated
indexes are also dropped.dropFKConstraint in interface DBAccessortableName - name of the tableconstraintName - name of the constraintSQLExceptionpublic void dropFKConstraint(String tableName, String constraintName, boolean ignoreFailure) throws SQLException
dropFKConstraint in interface DBAccessortableName - name of the tableconstraintName - name of the constraintSQLExceptionpublic void dropUniqueConstraint(String tableName, String constraintName, boolean ignoreFailure) throws SQLException
DBAccessordropUniqueConstraint in interface DBAccessortableName - name of the tableconstraintName - name of the constraintSQLExceptionpublic void dropUniqueConstraint(String tableName, String constraintName) throws SQLException
DBAccessordropUniqueConstraint in interface DBAccessortableName - name of the tableconstraintName - name of the constraintSQLExceptionpublic void dropPKConstraint(String tableName, String constraintName, String columnName, boolean cascade) throws SQLException
DBAccessordropPKConstraint in interface DBAccessortableName - name of the tableconstraintName - name of the constraintcolumnName - name of the column from the pk constraintcascade - cascade deleteSQLExceptionpublic void dropPKConstraint(String tableName, String constraintName, boolean ignoreFailure, boolean cascade) throws SQLException
DBAccessordropPKConstraint in interface DBAccessorconstraintName - name of the constraintcascade - cascade deleteSQLExceptionpublic void dropPKConstraint(String tableName, String constraintName, boolean cascade) throws SQLException
DBAccessordropPKConstraint in interface DBAccessortableName - name of the tableconstraintName - name of the constraintcascade - cascade deleteSQLExceptionpublic void executeScript(String filePath) throws SQLException, IOException
executeScript in interface DBAccessorSQLExceptionIOExceptionpublic org.eclipse.persistence.sessions.DatabaseSession getNewDatabaseSession()
DBAccessorgetNewDatabaseSession in interface DBAccessorpublic boolean tableHasPrimaryKey(String tableName, String columnName) throws SQLException
DBAccessortableHasPrimaryKey in interface DBAccessortableName - name of the tablecolumnName - name of the constraint, could be nullSQLExceptionpublic int getColumnType(String tableName, String columnName) throws SQLException
DBAccessorgetColumnType in interface DBAccessortableName - the name of the table (not null).columnName - the name of the column to retrieve type for (not null).SQLExceptionpublic Class getColumnClass(String tableName, String columnName) throws SQLException, ClassNotFoundException
DBAccessorgetColumnClass in interface DBAccessortableName - name of the tablecolumnName - name of the columnSQLExceptionClassNotFoundExceptionpublic boolean isColumnNullable(String tableName, String columnName) throws SQLException
DBAccessorisColumnNullable in interface DBAccessortableName - name of the tablecolumnName - name of the columnSQLExceptionpublic void setColumnNullable(String tableName, DBAccessor.DBColumnInfo columnInfo, boolean nullable) throws SQLException
DBAccessorNULL.setColumnNullable in interface DBAccessortableName - the name of the table (not null).columnInfo - the column object to get name and type of column (not null).nullable - true to indicate that the column allows NULL
values, false otherwise.SQLExceptionpublic void setColumnNullable(String tableName, String columnName, boolean nullable) throws SQLException
setColumnNullable in interface DBAccessorSQLExceptionpublic void changeColumnType(String tableName, String columnName, Class fromType, Class toType) throws SQLException
DBAccessorchangeColumnType in interface DBAccessortableName - name of the tablecolumnName - name of the columnfromType - previous typetoType - new desired typeSQLExceptionpublic DBAccessor.DBColumnInfo getColumnInfo(String tableName, String columnName)
getColumnInfo in interface DBAccessortableName - Name of the tablecolumnName - Name of the columnSQLExceptionpublic List<String> getIndexesList(String tableName, boolean unique) throws SQLException
DBAccessorgetIndexesList in interface DBAccessortableName - the name of the table (not null).unique - list only unique indexes (not null).SQLExceptionpublic String getPrimaryKeyConstraintName(String tableName) throws SQLException
Configuration.DatabaseType.POSTGRES, Configuration.DatabaseType.ORACLE and
Configuration.DatabaseType.SQL_SERVER. Configuration.DatabaseType.MYSQL does not need
this since PKs can be dropped without referencing their name.getPrimaryKeyConstraintName in interface DBAccessortableName - the name of the table to lookup the PK constraint.null if none.SQLExceptionpublic void dropPKConstraint(String tableName, String defaultConstraintName) throws SQLException
dropPKConstraint in interface DBAccessortableName - the table to drop the PK from (not null).defaultConstraintName - the default name of the PK constraint if none is found.SQLExceptionpublic void addDefaultConstraint(String tableName, DBAccessor.DBColumnInfo column) throws SQLException
addDefaultConstraint in interface DBAccessortableName - the table where the column is defined (not null).column - the column information which contains the default value (not
null).SQLExceptionpublic static String escapeParameter(Object value, org.eclipse.persistence.platform.database.DatabasePlatform databasePlatform)
public void copyColumnToAnotherTable(String sourceTableName, DBAccessor.DBColumnInfo sourceColumn, String sourceIDFieldName1, String sourceIDFieldName2, String sourceIDFieldName3, String targetTableName, DBAccessor.DBColumnInfo targetColumn, String targetIDFieldName1, String targetIDFieldName2, String targetIDFieldName3, String sourceConditionFieldName, String condition, Object initialValue) throws SQLException
targetTable by matching
table keys sourceIDColumnName and targetIDColumnName
and condition sourceConditionFieldName = conditioncopyColumnToAnotherTable in interface DBAccessorsourceTableName - the source table namesourceColumn - the source column namesourceIDFieldName1 - the source id key filed name matched with targetIDFieldName1sourceIDFieldName2 - the source id key filed name matched with targetIDFieldName2sourceIDFieldName3 - the source id key filed name matched with targetIDFieldName3targetTableName - the target table nametargetColumn - the target column nametargetIDFieldName1 - the target id key name matched with sourceIDFieldName1targetIDFieldName2 - the target id key name matched with sourceIDFieldName2targetIDFieldName3 - the target id key name matched with sourceIDFieldName3sourceConditionFieldName - source key column name which should match conditioncondition - value which should match sourceConditionFieldNameinitialValue - initial value for null-contained cellsSQLExceptionpublic List<Integer> getIntColumnValues(String tableName, String columnName, String[] conditionColumnNames, String[] values, boolean ignoreFailure) throws SQLException
columnName from tableName
where columnNames values = valuesgetIntColumnValues in interface DBAccessortableName - the table namecolumnName - the name of the column with the data to selectconditionColumnNames - an array of column names to use in the where clausevalues - an array of value to pair with the column names in conditionColumnNamesignoreFailure - true to ignore failures executing the query; false otherwise (errors building the query will be thrown, however)SQLExceptionpublic Map<Long,String> getKeyToStringColumnMap(String tableName, String keyColumnName, String valueColumnName, String[] conditionColumnNames, String[] values, boolean ignoreFailure) throws SQLException
keyColumnName, valueColumnName from tableName
where columnNames values = valuesgetKeyToStringColumnMap in interface DBAccessortableName - the table namekeyColumnName - the name of the column with the key data to selectvalueColumnName - the name of the column with the value data to selectconditionColumnNames - an array of column names to use in the where clausevalues - an array of value to pair with the column names in conditionColumnNamesignoreFailure - true to ignore failures executing the query; false otherwise (errors building the query will be thrown, however)SQLExceptionprotected <T> T executeQuery(String tableName, String[] requestedColumnNames, String[] conditionColumnNames, String[] conditionValues, boolean ignoreFailure, org.apache.ambari.server.orm.DBAccessorImpl.ResultGetter<T> resultGetter) throws SQLException
ResultGetter implementation.tableName - the table namerequestedColumnNames - an array of column names to selectconditionColumnNames - an array of column names to use in the where clauseconditionValues - an array of value to pair with the column names in conditionColumnNamesignoreFailure - true to ignore failures executing the query; false otherwise (errors building the query will be thrown, however)resultGetter - a ResultGetter implementation used to format the data into the expected return valueSQLExceptionprotected String buildQuery(String tableName, String[] requestedColumnNames, String[] conditionColumnNames, String[] conditionValues) throws SQLException
The conditional pairs are optional but multiple pairs will be ANDed together.
Examples:
tableName - the table namerequestedColumnNames - an array of column names to selectconditionColumnNames - an array of column names to use in the where clauseconditionValues - an array of value to pair with the column names in conditionColumnNamesSQLExceptionpublic void moveColumnToAnotherTable(String sourceTableName, DBAccessor.DBColumnInfo sourceColumn, String sourceIDFieldName, String targetTableName, DBAccessor.DBColumnInfo targetColumn, String targetIDFieldName, Object initialValue) throws SQLException
sourceTableName to targetTableName using sourceIDFieldName and
targetIDFieldName keys to match right rowsmoveColumnToAnotherTable in interface DBAccessorsourceTableName - the source table namesourceColumn - the source column namesourceIDFieldName - the source id key filed name matched with targetIDFieldNametargetTableName - the target table nametargetColumn - the target column nametargetIDFieldName - the target id key name matched with sourceIDFieldNameinitialValue - initial value for null-contained cellsSQLExceptionpublic void clearTable(String tableName) throws SQLException
clearTable in interface DBAccessortableName - name of the tableSQLExceptionpublic void clearTableColumn(String tableName, String columnName, Object value) throws SQLException
value for columnName columnclearTableColumn in interface DBAccessortableName - name of the tablecolumnName - value - data to use for updateSQLExceptionCopyright © 2022 Apache Software Foundation. All rights reserved.