1 package org.splat.dal.bo.kernel;
3 * Abstract root class of persistent objects supporting relations to other persistent objects.<br/>
4 * Relations are instances of concrete subclasses of Relation that are assigned to Entity objects at run time.<br/>
6 * Entity objects also support dynamic attributes provided by the Any class.
9 * @author Daniel Brunier-Coulin
10 * @copyright OPEN CASCADE 2012
13 import java.util.HashSet;
14 import java.util.Iterator;
15 import java.util.List;
17 import java.util.Vector;
19 import org.splat.kernel.InvalidPropertyException;
20 import org.splat.kernel.MissedPropertyException;
21 import org.splat.kernel.MultiplyDefinedException;
22 import org.splat.kernel.ObjectProperties;
25 public abstract class Entity extends Any {
27 private Set<Relation> relations;
29 // ==============================================================================================================================
31 // ==============================================================================================================================
33 // Database fetch constructor
36 // Initialization constructor
37 protected Entity (ObjectProperties prop) throws MissedPropertyException, InvalidPropertyException, MultiplyDefinedException {
38 // ----------------------------------------
40 relations = new HashSet<Relation>();
43 // ==============================================================================================================================
44 // Public member functions
45 // ==============================================================================================================================
47 public Relation getFirstRelation (Class<? extends Relation> type) {
48 // -----------------------------------------------------------------
49 for (Iterator<Relation> i=relations.iterator(); i.hasNext();) {
50 Relation link = i.next();
51 if (link.getClass().equals(type)) return link;
56 public List<Relation> getRelations (Class<? extends Relation> type) {
57 // -------------------------------------------------------------------
58 List<Relation> result = new Vector<Relation>();
60 for (Iterator<Relation> i=relations.iterator(); i.hasNext();) {
61 Relation link = i.next();
62 if (link.getClass().equals(type)) result.add(link);
67 // ==============================================================================================================================
69 // ==============================================================================================================================
71 protected Set<Relation> getAllRelations () {
72 // ------------------------------------------
76 protected Relation addRelation (Relation link) {
77 // ----------------------------------------------
78 // Session session = Database.getSession();
80 // session.save(link);
82 // session.update(this);
84 if (link.isBidirectional()) {
85 Entity to = (Entity)link.getTo(); // Bidirectional relation are necessarily between entities
87 link = link.getReverse();
88 // session.save(link);
89 // if (to.relations == null) to.relations = new HashSet<Relation>();
90 to.relations.add(link);
91 // session.update(to);
96 protected void removeRelation (Class<? extends Relation> type, Persistent to) {
97 // -----------------------------------------------------------------------------
98 for (Iterator<Relation> i=relations.iterator(); i.hasNext();) {
99 Relation link = i.next();
100 if (!link.getClass().equals(type)) continue;
101 if (!link.getTo().equals(to)) continue;
103 //RKV if (this.isSaved()) Database.getCurSession().update(this);