public abstract class DatabaseConnector
extends java.lang.Object
connect()
with the desired JDBC URL which may
cause an admin or user connection be created. This depends on the connector implementation,
so please see the documentation for details on how to setup the various connectors. Once
the connect()
method created a valid connection to the database, the connector
can be used until the connection breaks or times out or if the disconnect()
method is called explicitely
Instances should not be recycled e.g. by overriding the parameter container values since
this is may cause errors e.g. by re-using undesired admin connections for normal users.
Always create new connectors for new sessions.
Modifier and Type | Field and Description |
---|---|
protected java.util.Hashtable<java.lang.String,java.lang.String> |
cacheSchemaByTable
Remembers the table-schema mappings.
|
static int |
CONNECT_AUTH_REQUIRED
Status for
connect() method. |
static int |
CONNECT_FAILED
Status for
connect() method. |
static int |
CONNECT_SUCCESS
Status for
connect() method. |
protected java.lang.String |
databaseDescription
The description of the represented database management system.
|
protected java.lang.String |
databaseName
The name of the represented database management system.
|
protected DatabaseManager |
dbManager
The database manager for getting connections etc.
|
protected java.sql.Connection |
defaultConn
The default connection to the database.
|
protected java.lang.String |
defaultConnURL
The JSBC URL for the default connection to the database.
|
protected java.lang.String |
driverDisplayName
The name of the underlying JDBC driver to be displayed.
|
protected java.lang.String |
driverName
Fully qualified class name of the underlying JDBC driver.
|
protected java.lang.String |
driverProductName
The name of the database product provided by the underlying JDBC driver.
|
protected java.lang.String |
driverProductVersion
The version of the database product provided by the underlying JDBC driver.
|
protected java.util.Properties |
params
The collection of parameters to use for the database.
|
protected ConnectionPool |
pool
The cache for re-used connections (optional).
|
protected java.util.Hashtable<java.lang.String,java.lang.String> |
schemaMappings
Cache for mappings of default schemas and the used schema names.
|
protected JDBCConfiguration |
typeConfig
Provides handlers for the popular JDBC data types (serialization).
|
Constructor and Description |
---|
DatabaseConnector()
Constructor method for i18n purposes only.
|
DatabaseConnector(java.util.Properties params,
DatabaseManager manager)
Constructor method for the connector.
|
Modifier and Type | Method and Description |
---|---|
void |
addSchemaMapping(java.lang.String defaultschema,
java.lang.String usedschema)
Adds a mapping of a default schema and the corresponding used schema.
|
boolean |
checkAndCreateSchemas()
Makes sure that the required schemas do exist in the target database.
|
abstract boolean |
checkSequenceExists(java.lang.String schema,
java.lang.String table)
Checks whether a sequence for the given target table does exist.
|
abstract int |
connect(java.lang.String jdbcurl)
Connects to the configured database.
|
abstract boolean |
createSequence(java.lang.String schema,
java.lang.String table,
int initval)
Creates a new sequence for the given target table.
|
abstract javax.swing.tree.TreeNode[] |
createSubTree(java.lang.String[] jdbcurls)
Creates a connector specific sub-tree from a set of JDBC URLs handled by the connector.
|
boolean |
disconnect()
Disconnects from the configured database.
|
protected void |
finalize()
Clean-up method to help the gc.
|
java.io.InputStream |
getBytes(int columnIndex,
java.sql.ResultSet rs)
Provides the binary value from the certain column.
|
byte[] |
getBytes(java.sql.ResultSet rs,
int columnIndex)
Provides the binary value from the certain column.
|
byte[] |
getBytes(java.sql.ResultSet rs,
java.lang.String columnLabel)
Provides the binary value from the certain column.
|
java.io.InputStream |
getBytes(java.lang.String columnLabel,
java.sql.ResultSet rs)
Provides the binary value from the certain column.
|
ConnectionPool |
getConnectionPool()
Provides the connection pool for doing statistics etc.
|
java.lang.String |
getDatabaseDescription()
Provides the description of the represented database management system.
|
DatabaseManager |
getDatabaseManager()
Provides the application specific database manager instance.
|
java.lang.String |
getDatabaseName()
Provides the display name of the represented database management system.
|
java.lang.String |
getDatabaseProductName()
Provides the product name provided by the underlying JDBC driver.
|
java.lang.String |
getDatabaseProductVersion()
Provides the product version provided by the underlying JDBC driver.
|
java.sql.Connection |
getDefaultConnection()
Creates a fresh connection for the given JDBC URL (never taken from the pool).
|
abstract java.lang.String |
getDefaultConnectionURL()
Provides the JDBC URL for the default conenction (normally a user connection).
|
java.lang.String |
getDefaultSchema(java.lang.String usedschema)
Provides the default schema name for the given used schema name.
|
abstract java.lang.String |
getDisplayURL(java.lang.String jdbcurl)
Makes sure that the given JDBC URL does not contain any passwords.
|
java.sql.Driver |
getDriver()
Returns the JDBC driver instance.
|
java.lang.String |
getDriverDisplayName()
Returns the display JDBC driver name (e.g.
|
java.lang.String |
getDriverName()
Returns the fully qualified JDBC driver (e.g.
|
abstract javax.swing.ImageIcon |
getIcon()
Provides the connector specific icon to represent it by GUI components.
|
java.sql.Connection |
getNewConnection(java.lang.String jdbcurl)
Creates a fresh connection for the given JDBC URL (never taken from the pool).
|
java.lang.String |
getParamDatabaseHost()
Provides the name of the database server used for JDBC.
|
java.lang.String |
getParamDatabaseName()
Provides the name of the target database used for JDBC.
|
java.lang.String |
getParamDatabasePort()
Provides the database server port used for JDBC.
|
java.util.Properties |
getParams()
Provides the current parameters used for the connector.
|
java.sql.Connection |
getPooledConnection(java.lang.String jdbcurl)
Provides an open connection for the given JDBC URL (re-used if possible).
|
java.lang.String |
getSchema(java.lang.String table)
Provides the schema of the given table.
|
java.util.Hashtable<java.lang.String,java.lang.String> |
getSchemaMappings()
Provides the internal cache with schema mappings.
|
java.lang.String |
getSchemaSeparator()
Provides the character sequence needed to separate schema and tables.
|
abstract int |
getSequenceCurrentValue(java.lang.String schema,
java.lang.String table)
Reads the current (last generated) value from a sequence.
|
abstract int |
getSequenceNextValue(java.lang.String schema,
java.lang.String table)
Reads the next value from a sequence.
|
java.lang.String[] |
getSerializedField(java.sql.ResultSet rs,
java.lang.String colname)
Provides the serialized representation of a given database field value.
|
java.lang.String |
getTableFQN(java.lang.String table)
Convenience method to get the fully qualified table name including schema.
|
java.lang.String |
getTypeTable()
Provides the database specific type for regular tables (often "TABLE").
|
java.lang.String |
getUsedSchema(java.lang.String defaultschema)
Provides the used schema name for the given default schema name.
|
abstract java.lang.String |
getUserName()
Provides the name of the default user.
|
abstract java.lang.String |
getUserPassword()
Provides the password for the default user.
|
boolean |
isAvailable()
Is the JDBC driver available on the classpath?
|
boolean |
isBinary(int metadatatype)
Checks if the given JDBC type is binary to serialize native database types properly.
|
boolean |
isConnected()
Provides the info if this connector is currently connected to the database.
|
boolean |
isEmbedded()
Is this connector designed for an embedded database like Java DB?
|
java.lang.Class |
mapToJavaType(int metadatatype)
Provides the appropriate Java type to serialize native database types.
|
boolean |
releasePooledConnection(java.sql.Connection conn,
java.lang.String jdbcurl)
Releases an occupied connection from the pool if not longer needed.
|
java.lang.String |
replaceParams(java.lang.String rawtext)
Replace placeholder variables with the current parameters settings of this connector.
|
java.lang.String |
replaceTableFQN(java.lang.String text,
java.lang.String table)
Convenience method to replace table variables like %AGREEMENT% by table FQN (including schema).
|
abstract boolean |
resetSequence(java.lang.String schema,
java.lang.String table,
int nextval)
Resets an existing sequence for the given target table.
|
void |
setParams(java.util.Properties params)
Sets the current parameters used for the connector (only when disconnected).
|
void |
updateBytes(java.sql.ResultSet rs,
int columnIndex,
byte[] x)
Updates the designated column with a binary value.
|
void |
updateBytes(java.sql.ResultSet rs,
int columnIndex,
java.io.InputStream inputStream)
Updates the designated column with a binary value.
|
void |
updateBytes(java.sql.ResultSet rs,
java.lang.String columnLabel,
byte[] x)
Updates the designated column with a binary value.
|
void |
updateBytes(java.sql.ResultSet rs,
java.lang.String columnLabel,
java.io.InputStream inputStream)
Updates the designated column with a binary value.
|
void |
updateSchemaTables(java.lang.String[] schemas)
Updates the cache with tables found in the given schemas.
|
boolean |
updateSerializedField(java.sql.ResultSet rs,
java.lang.String colname,
java.lang.String value)
Updates a database field based on the given serialized value and column type.
|
public static final int CONNECT_SUCCESS
connect()
method.public static final int CONNECT_FAILED
connect()
method.public static final int CONNECT_AUTH_REQUIRED
connect()
method.protected java.lang.String databaseName
protected java.lang.String databaseDescription
protected java.lang.String driverName
protected java.lang.String driverDisplayName
protected java.lang.String driverProductName
protected java.lang.String driverProductVersion
protected DatabaseManager dbManager
protected java.util.Properties params
protected java.sql.Connection defaultConn
protected java.lang.String defaultConnURL
protected ConnectionPool pool
protected JDBCConfiguration typeConfig
protected java.util.Hashtable<java.lang.String,java.lang.String> schemaMappings
protected java.util.Hashtable<java.lang.String,java.lang.String> cacheSchemaByTable
public DatabaseConnector() throws java.lang.InstantiationException
I18NExtractor
).
java.lang.InstantiationException
- Error indicationpublic DatabaseConnector(java.util.Properties params, DatabaseManager manager)
super()
to get the protected variables
installed. After that the name sould be set. Configurations specific for the database
system like setting initialization procedures must be handled by implementations.
params
- The database configurationmanager
- The database managerjava.lang.NullPointerException
- If parameters are invalidprotected void finalize() throws java.lang.Throwable
finalize
in class java.lang.Object
java.lang.Throwable
- Error indicationpublic java.util.Properties getParams()
public void setParams(java.util.Properties params)
params
- The new parametersjava.lang.NullPointerException
- If parameters are invalidpublic java.lang.String getDatabaseName()
public java.lang.String getDatabaseDescription()
public java.lang.String getDriverName()
org.apache.derby.jdbc.ClientDriver
)
supported by the implementation.
public java.lang.String getDriverDisplayName()
public java.sql.Driver getDriver()
null
if not availablepublic boolean isAvailable()
public abstract int connect(java.lang.String jdbcurl)
jdbcurl
- The URL for the default connectionpublic boolean disconnect()
public boolean isConnected()
false
then none of the connection types should be used any more. Some
drivers like PostgreSQL do not support the isValid()
method yet.
public java.sql.Connection getDefaultConnection()
null
if not availablepublic abstract java.lang.String getDefaultConnectionURL()
null
if an error occurspublic java.sql.Connection getNewConnection(java.lang.String jdbcurl) throws java.sql.SQLException
jdbcurl
- The desired connector class in FQNnull
if an error occursjava.sql.SQLException
- If something goes wrongjava.lang.IllegalStateException
- If the connector is not connectedpublic abstract java.lang.String getDisplayURL(java.lang.String jdbcurl)
jdbcurl
- The original URL including passwordsjava.lang.NullPointerException
- If parameters are invalidpublic abstract javax.swing.tree.TreeNode[] createSubTree(java.lang.String[] jdbcurls)
StatusDialog
class.
The JDBC URLs directly reflect the database system capabilities which must be decoded
by the connector implementations. The JDBC URLs can be structured into servers, databases,
schemas etc. as is is useful for the underlying database system. Also user names and
passwords are passed in different ways via the JDBC URLs for available databases.
jdbcurls
- The JDBC URLs to be processedjava.lang.NullPointerException
- If parameters are invalidpublic java.sql.Connection getPooledConnection(java.lang.String jdbcurl) throws java.sql.SQLException
jdbcurl
- The desired connector class in FQNnull
if an error occursjava.sql.SQLException
- If something goes wrongjava.lang.IllegalStateException
- If the connector is not connectedpublic boolean releasePooledConnection(java.sql.Connection conn, java.lang.String jdbcurl) throws java.sql.SQLException
conn
- The occupied connectionjdbcurl
- The desired connector class in FQNjava.sql.SQLException
- If something goes wrongjava.lang.IllegalStateException
- If the connector is not connectedpublic ConnectionPool getConnectionPool()
public abstract java.lang.String getUserName()
null
public abstract java.lang.String getUserPassword()
null
public DatabaseManager getDatabaseManager()
public java.lang.String getDatabaseProductName()
null
java.lang.IllegalStateException
- If the connector is not connectedpublic java.lang.String getDatabaseProductVersion()
null
java.lang.IllegalStateException
- If the connector is not connectedpublic java.lang.String getParamDatabaseName()
null
public java.lang.String getParamDatabaseHost()
null
public java.lang.String getParamDatabasePort()
null
public abstract boolean checkSequenceExists(java.lang.String schema, java.lang.String table)
schema
- The target schema (optional)table
- The name of the target tablepublic abstract boolean createSequence(java.lang.String schema, java.lang.String table, int initval)
schema
- The target schema (optional)table
- The name of the target tableinitval
- The initial value from sequencepublic abstract int getSequenceCurrentValue(java.lang.String schema, java.lang.String table)
schema
- The target schema (optional)table
- The name of the target tablepublic abstract int getSequenceNextValue(java.lang.String schema, java.lang.String table)
schema
- The target schema (optional)table
- The name of the target tablepublic abstract boolean resetSequence(java.lang.String schema, java.lang.String table, int nextval)
schema
- The target schema (optional)table
- The name of the target tablenextval
- The next value from sequencepublic abstract javax.swing.ImageIcon getIcon()
GUIUtils.getIconVariant()
method.
public java.lang.String replaceParams(java.lang.String rawtext)
rawtext
- The text with placeholderspublic java.lang.String[] getSerializedField(java.sql.ResultSet rs, java.lang.String colname)
JDBCConfiguration
class may be used here.
rs
- The result set to get the native valuecolname
- The column name to processnull
indicates errorjava.lang.IllegalArgumentException
- If a parameter is invalidpublic boolean updateSerializedField(java.sql.ResultSet rs, java.lang.String colname, java.lang.String value)
JDBCConfiguration
class may be used here.
rs
- The result set to update the fieldcolname
- The column name to updatevalue
- The serialized field valuejava.lang.IllegalArgumentException
- If a parameter is invalidpublic java.lang.Class mapToJavaType(int metadatatype)
JDBCConfiguration
class may be used here.
metadatatype
- The original JDBC type to be mappednull
if not supportedpublic boolean isBinary(int metadatatype)
metadatatype
- The original JDBC type to be mappedpublic java.lang.String getTypeTable()
DatabaseMetaData
class. Other tyoes are "VIEW", "SYSTEM_TABLE" etc.
Sub-classes must override this method if the database uses a different type identifier.
public java.lang.String getSchemaSeparator()
public void addSchemaMapping(java.lang.String defaultschema, java.lang.String usedschema)
defaultschema
- The default schema nameusedschema
- The used schema namejava.lang.NullPointerException
- If parameters are null
public java.util.Hashtable<java.lang.String,java.lang.String> getSchemaMappings()
public java.lang.String getUsedSchema(java.lang.String defaultschema)
defaultschema
- The default name of the schemanull
java.lang.NullPointerException
- If parameters are null
public java.lang.String getDefaultSchema(java.lang.String usedschema)
usedschema
- The used name of the schemanull
java.lang.NullPointerException
- If parameters are null
public boolean checkAndCreateSchemas()
java.lang.IllegalStateException
- If the connector is not connectedjava.lang.NullPointerException
- If parameters are null
public void updateSchemaTables(java.lang.String[] schemas)
schemas
- The schema listjava.lang.NullPointerException
- If parameters are null
public java.lang.String getSchema(java.lang.String table)
table
- The tablenull
java.lang.NullPointerException
- If parameters are null
public java.lang.String getTableFQN(java.lang.String table)
table
- The tablenull
java.lang.NullPointerException
- If parameters are null
public java.lang.String replaceTableFQN(java.lang.String text, java.lang.String table)
text
- The SQL query etc.table
- The tablenull
java.lang.NullPointerException
- If parameters are null
public void updateBytes(java.sql.ResultSet rs, java.lang.String columnLabel, byte[] x) throws java.sql.SQLException
updateBlob(String,InputStream)
method does not work, but updateBytes(String,byte[])
does.
By default the updateBlob(String,InputStream)
method is called here.
rs
- The result set to be updatedcolumnLabel
- The label for the column specified with the SQL AS clausex
- The new column valuejava.lang.NullPointerException
- If a parameter is null
java.sql.SQLException
- If an SQL error occurspublic void updateBytes(java.sql.ResultSet rs, int columnIndex, byte[] x) throws java.sql.SQLException
updateBlob(int,InputStream)
method does not work, but updateBytes(int,byte[])
does.
By default the updateBlob(int,InputStream)
method is called here.
rs
- The result set to be updatedcolumnIndex
- The index of the column specified with the SQL AS clause (1-based)x
- The new column valuejava.lang.NullPointerException
- If a parameter is null
java.sql.SQLException
- If an SQL error occurspublic void updateBytes(java.sql.ResultSet rs, java.lang.String columnLabel, java.io.InputStream inputStream) throws java.sql.SQLException
updateBlob(String,InputStream)
method does not work, but updateBytes(String,byte[])
does.
By default the updateBlob(String,InputStream)
method is called here.
rs
- The result set to be updatedcolumnLabel
- The label for the column specified with the SQL AS clauseinputStream
- The new column valuejava.lang.NullPointerException
- If a parameter is null
java.sql.SQLException
- If an SQL error occurspublic void updateBytes(java.sql.ResultSet rs, int columnIndex, java.io.InputStream inputStream) throws java.sql.SQLException
updateBlob(int,InputStream)
method does not work, but updateBytes(int,byte[])
does.
By default the updateBlob(int,InputStream)
method is called here.
rs
- The result set to be updatedcolumnIndex
- The index of the column specified with the SQL AS clause (1-based)inputStream
- The new column valuejava.lang.NullPointerException
- If a parameter is null
java.sql.SQLException
- If an SQL error occurspublic byte[] getBytes(java.sql.ResultSet rs, java.lang.String columnLabel) throws java.sql.SQLException
updateBlob(String,InputStream)
method does not work, but updateBytes(String,byte[])
does.
By default the getBlob(String)
method is called here.
rs
- The result set to be updatedcolumnLabel
- The label for the column specified with the SQL AS clausenull
indicates errorjava.lang.NullPointerException
- If a parameter is null
java.sql.SQLException
- If an SQL error occurspublic byte[] getBytes(java.sql.ResultSet rs, int columnIndex) throws java.sql.SQLException
updateBlob(String,InputStream)
method does not work, but updateBytes(String,byte[])
does.
By default the getBlob(String)
method is called here.
rs
- The result set to be updatedcolumnIndex
- The index of the column specified with the SQL AS clause (1-based)null
indicates errorjava.lang.NullPointerException
- If a parameter is null
java.sql.SQLException
- If an SQL error occurspublic java.io.InputStream getBytes(java.lang.String columnLabel, java.sql.ResultSet rs) throws java.sql.SQLException
updateBlob(String,InputStream)
method does not work, but updateBytes(String,byte[])
does.
By default the getBlob(String)
method is called here.
columnLabel
- The label for the column specified with the SQL AS clausers
- The result set to be updatednull
indicates errorjava.lang.NullPointerException
- If a parameter is null
java.sql.SQLException
- If an SQL error occurspublic java.io.InputStream getBytes(int columnIndex, java.sql.ResultSet rs) throws java.sql.SQLException
updateBlob(String,InputStream)
method does not work, but updateBytes(String,byte[])
does.
By default the getBlob(String)
method is called here.
columnIndex
- The index of the column specified with the SQL AS clause (1-based)rs
- The result set to be updatednull
indicates errorjava.lang.NullPointerException
- If a parameter is null
java.sql.SQLException
- If an SQL error occurspublic boolean isEmbedded()
Copyright © 2005-2013 Leisenfels UG (haftungsbeschränkt). All rights reserved.