Package org.intermine.dataconversion
Class ItemToObjectTranslator
- java.lang.Object
-
- org.intermine.objectstore.translating.Translator
-
- org.intermine.dataconversion.ItemToObjectTranslator
-
public class ItemToObjectTranslator extends Translator
Translator that translates fulldata Items to business objects- Author:
- Andrew Varley, Mark Woodbridge
-
-
Field Summary
Fields Modifier and Type Field Description protected java.util.SortedMap<java.lang.Integer,java.lang.String>idToNamespaceprotected Modelmodelprotected java.util.Map<java.lang.String,java.lang.Integer>namespaceToId-
Fields inherited from class org.intermine.objectstore.translating.Translator
os
-
-
Constructor Summary
Constructors Constructor Description ItemToObjectTranslator(Model model, ObjectStore os)Constructor
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description java.lang.IntegeridentifierToId(java.lang.String identifier)Turn an item identifier into an object id.java.lang.StringidToIdentifier(java.lang.Integer id)Turn an object id into an item identifier.protected java.util.Collection<java.lang.Integer>toIntegers(java.util.Collection<java.lang.String> strings)Convert a set of Strings to a set of Integers using identifierToId()protected java.util.Collection<java.lang.String>toStrings(java.util.Collection<java.lang.Integer> integers)Convert a set of Integers to a set of String using idToIdentifier()java.lang.ObjecttranslateFromDbObject(java.lang.Object o)Translate an object exiting the ObjectStore.java.lang.ObjecttranslateIdToIdentifier(java.lang.Integer id)Translate an object id into a native identifier.QuerytranslateQuery(Query query)Translate a query.java.lang.ObjecttranslateToDbObject(java.lang.Object o)Translate an object entering the ObjectStore.-
Methods inherited from class org.intermine.objectstore.translating.Translator
setObjectStore
-
-
-
-
Field Detail
-
model
protected Model model
-
idToNamespace
protected java.util.SortedMap<java.lang.Integer,java.lang.String> idToNamespace
-
namespaceToId
protected java.util.Map<java.lang.String,java.lang.Integer> namespaceToId
-
-
Constructor Detail
-
ItemToObjectTranslator
public ItemToObjectTranslator(Model model, ObjectStore os) throws ObjectStoreException
Constructor- Parameters:
model- the Model used in business object creationos- an ObjectStore containing the Item data that we will be translating. Note that the contents of the objectstore must remain constant for IDs to not clash - newly written objects will not be accessible by their ID. This translator assumes that the Item identifier field contains some string, an underscore, then some number with no leading zeros.- Throws:
ObjectStoreException- if the initialisation query fails
-
-
Method Detail
-
idToIdentifier
public java.lang.String idToIdentifier(java.lang.Integer id)
Turn an object id into an item identifier.- Parameters:
id- an InterMineObject id- Returns:
- the corresponding item identifier
-
translateIdToIdentifier
public java.lang.Object translateIdToIdentifier(java.lang.Integer id)
Translate an object id into a native identifier.- Specified by:
translateIdToIdentifierin classTranslator- Parameters:
id- the object id- Returns:
- an object that represents the underlying object's identifier
-
identifierToId
public java.lang.Integer identifierToId(java.lang.String identifier)
Turn an item identifier into an object id.- Parameters:
identifier- an item identifier- Returns:
- the corresponding InterMineObject id
-
translateQuery
public Query translateQuery(Query query) throws ObjectStoreException
Translate a query.- Specified by:
translateQueryin classTranslator- Parameters:
query- the Query to translate- Returns:
- the translated query
- Throws:
ObjectStoreException- if the query cannot be translated
-
translateToDbObject
public java.lang.Object translateToDbObject(java.lang.Object o)
Translate an object entering the ObjectStore.- Specified by:
translateToDbObjectin classTranslator- Parameters:
o- the Object to translate- Returns:
- the translated object
-
translateFromDbObject
public java.lang.Object translateFromDbObject(java.lang.Object o) throws MetaDataExceptionTranslate an object exiting the ObjectStore.- Specified by:
translateFromDbObjectin classTranslator- Parameters:
o- the object to translate- Returns:
- the translated object
- Throws:
MetaDataException- if item has a field that isn't in InterMine model
-
toStrings
protected java.util.Collection<java.lang.String> toStrings(java.util.Collection<java.lang.Integer> integers)
Convert a set of Integers to a set of String using idToIdentifier()- Parameters:
integers- a set of Integers- Returns:
- the corresponding set of Strings
-
toIntegers
protected java.util.Collection<java.lang.Integer> toIntegers(java.util.Collection<java.lang.String> strings)
Convert a set of Strings to a set of Integers using identifierToId()- Parameters:
strings- a set of Strings- Returns:
- the corresponding set of Integers
-
-