Search in sources :

Example 1 with UserTestDbo

use of org.webpieces.plugins.hibernate.app.dbo.UserTestDbo in project webpieces by deanhiller.

the class TestAjaxHibernate method loadDataInDb.

public static UserTestDbo loadDataInDb() {
    String email = "dean2@sync.xsoftware.biz";
    //populate database....
    EntityManagerFactory factory = Persistence.createEntityManagerFactory(HibernateAppMeta.PERSISTENCE_TEST_UNIT);
    EntityManager mgr = factory.createEntityManager();
    EntityTransaction tx = mgr.getTransaction();
    tx.begin();
    UserTestDbo user = new UserTestDbo();
    user.setEmail(email);
    user.setName("SomeName");
    user.setFirstName("Dean");
    user.setLastName("Hill");
    mgr.persist(user);
    mgr.flush();
    tx.commit();
    return user;
}
Also used : EntityTransaction(javax.persistence.EntityTransaction) EntityManager(javax.persistence.EntityManager) UserTestDbo(org.webpieces.plugins.hibernate.app.dbo.UserTestDbo) EntityManagerFactory(javax.persistence.EntityManagerFactory)

Example 2 with UserTestDbo

use of org.webpieces.plugins.hibernate.app.dbo.UserTestDbo in project webpieces by deanhiller.

the class CrudTestController method multiSelect.

public Render multiSelect(Integer id) {
    if (id == null) {
        return Actions.renderThis("entity", new UserTestDbo(), "levels", LevelEducation.values(), "roles", Role.values(), "selectedRoles", new ArrayList<>());
    }
    UserTestDbo user = UserTestDbo.findWithJoin(Em.get(), id);
    List<UserRoleDbo> roles = user.getRoles();
    List<Role> selectedRoles = roles.stream().map(r -> r.getRole()).collect(Collectors.toList());
    return Actions.renderThis("entity", user, "levels", LevelEducation.values(), "roles", Role.values(), "selectedRoles", selectedRoles);
}
Also used : Logger(org.webpieces.util.logging.Logger) EDIT_USER_PAGE(org.webpieces.plugins.hibernate.app.HibernateRouteId.EDIT_USER_PAGE) FlashAndRedirect(org.webpieces.router.api.actions.FlashAndRedirect) Redirect(org.webpieces.router.api.actions.Redirect) Render(org.webpieces.router.api.actions.Render) EntityManager(javax.persistence.EntityManager) Singleton(javax.inject.Singleton) Collectors(java.util.stream.Collectors) Role(org.webpieces.plugins.hibernate.app.dbo.Role) ArrayList(java.util.ArrayList) ADD_USER_PAGE(org.webpieces.plugins.hibernate.app.HibernateRouteId.ADD_USER_PAGE) List(java.util.List) Query(javax.persistence.Query) Em(org.webpieces.plugins.hibernate.Em) UserRoleDbo(org.webpieces.plugins.hibernate.app.dbo.UserRoleDbo) LevelEducation(org.webpieces.plugins.hibernate.app.dbo.LevelEducation) UserTestDbo(org.webpieces.plugins.hibernate.app.dbo.UserTestDbo) LoggerFactory(org.webpieces.util.logging.LoggerFactory) Current(org.webpieces.ctx.api.Current) Actions(org.webpieces.router.api.actions.Actions) Role(org.webpieces.plugins.hibernate.app.dbo.Role) UserTestDbo(org.webpieces.plugins.hibernate.app.dbo.UserTestDbo) UserRoleDbo(org.webpieces.plugins.hibernate.app.dbo.UserRoleDbo)

Example 3 with UserTestDbo

use of org.webpieces.plugins.hibernate.app.dbo.UserTestDbo in project webpieces by deanhiller.

the class CrudTestController method userList.

