org.salespointframework.core.data.database
Class MysqlDatabaseConnection

java.lang.Object
  extended by org.salespointframework.core.data.database.MysqlDatabaseConnection
All Implemented Interfaces:
DatabaseConnection

public class MysqlDatabaseConnection
extends java.lang.Object
implements DatabaseConnection

This is the DatabaseConnection for Mysql Connections.

Since:
4.0
Author:
Thomas Kissinger

Nested Class Summary
private  class MysqlDatabaseConnection.MysqlConfigurationDialog
          The config dialog for Mysql connections
private  class MysqlDatabaseConnection.MysqlConfigurationFS
          Config FormSheet for mysql connections
 
Field Summary
protected  java.lang.String askpass
          "true", if user should be promptted for connection password on connect
protected  java.util.Map<java.lang.String,java.lang.String> cmds
          special commands for mysql databases
protected  java.lang.String db
          database
protected  java.lang.String description
          connection description
protected  java.lang.String host
          host name
protected  java.lang.String imageFilename
          filename of current image
protected  java.lang.String name
          connection name
protected  java.lang.String params
          additional parameters
protected  java.lang.String pass
          password
protected  java.lang.String tmpPass
          temporary password entered by user
protected  java.util.Map<java.lang.String,java.lang.String> typeMap
          typemap, which maps java types to sql types
protected  java.lang.String user
          username
 
Constructor Summary
MysqlDatabaseConnection()
          Default constructor. initializes type map and special commands
 
Method Summary
 boolean beforeConnect()
          prompt user for password if necessary
 java.util.Properties composeConnectionProperties(java.lang.String user, java.lang.String pass, java.lang.String askpass, java.lang.String tmpPass)
          builds the connection properties build on given parameters
 java.lang.String composeConnectionString(java.lang.String host, java.lang.String db, java.lang.String params)
          builds the connection string, based on given parameters
 void configure(java.awt.Window owner)
          displays the config dialog
 java.lang.Object doAssignmentFixing(java.lang.Class target, java.lang.Object obj)
          nothing to fix
 java.util.Properties getConnectionProperties()
          returns the connection properties
 java.lang.String getConnectionString()
          returns the connection string
 java.lang.String getDescription()
          returns the description
 java.awt.image.BufferedImage getImage()
          loads the image from imageFilename and returns it
 java.lang.String getName()
          returns the connection name
 java.util.Map<java.lang.String,java.lang.String> getSpecialCommands()
          returns the special commands
 java.util.Map<java.lang.String,java.lang.String> getTableColumns(java.sql.Statement st, java.lang.String tname)
          returns table infos
 java.util.List<java.lang.String> getTables(java.sql.Statement st)
          returns a list of all tables in current database
 java.util.Map<java.lang.String,java.lang.String> getTypeMapping()
          returns the type map
 boolean handleCreateTableException(java.sql.SQLException e)
          don't handle connections
 boolean loadDriver()
          loads the database driver. in this case: com.mysql.jdbc.Driver
 void onClose()
          nothing to do on close
 boolean onConnected(java.sql.Connection con)
          sets the DefaultClassNameEncoder into Hash mode after successful connect
 java.lang.String promptPassword()
          prompts the user for connection password
 void recover(java.util.Map<java.lang.String,java.lang.String> data)
          recovers connection properties
 java.util.Map<java.lang.String,java.lang.String> save()
          saves connection properties
 boolean supportsAutoGeneratedKeys()
          returns true
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

typeMap

protected java.util.Map<java.lang.String,java.lang.String> typeMap
typemap, which maps java types to sql types


cmds

protected java.util.Map<java.lang.String,java.lang.String> cmds
special commands for mysql databases


name

protected java.lang.String name
connection name


description

protected java.lang.String description
connection description


imageFilename

protected java.lang.String imageFilename
filename of current image


host

protected java.lang.String host
host name


db

protected java.lang.String db
database


user

protected java.lang.String user
username


pass

protected java.lang.String pass
password


askpass

protected java.lang.String askpass
"true", if user should be promptted for connection password on connect


params

protected java.lang.String params
additional parameters


tmpPass

protected java.lang.String tmpPass
temporary password entered by user

Constructor Detail

MysqlDatabaseConnection

public MysqlDatabaseConnection()
Default constructor. initializes type map and special commands

Method Detail

configure

public void configure(java.awt.Window owner)
displays the config dialog

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

supportsAutoGeneratedKeys

public boolean supportsAutoGeneratedKeys()
returns true

Specified by:
supportsAutoGeneratedKeys in interface DatabaseConnection
Returns:
See Also:
DatabaseConnection.supportsAutoGeneratedKeys()

composeConnectionString

public java.lang.String composeConnectionString(java.lang.String host,
                                                java.lang.String db,
                                                java.lang.String params)
builds the connection string, based on given parameters

Parameters:
host - host name
db - database
params - additional parameters
Returns:
vonnection string just build

composeConnectionProperties

public java.util.Properties composeConnectionProperties(java.lang.String user,
                                                        java.lang.String pass,
                                                        java.lang.String askpass,
                                                        java.lang.String tmpPass)
builds the connection properties build on given parameters

Parameters:
user - user name
pass - password
askpass - show password prompt on connect ?
tmpPass - temporaray password entered by user
Returns:
connection properties just build

promptPassword

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

Returns:
connection password or null on abort

getConnectionString

public java.lang.String getConnectionString()
returns the connection string

Specified by:
getConnectionString in interface DatabaseConnection
Returns:
connection string
See Also:
DriverManager.getConnection(String, Properties)

getConnectionProperties

public java.util.Properties getConnectionProperties()
returns the connection properties

Specified by:
getConnectionProperties in interface DatabaseConnection
Returns:
list of properties
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 it

Specified by:
getImage in interface DatabaseConnection
Returns:
image

getName

public java.lang.String getName()
returns the connection name

Specified by:
getName in interface DatabaseConnection
Returns:
connection name

getTypeMapping

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

Specified by:
getTypeMapping in interface DatabaseConnection
Returns:
type mapping

loadDriver

public boolean loadDriver()
loads the database driver. in this case: com.mysql.jdbc.Driver

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

onConnected

public boolean onConnected(java.sql.Connection con)
sets the DefaultClassNameEncoder into Hash mode after successful connect

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)
recovers connection properties

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

save

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

Specified by:
save in interface DatabaseConnection
Returns:
connection properties

getSpecialCommands

public java.util.Map<java.lang.String,java.lang.String> getSpecialCommands()
returns the special commands

Specified by:
getSpecialCommands in interface DatabaseConnection
Returns:
See Also:
cmds

beforeConnect

public boolean beforeConnect()
prompt user for password if necessary

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

getTables

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

Specified by:
getTables in interface DatabaseConnection
Parameters:
st - statement to use. closed by PersistenceManager

getTableColumns

public java.util.Map<java.lang.String,java.lang.String> getTableColumns(java.sql.Statement st,
                                                                        java.lang.String tname)
returns table infos

Specified by:
getTableColumns in interface DatabaseConnection
Parameters:
st - statement to use. closed by PersistenceManager
tname - table to examine
Returns:
columns -> type map

onClose

public void onClose()
nothing to do on close

Specified by:
onClose in interface DatabaseConnection

handleCreateTableException

public boolean handleCreateTableException(java.sql.SQLException e)
don't handle connections

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)
nothing to fix

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