Class 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> idToNamespace  
      protected Model model  
      protected java.util.Map<java.lang.String,​java.lang.Integer> namespaceToId  
      • Fields inherited from class org.intermine.objectstore.translating.Translator

        os
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      java.lang.Integer identifierToId​(java.lang.String identifier)
      Turn an item identifier into an object id.
      java.lang.String idToIdentifier​(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.Object translateFromDbObject​(java.lang.Object o)
      Translate an object exiting the ObjectStore.
      java.lang.Object translateIdToIdentifier​(java.lang.Integer id)
      Translate an object id into a native identifier.
      Query translateQuery​(Query query)
      Translate a query.
      java.lang.Object translateToDbObject​(java.lang.Object o)
      Translate an object entering the ObjectStore.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • 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 creation
        os - 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:
        translateIdToIdentifier in class Translator
        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
      • translateToDbObject

        public java.lang.Object translateToDbObject​(java.lang.Object o)
        Translate an object entering the ObjectStore.
        Specified by:
        translateToDbObject in class Translator
        Parameters:
        o - the Object to translate
        Returns:
        the translated object
      • translateFromDbObject

        public java.lang.Object translateFromDbObject​(java.lang.Object o)
                                               throws MetaDataException
        Translate an object exiting the ObjectStore.
        Specified by:
        translateFromDbObject in class Translator
        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