Search in sources :

Example 16 with UserTestDbo

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

the class HibernateAsyncController method runEntityLoad.

private Render runEntityLoad(EntityManager mgr, Integer id) {
    UserTestDbo user = mgr.find(UserTestDbo.class, id);
    log.info("user loaded");
    return Actions.renderThis("user", user);
}
Also used : UserTestDbo(org.webpieces.plugins.hibernate.app.dbo.UserTestDbo)

Example 17 with UserTestDbo

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

the class TestSyncHibernate method verifyLazyLoad.

public static void verifyLazyLoad(int id) {
    //verify lazy load is working so we know test is testing what it should be
    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);
    UserTestDbo manager = user.getManager();
    Assert.assertEquals("somadsf", manager.getName());
    mgr.flush();
    tx.commit();
}
Also used : EntityTransaction(javax.persistence.EntityTransaction) EntityManager(javax.persistence.EntityManager) UserTestDbo(org.webpieces.plugins.hibernate.app.dbo.UserTestDbo) EntityManagerFactory(javax.persistence.EntityManagerFactory)

Example 18 with UserTestDbo

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

the class TestSyncHibernate method testHibernatePostPartialDataDoesntBlowDataAway.

@Test
public void testHibernatePostPartialDataDoesntBlowDataAway() {
    UserTestDbo user = loadDataInDb();
    HttpDummyRequest req = Requests.createPostRequest("/testmerge", "user.id", user.getId() + "", "user.name", "blah1", "user.firstName", "blah2");
    http11Socket.send(req);
    FullResponse response = ResponseExtract.assertSingleResponse(http11Socket);
    response.assertStatusCode(KnownStatusCode.HTTP_303_SEEOTHER);
    UserTestDbo user2 = load(user.getId());
    //name changed
    Assert.assertEquals("blah1", user2.getName());
    //firstname changed
    Assert.assertEquals("blah2", user2.getFirstName());
    //lastname remained the same
    Assert.assertEquals(user.getLastName(), user2.getLastName());
}
Also used : FullResponse(org.webpieces.webserver.test.FullResponse) UserTestDbo(org.webpieces.plugins.hibernate.app.dbo.UserTestDbo) HttpDummyRequest(org.webpieces.webserver.test.HttpDummyRequest) AbstractWebpiecesTest(org.webpieces.webserver.test.AbstractWebpiecesTest) Test(org.junit.Test) WebserverForTest(org.webpieces.webserver.WebserverForTest)

Example 19 with UserTestDbo

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

the class HibernateController method save.

/**
	 * BIG NOTE: This is NOT the way you should use hibernate but is a base case for us to 
	 * just test out hibernate without filters and added complexity
	 * @return
	 */
public Redirect save() {
    EntityManager mgr = Em.get();
    UserTestDbo user = new UserTestDbo();
    user.setEmail("dean@sync.xsoftware.biz");
    user.setName("SomeName");
    mgr.persist(user);
    mgr.flush();
    return Actions.redirect(HibernateRouteId.DISPLAY_ENTITY, "id", user.getId());
}
Also used : EntityManager(javax.persistence.EntityManager) UserTestDbo(org.webpieces.plugins.hibernate.app.dbo.UserTestDbo)

Example 20 with UserTestDbo

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

the class HibernateController method display.

public Render display(Integer id) {
    EntityManager mgr = Em.get();
    UserTestDbo user = mgr.find(UserTestDbo.class, id);
    return Actions.renderThis("user", user);
}
Also used : EntityManager(javax.persistence.EntityManager) UserTestDbo(org.webpieces.plugins.hibernate.app.dbo.UserTestDbo)

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