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, toStringclone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitisInitialized, isRunningprotected 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)
DatabaseInterfacesqlEscape in interface DatabaseInterfacestr - The string to be escaped.public java.lang.String sqlEscapeLen(java.lang.String str,
int length)
DatabaseInterfacesqlEscapeLen in interface DatabaseInterfacestr - The string to be escaped.length - The maximum length.public java.lang.String formatTimestamp(long time)
DatabaseInterfaceformatTimestamp in interface DatabaseInterfacetime - The time in milliseconds.public DatabaseInterface.Rows makeRows(java.sql.ResultSet rs) throws java.sql.SQLException
java.sql.SQLExceptionpublic DatabaseInterface.Rows query(java.lang.String query) throws java.sql.SQLException
DatabaseInterfacequery in interface DatabaseInterfacequery - The query to execute.java.sql.SQLExceptionpublic int update(java.lang.String query)
throws java.sql.SQLException
DatabaseInterfaceupdate in interface DatabaseInterfacequery - The update statement to execute.java.sql.SQLExceptionpublic int update(java.lang.String query,
DatabaseInterface.Rows[] generatedKeys)
throws java.sql.SQLException
java.sql.SQLExceptionpublic java.lang.Object insertAutoIncrement(java.lang.String query)
throws java.sql.SQLException
DatabaseInterfaceinsertAutoIncrement in interface DatabaseInterfacequery - The insert statement.java.sql.SQLExceptionprotected void initConnectionPool()
public void init(ModuleManager manager, java.util.HashMap<java.lang.String,java.lang.Object> settings) throws ModuleException
ModuleInitialises 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 Moduleinit in class AbstractModulemanager - The module manager handling this module. You may keep a
reference to it if needed.ModuleExceptionpublic java.util.Collection<Module> getDependencies(ModuleManager manager) throws ModuleException
ModulegetDependencies in interface ModulegetDependencies in class AbstractModulemanager - The module manager handling this module.ModuleExceptionpublic void start(ModuleManager manager) throws ModuleException
Modulestart in interface Modulestart in class AbstractModulemanager - The module manager handling this module.ModuleExceptionpublic void stop(ModuleManager manager)
Modulestop in interface Modulestop in class AbstractModulemanager - The module manager handling this module.public DatabaseInterface.PreparedDatabaseStatement prepareStatement(java.lang.String query) throws java.sql.SQLException
DatabaseInterfaceprepareStatement in interface DatabaseInterfacequery - The statement to prepare.java.sql.SQLExceptionpublic void addDatabaseConnectionListener(DatabaseInterface.DatabaseConnectionListener l)
DatabaseInterfaceaddDatabaseConnectionListener in interface DatabaseInterfacepublic void removeDatabaseConnectionListener(DatabaseInterface.DatabaseConnectionListener l)
DatabaseInterfaceremoveDatabaseConnectionListener in interface DatabaseInterfaceprotected void fireDatabaseStarted()
protected void fireDatabaseClosed()
Copyright 2004-2015 Wandora Team