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 DBAccessor
public Connection getNewConnection()
getNewConnection
in interface DBAccessor
public String quoteObjectName(String name)
DBAccessor
quoteObjectName
in interface DBAccessor
name
- object name without quotespublic void createTable(String tableName, List<DBAccessor.DBColumnInfo> columnInfo, String... primaryKeyColumns) throws SQLException
DBAccessor
createTable
in interface DBAccessor
SQLException
protected DatabaseMetaData getDatabaseMetaData() throws SQLException
SQLException
public boolean tableExists(String tableName) throws SQLException
DBAccessor
tableExists
in interface DBAccessor
tableName
- name of the tableSQLException
public DBAccessor.DbType getDbType()
DBAccessor
getDbType
in interface DBAccessor
public String getDbSchema()
DBAccessor
getDbSchema
in interface DBAccessor
public boolean tableHasData(String tableName) throws SQLException
DBAccessor
tableHasData
in interface DBAccessor
SQLException
public boolean tableHasColumn(String tableName, String columnName) throws SQLException
DBAccessor
tableHasColumn
in interface DBAccessor
SQLException
public boolean tableHasColumn(String tableName, String... columnName) throws SQLException
DBAccessor
tableHasColumn
in interface DBAccessor
tableName
- name of the tablecolumnName
- name of the column to checkSQLException
public boolean tableHasForeignKey(String tableName, String fkName) throws SQLException
DBAccessor
tableHasForeignKey
in interface DBAccessor
SQLException
public String getCheckedForeignKey(String rawTableName, String rawForeignKeyName) throws SQLException
SQLException
public boolean tableHasForeignKey(String tableName, String refTableName, String columnName, String refColumnName) throws SQLException
DBAccessor
tableHasForeignKey
in interface DBAccessor
SQLException
public boolean tableHasForeignKey(String tableName, String referenceTableName, String[] keyColumns, String[] referenceColumns) throws SQLException
DBAccessor
tableHasForeignKey
in interface DBAccessor
SQLException
public boolean tableHasIndex(String tableName, boolean unique, String indexName) throws SQLException
DBAccessor
tableHasIndex
in interface DBAccessor
tableName
- the name of the table (not null
).unique
- list only unique indexes (not null
).indexName
- name of the index to checkSQLException
public void createIndex(String indexName, String tableName, String... columnNames) throws SQLException
DBAccessor
createIndex
in interface DBAccessor
SQLException
public void createIndex(String indexName, String tableName, boolean isUnique, String... columnNames) throws SQLException
DBAccessor
createIndex
in interface DBAccessor
indexName
- 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
DBAccessor
addFKConstraint
in interface DBAccessor
SQLException
public void addFKConstraint(String tableName, String constraintName, String keyColumn, String referenceTableName, String referenceColumn, boolean shouldCascadeOnDelete, boolean ignoreFailure) throws SQLException
addFKConstraint
in interface DBAccessor
SQLException
public void addFKConstraint(String tableName, String constraintName, String[] keyColumns, String referenceTableName, String[] referenceColumns, boolean ignoreFailure) throws SQLException
DBAccessor
addFKConstraint
in interface DBAccessor
SQLException
public void addFKConstraint(String tableName, String constraintName, String[] keyColumns, String referenceTableName, String[] referenceColumns, boolean shouldCascadeOnDelete, boolean ignoreFailure) throws SQLException
DBAccessor
addFKConstraint
in interface DBAccessor
SQLException
public boolean tableHasConstraint(String tableName, String constraintName) throws SQLException
SQLException
public void addUniqueConstraint(String tableName, String constraintName, String... columnNames) throws SQLException
DBAccessor
addUniqueConstraint
in interface DBAccessor
tableName
- name of the tableconstraintName
- name of the constraintcolumnNames
- list of columnsSQLException
public void updateUniqueConstraint(String tableName, String constraintName, String... columnNames) throws SQLException
DBAccessor
updateUniqueConstraint
in interface DBAccessor
tableName
- name of the tableconstraintName
- name of the constraintcolumnNames
- list of columnsSQLException
public void addPKConstraint(String tableName, String constraintName, boolean ignoreErrors, String... columnName) throws SQLException
addPKConstraint
in interface DBAccessor
tableName
- name of the tableconstraintName
- name of the constraintignoreErrors
- true to ignore database errorscolumnName
- name of the columnSQLException
public void addPKConstraint(String tableName, String constraintName, String... columnName) throws SQLException
addPKConstraint
in interface DBAccessor
tableName
- name of the tableconstraintName
- name of the constraintcolumnName
- name of the columnSQLException
public void renameColumn(String tableName, String oldColumnName, DBAccessor.DBColumnInfo columnInfo) throws SQLException
DBAccessor
renameColumn
in interface DBAccessor
SQLException
public 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 DBAccessor
SQLException
public void alterColumn(String tableName, DBAccessor.DBColumnInfo columnInfo) throws SQLException
DBAccessor
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)
alterColumn
in interface DBAccessor
SQLException
public void updateTable(String tableName, DBAccessor.DBColumnInfo columnNameFrom, DBAccessor.DBColumnInfo columnNameTo) throws SQLException
DBAccessor
updateTable
in interface DBAccessor
SQLException
public boolean insertRow(String tableName, String[] columnNames, String[] values, boolean ignoreFailure) throws SQLException
DBAccessor
insertRow
in interface DBAccessor
SQLException
public boolean insertRowIfMissing(String tableName, String[] columnNames, String[] values, boolean ignoreFailure) throws SQLException
DBAccessor
insertRowIfMissing
in interface DBAccessor
SQLException
public int updateTable(String tableName, String columnName, Object value, String whereClause) throws SQLException
DBAccessor
updateTable
in interface DBAccessor
SQLException
public int executeUpdate(String query) throws SQLException
executeUpdate
in interface DBAccessor
query
- update queryjava.sql.Statement
SQLException
public int executeUpdate(String query, boolean ignoreErrors) throws SQLException
executeUpdate
in interface DBAccessor
query
- update queryignoreErrors
- true to ignore errorsjava.sql.Statement
SQLException
public void executeQuery(String query, String tableName, String hasColumnName) throws SQLException
DBAccessor
executeQuery
in interface DBAccessor
SQLException
public void executeQuery(String query) throws SQLException
DBAccessor
executeQuery
in interface DBAccessor
SQLException
public void executeQuery(String query, boolean ignoreFailure) throws SQLException
DBAccessor
executeQuery
in interface DBAccessor
SQLException
public void executePreparedQuery(String query, Object... arguments) throws SQLException
executePreparedQuery
in interface DBAccessor
query
- query to executearguments
- list of arguments for prepared statementSQLException
public void executePreparedQuery(String query, boolean ignoreFailure, Object... arguments) throws SQLException
executePreparedQuery
in interface DBAccessor
query
- query to executeignoreFailure
- determines if exceptions during query execution should be ignoredarguments
- list of arguments for prepared statementSQLException
public void executePreparedUpdate(String query, Object... arguments) throws SQLException
executePreparedUpdate
in interface DBAccessor
query
- query to executearguments
- list of arguments for prepared statementSQLException
public void executePreparedUpdate(String query, boolean ignoreFailure, Object... arguments) throws SQLException
executePreparedUpdate
in interface DBAccessor
SQLException
public void dropTable(String tableName) throws SQLException
DBAccessor
dropTable
in interface DBAccessor
SQLException
public void truncateTable(String tableName) throws SQLException
DBAccessor
truncateTable
in interface DBAccessor
SQLException
public void dropColumn(String tableName, String columnName) throws SQLException
DBAccessor
dropColumn
in interface DBAccessor
SQLException
public void dropSequence(String sequenceName) throws SQLException
DBAccessor
dropSequence
in interface DBAccessor
SQLException
public void dropFKConstraint(String tableName, String constraintName) throws SQLException
DBAccessor
Configuration.DatabaseType.MYSQL
, this will also ensure that any associated
indexes are also dropped.dropFKConstraint
in interface DBAccessor
tableName
- name of the tableconstraintName
- name of the constraintSQLException
public void dropFKConstraint(String tableName, String constraintName, boolean ignoreFailure) throws SQLException
dropFKConstraint
in interface DBAccessor
tableName
- name of the tableconstraintName
- name of the constraintSQLException
public void dropUniqueConstraint(String tableName, String constraintName, boolean ignoreFailure) throws SQLException
DBAccessor
dropUniqueConstraint
in interface DBAccessor
tableName
- name of the tableconstraintName
- name of the constraintSQLException
public void dropUniqueConstraint(String tableName, String constraintName) throws SQLException
DBAccessor
dropUniqueConstraint
in interface DBAccessor
tableName
- name of the tableconstraintName
- name of the constraintSQLException
public void dropPKConstraint(String tableName, String constraintName, String columnName, boolean cascade) throws SQLException
DBAccessor
dropPKConstraint
in interface DBAccessor
tableName
- name of the tableconstraintName
- name of the constraintcolumnName
- name of the column from the pk constraintcascade
- cascade deleteSQLException
public void dropPKConstraint(String tableName, String constraintName, boolean ignoreFailure, boolean cascade) throws SQLException
DBAccessor
dropPKConstraint
in interface DBAccessor
constraintName
- name of the constraintcascade
- cascade deleteSQLException
public void dropPKConstraint(String tableName, String constraintName, boolean cascade) throws SQLException
DBAccessor
dropPKConstraint
in interface DBAccessor
tableName
- name of the tableconstraintName
- name of the constraintcascade
- cascade deleteSQLException
public void executeScript(String filePath) throws SQLException, IOException
executeScript
in interface DBAccessor
SQLException
IOException
public org.eclipse.persistence.sessions.DatabaseSession getNewDatabaseSession()
DBAccessor
getNewDatabaseSession
in interface DBAccessor
public boolean tableHasPrimaryKey(String tableName, String columnName) throws SQLException
DBAccessor
tableHasPrimaryKey
in interface DBAccessor
tableName
- name of the tablecolumnName
- name of the constraint, could be null
SQLException
public int getColumnType(String tableName, String columnName) throws SQLException
DBAccessor
getColumnType
in interface DBAccessor
tableName
- the name of the table (not null
).columnName
- the name of the column to retrieve type for (not null
).SQLException
public Class getColumnClass(String tableName, String columnName) throws SQLException, ClassNotFoundException
DBAccessor
getColumnClass
in interface DBAccessor
tableName
- name of the tablecolumnName
- name of the columnSQLException
ClassNotFoundException
public boolean isColumnNullable(String tableName, String columnName) throws SQLException
DBAccessor
isColumnNullable
in interface DBAccessor
tableName
- name of the tablecolumnName
- name of the columnSQLException
public void setColumnNullable(String tableName, DBAccessor.DBColumnInfo columnInfo, boolean nullable) throws SQLException
DBAccessor
NULL
.setColumnNullable
in interface DBAccessor
tableName
- 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.SQLException
public void setColumnNullable(String tableName, String columnName, boolean nullable) throws SQLException
setColumnNullable
in interface DBAccessor
SQLException
public void changeColumnType(String tableName, String columnName, Class fromType, Class toType) throws SQLException
DBAccessor
changeColumnType
in interface DBAccessor
tableName
- name of the tablecolumnName
- name of the columnfromType
- previous typetoType
- new desired typeSQLException
public DBAccessor.DBColumnInfo getColumnInfo(String tableName, String columnName)
getColumnInfo
in interface DBAccessor
tableName
- Name of the tablecolumnName
- Name of the columnSQLException
public List<String> getIndexesList(String tableName, boolean unique) throws SQLException
DBAccessor
getIndexesList
in interface DBAccessor
tableName
- the name of the table (not null
).unique
- list only unique indexes (not null
).SQLException
public 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 DBAccessor
tableName
- the name of the table to lookup the PK constraint.null
if none.SQLException
public void dropPKConstraint(String tableName, String defaultConstraintName) throws SQLException
dropPKConstraint
in interface DBAccessor
tableName
- the table to drop the PK from (not null
).defaultConstraintName
- the default name of the PK constraint if none is found.SQLException
public void addDefaultConstraint(String tableName, DBAccessor.DBColumnInfo column) throws SQLException
addDefaultConstraint
in interface DBAccessor
tableName
- the table where the column is defined (not null
).column
- the column information which contains the default value (not
null
).SQLException
public 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
= condition
copyColumnToAnotherTable
in interface DBAccessor
sourceTableName
- the source table namesourceColumn
- the source column namesourceIDFieldName1
- the source id key filed name matched with targetIDFieldName1
sourceIDFieldName2
- the source id key filed name matched with targetIDFieldName2
sourceIDFieldName3
- the source id key filed name matched with targetIDFieldName3
targetTableName
- the target table nametargetColumn
- the target column nametargetIDFieldName1
- the target id key name matched with sourceIDFieldName1
targetIDFieldName2
- the target id key name matched with sourceIDFieldName2
targetIDFieldName3
- the target id key name matched with sourceIDFieldName3
sourceConditionFieldName
- source key column name which should match condition
condition
- value which should match sourceConditionFieldName
initialValue
- initial value for null-contained cellsSQLException
public List<Integer> getIntColumnValues(String tableName, String columnName, String[] conditionColumnNames, String[] values, boolean ignoreFailure) throws SQLException
columnName
from tableName
where columnNames
values = values
getIntColumnValues
in interface DBAccessor
tableName
- 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)SQLException
public 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 = values
getKeyToStringColumnMap
in interface DBAccessor
tableName
- 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)SQLException
protected <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 valueSQLException
protected 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 conditionColumnNamesSQLException
public 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 DBAccessor
sourceTableName
- the source table namesourceColumn
- the source column namesourceIDFieldName
- the source id key filed name matched with targetIDFieldName
targetTableName
- the target table nametargetColumn
- the target column nametargetIDFieldName
- the target id key name matched with sourceIDFieldName
initialValue
- initial value for null-contained cellsSQLException
public void clearTable(String tableName) throws SQLException
clearTable
in interface DBAccessor
tableName
- name of the tableSQLException
public void clearTableColumn(String tableName, String columnName, Object value) throws SQLException
value
for columnName
columnclearTableColumn
in interface DBAccessor
tableName
- name of the tablecolumnName
- value
- data to use for updateSQLException
Copyright © 2022 Apache Software Foundation. All rights reserved.