use of com.autentia.tnt.dao.DataAccException in project TNTConcept by autentia.
the class HibernateManagerBase method insert.
/**
* Inserta un objeto de negocio en base de datos
*
* @param obj a insertar
*/
public void insert(T obj) throws DataAccException {
log.debug("insert");
Session session = null;
try {
session = HibernateUtil.getSessionFactory().getCurrentSession();
Date d = new Date();
obj.setInsertDate(d);
obj.setUpdateDate(d);
session.save(obj);
log.debug("objeto correctamente insertado");
} catch (Exception ex) {
log.error("insert - exception", ex);
StringBuffer msg = new StringBuffer("Error insertando el objeto: ");
msg.append(obj);
throw new DataAccException(msg.toString(), ex);
}
}
use of com.autentia.tnt.dao.DataAccException in project TNTConcept by autentia.
the class HibernateManagerBase method search.
/**
* Perform a custom Hibernate HQL search.
* @param hql the hql query
* @oaram args query parameters
* @return a List of Objects with the result
* @throws DataAccException
*/
@SuppressWarnings("unchecked")
protected List search(String hql, Object... args) throws DataAccException {
log.debug("search - hql='" + hql + "'");
Session session = null;
List<Object> ret = null;
try {
session = HibernateUtil.getSessionFactory().getCurrentSession();
if (!session.getTransaction().isActive()) {
session.beginTransaction();
}
Query q = session.createQuery(hql);
for (int i = 0; i < args.length; i++) {
if (args[i] instanceof Collection) {
q.setParameterList("arg" + i, (Collection) args[i]);
} else {
q.setParameter("arg" + i, args[i]);
}
}
ret = q.list();
log.debug("search - found " + ret.size() + " objects");
} catch (Exception ex) {
log.error("search - error searching", ex);
throw new DataAccException("Error searching '" + hql + "'", ex);
}
return ret;
}
use of com.autentia.tnt.dao.DataAccException in project TNTConcept by autentia.
the class HibernateManagerBase method update.
/**
* Actualiza una objeto de negocio en base de datos
*
* @param obj el objeto de negocio a actualizar
*/
public void update(ITransferObject obj, Serializable pk) throws DataAccException {
log.debug("update");
Session session = null;
try {
session = HibernateUtil.getSessionFactory().getCurrentSession();
obj.setUpdateDate(new Date());
session.merge(obj);
log.debug("objeto con clave '" + pk + "' correctamente actualizado");
if (this.cacheable)
HibernateManagerBase.removeCacheFor(obj.getClass().getName());
} catch (Exception ex) {
String msg = "Error actualizando el objeto '" + obj + "' con clave primaria '" + pk + "'";
log.debug("error actualizando el objeto '" + pk + "': " + msg);
throw new DataAccException(msg, ex);
}
}
use of com.autentia.tnt.dao.DataAccException in project TNTConcept by autentia.
the class HibernateManagerBase method search.
/**
* Get DAOs matching searching criteria
* @param <T> type of entity the manager works with
* @param clazz entity class
* @param search search criteria
* @param sort sort criteria (can be null)
* @return the list of objects matching the criteria
* @throws DataAccException
*/
protected List<T> search(Class<T> clazz, SearchCriteria search, SortCriteria sort) throws DataAccException {
log.debug("search - clazz='" + clazz + "' search='" + search + "' sort='" + sort + "'");
List<T> ret = null;
try {
// Append FROM condition
StringBuilder query = new StringBuilder("FROM ");
query.append(clazz.getName());
query.append(" p");
// Append WHERE condition
if (search != null) {
query.append(" ");
query.append(search.getHQL());
}
// Append ORDER BY condition
if (sort != null) {
query.append(" ");
query.append(sort.getHQL());
}
// Make query
ret = (List<T>) search(query.toString(), (search == null) ? new Object[0] : search.getArguments());
log.debug("search - found " + ret.size() + " objects of type " + clazz.getName());
} catch (Exception ex) {
log.error("search - error searching", ex);
throw new DataAccException("Error searching " + clazz.getName() + " objects", ex);
}
return ret;
}
use of com.autentia.tnt.dao.DataAccException in project TNTConcept by autentia.
the class HibernateManagerBase method delete.
/**
* Elimina un objeto de negocio de base de datos
* @deprecated use this method only from derived classes, and use delete() methods in derived classes from other places
* @param obj el objeto de negocio a eliminar
* @param pk clave primaria del objeto de negocio a eliminar
*/
public void delete(Object obj, Serializable pk) throws DataAccException {
log.debug("delete");
Class clazz = obj.getClass();
Session session = null;
try {
session = HibernateUtil.getSessionFactory().getCurrentSession();
// Cargamos el objeto antiguo
Object objOld = session.load(clazz, pk);
log.debug("objeto con clave '" + pk + "' recuperado");
// Borramos
session.delete(objOld);
log.debug("objeto con clave '" + pk + "' correctamente eliminado");
if (this.cacheable)
HibernateManagerBase.removeCacheFor(clazz.getName());
doAfterDelete(pk);
} catch (Exception ex) {
StringBuffer msg = new StringBuffer("Error borrando el objeto '");
msg.append(pk);
log.debug("error eliminando el objeto '" + pk + "': " + msg.toString());
throw new DataAccException(msg.toString(), ex);
}
}
Aggregations