Package dev.morphia

Interface ObjectFactory

  • All Known Implementing Classes:
    DefaultCreator

    public interface ObjectFactory
    The ObjectFactory is used by morphia to create instances of classes which can be customized to fit a particular applications needs.
    • Method Summary

      All Methods Instance Methods Abstract Methods 
      Modifier and Type Method Description
      java.lang.Object createInstance​(Mapper mapper, MappedField mf, com.mongodb.DBObject dbObj)
      Creates an instance of the class defined in the discriminator field in the dbObject passed in.
      <T> T createInstance​(java.lang.Class<T> clazz)
      Creates an instance of the given class.
      <T> T createInstance​(java.lang.Class<T> clazz, com.mongodb.DBObject dbObj)
      Creates an instance of the class defined in the discriminator field in the dbObject passed in.
      java.util.List createList​(MappedField mf)
      Defines how morphia creates a List object.
      java.util.Map createMap​(MappedField mf)
      Defines how morphia creates a Map object.
      java.util.Set createSet​(MappedField mf)
      Defines how morphia creates a Set object.
    • Method Detail

      • createInstance

        <T> T createInstance​(java.lang.Class<T> clazz)
        Creates an instance of the given class.
        Type Parameters:
        T - the type of the entity
        Parameters:
        clazz - type class to instantiate
        Returns:
        the new instance
      • createInstance

        <T> T createInstance​(java.lang.Class<T> clazz,
                             com.mongodb.DBObject dbObj)
        Creates an instance of the class defined in the discriminator field in the dbObject passed in. If that field is missing, the given Class is used instead.
        Type Parameters:
        T - the type of the entity
        Parameters:
        clazz - type class to instantiate
        dbObj - the state to populate the new instance with
        Returns:
        the new instance
      • createInstance

        java.lang.Object createInstance​(Mapper mapper,
                                        MappedField mf,
                                        com.mongodb.DBObject dbObj)
        Creates an instance of the class defined in the discriminator field in the dbObject passed in. If that field is missing, morphia attempts to the MappedField to determine which concrete class to instantiate.
        Parameters:
        mapper - the Mapper to use
        mf - the MappedField to consult when creating the instance
        dbObj - the state to populate the new instance with
        Returns:
        the new instance
      • createList

        java.util.List createList​(MappedField mf)
        Defines how morphia creates a List object.
        Parameters:
        mf - the MappedField containing any metadata that might define the type of the List to create
        Returns:
        the List
      • createMap

        java.util.Map createMap​(MappedField mf)
        Defines how morphia creates a Map object.
        Parameters:
        mf - the MappedField containing any metadata that might define the type of the Map to create
        Returns:
        the Map
      • createSet

        java.util.Set createSet​(MappedField mf)
        Defines how morphia creates a Set object.
        Parameters:
        mf - the MappedField containing any metadata that might define the type of the Set to create
        Returns:
        the Set