Class SQLListener
- java.lang.Object
-
- org.bridgedb.sql.SQLBase
-
- org.bridgedb.sql.SQLListener
-
- All Implemented Interfaces:
MappingListener
- Direct Known Subclasses:
SQLIdMapper
public class SQLListener extends SQLBase implements MappingListener
This is the root class of the SQL stack. It handles the creation of all the tables and handles all inserts, except those only required for URL and UriSpaces See CreateSQLTables method for an explanation of the tables.- Author:
- Christian
-
-
Field Summary
Fields Modifier and Type Field Description protected StringautoIncrementprotected static intFULLNAME_LENGTHstatic StringID_COLUMN_NAMEprotected static intID_LENGTHstatic StringMAPPING_SET_ID_COLUMN_NAMEstatic StringMAPPING_SET_TABLE_NAMEprotected static intMAPPING_URI_LENGTHprotected static StringSOURCE_DATASOURCE_COLUMN_NAMEstatic intSQL_COMPAT_VERSIONprotected static intSYSCODE_LENGTHprotected static StringTARGET_DATASOURCE_COLUMN_NAME-
Fields inherited from class org.bridgedb.sql.SQLBase
possibleOpenConnection, sqlAccess
-
-
Constructor Summary
Constructors Constructor Description SQLListener(boolean dropTables)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidcloseInput()Closes the input, flushing any links into storage.protected voidcreateMappingSetTable()protected voidcreateSQLTables()Excecutes several SQL statements to create the tables and indexes in the database.protected voiddropSQLTables()Excecutes several SQL statements to drop the tablesprotected voiddropTable(String name)Drops a single table if it exists.protected intgetAutoInc()protected StringgetDataSourceKey(DataSource dataSource)voidinsertLink(String sourceId, String targetId, int mappingSet, boolean symetric)Inserts a mapping into the system.voidputProperty(String key, String value)intregisterMappingSet(DataSource source, DataSource target, boolean symetric)Loads all the meta data for a Mapping Set.-
Methods inherited from class org.bridgedb.sql.SQLBase
close, closeConnection, commitTransaction, createPreparedStatement, createStatement, insertEscpaeCharacters, rollbackTransaction, startTransaction
-
-
-
-
Field Detail
-
SQL_COMPAT_VERSION
public static final int SQL_COMPAT_VERSION
- See Also:
- Constant Field Values
-
SYSCODE_LENGTH
protected static final int SYSCODE_LENGTH
- See Also:
- Constant Field Values
-
FULLNAME_LENGTH
protected static final int FULLNAME_LENGTH
- See Also:
- Constant Field Values
-
ID_LENGTH
protected static final int ID_LENGTH
- See Also:
- Constant Field Values
-
MAPPING_URI_LENGTH
protected static final int MAPPING_URI_LENGTH
- See Also:
- Constant Field Values
-
MAPPING_SET_TABLE_NAME
public static final String MAPPING_SET_TABLE_NAME
- See Also:
- Constant Field Values
-
ID_COLUMN_NAME
public static final String ID_COLUMN_NAME
- See Also:
- Constant Field Values
-
MAPPING_SET_ID_COLUMN_NAME
public static final String MAPPING_SET_ID_COLUMN_NAME
- See Also:
- Constant Field Values
-
SOURCE_DATASOURCE_COLUMN_NAME
protected static final String SOURCE_DATASOURCE_COLUMN_NAME
- See Also:
- Constant Field Values
-
TARGET_DATASOURCE_COLUMN_NAME
protected static final String TARGET_DATASOURCE_COLUMN_NAME
- See Also:
- Constant Field Values
-
autoIncrement
protected final String autoIncrement
-
-
Constructor Detail
-
SQLListener
public SQLListener(boolean dropTables) throws BridgeDBException- Throws:
BridgeDBException
-
-
Method Detail
-
registerMappingSet
public int registerMappingSet(DataSource source, DataSource target, boolean symetric) throws BridgeDBException
Description copied from interface:MappingListenerLoads all the meta data for a Mapping Set.- Specified by:
registerMappingSetin interfaceMappingListener- Parameters:
source- The SysCode of DataSource part of the source xref/urltarget- The SysCode of DataSource part of the target xref/urlsymetric- Flag to say if mapping should be loaded one way of both ways. Creates two mapping sets this one and the inverse with one number higher.- Returns:
- Id of the forward mappingSet.
- Throws:
BridgeDBException- - if something goes wrong Always thrown by the URI based version as it requires extra parameters to register a mapping Set.
-
getDataSourceKey
protected final String getDataSourceKey(DataSource dataSource)
-
getAutoInc
protected final int getAutoInc() throws BridgeDBException- Throws:
BridgeDBException
-
closeInput
public void closeInput() throws BridgeDBExceptionDescription copied from interface:MappingListenerCloses the input, flushing any links into storage.May also update any cashed counts ext.
This method and URLListener method are intended to be duplicates of each other.
- Specified by:
closeInputin interfaceMappingListener- Throws:
BridgeDBException- - if something goes wrong
-
insertLink
public void insertLink(String sourceId, String targetId, int mappingSet, boolean symetric) throws BridgeDBException
Description copied from interface:MappingListenerInserts a mapping into the system.Implementatins may buffer the inserts, so closeInput must be called after the last insert or inserts may be lost.
No checking can be done that the DataSource part of the Xrefs match the declaration.
For speed, the implemented methods is also not required to check that the MappingsSet exists nor that the mapping Set's semantic setting matches that in the insert call.
- Specified by:
insertLinkin interfaceMappingListener- Parameters:
sourceId- ID of the source xreftargetId- ID of the target xrefmappingSet- The ID of the mapping set to be inserted into.symetric- If true the inverse mapping will be inserted into the mapping set one number higher.- Throws:
BridgeDBException- - if something goes wrong
-
dropSQLTables
protected void dropSQLTables() throws BridgeDBExceptionExcecutes several SQL statements to drop the tables- Throws:
BridgeDBException- - if something goes wrong
-
dropTable
protected void dropTable(String name) throws BridgeDBException
Drops a single table if it exists.Virtuosos appears not to have the if exists syntax so errors are assumed to be table not found.
- Parameters:
name- - name of the table- Throws:
BridgeDBException- - if something goes wrong
-
createSQLTables
protected void createSQLTables() throws BridgeDBExceptionExcecutes several SQL statements to create the tables and indexes in the database.Table "info" is a control table used by all database version of BridgeDB, inlcuing none OPS ones. If verifies that database is called with the code that matches the schema version.
Table DataSource holds the org.bridgedb.DataSource registry between deployments of the service. The whole table is loaded into the DataSource.class regisrty in the constructor.
- Throws:
BridgeDBException- - if something goes wrong- See Also:
Table "mapping" holds the Id part of the mapping. (The DataSource part is handled by MappingSet) The "id" field is purely for provenace tracking. Ie getting a particular mapping based on its Id. Mappings are only looked up in one direction, so ids are specically source and target. "mappingSetId" is a foreign key to the "mappingSet" table. Table "mappingSet" holds the DataSource part of each Mapping. Specifically it holds the SysCodes for which org.bridgedb.DataSource objects can be looked up. The Ops version will also map SysCodes to UriSpace(s). "predicate" is purely for provenace. (but could be used for Ops Profiles) "isTransitive" is a flag set at the time of loading to identify mappinSet generated using transativity of other sets. Currently only used by OPS to draw a different line in the graphviz but could be used by lenses. "mappingCount" is a precomputed value @see countLinks() method. Table "properties" underpins bridgeDB properties methods. "isPublic" field dettermines if the key will be returned by the getKeys() method.
-
createMappingSetTable
protected void createMappingSetTable() throws BridgeDBException- Throws:
BridgeDBException
-
putProperty
public void putProperty(String key, String value) throws BridgeDBException
- Throws:
BridgeDBException
-
-