Package adams.db
Class AbstractIndexedTable
- java.lang.Object
-
- adams.core.logging.LoggingObject
-
- adams.db.generic.SQL
-
- adams.db.AbstractTable
-
- adams.db.AbstractIndexedTable
-
- All Implemented Interfaces:
LoggingSupporter,SizeOfHandler,DatabaseConnectionProvider,DatabaseConnectionUser,SQLIntf,TableInterface,DatabaseConnectionChangeListener,Serializable
- Direct Known Subclasses:
BulkInsertTable,LogT,ReportTableByDBID,ReportTableByID
public abstract class AbstractIndexedTable extends AbstractTable
Class to implement the features of a database table. Subclass with column descriptions- Author:
- dale
- See Also:
- Serialized Form
-
-
Field Summary
Fields Modifier and Type Field Description protected booleanm_inithas this object been initialised.-
Fields inherited from class adams.db.AbstractTable
FILENAME, m_AnsiQuotes, m_Properties, m_TableName
-
Fields inherited from class adams.db.generic.SQL
m_DatabaseConnection, m_Debug, m_Queries, m_Quirks, m_TableManager
-
Fields inherited from class adams.core.logging.LoggingObject
m_Logger, m_LoggingIsEnabled, m_LoggingLevel
-
Fields inherited from interface adams.db.SQLIntf
FAKE_TABLE_NAME
-
-
Constructor Summary
Constructors Modifier Constructor Description protectedAbstractIndexedTable(AbstractDatabaseConnection dbcon, String tableName)Constructor.
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description protected booleancolumnsMatch(ColumnMapping cm, boolean print, boolean addMissing)Determine if columns (name & datatype) of table match table specification.protected booleancolumnsMatchTest(ColumnMapping cm, boolean print, boolean tryAgain, boolean addMissing)Determine if columns (name & datatype) of table match table specification.protected booleancreate()Create the table in database according to column and index specs.StringgetAllColumns()Returns the SELECT part with all columns listed.protected abstract ColumnMappinggetColumnMapping()Implement this method to return column names and data types.protected abstract IndicesgetIndices()Implement this method to return required indices for this table.static String[]getTables()Returns a list with classnames of tables.booleaninit()Initialise table.static voidinitTables(AbstractDatabaseConnection dbcon)Initializes all tables.booleanisThere(String condition)Returns true if this table holds data that satisfies 'condition'.protected booleanpostCreate()Optional post-create hook for filling the table with initial values.ResultSetselect(String columns)Do a select on given columns for all data in table.ResultSetselect(String columns, String where)Do a select on given columns for all data in table, with condition.ResultSetselectDistinct(String columns)Do a select distinct on given columns for all data in table, with condition.ResultSetselectDistinct(String columns, String where)Do a select distinct on given columns for all data in table, with condition.booleantruncate()Empty table.intupdate(String updateString, String where)Update table.-
Methods inherited from class adams.db.AbstractTable
columnExists, databaseConnectionStateChanged, getProperties, getQueries, getTableName, getTablePrefix, isEnabled, quoteName, tableExists, toString, useAnsiQuotes
-
Methods inherited from class adams.db.generic.SQL
columnExists, doSelect, drop, execute, executeGeneratedKeys, getDatabaseConnection, getDebug, getMaxColumnNameLength, getResultSet, getSimpleResultSet, prepareStatement, prepareStatement, prepareStatement, select, selectDistinct, selectDouble, selectInt, selectLong, selectString, selectStrings, setDebug, singleton, tableExists, truncate, update, updatePrefix, updateTableName
-
Methods inherited from class adams.core.logging.LoggingObject
configureLogger, getLogger, getLoggingLevel, initializeLogging, isLoggingEnabled, sizeOf
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface adams.core.logging.LoggingSupporter
getLogger, isLoggingEnabled
-
-
-
-
Constructor Detail
-
AbstractIndexedTable
protected AbstractIndexedTable(AbstractDatabaseConnection dbcon, String tableName)
Constructor.- Parameters:
dbcon- the database context this table is used intableName- the name of the table
-
-
Method Detail
-
getIndices
protected abstract Indices getIndices()
Implement this method to return required indices for this table.- Returns:
- Indices
-
getColumnMapping
protected abstract ColumnMapping getColumnMapping()
Implement this method to return column names and data types.- Returns:
- Column Mapping
-
getAllColumns
public String getAllColumns()
Returns the SELECT part with all columns listed.- Returns:
- the SELECT part
-
columnsMatchTest
protected boolean columnsMatchTest(ColumnMapping cm, boolean print, boolean tryAgain, boolean addMissing)
Determine if columns (name & datatype) of table match table specification.- Parameters:
cm- the column mapping to useprint- whether to print error messages etctryAgain- whether to try againaddMissing- whether to add the missing columns (if possible)- Returns:
- columns match?
-
columnsMatch
protected boolean columnsMatch(ColumnMapping cm, boolean print, boolean addMissing)
Determine if columns (name & datatype) of table match table specification.- Parameters:
cm- the column mapping to useprint- whether to print error messages etcaddMissing- whether to add missing columns if possible- Returns:
- columns match?
-
init
public boolean init()
Initialise table. Create if necessary, else compare with spec.- Specified by:
initin classAbstractTable- Returns:
- success?
-
create
protected boolean create()
Create the table in database according to column and index specs.- Returns:
- success?
-
postCreate
protected boolean postCreate()
Optional post-create hook for filling the table with initial values. The default implementation does nothing and just returns true.- Returns:
- true if successfully run
-
isThere
public boolean isThere(String condition)
Returns true if this table holds data that satisfies 'condition'.- Parameters:
condition- boolean SQL eg "JOBNO=100 AND SAMPLENO=2"- Returns:
- true if condition holds for tablename
-
update
public int update(String updateString, String where) throws Exception
Update table.- Parameters:
updateString- comma separated updates. e.g weight='80',height=180where- condition. e.g name='bob smith'- Returns:
- number of rows affected
- Throws:
Exception- if something goes wrong
-
truncate
public boolean truncate()
Empty table.- Returns:
- success?
-
select
public ResultSet select(String columns) throws Exception
Do a select on given columns for all data in table.- Parameters:
columns- comma separated column list- Returns:
- resulset of data
- Throws:
Exception- if something goes wrong
-
select
public ResultSet select(String columns, String where) throws Exception
Do a select on given columns for all data in table, with condition.- Parameters:
columns- columns to selectwhere- condition- Returns:
- resultset of data
- Throws:
Exception- if something goes wrong
-
selectDistinct
public ResultSet selectDistinct(String columns) throws Exception
Do a select distinct on given columns for all data in table, with condition.- Parameters:
columns- columns to select- Returns:
- resultset of data
- Throws:
Exception- if something goes wrong
-
selectDistinct
public ResultSet selectDistinct(String columns, String where) throws Exception
Do a select distinct on given columns for all data in table, with condition.- Parameters:
columns- columns to selectwhere- condition- Returns:
- resultset of data
- Throws:
Exception- if something goes wrong
-
getTables
public static String[] getTables()
Returns a list with classnames of tables.- Returns:
- the table classnames
-
initTables
public static void initTables(AbstractDatabaseConnection dbcon)
Initializes all tables.- Parameters:
dbcon- the database context
-
-