org.salespointframework.core.data.database
Interface DatabaseConnection

All Known Implementing Classes:
AbstractJavaDBConnection, DefaultDatabaseConnection, JavaDBClientConnection, JavaDBEmbeddedConnection, MssqlDatabaseConnection, MysqlDatabaseConnection, SqliteDatabaseConnection

public interface DatabaseConnection

This interface defines a database connection. It needs to load drivers and provide properties and and functionality for the specific database type. further more it has to hald connection properties. derive this class if your wish to implement your own Database type. this interface is needed because databases differ extremely from each other.

Since:
4.0
Author:
Thomas Kissinger
See Also:
DatabaseConnectionTemplate

Method Summary
 boolean beforeConnect()
          this hook is called before connect. use to ask for passwords or whatever.
 void configure(java.awt.Window owner)
          give the user the possibility to configure this connection. this should usually show a configuration dialog
 java.lang.Object doAssignmentFixing(java.lang.Class target, java.lang.Object obj)
          Most drivers return strange values.
 java.util.Properties getConnectionProperties()
          get property list for connection.
 java.lang.String getConnectionString()
          get connection string
 java.lang.String getDescription()
          get description of this connection
 java.awt.image.BufferedImage getImage()
          get connection image
 java.lang.String getName()
          get the name of this connection
 java.util.Map<java.lang.String,java.lang.String> getSpecialCommands()
          get a list of special commands for this databse types possible keys: autoincrement -> keyword(s) for auto increment respectively identity columns createtable -> "create table if not exists" string. replaces %%tname%% with table name and %%vars%% with column values droptable -> drop table command.
 java.util.Map<java.lang.String,java.lang.String> getTableColumns(java.sql.Statement st, java.lang.String tname)
          get a map of table columns mapped to their types for given table
 java.util.List<java.lang.String> getTables(java.sql.Statement st)
          get a list of all tables in this databse
 java.util.Map<java.lang.String,java.lang.String> getTypeMapping()
          The type mapping is to map java types to database specific types that can be used in create table statement java type is identified my Class.getName()
 boolean handleCreateTableException(java.sql.SQLException e)
          handle an exception that was thrown due create table command
 boolean loadDriver()
          load the database driver if necessary
 void onClose()
          hook which is called right after connection was closed
 boolean onConnected(java.sql.Connection con)
          called right after successful connection.
 void recover(java.util.Map<java.lang.String,java.lang.String> data)
          recover connection properties which where obtained form PreferenceStorage
 java.util.Map<java.lang.String,java.lang.String> save()
          return a list of connection properties that can be saved in PreferenceStorage
 boolean supportsAutoGeneratedKeys()
          return true if your database type supports automatically generated keys.
 

Method Detail

loadDriver

boolean loadDriver()
load the database driver if necessary

Returns:
true on success

getConnectionString

java.lang.String getConnectionString()
get connection string

Returns:
connection string
See Also:
DriverManager.getConnection(String, Properties)

getConnectionProperties

java.util.Properties getConnectionProperties()
get property list for connection.

Returns:
list of properties
See Also:
DriverManager.getConnection(String, Properties)

getName

java.lang.String getName()
get the name of this connection

Returns:
connection name

getDescription

java.lang.String getDescription()
get description of this connection

Returns:
connection description

getImage

java.awt.image.BufferedImage getImage()
get connection image

Returns:
image

configure

void configure(java.awt.Window owner)
give the user the possibility to configure this connection. this should usually show a configuration dialog

Parameters:
owner - owning window

getTypeMapping

java.util.Map<java.lang.String,java.lang.String> getTypeMapping()
The type mapping is to map java types to database specific types that can be used in create table statement java type is identified my Class.getName()

Returns:
type mapping

save

java.util.Map<java.lang.String,java.lang.String> save()
return a list of connection properties that can be saved in PreferenceStorage

Returns:
connection properties

recover

void recover(java.util.Map<java.lang.String,java.lang.String> data)
recover connection properties which where obtained form PreferenceStorage

Parameters:
data - recovered properties

beforeConnect

boolean beforeConnect()
this hook is called before connect. use to ask for passwords or whatever.

Returns:
true on success

onConnected

boolean onConnected(java.sql.Connection con)
called right after successful connection.

Parameters:
con - connection which was established
Returns:
true on success

onClose

void onClose()
hook which is called right after connection was closed


getSpecialCommands

java.util.Map<java.lang.String,java.lang.String> getSpecialCommands()
get a list of special commands for this databse types possible keys: autoincrement -> keyword(s) for auto increment respectively identity columns createtable -> "create table if not exists" string. replaces %%tname%% with table name and %%vars%% with column values droptable -> drop table command. %%tname%% replaced table name emptyinsert -> sometimes inserts are empty "() values()". some dbs doesn't support this so replace this string. altermodify -> replace modify in alter modify ... command.

Returns:

getTables

java.util.List<java.lang.String> getTables(java.sql.Statement st)
get a list of all tables in this databse

Parameters:
st - statement to use. closed by PersistenceManager

getTableColumns

java.util.Map<java.lang.String,java.lang.String> getTableColumns(java.sql.Statement st,
                                                                 java.lang.String tname)
get a map of table columns mapped to their types for given table

Parameters:
st - statement to use. closed by PersistenceManager
tname - table to examine
Returns:
columns -> type map

supportsAutoGeneratedKeys

boolean supportsAutoGeneratedKeys()
return true if your database type supports automatically generated keys. otherwise return false

Returns:

handleCreateTableException

boolean handleCreateTableException(java.sql.SQLException e)
handle an exception that was thrown due create table command

Parameters:
e - caught exception
Returns:
true if expception was handled here. otherwise false and PersistenceManager will throw a RuntimeException

doAssignmentFixing

java.lang.Object doAssignmentFixing(java.lang.Class target,
                                    java.lang.Object obj)
Most drivers return strange values. SO there is a need to fix them before they will be assigned to objects field. a lot of fixing is already done by PersistenceManager.

Parameters:
target - target type
obj - object which will be assigned afterwards
Returns:
fixed object