public class DBAccessorImpl extends Object implements DBAccessor
DBAccessor.DBColumnInfo| Constructor and Description |
|---|
DBAccessorImpl(Configuration configuration) |
| Modifier and Type | Method and Description |
|---|---|
void |
addColumn(String tableName,
DBAccessor.DBColumnInfo columnInfo)
Add column to existing table
|
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 keyColumn,
String referenceTableName,
String referenceColumn,
boolean ignoreFailure)
Add foreign key for a relation
|
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) |
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 |
dropConstraint(String tableName,
String constraintName)
Drop a constraint from table
|
void |
dropConstraint(String tableName,
String constraintName,
boolean ignoreFailure)
Drop a constraint from table
|
void |
dropSequence(String sequenceName)
Drop sequence
|
void |
dropTable(String tableName)
Drop table from schema
|
void |
executeQuery(String query)
Execute ad-hoc query on DB.
|
void |
executeQuery(String query,
boolean ignoreFailure)
Execute query on DB
|
void |
executeScript(String filePath)
Helper method to run third party scripts like Quartz DDL
|
ResultSet |
executeSelect(String query)
Execute select query
|
protected Connection |
getConnection() |
protected DatabaseMetaData |
getDatabaseMetaData() |
protected String |
getDbType() |
org.eclipse.persistence.sessions.DatabaseSession |
getNewDatabaseSession()
Get a new DB session
|
boolean |
insertRow(String tableName,
String[] columnNames,
String[] values,
boolean ignoreFailure)
Insert row into table
|
protected DbmsHelper |
loadHelper(org.eclipse.persistence.platform.database.DatabasePlatform databasePlatform) |
void |
renameColumn(String tableName,
String oldColumnName,
DBAccessor.DBColumnInfo columnInfo)
Rename existing column
|
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 |
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.
|
void |
truncateTable(String tableName)
Delete all table data
|
int |
updateTable(String tableName,
String columnName,
Object value,
String whereClause)
Simple update operation on table
|
@Inject public DBAccessorImpl(Configuration configuration)
protected DbmsHelper loadHelper(org.eclipse.persistence.platform.database.DatabasePlatform databasePlatform)
protected Connection getConnection()
public 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 DBAccessorSQLExceptionprotected String getDbType()
public boolean tableHasData(String tableName) throws SQLException
DBAccessortableHasData in interface DBAccessorSQLExceptionpublic boolean tableHasColumn(String tableName, String columnName) throws SQLException
DBAccessortableHasColumn in interface DBAccessorSQLExceptionpublic boolean tableHasForeignKey(String tableName, String fkName) throws SQLException
DBAccessortableHasForeignKey in interface DBAccessorSQLExceptionpublic 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 void createIndex(String indexName, String tableName, String... columnNames) throws SQLException
DBAccessorcreateIndex in interface DBAccessorSQLExceptionpublic 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[] keyColumns, String referenceTableName, String[] referenceColumns, boolean ignoreFailure) throws SQLException
DBAccessoraddFKConstraint in interface DBAccessorSQLExceptionpublic void renameColumn(String tableName, String oldColumnName, DBAccessor.DBColumnInfo columnInfo) throws SQLException
DBAccessorrenameColumn in interface DBAccessorSQLExceptionpublic void addColumn(String tableName, DBAccessor.DBColumnInfo columnInfo) throws SQLException
DBAccessoraddColumn 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 boolean insertRow(String tableName, String[] columnNames, String[] values, boolean ignoreFailure) throws SQLException
DBAccessorinsertRow in interface DBAccessorSQLExceptionpublic int updateTable(String tableName, String columnName, Object value, String whereClause) throws SQLException
DBAccessorupdateTable in interface DBAccessorSQLExceptionpublic void executeQuery(String query) throws SQLException
DBAccessorexecuteQuery in interface DBAccessorSQLExceptionpublic ResultSet executeSelect(String query) throws SQLException
DBAccessorexecuteSelect in interface DBAccessorSQLExceptionpublic void executeQuery(String query, boolean ignoreFailure) throws SQLException
DBAccessorexecuteQuery 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 dropConstraint(String tableName, String constraintName) throws SQLException
DBAccessordropConstraint in interface DBAccessorSQLExceptionpublic void dropConstraint(String tableName, String constraintName, boolean ignoreFailure) throws SQLException
DBAccessordropConstraint in interface DBAccessorSQLExceptionpublic void executeScript(String filePath) throws SQLException, IOException
DBAccessorexecuteScript in interface DBAccessorSQLExceptionIOExceptionpublic org.eclipse.persistence.sessions.DatabaseSession getNewDatabaseSession()
DBAccessorgetNewDatabaseSession in interface DBAccessorCopyright © 2016. All rights reserved.