[Bprocessor-commit] model/src/net/sourceforge/bprocessor/model SQLFacade.java,NONE,1.1 DatabaseFacad
Status: Pre-Alpha
Brought to you by:
henryml
From: Michael L. <he...@us...> - 2005-10-06 08:20:41
|
Update of /cvsroot/bprocessor/model/src/net/sourceforge/bprocessor/model In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv13798/src/net/sourceforge/bprocessor/model Modified Files: DatabaseFacade.java Added Files: SQLFacade.java Log Message: DatabaseFacade has been split into abstract super class "DatabaseFacade" and concrete implementation "SQLFacade". Other implementations can be added by changing what instance is created in DatabaseFacade.getInstance() Index: DatabaseFacade.java =================================================================== RCS file: /cvsroot/bprocessor/model/src/net/sourceforge/bprocessor/model/DatabaseFacade.java,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** DatabaseFacade.java 5 Oct 2005 08:05:36 -0000 1.1 --- DatabaseFacade.java 6 Oct 2005 08:20:32 -0000 1.2 *************** *** 6,26 **** //--------------------------------------------------------------------------------- - package net.sourceforge.bprocessor.model; import java.util.Set; - import net.sourceforge.bprocessor.model.db.HibernateUtil; - - import org.apache.log4j.Logger; - import org.hibernate.Session; - import org.hibernate.Transaction; - /** ! * Facade for database */ ! public class DatabaseFacade { ! /** The logger */ ! private static Logger log = Logger.getLogger(DatabaseFacade.class); /** The instance */ --- 6,19 ---- //--------------------------------------------------------------------------------- package net.sourceforge.bprocessor.model; import java.util.Set; /** ! * Database interface ! * */ ! ! public abstract class DatabaseFacade { /** The instance */ *************** *** 34,38 **** public static synchronized DatabaseFacade getInstance() { if (instance == null) { ! instance = new DatabaseFacade(); } return instance; --- 27,31 ---- public static synchronized DatabaseFacade getInstance() { if (instance == null) { ! instance = new SQLFacade(); } return instance; *************** *** 43,108 **** * @param o The object */ ! public void intern(Object o) { ! HibernateUtil hu = HibernateUtil.getInstance(); ! Transaction tx = null; ! try { ! Session session = hu.currentSession(); ! tx = session.beginTransaction(); ! session.save(o); ! tx.commit(); ! } catch (Exception ex) { ! if (tx != null) { ! tx.rollback(); ! } ! log.error(ex.getMessage(), ex); ! } finally { ! hu.closeSession(); ! } ! } ! /** * Update an object * @param o The object */ ! public void update(Object o) { ! HibernateUtil hu = HibernateUtil.getInstance(); ! Transaction tx = null; ! try { ! Session session = hu.currentSession(); ! tx = session.beginTransaction(); ! session.update(o); ! tx.commit(); ! } catch (Exception ex) { ! if (tx != null) { ! tx.rollback(); ! } ! log.error(ex.getMessage(), ex); ! } finally { ! hu.closeSession(); ! } ! } ! /** * Remove and object * @param o The object */ ! public void remove(Object o) { ! HibernateUtil hu = HibernateUtil.getInstance(); ! Transaction tx = null; ! try { ! Session session = hu.currentSession(); ! tx = session.beginTransaction(); ! session.delete(o); ! tx.commit(); ! } catch (Exception ex) { ! if (tx != null) { ! tx.rollback(); ! } ! log.error(ex.getMessage(), ex); ! } finally { ! hu.closeSession(); ! } ! } ! /** * Find a attribute by id --- 36,53 ---- * @param o The object */ ! public abstract void intern(Object o); ! /** * Update an object * @param o The object */ ! public abstract void update(Object o); ! /** * Remove and object * @param o The object */ ! public abstract void remove(Object o); ! /** * Find a attribute by id *************** *** 110,124 **** * @return The attribute */ ! public Attribute findAttributeById(Long id) { ! return AttributeFacade.getInstance().findById(id); ! } ! /** * Find all construction spaces * @return The construction spaces */ ! public Set getConstructionSpaces() { ! return ConstructionSpaceFacade.getInstance().findAll(); ! } /** --- 55,65 ---- * @return The attribute */ ! public abstract Attribute findAttributeById(Long id); ! /** * Find all construction spaces * @return The construction spaces */ ! public abstract Set getConstructionSpaces(); /** *************** *** 127,133 **** * @return The construction space */ ! public ConstructionSpace findConstructionSpaceById(Long id) { ! return ConstructionSpaceFacade.getInstance().findById(id); ! } /** --- 68,72 ---- * @return The construction space */ ! public abstract ConstructionSpace findConstructionSpaceById(Long id); /** *************** *** 135,142 **** * @return the set of all domains */ ! public Set getDomains() { ! return DomainFacade.getInstance().findAll(); ! } ! /** * Find a domain by id --- 74,79 ---- * @return the set of all domains */ ! public abstract Set getDomains(); ! /** * Find a domain by id *************** *** 144,158 **** * @return The domain */ ! public Domain findDomainById(Long id) { ! return DomainFacade.getInstance().findById(id); ! } ! /** * Find all edges * @return The edges */ ! public Set getEdges() { ! return EdgeFacade.getInstance().findAll(); ! } /** --- 81,91 ---- * @return The domain */ ! public abstract Domain findDomainById(Long id); ! /** * Find all edges * @return The edges */ ! public abstract Set getEdges(); /** *************** *** 161,167 **** * @return The edge */ ! public Edge findEdgeById(Long id) { ! return EdgeFacade.getInstance().findById(id); ! } /** --- 94,98 ---- * @return The edge */ ! public abstract Edge findEdgeById(Long id); /** *************** *** 169,175 **** * @return The elements */ ! public Set getElements() { ! return ElementFacade.getInstance().findAll(); ! } /** --- 100,104 ---- * @return The elements */ ! public abstract Set getElements(); /** *************** *** 178,192 **** * @return The element */ ! public Element findElementById(Long id) { ! return ElementFacade.getInstance().findById(id); ! } ! /** * Find all functional spaces * @return The functional spaces */ ! public Set getFunctionalSpaces() { ! return FunctionalSpaceFacade.getInstance().findAll(); ! } /** --- 107,117 ---- * @return The element */ ! public abstract Element findElementById(Long id); ! /** * Find all functional spaces * @return The functional spaces */ ! public abstract Set getFunctionalSpaces(); /** *************** *** 195,201 **** * @return The functional space */ ! public FunctionalSpace findFunctionalSpaceById(Long id) { ! return FunctionalSpaceFacade.getInstance().findById(id); ! } /** --- 120,124 ---- * @return The functional space */ ! public abstract FunctionalSpace findFunctionalSpaceById(Long id); /** *************** *** 203,209 **** * @return The parts */ ! public Set getParts() { ! return PartFacade.getInstance().findAll(); ! } /** --- 126,130 ---- * @return The parts */ ! public abstract Set getParts(); /** *************** *** 212,218 **** * @return The part */ ! public Part findPartById(Long id) { ! return PartFacade.getInstance().findById(id); ! } /** --- 133,137 ---- * @return The part */ ! public abstract Part findPartById(Long id); /** *************** *** 220,226 **** * @return The surfaces */ ! public Set getSurfaces() { ! return SurfaceFacade.getInstance().findAll(); ! } /** --- 139,143 ---- * @return The surfaces */ ! public abstract Set getSurfaces(); /** *************** *** 229,235 **** * @return The surface */ ! public Surface findSurfaceById(Long id) { ! return SurfaceFacade.getInstance().findById(id); ! } /** --- 146,150 ---- * @return The surface */ ! public abstract Surface findSurfaceById(Long id); /** *************** *** 237,243 **** * @return The vertexs */ ! public Set getVertices() { ! return VertexFacade.getInstance().findAll(); ! } /** --- 152,156 ---- * @return The vertexs */ ! public abstract Set getVertices(); /** *************** *** 246,251 **** * @return The vertex */ ! public Vertex findVertexById(Long id) { ! return VertexFacade.getInstance().findById(id); ! } } --- 159,162 ---- * @return The vertex */ ! public abstract Vertex findVertexById(Long id); } --- NEW FILE: SQLFacade.java --- //--------------------------------------------------------------------------------- // $Id: SQLFacade.java,v 1.1 2005/10/06 08:20:32 henryml Exp $ // // Copyright (c) 2005 The BProcessor Team (http://bprocessor.sourceforge.net) // Released under the Lesser GNU Public License v2.1 //--------------------------------------------------------------------------------- package net.sourceforge.bprocessor.model; import java.util.Set; import net.sourceforge.bprocessor.model.db.HibernateUtil; import org.apache.log4j.Logger; import org.hibernate.Session; import org.hibernate.Transaction; /** * Facade for database */ public class SQLFacade extends DatabaseFacade { /** The logger */ private static Logger log = Logger.getLogger(SQLFacade.class); /** * Insert an object into the database * @param o The object */ public void intern(Object o) { HibernateUtil hu = HibernateUtil.getInstance(); Transaction tx = null; try { Session session = hu.currentSession(); tx = session.beginTransaction(); session.save(o); tx.commit(); } catch (Exception ex) { if (tx != null) { tx.rollback(); } log.error(ex.getMessage(), ex); } finally { hu.closeSession(); } } /** * Update an object * @param o The object */ public void update(Object o) { HibernateUtil hu = HibernateUtil.getInstance(); Transaction tx = null; try { Session session = hu.currentSession(); tx = session.beginTransaction(); session.update(o); tx.commit(); } catch (Exception ex) { if (tx != null) { tx.rollback(); } log.error(ex.getMessage(), ex); } finally { hu.closeSession(); } } /** * Remove and object * @param o The object */ public void remove(Object o) { HibernateUtil hu = HibernateUtil.getInstance(); Transaction tx = null; try { Session session = hu.currentSession(); tx = session.beginTransaction(); session.delete(o); tx.commit(); } catch (Exception ex) { if (tx != null) { tx.rollback(); } log.error(ex.getMessage(), ex); } finally { hu.closeSession(); } } /** * Find a attribute by id * @param id The id * @return The attribute */ public Attribute findAttributeById(Long id) { return AttributeFacade.getInstance().findById(id); } /** * Find all construction spaces * @return The construction spaces */ public Set getConstructionSpaces() { return ConstructionSpaceFacade.getInstance().findAll(); } /** * Find a construction space by id * @param id The id * @return The construction space */ public ConstructionSpace findConstructionSpaceById(Long id) { return ConstructionSpaceFacade.getInstance().findById(id); } /** * Find all domains * @return the set of all domains */ public Set getDomains() { return DomainFacade.getInstance().findAll(); } /** * Find a domain by id * @param id The id * @return The domain */ public Domain findDomainById(Long id) { return DomainFacade.getInstance().findById(id); } /** * Find all edges * @return The edges */ public Set getEdges() { return EdgeFacade.getInstance().findAll(); } /** * Find an edge by id * @param id The id * @return The edge */ public Edge findEdgeById(Long id) { return EdgeFacade.getInstance().findById(id); } /** * Find all elements * @return The elements */ public Set getElements() { return ElementFacade.getInstance().findAll(); } /** * Find a element by id * @param id The id * @return The element */ public Element findElementById(Long id) { return ElementFacade.getInstance().findById(id); } /** * Find all functional spaces * @return The functional spaces */ public Set getFunctionalSpaces() { return FunctionalSpaceFacade.getInstance().findAll(); } /** * Find a functional space by id * @param id The id * @return The functional space */ public FunctionalSpace findFunctionalSpaceById(Long id) { return FunctionalSpaceFacade.getInstance().findById(id); } /** * Find all parts * @return The parts */ public Set getParts() { return PartFacade.getInstance().findAll(); } /** * Find a part by id * @param id The id * @return The part */ public Part findPartById(Long id) { return PartFacade.getInstance().findById(id); } /** * Find all surfaces * @return The surfaces */ public Set getSurfaces() { return SurfaceFacade.getInstance().findAll(); } /** * Find a surface by id * @param id The id * @return The surface */ public Surface findSurfaceById(Long id) { return SurfaceFacade.getInstance().findById(id); } /** * Find all vertexs * @return The vertexs */ public Set getVertices() { return VertexFacade.getInstance().findAll(); } /** * Find a vertex by id * @param id The id * @return The vertex */ public Vertex findVertexById(Long id) { return VertexFacade.getInstance().findById(id); } } |