org.salespointframework.core.data.database
Class AbstractJavaDBConnection

java.lang.Object
  extended by org.salespointframework.core.data.database.AbstractJavaDBConnection
All Implemented Interfaces:
DatabaseConnection
Direct Known Subclasses:
JavaDBClientConnection, JavaDBEmbeddedConnection

public abstract class AbstractJavaDBConnection
extends java.lang.Object
implements DatabaseConnection

This abstract class is for JavaDB Connections JavaDBClientConnection and JavaDBEmbeddedConnection it provides an abstract configuration and a typemap ans special commands, which are suitable for both special connections

Since:
4.0
Author:
Thomas Kissinger
See Also:
DatabaseConnection

Nested Class Summary
protected  class AbstractJavaDBConnection.JavaDBConfigurationDialog
          Configuration dialog for javadb connections. useable for JavaDBClientConnection and JavaDBEmbeddedConnection
protected  class AbstractJavaDBConnection.JavaDBConfigurationFS
          configuration formsheet
 
Field Summary
protected  java.lang.String askpass
          String containing "true" is PersistenceManager should ask for password on connect
protected  java.util.Map<java.lang.String,java.lang.String> cmds
          Special command used for javadb connections
protected  java.lang.String description
          the desciption for the connection
protected  java.lang.String imageFilename
          the imagefile name for connection's image
protected  java.lang.String name
          the display name of the connection
protected  java.lang.String params
          additional parameters for connection string
protected  java.lang.String pass
          connection password, if one was set. will not be saved if "ask for password" was checked in config
protected  java.lang.String target
          the target is the host or the database filename
protected  java.lang.String tmpPass
          temporary password entered by user on connect. will not be saved
protected  java.util.Map<java.lang.String,java.lang.String> typeMap
          the typemap, which maps maps field names to their datatype
protected  java.lang.String user
          username for connection
 
Constructor Summary
AbstractJavaDBConnection()
          parameterless constructor. used for default instanciation
 
Method Summary
 boolean beforeConnect()
          Jobs to do before connection. here: ask the user for connection password if necessary
abstract  void configure(java.awt.Window owner)
          configuration dialog
 java.lang.Object doAssignmentFixing(java.lang.Class target, java.lang.Object obj)
          fix connection types before field assignment.
 java.util.Properties getConnectionProperties()
          the default connection properties for javadb connections.
 java.lang.String getConnectionString()
          default connection sting for javadb connections.
 java.lang.String getDescription()
          returns the description
 java.awt.image.BufferedImage getImage()
          loads the image from imageFilename and returns this image
 java.lang.String getName()
          returns connection's name
 java.util.Map<java.lang.String,java.lang.String> getSpecialCommands()
          returns a map of special commands for javadb connections
 java.util.Map<java.lang.String,java.lang.String> getTableColumns(java.sql.Statement st, java.lang.String tname)
          returns a map which maps each table column to its datatype
 java.util.List<java.lang.String> getTables(java.sql.Statement st)
          get a list of all tables on current database
 java.util.Map<java.lang.String,java.lang.String> getTypeMapping()
          returns the typeMap
 boolean handleCreateTableException(java.sql.SQLException e)
          operations to do if table creation throws an exception handles "table already exists" exceptions
abstract  boolean loadDriver()
          load the connection driver if necessary. needs to be overridden from derrived classes
abstract  void onClose()
          operations on connection close
 boolean onConnected(java.sql.Connection con)
          operations to do after connect.
 java.lang.String promptPassword()
          prompts the user for connection password
 void recover(java.util.Map<java.lang.String,java.lang.String> data)
          recover connection properties
 java.util.Map<java.lang.String,java.lang.String> save()
          return the connection properties
 boolean supportsAutoGeneratedKeys()
          returns always true
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

imageFilename

protected java.lang.String imageFilename
the imagefile name for connection's image


name

protected java.lang.String name
the display name of the connection


description

protected java.lang.String description
the desciption for the connection


target

protected java.lang.String target
the target is the host or the database filename


params

protected java.lang.String params
additional parameters for connection string


user

protected java.lang.String user
username for connection


pass

protected java.lang.String pass
connection password, if one was set. will not be saved if "ask for password" was checked in config


askpass

protected java.lang.String askpass
String containing "true" is PersistenceManager should ask for password on connect


tmpPass

protected java.lang.String tmpPass
temporary password entered by user on connect. will not be saved


typeMap

protected java.util.Map<java.lang.String,java.lang.String> typeMap
the typemap, which maps maps field names to their datatype


