Java tutorial
/** * "Visual Paradigm: DO NOT MODIFY THIS FILE!" * * This is an automatic generated file. It will be regenerated every time * you generate persistence class. * * Modifying its content may cause the program not work, or your work may lost. */ /** * Licensee: University of Almeria * License Type: Academic */ package diagrama_de_base_de_datos; import org.orm.*; import org.hibernate.Query; import org.hibernate.LockMode; import java.util.List; public class ConsultaDAO { public static Consulta loadConsultaByORMID(int ID) throws PersistentException { try { PersistentSession session = diagrama_de_base_de_datos.ProyectoMDS2PersistentManager.instance() .getSession(); return loadConsultaByORMID(session, ID); } catch (Exception e) { e.printStackTrace(); throw new PersistentException(e); } } public static Consulta getConsultaByORMID(int ID) throws PersistentException { try { PersistentSession session = diagrama_de_base_de_datos.ProyectoMDS2PersistentManager.instance() .getSession(); return getConsultaByORMID(session, ID); } catch (Exception e) { e.printStackTrace(); throw new PersistentException(e); } } public static Consulta loadConsultaByORMID(int ID, org.hibernate.LockMode lockMode) throws PersistentException { try { PersistentSession session = diagrama_de_base_de_datos.ProyectoMDS2PersistentManager.instance() .getSession(); return loadConsultaByORMID(session, ID, lockMode); } catch (Exception e) { e.printStackTrace(); throw new PersistentException(e); } } public static Consulta getConsultaByORMID(int ID, org.hibernate.LockMode lockMode) throws PersistentException { try { PersistentSession session = diagrama_de_base_de_datos.ProyectoMDS2PersistentManager.instance() .getSession(); return getConsultaByORMID(session, ID, lockMode); } catch (Exception e) { e.printStackTrace(); throw new PersistentException(e); } } public static Consulta loadConsultaByORMID(PersistentSession session, int ID) throws PersistentException { try { return (Consulta) session.load(diagrama_de_base_de_datos.Consulta.class, new Integer(ID)); } catch (Exception e) { e.printStackTrace(); throw new PersistentException(e); } } public static Consulta getConsultaByORMID(PersistentSession session, int ID) throws PersistentException { try { return (Consulta) session.get(diagrama_de_base_de_datos.Consulta.class, new Integer(ID)); } catch (Exception e) { e.printStackTrace(); throw new PersistentException(e); } } public static Consulta loadConsultaByORMID(PersistentSession session, int ID, org.hibernate.LockMode lockMode) throws PersistentException { try { return (Consulta) session.load(diagrama_de_base_de_datos.Consulta.class, new Integer(ID), lockMode); } catch (Exception e) { e.printStackTrace(); throw new PersistentException(e); } } public static Consulta getConsultaByORMID(PersistentSession session, int ID, org.hibernate.LockMode lockMode) throws PersistentException { try { return (Consulta) session.get(diagrama_de_base_de_datos.Consulta.class, new Integer(ID), lockMode); } catch (Exception e) { e.printStackTrace(); throw new PersistentException(e); } } public static List queryConsulta(String condition, String orderBy) throws PersistentException { try { PersistentSession session = diagrama_de_base_de_datos.ProyectoMDS2PersistentManager.instance() .getSession(); return queryConsulta(session, condition, orderBy); } catch (Exception e) { e.printStackTrace(); throw new PersistentException(e); } } public static List queryConsulta(String condition, String orderBy, org.hibernate.LockMode lockMode) throws PersistentException { try { PersistentSession session = diagrama_de_base_de_datos.ProyectoMDS2PersistentManager.instance() .getSession(); return queryConsulta(session, condition, orderBy, lockMode); } catch (Exception e) { e.printStackTrace(); throw new PersistentException(e); } } public static Consulta[] listConsultaByQuery(String condition, String orderBy) throws PersistentException { try { PersistentSession session = diagrama_de_base_de_datos.ProyectoMDS2PersistentManager.instance() .getSession(); return listConsultaByQuery(session, condition, orderBy); } catch (Exception e) { e.printStackTrace(); throw new PersistentException(e); } } public static Consulta[] listConsultaByQuery(String condition, String orderBy, org.hibernate.LockMode lockMode) throws PersistentException { try { PersistentSession session = diagrama_de_base_de_datos.ProyectoMDS2PersistentManager.instance() .getSession(); return listConsultaByQuery(session, condition, orderBy, lockMode); } catch (Exception e) { e.printStackTrace(); throw new PersistentException(e); } } public static List queryConsulta(PersistentSession session, String condition, String orderBy) throws PersistentException { StringBuffer sb = new StringBuffer("From diagrama_de_base_de_datos.Consulta as Consulta"); if (condition != null) sb.append(" Where ").append(condition); if (orderBy != null) sb.append(" Order By ").append(orderBy); try { Query query = session.createQuery(sb.toString()); return query.list(); } catch (Exception e) { e.printStackTrace(); throw new PersistentException(e); } } public static List queryConsulta(PersistentSession session, String condition, String orderBy, org.hibernate.LockMode lockMode) throws PersistentException { StringBuffer sb = new StringBuffer("From diagrama_de_base_de_datos.Consulta as Consulta"); if (condition != null) sb.append(" Where ").append(condition); if (orderBy != null) sb.append(" Order By ").append(orderBy); try { Query query = session.createQuery(sb.toString()); query.setLockMode("Consulta", lockMode); return query.list(); } catch (Exception e) { e.printStackTrace(); throw new PersistentException(e); } } public static Consulta[] listConsultaByQuery(PersistentSession session, String condition, String orderBy) throws PersistentException { try { List list = queryConsulta(session, condition, orderBy); return (Consulta[]) list.toArray(new Consulta[list.size()]); } catch (Exception e) { e.printStackTrace(); throw new PersistentException(e); } } public static Consulta[] listConsultaByQuery(PersistentSession session, String condition, String orderBy, org.hibernate.LockMode lockMode) throws PersistentException { try { List list = queryConsulta(session, condition, orderBy, lockMode); return (Consulta[]) list.toArray(new Consulta[list.size()]); } catch (Exception e) { e.printStackTrace(); throw new PersistentException(e); } } public static Consulta loadConsultaByQuery(String condition, String orderBy) throws PersistentException { try { PersistentSession session = diagrama_de_base_de_datos.ProyectoMDS2PersistentManager.instance() .getSession(); return loadConsultaByQuery(session, condition, orderBy); } catch (Exception e) { e.printStackTrace(); throw new PersistentException(e); } } public static Consulta loadConsultaByQuery(String condition, String orderBy, org.hibernate.LockMode lockMode) throws PersistentException { try { PersistentSession session = diagrama_de_base_de_datos.ProyectoMDS2PersistentManager.instance() .getSession(); return loadConsultaByQuery(session, condition, orderBy, lockMode); } catch (Exception e) { e.printStackTrace(); throw new PersistentException(e); } } public static Consulta loadConsultaByQuery(PersistentSession session, String condition, String orderBy) throws PersistentException { Consulta[] consultas = listConsultaByQuery(session, condition, orderBy); if (consultas != null && consultas.length > 0) return consultas[0]; else return null; } public static Consulta loadConsultaByQuery(PersistentSession session, String condition, String orderBy, org.hibernate.LockMode lockMode) throws PersistentException { Consulta[] consultas = listConsultaByQuery(session, condition, orderBy, lockMode); if (consultas != null && consultas.length > 0) return consultas[0]; else return null; } public static java.util.Iterator iterateConsultaByQuery(String condition, String orderBy) throws PersistentException { try { PersistentSession session = diagrama_de_base_de_datos.ProyectoMDS2PersistentManager.instance() .getSession(); return iterateConsultaByQuery(session, condition, orderBy); } catch (Exception e) { e.printStackTrace(); throw new PersistentException(e); } } public static java.util.Iterator iterateConsultaByQuery(String condition, String orderBy, org.hibernate.LockMode lockMode) throws PersistentException { try { PersistentSession session = diagrama_de_base_de_datos.ProyectoMDS2PersistentManager.instance() .getSession(); return iterateConsultaByQuery(session, condition, orderBy, lockMode); } catch (Exception e) { e.printStackTrace(); throw new PersistentException(e); } } public static java.util.Iterator iterateConsultaByQuery(PersistentSession session, String condition, String orderBy) throws PersistentException { StringBuffer sb = new StringBuffer("From diagrama_de_base_de_datos.Consulta as Consulta"); if (condition != null) sb.append(" Where ").append(condition); if (orderBy != null) sb.append(" Order By ").append(orderBy); try { Query query = session.createQuery(sb.toString()); return query.iterate(); } catch (Exception e) { e.printStackTrace(); throw new PersistentException(e); } } public static java.util.Iterator iterateConsultaByQuery(PersistentSession session, String condition, String orderBy, org.hibernate.LockMode lockMode) throws PersistentException { StringBuffer sb = new StringBuffer("From diagrama_de_base_de_datos.Consulta as Consulta"); if (condition != null) sb.append(" Where ").append(condition); if (orderBy != null) sb.append(" Order By ").append(orderBy); try { Query query = session.createQuery(sb.toString()); query.setLockMode("Consulta", lockMode); return query.iterate(); } catch (Exception e) { e.printStackTrace(); throw new PersistentException(e); } } public static Consulta createConsulta() { return new diagrama_de_base_de_datos.Consulta(); } public static boolean save(diagrama_de_base_de_datos.Consulta consulta) throws PersistentException { try { diagrama_de_base_de_datos.ProyectoMDS2PersistentManager.instance().saveObject(consulta); return true; } catch (Exception e) { e.printStackTrace(); throw new PersistentException(e); } } public static boolean delete(diagrama_de_base_de_datos.Consulta consulta) throws PersistentException { try { diagrama_de_base_de_datos.ProyectoMDS2PersistentManager.instance().deleteObject(consulta); return true; } catch (Exception e) { e.printStackTrace(); throw new PersistentException(e); } } public static boolean deleteAndDissociate(diagrama_de_base_de_datos.Consulta consulta) throws PersistentException { try { if (consulta.getRealiza() != null) { consulta.getRealiza().realizada_por.remove(consulta); } return delete(consulta); } catch (Exception e) { e.printStackTrace(); throw new PersistentException(e); } } public static boolean deleteAndDissociate(diagrama_de_base_de_datos.Consulta consulta, org.orm.PersistentSession session) throws PersistentException { try { if (consulta.getRealiza() != null) { consulta.getRealiza().realizada_por.remove(consulta); } try { session.delete(consulta); return true; } catch (Exception e) { return false; } } catch (Exception e) { e.printStackTrace(); throw new PersistentException(e); } } public static boolean refresh(diagrama_de_base_de_datos.Consulta consulta) throws PersistentException { try { diagrama_de_base_de_datos.ProyectoMDS2PersistentManager.instance().getSession().refresh(consulta); return true; } catch (Exception e) { e.printStackTrace(); throw new PersistentException(e); } } public static boolean evict(diagrama_de_base_de_datos.Consulta consulta) throws PersistentException { try { diagrama_de_base_de_datos.ProyectoMDS2PersistentManager.instance().getSession().evict(consulta); return true; } catch (Exception e) { e.printStackTrace(); throw new PersistentException(e); } } public static Consulta loadConsultaByCriteria(ConsultaCriteria consultaCriteria) { Consulta[] consultas = listConsultaByCriteria(consultaCriteria); if (consultas == null || consultas.length == 0) { return null; } return consultas[0]; } public static Consulta[] listConsultaByCriteria(ConsultaCriteria consultaCriteria) { return consultaCriteria.listConsulta(); } }