Holger's
Java API

com.antelmann.sql
Class SQLDatabase

java.lang.Object
  extended by com.antelmann.db.AbstractDatabase<Connection>
      extended by com.antelmann.sql.SQLDatabase
All Implemented Interfaces:
Database<Connection>, LoginListener, LoggerProvider, QueryMechanism, Closeable, EventListener
Direct Known Subclasses:
OpenGeoDB, SQLFactoryDatabase

public class SQLDatabase
extends AbstractDatabase<Connection>

implements a database using a SQLTransaction instance based on a JDBC connection. The given Connection will be set to disable autoCommit.

Author:
Holger Antelmann
See Also:
SQLTransaction

Nested Class Summary
 
Nested classes/interfaces inherited from interface com.antelmann.db.LoginListener
LoginListener.Adapter
 
Field Summary
protected  int connectionCheckTimeout
           
 
Constructor Summary
SQLDatabase(Connection con)
           
SQLDatabase(Connection con, User user, LogWriter logWriter)
          the logWriter remains unchecked regarding access during a non-active transaction
 
Method Summary
 void close()
           
protected  DBTransaction createTransaction()
          called by the constructor
 DBClassStore<RowItem> generateGenericClassStore(String table, String idColumn)
          generates and returns a generic wrapped DBClassStore on RowItem objects; the store is not put into the database.
 GenericPropertyEntryStore<RowItem> generateGenericClassStore(String table, String idColumn, String displayColumn)
          generates and returns a generic wrapped DBClassStore on RowItem objects; the store is not put into the database (as multiple stores working on different tables could map to the RowItem class).
 String[] getColumnNames(Class<? extends DBEntry> type)
          returns all column names that are mapped by the standard query by taking advantage of the MappingInfo interface - if applicable
 Hashtable<String,Integer> getColumnTypes(Class<? extends DBEntry> type)
          returns all column names mapped to their respective Types.
 String getDisplayColumn(Class<? extends DBEntry> type)
          takes advantage of the MappingInfo interface - if applicable
protected  ConnectionHelper getHelper()
           
 String getIDColumn(Class<? extends DBEntry> type)
          takes advantage of the MappingInfo interface - if applicable
<T extends DBEntry>
T
getRandomEntry(Class<T> type, Filter<? super T> filter)
           
 String getTableName(Class<? extends DBEntry> type)
          takes advantage of the MappingInfo interface - if applicable
 String[] getTableNames()
           
 String getTableQuery(Class<? extends DBEntry> type)
          takes advantage of the MappingInfo interface - if applicable
 DBTransaction getTransaction()
          provides access to the DBTransaction, which coordinates all access to the Resources via DBClassStore.
protected  boolean isValid(Connection con)
          by overwriting this method you can customize the way a connection is checked for being valid by overwriting this method (note that this default implementation is not supported by the Sun JDBC/ODBC bridge).
<E extends DBEntry,I>
I
queryStoreForInterface(Class<E> type, Class<I> desiredInterface)
          additionally supports SQLColumnInfo via SQLColumnInfoStore for every store supporting MappingInfo
 
Methods inherited from class com.antelmann.db.AbstractDatabase
addConfigListener, addStoreListener, checkAccessRight, checkTransactionActive, clearAllData, contains, contains, count, countStubs, delete, delete, delete, extractInterface, failedLogin, finalize, fireStoreChanges, getAccessController, getAvailableClassStores, getConfigListeners, getCurrentUser, getDatabaseService, getEntry, getEntry, getEntry, getFirstEntry, getFirstStub, getLogger, getOriginalClassStore, getRandomEntry, getRandomStub, getStore, getStoreForEntry, getStoreListeners, getStub, getStub, hasAutomatedTransactions, isEnsureTransactions, isVersioningEnabled, listEntries, listEntries, listStubs, loginPerformed, logoutPerformed, mapEntries, mapStubs, putClassStore, query, remove, removeConfigListener, removeStoreListener, setAccessController, setAutomatedTransactions, setCurrentUser, setEnsureTransactions, setVersioningEnabled, store
 
Methods inherited from class java.lang.Object
clone, equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

connectionCheckTimeout

protected int connectionCheckTimeout
Constructor Detail

SQLDatabase

public SQLDatabase(Connection con)
            throws SQLException
Throws:
SQLException

SQLDatabase

public SQLDatabase(Connection con,
                   User user,
                   LogWriter logWriter)
            throws SQLException
