Package uk.ac.ebi.utils.orm
Class Many2ManyUtils
java.lang.Object
uk.ac.ebi.utils.orm.Many2ManyUtils
Facilities to manager many-to-many relations in JPA.
- date
- Mar 25, 2013
- Author:
- Marco Brandizi
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionstatic <O,
A> boolean addMany2Many
(O obj, A added, String inverseRelationAddMethod, Collection<A> internalCollection) Synchronises the addition of an object to a many2many relationship.static <O,
A> boolean deleteMany2Many
(O obj, A deleted, String inverseRelationDeleteMethod, Collection<A> internalCollection) The opposite ofaddMany2Many(Object, Object, String, Collection)
, the parameters and the return value have an analogous meaning.
-
Constructor Details
-
Many2ManyUtils
public Many2ManyUtils()
-
-
Method Details
-
addMany2Many
public static <O,A> boolean addMany2Many(O obj, A added, String inverseRelationAddMethod, Collection<A> internalCollection) Synchronises the addition of an object to a many2many relationship. For example, if you have: Product.orders and Order.products, you can implement:boolean Product.addOrder( Order prod )
as:return addManyToMany ( this, order, "addProduct", this.orders ); // or this.getOrders()
where this.orders is the set internal to Product that backs the corresponding relation. This call invokes this.orders.add ( order ) and, in case this operation returns true (i.e., the order was not already inside the collection), it invokes order.addProduct ( this ) too. You should implement Order.product() in a dual way. The check that the element was added to the set avoids infinite loops.- Parameters:
obj
- the object to which added is addedadded
- the added objectinverseRelationAddMethod
- the name of the method to be called to add obj to added, using the inverse side of the relation obj-added relation.internalCollection
- the collection for the side from obj to added to which added is actually added- Returns:
- true if the added was really added to obj.
-
deleteMany2Many
public static <O,A> boolean deleteMany2Many(O obj, A deleted, String inverseRelationDeleteMethod, Collection<A> internalCollection) The opposite ofaddMany2Many(Object, Object, String, Collection)
, the parameters and the return value have an analogous meaning.
-