net.sf.jso.sql
Class JSODatabase

java.lang.Object
  extended bynet.sf.jso.sql.JSODatabase
All Implemented Interfaces:
DatabaseInterface

public class JSODatabase
extends java.lang.Object
implements DatabaseInterface


Constructor Summary
JSODatabase()
           
 
Method Summary
 java.sql.Connection connect(java.lang.String anUrl, java.lang.String anUser, java.lang.String aPassword)
          Connects to the database.
 void createTable(TableDescriptor aTable, java.sql.Connection aConnection)
          Creates a table in the database.
 void dropTable(java.lang.String aTable, java.sql.Connection aConnection)
          Drops a table in the database.
 java.lang.String getDriverClass()
          Returns database's JDBC driver class name.
 int getStringLength()
          Returns the length to be used as string comlumns length in tables.
 boolean isDuplicateKeyCode(int aCode)
          Indicates if a vendor error code is a duplicate key error code.
 boolean isReferentialIntegrityCode(int aCode)
          Indicates if a vendor error code is a referential integrity error code.
 boolean mapTypes(java.sql.Connection aConnection)
          Maps JDBC SQL types to database data types.
 boolean mapTypes(java.io.InputStream aStream)
          Maps JDBC SQL types to database data types.
 boolean mapTypes(java.util.Properties properties)
          Maps JDBC SQL types to database data types.
 boolean set(java.io.InputStream aStream)
          Sets database properties.
 boolean set(java.util.Properties properties)
          Sets database properties.
 void setDriverClass(java.lang.String className)
          Sets database's JDBC driver class name.
 void setDuplicateKeyCodes(java.lang.String codes)
          Sets SQL error codes for duplicate keys.
 void setReferentialIntegrityCodes(java.lang.String codes)
          Sets SQL error codes for referential integrity errors.
 void setStringLength(int someLength)
          Sets the length to be used as string comlumns length in tables.
 void setStringLength(java.lang.String someLength)
          Sets the length to be used as string comlumns length in tables.
 boolean tableExists(java.lang.String aTable, java.sql.Connection aConnection)
          Checks for table existence.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

JSODatabase

public JSODatabase()
Method Detail

set

public boolean set(java.io.InputStream aStream)
            throws java.io.IOException
Sets database properties.

Specified by:
set in interface DatabaseInterface
Parameters:
aStream - Input stream of a properties file.
Returns:
true if all mandatory properties could be set; false otherwise.
Throws:
java.io.IOException
See Also:
Properties.load(InputStream), DatabaseInterface.set(Properties)

set

public boolean set(java.util.Properties properties)
Sets database properties.

Specified by:
set in interface DatabaseInterface
Parameters:
properties - Properties from which database properties will be set.
Returns:
true if all mandatory properties could be set; false otherwise.

setDriverClass

public void setDriverClass(java.lang.String className)
Sets database's JDBC driver class name.

Specified by:
setDriverClass in interface DatabaseInterface
Parameters:
className - Fully qualified name for the JDBC driver class.

getDriverClass

public java.lang.String getDriverClass()
Returns database's JDBC driver class name.

Specified by:
getDriverClass in interface DatabaseInterface
Returns:
Fully qualified name for the JDBC driver class.

setStringLength

public void setStringLength(java.lang.String someLength)
Sets the length to be used as string comlumns length in tables.

Specified by:
setStringLength in interface DatabaseInterface
Parameters:
someLength - String comlumns length in tables.

setStringLength

public void setStringLength(int someLength)
Sets the length to be used as string comlumns length in tables.

Specified by:
setStringLength in interface DatabaseInterface
Parameters:
someLength - String comlumns length in tables.

getStringLength

public int getStringLength()
Returns the length to be used as string comlumns length in tables.

Specified by:
getStringLength in interface DatabaseInterface
Returns:
The length to be used as string comlumns length in tables.

mapTypes

public boolean mapTypes(java.sql.Connection aConnection)
                 throws java.sql.SQLException
