use of br.com.caelum.vraptor.util.jpa.EntityManagerFactoryCreator 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();
}
Aggregations