Package com.storedobject.core
Class SQLConnector
java.lang.Object
com.storedobject.core.SQLConnector
- Direct Known Subclasses:
SQLConnector
The database driver interface. In order to write a database driver that works with the stored objects system,
one of the tasks is to create a concrete class that extends this abstract class. The class should be packaged in a
package like "com.storedobject.database.DDD" where DDD is the name of the database driver. For example, the Sybase
Adaptive Server Enterprise driver package is "com.storedobject.database.ase" and the Oracle driver package is
"com.storedobject.database.oracle".
- Author:
- Syam
- See Also:
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected static Properties
The connection properties used to connect to the database via JDBC driver.protected static String
The connection string used to connect via the JDBC driver.protected static String
The name of the database.protected static String
The name of the database master.static boolean
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected boolean
See if canceling of a connection is possible or not.protected void
cancelConnection
(com.storedobject.core.SQLConnector.DBConnection c) Cancels a given SQL connection.static void
changePassword
(String oldPassword, String newPassword) A call to this method needs to be made whenever the password is changed.protected void
closeConnection
(com.storedobject.core.SQLConnector.DBConnection c) Closes a given SQL connection.protected com.storedobject.core.SQLConnector.DBConnection
createConnection
(boolean master) Create a new SQL connection.protected abstract Process
doDataDump
(String securityPassword, boolean sql, String dbName) protected abstract Process
doDataRestore
(String securityPassword, String dbName) static void
Dump debug information on busy connections older than 5 minutes.static void
dumpDebugInfo
(int ageInMinutes) Dump debug information on busy connections.protected static int
Gets the number of busy connections as of now.final com.storedobject.core.SQLConnector.DBConnection
getConnection
(RawSQL sql, boolean master) Gets a connection.static String
Gets the name of the database master.static String
Gets the name of the database.Get debug information on busy connections older than 5 minutes.getDebugInfo
(int ageInMinutes) Get debug information on busy connections.protected final Exception
getException
(String message) Gets an equivalent exception from the StoredObject system.protected static int
Gets the number of free connections available in the pool as of now.static Logger
static int
Gets the current connection pool size.static Statement
getStatement
(String user, String password) Gets a statement object for execution of SQL for a particular login/password pair.protected boolean
handleError
(int code) Handles errors.final void
Handles all SQL exceptions from SQL statement execution.protected boolean
handleSQLMessage
(String message) Handles SQL error message.protected boolean
handleSQLState
(String state) Handles SQL states.static void
static void
This method releases all SQL connections.final void
releaseConnection
(com.storedobject.core.SQLConnector.DBConnection connection) This method releases a given SQL connection.static void
static void
setPoolSize
(int size) Sets the pool size for the connection pool.
-
Field Details
-
debug
public static boolean debug -
database
The name of the database. This value may be set by the derived class. -
databaseMaster
The name of the database master. This value may be set by the derived class. This could be same as database. -
connectionString
The connection string used to connect via the JDBC driver. This value MUST be set by the derived class. -
connectionProperties
The connection properties used to connect to the database via JDBC driver. The necessary property values MUST be set by the derived class.
-
-
Constructor Details
-
SQLConnector
public SQLConnector()Constructor that initializes the necessary stuff.
-
-
Method Details
-
getLogger
-
setLogger
-
log
-
setPoolSize
public static void setPoolSize(int size) Sets the pool size for the connection pool.- Parameters:
size
- Maximum number of connections to be kept alive.
-
getPoolSize
public static int getPoolSize()Gets the current connection pool size.- Returns:
- Pool size.
-
changePassword
-
getDatabaseName
-
getDatabaseMasterName
Gets the name of the database master.- Returns:
- The database master name.
-
releaseAllConnections
public static void releaseAllConnections()This method releases all SQL connections. -
releaseConnection
public final void releaseConnection(com.storedobject.core.SQLConnector.DBConnection connection) This method releases a given SQL connection.- Parameters:
connection
- The connection to be released.
-
getConnection
public final com.storedobject.core.SQLConnector.DBConnection getConnection(RawSQL sql, boolean master) Gets a connection. If a free connection is available in the pool, that will be returned. Otherwise, a new connection is created and returned.- Parameters:
sql
- AssociatedRawSQL
instance.master
- Whether master or not.- Returns:
- A SQL connection.
-
getDebugInfo
-
getDebugInfo
-
dumpDebugInfo
public static void dumpDebugInfo()Dump debug information on busy connections older than 5 minutes. -
dumpDebugInfo
public static void dumpDebugInfo(int ageInMinutes) Dump debug information on busy connections.- Parameters:
ageInMinutes
- Age in minutes.
-
getStatement
Gets a statement object for execution of SQL for a particular login/password pair.- Parameters:
user
- The name of the user.password
- The password.- Returns:
- The statement object.
- Throws:
Exception
- If any database error occurs.
-
getBusyConnectionCount
protected static int getBusyConnectionCount()Gets the number of busy connections as of now.- Returns:
- The number of busy connections.
-
getFreeConnectionCount
protected static int getFreeConnectionCount()Gets the number of free connections available in the pool as of now.- Returns:
- The number of free connections.
-
createConnection
protected com.storedobject.core.SQLConnector.DBConnection createConnection(boolean master) Create a new SQL connection.- Parameters:
master
- Whether to create a master connection or not.- Returns:
- The newly created SQL connection.
-
closeConnection
protected void closeConnection(com.storedobject.core.SQLConnector.DBConnection c) Closes a given SQL connection.- Parameters:
c
- The connection to close.
-
cancelConnection
protected void cancelConnection(com.storedobject.core.SQLConnector.DBConnection c) Cancels a given SQL connection.- Parameters:
c
- The connection to cancel.
-
canCancel
protected boolean canCancel()See if canceling of a connection is possible or not. (Some databases do not support/implement cancel operation).- Returns:
- True if cancel is possible. Otherwise, false. The default is "false".
-
handleError
Handles errors. Any database error can cause the generation of an error code. This method is called when such errors occur. If the error needs to be ignored, this method can return "true".- Parameters:
code
- The error code.- Returns:
- True if the error needs to be ignored, otherwise false. The default behaviour is to return "false".
- Throws:
Exception
- It can raise another exception to redirect the exception handling.
-
handleSQLState
Handles SQL states. Any database error can cause the generation of a SQL state code. This method is called when such errors occur. If the error needs to be ignored, this method can return "true".- Parameters:
state
- The SQL state code.- Returns:
- True if the error needs to be ignored, otherwise false. The default behaviour is to return "false".
- Throws:
Exception
- It can raise another exception to redirect the exception handling.
-
handleSQLMessage
Handles SQL error message. Any database error can cause the generation of a SQL error message. This method is called when such errors occur. If the error needs to be ignored, this method can return "true".- Parameters:
message
- The SQL error message.- Returns:
- True if the error needs to be ignored, otherwise false. The default behaviour is to return "false".
- Throws:
Exception
- It can raise another exception to redirect the exception handling.
-
handleException
Handles all SQL exceptions from SQL statement execution.- Parameters:
w
- The SQL exception.- Throws:
Error_Running_SQL
- It can throw exceptions with error details.
-
getException
Gets an equivalent exception from the StoredObject system. For example, a database error message like "Account Not Found" will throw an Account_Not_Found() exception.- Parameters:
message
- The message to translate to an exception.- Returns:
- The exception value.
-
doDataDump
-
doDataRestore
-