Class Linker
java.lang.Object
com.erudika.para.core.Linker
- All Implemented Interfaces:
Linkable, ParaObject, Votable, Serializable
This class represents a many-to-many relationship (link) between two objects.
- Author:
- Alex Bogdanovski [[email protected]]
- See Also:
-
Nested Class Summary
Nested classes/interfaces inherited from interface Votable
Votable.VoteValue -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidAdd an object to nest inside the linker object.countChildren(String type) Count the total number of child objects for this object.countLinks(String type2) Count the total number of links between this object and another type of object.create()Stores this object in the data store.voiddelete()Deletes the object permanently by removing it from the data store.voiddeleteChildren(String type) Deletes all child objects permanently.booleanbooleanexists()Checks if an object is stored in the data store.<P extends ParaObject>
List<P> findChildren(String type, String query, Pager... pager) Search through all child objects.<P extends ParaObject>
List<P> findLinkedObjects(String type, String field, String query, Pager... pager) Similar toLinkable.findChildren(java.lang.String, java.lang.String, com.erudika.para.core.utils.Pager...)but for many-to-many relationships.getAppid()The application name.Boolean flag which controls whether this object is cached.<P extends ParaObject>
List<P> getChildren(String type, Pager... pager) Returns all child objects linked to this object.<P extends ParaObject>
List<P> getChildren(String type, String field, String term, Pager... pager) Returns all child objects linked to this object.The id of the user who created this.getId()/////////////////////////////////////////////////////getId1()Returns the id of the first object in the link.getId2()Returns the id of the second object in the link.getIdFieldNameFor(String type) Returns "id1" or "id2" depending on the alphabetical order of type.Boolean flag which controls whether this object is indexed by the search engine.<P extends ParaObject>
List<P> getLinkedObjects(String type, Pager... pager) Similar toLinkable.getChildren(java.lang.String, com.erudika.para.core.utils.Pager...)but for many-to-many relationships.Returns all links between this type object and another type of object.Returns the additional information about the link.getName()The name of the object.getNstd()Get the nested objects that are linked by this link.The URI of this object.The id of the parent object.The plural name of the object.Boolean flag which controls whether this object is stored in the database or not.getTags()The tags associated with this object.The time when the object was created, in milliseconds.getType()The name of the object's class.getType1()Returns the type of the first object in the link.getType2()Returns the type of the second object in the link.The last time this object was updated.Returns the version number for this object.getVotes()Returns the total sum of all votes for this object.inthashCode()booleanChecks if the position of a given object is first or second.booleanisLinked(ParaObject toObj) Checks if a given object is linked to this one.booleanChecks if this object is linked to another.Links an object to this one in a many-to-many relationship.voidSets a new app name.voidSets the "isCached" flag.voidsetCreatorid(String creatorid) Sets a new creator id.voidSets a new id.voidSets the id of the first object in the link.voidSets the id of the second object in the link.voidsetIndexed(Boolean indexed) Sets the "isIndexed" flag.voidsetMetadata(String metadata) Sets additional information about the link.voidSets a new name.voidSets the nested array of objects that are linked by this link.voidsetParentid(String parentid) Sets a new parent id.voidSets the "isStored" flag.voidMerges the given tags with existing tags.voidsetTimestamp(Long timestamp) Sets the timestamp.voidSets a new object type.voidSets the type of the first object in the link.voidSets the type of the second object in the link.voidsetUpdated(Long updated) Sets the last updated timestamp.voidsetVersion(Long version) Sets the version of this object.voidSets the total votes for this object.toString()voidUnlinks an object from this one.voidUnlinks all objects that are linked to this one.voidupdate()Updates the object permanently.booleanDownvotes the object.booleanUpvotes the object.
-
Constructor Details
-
Linker
public Linker()No-args constructor. -
Linker
-
-
Method Details
-
getId2
-
setId2
Sets the id of the second object in the link.- Parameters:
id2- a new id
-
getId1
-
setId1
Sets the id of the first object in the link.- Parameters:
id1- a new id
-
getType1
-
setType1
Sets the type of the first object in the link.- Parameters:
type1- the type
-
getType2
-
setType2
Sets the type of the second object in the link.- Parameters:
type2- second type
-
getMetadata
-
setMetadata
Sets additional information about the link.- Parameters:
metadata- some info
-
isFirst
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
-
getNstd
-
setNstd
-
addNestedObject
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
/////////////////////////////////////////////////////- Specified by:
getIdin interfaceParaObject- Returns:
- the id
-
setId
Description copied from interface:ParaObjectSets a new id. Must not be null or empty.- Specified by:
setIdin interfaceParaObject- Parameters:
id- the new id
-
getType
Description copied from interface:ParaObjectThe name of the object's class. This is equivalent toClass.getSimpleName().toLowerCase()- Specified by:
getTypein interfaceParaObject- Returns:
- the simple name of the class
-
setType
Description copied from interface:ParaObjectSets a new object type. Must not be null or empty.- Specified by:
setTypein interfaceParaObject- Parameters:
type- a new type
-
getAppid
Description copied from interface:ParaObjectThe application name. Added to support multiple separate apps. Every object must belong to an app.- Specified by:
getAppidin interfaceParaObject- Returns:
- the app id (name). default: para
-
setAppid
Description copied from interface:ParaObjectSets a new app name. Must not be null or empty.- Specified by:
setAppidin interfaceParaObject- Parameters:
appid- the new app id (name)
-
getObjectURI
Description copied from interface:ParaObjectThe URI of this object. For example: /users/123- Specified by:
getObjectURIin interfaceParaObject- Returns:
- the URI
- See Also:
-
getTags
Description copied from interface:ParaObjectThe tags associated with this object. Tags must not be null or empty.- Specified by:
getTagsin interfaceParaObject- Returns:
- a set of tags, or an empty set
- See Also:
-
setTags
Description copied from interface:ParaObjectMerges the given tags with existing tags.- Specified by:
setTagsin interfaceParaObject- Parameters:
tags- the additional tags, or clears all tags if set to null
-
getStored
Description copied from interface:ParaObjectBoolean flag which controls whether this object is stored in the database or not. Default is true.- Specified by:
getStoredin interfaceParaObject- Returns:
- true if this object is stored in DB.
-
setStored
Description copied from interface:ParaObjectSets the "isStored" flag.- Specified by:
setStoredin interfaceParaObject- Parameters:
stored- when set to true, object is stored in DB.
-
getIndexed
Description copied from interface:ParaObjectBoolean flag which controls whether this object is indexed by the search engine. Default is true.- Specified by:
getIndexedin interfaceParaObject- Returns:
- true if this object is indexed
-
setIndexed
Description copied from interface:ParaObjectSets the "isIndexed" flag.- Specified by:
setIndexedin interfaceParaObject- Parameters:
indexed- when set to true, object is indexed.
-
getCached
Description copied from interface:ParaObjectBoolean flag which controls whether this object is cached. Default is true.- Specified by:
getCachedin interfaceParaObject- Returns:
- true if this object is cached on update() and create().
-
setCached
Description copied from interface:ParaObjectSets the "isCached" flag.- Specified by:
setCachedin interfaceParaObject- Parameters:
cached- when set to true, object is cached.
-
getTimestamp
Description copied from interface:ParaObjectThe time when the object was created, in milliseconds.- Specified by:
getTimestampin interfaceParaObject- Returns:
- the timestamp of creation
-
setTimestamp
Description copied from interface:ParaObjectSets the timestamp.- Specified by:
setTimestampin interfaceParaObject- Parameters:
timestamp- a new timestamp in milliseconds.
-
getCreatorid
Description copied from interface:ParaObjectThe id of the user who created this. Should point to aUserid.- Specified by:
getCreatoridin interfaceParaObject- Returns:
- the id or null
-
setCreatorid
Description copied from interface:ParaObjectSets a new creator id. Must not be null or empty.- Specified by:
setCreatoridin interfaceParaObject- Parameters:
creatorid- a new id
-
getName
Description copied from interface:ParaObjectThe name of the object. Can be anything.- Specified by:
getNamein interfaceParaObject- Returns:
- the name. default: [type id]
-
setName
Description copied from interface:ParaObjectSets a new name. Must not be null or empty.- Specified by:
setNamein interfaceParaObject- Parameters:
name- the new name
-
getPlural
Description copied from interface:ParaObjectThe plural name of the object. For example: user - users- Specified by:
getPluralin interfaceParaObject- Returns:
- the plural name
-
getParentid
Description copied from interface:ParaObjectThe id of the parent object.- Specified by:
getParentidin interfaceParaObject- Returns:
- the id of the parent or null
-
setParentid
Description copied from interface:ParaObjectSets a new parent id. Must not be null or empty.- Specified by:
setParentidin interfaceParaObject- Parameters:
parentid- a new id
-
getUpdated
Description copied from interface:ParaObjectThe last time this object was updated. Timestamp in ms.- Specified by:
getUpdatedin interfaceParaObject- Returns:
- timestamp in milliseconds
-
setUpdated
Description copied from interface:ParaObjectSets the last updated timestamp.- Specified by:
setUpdatedin interfaceParaObject- Parameters:
updated- a new timestamp
-
create
Description copied from interface:ParaObjectStores this object in the data store.- Specified by:
createin interfaceParaObject- Returns:
- the id of the object (a new id if object is new)
- See Also:
-
update
public void update()Description copied from interface:ParaObjectUpdates the object permanently. Changes toLockedfields are ignored.- Specified by:
updatein interfaceParaObject- See Also:
-
delete
public void delete()Description copied from interface:ParaObjectDeletes the object permanently by removing it from the data store.- Specified by:
deletein interfaceParaObject- See Also:
-
exists
public boolean exists()Description copied from interface:ParaObjectChecks if an object is stored in the data store.- Specified by:
existsin interfaceParaObject- Returns:
- true if the object is persisted to the data store.
- See Also:
-
voteUp
-
voteDown
-
getVotes
-
setVotes
-
getVersion
Description copied from interface:ParaObjectReturns the version number for this object. Used primarily for optimistic locking.- Specified by:
getVersionin interfaceParaObject- Returns:
- a positive number,
0if unused or-1, indicating a failed update.
-
setVersion
Description copied from interface:ParaObjectSets the version of this object. This value should come from the database.- Specified by:
setVersionin interfaceParaObject- Parameters:
version- a positive number, different than the current value of the version field
-
countLinks
Description copied from interface:LinkableCount the total number of links between this object and another type of object.- Specified by:
countLinksin interfaceLinkable- Parameters:
type2- the other type of object- Returns:
- the number of links
-
getLinks
Description copied from interface:LinkableReturns all links between this type object and another type of object. -
getLinkedObjects
Description copied from interface:LinkableSimilar toLinkable.getChildren(java.lang.String, com.erudika.para.core.utils.Pager...)but for many-to-many relationships.- Specified by:
getLinkedObjectsin interfaceLinkable- Type Parameters:
P- type of linked objects- Parameters:
type- type of linked objects to look forpager- aPager- Returns:
- a list of linked objects
-
findLinkedObjects
public <P extends ParaObject> List<P> findLinkedObjects(String type, String field, String query, Pager... pager) Description copied from interface:LinkableSimilar toLinkable.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 aLinkerobject.- Specified by:
findLinkedObjectsin interfaceLinkable- Type Parameters:
P- type of linked objects- Parameters:
type- type of linked objects to look forfield- the name of the field to target (within a nested field "nstd")query- a query stringpager- aPager- Returns:
- a list of linked objects matching the search query
-
isLinked
-
isLinked
Description copied from interface:LinkableChecks if a given object is linked to this one. -
link
Description copied from interface:LinkableLinks 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. -
unlink
-
unlinkAll
-
countChildren
Description copied from interface:LinkableCount the total number of child objects for this object.- Specified by:
countChildrenin interfaceLinkable- Parameters:
type- the other type of object- Returns:
- the number of links
-
getChildren
Description copied from interface:LinkableReturns all child objects linked to this object.- Specified by:
getChildrenin interfaceLinkable- Type Parameters:
P- the type of children- Parameters:
type- the type of children to look forpager- aPager- Returns:
- a list of
ParaObjectin a one-to-many relationship with this object
-
getChildren
public <P extends ParaObject> List<P> getChildren(String type, String field, String term, Pager... pager) Description copied from interface:LinkableReturns all child objects linked to this object.- Specified by:
getChildrenin interfaceLinkable- Type Parameters:
P- the type of children- Parameters:
type- the type of children to look forfield- the field name to use as filterterm- the field value to use as filterpager- aPager- Returns:
- a list of
ParaObjectin a one-to-many relationship with this object
-
findChildren
Description copied from interface:LinkableSearch through all child objects. Only searches child objects directly connected to this parent via theparentidfield.- Specified by:
findChildrenin interfaceLinkable- Type Parameters:
P- the type of children- Parameters:
type- the type of children to look forquery- a query stringpager- aPager- Returns:
- a list of
ParaObjectin a one-to-many relationship with this object
-
deleteChildren
Description copied from interface:LinkableDeletes all child objects permanently.- Specified by:
deleteChildrenin interfaceLinkable- Parameters:
type- the children's type.
-
hashCode
-
equals
-
toString
-