public class GenericDatabaseInterface extends AbstractModule implements DatabaseInterface
Modifier and Type | Class and Description |
---|---|
protected class |
GenericDatabaseInterface.GenericPreparedDatabaseStatement |
DatabaseInterface.DatabaseConnectionListener, DatabaseInterface.PreparedDatabaseStatement, DatabaseInterface.Row, DatabaseInterface.Rows
Modifier and Type | Field and Description |
---|---|
protected org.apache.commons.dbcp.BasicDataSource |
connectionPool |
protected java.lang.String |
connectionString |
protected java.lang.String |
driver |
protected ListenerList<DatabaseInterface.DatabaseConnectionListener> |
listeners |
protected java.lang.String |
password |
protected java.lang.String |
userName |
autoStart, isInitialized, isRunning, logging, loggingModule, moduleManager
Constructor and Description |
---|
GenericDatabaseInterface() |
Modifier and Type | Method and Description |
---|---|
void |
addDatabaseConnectionListener(DatabaseInterface.DatabaseConnectionListener l)
Adds a database connection listener that will be notified when
a database connection is established or closed.
|
protected void |
fireDatabaseClosed() |
protected void |
fireDatabaseStarted() |
java.lang.String |
formatTimestamp(long time)
Makes a time stamp value out of a milliseconds time.
|
java.util.Collection<Module> |
getDependencies(ModuleManager manager)
Returns all the modules this module depends on.
|
void |
init(ModuleManager manager,
java.util.HashMap<java.lang.String,java.lang.Object> settings)
Initialises the module.
|
protected void |
initConnectionPool() |
java.lang.Object |
insertAutoIncrement(java.lang.String query)
Inserts a row with an auto increment field and returns the
automatically assigned value.
|
DatabaseInterface.Rows |
makeRows(java.sql.ResultSet rs) |
DatabaseInterface.PreparedDatabaseStatement |
prepareStatement(java.lang.String query)
Prepares a statement for later execution.
|
DatabaseInterface.Rows |
query(java.lang.String query)
Executes a database query and returns the results.
|
void |
removeDatabaseConnectionListener(DatabaseInterface.DatabaseConnectionListener l)
Removes a database connection listener.
|
java.lang.String |
sqlEscape(java.lang.String str)
Escapes a string so that it can then be safely used as part of a
query.
|
java.lang.String |
sqlEscapeLen(java.lang.String str,
int length)
Escapes a string so that it can then be safely used as part of a
query with a maximum length of the returned string.
|
void |
start(ModuleManager manager)
Starts the module.
|
void |
stop(ModuleManager manager)
Stops the module.
|
int |
update(java.lang.String query)
Executes an update statement.
|
int |
update(java.lang.String query,
DatabaseInterface.Rows[] generatedKeys) |
isInitialized, isRunning, requireLogging, toString
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
isInitialized, isRunning
protected ListenerList<DatabaseInterface.DatabaseConnectionListener> listeners
protected java.lang.String driver
protected java.lang.String connectionString
protected java.lang.String userName
protected java.lang.String password
protected org.apache.commons.dbcp.BasicDataSource connectionPool
public java.lang.String sqlEscape(java.lang.String str)
DatabaseInterface
sqlEscape
in interface DatabaseInterface
str
- The string to be escaped.public java.lang.String sqlEscapeLen(java.lang.String str, int length)
DatabaseInterface
sqlEscapeLen
in interface DatabaseInterface
str
- The string to be escaped.length
- The maximum length.public java.lang.String formatTimestamp(long time)
DatabaseInterface
formatTimestamp
in interface DatabaseInterface
time
- The time in milliseconds.public DatabaseInterface.Rows makeRows(java.sql.ResultSet rs) throws java.sql.SQLException
java.sql.SQLException
public DatabaseInterface.Rows query(java.lang.String query) throws java.sql.SQLException
DatabaseInterface
query
in interface DatabaseInterface
query
- The query to execute.java.sql.SQLException
public int update(java.lang.String query) throws java.sql.SQLException
DatabaseInterface
update
in interface DatabaseInterface
query
- The update statement to execute.java.sql.SQLException
public int update(java.lang.String query, DatabaseInterface.Rows[] generatedKeys) throws java.sql.SQLException
java.sql.SQLException
public java.lang.Object insertAutoIncrement(java.lang.String query) throws java.sql.SQLException
DatabaseInterface
insertAutoIncrement
in interface DatabaseInterface
query
- The insert statement.java.sql.SQLException
protected void initConnectionPool()
public void init(ModuleManager manager, java.util.HashMap<java.lang.String,java.lang.Object> settings) throws ModuleException
Module
Initialises the module. After constructor, this is the first method called in the life cycle of a module. It should not perform anything time consuming or anything with notable outside side effects. It should only read the parameters and initialise the module so that it can later be started. Note that a module being initialised doesn't mean that it necessarily will ever be started.
A ModuleException may be thrown if something vital is missing from the parameters or they are not sensible. In some cases you may not want to throw an exception even if vital initialisation information is missing. If, for example, it is possible that the module is initialised in some other way between the init and the start method calls. A ModuleException may also be thrown at the start method if the module is still not initialised.
init
in interface Module
init
in class AbstractModule
manager
- The module manager handling this module. You may keep a
reference to it if needed.ModuleException
public java.util.Collection<Module> getDependencies(ModuleManager manager) throws ModuleException
Module
getDependencies
in interface Module
getDependencies
in class AbstractModule
manager
- The module manager handling this module.ModuleException
public void start(ModuleManager manager) throws ModuleException
Module
start
in interface Module
start
in class AbstractModule
manager
- The module manager handling this module.ModuleException
public void stop(ModuleManager manager)
Module
stop
in interface Module
stop
in class AbstractModule
manager
- The module manager handling this module.public DatabaseInterface.PreparedDatabaseStatement prepareStatement(java.lang.String query) throws java.sql.SQLException
DatabaseInterface
prepareStatement
in interface DatabaseInterface
query
- The statement to prepare.java.sql.SQLException
public void addDatabaseConnectionListener(DatabaseInterface.DatabaseConnectionListener l)
DatabaseInterface
addDatabaseConnectionListener
in interface DatabaseInterface
public void removeDatabaseConnectionListener(DatabaseInterface.DatabaseConnectionListener l)
DatabaseInterface
removeDatabaseConnectionListener
in interface DatabaseInterface
protected void fireDatabaseStarted()
protected void fireDatabaseClosed()
Copyright 2004-2015 Wandora Team