the logWriter remains unchecked regarding access during a non-active transaction

Throws:
SQLException
Method Detail

createTransaction

protected DBTransaction createTransaction()
                                   throws SQLException
called by the constructor

Throws:
SQLException

getHelper

protected final ConnectionHelper getHelper()

getTransaction

public DBTransaction getTransaction()
Description copied from interface: Database
provides access to the DBTransaction, which coordinates all access to the Resources via DBClassStore. The returned DBTransaction is always the same object for a particular database.


close

public void close()
           throws IOException
Specified by:
close in interface Closeable
Overrides:
close in class AbstractDatabase<Connection>
Throws:
IOException

isValid

protected boolean isValid(Connection con)
                   throws SQLException
by overwriting this method you can customize the way a connection is checked for being valid by overwriting this method (note that this default implementation is not supported by the Sun JDBC/ODBC bridge).

Throws:
SQLException
See Also:
Connection.isValid(int), connectionCheckTimeout

generateGenericClassStore

public DBClassStore<RowItem> generateGenericClassStore(String table,
                                                       String idColumn)
                                                throws DatabaseException
generates and returns a generic wrapped DBClassStore on RowItem objects; the store is not put into the database.

Throws:
DatabaseException
See Also:
GenericPropertyEntryStore, DBClassStoreWrapper

generateGenericClassStore

@Warning(value="NOTE THAT CALLS ON THE INTERFACE STILL NEED TO BE SYNCHRONIZED WITH THE TRANSACTION!")
@Todo(value="support inserts with an idFactory")
public GenericPropertyEntryStore<RowItem> generateGenericClassStore(String table,
                                                                                           String idColumn,
                                                                                           String displayColumn)
                                                             throws DatabaseException
generates and returns a generic wrapped DBClassStore on RowItem objects; the store is not put into the database (as multiple stores working on different tables could map to the RowItem class).

Throws:
DatabaseException
See Also:
DBUtils.wrapTransactional(com.antelmann.db.DBTransaction, Object, Class), GenericPropertyEntryStore

getTableNames

public String[] getTableNames()
                       throws DatabaseException
Throws:
DatabaseException

getTableName

public String getTableName(Class<? extends DBEntry> type)
takes advantage of the MappingInfo interface - if applicable


getIDColumn

public String getIDColumn(Class<? extends DBEntry> type)
takes advantage of the MappingInfo interface - if applicable


getTableQuery

public String getTableQuery(Class<? extends DBEntry> type)
takes advantage of the MappingInfo interface - if applicable


getDisplayColumn

public String getDisplayColumn(Class<? extends DBEntry> type)
takes advantage of the MappingInfo interface - if applicable


getColumnNames

public String[] getColumnNames(Class<? extends DBEntry> type)
                        throws DatabaseException
returns all column names that are mapped by the standard query by taking advantage of the MappingInfo interface - if applicable

Throws:
DatabaseException

getColumnTypes

public Hashtable<String,Integer> getColumnTypes(Class<? extends DBEntry> type)
                                         throws DatabaseException
returns all column names mapped to their respective Types. of the MappingInfo interface - if applicable

Throws:
DatabaseException

queryStoreForInterface

public <E extends DBEntry,I> I queryStoreForInterface(Class<E> type,
                                                      Class<I> desiredInterface)
additionally supports SQLColumnInfo via SQLColumnInfoStore for every store supporting MappingInfo

Specified by:
queryStoreForInterface in interface Database<Connection>
Overrides:
queryStoreForInterface in class AbstractDatabase<Connection>
Parameters:
type - the DBEntry-type of the DBClassStore that is to implement the desired interface
desiredInterface - the class of the interface that the store is implementing
Returns:
a proxy to the functionality that the queried store provides or null if either the class store doesn't exist or doesn't support the desired interface.
See Also:
WrappedDBClassStore.exposesInterfaces()

getRandomEntry

@Warning(value="only works properly for classes that are represented by a JDBCRowStore, since it supports an OffsetFilter in the reqired way")
public <T extends DBEntry> T getRandomEntry(Class<T> type,
                                                         Filter<? super T> filter)
                                 throws DatabaseException
Overrides:
getRandomEntry in class AbstractDatabase<Connection>
Throws:
DatabaseException


(c) Holger Antelmann since 2001- all rights reserved (contact: info@antelmann.com)
see www.antelmann.com/developer for further details and available downloads