Guest User

Untitled

a guest
Sep 21st, 2018
93
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 12.36 KB | None | 0 0
  1. package org.hibernate.model.dao;
  2.  
  3. import java.util.List;
  4. import org.hibernate.*;
  5. import org.hibernate.criterion.Example;
  6. import org.hibernate.model.*;
  7.  
  8. /**
  9.  *
  10.  * @author Miguel
  11.  */
  12. public class infoDao {
  13.  
  14.     Session sn = HibernateUtil.getSessionFactory().getCurrentSession();
  15.     Transaction tx = null;
  16.     Query qr = null;
  17.  
  18.     public boolean createAeropuerto(Aeropuerto instance) {
  19.         try {
  20.             tx = sn.beginTransaction();
  21.             sn.save(instance);
  22.             tx.commit();
  23.             return true;
  24.  
  25.         } catch (HibernateException he) {
  26.             tx.rollback();
  27.             System.out.println(he.getMessage());
  28.             return false;
  29.         }
  30.     }
  31.  
  32.     public List<Aeropuerto> readAeropuerto() {
  33.         List<Aeropuerto> list = null;
  34.         try {
  35.             tx = sn.beginTransaction();
  36.             qr = sn.createQuery("FROM aeropuerto");
  37.             list = qr.list();
  38.             tx.commit();
  39.             return list;
  40.         } catch (HibernateException he) {
  41.             tx.rollback();
  42.             System.out.println(he.getMessage());
  43.             return list;
  44.         }
  45.     }
  46.  
  47.     public boolean updateAeropuerto(Aeropuerto instance) {
  48.         try {
  49.             tx = sn.beginTransaction();
  50.             sn.update(instance);
  51.             tx.commit();
  52.             return true;
  53.         } catch (HibernateException he) {
  54.             tx.rollback();
  55.             System.out.println(he.getMessage());
  56.             return false;
  57.         }
  58.     }
  59.  
  60.     public boolean deleteAeropuerto(Aeropuerto instance) {
  61.         try {
  62.             tx = sn.beginTransaction();
  63.             sn.delete(instance);
  64.             tx.commit();
  65.             return true;
  66.         } catch (HibernateException he) {
  67.             tx.rollback();
  68.             System.out.println(he.getMessage());
  69.             return false;
  70.         }
  71.     }
  72.  
  73.     public Aeropuerto findAeropuertoById(int id) {
  74.         Aeropuerto pci = new Aeropuerto();
  75.         try {
  76.             tx = sn.beginTransaction();
  77.             pci = (Aeropuerto) sn.get("org.hibernate.model.Aeropuerto", id);
  78.             tx.commit();
  79.             return pci;
  80.         } catch (HibernateException he) {
  81.             tx.rollback();
  82.             System.out.println(he.getMessage());
  83.             return pci;
  84.         }
  85.     }
  86.  
  87.     public List<Aeropuerto> findAeropuertoByCriteria(Aeropuerto instance) {
  88.         List<Aeropuerto> lis = null;
  89.         try {
  90.             tx = sn.beginTransaction();
  91.             lis = sn.createCriteria("org.hibernate.model.Aeropuerto").add(Example.create(instance)).list();
  92.             tx.commit();
  93.             return lis;
  94.         } catch (HibernateException he) {
  95.             tx.rollback();
  96.             System.out.println(he.getMessage());
  97.             return lis;
  98.         }
  99.     }
  100.  
  101.     public boolean createAvion(Avion instance) {
  102.         try {
  103.             tx = sn.beginTransaction();
  104.             sn.save(instance);
  105.             tx.commit();
  106.             return true;
  107.  
  108.         } catch (HibernateException he) {
  109.             tx.rollback();
  110.             System.out.println(he.getMessage());
  111.             return false;
  112.         }
  113.     }
  114.  
  115.     public List<Avion> readAvion() {
  116.         List<Avion> list = null;
  117.         try {
  118.             tx = sn.beginTransaction();
  119.             qr = sn.createQuery("FROM Avion");
  120.             list = qr.list();
  121.             tx.commit();
  122.             return list;
  123.         } catch (HibernateException he) {
  124.             tx.rollback();
  125.             System.out.println(he.getMessage());
  126.             return list;
  127.         }
  128.     }
  129.  
  130.     public boolean updateAvion(Avion instance) {
  131.         try {
  132.             tx = sn.beginTransaction();
  133.             sn.update(instance);
  134.             tx.commit();
  135.             return true;
  136.         } catch (HibernateException he) {
  137.             tx.rollback();
  138.             System.out.println(he.getMessage());
  139.             return false;
  140.         }
  141.     }
  142.  
  143.     public boolean deleteAvion(Avion instance) {
  144.         try {
  145.             tx = sn.beginTransaction();
  146.             sn.delete(instance);
  147.             tx.commit();
  148.             return true;
  149.         } catch (HibernateException he) {
  150.             tx.rollback();
  151.             System.out.println(he.getMessage());
  152.             return false;
  153.         }
  154.     }
  155.  
  156.     public Avion findAvionById(int id) {
  157.         Avion av = new Avion();
  158.         try {
  159.             tx = sn.beginTransaction();
  160.             av = (Avion) sn.get("org.hibernate.model.Avion", id);
  161.             tx.commit();
  162.             return av;
  163.         } catch (HibernateException he) {
  164.             tx.rollback();
  165.             System.out.println(he.getMessage());
  166.             return av;
  167.         }
  168.     }
  169.  
  170.     public List<Avion> findAvionByCriteria(Avion instance) {
  171.         List<Avion> lis = null;
  172.         try {
  173.             tx = sn.beginTransaction();
  174.             lis = sn.createCriteria("org.hibernate.model.Avion").add(Example.create(instance)).list();
  175.             tx.commit();
  176.             return lis;
  177.         } catch (HibernateException he) {
  178.             tx.rollback();
  179.             System.out.println(he.getMessage());
  180.             return lis;
  181.         }
  182.     }
  183.  
  184.     public boolean createClientes(Clientes instance) {
  185.         try {
  186.             tx = sn.beginTransaction();
  187.             sn.save(instance);
  188.             tx.commit();
  189.             return true;
  190.  
  191.         } catch (HibernateException he) {
  192.             tx.rollback();
  193.             System.out.println(he.getMessage());
  194.             return false;
  195.         }
  196.     }
  197.  
  198.     public List<Clientes> readClientes() {
  199.         List<Clientes> list = null;
  200.         try {
  201.             tx = sn.beginTransaction();
  202.             qr = sn.createQuery("FROM Clientes");
  203.             list = qr.list();
  204.             tx.commit();
  205.             return list;
  206.         } catch (HibernateException he) {
  207.             tx.rollback();
  208.             System.out.println(he.getMessage());
  209.             return list;
  210.         }
  211.     }
  212.  
  213.     public boolean updateClientes(Clientes instance) {
  214.         try {
  215.             tx = sn.beginTransaction();
  216.             sn.update(instance);
  217.             tx.commit();
  218.             return true;
  219.         } catch (HibernateException he) {
  220.             tx.rollback();
  221.             System.out.println(he.getMessage());
  222.             return false;
  223.         }
  224.     }
  225.  
  226.     public boolean deleteClientes(Clientes instance) {
  227.         try {
  228.             tx = sn.beginTransaction();
  229.             sn.delete(instance);
  230.             tx.commit();
  231.             return true;
  232.         } catch (HibernateException he) {
  233.             tx.rollback();
  234.             System.out.println(he.getMessage());
  235.             return false;
  236.         }
  237.     }
  238.  
  239.     public Clientes findClientesById(int id) {
  240.         Clientes cl = new Clientes();
  241.         try {
  242.             tx = sn.beginTransaction();
  243.             cl = (Clientes) sn.get("org.hibernate.model.Clientes", id);
  244.             tx.commit();
  245.             return cl;
  246.         } catch (HibernateException he) {
  247.             tx.rollback();
  248.             System.out.println(he.getMessage());
  249.             return cl;
  250.         }
  251.     }
  252.  
  253.     public List<Clientes> findClientesByCriteria(Clientes instance) {
  254.         List<Clientes> lis = null;
  255.         try {
  256.             tx = sn.beginTransaction();
  257.             lis = sn.createCriteria("org.hibernate.model.Clientes").add(Example.create(instance)).list();
  258.             tx.commit();
  259.             return lis;
  260.         } catch (HibernateException he) {
  261.             tx.rollback();
  262.             System.out.println(he.getMessage());
  263.             return lis;
  264.         }
  265.     }
  266.  
  267.     public boolean createReservaciones(Reservaciones instance) {
  268.         try {
  269.             tx = sn.beginTransaction();
  270.             sn.save(instance);
  271.             tx.commit();
  272.             return true;
  273.  
  274.         } catch (HibernateException he) {
  275.             tx.rollback();
  276.             System.out.println(he.getMessage());
  277.             return false;
  278.         }
  279.     }
  280.  
  281.     public List<Reservaciones> readReservaciones() {
  282.         List<Reservaciones> list = null;
  283.         try {
  284.             tx = sn.beginTransaction();
  285.             qr = sn.createQuery("FROM Reservaciones");
  286.             list = qr.list();
  287.             tx.commit();
  288.             return list;
  289.         } catch (HibernateException he) {
  290.             tx.rollback();
  291.             System.out.println(he.getMessage());
  292.             return list;
  293.         }
  294.     }
  295.  
  296.     public boolean updateReservaciones(Reservaciones instance) {
  297.         try {
  298.             tx = sn.beginTransaction();
  299.             sn.update(instance);
  300.             tx.commit();
  301.             return true;
  302.         } catch (HibernateException he) {
  303.             tx.rollback();
  304.             System.out.println(he.getMessage());
  305.             return false;
  306.         }
  307.     }
  308.  
  309.     public boolean deleteReservaciones(Reservaciones instance) {
  310.         try {
  311.             tx = sn.beginTransaction();
  312.             sn.delete(instance);
  313.             tx.commit();
  314.             return true;
  315.         } catch (HibernateException he) {
  316.             tx.rollback();
  317.             System.out.println(he.getMessage());
  318.             return false;
  319.         }
  320.     }
  321.  
  322.     public Reservaciones findReservacionesById(int id) {
  323.         Reservaciones re = new Reservaciones();
  324.         try {
  325.             tx = sn.beginTransaction();
  326.             re = (Reservaciones) sn.get("org.hibernate.model.Reservaciones", id);
  327.             tx.commit();
  328.             return re;
  329.         } catch (HibernateException he) {
  330.             tx.rollback();
  331.             System.out.println(he.getMessage());
  332.             return re;
  333.         }
  334.     }
  335.  
  336.     public List<Reservaciones> findReservacionesByCriteria(Reservaciones instance) {
  337.         List<Reservaciones> lis = null;
  338.         try {
  339.             tx = sn.beginTransaction();
  340.             lis = sn.createCriteria("org.hibernate.model.Reservaciones").add(Example.create(instance)).list();
  341.             tx.commit();
  342.             return lis;
  343.         } catch (HibernateException he) {
  344.             tx.rollback();
  345.             System.out.println(he.getMessage());
  346.             return lis;
  347.         }
  348.     }
  349.  
  350.     public boolean createVuelos(Vuelos instance) {
  351.         try {
  352.             tx = sn.beginTransaction();
  353.             sn.save(instance);
  354.             tx.commit();
  355.             return true;
  356.  
  357.         } catch (HibernateException he) {
  358.             tx.rollback();
  359.             System.out.println(he.getMessage());
  360.             return false;
  361.         }
  362.     }
  363.  
  364.     public List<Vuelos> readVuelos() {
  365.         List<Vuelos> list = null;
  366.         try {
  367.             tx = sn.beginTransaction();
  368.             qr = sn.createQuery("FROM Vuelos");
  369.             list = qr.list();
  370.             tx.commit();
  371.             return list;
  372.         } catch (HibernateException he) {
  373.             tx.rollback();
  374.             System.out.println(he.getMessage());
  375.             return list;
  376.         }
  377.     }
  378.  
  379.     public boolean updateVuelos(Vuelos instance) {
  380.         try {
  381.             tx = sn.beginTransaction();
  382.             sn.update(instance);
  383.             tx.commit();
  384.             return true;
  385.         } catch (HibernateException he) {
  386.             tx.rollback();
  387.             System.out.println(he.getMessage());
  388.             return false;
  389.         }
  390.     }
  391.  
  392.     public boolean deleteVuelos(Vuelos instance) {
  393.         try {
  394.             tx = sn.beginTransaction();
  395.             sn.delete(instance);
  396.             tx.commit();
  397.             return true;
  398.         } catch (HibernateException he) {
  399.             tx.rollback();
  400.             System.out.println(he.getMessage());
  401.             return false;
  402.         }
  403.     }
  404.  
  405.     public Vuelos findVuelosById(int id) {
  406.         Vuelos vu = new Vuelos();
  407.         try {
  408.             tx = sn.beginTransaction();
  409.             vu = (Vuelos) sn.get("org.hibernate.model.Vuelos", id);
  410.             tx.commit();
  411.             return vu;
  412.         } catch (HibernateException he) {
  413.             tx.rollback();
  414.             System.out.println(he.getMessage());
  415.             return vu;
  416.         }
  417.     }
  418.  
  419.     public List<Vuelos> findVuelosByCriteria(Vuelos instance) {
  420.         List<Vuelos> lis = null;
  421.         try {
  422.             tx = sn.beginTransaction();
  423.             lis = sn.createCriteria("org.hibernate.model.Vuelos").add(Example.create(instance)).list();
  424.             tx.commit();
  425.             return lis;
  426.         } catch (HibernateException he) {
  427.             tx.rollback();
  428.             System.out.println(he.getMessage());
  429.             return lis;
  430.         }
  431.     }
  432. }
Add Comment
Please, Sign In to add comment