[Bprocessor-commit] model/src/net/sourceforge/bprocessor/model Attribute.java,1.1.1.1,1.2 Constructi
Status: Pre-Alpha
Brought to you by:
henryml
Update of /cvsroot/bprocessor/model/src/net/sourceforge/bprocessor/model In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv7693 Modified Files: Attribute.java ConstructionSpaceFacade.java ConstructionSpace.java Domain.java EdgeFacade.java Edge.java ElementFacade.java Element.java FunctionalSpaceFacade.java FunctionalSpace.java PartFacade.java Part.java Space.java SurfaceFacade.java Surface.java VertexFacade.java Vertex.java Log Message: Use Hibernate for the persistence layer Index: EdgeFacade.java =================================================================== RCS file: /cvsroot/bprocessor/model/src/net/sourceforge/bprocessor/model/EdgeFacade.java,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** EdgeFacade.java 11 Jul 2005 09:31:23 -0000 1.1 --- EdgeFacade.java 28 Jul 2005 06:48:54 -0000 1.2 *************** *** 7,11 **** package net.sourceforge.bprocessor.model; ! import java.util.Collections; import java.util.HashSet; import java.util.Iterator; --- 7,12 ---- package net.sourceforge.bprocessor.model; ! import net.sourceforge.bprocessor.model.db.HibernateUtil; ! import java.util.HashSet; import java.util.Iterator; *************** *** 13,16 **** --- 14,20 ---- import org.apache.log4j.Logger; + import org.hibernate.Query; + import org.hibernate.Session; + import org.hibernate.Transaction; /** *************** *** 24,35 **** private static EdgeFacade instance; - /** Edges */ - private Set edges; - /** * Constructor */ private EdgeFacade() { - edges = new HashSet(); } --- 28,35 ---- *************** *** 46,102 **** /** ! * Add a edge * @param e The edge */ ! public synchronized void add(Edge e) { ! edges.add(e); } /** ! * Remove a edge * @param e The edge */ public synchronized void remove(Edge e) { ! edges.remove(e); } /** * Find all edges ! * @return The edges (unmodifiable) */ public Set findAll() { ! return Collections.unmodifiableSet(edges); } /** ! * Find a edge by id * @param id The id * @return The edge */ ! public synchronized Edge findById(Long id) { ! Iterator it = edges.iterator(); ! while (it.hasNext()) { ! Edge e = (Edge)it.next(); ! if (e.getId().equals(id)) { ! return e; ! } } ! return null; } /** ! * Find a edge by name * @param name The name * @return The edge */ ! public synchronized Edge findByName(String name) { ! Iterator it = edges.iterator(); ! while (it.hasNext()) { ! Edge e = (Edge)it.next(); ! if (e.getName().equals(name)) { ! return e; } } ! return null; } } --- 46,194 ---- /** ! * Create an edge * @param e The edge + * @return The edge */ ! public synchronized Edge create(Edge e) { ! HibernateUtil hu = HibernateUtil.getInstance(); ! try { ! Session session = hu.currentSession(); ! Transaction tx = session.beginTransaction(); ! ! session.save(e); ! ! tx.commit(); ! } catch (Exception ex) { ! log.error(ex.getMessage(), ex); ! } finally { ! hu.closeSession(); ! } ! ! return e; } /** ! * Update an edge ! * @param e The edge ! */ ! public synchronized void update(Edge e) { ! HibernateUtil hu = HibernateUtil.getInstance(); ! try { ! Session session = hu.currentSession(); ! Transaction tx = session.beginTransaction(); ! ! session.update(e); ! ! tx.commit(); ! } catch (Exception ex) { ! log.error(ex.getMessage(), ex); ! } finally { ! hu.closeSession(); ! } ! } ! ! /** ! * Remove an edge * @param e The edge */ public synchronized void remove(Edge e) { ! HibernateUtil hu = HibernateUtil.getInstance(); ! try { ! Session session = hu.currentSession(); ! Transaction tx = session.beginTransaction(); ! ! session.delete(e); ! ! tx.commit(); ! } catch (Exception ex) { ! log.error(ex.getMessage(), ex); ! } finally { ! hu.closeSession(); ! } } /** * Find all edges ! * @return The edges */ public Set findAll() { ! Set result = new HashSet(); ! ! HibernateUtil hu = HibernateUtil.getInstance(); ! try { ! Session session = hu.currentSession(); ! Transaction tx = session.beginTransaction(); ! ! Query q = session.createQuery("SELECT e FROM Edge AS e"); ! ! Iterator it = q.iterate(); ! while (it.hasNext()) { ! result.add((Edge)it.next()); ! } ! ! tx.commit(); ! } catch (Exception ex) { ! log.error(ex.getMessage(), ex); ! } finally { ! hu.closeSession(); ! } ! ! return result; } /** ! * Find an edge by id * @param id The id * @return The edge */ ! public Edge findById(Long id) { ! Edge result = null; ! ! HibernateUtil hu = HibernateUtil.getInstance(); ! try { ! Session session = hu.currentSession(); ! Transaction tx = session.beginTransaction(); ! ! result = (Edge)session.load(Edge.class, id); ! ! tx.commit(); ! } catch (Exception ex) { ! log.error(ex.getMessage(), ex); ! } finally { ! hu.closeSession(); } ! ! return result; } /** ! * Find an edge by name * @param name The name * @return The edge */ ! public Edge findByName(String name) { ! Edge result = null; ! ! HibernateUtil hu = HibernateUtil.getInstance(); ! try { ! Session session = hu.currentSession(); ! Transaction tx = session.beginTransaction(); ! ! Query q = session.createQuery("SELECT e FROM Edge AS e WHERE e.name = :name"); ! q.setString("name", name); ! ! Iterator it = q.iterate(); ! if (it.hasNext()) { ! result = (Edge)it.next(); } + + tx.commit(); + } catch (Exception ex) { + log.error(ex.getMessage(), ex); + } finally { + hu.closeSession(); } ! ! return result; } } Index: ConstructionSpaceFacade.java =================================================================== RCS file: /cvsroot/bprocessor/model/src/net/sourceforge/bprocessor/model/ConstructionSpaceFacade.java,v retrieving revision 1.1.1.1 retrieving revision 1.2 diff -C2 -d -r1.1.1.1 -r1.2 *** ConstructionSpaceFacade.java 27 Jun 2005 09:31:14 -0000 1.1.1.1 --- ConstructionSpaceFacade.java 28 Jul 2005 06:48:54 -0000 1.2 *************** *** 7,11 **** package net.sourceforge.bprocessor.model; ! import java.util.Collections; import java.util.HashSet; import java.util.Iterator; --- 7,12 ---- package net.sourceforge.bprocessor.model; ! import net.sourceforge.bprocessor.model.db.HibernateUtil; ! import java.util.HashSet; import java.util.Iterator; *************** *** 13,16 **** --- 14,20 ---- import org.apache.log4j.Logger; + import org.hibernate.Query; + import org.hibernate.Session; + import org.hibernate.Transaction; /** *************** *** 24,35 **** private static ConstructionSpaceFacade instance; - /** Construction spaces */ - private Set constructionSpaces; - /** * Constructor */ private ConstructionSpaceFacade() { - constructionSpaces = new HashSet(); } --- 28,35 ---- *************** *** 46,54 **** /** ! * Add a construction space * @param c The construction space */ ! public synchronized void add(ConstructionSpace c) { ! constructionSpaces.add(c); } --- 46,89 ---- /** ! * Create a construction space * @param c The construction space + * @return The construction space */ ! public synchronized ConstructionSpace create(ConstructionSpace c) { ! HibernateUtil hu = HibernateUtil.getInstance(); ! try { ! Session session = hu.currentSession(); ! Transaction tx = session.beginTransaction(); ! ! session.save(c); ! ! tx.commit(); ! } catch (Exception ex) { ! log.error(ex.getMessage(), ex); ! } finally { ! hu.closeSession(); ! } ! ! return c; ! } ! ! /** ! * Update a construction space ! * @param c The construction space ! */ ! public synchronized void update(ConstructionSpace c) { ! HibernateUtil hu = HibernateUtil.getInstance(); ! try { ! Session session = hu.currentSession(); ! Transaction tx = session.beginTransaction(); ! ! session.update(c); ! ! tx.commit(); ! } catch (Exception ex) { ! log.error(ex.getMessage(), ex); ! } finally { ! hu.closeSession(); ! } } *************** *** 58,70 **** */ public synchronized void remove(ConstructionSpace c) { ! constructionSpaces.remove(c); } /** * Find all construction spaces ! * @return The construction spaces (unmodifiable) */ public Set findAll() { ! return Collections.unmodifiableSet(constructionSpaces); } --- 93,138 ---- */ public synchronized void remove(ConstructionSpace c) { ! HibernateUtil hu = HibernateUtil.getInstance(); ! try { ! Session session = hu.currentSession(); ! Transaction tx = session.beginTransaction(); ! ! session.delete(c); ! ! tx.commit(); ! } catch (Exception ex) { ! log.error(ex.getMessage(), ex); ! } finally { ! hu.closeSession(); ! } } /** * Find all construction spaces ! * @return The construction spaces */ public Set findAll() { ! Set result = new HashSet(); ! ! HibernateUtil hu = HibernateUtil.getInstance(); ! try { ! Session session = hu.currentSession(); ! Transaction tx = session.beginTransaction(); ! ! Query q = session.createQuery("SELECT c FROM ConstructionSpace AS c"); ! ! Iterator it = q.iterate(); ! while (it.hasNext()) { ! result.add((ConstructionSpace)it.next()); ! } ! ! tx.commit(); ! } catch (Exception ex) { ! log.error(ex.getMessage(), ex); ! } finally { ! hu.closeSession(); ! } ! ! return result; } *************** *** 74,86 **** * @return The construction space */ ! public synchronized ConstructionSpace findById(Long id) { ! Iterator it = constructionSpaces.iterator(); ! while (it.hasNext()) { ! ConstructionSpace c = (ConstructionSpace)it.next(); ! if (c.getId().equals(id)) { ! return c; ! } } ! return null; } --- 142,163 ---- * @return The construction space */ ! public ConstructionSpace findById(Long id) { ! ConstructionSpace result = null; ! ! HibernateUtil hu = HibernateUtil.getInstance(); ! try { ! Session session = hu.currentSession(); ! Transaction tx = session.beginTransaction(); ! ! result = (ConstructionSpace)session.load(ConstructionSpace.class, id); ! ! tx.commit(); ! } catch (Exception ex) { ! log.error(ex.getMessage(), ex); ! } finally { ! hu.closeSession(); } ! ! return result; } *************** *** 90,102 **** * @return The construction space */ ! public synchronized ConstructionSpace findByName(String name) { ! Iterator it = constructionSpaces.iterator(); ! while (it.hasNext()) { ! ConstructionSpace c = (ConstructionSpace)it.next(); ! if (c.getName().equals(name)) { ! return c; } } ! return null; } } --- 167,194 ---- * @return The construction space */ ! public ConstructionSpace findByName(String name) { ! ConstructionSpace result = null; ! ! HibernateUtil hu = HibernateUtil.getInstance(); ! try { ! Session session = hu.currentSession(); ! Transaction tx = session.beginTransaction(); ! ! Query q = session.createQuery("SELECT c FROM ConstructionSpace AS c WHERE c.name = :name"); ! q.setString("name", name); ! ! Iterator it = q.iterate(); ! if (it.hasNext()) { ! result = (ConstructionSpace)it.next(); } + + tx.commit(); + } catch (Exception ex) { + log.error(ex.getMessage(), ex); + } finally { + hu.closeSession(); } ! ! return result; } } Index: ElementFacade.java =================================================================== RCS file: /cvsroot/bprocessor/model/src/net/sourceforge/bprocessor/model/ElementFacade.java,v retrieving revision 1.1.1.1 retrieving revision 1.2 diff -C2 -d -r1.1.1.1 -r1.2 *** ElementFacade.java 27 Jun 2005 09:31:14 -0000 1.1.1.1 --- ElementFacade.java 28 Jul 2005 06:48:54 -0000 1.2 *************** *** 7,11 **** package net.sourceforge.bprocessor.model; ! import java.util.Collections; import java.util.HashSet; import java.util.Iterator; --- 7,12 ---- package net.sourceforge.bprocessor.model; ! import net.sourceforge.bprocessor.model.db.HibernateUtil; ! import java.util.HashSet; import java.util.Iterator; *************** *** 13,16 **** --- 14,20 ---- import org.apache.log4j.Logger; + import org.hibernate.Query; + import org.hibernate.Session; + import org.hibernate.Transaction; /** *************** *** 24,35 **** private static ElementFacade instance; - /** Elements */ - private Set elements; - /** * Constructor */ private ElementFacade() { - elements = new HashSet(); } --- 28,35 ---- *************** *** 46,54 **** /** ! * Add an element * @param e The element */ ! public synchronized void add(Element e) { ! elements.add(e); } --- 46,89 ---- /** ! * Create an element * @param e The element + * @return The element */ ! public synchronized Element create(Element e) { ! HibernateUtil hu = HibernateUtil.getInstance(); ! try { ! Session session = hu.currentSession(); ! Transaction tx = session.beginTransaction(); ! ! session.save(e); ! ! tx.commit(); ! } catch (Exception ex) { ! log.error(ex.getMessage(), ex); ! } finally { ! hu.closeSession(); ! } ! ! return e; ! } ! ! /** ! * Update an element ! * @param e The element ! */ ! public synchronized void update(Element e) { ! HibernateUtil hu = HibernateUtil.getInstance(); ! try { ! Session session = hu.currentSession(); ! Transaction tx = session.beginTransaction(); ! ! session.update(e); ! ! tx.commit(); ! } catch (Exception ex) { ! log.error(ex.getMessage(), ex); ! } finally { ! hu.closeSession(); ! } } *************** *** 58,70 **** */ public synchronized void remove(Element e) { ! elements.remove(e); } /** * Find all elements ! * @return The elements (unmodifiable) */ public Set findAll() { ! return Collections.unmodifiableSet(elements); } --- 93,138 ---- */ public synchronized void remove(Element e) { ! HibernateUtil hu = HibernateUtil.getInstance(); ! try { ! Session session = hu.currentSession(); ! Transaction tx = session.beginTransaction(); ! ! session.delete(e); ! ! tx.commit(); ! } catch (Exception ex) { ! log.error(ex.getMessage(), ex); ! } finally { ! hu.closeSession(); ! } } /** * Find all elements ! * @return The elements */ public Set findAll() { ! Set result = new HashSet(); ! ! HibernateUtil hu = HibernateUtil.getInstance(); ! try { ! Session session = hu.currentSession(); ! Transaction tx = session.beginTransaction(); ! ! Query q = session.createQuery("SELECT e FROM Element AS e"); ! ! Iterator it = q.iterate(); ! while (it.hasNext()) { ! result.add((Element)it.next()); ! } ! ! tx.commit(); ! } catch (Exception ex) { ! log.error(ex.getMessage(), ex); ! } finally { ! hu.closeSession(); ! } ! ! return result; } *************** *** 74,86 **** * @return The element */ ! public synchronized Element findById(Long id) { ! Iterator it = elements.iterator(); ! while (it.hasNext()) { ! Element e = (Element)it.next(); ! if (e.getId().equals(id)) { ! return e; ! } } ! return null; } --- 142,163 ---- * @return The element */ ! public Element findById(Long id) { ! Element result = null; ! ! HibernateUtil hu = HibernateUtil.getInstance(); ! try { ! Session session = hu.currentSession(); ! Transaction tx = session.beginTransaction(); ! ! result = (Element)session.load(Element.class, id); ! ! tx.commit(); ! } catch (Exception ex) { ! log.error(ex.getMessage(), ex); ! } finally { ! hu.closeSession(); } ! ! return result; } *************** *** 90,102 **** * @return The element */ ! public synchronized Element findByName(String name) { ! Iterator it = elements.iterator(); ! while (it.hasNext()) { ! Element e = (Element)it.next(); ! if (e.getName().equals(name)) { ! return e; } } ! return null; } } --- 167,194 ---- * @return The element */ ! public Element findByName(String name) { ! Element result = null; ! ! HibernateUtil hu = HibernateUtil.getInstance(); ! try { ! Session session = hu.currentSession(); ! Transaction tx = session.beginTransaction(); ! ! Query q = session.createQuery("SELECT e FROM Element AS e WHERE e.name = :name"); ! q.setString("name", name); ! ! Iterator it = q.iterate(); ! if (it.hasNext()) { ! result = (Element)it.next(); } + + tx.commit(); + } catch (Exception ex) { + log.error(ex.getMessage(), ex); + } finally { + hu.closeSession(); } ! ! return result; } } Index: FunctionalSpace.java =================================================================== RCS file: /cvsroot/bprocessor/model/src/net/sourceforge/bprocessor/model/FunctionalSpace.java,v retrieving revision 1.1.1.1 retrieving revision 1.2 diff -C2 -d -r1.1.1.1 -r1.2 *** FunctionalSpace.java 27 Jun 2005 09:31:14 -0000 1.1.1.1 --- FunctionalSpace.java 28 Jul 2005 06:48:54 -0000 1.2 *************** *** 11,14 **** --- 11,19 ---- /** * The functional space + * @hibernate.joined-subclass + * table="FUNCTIONALSPACE" + * lazy="false" + * @hibernate.key + * column="SPACE_ID" */ public class FunctionalSpace extends Space { *************** *** 16,21 **** private static Logger log = Logger.getLogger(FunctionalSpace.class); ! /** Id generator */ ! private static long l = 0; /** --- 21,26 ---- private static Logger log = Logger.getLogger(FunctionalSpace.class); ! /** The functional space id */ ! private Long functionalSpaceId; /** *************** *** 30,35 **** */ public FunctionalSpace(String name) { ! super(new Long(l++)); setName(name); } --- 35,60 ---- */ public FunctionalSpace(String name) { ! super(); setName(name); + setElements(null); + } + + /** + * Get the functional space id + * @return The functional space id + * @hibernate.id + * column="FUNCTIONALSPACE_ID" + * generator-class="increment" + */ + protected Long getFunctionalSpaceId() { + return functionalSpaceId; + } + + /** + * Set the functional space id + * @param id The functional space id + */ + private void setFunctionalSpaceId(Long id) { + this.functionalSpaceId = id; } *************** *** 56,58 **** --- 81,91 ---- return getId().equals(fs.getId()); } + + /** + * String representation of the object + * @return The string + */ + public String toString() { + return "FunctionalSpace[" + super.toString() + "]"; + } } Index: Surface.java =================================================================== RCS file: /cvsroot/bprocessor/model/src/net/sourceforge/bprocessor/model/Surface.java,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** Surface.java 18 Jul 2005 09:24:35 -0000 1.3 --- Surface.java 28 Jul 2005 06:48:54 -0000 1.4 *************** *** 8,12 **** import java.io.Serializable; - import java.util.HashSet; import java.util.Set; --- 8,11 ---- *************** *** 15,18 **** --- 14,20 ---- /** * The surface + * @hibernate.class + * table="SURFACE" + * lazy="false" */ public class Surface implements Serializable { *************** *** 20,26 **** private static Logger log = Logger.getLogger(Surface.class); - /** Id generator */ - private static long l = 0; - /** The id */ private Long id; --- 22,25 ---- *************** *** 46,53 **** */ public Surface(String name) { ! setId(new Long(l++)); setName(name); setConstructor(false); ! setEdges(new HashSet()); } --- 45,52 ---- */ public Surface(String name) { ! super(); setName(name); setConstructor(false); ! setEdges(null); } *************** *** 55,58 **** --- 54,60 ---- * Get the id * @return The id + * @hibernate.id + * column="SURFACE_ID" + * generator-class="increment" */ public Long getId() { *************** *** 71,74 **** --- 73,77 ---- * Get the name * @return The name + * @hibernate.property */ public String getName() { *************** *** 87,90 **** --- 90,94 ---- * Is the surface a constructor * @return True if constructor; otherwise false + * @hibernate.property */ public boolean getConstructor() { *************** *** 103,106 **** --- 107,117 ---- * Get the edges * @return The edges + * @hibernate.set + * cascade="delete" + * lazy="false" + * @hibernate.key + * column="SURFACE_ID" + * @hibernate.one-to-many + * class="net.sourceforge.bprocessor.model.Edge" */ public Set getEdges() { *************** *** 138,140 **** --- 149,160 ---- return this.id.equals(s.getId()); } + + /** + * String representation of the object + * @return The string + */ + public String toString() { + return "Surface[id=" + id + ",name=" + name + ",constructor=" + constructor + + ",edges=" + edges.size() + "]"; + } } Index: Part.java =================================================================== RCS file: /cvsroot/bprocessor/model/src/net/sourceforge/bprocessor/model/Part.java,v retrieving revision 1.1.1.1 retrieving revision 1.2 diff -C2 -d -r1.1.1.1 -r1.2 *** Part.java 27 Jun 2005 09:31:14 -0000 1.1.1.1 --- Part.java 28 Jul 2005 06:48:54 -0000 1.2 *************** *** 11,14 **** --- 11,19 ---- /** * The part + * @hibernate.joined-subclass + * table="PART" + * lazy="false" + * @hibernate.key + * column="DOMAIN_ID" */ public class Part extends Domain { *************** *** 16,21 **** private static Logger log = Logger.getLogger(Part.class); ! /** Id generator */ ! private static long l = 0; /** --- 21,26 ---- private static Logger log = Logger.getLogger(Part.class); ! /** The part id */ ! private Long partId; /** *************** *** 30,38 **** */ public Part(String name) { ! super(new Long(l++)); setName(name); } /** * Return the hash code of the object * @return The hash --- 35,62 ---- */ public Part(String name) { ! super(); setName(name); } /** + * Get the part id + * @return The part id + * @hibernate.id + * column="PART_ID" + * generator-class="increment" + */ + protected Long getPartId() { + return partId; + } + + /** + * Set the part id + * @param id The part id + */ + private void setPartId(Long id) { + this.partId = id; + } + + /** * Return the hash code of the object * @return The hash *************** *** 56,58 **** --- 80,90 ---- return getId().equals(p.getId()); } + + /** + * String representation of the object + * @return The string + */ + public String toString() { + return "Part[" + super.toString() + "]"; + } } Index: Edge.java =================================================================== RCS file: /cvsroot/bprocessor/model/src/net/sourceforge/bprocessor/model/Edge.java,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** Edge.java 18 Jul 2005 09:25:05 -0000 1.2 --- Edge.java 28 Jul 2005 06:48:54 -0000 1.3 *************** *** 13,16 **** --- 13,19 ---- /** * The edge + * @hibernate.class + * table="EDGE" + * lazy="false" */ public class Edge implements Serializable { *************** *** 18,24 **** private static Logger log = Logger.getLogger(Edge.class); - /** Id generator */ - private static long l = 0; - /** The id */ private Long id; --- 21,24 ---- *************** *** 44,51 **** */ public Edge(String name) { ! setId(new Long(l++)); setName(name); ! setFrom(new Vertex()); ! setTo(new Vertex()); } --- 44,51 ---- */ public Edge(String name) { ! super(); setName(name); ! setFrom(null); ! setTo(null); } *************** *** 53,56 **** --- 53,59 ---- * Get the id * @return The id + * @hibernate.id + * column="EDGE_ID" + * generator-class="increment" */ public Long getId() { *************** *** 69,72 **** --- 72,76 ---- * Get the name * @return The name + * @hibernate.property */ public String getName() { *************** *** 85,88 **** --- 89,95 ---- * Get the to vertex * @return The end vertex + * @hibernate.many-to-one + * column="TO_ID" + * class="net.sourceforge.bprocessor.model.Vertex" */ public Vertex getTo() { *************** *** 101,104 **** --- 108,114 ---- * Get the from vertex * @return The begin vertex + * @hibernate.many-to-one + * column="FROM_ID" + * class="net.sourceforge.bprocessor.model.Vertex" */ public Vertex getFrom() { *************** *** 136,138 **** --- 146,156 ---- return this.id.equals(e.getId()); } + + /** + * String representation of the object + * @return The string + */ + public String toString() { + return "Edge[id=" + id + ",name=" + name + ",from=" + from + ",to=" + to + "]"; + } } Index: ConstructionSpace.java =================================================================== RCS file: /cvsroot/bprocessor/model/src/net/sourceforge/bprocessor/model/ConstructionSpace.java,v retrieving revision 1.1.1.1 retrieving revision 1.2 diff -C2 -d -r1.1.1.1 -r1.2 *** ConstructionSpace.java 27 Jun 2005 09:31:14 -0000 1.1.1.1 --- ConstructionSpace.java 28 Jul 2005 06:48:54 -0000 1.2 *************** *** 11,14 **** --- 11,19 ---- /** * The construction space + * @hibernate.joined-subclass + * table="CONSTRUCTIONSPACE" + * lazy="false" + * @hibernate.key + * column="SPACE_ID" */ public class ConstructionSpace extends Space { *************** *** 16,21 **** private static Logger log = Logger.getLogger(ConstructionSpace.class); ! /** Id generator */ ! private static long l = 0; /** --- 21,26 ---- private static Logger log = Logger.getLogger(ConstructionSpace.class); ! /** The construction space id */ ! private Long constructionSpaceId; /** *************** *** 30,35 **** */ public ConstructionSpace(String name) { ! super(new Long(l++)); setName(name); } --- 35,60 ---- */ public ConstructionSpace(String name) { ! super(); setName(name); + setElements(null); + } + + /** + * Get the construction space id + * @return The construction space id + * @hibernate.id + * column="CONSTRUCTIONSPACE_ID" + * generator-class="increment" + */ + protected Long getConstructionSpaceId() { + return constructionSpaceId; + } + + /** + * Set the construction space id + * @param id The construction space id + */ + private void setConstructionSpaceId(Long id) { + this.constructionSpaceId = id; } *************** *** 56,58 **** --- 81,91 ---- return getId().equals(cs.getId()); } + + /** + * String representation of the object + * @return The string + */ + public String toString() { + return "ConstructionSpace[" + super.toString() + "]"; + } } Index: Attribute.java =================================================================== RCS file: /cvsroot/bprocessor/model/src/net/sourceforge/bprocessor/model/Attribute.java,v retrieving revision 1.1.1.1 retrieving revision 1.2 diff -C2 -d -r1.1.1.1 -r1.2 *** Attribute.java 27 Jun 2005 09:31:14 -0000 1.1.1.1 --- Attribute.java 28 Jul 2005 06:48:54 -0000 1.2 *************** *** 13,16 **** --- 13,20 ---- /** * The attribute + * + * @hibernate.class + * table="ATTRIBUTE" + * lazy="false" */ public class Attribute implements Serializable { *************** *** 18,24 **** private static Logger log = Logger.getLogger(Attribute.class); - /** Id generator */ - private static long l = 0; - /** The id */ private Long id; --- 22,25 ---- *************** *** 31,35 **** /** The value */ ! private Object value; /** --- 32,36 ---- /** The value */ ! private String value; /** *************** *** 45,50 **** * @param value The value */ ! public Attribute(String name, String type, Object value) { ! setId(new Long(l++)); setName(name); setType(type); --- 46,51 ---- * @param value The value */ ! public Attribute(String name, String type, String value) { ! super(); setName(name); setType(type); *************** *** 55,58 **** --- 56,61 ---- * Get the id * @return The id + * @hibernate.id + * generator-class="increment" */ public Long getId() { *************** *** 71,74 **** --- 74,78 ---- * Get the name * @return The name + * @hibernate.property */ public String getName() { *************** *** 87,90 **** --- 91,95 ---- * Get the type * @return The type + * @hibernate.property */ public String getType() { *************** *** 103,108 **** * Get the value * @return The value */ ! public Object getValue() { return value; } --- 108,114 ---- * Get the value * @return The value + * @hibernate.property */ ! public String getValue() { return value; } *************** *** 112,116 **** * @param value The value */ ! public void setValue(Object value) { this.value = value; } --- 118,122 ---- * @param value The value */ ! public void setValue(String value) { this.value = value; } *************** *** 138,140 **** --- 144,154 ---- return this.id.equals(a.getId()); } + + /** + * String representation of the object + * @return The string + */ + public String toString() { + return "Attribute[id=" + id + ",name=" + name + ",type=" + type + ",value=" + value + "]"; + } } Index: Space.java =================================================================== RCS file: /cvsroot/bprocessor/model/src/net/sourceforge/bprocessor/model/Space.java,v retrieving revision 1.1.1.1 retrieving revision 1.2 diff -C2 -d -r1.1.1.1 -r1.2 *** Space.java 27 Jun 2005 09:31:14 -0000 1.1.1.1 --- Space.java 28 Jul 2005 06:48:54 -0000 1.2 *************** *** 7,11 **** package net.sourceforge.bprocessor.model; - import java.util.HashSet; import java.util.Set; --- 7,10 ---- *************** *** 14,17 **** --- 13,21 ---- /** * The space + * @hibernate.joined-subclass + * table="SPACE" + * lazy="false" + * @hibernate.key + * column="DOMAIN_ID" */ public abstract class Space extends Domain { *************** *** 19,22 **** --- 23,29 ---- private static Logger log = Logger.getLogger(Space.class); + /** The space id */ + private Long spaceId; + /** The elements */ private Set elements; *************** *** 29,38 **** /** ! * Constructor ! * @param id The id */ ! protected Space(Long id) { ! super(id); ! setElements(new HashSet()); } --- 36,55 ---- /** ! * Get the space id ! * @return The space id ! * @hibernate.id ! * column="SPACE_ID" ! * generator-class="increment" */ ! protected Long getSpaceId() { ! return spaceId; ! } ! ! /** ! * Set the space id ! * @param id The space id ! */ ! private void setSpaceId(Long id) { ! this.spaceId = id; } *************** *** 40,43 **** --- 57,67 ---- * Get the elements * @return The elements + * @hibernate.set + * cascade="delete" + * lazy="false" + * @hibernate.key + * column="SPACE_ID" + * @hibernate.one-to-many + * class="net.sourceforge.bprocessor.model.Element" */ public Set getElements() { *************** *** 52,54 **** --- 76,86 ---- this.elements = elements; } + + /** + * String representation of the object + * @return The string + */ + public String toString() { + return "Space[" + super.toString() + ",elements=" + elements.size() + "]"; + } } Index: SurfaceFacade.java =================================================================== RCS file: /cvsroot/bprocessor/model/src/net/sourceforge/bprocessor/model/SurfaceFacade.java,v retrieving revision 1.1.1.1 retrieving revision 1.2 diff -C2 -d -r1.1.1.1 -r1.2 *** SurfaceFacade.java 27 Jun 2005 09:31:14 -0000 1.1.1.1 --- SurfaceFacade.java 28 Jul 2005 06:48:54 -0000 1.2 *************** *** 7,11 **** package net.sourceforge.bprocessor.model; ! import java.util.Collections; import java.util.HashSet; import java.util.Iterator; --- 7,12 ---- package net.sourceforge.bprocessor.model; ! import net.sourceforge.bprocessor.model.db.HibernateUtil; ! import java.util.HashSet; import java.util.Iterator; *************** *** 13,16 **** --- 14,20 ---- import org.apache.log4j.Logger; + import org.hibernate.Query; + import org.hibernate.Session; + import org.hibernate.Transaction; /** *************** *** 24,35 **** private static SurfaceFacade instance; - /** Surfaces */ - private Set surfaces; - /** * Constructor */ private SurfaceFacade() { - surfaces = new HashSet(); } --- 28,35 ---- *************** *** 46,54 **** /** ! * Add a surface * @param s The surface */ ! public synchronized void add(Surface s) { ! surfaces.add(s); } --- 46,89 ---- /** ! * Create a surface * @param s The surface + * @return The created surface */ ! public synchronized Surface create(Surface s) { ! HibernateUtil hu = HibernateUtil.getInstance(); ! try { ! Session session = hu.currentSession(); ! Transaction tx = session.beginTransaction(); ! ! session.save(s); ! ! tx.commit(); ! } catch (Exception ex) { ! log.error(ex.getMessage(), ex); ! } finally { ! hu.closeSession(); ! } ! ! return s; ! } ! ! /** ! * Update a surface ! * @param s The surface ! */ ! public synchronized void update(Surface s) { ! HibernateUtil hu = HibernateUtil.getInstance(); ! try { ! Session session = hu.currentSession(); ! Transaction tx = session.beginTransaction(); ! ! session.update(s); ! ! tx.commit(); ! } catch (Exception ex) { ! log.error(ex.getMessage(), ex); ! } finally { ! hu.closeSession(); ! } } *************** *** 58,70 **** */ public synchronized void remove(Surface s) { ! surfaces.remove(s); } /** * Find all surfaces ! * @return The surfaces (unmodifiable) */ public Set findAll() { ! return Collections.unmodifiableSet(surfaces); } --- 93,138 ---- */ public synchronized void remove(Surface s) { ! HibernateUtil hu = HibernateUtil.getInstance(); ! try { ! Session session = hu.currentSession(); ! Transaction tx = session.beginTransaction(); ! ! session.delete(s); ! ! tx.commit(); ! } catch (Exception ex) { ! log.error(ex.getMessage(), ex); ! } finally { ! hu.closeSession(); ! } } /** * Find all surfaces ! * @return The surfaces */ public Set findAll() { ! Set result = new HashSet(); ! ! HibernateUtil hu = HibernateUtil.getInstance(); ! try { ! Session session = hu.currentSession(); ! Transaction tx = session.beginTransaction(); ! ! Query q = session.createQuery("SELECT s FROM Surface AS s"); ! ! Iterator it = q.iterate(); ! while (it.hasNext()) { ! result.add((Surface)it.next()); ! } ! ! tx.commit(); ! } catch (Exception ex) { ! log.error(ex.getMessage(), ex); ! } finally { ! hu.closeSession(); ! } ! ! return result; } *************** *** 74,86 **** * @return The surface */ ! public synchronized Surface findById(Long id) { ! Iterator it = surfaces.iterator(); ! while (it.hasNext()) { ! Surface s = (Surface)it.next(); ! if (s.getId().equals(id)) { ! return s; ! } } ! return null; } --- 142,163 ---- * @return The surface */ ! public Surface findById(Long id) { ! Surface result = null; ! ! HibernateUtil hu = HibernateUtil.getInstance(); ! try { ! Session session = hu.currentSession(); ! Transaction tx = session.beginTransaction(); ! ! result = (Surface)session.load(Surface.class, id); ! ! tx.commit(); ! } catch (Exception ex) { ! log.error(ex.getMessage(), ex); ! } finally { ! hu.closeSession(); } ! ! return result; } *************** *** 90,102 **** * @return The surface */ ! public synchronized Surface findByName(String name) { ! Iterator it = surfaces.iterator(); ! while (it.hasNext()) { ! Surface s = (Surface)it.next(); ! if (s.getName().equals(name)) { ! return s; } } ! return null; } } --- 167,194 ---- * @return The surface */ ! public Surface findByName(String name) { ! Surface result = null; ! ! HibernateUtil hu = HibernateUtil.getInstance(); ! try { ! Session session = hu.currentSession(); ! Transaction tx = session.beginTransaction(); ! ! Query q = session.createQuery("SELECT s FROM Surface AS s WHERE s.name = :name"); ! q.setString("name", name); ! ! Iterator it = q.iterate(); ! if (it.hasNext()) { ! result = (Surface)it.next(); } + + tx.commit(); + } catch (Exception ex) { + log.error(ex.getMessage(), ex); + } finally { + hu.closeSession(); } ! ! return result; } } Index: VertexFacade.java =================================================================== RCS file: /cvsroot/bprocessor/model/src/net/sourceforge/bprocessor/model/VertexFacade.java,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** VertexFacade.java 11 Jul 2005 09:31:24 -0000 1.1 --- VertexFacade.java 28 Jul 2005 06:48:54 -0000 1.2 *************** *** 7,11 **** package net.sourceforge.bprocessor.model; ! import java.util.Collections; import java.util.HashSet; import java.util.Iterator; --- 7,12 ---- package net.sourceforge.bprocessor.model; ! import net.sourceforge.bprocessor.model.db.HibernateUtil; ! import java.util.HashSet; import java.util.Iterator; *************** *** 13,16 **** --- 14,20 ---- import org.apache.log4j.Logger; + import org.hibernate.Query; + import org.hibernate.Session; + import org.hibernate.Transaction; /** *************** *** 24,35 **** private static VertexFacade instance; - /** Vertexs */ - private Set vertexs; - /** * Constructor */ private VertexFacade() { - vertexs = new HashSet(); } --- 28,35 ---- *************** *** 46,54 **** /** ! * Add a vertex * @param v The vertex */ ! public synchronized void add(Vertex v) { ! vertexs.add(v); } --- 46,89 ---- /** ! * Create a vertex * @param v The vertex + * @return The vertex */ ! public synchronized Vertex create(Vertex v) { ! HibernateUtil hu = HibernateUtil.getInstance(); ! try { ! Session session = hu.currentSession(); ! Transaction tx = session.beginTransaction(); ! ! session.save(v); ! ! tx.commit(); ! } catch (Exception ex) { ! log.error(ex.getMessage(), ex); ! } finally { ! hu.closeSession(); ! } ! ! return v; ! } ! ! /** ! * Update a vertex ! * @param v The vertex ! */ ! public synchronized void update(Vertex v) { ! HibernateUtil hu = HibernateUtil.getInstance(); ! try { ! Session session = hu.currentSession(); ! Transaction tx = session.beginTransaction(); ! ! session.update(v); ! ! tx.commit(); ! } catch (Exception ex) { ! log.error(ex.getMessage(), ex); ! } finally { ! hu.closeSession(); ! } } *************** *** 58,70 **** */ public synchronized void remove(Vertex v) { ! vertexs.remove(v); } /** * Find all vertexs ! * @return The vertexs (unmodifiable) */ public Set findAll() { ! return Collections.unmodifiableSet(vertexs); } --- 93,138 ---- */ public synchronized void remove(Vertex v) { ! HibernateUtil hu = HibernateUtil.getInstance(); ! try { ! Session session = hu.currentSession(); ! Transaction tx = session.beginTransaction(); ! ! session.delete(v); ! ! tx.commit(); ! } catch (Exception ex) { ! log.error(ex.getMessage(), ex); ! } finally { ! hu.closeSession(); ! } } /** * Find all vertexs ! * @return The vertexs */ public Set findAll() { ! Set result = new HashSet(); ! ! HibernateUtil hu = HibernateUtil.getInstance(); ! try { ! Session session = hu.currentSession(); ! Transaction tx = session.beginTransaction(); ! ! Query q = session.createQuery("SELECT v FROM Vertex AS v"); ! ! Iterator it = q.iterate(); ! while (it.hasNext()) { ! result.add((Vertex)it.next()); ! } ! ! tx.commit(); ! } catch (Exception ex) { ! log.error(ex.getMessage(), ex); ! } finally { ! hu.closeSession(); ! } ! ! return result; } *************** *** 74,86 **** * @return The vertex */ ! public synchronized Vertex findById(Long id) { ! Iterator it = vertexs.iterator(); ! while (it.hasNext()) { ! Vertex v = (Vertex)it.next(); ! if (v.getId().equals(id)) { ! return v; ! } } ! return null; } --- 142,163 ---- * @return The vertex */ ! public Vertex findById(Long id) { ! Vertex result = null; ! ! HibernateUtil hu = HibernateUtil.getInstance(); ! try { ! Session session = hu.currentSession(); ! Transaction tx = session.beginTransaction(); ! ! result = (Vertex)session.load(Vertex.class, id); ! ! tx.commit(); ! } catch (Exception ex) { ! log.error(ex.getMessage(), ex); ! } finally { ! hu.closeSession(); } ! ! return result; } *************** *** 90,102 **** * @return The vertex */ ! public synchronized Vertex findByName(String name) { ! Iterator it = vertexs.iterator(); ! while (it.hasNext()) { ! Vertex v = (Vertex)it.next(); ! if (v.getName().equals(name)) { ! return v; } } ! return null; } } --- 167,194 ---- * @return The vertex */ ! public Vertex findByName(String name) { ! Vertex result = null; ! ! HibernateUtil hu = HibernateUtil.getInstance(); ! try { ! Session session = hu.currentSession(); ! Transaction tx = session.beginTransaction(); ! ! Query q = session.createQuery("SELECT v FROM Vertex AS v WHERE v.name = :name"); ! q.setString("name", name); ! ! Iterator it = q.iterate(); ! if (it.hasNext()) { ! result = (Vertex)it.next(); } + + tx.commit(); + } catch (Exception ex) { + log.error(ex.getMessage(), ex); + } finally { + hu.closeSession(); } ! ! return result; } } Index: Domain.java =================================================================== RCS file: /cvsroot/bprocessor/model/src/net/sourceforge/bprocessor/model/Domain.java,v retrieving revision 1.1.1.1 retrieving revision 1.2 diff -C2 -d -r1.1.1.1 -r1.2 *** Domain.java 27 Jun 2005 09:31:14 -0000 1.1.1.1 --- Domain.java 28 Jul 2005 06:48:54 -0000 1.2 *************** *** 8,12 **** import java.io.Serializable; - import java.util.HashSet; import java.util.Set; --- 8,11 ---- *************** *** 15,18 **** --- 14,20 ---- /** * The domain + * @hibernate.class + * table="DOMAIN" + * lazy="false" */ public abstract class Domain implements Serializable { *************** *** 39,54 **** /** - * Constructor - * @param id The id - */ - protected Domain(Long id) { - setId(id); - setAttributes(new HashSet()); - setSurfaces(new HashSet()); - } - - /** * Get the id * @return The id */ public Long getId() { --- 41,49 ---- /** * Get the id * @return The id + * @hibernate.id + * column="DOMAIN_ID" + * generator-class="increment" */ public Long getId() { *************** *** 67,70 **** --- 62,66 ---- * Get the name * @return The name + * @hibernate.property */ public String getName() { *************** *** 83,86 **** --- 79,89 ---- * Get the attributes * @return The attributes + * @hibernate.set + * cascade="delete" + * lazy="false" + * @hibernate.key + * column="DOMAIN_ID" + * @hibernate.one-to-many + * class="net.sourceforge.bprocessor.model.Attribute" */ public Set getAttributes() { *************** *** 99,102 **** --- 102,112 ---- * Get the surfaces * @return The surfaces + * @hibernate.set + * cascade="delete" + * lazy="false" + * @hibernate.key + * column="DOMAIN_ID" + * @hibernate.one-to-many + * class="net.sourceforge.bprocessor.model.Surface" */ public Set getSurfaces() { *************** *** 111,113 **** --- 121,132 ---- this.surfaces = surfaces; } + + /** + * String representation of the object + * @return The string + */ + public String toString() { + return "Domain[id=" + id + ",name=" + name + ",attributes=" + attributes.size() + + ",surfaces=" + surfaces.size() + "]"; + } } Index: Element.java =================================================================== RCS file: /cvsroot/bprocessor/model/src/net/sourceforge/bprocessor/model/Element.java,v retrieving revision 1.1.1.1 retrieving revision 1.2 diff -C2 -d -r1.1.1.1 -r1.2 *** Element.java 27 Jun 2005 09:31:14 -0000 1.1.1.1 --- Element.java 28 Jul 2005 06:48:54 -0000 1.2 *************** *** 7,11 **** package net.sourceforge.bprocessor.model; - import java.util.HashSet; import java.util.Set; --- 7,10 ---- *************** *** 14,17 **** --- 13,21 ---- /** * The element + * @hibernate.joined-subclass + * table="ELEMENT" + * lazy="false" + * @hibernate.key + * column="DOMAIN_ID" */ public class Element extends Domain { *************** *** 19,24 **** private static Logger log = Logger.getLogger(Element.class); ! /** Id generator */ ! private static long l = 0; /** The parts */ --- 23,28 ---- private static Logger log = Logger.getLogger(Element.class); ! /** The element id */ ! private Long elementId; /** The parts */ *************** *** 36,42 **** */ public Element(String name) { ! super(new Long(l++)); setName(name); ! setParts(new HashSet()); } --- 40,65 ---- */ public Element(String name) { ! super(); setName(name); ! setParts(null); ! } ! ! /** ! * Get the element id ! * @return The element id ! * @hibernate.id ! * column="ELEMENT_ID" ! * generator-class="increment" ! */ ! protected Long getElementId() { ! return elementId; ! } ! ! /** ! * Set the element id ! * @param id The element id ! */ ! private void setElementId(Long id) { ! this.elementId = id; } *************** *** 44,47 **** --- 67,77 ---- * Get the parts * @return The parts + * @hibernate.set + * cascade="delete" + * lazy="false" + * @hibernate.key + * column="ELEMENT_ID" + * @hibernate.one-to-many + * class="net.sourceforge.bprocessor.model.Part" */ public Set getParts() { *************** *** 79,81 **** --- 109,119 ---- return getId().equals(e.getId()); } + + /** + * String representation of the object + * @return The string + */ + public String toString() { + return "Element[" + super.toString() + ",parts=" + parts.size() + "]"; + } } Index: Vertex.java =================================================================== RCS file: /cvsroot/bprocessor/model/src/net/sourceforge/bprocessor/model/Vertex.java,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** Vertex.java 18 Jul 2005 09:21:16 -0000 1.2 --- Vertex.java 28 Jul 2005 06:48:54 -0000 1.3 *************** *** 8,13 **** import java.io.Serializable; - import java.util.HashSet; - import java.util.Set; import org.apache.log4j.Logger; --- 8,11 ---- *************** *** 15,18 **** --- 13,19 ---- /** * The vertex + * @hibernate.class + * table="VERTEX" + * lazy="false" */ public class Vertex implements Serializable { *************** *** 20,26 **** private static Logger log = Logger.getLogger(Vertex.class); - /** Id generator */ - private static long l = 0; - /** The id */ private Long id; --- 21,24 ---- *************** *** 41,47 **** private double w; - /** The edge relationship */ - private Set edges; - /** * Constructor for persistence layer --- 39,42 ---- *************** *** 55,59 **** */ public Vertex(String name) { ! setId(new Long(l++)); setName(name); setX(0.0); --- 50,54 ---- */ public Vertex(String name) { ! super(); setName(name); setX(0.0); *************** *** 61,65 **** setZ(0.0); setW(0.0); - setEdges(new HashSet()); } --- 56,59 ---- *************** *** 67,70 **** --- 61,67 ---- * Get the id * @return The id + * @hibernate.id + * column="VERTEX_ID" + * generator-class="increment" */ public Long getId() { *************** *** 83,86 **** --- 80,84 ---- * Get the name * @return The name + * @hibernate.property */ public String getName() { *************** *** 99,102 **** --- 97,101 ---- * Get the x coordinate * @return The x coordinate + * @hibernate.property */ public double getX() { *************** *** 115,118 **** --- 114,118 ---- * Get the y coordinate * @return The y coordinate + * @hibernate.property */ public double getY() { *************** *** 131,134 **** --- 131,135 ---- * Get the z coordinate * @return The z coordinate + * @hibernate.property */ public double getZ() { *************** *** 147,150 **** --- 148,152 ---- * Get the w coordinate * @return The w coordinate + * @hibernate.property */ public double getW() { *************** *** 161,180 **** /** - * Get the edges - * @return The edges - */ - public Set getEdges() { - return edges; - } - - /** - * Set the edges - * @param edges The edges - */ - public void setEdges(Set edges) { - this.edges = edges; - } - - /** * Return the hash code of the object * @return The hash --- 163,166 ---- *************** *** 198,200 **** --- 184,195 ---- return this.id.equals(v.getId()); } + + /** + * String representation of the object + * @return The string + */ + public String toString() { + return "Vertex[id=" + id + ",name=" + name + ",x=" + x + ",y=" + y + + ",z=" + z + ",w=" + w + "]"; + } } Index: PartFacade.java =================================================================== RCS file: /cvsroot/bprocessor/model/src/net/sourceforge/bprocessor/model/PartFacade.java,v retrieving revision 1.1.1.1 retrieving revision 1.2 diff -C2 -d -r1.1.1.1 -r1.2 *** PartFacade.java 27 Jun 2005 09:31:14 -0000 1.1.1.1 --- PartFacade.java 28 Jul 2005 06:48:54 -0000 1.2 *************** *** 7,11 **** package net.sourceforge.bprocessor.model; ! import java.util.Collections; import java.util.HashSet; import java.util.Iterator; --- 7,12 ---- package net.sourceforge.bprocessor.model; ! import net.sourceforge.bprocessor.model.db.HibernateUtil; ! import java.util.HashSet; import java.util.Iterator; *************** *** 13,16 **** --- 14,20 ---- import org.apache.log4j.Logger; + import org.hibernate.Query; + import org.hibernate.Session; + import org.hibernate.Transaction; /** *************** *** 24,35 **** private static PartFacade instance; - /** Parts */ - private Set parts; - /** * Constructor */ private PartFacade() { - parts = new HashSet(); } --- 28,35 ---- *************** *** 46,54 **** /** ! * Add a part * @param p The part */ ! public synchronized void add(Part p) { ! parts.add(p); } --- 46,89 ---- /** ! * Create a part * @param p The part + * @return The part */ ! public synchronized Part create(Part p) { ! HibernateUtil hu = HibernateUtil.getInstance(); ! try { ! Session session = hu.currentSession(); ! Transaction tx = session.beginTransaction(); ! ! session.save(p); ! ! tx.commit(); ! } catch (Exception ex) { ! log.error(ex.getMessage(), ex); ! } finally { ! hu.closeSession(); ! } ! ! return p; ! } ! ! /** ! * Update a part ! * @param p The part ! */ ! public synchronized void update(Part p) { ! HibernateUtil hu = HibernateUtil.getInstance(); ! try { ! Session session = hu.currentSession(); ! Transaction tx = session.beginTransaction(); ! ! session.update(p); ! ! tx.commit(); ! } catch (Exception ex) { ! log.error(ex.getMessage(), ex); ! } finally { ! hu.closeSession(); ! } } *************** *** 58,70 **** */ public synchronized void remove(Part p) { ! parts.remove(p); } /** * Find all parts ! * @return The parts (unmodifiable) */ public Set findAll() { ! return Collections.unmodifiableSet(parts); } --- 93,138 ---- */ public synchronized void remove(Part p) { ! HibernateUtil hu = HibernateUtil.getInstance(); ! try { ! Session session = hu.currentSession(); ! Transaction tx = session.beginTransaction(); ! ! session.delete(p); ! ! tx.commit(); ! } catch (Exception ex) { ! log.error(ex.getMessage(), ex); ! } finally { ! hu.closeSession(); ! } } /** * Find all parts ! * @return The parts */ public Set findAll() { ! Set result = new HashSet(); ! ! HibernateUtil hu = HibernateUtil.getInstance(); ! try { ! Session session = hu.currentSession(); ! Transaction tx = session.beginTransaction(); ! ! Query q = session.createQuery("SELECT p FROM Part AS p"); ! ! Iterator it = q.iterate(); ! while (it.hasNext()) { ! result.add((Part)it.next()); ! } ! ! tx.commit(); ! } catch (Exception ex) { ! log.error(ex.getMessage(), ex); ! } finally { ! hu.closeSession(); ! } ! ! return result; } *************** *** 74,86 **** * @return The part */ ! public synchronized Part findById(Long id) { ! Iterator it = parts.iterator(); ! while (it.hasNext()) { ! Part p = (Part)it.next(); ! if (p.getId().equals(id)) { ! return p; ! } } ! return null; } --- 142,163 ---- * @return The part */ ! public Part findById(Long id) { ! Part result = null; ! ! HibernateUtil hu = HibernateUtil.getInstance(); ! try { ! Session session = hu.currentSession(); ! Transaction tx = session.beginTransaction(); ! ! result = (Part)session.load(Part.class, id); ! ! tx.commit(); ! } catch (Exception ex) { ! log.error(ex.getMessage(), ex); ! } finally { ! hu.closeSession(); } ! ! return result; } *************** *** 90,102 **** * @return The part */ ! public synchronized Part findByName(String name) { ! Iterator it = parts.iterator(); ! while (it.hasNext()) { ! Part p = (Part)it.next(); ! if (p.getName().equals(name)) { ! return p; } } ! return null; } } --- 167,194 ---- * @return The part */ ! public Part findByName(String name) { ! Part result = null; ! ! HibernateUtil hu = HibernateUtil.getInstance(); ! try { ! Session session = hu.currentSession(); ! Transaction tx = session.beginTransaction(); ! ! Query q = session.createQuery("SELECT p FROM Part AS p WHERE p.name = :name"); ! q.setString("name", name); ! ! Iterator it = q.iterate(); ! if (it.hasNext()) { ! result = (Part)it.next(); } + + tx.commit(); + } catch (Exception ex) { + log.error(ex.getMessage(), ex); + } finally { + hu.closeSession(); } ! ! return result; } } Index: FunctionalSpaceFacade.java =================================================================== RCS file: /cvsroot/bprocessor/model/src/net/sourceforge/bprocessor/model/FunctionalSpaceFacade.java,v retrieving revision 1.1.1.1 retrieving revision 1.2 diff -C2 -d -r1.1.1.1 -r1.2 *** FunctionalSpaceFacade.java 27 Jun 2005 09:31:14 -0000 1.1.1.1 --- FunctionalSpaceFacade.java 28 Jul 2005 06:48:54 -0000 1.2 *************** *** 7,11 **** package net.sourceforge.bprocessor.model; ! import java.util.Collections; import java.util.HashSet; import java.util.Iterator; --- 7,12 ---- package net.sourceforge.bprocessor.model; ! import net.sourceforge.bprocessor.model.db.HibernateUtil; ! import java.util.HashSet; import java.util.Iterator; *************** *** 13,16 **** --- 14,20 ---- import org.apache.log4j.Logger; + import org.hibernate.Query; + import org.hibernate.Session; + import org.hibernate.Transaction; /** *************** *** 24,35 **** private static FunctionalSpaceFacade instance; - /** Functional spaces */ - private Set functionalSpaces; - /** * Constructor */ private FunctionalSpaceFacade() { - functionalSpaces = new HashSet(); } --- 28,35 ---- *************** *** 46,70 **** /** ! * Add a functional space ! * @param c The functional space */ ! public synchronized void add(FunctionalSpace c) { ! functionalSpaces.add(c); } /** * Remove a functional space ! * @param c The functional space */ ! public synchronized void remove(FunctionalSpace c) { ! functionalSpaces.remove(c); } /** * Find all functional spaces ! * @return The functional spaces (unmodifiable) */ public Set findAll() { ! return Collections.unmodifiableSet(functionalSpaces); } --- 46,138 ---- /** ! * Create a functional space ! * @param f The functional space ! * @return The functional space */ ! public synchronized FunctionalSpace create(FunctionalSpace f) { ! HibernateUtil hu = HibernateUtil.getInstance(); ! try { ! Session session = hu.currentSession(); ! Transaction tx = session.beginTransaction(); ! ! session.save(f); ! ! tx.commit(); ! } catch (Exception ex) { ! log.error(ex.getMessage(), ex); ! } finally { ... [truncated message content] |