List of usage examples for org.hibernate.boot.registry StandardServiceRegistryBuilder destroy
public static void destroy(ServiceRegistry serviceRegistry)
From source file:poo.estacionamiento.controller.Main.java
public static void main(String[] args) { SessionFactory sessionFactory = null; // A SessionFactory is set up once for an application! final StandardServiceRegistry registry = new StandardServiceRegistryBuilder() .configure("resources/hibernate.cfg.xml") // configures settings from hibernate.cfg.xml .build();/*from w ww . ja v a 2 s . c o m*/ try { sessionFactory = new MetadataSources(registry).buildMetadata().buildSessionFactory(); } catch (Exception e) { // The registry would be destroyed by the SessionFactory, but we had trouble building the SessionFactory // so destroy it manually. StandardServiceRegistryBuilder.destroy(registry); throw e; } PropietariosDao propietariosDao = new PropietariosDaoHibernateImpl(sessionFactory); AbonosPropietarioDao abonosPropietarioDao = new AbonosPropietarioDaoHibernateImpl(sessionFactory); UsuariosDao usuariosDao = new UsuariosDaoHibernateImpl(sessionFactory); // obtenemos el usuario logueado Usuario polo = usuariosDao.buscarPorNombre("polo"); new GestorCobroAbono(propietariosDao, abonosPropietarioDao, polo).run(); }
From source file:poo.mercado.controller.DatabaseSeeder.java
public static void main(String[] args) { SessionFactory sessionFactory = null; // A SessionFactory is set up once for an application! final StandardServiceRegistry registry = new StandardServiceRegistryBuilder() .configure("resources/hibernate.cfg.xml") // configures settings from hibernate.cfg.xml .build();// w ww .j a va 2 s .com try { sessionFactory = new MetadataSources(registry).buildMetadata().buildSessionFactory(); } catch (Exception e) { // The registry would be destroyed by the SessionFactory, but we had trouble building the SessionFactory // so destroy it manually. StandardServiceRegistryBuilder.destroy(registry); throw e; } Calendar hoy = Calendar.getInstance(); Calendar dentroDeSeisMeses = Calendar.getInstance(); dentroDeSeisMeses.add(Calendar.MONTH, 6); Calendar haceUnMes = Calendar.getInstance(); haceUnMes.add(Calendar.MONTH, -1); Calendar haceSeisMeses = Calendar.getInstance(); haceSeisMeses.add(Calendar.MONTH, -6); // creamos los tipos de puesto TiposPuestoDao tiposPuestoDao = new TiposPuestoDaoHibernateImpl(sessionFactory); TipoPuesto techado = new TipoPuesto("Techado", "Con techo de chapa"); tiposPuestoDao.guardar(techado); TipoPuesto sinTecho = new TipoPuesto("Sin techo", "Sin techo"); tiposPuestoDao.guardar(sinTecho); TipoPuesto refrigerado = new TipoPuesto("Refrigerado", "Con cmara refrigerante"); tiposPuestoDao.guardar(refrigerado); // creamos las dimensiones DimensionesDao dimensionesDao = new DimensionesDaoHibernateImpl(sessionFactory); Dimension d10m2 = new Dimension(5, 2, "10"); dimensionesDao.guardar(d10m2); Dimension d15m2 = new Dimension(5, 3, "15"); dimensionesDao.guardar(d15m2); Dimension d20m2 = new Dimension(5, 4, "20"); dimensionesDao.guardar(d20m2); // creamos los sectores SectoresDao sectoresDao = new SectoresDaoHibernateImpl(sessionFactory); Sector alaSur = new Sector("Ala Sur", "Ala Sur"); sectoresDao.guardar(alaSur); Sector alaNorte = new Sector("Ala Norte", "Ala Norte"); sectoresDao.guardar(alaNorte); // creamos los estados EstadosDao estadosDao = new EstadosDaoHibernateImpl(sessionFactory); Estado disponible = new Estado("Disponible", "Disponible"); estadosDao.guardar(disponible); Estado inhabilitado = new Estado("Inhabilitado", "Inhabilitado"); estadosDao.guardar(inhabilitado); Estado alquilado = new Estado("Alquilado", "Alquilado"); estadosDao.guardar(alquilado); // creamos los empleados EmpleadosDao empleadosDao = new EmpleadosDaoHibernateImpl(sessionFactory); Empleado marcosSastre = new Empleado("Sastre", 33123123, haceSeisMeses.getTime(), (int) Math.ceil(Math.random() * 1000), "Marcos", "msastre", "asdqwe123"); empleadosDao.guardar(marcosSastre); // simulamos el inicio de sesion de un empleado Sesion sesion = new Sesion(null, hoy.getTime(), marcosSastre); new SesionesDaoHibernateImpl(sessionFactory).guardar(sesion); // creamos los puestos // 1: Ala Sur, 10m2, Techado (DISPONIBLE) List<Lectura> lecturasUnoSur10m2Techado = new ArrayList<>(); lecturasUnoSur10m2Techado.add(new Lectura("56", hoy.getTime())); List<PrecioAlquiler> preciosUnoSur10m2Techado = new ArrayList<>(); preciosUnoSur10m2Techado .add(new PrecioAlquiler(haceUnMes.getTime(), new BigDecimal(4500), alaSur, d10m2, techado)); preciosUnoSur10m2Techado .add(new PrecioAlquiler(dentroDeSeisMeses.getTime(), new BigDecimal(4250), alaSur, d10m2, techado)); Puesto unoSur10m2Techado = new Puesto(1, lecturasUnoSur10m2Techado, disponible, preciosUnoSur10m2Techado); // 1: Ala Sur, 20m2, Techado (INHABILITADO) List<Lectura> lecturasDosSur10m2Techado = new ArrayList<>(); lecturasDosSur10m2Techado.add(new Lectura("11", hoy.getTime())); List<PrecioAlquiler> preciosDosSur10m2Techado = new ArrayList<>(); preciosDosSur10m2Techado .add(new PrecioAlquiler(haceUnMes.getTime(), new BigDecimal(4500), alaSur, d20m2, techado)); preciosDosSur10m2Techado .add(new PrecioAlquiler(dentroDeSeisMeses.getTime(), new BigDecimal(4250), alaSur, d20m2, techado)); Puesto dosSur10m2Techado = new Puesto(2, lecturasDosSur10m2Techado, inhabilitado, preciosDosSur10m2Techado); // 3: Ala Sur, 10m2, Sin Techo (DISPONIBLE) List<Lectura> lecturasTresSur10m2SinTecho = new ArrayList<>(); lecturasTresSur10m2SinTecho.add(new Lectura("45", hoy.getTime())); List<PrecioAlquiler> preciosTresSur10m2SinTecho = new ArrayList<>(); preciosTresSur10m2SinTecho .add(new PrecioAlquiler(haceUnMes.getTime(), new BigDecimal(2000), alaSur, d10m2, sinTecho)); preciosTresSur10m2SinTecho.add( new PrecioAlquiler(dentroDeSeisMeses.getTime(), new BigDecimal(2100), alaSur, d10m2, sinTecho)); Puesto tresSur10m2SinTecho = new Puesto(3, lecturasTresSur10m2SinTecho, disponible, preciosTresSur10m2SinTecho); // 4: Ala Norte, 10m2, Techado (ALQUILADO) List<Lectura> lecturasCuatroNorte10m2Techado = new ArrayList<>(); lecturasCuatroNorte10m2Techado.add(new Lectura("37", hoy.getTime())); List<PrecioAlquiler> preciosCuatroNorte10m2Techado = new ArrayList<>(); preciosCuatroNorte10m2Techado.add( new PrecioAlquiler(dentroDeSeisMeses.getTime(), new BigDecimal(3700), alaNorte, d10m2, techado)); Puesto cuatroNorte10m2Techado = new Puesto(4, lecturasCuatroNorte10m2Techado, alquilado, preciosCuatroNorte10m2Techado); // creamos los puestos PuestosDao puestosDao = new PuestosDaoHibernateImpl(sessionFactory, estadosDao); puestosDao.guardar(unoSur10m2Techado); puestosDao.guardar(dosSur10m2Techado); puestosDao.guardar(tresSur10m2SinTecho); puestosDao.guardar(cuatroNorte10m2Techado); // creamos los contratos Contrato contratoPuestoCuatro = new Contrato(null, dentroDeSeisMeses.getTime(), haceUnMes.getTime(), new BigDecimal(3700), 1, marcosSastre, sesion, cuatroNorte10m2Techado, null); // creamos los clientes ClientesDao clientesDao = new ClientesDaoHibernateImpl(sessionFactory); List<Contrato> contratosDeRosa = new ArrayList<>(); contratosDeRosa.add(contratoPuestoCuatro); clientesDao.guardar(new Cliente(20343434345l, "Av Siempreviva 123", "Rosa Fernndez", contratosDeRosa)); }
From source file:poo.mercado.controller.Main.java
/** * @param args the command line arguments *//*from w ww . j a v a2 s. c o m*/ public static void main(String[] args) { SessionFactory sessionFactory = null; // A SessionFactory is set up once for an application! final StandardServiceRegistry registry = new StandardServiceRegistryBuilder() .configure("resources/hibernate.cfg.xml") // configures settings from hibernate.cfg.xml .build(); try { sessionFactory = new MetadataSources(registry).buildMetadata().buildSessionFactory(); } catch (Exception e) { // The registry would be destroyed by the SessionFactory, but we had trouble building the SessionFactory // so destroy it manually. StandardServiceRegistryBuilder.destroy(registry); throw e; } Calendar hoy = Calendar.getInstance(); // creamos las instancias de capa DAO EmpleadosDao empleadosDao = new EmpleadosDaoHibernateImpl(sessionFactory); // simulamos el inicio de sesion de un empleado Empleado marcosSastre = empleadosDao.buscarPorNombreUsuario("msastre"); Sesion sesion = new Sesion(null, hoy.getTime(), marcosSastre); new SesionesDaoHibernateImpl(sessionFactory).guardar(sesion); // inicializamos el caso de uso new GestorAlquilerPuesto(sessionFactory, sesion).run(); }
From source file:poo.panaderia.controller.Main.java
/** * @param args the command line arguments */// w w w . j a v a 2s .c om public static void main(String[] args) { SessionFactory sessionFactory = null; // A SessionFactory is set up once for an application! final StandardServiceRegistry registry = new StandardServiceRegistryBuilder() .configure("resources/hibernate.cfg.xml") // configures settings from hibernate.cfg.xml .build(); try { sessionFactory = new MetadataSources(registry).buildMetadata().buildSessionFactory(); } catch (Exception e) { // The registry would be destroyed by the SessionFactory, but we had trouble building the SessionFactory // so destroy it manually. StandardServiceRegistryBuilder.destroy(registry); throw e; } // inicializamos las capas de acceso a datos ProductosDao productosDao = new ProductosDaoHibernateImpl(sessionFactory); DinerosDao dinerosDao = new DinerosDaoHibernateImpl(sessionFactory); // seteamos la composicin de la caja con 10 billetes de 10 ArrayList<ComposicionCaja> composiciones = new ArrayList<>(); ComposicionCaja c = new ComposicionCaja(); c.setCantidad(10); c.setDinero(dinerosDao.buscarBillete(10)); composiciones.add(c); // inicializamos la caja Caja caja = new Caja(); caja.setComposiciones(composiciones); // iniciamos el caso de uso new GestorDeCobros(productosDao, dinerosDao, caja).run(); }
From source file:poo.pizzeria.controller.Main.java
public static void main(String[] args) { SessionFactory sessionFactory = null; // A SessionFactory is set up once for an application! final StandardServiceRegistry registry = new StandardServiceRegistryBuilder() .configure("resources/hibernate.cfg.xml") // configures settings from hibernate.cfg.xml .build();/*from ww w .j a v a 2s. c o m*/ try { sessionFactory = new MetadataSources(registry).buildMetadata().buildSessionFactory(); } catch (Exception e) { // The registry would be destroyed by the SessionFactory, but we had trouble building the SessionFactory // so destroy it manually. StandardServiceRegistryBuilder.destroy(registry); throw e; } new GestorFacturacion(sessionFactory).run(); }
From source file:resources.DatabaseSeeder.java
public static void main(String[] args) { SessionFactory sessionFactory = null; // A SessionFactory is set up once for an application! final StandardServiceRegistry registry = new StandardServiceRegistryBuilder() .configure("resources/hibernate.cfg.xml") // configures settings from hibernate.cfg.xml .build();//from w w w . j a v a2s .c o m try { sessionFactory = new MetadataSources(registry).buildMetadata().buildSessionFactory(); } catch (Exception e) { // The registry would be destroyed by the SessionFactory, but we had trouble building the SessionFactory // so destroy it manually. StandardServiceRegistryBuilder.destroy(registry); throw e; } Calendar hoy = Calendar.getInstance(); // creamos los tipos de doc TipoDoc dni = new TipoDoc("Documento Nacional de Identidad", "DNI"); // creamos la fecha de nacimiento de ariel Calendar calAriel = Calendar.getInstance(); calAriel.set(Calendar.YEAR, 1980); calAriel.set(Calendar.MONTH, 11); calAriel.set(Calendar.DAY_OF_MONTH, 4); // creamos los odontologos Odontologo ariel = new Odontologo("Loza", "Av San Martn 1889", "Ariel", calAriel.getTime(), 30123123, 1234, dni); // creamos la definicion de agenda de ariel loza Calendar vigenteHasta = Calendar.getInstance(); vigenteHasta.add(Calendar.MONTH, 3); DefinicionAgenda definicionAgendaAriel = new DefinicionAgenda(30, hoy.getTime(), vigenteHasta.getTime()); // creamos el detalle de definicion por dia de la semana Calendar inicioDia = Calendar.getInstance(); inicioDia.set(Calendar.HOUR_OF_DAY, 8); inicioDia.set(Calendar.MINUTE, 0); inicioDia.set(Calendar.SECOND, 0); Calendar finDia = Calendar.getInstance(); finDia.set(Calendar.HOUR_OF_DAY, 18); finDia.set(Calendar.MINUTE, 0); finDia.set(Calendar.SECOND, 0); Calendar inicioIntervalo = Calendar.getInstance(); inicioIntervalo.set(Calendar.HOUR_OF_DAY, 12); inicioIntervalo.set(Calendar.MINUTE, 0); inicioIntervalo.set(Calendar.SECOND, 0); // para cada dia de la semana DetalleDefinicionAgenda lunes = new DetalleDefinicionAgenda(Calendar.MONDAY, 60, finDia.getTime(), inicioDia.getTime(), inicioIntervalo.getTime()); DetalleDefinicionAgenda martes = new DetalleDefinicionAgenda(Calendar.TUESDAY, 60, finDia.getTime(), inicioDia.getTime(), inicioIntervalo.getTime()); DetalleDefinicionAgenda miercoles = new DetalleDefinicionAgenda(Calendar.WEDNESDAY, 60, finDia.getTime(), inicioDia.getTime(), inicioIntervalo.getTime()); DetalleDefinicionAgenda jueves = new DetalleDefinicionAgenda(Calendar.THURSDAY, 60, finDia.getTime(), inicioDia.getTime(), inicioIntervalo.getTime()); DetalleDefinicionAgenda viernes = new DetalleDefinicionAgenda(Calendar.FRIDAY, 60, finDia.getTime(), inicioDia.getTime(), inicioIntervalo.getTime()); // ...los agregamos a la definicion definicionAgendaAriel.agregarDetalle(lunes); definicionAgendaAriel.agregarDetalle(martes); definicionAgendaAriel.agregarDetalle(miercoles); definicionAgendaAriel.agregarDetalle(jueves); definicionAgendaAriel.agregarDetalle(viernes); ArrayList<DefinicionAgenda> definiciones = new ArrayList<>(); definiciones.add(definicionAgendaAriel); // ...y se la asignamos a ariel ariel.setDefinicionesAgenda(definiciones); // creamos el DAO para guardarlos OdontologosDao odontologosDao = new OdontologosDaoHibernateImpl(sessionFactory); odontologosDao.guardar(ariel); // creamos el estado "Disponible" para los Turnos Estado disponible = new Estado("Disponible", "Disponible para reservar"); // y creamos el DAO para guardarlo EstadosDao estadosDao = new EstadosDaoHibernateImpl(sessionFactory); estadosDao.guardar(disponible); System.out.println("Objetos para pruebas inicializados correctamente..."); }
From source file:run.NewHibernateUtil.java
public static void close() { sessionFactory.close(); StandardServiceRegistryBuilder.destroy(sr); }
From source file:SessionManager.SessionManager.java
public static void ShutDown() { try {/* w ww .ja v a2 s. c o m*/ factory.close(); StandardServiceRegistryBuilder.destroy(factory.getSessionFactoryOptions().getServiceRegistry()); //Seems like a bug, we need to explicitly destroy service registry!! } catch (Throwable t) { System.err.println("Exception while closing session factory: " + t); } }
From source file:sk.fri.uniza.hibernate.Main.java
public static void main(String[] args) { Configuration conf = new Configuration(); conf.configure();//from w ww . j a v a 2s . c o m StandardServiceRegistry registry = new StandardServiceRegistryBuilder().configure().build(); SessionFactory buildSessionFactory = new MetadataSources(registry).buildMetadata().buildSessionFactory(); Session session = buildSessionFactory.openSession(); session.beginTransaction(); Student student = new Student(new Date(), "Bod", 26); Lecturer lecturer = new Lecturer("KTK", "Martin", 27); Person person = new Person("Jozef", 35); session.save(person); session.save(student); session.save(lecturer); session.getTransaction().commit(); session.close(); StandardServiceRegistryBuilder.destroy(registry); }
From source file:uk.org.openeyes.DatabaseFunctions.java
/** * * @param configFile/*from w ww. java2 s. com*/ * @param SystemLogger */ public void initSessionFactory(String configFile, DICOMLogger SystemLogger) { // A SessionFactory is set up once for an application! // if no config specified we should use the default one // TODO: need to check for /etc/openeyes/db.conf here!! if (this.dicomLogger == null) { this.dicomLogger = SystemLogger; } if (configFile.matches("(?i).*hibernate.cfg.xml") || configFile.equals("")) { String defaultConfig = "resources/hibernate.cfg.xml"; File inputFile = null; final StandardServiceRegistry registry; if (!configFile.equals("")) { inputFile = new File(configFile); } if (inputFile != null) { registry = new StandardServiceRegistryBuilder().configure(inputFile) // configures settings from hibernate.cfg.xml .build(); } else { registry = new StandardServiceRegistryBuilder().configure(defaultConfig) // configures settings from hibernate.cfg.xml .build(); } try { sessionFactory = new MetadataSources(registry).buildMetadata().buildSessionFactory(); setSession(); setTransaction(); } catch (Exception e) { // The registry would be destroyed by the SessionFactory, but we had trouble building the SessionFactory // so destroy it manually. // TODO: need to add debug config here! e.printStackTrace(); StandardServiceRegistryBuilder.destroy(registry); dicomLogger.systemExitWithLog(5, "Failed to connect to the database, please check your hibernate configuration file!", this); //System.exit(5); } } else { // try to open /etc/ database config try { sessionFactory = configureHibernate(configFile).buildSessionFactory(); setSession(); setTransaction(); } catch (Exception e) { dicomLogger.systemExitWithLog(5, "Failed to connect to the database, please check your hibernate configuration file!", this); } } }