Package adams.db.generic
Class SpectrumT
- java.lang.Object
-
- adams.core.logging.LoggingObject
-
- adams.db.generic.SQL
-
- adams.db.AbstractTable
-
- adams.db.AbstractIndexedTable
-
- adams.db.generic.SpectrumT
-
- All Implemented Interfaces:
adams.core.logging.LoggingSupporter
,adams.core.SizeOfHandler
,adams.db.DatabaseConnectionProvider
,adams.db.DatabaseConnectionUser
,adams.db.DataProvider<Spectrum>
,SpectrumIntf
,adams.db.SQLIntf
,adams.db.TableInterface
,adams.event.DatabaseConnectionChangeListener
,Serializable
public abstract class SpectrumT extends adams.db.AbstractIndexedTable implements SpectrumIntf
Manages Spectrum tables. Spectrums can be cached, see thePerformance
class.- Author:
- dale
- See Also:
- Serialized Form
-
-
Field Summary
Fields Modifier and Type Field Description protected boolean
m_BulkAddStopped
whether to stop the bulk add.protected static adams.db.TableManager<SpectrumT>
m_TableManager
the table manager.-
Fields inherited from class adams.db.AbstractTable
FILENAME, m_AnsiQuotes, m_Properties, m_TableName
-
Fields inherited from class adams.core.logging.LoggingObject
m_Logger, m_LoggingIsEnabled, m_LoggingLevel
-
Fields inherited from interface adams.db.SpectrumIntf
MAX_NUM_SPECTRUMS_CACHED, TABLE_NAME
-
-
Constructor Summary
Constructors Modifier Constructor Description protected
SpectrumT(adams.db.AbstractDatabaseConnection dbcon)
Constructor - initalise with database connection.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description Integer
add(Spectrum sp)
Adds a spectrum to the database.Integer
add(Spectrum sp, boolean storeWaveNo)
Adds a spectrum to the database.protected StringBuilder
addQuery(Spectrum sp, boolean storeWaveNo)
Generates the query string for adding a spectrum.boolean
bulkAdd(Spectrum[] sp, boolean storeWaveNo, int batchSize, boolean autoCommit, boolean newConnection)
Stores the spectra in the database.boolean
exists(int id)
Checks whether the container exists in the database.boolean
exists(String id)
Checks whether the container exists in the database.boolean
exists(String id, String format)
Checks whether the container exists in the database.protected adams.db.ColumnMapping
getColumnMapping()
Return columns for this table.int
getDatabaseID(String id)
Returns the database ID for given spectrum ID.int
getDatabaseID(String sample_id, String format)
Returns the database ID for given sample ID and type.protected adams.db.indices.Indices
getIndices()
Return indices for this table.static SpectrumIntf
getSingleton(adams.db.AbstractDatabaseConnection dbcon)
Returns the singleton of the table (active).List<String>
getValues(String[] fields, SpectrumIDConditions cond)
returns all the specified fields in the database, separated by TABs.List<String>
getValues(String[] fields, String where, SpectrumIDConditions cond)
returns all the specified fields in the database, separated by TABs.List<String>
getValues(String[] fields, String tables, String where, SpectrumIDConditions cond)
returns all the specified fields in the database, separated by TABs.boolean
init()
Initialise table & sub-tables.static void
initTable(adams.db.AbstractDatabaseConnection dbcon)
Initializes the table.Spectrum
load(int auto_id)
Load a spectrum with given database ID.Spectrum
load(String id)
Load a spectrum with given ID.Spectrum
load(String sample_id, String format)
Load a spectrum with given sample ID and type.Spectrum
loadFromDB(int auto_id, String rlike, boolean raw)
Load a spectrum from DB with given auto_id.Spectrum
loadFromDB(String sample_id, String format, boolean raw)
Load a spectrum from DB with given sample_id and format.Spectrum
loadRaw(int auto_id)
Load a data container with given auto_id, without passing it through the global filter.Spectrum
loadRaw(String sample_id, String format)
Load a spectrum with given sample ID and type, without filtering through the global container filter.protected String
pointsToString(Spectrum sp, boolean storeWaveNo)
Turns the spectrum points into a string to be stored in the database.boolean
remove(int id, boolean keepReport)
Removes the spectrum and its sample data.boolean
remove(String sample_id, boolean keepReport)
Removes the spectrum and its sample data.boolean
remove(String sample_id, String format, boolean keepReport)
Removes the spectrum and its sample data.protected Spectrum
resultsetToSpectrum(ResultSet rs, boolean raw)
Turns a ResultSet into a spectrum.void
stopBulkAdd()
Interrupts a currently running bulk store, if possible.-
Methods inherited from class adams.db.AbstractIndexedTable
columnsMatch, columnsMatchTest, create, getAllColumns, getTables, initTables, isThere, postCreate, select, select, selectDistinct, selectDistinct, truncate, update
-
Methods inherited from class adams.db.AbstractTable
columnExists, databaseConnectionStateChanged, getProperties, getQueries, getTableName, 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.db.SpectrumIntf
getSampleDataHandler
-
-
-
-
Field Detail
-
m_TableManager
protected static adams.db.TableManager<SpectrumT> m_TableManager
the table manager.
-
m_BulkAddStopped
protected boolean m_BulkAddStopped
whether to stop the bulk add.
-
-
Method Detail
-
init
public boolean init()
Initialise table & sub-tables.- Specified by:
init
in interfaceSpectrumIntf
- Overrides:
init
in classadams.db.AbstractIndexedTable
- Returns:
- success?
-
exists
public boolean exists(int id)
Checks whether the container exists in the database.- Specified by:
exists
in interfaceadams.db.DataProvider<Spectrum>
- Specified by:
exists
in interfaceSpectrumIntf
- Parameters:
id
- the database ID of the data container- Returns:
- true if the container exists
-
exists
public boolean exists(String id)
Checks whether the container exists in the database. UsesSampleData.DEFAULT_FORMAT
as format.- Specified by:
exists
in interfaceadams.db.DataProvider<Spectrum>
- Specified by:
exists
in interfaceSpectrumIntf
- Parameters:
id
- the ID of the data container- Returns:
- true if the container exists
- See Also:
exists(String, String)
-
exists
public boolean exists(String id, String format)
Checks whether the container exists in the database.- Specified by:
exists
in interfaceSpectrumIntf
- Parameters:
id
- the ID of the data container- Returns:
- true if the container exists
-
load
public Spectrum load(int auto_id)
Load a spectrum with given database ID. Get from cache if available- Specified by:
load
in interfaceadams.db.DataProvider<Spectrum>
- Specified by:
load
in interfaceSpectrumIntf
- Parameters:
auto_id
- the database ID- Returns:
- Spectrum, or null if not found
-
load
public Spectrum load(String id)
Load a spectrum with given ID. Get from cache if available UsesSampleData.DEFAULT_FORMAT
as format.- Specified by:
load
in interfaceadams.db.DataProvider<Spectrum>
- Specified by:
load
in interfaceSpectrumIntf
- Parameters:
id
- the ID- Returns:
- Spectrum, or null if not found
- See Also:
load(String, String)
-
load
public Spectrum load(String sample_id, String format)
Load a spectrum with given sample ID and type. Get from cache if available- Specified by:
load
in interfaceSpectrumIntf
- Parameters:
sample_id
- the sample IDformat
- the format- Returns:
- Spectrum, or null if not found
-
loadRaw
public Spectrum loadRaw(int auto_id)
Load a data container with given auto_id, without passing it through the global filter.- Specified by:
loadRaw
in interfaceSpectrumIntf
- Parameters:
auto_id
- the databae ID- Returns:
- the data container, or null if not found
-
loadRaw
public Spectrum loadRaw(String sample_id, String format)
Load a spectrum with given sample ID and type, without filtering through the global container filter.- Specified by:
loadRaw
in interfaceSpectrumIntf
- Parameters:
sample_id
- the sample IDformat
- the format- Returns:
- Spectrum, or null if not found
-
resultsetToSpectrum
protected Spectrum resultsetToSpectrum(ResultSet rs, boolean raw) throws Exception
Turns a ResultSet into a spectrum.- Parameters:
rs
- the ResultSet to useraw
- whether to return the raw spectrum or filter through the global container filter- Returns:
- the spectrum, null in case of an error
- Throws:
Exception
- if something goes wrong
-
loadFromDB
public Spectrum loadFromDB(int auto_id, String rlike, boolean raw)
Load a spectrum from DB with given auto_id.- Specified by:
loadFromDB
in interfaceSpectrumIntf
- Parameters:
auto_id
- the databae IDrlike
- regex for spectrum IDraw
- whether to return the raw spectrum or filter it through the global container filter- Returns:
- Spectrum, or null if not found
-
loadFromDB
public Spectrum loadFromDB(String sample_id, String format, boolean raw)
Load a spectrum from DB with given sample_id and format.- Specified by:
loadFromDB
in interfaceSpectrumIntf
- Parameters:
sample_id
- the sample IDformat
- the formatraw
- whether to return the raw spectrum or filter it through the global container filter- Returns:
- Spectrum, or null if not found
-
getDatabaseID
public int getDatabaseID(String id)
Returns the database ID for given spectrum ID. Get from cache if available UsesSampleData.DEFAULT_FORMAT
as format.- Specified by:
getDatabaseID
in interfaceSpectrumIntf
- Parameters:
id
- the ID- Returns:
- Spectrum, or null if not found
- See Also:
load(String, String)
-
getDatabaseID
public int getDatabaseID(String sample_id, String format)
Returns the database ID for given sample ID and type. Get from cache if available- Specified by:
getDatabaseID
in interfaceSpectrumIntf
- Parameters:
sample_id
- the sample IDformat
- the format- Returns:
- the database ID,
Constants.NO_ID
-
getValues
public List<String> getValues(String[] fields, SpectrumIDConditions cond)
returns all the specified fields in the database, separated by TABs.- Specified by:
getValues
in interfaceSpectrumIntf
- Parameters:
fields
- the field namescond
- the conditions for the retrieval- Returns:
- list of tab-separated values
-
getValues
public List<String> getValues(String[] fields, String where, SpectrumIDConditions cond)
returns all the specified fields in the database, separated by TABs.- Specified by:
getValues
in interfaceSpectrumIntf
- Parameters:
fields
- the field nameswhere
- the where clause, can be nullcond
- the conditions for the retrieval- Returns:
- list of tab-separated values
-
getValues
public List<String> getValues(String[] fields, String tables, String where, SpectrumIDConditions cond)
returns all the specified fields in the database, separated by TABs.- Specified by:
getValues
in interfaceSpectrumIntf
- Parameters:
fields
- the field namestables
- the involved tableswhere
- the where clause, can be nullcond
- the conditions for the retrieval- Returns:
- list of tab-separated values
-
pointsToString
protected String pointsToString(Spectrum sp, boolean storeWaveNo)
Turns the spectrum points into a string to be stored in the database. Format: wave1:ampltd1,wave2:ampltd2,...- Parameters:
sp
- the spectrum to convertstoreWaveNo
- whether to store the wave numbers as well- Returns:
- the generated string
-
addQuery
protected StringBuilder addQuery(Spectrum sp, boolean storeWaveNo)
Generates the query string for adding a spectrum.- Parameters:
sp
- the spectrum to turn into querystoreWaveNo
- whether to store the wave numbers as well- Returns:
- the generated query
-
add
public Integer add(Spectrum sp)
Adds a spectrum to the database. Returns the created auto-id, and sets in Spectrum. Wave numbers get stored.- Specified by:
add
in interfaceadams.db.DataProvider<Spectrum>
- Specified by:
add
in interfaceSpectrumIntf
- Parameters:
sp
- spectrum Header- Returns:
- new ID, or null if fail
-
add
public Integer add(Spectrum sp, boolean storeWaveNo)
Adds a spectrum to the database. Returns the created auto-id, and sets in Spectrum.- Specified by:
add
in interfaceSpectrumIntf
- Parameters:
sp
- the spectrum to addstoreWaveNo
- whether to store the wave numbers as well- Returns:
- new ID, or null if fail
-
bulkAdd
public boolean bulkAdd(Spectrum[] sp, boolean storeWaveNo, int batchSize, boolean autoCommit, boolean newConnection)
Stores the spectra in the database.- Specified by:
bulkAdd
in interfaceSpectrumIntf
- Parameters:
sp
- the spectra to addstoreWaveNo
- whether to store the wave numbers as wellbatchSize
- the maximum number of records in one batchautoCommit
- whether to use auto-commit or not (turning off may impact other transactions!)newConnection
- uses a separate database connection just for this connection (then no auto-commit doesn't affect the rest)- Returns:
- true if successfully inserted/updated
-
stopBulkAdd
public void stopBulkAdd()
Interrupts a currently running bulk store, if possible.- Specified by:
stopBulkAdd
in interfaceSpectrumIntf
-
getColumnMapping
protected adams.db.ColumnMapping getColumnMapping()
Return columns for this table.- Specified by:
getColumnMapping
in classadams.db.AbstractIndexedTable
- Returns:
- database columns
-
getIndices
protected adams.db.indices.Indices getIndices()
Return indices for this table.- Specified by:
getIndices
in classadams.db.AbstractIndexedTable
- Returns:
- indices
-
remove
public boolean remove(String sample_id, boolean keepReport)
Removes the spectrum and its sample data. UsesSampleData.DEFAULT_FORMAT
as format.- Specified by:
remove
in interfaceadams.db.DataProvider<Spectrum>
- Specified by:
remove
in interfaceSpectrumIntf
- Parameters:
sample_id
- the sample ID of the spectrumkeepReport
- if true does not delete associated report- Returns:
- true if no error
- See Also:
remove(String, String, boolean)
-
remove
public boolean remove(String sample_id, String format, boolean keepReport)
Removes the spectrum and its sample data.- Specified by:
remove
in interfaceSpectrumIntf
- Parameters:
sample_id
- the sample ID of the spectrumformat
- the format of the spectrum (eg NIR)keepReport
- if true does not delete associated report- Returns:
- true if no error
-
remove
public boolean remove(int id, boolean keepReport)
Removes the spectrum and its sample data.- Specified by:
remove
in interfaceadams.db.DataProvider<Spectrum>
- Specified by:
remove
in interfaceSpectrumIntf
- Parameters:
id
- the ID of the spectrum to remove from the databasekeepReport
- if true does not delete associated report- Returns:
- true if no error
-
initTable
public static void initTable(adams.db.AbstractDatabaseConnection dbcon)
Initializes the table. Used by the "InitializeTables" tool.- Parameters:
dbcon
- the database context
-
getSingleton
public static SpectrumIntf getSingleton(adams.db.AbstractDatabaseConnection dbcon)
Returns the singleton of the table (active).- Parameters:
dbcon
- the database connection to get the singleton for- Returns:
- the singleton
-
-