cmds

protected java.util.Map<java.lang.String,java.lang.String> cmds
Special command used for javadb connections

Constructor Detail

AbstractJavaDBConnection

public AbstractJavaDBConnection()
parameterless constructor. used for default instanciation

Method Detail

promptPassword

public java.lang.String promptPassword()
prompts the user for connection password

Returns:
the password or null on abort

beforeConnect

public boolean beforeConnect()
Jobs to do before connection. here: ask the user for connection password if necessary

Specified by:
beforeConnect in interface DatabaseConnection
Returns:
true on success

configure

public abstract void configure(java.awt.Window owner)
configuration dialog

Specified by:
configure in interface DatabaseConnection
Parameters:
owner - owning window

getConnectionProperties

public java.util.Properties getConnectionProperties()
the default connection properties for javadb connections. sets "create" to "true"

Specified by:
getConnectionProperties in interface DatabaseConnection
Returns:
list of properties
See Also:
DriverManager.getConnection(String, Properties)

getConnectionString

public java.lang.String getConnectionString()
default connection sting for javadb connections.

Specified by:
getConnectionString in interface DatabaseConnection
Returns:
"jdbc:derby:"
See Also:
DriverManager.getConnection(String, Properties)

getDescription

public java.lang.String getDescription()
returns the description

Specified by:
getDescription in interface DatabaseConnection
Returns:
connection description

getImage

public java.awt.image.BufferedImage getImage()
loads the image from imageFilename and returns this image

Specified by:
getImage in interface DatabaseConnection
Returns:
connection image

getName

public java.lang.String getName()
returns connection's name

Specified by:
getName in interface DatabaseConnection
Returns:
connection name

getSpecialCommands

public java.util.Map<java.lang.String,java.lang.String> getSpecialCommands()
returns a map of special commands for javadb connections

Specified by:
getSpecialCommands in interface DatabaseConnection
Returns:

getTableColumns

public java.util.Map<java.lang.String,java.lang.String> getTableColumns(java.sql.Statement st,
                                                                        java.lang.String tname)
returns a map which maps each table column to its datatype

Specified by:
getTableColumns in interface DatabaseConnection
Parameters:
st - a usable statement for an open connection
tname - table to inspect
Returns:
mapping from column to datatype

getTables

public java.util.List<java.lang.String> getTables(java.sql.Statement st)
get a list of all tables on current database

Specified by:
getTables in interface DatabaseConnection
Parameters:
st - a usable statement for the open connection

getTypeMapping

public java.util.Map<java.lang.String,java.lang.String> getTypeMapping()
returns the typeMap

Specified by:
getTypeMapping in interface DatabaseConnection
Returns:
type mapping

supportsAutoGeneratedKeys

public boolean supportsAutoGeneratedKeys()
returns always true

Specified by:
supportsAutoGeneratedKeys in interface DatabaseConnection
Returns:

loadDriver

public abstract boolean loadDriver()
load the connection driver if necessary. needs to be overridden from derrived classes

Specified by:
loadDriver in interface DatabaseConnection
Returns:
true on success

onClose

public abstract void onClose()
operations on connection close

Specified by:
onClose in interface DatabaseConnection

onConnected

public boolean onConnected(java.sql.Connection con)
operations to do after connect. sets the DefaultClassNameEncoder to hash mode

Specified by:
onConnected in interface DatabaseConnection
Parameters:
con - connection which was established
Returns:
true on success

recover

public void recover(java.util.Map<java.lang.String,java.lang.String> data)
recover connection properties

Specified by:
recover in interface DatabaseConnection
Parameters:
data - recovered properties

save

public java.util.Map<java.lang.String,java.lang.String> save()
return the connection properties

Specified by:
save in interface DatabaseConnection
Returns:
connection properties

handleCreateTableException

public boolean handleCreateTableException(java.sql.SQLException e)
operations to do if table creation throws an exception handles "table already exists" exceptions

Specified by:
handleCreateTableException in interface DatabaseConnection
Parameters:
e - caught exception
Returns:
true if expception was handled here. otherwise false and PersistenceManager will throw a RuntimeException

doAssignmentFixing

public java.lang.Object doAssignmentFixing(java.lang.Class target,
                                           java.lang.Object obj)
fix connection types before field assignment.

Specified by:
doAssignmentFixing in interface DatabaseConnection
Parameters:
target - target type
obj - object which will be assigned afterwards
Returns:
fixed object