Interface Linkable

  • All Known Subinterfaces:
    ParaObject
    All Known Implementing Classes:
    Address, App, Linker, Sysprop, Tag, Translation, User, Vote, Webhook

    public interface Linkable
    Applied to all ParaObjects by default. Allows an object to be linked to another object. A link can be: 1-1, 1-* or *-*. One-to-one and one-to-many links are implemented using the parentid field. Many-to-many links are implemented using Linker objects.
    Author:
    Alex Bogdanovski [alex@erudika.com]
    See Also:
    Linker
    • Method Detail

      • countLinks

        Long countLinks​(String type2)
        Count the total number of links between this object and another type of object.
        Parameters:
        type2 - the other type of object
        Returns:
        the number of links
      • getLinks

        List<Linker> getLinks​(String type2,
                              Pager... pager)
        Returns all links between this type object and another type of object.
        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

        boolean isLinked​(String type2,
                         String id2)
        Checks if this object is linked to another.
        Parameters:
        type2 - the other type
        id2 - the other id
        Returns:
        true if the two are linked
      • isLinked

        boolean isLinked​(ParaObject toObj)
        Checks if a given object is linked to this one.
        Parameters:
        toObj - the other object
        Returns:
        true if linked
      • link

        String link​(String id2)
        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.
        Parameters:
        id2 - the other id
        Returns:
        the id of the Linker object that is created
      • unlink

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

        void unlinkAll()
        Unlinks all objects that are linked to this one. Deletes all Linker objects. Only the links are deleted. Objects are left untouched.
      • countChildren

        Long countChildren​(String type)
        Count the total number of child objects for this object.
        Parameters:
        type - the other type of object
        Returns:
        the number of links
      • getChildren

        <P extends ParaObjectList<P> getChildren​(String type,
                                                   Pager... pager)
        Returns all child objects linked to this object.
        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
      • findChildren

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

        <P extends ParaObjectList<P> getChildren​(String type,
                                                   String field,
                                                   String term,
                                                   Pager... pager)
        Returns all child objects linked to this object.
        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
      • deleteChildren

        void deleteChildren​(String type)
        Deletes all child objects permanently.
        Parameters:
        type - the children's type.