Update of /cvsroot/bprocessor/model/src/net/sourceforge/bprocessor/model
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv15811
Added Files:
AttributeFacade.java
Log Message:
Initial import
--- NEW FILE: AttributeFacade.java ---
//---------------------------------------------------------------------------------
// $Id: AttributeFacade.java,v 1.1 2005/08/24 06:58:06 jews 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 org.apache.log4j.Logger;
import org.hibernate.Session;
import org.hibernate.Transaction;
/**
* Facade for attribute
*/
public class AttributeFacade {
/** The logger */
private static Logger log = Logger.getLogger(AttributeFacade.class);
/** The instance */
private static AttributeFacade instance;
/**
* Constructor
*/
private AttributeFacade() {
}
/**
* Get the instance
* @return The instance
*/
public static synchronized AttributeFacade getInstance() {
if (instance == null) {
instance = new AttributeFacade();
}
return instance;
}
/**
* Create an attribute
* @param a The attribute
* @return The created attribute
*/
public synchronized Attribute create(Attribute a) {
HibernateUtil hu = HibernateUtil.getInstance();
try {
Session session = hu.currentSession();
Transaction tx = session.beginTransaction();
session.save(a);
tx.commit();
} catch (Exception ex) {
log.error(ex.getMessage(), ex);
} finally {
hu.closeSession();
}
return a;
}
/**
* Update an attribute
* @param a The attribute
*/
public synchronized void update(Attribute a) {
HibernateUtil hu = HibernateUtil.getInstance();
try {
Session session = hu.currentSession();
Transaction tx = session.beginTransaction();
session.update(a);
tx.commit();
} catch (Exception ex) {
log.error(ex.getMessage(), ex);
} finally {
hu.closeSession();
}
}
/**
* Remove an attribute
* @param a The attribute
*/
public synchronized void remove(Attribute a) {
HibernateUtil hu = HibernateUtil.getInstance();
try {
Session session = hu.currentSession();
Transaction tx = session.beginTransaction();
session.delete(a);
tx.commit();
} catch (Exception ex) {
log.error(ex.getMessage(), ex);
} finally {
hu.closeSession();
}
}
/**
* Find a attribute by id
* @param id The id
* @return The attribute
*/
public synchronized Attribute findById(Long id) {
Attribute result = null;
HibernateUtil hu = HibernateUtil.getInstance();
try {
Session session = hu.currentSession();
Transaction tx = session.beginTransaction();
result = (Attribute)session.load(Attribute.class, id);
tx.commit();
} catch (Exception ex) {
log.error(ex.getMessage(), ex);
} finally {
hu.closeSession();
}
return result;
}
}
|