Class DetachedEntity<ID,​T extends Entity>

    • Constructor Detail

      • DetachedEntity

        protected DetachedEntity()
        No-arg constructor (for Jackson et al).
      • DetachedEntity

        protected DetachedEntity​(T entity,
                                 String[] properties)
        Construct a new representation from a entity.
        Parameters:
        entity - to construct a representation from. Must not be null.
        properties - keys of properties to be included in the representation. Can be null, which represents all. Empty array represents none.
      • DetachedEntity

        protected DetachedEntity​(long graphId)
        Construct a representation of a entity from its internal Neo4j ID.
        Parameters:
        graphId - ID.
      • DetachedEntity

        protected DetachedEntity​(Map<String,​Object> properties)
        Construct a new representation of a entity from a map of properties.
        Parameters:
        properties - of the new entity. Must not be null, but can be empty.
      • DetachedEntity

        protected DetachedEntity​(long graphId,
                                 Map<String,​Object> properties)
        Construct a new representation of a entity from its internal Neo4j ID and a map of properties.

        Note that this constructor is only intended for testing.

        Parameters:
        graphId - ID.
        properties - of the new entity. Must not be null, but can be empty.
    • Method Detail

      • getId

        protected abstract ID getId()
      • putProperty

        public void putProperty​(String key,
                                Object value)
        Add a property.
        Parameters:
        key - key. Must not be null.
        value - value. Must not be null.
      • produceEntity

        public T produceEntity​(Transaction tx)
        Produce a Entity from this representation. This means either fetch the entity from the given tx (iff id is set), or create it.
        Parameters:
        tx - to create/fetch entity in.
        Returns:
        entity.
      • create

        protected abstract T create​(Transaction tx)
        Create a new entity from this representation in the given database.
        Parameters:
        tx - to create the entity in.
        Returns:
        entity.
      • fetch

        protected abstract T fetch​(Transaction tx)
        Fetch a entity from the given database.
        Parameters:
        tx - to fetch in.
        Returns:
        entity.
      • populate

        protected void populate​(T t)
        Populate this instance of a entity representation with data from the given Entity.
        Parameters:
        t - to populate from.
      • checkCanCreate

        protected void checkCanCreate()
        Check that this instance of entity representation can be created in the db.
        Throws:
        IllegalStateException - if not possible to create.
      • checkCanFetch

        protected void checkCanFetch()
        Check that this instance of entity representation can be fetched from the db.
        Throws:
        IllegalStateException - if not possible to fetch.
      • getGraphId

        public long getGraphId()
      • setGraphId

        public void setGraphId​(long graphId)
      • setProperties

        public void setProperties​(Map<String,​Object> properties)
        Set properties.
        Parameters:
        properties - Must not be null, but can be empty.
      • propertyKeySetAsStringArray

        protected String[] propertyKeySetAsStringArray​(Iterable<String> keySet)
        Returns a properties keyset from a graph object to a string array
        Parameters:
        keySet - properties keyset
      • hashCode

        public int hashCode()
        Overrides:
        hashCode in class Object