public Render userList() {
    EntityManager mgr = Em.get();
    Query query = mgr.createNamedQuery("findAllUsers");
    @SuppressWarnings("unchecked") List<UserTestDbo> users = query.getResultList();
    return Actions.renderThis("users", users);
}
Also used : EntityManager(javax.persistence.EntityManager) Query(javax.persistence.Query) UserTestDbo(org.webpieces.plugins.hibernate.app.dbo.UserTestDbo)

Example 4 with UserTestDbo

use of org.webpieces.plugins.hibernate.app.dbo.UserTestDbo in project webpieces by deanhiller.

the class TestSyncHibernate method load.

private UserTestDbo load(Integer id) {
    EntityManagerFactory factory = Persistence.createEntityManagerFactory(HibernateAppMeta.PERSISTENCE_TEST_UNIT);
    EntityManager mgr = factory.createEntityManager();
    EntityTransaction tx = mgr.getTransaction();
    tx.begin();
    UserTestDbo user = mgr.find(UserTestDbo.class, id);
    tx.commit();
    return user;
}
Also used : EntityTransaction(javax.persistence.EntityTransaction) EntityManager(javax.persistence.EntityManager) UserTestDbo(org.webpieces.plugins.hibernate.app.dbo.UserTestDbo) EntityManagerFactory(javax.persistence.EntityManagerFactory)

Example 5 with UserTestDbo

use of org.webpieces.plugins.hibernate.app.dbo.UserTestDbo in project webpieces by deanhiller.

the class TestSyncHibernate method loadDataInDb.

public static UserTestDbo loadDataInDb() {
    String email = "dean2@sync.xsoftware.biz";
    //populate database....
    EntityManagerFactory factory = Persistence.createEntityManagerFactory(HibernateAppMeta.PERSISTENCE_TEST_UNIT);
    EntityManager mgr = factory.createEntityManager();
    EntityTransaction tx = mgr.getTransaction();
    tx.begin();
    UserTestDbo manager = new UserTestDbo();
    manager.setEmail("asdf@asf.com");
    manager.setName("somadsf");
    UserTestDbo user = new UserTestDbo();
    user.setEmail(email);
    user.setName("SomeName");
    user.setFirstName("Dean");
    user.setLastName("Hill");
    user.setManager(manager);
    mgr.persist(manager);
    mgr.persist(user);
    mgr.flush();
    tx.commit();
    return user;
}
Also used : EntityTransaction(javax.persistence.EntityTransaction) EntityManager(javax.persistence.EntityManager) UserTestDbo(org.webpieces.plugins.hibernate.app.dbo.UserTestDbo) EntityManagerFactory(javax.persistence.EntityManagerFactory)

Aggregations

UserTestDbo (org.webpieces.plugins.hibernate.app.dbo.UserTestDbo)20 EntityManager (javax.persistence.EntityManager)13 EntityManagerFactory (javax.persistence.EntityManagerFactory)6 EntityTransaction (javax.persistence.EntityTransaction)6 Query (javax.persistence.Query)3 Test (org.junit.Test)3 WebserverForTest (org.webpieces.webserver.WebserverForTest)3 AbstractWebpiecesTest (org.webpieces.webserver.test.AbstractWebpiecesTest)3 FullResponse (org.webpieces.webserver.test.FullResponse)3 HttpDummyRequest (org.webpieces.webserver.test.HttpDummyRequest)3 UserRoleDbo (org.webpieces.plugins.hibernate.app.dbo.UserRoleDbo)2 ArrayList (java.util.ArrayList)1 List (java.util.List)1 Collectors (java.util.stream.Collectors)1 Singleton (javax.inject.Singleton)1 Current (org.webpieces.ctx.api.Current)1 Em (org.webpieces.plugins.hibernate.Em)1 ADD_USER_PAGE (org.webpieces.plugins.hibernate.app.HibernateRouteId.ADD_USER_PAGE)1 EDIT_USER_PAGE (org.webpieces.plugins.hibernate.app.HibernateRouteId.EDIT_USER_PAGE)1 LevelEducation (org.webpieces.plugins.hibernate.app.dbo.LevelEducation)1