org.salespointframework.core.data.database
Class MssqlDatabaseConnection

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

public class MssqlDatabaseConnection
extends java.lang.Object
implements DatabaseConnection

DatabaseConnection implementation for Microsoft SQL server (also express editions) 2008

Since:
4.0
Author:
Thomas Kissinger

Nested Class Summary
private  class MssqlDatabaseConnection.MssqlConfigurationDialog
          The configuration dialog for MSSQL cnnections
private  class MssqlDatabaseConnection.MssqlConfigurationFS
          Configuration FormSheet
 
Field Summary
protected  java.lang.String askpass
          if true, connection will ask for connection password on connect
protected  java.util.Map<java.lang.String,java.lang.String> cmds
          special commands for this connection type
protected  java.lang.String db
          connection database
protected  java.lang.String description
          connection description
protected  java.lang.String host
          connection host
protected  java.lang.String imageFilename
          filename pointing to connection image
protected  java.lang.String name
          connection name
protected  java.lang.String params
          additional connection parameters
protected  java.lang.String pass
          stored password for connection
protected  java.lang.String tmpPass
          password entered by user on connect if necessary. will not be saved
protected  java.util.Map<java.lang.String,java.lang.String> typeMap
          map which maps java types to sql types
protected  java.lang.String user
          connection username
 
Constructor Summary
MssqlDatabaseConnection()
          default constructor. just loads type map and special commands in a static way
 
Method Summary
 boolean beforeConnect()
          called before connect. prompts the user for password if necessary.
 java.util.Properties composeConnectionProperties(java.lang.String db, java.lang.String user, java.lang.String pass, java.lang.String askpass, java.lang.String tmpPass)
          builds the connection properties
 java.lang.String composeConnectionString(java.lang.String host, java.lang.String params)
          builds the connection string based on given arguments
 void configure(java.awt.Window owner)
          displays the configuration dialog
 java.lang.Object doAssignmentFixing(java.lang.Class target, java.lang.Object obj)
          nothing to fix
 java.util.Properties getConnectionProperties()
          returns connection properties
 java.lang.String getConnectionString()
          returns the connection string
 java.lang.String getDescription()
          returns the connection description
 java.awt.image.BufferedImage getImage()
          returns connection's image which is loaded from imageFilename
 java.lang.String getName()
          returns connection's name
 java.util.Map<java.lang.String,java.lang.String> getSpecialCommands()
          returns a list of static commands for this connection
 java.util.Map<java.lang.String,java.lang.String> getTableColumns(java.sql.Statement st, java.lang.String tname)
          retuns a map of columns and its type
 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 typeMap
 boolean handleCreateTableException(java.sql.SQLException e)
          nothing to do if exception in table creation ocurres.
 boolean loadDriver()
          loads the driver. in this case: com.microsoft.sqlserver.jdbc.SQLServerDriver
 void onClose()
          nothing to do on close
 boolean onConnected(java.sql.Connection con)
          called after successful connect. sets mode of DefaultClassNameEncoder to Hash mode
 java.lang.String promptPassword()
          displays the password prompt
 void recover(java.util.Map<java.lang.String,java.lang.String> data)
          recovers the connection and sets given properties
 java.util.Map<java.lang.String,java.lang.String> save()
          saves the connection
 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

typeMap

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


cmds

protected java.util.Map<java.lang.String,java.lang.String> cmds
special commands for this connection type


name

protected java.lang.String name
connection name


description

protected java.lang.String description
connection description


imageFilename

protected java.lang.String imageFilename
filename pointing to connection image


host

protected java.lang.String host
connection host


db

protected java.lang.String db
connection database


user

protected java.lang.String user
connection username


pass

protected java.lang.String pass
stored password for connection


askpass

protected java.lang.String askpass
if true, connection will ask for connection password on connect


params

protected java.lang.String params
additional connection parameters


tmpPass

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

Constructor Detail

MssqlDatabaseConnection

public MssqlDatabaseConnection()
default constructor. just loads type map and special commands in a static way

Method Detail

configure

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

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

supportsAutoGeneratedKeys

public boolean supportsAutoGeneratedKeys()
Returns always true

Specified by:
supportsAutoGeneratedKeys in interface DatabaseConnection
Returns:
See Also:
DatabaseConnection

composeConnectionString

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

Parameters:
host - host address
params - additional parameters
Returns:
connection string

composeConnectionProperties

public java.util.Properties composeConnectionProperties(java.lang.String db,
                                                        java.lang.String user,
                                                        java.lang.String pass,
                                                        java.lang.String askpass,
                                                        java.lang.String tmpPass)
builds the connection properties

Parameters:
db - database
user - user name
pass - password
askpass - true, if user should be prompted for password on connect
tmpPass - temporary password
Returns:
connection properties

promptPassword

public java.lang.String promptPassword()
displays the password prompt

Returns:
entered password. 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 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 connection description

Specified by:
getDescription in interface DatabaseConnection
Returns:
connection description

getImage

public java.awt.image.BufferedImage getImage()
returns connection's image which is loaded from imageFilename

Specified by:
getImage in interface DatabaseConnection
Returns:
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 list of static commands for this connection

Specified by:
getSpecialCommands in interface DatabaseConnection
Returns:

getTypeMapping

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

Specified by:
getTypeMapping in interface DatabaseConnection
Returns:
type mapping

loadDriver

public boolean loadDriver()
loads the driver. in this case: com.microsoft.sqlserver.jdbc.SQLServerDriver

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

onConnected

public boolean onConnected(java.sql.Connection con)
called after successful connect. sets mode of 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)
recovers the connection and sets given properties

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

save

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

Specified by:
save in interface DatabaseConnection
Returns:
connection properties

beforeConnect

public boolean beforeConnect()
called before connect. prompts the 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)
retuns a map of columns and its type

Specified by:
getTableColumns in interface DatabaseConnection
Parameters:
st - statement to use. closed by PersistenceManager
tname - table to examine
Returns:
columns -> type map
See Also:
DatabaseConnection.getTableColumns(Statement, String)

onClose

public void onClose()
nothing to do on close

Specified by:
onClose in interface DatabaseConnection

handleCreateTableException

public boolean handleCreateTableException(java.sql.SQLException e)
nothing to do if exception in table creation ocurres.

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