Maps JDBC SQL types to database data types.

Specified by:
mapTypes in interface DatabaseInterface
Parameters:
aConnection - Connection from which data type metadata will be retrieved.
Returns:
true if all necessary jdbc types could be mapped or false otherwise.
Throws:
java.sql.SQLException

mapTypes

public boolean mapTypes(java.io.InputStream aStream)
                 throws java.io.IOException
Maps JDBC SQL types to database data types.

Specified by:
mapTypes in interface DatabaseInterface
Parameters:
aStream - Input stream of a properties file.
Returns:
true if all necessary jdbc types could be mapped or false otherwise.
Throws:
java.io.IOException
See Also:
Properties.load(InputStream), DatabaseInterface.mapTypes(Properties)

mapTypes

public boolean mapTypes(java.util.Properties properties)
Maps JDBC SQL types to database data types.

Specified by:
mapTypes in interface DatabaseInterface
Parameters:
properties - Properties from which data type metadata will be retrieved.
Returns:
true if all necessary jdbc types could be mapped or false otherwise.
See Also:
DatabaseInterface.set(Properties)

createTable

public void createTable(TableDescriptor aTable,
                        java.sql.Connection aConnection)
                 throws java.sql.SQLException
Creates a table in the database.

Specified by:
createTable in interface DatabaseInterface
Parameters:
aTable - The table descriptor of the table to be created.
aConnection - A connection to the database.
Throws:
java.sql.SQLException

tableExists

public boolean tableExists(java.lang.String aTable,
                           java.sql.Connection aConnection)
                    throws java.sql.SQLException
Checks for table existence.

Specified by:
tableExists in interface DatabaseInterface
Parameters:
aTable - The table name.
aConnection - A connection to the database.
Throws:
java.sql.SQLException

dropTable

public void dropTable(java.lang.String aTable,
                      java.sql.Connection aConnection)
               throws java.sql.SQLException
Drops a table in the database.

Specified by:
dropTable in interface DatabaseInterface
Parameters:
aTable - The table name.
aConnection - A connection to the database.
Throws:
java.sql.SQLException

setDuplicateKeyCodes

public void setDuplicateKeyCodes(java.lang.String codes)
                          throws java.lang.IllegalArgumentException
Sets SQL error codes for duplicate keys.

Specified by:
setDuplicateKeyCodes in interface DatabaseInterface
Parameters:
codes - String containing numeric error codes separated by commas.
Throws:
java.lang.IllegalArgumentException

isDuplicateKeyCode

public boolean isDuplicateKeyCode(int aCode)
Indicates if a vendor error code is a duplicate key error code.

Specified by:
isDuplicateKeyCode in interface DatabaseInterface
Parameters:
aCode - Vendor error code.
Returns:
true if the supplied code is a duplicate key error code; false

setReferentialIntegrityCodes

public void setReferentialIntegrityCodes(java.lang.String codes)
                                  throws java.lang.IllegalArgumentException
Sets SQL error codes for referential integrity errors.

Specified by:
setReferentialIntegrityCodes in interface DatabaseInterface
Parameters:
codes - String containing numeric error codes separated by commas.
Throws:
java.lang.IllegalArgumentException

isReferentialIntegrityCode

public boolean isReferentialIntegrityCode(int aCode)
Indicates if a vendor error code is a referential integrity error code.

Specified by:
isReferentialIntegrityCode in interface DatabaseInterface
Parameters:
aCode - Vendor error code.
Returns:
true if the supplied code is a referential integrity error code; false

connect

public java.sql.Connection connect(java.lang.String anUrl,
                                   java.lang.String anUser,
                                   java.lang.String aPassword)
                            throws java.sql.SQLException
Connects to the database.

Specified by:
connect in interface DatabaseInterface
Parameters:
anUrl - A database url of the form jdbc:subprotocol:subname.
anUser - The database user on whose behalf the connections will be made.
aPassword - The user's password.
Throws:
java.sql.SQLException