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 [[email protected]]
See Also:
  • Method Details

    • 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.
    • getLinkedObjects

      <P extends ParaObject> List<P> getLinkedObjects(String type, Pager... pager)
      Similar to getChildren(java.lang.String, com.erudika.para.core.utils.Pager...) but for many-to-many relationships.
      Type Parameters:
      P - type of linked objects
      Parameters:
      type - type of linked objects to look for
      pager - a Pager
      Returns:
      a list of linked objects
    • findLinkedObjects

      <P extends ParaObject> List<P> findLinkedObjects(String type, String field, String query, Pager... pager)
      Similar to findChildren(java.lang.String, java.lang.String, com.erudika.para.core.utils.Pager...) but for many-to-many relationships. Searches through all linked objects connected to this via a Linker object.
      Type Parameters:
      P - type of linked objects
      Parameters:
      type - type of linked objects to look for
      field - the name of the field to target (within a nested field "nstd")
      query - a query string
      pager - a Pager
      Returns:
      a list of linked objects matching the search query
    • 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 ParaObject> List<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 ParaObject> List<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
      query - a query string
      pager - a Pager
      Returns:
      a list of ParaObject in a one-to-many relationship with this object
    • getChildren

      <P extends ParaObject> List<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.