[Bprocessor-commit] model/src/net/sourceforge/bprocessor/model DomainFacade.java,NONE,1.1
Status: Pre-Alpha
Brought to you by:
henryml
From: Nordholt <nor...@us...> - 2005-09-20 12:39:48
|
Update of /cvsroot/bprocessor/model/src/net/sourceforge/bprocessor/model In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv8888 Added Files: DomainFacade.java Log Message: first commit --- NEW FILE: DomainFacade.java --- //--------------------------------------------------------------------------------- // $Id: DomainFacade.java,v 1.1 2005/09/20 12:39:40 nordholt 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 net.sourceforge.bprocessor.model.db.HibernateUtil; import java.util.HashSet; import java.util.Iterator; import java.util.Set; import org.apache.log4j.Logger; import org.hibernate.Query; import org.hibernate.Session; import org.hibernate.Transaction; /** * Facade for Domains */ public class DomainFacade { /** The logger */ private Logger log = Logger.getLogger(DomainFacade.class); /** The instance */ private static DomainFacade instance; /** * Constructor */ private DomainFacade() { } /** * Get the instance * @return the instance */ public static synchronized DomainFacade getInstance() { if (instance == null) { instance = new DomainFacade(); } return instance; } /** * Find all domains * @return the set of all domains */ public synchronized Set findAll() { Set result = new HashSet(); HibernateUtil hu = HibernateUtil.getInstance(); try { Session session = hu.currentSession(); Transaction tx = session.beginTransaction(); Query q = session.createQuery("SELECT d FROM Domain AS d"); Iterator it = q.iterate(); while (it.hasNext()) { result.add((Domain)it.next()); } tx.commit(); } catch (Exception ex) { log.error(ex.getMessage(), ex); } finally { hu.closeSession(); } return result; } /** * Find a domain by id * @param id The id * @return The domain */ public synchronized Domain findById(Long id) { Domain result = null; HibernateUtil hu = HibernateUtil.getInstance(); try { Session session = hu.currentSession(); Transaction tx = session.beginTransaction(); result = (Domain)session.load(Domain.class, id); tx.commit(); } catch (Exception ex) { log.error(ex.getMessage(), ex); } finally { hu.closeSession(); } return result; } /** * Find all the domains associated with a surface * @param surface the surface * @return the set of domains */ public Set findBySurface(Surface surface) { Set result = new HashSet(); HibernateUtil hu = HibernateUtil.getInstance(); try { Session session = hu.currentSession(); Transaction tx = session.beginTransaction(); //this query is wrong Query q = session.createQuery("SELECT d FROM Domain AS d " + "JOIN d.surfaces AS surfaces " + "WHERE surfaces.id = :id AND d.id = f.id"); q.setLong("id", surface.getId().longValue()); Iterator it = q.iterate(); while (it.hasNext()) { result.add((Domain)it.next()); } tx.commit(); } catch (Exception ex) { log.error(ex.getMessage(), ex); } finally { hu.closeSession(); } return result; } } |