Class Linker

    • Constructor Detail

      • Linker

        public Linker()
        No-args constructor.
      • Linker

        public Linker​(String type1,
                      String type2,
                      String id1,
                      String id2)
        A link. The names of the objects are compared and sorted alphabetically.
        Parameters:
        type1 - the type of the first object
        type2 - the type of the second object
        id1 - the id of the first object
        id2 - the id of the second object
    • Method Detail

      • getId2

        public String getId2()
        Returns the id of the second object in the link.
        Returns:
        the id
      • setId2

        public void setId2​(String id2)
        Sets the id of the second object in the link.
        Parameters:
        id2 - a new id
      • getId1

        public String getId1()
        Returns the id of the first object in the link.
        Returns:
        the id
      • setId1

        public void setId1​(String id1)
        Sets the id of the first object in the link.
        Parameters:
        id1 - a new id
      • getType1

        public String getType1()
        Returns the type of the first object in the link.
        Returns:
        the type
      • setType1

        public void setType1​(String type1)
        Sets the type of the first object in the link.
        Parameters:
        type1 - the type
      • getType2

        public String getType2()
        Returns the type of the second object in the link.
        Returns:
        the type
      • setType2

        public void setType2​(String type2)
        Sets the type of the second object in the link.
        Parameters:
        type2 - second type
      • getMetadata

        public String getMetadata()
        Returns the additional information about the link.
        Returns:
        some info
      • setMetadata

        public void setMetadata​(String metadata)
        Sets additional information about the link.
        Parameters:
        metadata - some info
      • isFirst

        public boolean isFirst​(String type2)
        Checks if the position of a given object is first or second.
        Parameters:
        type2 - the given class of object
        Returns:
        true if the object's type is equal to getType1()
      • getIdFieldNameFor

        public String getIdFieldNameFor​(String type)
        Returns "id1" or "id2" depending on the alphabetical order of type.
        Parameters:
        type - the type
        Returns:
        id1 or id2
      • getNstd

        public List<Map<String,​Object>> getNstd()
        Get the nested objects that are linked by this link.
        Returns:
        a 2-element array of objects or null
      • setNstd

        public void setNstd​(List<Map<String,​Object>> nstd)
        Sets the nested array of objects that are linked by this link.
        Parameters:
        nstd - an array of 2 objects only
      • addNestedObject

        public void addNestedObject​(ParaObject obj)
        Add an object to nest inside the linker object. Used for joining queries when searching objects in a many-to-many relationship.
        Parameters:
        obj - object
      • getId

        public String getId()
        Description copied from interface: ParaObject
        The id of an object. Usually an autogenerated unique string of numbers.
        Specified by:
        getId in interface ParaObject
        Returns:
        the id
      • setId

        public void setId​(String id)
        Description copied from interface: ParaObject
        Sets a new id. Must not be null or empty.
        Specified by:
        setId in interface ParaObject
        Parameters:
        id - the new id
      • setType

        public void setType​(String type)
        Description copied from interface: ParaObject
        Sets a new object type. Must not be null or empty.
        Specified by:
        setType in interface ParaObject
        Parameters:
        type - a new type
      • getAppid

        public String getAppid()
        Description copied from interface: ParaObject
        The application name. Added to support multiple separate apps. Every object must belong to an app.
        Specified by:
        getAppid in interface ParaObject
        Returns:
        the app id (name). default: para
      • setAppid

        public void setAppid​(String appid)
        Description copied from interface: ParaObject
        Sets a new app name. Must not be null or empty.
        Specified by:
        setAppid in interface ParaObject
        Parameters:
        appid - the new app id (name)
      • getTags

        public List<String> getTags()
        Description copied from interface: ParaObject
        The tags associated with this object. Tags must not be null or empty.
        Specified by:
        getTags in interface ParaObject
        Returns:
        a set of tags, or an empty set
        See Also:
        Tag
      • setTags

        public void setTags​(List<String> tags)
        Description copied from interface: ParaObject
        Merges the given tags with existing tags.
        Specified by:
        setTags in interface ParaObject
        Parameters:
        tags - the additional tags, or clears all tags if set to null
      • getStored

        public Boolean getStored()
        Description copied from interface: ParaObject
        Boolean flag which controls whether this object is stored in the database or not. Default is true.
        Specified by:
        getStored in interface ParaObject
        Returns:
        true if this object is stored in DB.
      • setStored

        public void setStored​(Boolean stored)
        Description copied from interface: ParaObject
        Sets the "isStored" flag.
        Specified by:
        setStored in interface ParaObject
        Parameters:
        stored - when set to true, object is stored in DB.
      • getIndexed

        public Boolean getIndexed()
        Description copied from interface: ParaObject
        Boolean flag which controls whether this object is indexed by the search engine. Default is true.
        Specified by:
        getIndexed in interface ParaObject
        Returns:
        true if this object is indexed
      • setIndexed

        public void setIndexed​(Boolean indexed)
        Description copied from interface: ParaObject
        Sets the "isIndexed" flag.
        Specified by:
        setIndexed in interface ParaObject
        Parameters:
        indexed - when set to true, object is indexed.
      • getCached

        public Boolean getCached()
        Description copied from interface: ParaObject
        Boolean flag which controls whether this object is cached. Default is true.
        Specified by:
        getCached in interface ParaObject
        Returns:
        true if this object is cached on update() and create().
      • setCached

        public void setCached​(Boolean cached)
        Description copied from interface: ParaObject
        Sets the "isCached" flag.
        Specified by:
        setCached in interface ParaObject
        Parameters:
        cached - when set to true, object is cached.
      • getTimestamp

        public Long getTimestamp()
        Description copied from interface: ParaObject
        The time when the object was created, in milliseconds.
        Specified by:
        getTimestamp in interface ParaObject
        Returns:
        the timestamp of creation
      • setTimestamp

        public void setTimestamp​(Long timestamp)
        Description copied from interface: ParaObject
        Sets the timestamp.
        Specified by:
        setTimestamp in interface ParaObject
        Parameters:
        timestamp - a new timestamp in milliseconds.
      • getCreatorid

        public String getCreatorid()
        Description copied from interface: ParaObject
        The id of the user who created this. Should point to a User id.
        Specified by:
        getCreatorid in interface ParaObject
        Returns:
        the id or null
      • setCreatorid

        public void setCreatorid​(String creatorid)
        Description copied from interface: ParaObject
        Sets a new creator id. Must not be null or empty.
        Specified by:
        setCreatorid in interface ParaObject
        Parameters:
        creatorid - a new id
      • getName

        public String getName()
        Description copied from interface: ParaObject
        The name of the object. Can be anything.
        Specified by:
        getName in interface ParaObject
        Returns:
        the name. default: [type id]
      • setName

        public void setName​(String name)
        Description copied from interface: ParaObject
        Sets a new name. Must not be null or empty.
        Specified by:
        setName in interface ParaObject
        Parameters:
        name - the new name
      • getPlural

        public String getPlural()
        Description copied from interface: ParaObject
        The plural name of the object. For example: user - users
        Specified by:
        getPlural in interface ParaObject
        Returns:
        the plural name
      • getParentid

        public String getParentid()
        Description copied from interface: ParaObject
        The id of the parent object.
        Specified by:
        getParentid in interface ParaObject
        Returns:
        the id of the parent or null
      • setParentid

        public void setParentid​(String parentid)
        Description copied from interface: ParaObject
        Sets a new parent id. Must not be null or empty.
        Specified by:
        setParentid in interface ParaObject
        Parameters:
        parentid - a new id
      • getUpdated

        public Long getUpdated()
        Description copied from interface: ParaObject
        The last time this object was updated. Timestamp in ms.
        Specified by:
        getUpdated in interface ParaObject
        Returns:
        timestamp in milliseconds
      • setUpdated

        public void setUpdated​(Long updated)
        Description copied from interface: ParaObject
        Sets the last updated timestamp.
        Specified by:
        setUpdated in interface ParaObject
        Parameters:
        updated - a new timestamp
      • exists

        public boolean exists()
        Description copied from interface: ParaObject
        Checks if an object is stored in the data store.
        Specified by:
        exists in interface ParaObject
        Returns:
        true if the object is persisted to the data store.
        See Also:
        DAO.read(java.lang.String)
      • voteUp

        public boolean voteUp​(String userid)
        Description copied from interface: Votable
        Upvotes the object.
        Specified by:
        voteUp in interface Votable
        Parameters:
        userid - id of voter
        Returns:
        true if successful
      • voteDown

        public boolean voteDown​(String userid)
        Description copied from interface: Votable
        Downvotes the object.
        Specified by:
        voteDown in interface Votable
        Parameters:
        userid - id of voter
        Returns:
        true if successful
      • getVotes

        public Integer getVotes()
        Description copied from interface: Votable
        Returns the total sum of all votes for this object. For example: (+6) + (-4) = 2
        Specified by:
        getVotes in interface Votable
        Returns:
        the total sum of votes
      • setVotes

        public void setVotes​(Integer votes)
        Description copied from interface: Votable
        Sets the total votes for this object.
        Specified by:
        setVotes in interface Votable
        Parameters:
        votes - the number of votes
      • getVersion

        public Long getVersion()
        Description copied from interface: ParaObject
        Returns the version number for this object. Used primarily for optimistic locking.
        Specified by:
        getVersion in interface ParaObject
        Returns:
        a positive number, 0 if unused or -1, indicating a failed update.
      • setVersion

        public void setVersion​(Long version)
        Description copied from interface: ParaObject
        Sets the version of this object. This value should come from the database.
        Specified by:
        setVersion in interface ParaObject
        Parameters:
        version - a positive number, different than the current value of the version field
      • countLinks

        public Long countLinks​(String type2)
        Description copied from interface: Linkable
        Count the total number of links between this object and another type of object.
        Specified by:
        countLinks in interface Linkable
        Parameters:
        type2 - the other type of object
        Returns:
        the number of links
      • getLinks

        public List<Linker> getLinks​(String type2,
                                     Pager... pager)
        Description copied from interface: Linkable
        Returns all links between this type object and another type of object.
        Specified by:
        getLinks in interface Linkable
        Parameters:
        type2 - the other type of object
        pager - a Pager
        Returns:
        a list of Linker objects in a many-to-many relationship with this object.
      • isLinked

        public boolean isLinked​(String type2,
                                String id2)
        Description copied from interface: Linkable
        Checks if this object is linked to another.
        Specified by:
        isLinked in interface Linkable
        Parameters:
        type2 - the other type
        id2 - the other id
        Returns:
        true if the two are linked
      • isLinked

        public boolean isLinked​(ParaObject toObj)
        Description copied from interface: Linkable
        Checks if a given object is linked to this one.
        Specified by:
        isLinked in interface Linkable
        Parameters:
        toObj - the other object
        Returns:
        true if linked
      • link

        public String link​(String id2)
        Description copied from interface: Linkable
        Links an object to this one in a many-to-many relationship. Only a link is created. Objects are left untouched. The type of the second object is automatically determined on read.
        Specified by:
        link in interface Linkable
        Parameters:
        id2 - the other id
        Returns:
        the id of the Linker object that is created
      • unlink

        public void unlink​(String type,
                           String id2)
        Description copied from interface: Linkable
        Unlinks an object from this one. Only a link is deleted. Objects are left untouched.
        Specified by:
        unlink in interface Linkable
        Parameters:
        type - the other type
        id2 - the other id
      • unlinkAll

        public void unlinkAll()
        Description copied from interface: Linkable
        Unlinks all objects that are linked to this one. Deletes all Linker objects. Only the links are deleted. Objects are left untouched.
        Specified by:
        unlinkAll in interface Linkable
      • countChildren

        public Long countChildren​(String type)
        Description copied from interface: Linkable
        Count the total number of child objects for this object.
        Specified by:
        countChildren in interface Linkable
        Parameters:
        type - the other type of object
        Returns:
        the number of links
      • getChildren

        public <P extends ParaObjectList<P> getChildren​(String type,
                                                          Pager... pager)
        Description copied from interface: Linkable
        Returns all child objects linked to this object.
        Specified by:
        getChildren in interface Linkable
        Type Parameters:
        P - the type of children
        Parameters:
        type - the type of children to look for
        pager - a Pager
        Returns:
        a list of ParaObject in a one-to-many relationship with this object
      • getChildren

        public <P extends ParaObjectList<P> getChildren​(String type,
                                                          String field,
                                                          String term,
                                                          Pager... pager)
        Description copied from interface: Linkable
        Returns all child objects linked to this object.
        Specified by:
        getChildren in interface Linkable
        Type Parameters:
        P - the type of children
        Parameters:
        type - the type of children to look for
        field - the field name to use as filter
        term - the field value to use as filter
        pager - a Pager
        Returns:
        a list of ParaObject in a one-to-many relationship with this object
      • findChildren

        public <P extends ParaObjectList<P> findChildren​(String type,
                                                           String query,
                                                           Pager... pager)
        Description copied from interface: Linkable
        Search through all child objects. Only searches child objects directly connected to this parent via the parentid field.
        Specified by:
        findChildren in interface Linkable
        Type Parameters:
        P - the type of children
        Parameters:
        type - the type of children to look for
        query - a query string
        pager - a Pager
        Returns:
        a list of ParaObject in a one-to-many relationship with this object
      • deleteChildren

        public void deleteChildren​(String type)
        Description copied from interface: Linkable
        Deletes all child objects permanently.
        Specified by:
        deleteChildren in interface Linkable
        Parameters:
        type - the children's type.
      • hashCode

        public int hashCode()
        Overrides:
        hashCode in class Object