Package org.bridgedb.sql
Class SQLIdMapper
- java.lang.Object
-
- org.bridgedb.sql.SQLBase
-
- org.bridgedb.sql.SQLListener
-
- org.bridgedb.sql.SQLIdMapper
-
- All Implemented Interfaces:
IDMapper,IDMapperCapabilities,MappingListener
public class SQLIdMapper extends SQLListener implements IDMapper, IDMapperCapabilities
Builds on the SQLListener to implement the Standard BridgeDB functions of IDMapper and IDMapperCapabilities. This Allows the OPS version to function as any other BridgeDB implementation- Author:
- Christian
-
-
Field Summary
Fields Modifier and Type Field Description protected CodeMappercodeMapperMap between IdSysCodePair and Xref or DataSourcesprotected static intDEFAULT_LIMIT-
Fields inherited from class org.bridgedb.sql.SQLListener
autoIncrement, FULLNAME_LENGTH, ID_COLUMN_NAME, ID_LENGTH, MAPPING_SET_ID_COLUMN_NAME, MAPPING_SET_TABLE_NAME, MAPPING_URI_LENGTH, SOURCE_DATASOURCE_COLUMN_NAME, SQL_COMPAT_VERSION, SYSCODE_LENGTH, TARGET_DATASOURCE_COLUMN_NAME
-
Fields inherited from class org.bridgedb.sql.SQLBase
possibleOpenConnection, sqlAccess
-
-
Constructor Summary
Constructors Constructor Description SQLIdMapper(boolean dropTables, CodeMapper codeMapper)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected voidappendLimitConditions(StringBuilder query, Integer position, Integer limit)Adds the limit condition if this is the support method for limitng the number of results.protected voidappendMappingJoinMapping(StringBuilder query)protected voidappendSourceIdSysCodePair(StringBuilder query, IdSysCodePair ref)Add a condition to the query that only mappings with a specific source IdSysCodePair should be used.protected voidappendSourceXref(StringBuilder query, String id, String sysCode)Add a condition to the query that only mappings with a specific source Xref should be used.protected voidappendTopConditions(StringBuilder query, Integer position, Integer limit)Adds the top condition if this is the support method for limitng the number of results.protected booleanbadXref(Xref ref)Check if the Xref is invalid in some way.voidclose()Set<Xref>freeSearch(String text, int limit)IDMapperCapabilitiesgetCapabilities()Set<String>getKeys()StringgetProperty(String key)Set<DataSource>getSupportedSrcDataSources()Set<DataSource>getSupportedTgtDataSources()protected booleanIdSysCodePairExists(IdSysCodePair ref)booleanisConnected()booleanisFreeSearchSupported()booleanisMappingSupported(DataSource src, DataSource tgt)Map<Xref,Set<Xref>>mapID(Collection<Xref> srcXrefs, DataSource... tgtDataSources)Set<Xref>mapID(Xref xref, DataSource tgtDataSource)Get all cross-references for the given entity, restricting the result to contain only references from the given set of data sources.Set<Xref>mapID(Xref xref, DataSource... tgtDataSources)protected StringtoCode(DataSource tgtDataSource)protected String[]toCodes(DataSource[] tgtDataSources)protected IdSysCodePairtoIdSysCodePair(Xref xref)protected Set<Xref>toXrefs(Set<IdSysCodePair> pairs)booleanxrefExists(Xref xref)-
Methods inherited from class org.bridgedb.sql.SQLListener
closeInput, createMappingSetTable, createSQLTables, dropSQLTables, dropTable, getAutoInc, getDataSourceKey, insertLink, putProperty, registerMappingSet
-
Methods inherited from class org.bridgedb.sql.SQLBase
close, closeConnection, commitTransaction, createPreparedStatement, createStatement, insertEscpaeCharacters, rollbackTransaction, startTransaction
-
-
-
-
Field Detail
-
DEFAULT_LIMIT
protected static final int DEFAULT_LIMIT
- See Also:
- Constant Field Values
-
codeMapper
protected final CodeMapper codeMapper
Map between IdSysCodePair and Xref or DataSources
-
-
Constructor Detail
-
SQLIdMapper
public SQLIdMapper(boolean dropTables, CodeMapper codeMapper) throws BridgeDBException- Throws:
BridgeDBException
-
-
Method Detail
-
mapID
public Map<Xref,Set<Xref>> mapID(Collection<Xref> srcXrefs, DataSource... tgtDataSources) throws IDMapperException
- Specified by:
mapIDin interfaceIDMapper- Throws:
IDMapperException
-
mapID
public Set<Xref> mapID(Xref xref, DataSource... tgtDataSources) throws BridgeDBException
- Specified by:
mapIDin interfaceIDMapper- Throws:
BridgeDBException
-
mapID
public Set<Xref> mapID(Xref xref, DataSource tgtDataSource) throws BridgeDBException
Get all cross-references for the given entity, restricting the result to contain only references from the given set of data sources.- Parameters:
xref- the entity to get cross-references for.tgtDataSource- target ID types/data source. Can not be null- Returns:
- A Set containing the cross references, or an empty Set when no cross references could be found. This method does not return null.
- Throws:
BridgeDBException- if the mapping service is (temporarily) unavailable
-
xrefExists
public boolean xrefExists(Xref xref) throws BridgeDBException
- Specified by:
xrefExistsin interfaceIDMapper- Throws:
BridgeDBException
-
IdSysCodePairExists
protected boolean IdSysCodePairExists(IdSysCodePair ref) throws BridgeDBException
- Throws:
BridgeDBException
-
freeSearch
public Set<Xref> freeSearch(String text, int limit) throws BridgeDBException
- Specified by:
freeSearchin interfaceIDMapper- Throws:
BridgeDBException
-
getCapabilities
public IDMapperCapabilities getCapabilities()
- Specified by:
getCapabilitiesin interfaceIDMapper
-
isConnected
public boolean isConnected()
- Specified by:
isConnectedin interfaceIDMapper
-
isFreeSearchSupported
public boolean isFreeSearchSupported()
- Specified by:
isFreeSearchSupportedin interfaceIDMapperCapabilities
-
getSupportedSrcDataSources
public Set<DataSource> getSupportedSrcDataSources() throws BridgeDBException
- Specified by:
getSupportedSrcDataSourcesin interfaceIDMapperCapabilities- Throws:
BridgeDBException
-
getSupportedTgtDataSources
public Set<DataSource> getSupportedTgtDataSources() throws BridgeDBException
- Specified by:
getSupportedTgtDataSourcesin interfaceIDMapperCapabilities- Throws:
BridgeDBException
-
isMappingSupported
public boolean isMappingSupported(DataSource src, DataSource tgt) throws BridgeDBException
- Specified by:
isMappingSupportedin interfaceIDMapperCapabilities- Throws:
BridgeDBException
-
getProperty
public String getProperty(String key)
- Specified by:
getPropertyin interfaceIDMapperCapabilities
-
getKeys
public Set<String> getKeys()
- Specified by:
getKeysin interfaceIDMapperCapabilities
-
badXref
protected final boolean badXref(Xref ref)
Check if the Xref is invalid in some way.For example if it is null or if either the Id or DataSource part is null.
- Parameters:
ref- - the xref to check- Returns:
- if the xref whether or not the xref is valid
-
appendSourceIdSysCodePair
protected final void appendSourceIdSysCodePair(StringBuilder query, IdSysCodePair ref)
Add a condition to the query that only mappings with a specific source IdSysCodePair should be used.- Parameters:
query- Query to add to.ref- IdSysCodePair that forms the base of the condition.
-
appendSourceXref
protected final void appendSourceXref(StringBuilder query, String id, String sysCode)
Add a condition to the query that only mappings with a specific source Xref should be used.- Parameters:
query- Query to add to.id- - identifier of the XrefsysCode- - system code of the source database of the Xref
-
appendLimitConditions
protected void appendLimitConditions(StringBuilder query, Integer position, Integer limit)
Adds the limit condition if this is the support method for limitng the number of results.System such as MYSQL use a Limit clause at the end of the query. Where applicable this is added here.
- Parameters:
query- Query to add Limit toposition- The offset of the fragment of results to returnlimit- The size of the fragment of results to return
-
appendTopConditions
protected void appendTopConditions(StringBuilder query, Integer position, Integer limit)
Adds the top condition if this is the support method for limitng the number of results.System such as Virtuosos use a Top clause directly after the select. Where applicable this is added here.
- Parameters:
query- Query to add TOP toposition- The offset of the fragment of results to returnlimit- The size of the fragment of results to return
-
appendMappingJoinMapping
protected final void appendMappingJoinMapping(StringBuilder query)
-
toCodes
protected final String[] toCodes(DataSource[] tgtDataSources)
-
toIdSysCodePair
protected final IdSysCodePair toIdSysCodePair(Xref xref) throws BridgeDBException
- Throws:
BridgeDBException
-
toXrefs
protected final Set<Xref> toXrefs(Set<IdSysCodePair> pairs) throws BridgeDBException
- Throws:
BridgeDBException
-
toCode
protected final String toCode(DataSource tgtDataSource)
-
-