Example usage for org.hibernate.boot.registry StandardServiceRegistryBuilder StandardServiceRegistryBuilder

List of usage examples for org.hibernate.boot.registry StandardServiceRegistryBuilder StandardServiceRegistryBuilder

Introduction

In this page you can find the example usage for org.hibernate.boot.registry StandardServiceRegistryBuilder StandardServiceRegistryBuilder.

Prototype

public StandardServiceRegistryBuilder() 

Source Link

Document

Create a default builder.

Usage

From source file:pl.edu.wat.cinema.util.HibernateUtil.java

private static SessionFactory configureSessionFactory() throws HibernateException {
    Configuration configuration = new Configuration();
    configuration.configure();//from  w  w  w .j a v  a 2  s . com
    serviceRegistry = new StandardServiceRegistryBuilder().applySettings(configuration.getProperties()).build();
    sessionFactory = configuration.buildSessionFactory(serviceRegistry);
    return sessionFactory;
}

From source file:poo.cine.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();/* w w w .jav 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;
    }

    new GestorPelicula(sessionFactory).run();
}

From source file:poo.consultorio.controller.Main.java

/**
 * @param args the command line arguments
 *//*  ww w . ja va  2 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;
    }

    // creamos los objetos de DAO
    OdontologosDao odontologosDao = new OdontologosDaoHibernateImpl(sessionFactory);
    EstadosDao estadosDao = new EstadosDaoHibernateImpl(sessionFactory);

    // iniciamos el caso de uso
    new GestorDeAgenda(odontologosDao, estadosDao).run();
}

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  w w.  j a va  2  s .c  om
    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();/*from   w  w w  .j  av  a 2s  . c om*/
    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  www  . j  a v  a 2  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
 *///  ww w . j a  va  2 s  .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();// ww w . jav 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:powerhibernate.HibernateUtil.java

public static SessionFactory getSessionFactory() {
    if (sessionFactory == null) {
        Configuration configuration = new Configuration().configure();
        ServiceRegistry sr = new StandardServiceRegistryBuilder().applySettings(configuration.getProperties())
                .build();/*ww w .j  ava  2 s  . c om*/
        //configuration.addClass(powerhibernate.Student.class);
        // Read mappings as a application resourceName
        // addResource is for add hbml.xml files in case of declarative approach
        configuration.addResource("powerhibernate/Student.hbm.xml");
        sessionFactory = configuration.buildSessionFactory(sr);
    }
    return sessionFactory;
}

From source file:principal.HibernateUtil.java

private static SessionFactory buildSessionFactory() {
    try {//from w w  w.  j a  v a 2  s .  c  o  m
        if (sessionFactory == null) {
            Configuration configuration = new Configuration()
                    .configure(HibernateUtil.class.getResource("/hibernate.cfg.xml"));
            StandardServiceRegistryBuilder serviceRegistryBuilder = new StandardServiceRegistryBuilder();
            serviceRegistryBuilder.applySettings(configuration.getProperties());
            ServiceRegistry serviceRegistry = serviceRegistryBuilder.build();
            sessionFactory = configuration.buildSessionFactory(serviceRegistry);
        }
        return sessionFactory;
    } catch (Throwable ex) {
        System.err.println("Initial SessionFactory creation failed: " + ex);
        throw new ExceptionInInitializerError(ex);
    }
}