org.knime.core.node.port.database
Class DatabaseConnectionSettings

java.lang.Object
  extended by org.knime.core.node.port.database.DatabaseConnectionSettings
Direct Known Subclasses:
DatabaseQueryConnectionSettings

public class DatabaseConnectionSettings
extends Object

Author:
Thomas Gabriel, University of Konstanz

Field Summary
static String CFG_STATEMENT
          Config for SQL statement.
static StringHistory DATABASE_URLS
          Keeps the history of all database URLs.
static StringHistory DRIVER_ORDER
          Keeps the history of all loaded driver and its order.
static Integer FETCH_SIZE
          DriverManager fetch size to chunk specified number of rows.
 
Constructor Summary
DatabaseConnectionSettings()
          Create a default settings connection object.
DatabaseConnectionSettings(DatabaseConnectionSettings conn)
          Creates a new DBConnection based on the given connection object.
DatabaseConnectionSettings(String driver, String dbName, String user, String pass, String credName)
          Create a default database connection object.
 
Method Summary
 Connection createConnection()
          Deprecated. use createConnection(CredentialsProvider)
 Connection createConnection(CredentialsProvider cp)
          Create a database connection based on this settings.
 ModelContentRO createConnectionModel()
          Create connection model with all settings used to create a database connection.
 void execute(String statement, CredentialsProvider cp)
          Execute statement on current database connection.
 String getDBName()
           
 String getDriver()
           
 String getPassword()
          Deprecated. use getPassword(CredentialsProvider)
 String getPassword(CredentialsProvider cp)
           
 String getUserName()
          Deprecated. use getUserName(CredentialsProvider)
 String getUserName(CredentialsProvider cp)
           
 boolean loadValidatedConnection(ConfigRO settings, CredentialsProvider cp)
          Load validated settings.
 void saveConnection(ConfigWO settings)
          Save settings.
 void setDBName(String databaseName)
          Deprecated. use DatabaseConnectionSettings(String, String, String, String, String)
 void setDriver(String driver)
          Deprecated. use DatabaseConnectionSettings(String, String, String, String, String)
 void setPassword(String password)
          Deprecated. use DatabaseConnectionSettings(String, String, String, String, String)
 void setUserName(String userName)
          Deprecated. use DatabaseConnectionSettings(String, String, String, String, String)
(package private)  Object syncConnection(Connection connection)
          Used to sync access to mySQL databases.
 void validateConnection(ConfigRO settings, CredentialsProvider cp)
          Validate settings.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

CFG_STATEMENT

public static final String CFG_STATEMENT
Config for SQL statement.

See Also:
Constant Field Values

DRIVER_ORDER

public static final StringHistory DRIVER_ORDER
Keeps the history of all loaded driver and its order.


DATABASE_URLS

public static final StringHistory DATABASE_URLS
Keeps the history of all database URLs.


FETCH_SIZE

public static final Integer FETCH_SIZE
DriverManager fetch size to chunk specified number of rows.

Constructor Detail

DatabaseConnectionSettings

public DatabaseConnectionSettings()
Create a default settings connection object.


DatabaseConnectionSettings

public DatabaseConnectionSettings(String driver,
                                  String dbName,
                                  String user,
                                  String pass,
                                  String credName)
Create a default database connection object.

Parameters:
driver - the database driver
dbName - database URL
user - user name
pass - password for user name
credName - credential id from CredentialsProvider or null

DatabaseConnectionSettings

public DatabaseConnectionSettings(DatabaseConnectionSettings conn)
Creates a new DBConnection based on the given connection object.

Parameters:
conn - connection used to copy settings from
Throws:
NullPointerException - if the connection is null
Method Detail

createConnection

@Deprecated
public Connection createConnection()
                            throws InvalidSettingsException,
                                   SQLException,
                                   BadPaddingException,
                                   IllegalBlockSizeException,
                                   InvalidKeyException,
                                   IOException
Deprecated. use createConnection(CredentialsProvider)

Create a database connection based on this settings. Note, don't close the connection since it cached for subsequent calls or later reuse to same database URL (under the same user name).

Returns:
a new database connection object
Throws:
SQLException - SQLException
InvalidSettingsException - InvalidSettingsException
IllegalBlockSizeException - IllegalBlockSizeException
BadPaddingException - BadPaddingException
InvalidKeyException - InvalidKeyException
IOException - IOException

createConnection

