|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectcom.continuent.tungsten.replicator.database.AbstractDatabase
public abstract class AbstractDatabase
Provides a generic implementation for Database interface. Subclasses must supply at least the implementation for method columnToTypeString(), which converts values from java.sql.Types to DBMS-specific column specifications.
| Field Summary | |
|---|---|
protected boolean |
autoCommit
|
protected boolean |
connected
|
protected java.sql.Connection |
dbConn
|
protected java.lang.String |
dbDriver
|
protected DBMS |
dbms
|
protected java.lang.String |
dbPassword
|
protected java.lang.String |
dbUri
|
protected java.lang.String |
dbUser
|
protected java.lang.String |
defaultSchema
|
protected static java.util.Map<java.lang.String,java.lang.Class<?>> |
drivers
|
protected boolean |
privileged
|
| Fields inherited from interface com.continuent.tungsten.replicator.database.Database |
|---|
MYSQL, ORACLE, POSTGRESQL, UNKNOWN |
| Constructor Summary | |
|---|---|
AbstractDatabase()
Create a new database instance. |
|
| Method Summary | |
|---|---|
void |
close()
Closes the instance and frees all resources. |
protected abstract java.lang.String |
columnToTypeString(Column c,
java.lang.String tableType)
Return a properly constructed type specification for the column. |
void |
commit()
Commit the current transaction. |
void |
connect()
Connects to the database. |
void |
connect(boolean binlog)
Connects to the database. |
void |
consistencyCheck(Table ct,
ConsistencyCheck cc)
Runs consistency check transaction |
void |
consistencyCheck(Table ct,
ConsistencyCheck cc,
java.lang.String masterCrc,
int masterCnt)
Runs consistency check transaction: a.) If masterCrc==null - normal (master side) consistency check is executed, which is expected to be replicated to the slaves by replication. b.) If masterCrc!=null, then masterCrc and masterCnt are put into corresponding columns, while executed check's results are put into this_crc and this_cnt columns. |
void |
controlSessionLevelLogging(boolean suppressed)
Sets session-level logging of updates. |
void |
createSchema(java.lang.String schema)
Creates the named schema. |
java.sql.Statement |
createStatement()
Generate a JDBC statement. |
void |
createTable(Table t,
boolean replace)
Creates a table using the supplied table definition. |
void |
createTable(Table table,
boolean replace,
java.lang.String tungstenTableType)
Stub routine that ignores table type. |
void |
createTable(Table table,
boolean replace,
java.lang.String tungstenSchema,
java.lang.String tungstenTableType)
|
void |
createTable(Table table,
boolean replace,
java.lang.String tungstenSchema,
java.lang.String tungstenTableType,
java.lang.String serviceName)
|
void |
createUser(User user)
Creates a user. |
int |
delete(Table table,
boolean allRows)
Deletes a row in a table. |
void |
disconnect()
Disconnects from the database. |
void |
dropSchema(java.lang.String schema)
Drops the named schema. |
void |
dropTable(Table table)
Drops an existing table. |
void |
dropTungstenCatalog(java.lang.String schemaName,
java.lang.String tungstenTableType,
java.lang.String serviceName)
dropTungstenCatalog removes Tungsten catalog. |
void |
dropUser(User user,
boolean ignore)
Deletes a user. |
void |
execute(java.lang.String SQL)
Executes a SQL request. |
void |
executeUpdate(java.lang.String SQL)
Executes a SQL request containing an update. |
Table |
findTable(int tableID)
Return the Table with all its current accompanying Columns that matches tableID. |
Table |
findTable(int tableID,
java.lang.String scn)
Return the Table with all its accompanying Columns at the provided scn that matches tableID. |
Table |
findTable(java.lang.String schemaName,
java.lang.String tableName)
Return the Table with all its accompanying Columns. |
byte[] |
getBlobAsBytes(java.sql.ResultSet resultSet,
int column)
Fetches the given column as a byte[] array. |
abstract java.sql.ResultSet |
getColumnsResultSet(java.sql.DatabaseMetaData md,
java.lang.String schemaName,
java.lang.String tableName)
This function should be implemented in concrete class. |
java.sql.Connection |
getConnection()
Returns the database connection |
java.lang.String |
getControlTimestampQuery(java.lang.Long timestamp)
Returns a query that can be used to set the timestamp. |
java.sql.DatabaseMetaData |
getDatabaseMetaData()
Returns JDBC DatabaseMetadata for the current connection. |
java.lang.String |
getDatabaseObjectName(java.lang.String name)
Returns the eventually quoted database object name. |
java.lang.String |
getPlaceHolder(OneRowChange.ColumnSpec col,
java.lang.Object colValue,
java.lang.String typeDesc)
Return a place holder in a prepared statement for a column of type ColumnSpec. |
protected abstract java.sql.ResultSet |
getPrimaryKeyResultSet(java.sql.DatabaseMetaData md,
java.lang.String schemaName,
java.lang.String tableName)
This function should be implemented in concrete class. |
java.util.ArrayList<java.lang.String> |
getReservedWords()
Returns a list of reserved words used by the DBMS, which cannot be used as table and column names. Words are expected to be upper case and applications checking with something similar to getReservedWords().contains(table.getName().toUpperCase()). |
java.lang.String |
getSessionVariable(java.lang.String name)
Gets a variable on the current session. |
abstract SqlOperationMatcher |
getSqlNameMatcher()
Returns a SQL name matcher for this database type. |
java.util.ArrayList<Table> |
getTables(java.lang.String schemaName,
boolean baseTablesOnly)
Implement ability to fetch tables. |
protected abstract java.sql.ResultSet |
getTablesResultSet(java.sql.DatabaseMetaData md,
java.lang.String schemaName,
boolean baseTablesOnly)
This function should be implemented in concrete class. |
DBMS |
getType()
Returns the type of DBMS behind the interface |
java.lang.String |
getUseSchemaQuery(java.lang.String schema)
Returns a query that can be used to set the schema. |
int |
insert(Table table)
Inserts a row into a table. |
boolean |
isPrivileged()
Returns true if this account is a super user. |
int |
javaSQLTypeToNativeType(int javaSQLType)
Opposite of the above function. |
void |
kill(Session session)
Kills a particular session. |
java.util.List<Session> |
listSessions()
Lists user sessions in the DBMS server. |
int |
nativeTypeToJavaSQLType(int nativeType)
Databases have various column types usually identified by some vendor defined integer value. |
boolean |
nullsBoundDifferently(OneRowChange.ColumnSpec col)
Return TRUE IFF NULL values are bound differently in SQL statement from non null values for the given column type. |
boolean |
nullsEverBoundDifferently()
return true IFF nulls are sometimes treated differently in nullsBoundDifferently() as non nulls. |
java.lang.String |
prepareOptionSetStatement(java.lang.String optionName,
java.lang.String optionValue)
prepareOptionSetStatement generates the sql statement that is to be used to set an option (or a session variable) at the database connection level. |
java.sql.PreparedStatement |
prepareStatement(java.lang.String statement)
Generate a JDBC prepared statement. |
void |
replace(Table table)
Replaces a row in the table using the data supplied by the Table specification. |
void |
rollback()
Rollback the current transaction. |
void |
setAutoCommit(boolean autoCommit)
Toggles autocommit by calling Connection.setAutocommit(). |
void |
setPassword(java.lang.String dbPassword)
Sets the database password. |
void |
setPrivileged(boolean privileged)
Determines whether this connection has superuser privileges (e.g., SYSDBA or SUPER depending on the DBMS type). |
void |
setSessionVariable(java.lang.String name,
java.lang.String value)
Sets a variable on the current session. |
void |
setUrl(java.lang.String dbUri)
Sets the JDBC URL used for database connections. |
void |
setUser(java.lang.String dbUser)
Sets the database user. |
boolean |
supportsControlSessionLevelLogging()
Returns true if this implementation allow clients to turn logging of SQL updates on and off at the session level. |
boolean |
supportsControlTimestamp()
By default we do not support controlling the timestamp. |
boolean |
supportsCreateDropSchema()
Returns false by default as only some database types allow schema to be created dynamically. |
boolean |
supportsNativeSlaveSync()
Returns true if this implementation supports synchronization of native slave replication with Tungsten position. |
boolean |
supportsReplace()
Returns true if the implementation supports a SQL REPLACE command. |
boolean |
supportsSessionVariables()
By default we do not support setting session variables. |
boolean |
supportsUseDefaultSchema()
Returns false by default as only some database types allow schema to change. |
boolean |
supportsUserManagement()
Returns true if this implementation supports user management commands. |
void |
syncNativeSlave(java.lang.String eventId)
Synchronize the native slave position with Tungsten so that native replication can start properly after Tungsten goes offline. |
int |
update(Table table,
java.util.ArrayList<Column> whereClause,
java.util.ArrayList<Column> values)
Updates on or more rows in a table. |
void |
useDefaultSchema(java.lang.String schema)
Changes the default schema to the named schema. |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Methods inherited from interface com.continuent.tungsten.replicator.database.Database |
|---|
getCsvWriter, getNowFunction, getSchemas, getTimeDiff |
| Field Detail |
|---|
protected DBMS dbms
protected java.lang.String dbDriver
protected java.lang.String dbUri
protected java.lang.String dbUser
protected java.lang.String dbPassword
protected boolean privileged
protected java.sql.Connection dbConn
protected boolean autoCommit
protected java.lang.String defaultSchema
protected static java.util.Map<java.lang.String,java.lang.Class<?>> drivers
protected boolean connected
| Constructor Detail |
|---|
public AbstractDatabase()
| Method Detail |
|---|
public java.sql.Connection getConnection()
Database
getConnection in interface Databasepublic DBMS getType()
Database
getType in interface Database
public abstract SqlOperationMatcher getSqlNameMatcher()
throws ReplicatorException
Database
getSqlNameMatcher in interface DatabaseReplicatorExceptionpublic void setUrl(java.lang.String dbUri)
Database
setUrl in interface Databasepublic void setUser(java.lang.String dbUser)
Database
setUser in interface Databasepublic void setPassword(java.lang.String dbPassword)
Database
setPassword in interface Databasepublic boolean isPrivileged()
Database
isPrivileged in interface Databasepublic void setPrivileged(boolean privileged)
Database
setPrivileged in interface Databaseprivileged - If true this account is a superuser
public java.lang.String getPlaceHolder(OneRowChange.ColumnSpec col,
java.lang.Object colValue,
java.lang.String typeDesc)
Database
getPlaceHolder in interface Databasepublic boolean nullsBoundDifferently(OneRowChange.ColumnSpec col)
Database
nullsBoundDifferently in interface Databasepublic boolean nullsEverBoundDifferently()
Database
nullsEverBoundDifferently in interface Database
protected abstract java.lang.String columnToTypeString(Column c,
java.lang.String tableType)
c - Column for which specification is required
public void connect()
throws java.sql.SQLException
connect in interface Databasejava.sql.SQLExceptionDatabase.connect()
public void connect(boolean binlog)
throws java.sql.SQLException
connect in interface Databasebinlog - log connection updates.
java.sql.SQLExceptionDatabase.connect(boolean)public void disconnect()
disconnect in interface DatabaseDatabase.disconnect()
public java.sql.DatabaseMetaData getDatabaseMetaData()
throws java.sql.SQLException
Database
getDatabaseMetaData in interface Databasejava.sql.SQLExceptionpublic boolean supportsCreateDropSchema()
supportsCreateDropSchema in interface DatabaseDatabase.supportsCreateDropSchema()
public void createSchema(java.lang.String schema)
throws java.sql.SQLException
createSchema in interface Databasejava.sql.SQLExceptionDatabase.createSchema(java.lang.String)
public void dropSchema(java.lang.String schema)
throws java.sql.SQLException
dropSchema in interface Databasejava.sql.SQLExceptionDatabase.dropSchema(java.lang.String)public boolean supportsUseDefaultSchema()
supportsUseDefaultSchema in interface DatabaseDatabase.supportsUseDefaultSchema()
public void useDefaultSchema(java.lang.String schema)
throws java.sql.SQLException
useDefaultSchema in interface Databasejava.sql.SQLExceptionDatabase.useDefaultSchema(java.lang.String)public java.lang.String getUseSchemaQuery(java.lang.String schema)
getUseSchemaQuery in interface DatabaseDatabase.getUseSchemaQuery(java.lang.String)public boolean supportsControlSessionLevelLogging()
supportsControlSessionLevelLogging in interface DatabaseDatabase.supportsControlSessionLevelLogging()
public void controlSessionLevelLogging(boolean suppressed)
throws java.sql.SQLException
controlSessionLevelLogging in interface Databasesuppressed - If true, updates are not logged; otherwise logging is
turned on
java.sql.SQLExceptionDatabase.controlSessionLevelLogging(boolean)public boolean supportsNativeSlaveSync()
supportsNativeSlaveSync in interface DatabaseDatabase.supportsNativeSlaveSync()
public void syncNativeSlave(java.lang.String eventId)
throws java.sql.SQLException
syncNativeSlave in interface DatabaseeventId - Tungsten event ID containing native log coordinates
java.sql.SQLExceptionDatabase.syncNativeSlave(java.lang.String)public boolean supportsControlTimestamp()
supportsControlTimestamp in interface DatabaseDatabase.supportsControlTimestamp()public java.lang.String getControlTimestampQuery(java.lang.Long timestamp)
getControlTimestampQuery in interface Databasetimestamp - Time in milliseconds according to Java standardsupportsControlTimestamp()public boolean supportsSessionVariables()
supportsSessionVariables in interface DatabaseDatabase.supportsSessionVariables()
public void setSessionVariable(java.lang.String name,
java.lang.String value)
throws java.sql.SQLException
setSessionVariable in interface Databasename - Name of the variable to setvalue - Value to set
java.sql.SQLException - Thrown if setting variable is unsuccessfulDatabase.setSessionVariable(java.lang.String,
java.lang.String)
public java.lang.String getSessionVariable(java.lang.String name)
throws java.sql.SQLException
getSessionVariable in interface Databasename - Name of the variable to get
java.sql.SQLException - Thrown if getting variable is unsuccessfulDatabase.getSessionVariable(java.lang.String)public boolean supportsUserManagement()
supportsUserManagement in interface DatabaseDatabase.supportsUserManagement()
public void createUser(User user)
throws java.sql.SQLException
createUser in interface Databaseuser - User definition
java.sql.SQLExceptionDatabase.createUser(com.continuent.tungsten.replicator.database.User)
public void dropUser(User user,
boolean ignore)
throws java.sql.SQLException
dropUser in interface Databaseuser - User definitionignore - If true, ignore error
java.sql.SQLExceptionDatabase.dropUser(com.continuent.tungsten.replicator.database.User,
boolean)
public java.util.List<Session> listSessions()
throws java.sql.SQLException
listSessions in interface Databasejava.sql.SQLExceptionDatabase.listSessions()
public void kill(Session session)
throws java.sql.SQLException,
ReplicatorException
kill in interface Databasejava.sql.SQLException
ReplicatorExceptionDatabase.kill(com.continuent.tungsten.replicator.database.Session)
public void execute(java.lang.String SQL)
throws java.sql.SQLException
execute in interface Databasejava.sql.SQLExceptionDatabase.execute(java.lang.String)
public void executeUpdate(java.lang.String SQL)
throws java.sql.SQLException
executeUpdate in interface Databasejava.sql.SQLExceptionDatabase.executeUpdate(java.lang.String)
public int insert(Table table)
throws java.sql.SQLException
insert in interface Databasetable - Table instance containing column data
java.sql.SQLExceptionDatabase.insert(com.continuent.tungsten.replicator.database.Table)
public int update(Table table,
java.util.ArrayList<Column> whereClause,
java.util.ArrayList<Column> values)
throws java.sql.SQLException
update in interface Databasetable - Table instance to updatewhereClause - List of columns containing where clause values, which
are ANDedvalues - List of columns containing values to set for matching rows
java.sql.SQLExceptionDatabase.update(com.continuent.tungsten.replicator.database.Table,
java.util.ArrayList, java.util.ArrayList)public boolean supportsReplace()
Database
supportsReplace in interface Database
public void replace(Table table)
throws java.sql.SQLException
replace in interface Databasetable - Table definition with column data and primary key
java.sql.SQLExceptionDatabase.replace(com.continuent.tungsten.replicator.database.Table)
public int delete(Table table,
boolean allRows)
throws java.sql.SQLException
delete in interface Databasetable - Table specification with primary key; columns for the key
must be defined.allRows - flag indicating that all rows from the underlying table
should be deleted
java.sql.SQLExceptionDatabase.delete(com.continuent.tungsten.replicator.database.Table,
boolean)
public java.sql.PreparedStatement prepareStatement(java.lang.String statement)
throws java.sql.SQLException
prepareStatement in interface Databasestatement - SQL statement to prepare
java.sql.SQLExceptionDatabase.prepareStatement(java.lang.String)
public java.sql.Statement createStatement()
throws java.sql.SQLException
createStatement in interface Databasejava.sql.SQLExceptionDatabase.createStatement()
public void commit()
throws java.sql.SQLException
commit in interface Databasejava.sql.SQLExceptionDatabase.commit()
public void rollback()
throws java.sql.SQLException
rollback in interface Databasejava.sql.SQLExceptionDatabase.rollback()
public void setAutoCommit(boolean autoCommit)
throws java.sql.SQLException
setAutoCommit in interface Databasejava.sql.SQLExceptionDatabase.setAutoCommit(boolean)
public void createTable(Table t,
boolean replace)
throws java.sql.SQLException
createTable in interface Databaset - Table specificationreplace - If true, replace an existing table
java.sql.SQLExceptionDatabase.createTable(com.continuent.tungsten.replicator.database.Table,
boolean)public void dropTable(Table table)
dropTable in interface DatabaseDatabase.dropTable(com.continuent.tungsten.replicator.database.Table)public void close()
close in interface DatabaseDatabase.close()
public int nativeTypeToJavaSQLType(int nativeType)
throws java.sql.SQLException
Database
nativeTypeToJavaSQLType in interface Databasejava.sql.SQLException
public int javaSQLTypeToNativeType(int javaSQLType)
throws java.sql.SQLException
Database
javaSQLTypeToNativeType in interface Databasejava.sql.SQLException
public Table findTable(int tableID)
throws java.sql.SQLException
Database
findTable in interface Databasejava.sql.SQLException
public Table findTable(int tableID,
java.lang.String scn)
throws java.sql.SQLException
findTable in interface DatabasetableID - the object which is looked forscn - when the object is search for
java.sql.SQLException - if an error occursDatabase.findTable(int,
java.lang.String)
public abstract java.sql.ResultSet getColumnsResultSet(java.sql.DatabaseMetaData md,
java.lang.String schemaName,
java.lang.String tableName)
throws java.sql.SQLException
getColumnsResultSet in interface Databasemd - DatabaseMetaData objectschemaName - schema nametableName - table name
java.sql.SQLException
protected abstract java.sql.ResultSet getPrimaryKeyResultSet(java.sql.DatabaseMetaData md,
java.lang.String schemaName,
java.lang.String tableName)
throws java.sql.SQLException
md - DatabaseMetaData objectschemaName - schema nametableName - table name
java.sql.SQLException
protected abstract java.sql.ResultSet getTablesResultSet(java.sql.DatabaseMetaData md,
java.lang.String schemaName,
boolean baseTablesOnly)
throws java.sql.SQLException
md - DatabaseMetaData objectschemaName - schema namebaseTablesOnly - If true, return only base tables, not catalogs or
views
java.sql.SQLException
public Table findTable(java.lang.String schemaName,
java.lang.String tableName)
throws java.sql.SQLException
findTable in interface DatabaseschemaName - name of schema containing the tabletableName - name of the table
java.sql.SQLException - if an error occursDatabase.findTable(java.lang.String,
java.lang.String)
public java.util.ArrayList<Table> getTables(java.lang.String schemaName,
boolean baseTablesOnly)
throws java.sql.SQLException
getTables in interface DatabaseschemaName - Name of the schemabaseTablesOnly - If true, only return real tables and not catalogs
or views
java.sql.SQLExceptionDatabase.getTables(java.lang.String,
boolean)
public void consistencyCheck(Table ct,
ConsistencyCheck cc)
throws java.sql.SQLException,
ConsistencyException
consistencyCheck in interface Databasect - consitency tablecc - ConsistencyCheck specification
java.sql.SQLException
ConsistencyExceptionDatabase.consistencyCheck(com.continuent.tungsten.replicator.database.Table,
com.continuent.tungsten.replicator.consistency.ConsistencyCheck)
public void consistencyCheck(Table ct,
ConsistencyCheck cc,
java.lang.String masterCrc,
int masterCnt)
throws java.sql.SQLException,
ConsistencyException
consistencyCheck in interface Databasect - Consistency table.cc - ConsistencyCheck specification.masterCrc - CRC value of this check on the master.masterCnt - Count of rows of this check on the master.
java.sql.SQLException
ConsistencyExceptionDatabase.consistencyCheck(com.continuent.tungsten.replicator.database.Table,
com.continuent.tungsten.replicator.consistency.ConsistencyCheck,
String, int)
public void createTable(Table table,
boolean replace,
java.lang.String tungstenTableType)
throws java.sql.SQLException
createTable in interface Databasetable - Table specificationreplace - If true, replace an existing tabletungstenTableType - table type to be used for tungsten catalog
tables
java.sql.SQLExceptionDatabase.createTable(com.continuent.tungsten.replicator.database.Table,
boolean, java.lang.String)
public void createTable(Table table,
boolean replace,
java.lang.String tungstenSchema,
java.lang.String tungstenTableType)
throws java.sql.SQLException
createTable in interface Databasejava.sql.SQLExceptionDatabase.createTable(com.continuent.tungsten.replicator.database.Table,
boolean, java.lang.String, java.lang.String)
public void createTable(Table table,
boolean replace,
java.lang.String tungstenSchema,
java.lang.String tungstenTableType,
java.lang.String serviceName)
throws java.sql.SQLException
createTable in interface Databasejava.sql.SQLExceptionDatabase.createTable(com.continuent.tungsten.replicator.database.Table,
boolean, java.lang.String, java.lang.String, java.lang.String)
public java.lang.String prepareOptionSetStatement(java.lang.String optionName,
java.lang.String optionValue)
prepareOptionSetStatement in interface DatabaseoptionName - the option to be setoptionValue - the value to be used
Database.prepareOptionSetStatement(java.lang.String,
java.lang.String)
public byte[] getBlobAsBytes(java.sql.ResultSet resultSet,
int column)
throws java.sql.SQLException
getBlobAsBytes in interface DatabaseresultSet - ResultSet which has this blob column.column - Index of the column to fetch value from.
java.sql.SQLException - As this method is operating on ResultSet, it might
throw a SQLException.Database.getBlobAsBytes(ResultSet,
int)public java.lang.String getDatabaseObjectName(java.lang.String name)
getDatabaseObjectName in interface Databasename - unquoted database object name
Database.getDatabaseObjectName(java.lang.String)public java.util.ArrayList<java.lang.String> getReservedWords()
getReservedWords in interface Database
public void dropTungstenCatalog(java.lang.String schemaName,
java.lang.String tungstenTableType,
java.lang.String serviceName)
throws java.sql.SQLException
dropTungstenCatalog in interface DatabaseschemaName - The schema name where Tungsten catalog is storedtungstenTableType - The type of table used to store Tungsten metadataserviceName - The service name for which the catalog has to be dropped
java.sql.SQLExceptioncom.continuent.tungsten.replicator.database.Database#dropTungstenCatalog(java.lang.String)
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||