@SuppressWarnings("unchecked") @Test public void testExecute() { final EntityManager entityManager = context.mock(EntityManager.class); final PersistenceListRequest req = context.mock(PersistenceListRequest.class); final Session session = context.mock(Session.class); final EntityTransaction transaction = context.mock(EntityTransaction.class); final List<Activity> activities = new LinkedList<Activity>(); for (int i = 0; i < NUMOFACTIVITY; i++) { activities.add(context.mock(Activity.class, "a" + String.valueOf(i))); } InsertBulkMapper sut = new InsertBulkMapper(); sut.setEntityManager(entityManager); context.checking(new Expectations() { { oneOf(req).getDomainEnities(); will(returnValue(activities)); oneOf(entityManager).getDelegate(); will(returnValue(session)); exactly(NUMOFACTIVITY).of(session).save(with(any(Activity.class))); exactly(5).of(session).flush(); exactly(5).of(session).clear(); oneOf(entityManager).getTransaction(); will(returnValue(transaction)); oneOf(transaction).commit(); oneOf(session).close(); } }); assertTrue(sut.execute(req)); context.assertIsSatisfied(); }
public Boolean execute(final PersistenceListRequest inRequest) { List entities = inRequest.getDomainEnities(); Session session = getHibernateSession(); for (int i = 0; i < entities.size(); i++) { session.save(entities.get(i)); if (i % BULKNUM == 0) { session.flush(); session.clear(); } } getEntityManager().getTransaction().commit(); session.close(); return true; }
InsertBulkMapper extends
        BaseArgDomainMapper<PersistenceListRequest, Boolean> { public Boolean execute(final PersistenceListRequest inRequest) { List entities = inRequest.getDomainEnities(); Session session = getHibernateSession(); for (int i = 0; i < entities.size(); i++) { session.save(entities.get(i)); if (i % BULKNUM == 0) { session.flush(); session.clear(); } } getEntityManager().getTransaction().commit(); session.close(); return true; } }
InsertBulkMapper extends
        BaseArgDomainMapper<PersistenceListRequest, Boolean> { public Boolean execute(final PersistenceListRequest inRequest) { List entities = inRequest.getDomainEnities(); Session session = getHibernateSession(); for (int i = 0; i < entities.size(); i++) { session.save(entities.get(i)); if (i % BULKNUM == 0) { session.flush(); session.clear(); } } getEntityManager().getTransaction().commit(); session.close(); return true; }  }
InsertBulkMapper extends
        BaseArgDomainMapper<PersistenceListRequest, Boolean> { public Boolean execute(final PersistenceListRequest inRequest) { List entities = inRequest.getDomainEnities(); Session session = getHibernateSession(); for (int i = 0; i < entities.size(); i++) { session.save(entities.get(i)); if (i % BULKNUM == 0) { session.flush(); session.clear(); } } getEntityManager().getTransaction().commit(); session.close(); return true; }  Boolean execute(final PersistenceListRequest inRequest); }
InsertBulkMapper extends
        BaseArgDomainMapper<PersistenceListRequest, Boolean> { public Boolean execute(final PersistenceListRequest inRequest) { List entities = inRequest.getDomainEnities(); Session session = getHibernateSession(); for (int i = 0; i < entities.size(); i++) { session.save(entities.get(i)); if (i % BULKNUM == 0) { session.flush(); session.clear(); } } getEntityManager().getTransaction().commit(); session.close(); return true; }  Boolean execute(final PersistenceListRequest inRequest);  }