Search in sources :

Example 1 with EntityManagerCreator

use of br.com.caelum.vraptor.util.jpa.EntityManagerCreator in project agiletickets by caelum.

the class PreencheBanco method main.

// ALUNO: Não apague essa classe
public static void main(String[] args) {
    EntityManagerFactoryCreator creator = new EntityManagerFactoryCreator();
    creator.create();
    EntityManagerCreator managerCreator = new EntityManagerCreator(creator.getInstance());
    managerCreator.create();
    EntityManager manager = managerCreator.getInstance();
    manager.getTransaction().begin();
    manager.createQuery("delete from Sessao").executeUpdate();
    manager.createQuery("delete from Espetaculo").executeUpdate();
    manager.createQuery("delete from Estabelecimento").executeUpdate();
    Estabelecimento estabelecimento = new Estabelecimento();
    estabelecimento.setNome("Casa de shows");
    estabelecimento.setEndereco("Rua dos Silveiras, 12345");
    Espetaculo espetaculo = new Espetaculo();
    espetaculo.setEstabelecimento(estabelecimento);
    espetaculo.setNome("Depeche Mode");
    espetaculo.setTipo(TipoDeEspetaculo.SHOW);
    manager.persist(estabelecimento);
    manager.persist(espetaculo);
    for (int i = 0; i < 10; i++) {
        Sessao sessao = new Sessao();
        sessao.setEspetaculo(espetaculo);
        sessao.setInicio(new DateTime().plusDays(7 + i));
        sessao.setDuracaoEmMinutos(60 * 3);
        sessao.setTotalIngressos(100);
        sessao.setIngressosReservados(i < 5 ? 100 - i : 0);
        sessao.setPreco(new BigDecimal("50"));
        manager.persist(sessao);
    }
    manager.getTransaction().commit();
    manager.close();
}
Also used : Estabelecimento(br.com.caelum.agiletickets.models.Estabelecimento) EntityManager(javax.persistence.EntityManager) Sessao(br.com.caelum.agiletickets.models.Sessao) EntityManagerCreator(br.com.caelum.vraptor.util.jpa.EntityManagerCreator) EntityManagerFactoryCreator(br.com.caelum.vraptor.util.jpa.EntityManagerFactoryCreator) DateTime(org.joda.time.DateTime) BigDecimal(java.math.BigDecimal) Espetaculo(br.com.caelum.agiletickets.models.Espetaculo) TipoDeEspetaculo(br.com.caelum.agiletickets.models.TipoDeEspetaculo)

Aggregations

Espetaculo (br.com.caelum.agiletickets.models.Espetaculo)1 Estabelecimento (br.com.caelum.agiletickets.models.Estabelecimento)1 Sessao (br.com.caelum.agiletickets.models.Sessao)1 TipoDeEspetaculo (br.com.caelum.agiletickets.models.TipoDeEspetaculo)1 EntityManagerCreator (br.com.caelum.vraptor.util.jpa.EntityManagerCreator)1 EntityManagerFactoryCreator (br.com.caelum.vraptor.util.jpa.EntityManagerFactoryCreator)1 BigDecimal (java.math.BigDecimal)1 EntityManager (javax.persistence.EntityManager)1 DateTime (org.joda.time.DateTime)1