public Connection createConnection(CredentialsProvider cp)
                            throws InvalidSettingsException,
                                   SQLException,
                                   BadPaddingException,
                                   IllegalBlockSizeException,
                                   InvalidKeyException,
                                   IOException
Create a database connection based on this settings. Note, don't close the connection since it cached for subsequent calls or later reuse to same database URL (under the same user name).

Parameters:
cp - CredentialsProvider provides user/password pairs
Returns:
a new database connection object
Throws:
SQLException - SQLException
InvalidSettingsException - InvalidSettingsException
IllegalBlockSizeException - IllegalBlockSizeException
BadPaddingException - BadPaddingException
InvalidKeyException - InvalidKeyException
IOException - IOException

syncConnection

final Object syncConnection(Connection connection)
Used to sync access to mySQL databases.

Parameters:
connection - (not null) used to sync mySQL database access
Returns:
sync object which is either the given connection inherit from "com.mysql" or an new object (no sync necessary)
Throws:
NullPointerException - if the given connection is null

saveConnection

public void saveConnection(ConfigWO settings)
Save settings.

Parameters:
settings - connection settings

validateConnection

public void validateConnection(ConfigRO settings,
                               CredentialsProvider cp)
                        throws InvalidSettingsException
Validate settings.

Parameters:
settings - to validate
cp - CredentialProvider used to get user name/password
Throws:
InvalidSettingsException - if the settings are not valid

loadValidatedConnection

public boolean loadValidatedConnection(ConfigRO settings,
                                       CredentialsProvider cp)
                                throws InvalidSettingsException
Load validated settings.

Parameters:
settings - to load
cp - CredentialProvider used to get user name/password
Returns:
true, if settings have changed
Throws:
InvalidSettingsException - if settings are invalid

execute

public void execute(String statement,
                    CredentialsProvider cp)
             throws InvalidKeyException,
                    BadPaddingException,
                    IllegalBlockSizeException,
                    InvalidSettingsException,
                    SQLException,
                    IOException
Execute statement on current database connection.

Parameters:
statement - to be executed
cp - CredentialsProvider providing user/password
Throws:
SQLException - SQLException
InvalidSettingsException - InvalidSettingsException
IllegalBlockSizeException - IllegalBlockSizeException
BadPaddingException - BadPaddingException
InvalidKeyException - InvalidKeyException
IOException - IOException

createConnectionModel

public ModelContentRO createConnectionModel()
Create connection model with all settings used to create a database connection.

Returns:
database connection model

getDriver

public final String getDriver()
Returns:
database driver used to open the connection

getDBName

public final String getDBName()
Returns:
database name used to access the database URL

getUserName

public final String getUserName(CredentialsProvider cp)
Parameters:
cp - CredentialsProvider
Returns:
user name used to login to the database

getPassword

public final String getPassword(CredentialsProvider cp)
Parameters:
cp - CredentialsProvider
Returns:
password (decrypted) used to login to the database

getUserName

@Deprecated
public final String getUserName()
Deprecated. use getUserName(CredentialsProvider)

Returns:
user name used to login to the database

getPassword

@Deprecated
public final String getPassword()
Deprecated. use getPassword(CredentialsProvider)

Returns:
password (decrypted) used to login to the database

setDriver

@Deprecated
public final void setDriver(String driver)
Deprecated. use DatabaseConnectionSettings(String, String, String, String, String)

Set a new database driver.

Parameters:
driver - used to open the connection

setDBName

@Deprecated
public final void setDBName(String databaseName)
Deprecated. use DatabaseConnectionSettings(String, String, String, String, String)

Set a new database name.

Parameters:
databaseName - used to access the database URL

setUserName

@Deprecated
public final void setUserName(String userName)
Deprecated. use DatabaseConnectionSettings(String, String, String, String, String)

Set a new user name.

Parameters:
userName - used to login to the database

setPassword

@Deprecated
public final void setPassword(String password)
Deprecated. use DatabaseConnectionSettings(String, String, String, String, String)

Set a new password.

Parameters:
password - (decrypted) used to login to the database


Copyright, 2003 - 2012. All rights reserved.
University of Konstanz, Germany.
Chair for Bioinformatics and Information Mining, Prof. Dr. Michael R. Berthold.
You may not modify, publish, transmit, transfer or sell, reproduce, create derivative works from, distribute, perform, display, or in any way exploit any of the content, in whole or in part, except as otherwise expressly permitted in writing by the copyright owner or as specified in the license file distributed with this product.