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
DBAccessor
createTable
in interface DBAccessor
SQLException
protected DatabaseMetaData getDatabaseMetaData() throws SQLException
SQLException
public boolean tableExists(String tableName) throws SQLException
DBAccessor
tableExists
in interface DBAccessor
SQLException
protected String getDbType()
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 tableHasForeignKey(String tableName, String fkName) throws SQLException
DBAccessor
tableHasForeignKey
in interface DBAccessor
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 void createIndex(String indexName, String tableName, String... columnNames) throws SQLException
DBAccessor
createIndex
in interface DBAccessor
SQLException
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[] keyColumns, String referenceTableName, String[] referenceColumns, boolean ignoreFailure) throws SQLException
DBAccessor
addFKConstraint
in interface DBAccessor
SQLException
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
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 boolean insertRow(String tableName, String[] columnNames, String[] values, boolean ignoreFailure) throws SQLException
DBAccessor
insertRow
in interface DBAccessor
SQLException
public int updateTable(String tableName, String columnName, Object value, String whereClause) throws SQLException
DBAccessor
updateTable
in interface DBAccessor
SQLException
public void executeQuery(String query) throws SQLException
DBAccessor
executeQuery
in interface DBAccessor
SQLException
public ResultSet executeSelect(String query) throws SQLException
DBAccessor
executeSelect
in interface DBAccessor
SQLException
public void executeQuery(String query, boolean ignoreFailure) throws SQLException
DBAccessor
executeQuery
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 dropConstraint(String tableName, String constraintName) throws SQLException
DBAccessor
dropConstraint
in interface DBAccessor
SQLException
public void dropConstraint(String tableName, String constraintName, boolean ignoreFailure) throws SQLException
DBAccessor
dropConstraint
in interface DBAccessor
SQLException
public void executeScript(String filePath) throws SQLException, IOException
DBAccessor
executeScript
in interface DBAccessor
SQLException
IOException
public org.eclipse.persistence.sessions.DatabaseSession getNewDatabaseSession()
DBAccessor
getNewDatabaseSession
in interface DBAccessor
Copyright © 2015. All rights reserved.