/** * Instantiates a new entity manager impl. * * @param factory * the factory */ EntityManagerImpl(final EntityManagerFactory factory, final PersistenceUnitTransactionType transactionType, final PersistenceContextType persistenceContextType) { this.factory = factory; if (logger.isDebugEnabled()) { logger.debug("Creating EntityManager for persistence unit : " + getPersistenceUnit()); } this.persistenceContextType = persistenceContextType; this.persistenceCache = new PersistenceCache((Cache) factory.getCache()); this.persistenceCache.setPersistenceContextType(this.persistenceContextType); this.transactionType = transactionType; this.persistenceDelegator = new PersistenceDelegator( ((EntityManagerFactoryImpl) this.factory).getKunderaMetadataInstance(), this.persistenceCache); for (String pu : ((EntityManagerFactoryImpl) this.factory).getPersistenceUnits()) { this.persistenceDelegator.loadClient(pu, discoverClient(pu)); } if (logger.isDebugEnabled()) { logger.debug("Created EntityManager for persistence unit : " + getPersistenceUnit()); } }
/** * Test method for * {@link com.impetus.kundera.lifecycle.states.ManagedState#handleRollback(com.impetus.kundera.lifecycle.NodeStateContext)} * . */ // @Test public void testHandleRollback() { // Extended pc.setPersistenceContextType(PersistenceContextType.EXTENDED); Node storeNode = StoreBuilder.buildStoreNode(pc, state, CascadeType.PERSIST); state.handleDetach(storeNode); Assert.assertEquals(TransientState.class, storeNode.getCurrentNodeState().getClass()); for (Node childNode : storeNode.getChildren().values()) { Assert.assertEquals(BillingCounter.class, childNode.getDataClass()); Assert.assertEquals(ManagedState.class, childNode.getCurrentNodeState().getClass()); } // Transactional pc.setPersistenceContextType(PersistenceContextType.TRANSACTION); storeNode = StoreBuilder.buildStoreNode(pc, state, CascadeType.PERSIST); state.handleDetach(storeNode); Assert.assertEquals(DetachedState.class, storeNode.getCurrentNodeState().getClass()); for (Node childNode : storeNode.getChildren().values()) { Assert.assertEquals(BillingCounter.class, childNode.getDataClass()); Assert.assertEquals(ManagedState.class, childNode.getCurrentNodeState().getClass()); } }
/** * Test method for * {@link com.impetus.kundera.lifecycle.states.RemovedState#handleRollback(com.impetus.kundera.lifecycle.NodeStateContext)} * . */ @Test public void testHandleRollback() { // Extended pc.setPersistenceContextType(PersistenceContextType.EXTENDED); Node storeNode = StoreBuilder.buildStoreNode(pc, state, CascadeType.PERSIST); state.handleRollback(storeNode); Assert.assertEquals(ManagedState.class, storeNode.getCurrentNodeState().getClass()); for (Node childNode : storeNode.getChildren().values()) { Assert.assertEquals(BillingCounter.class, childNode.getDataClass()); Assert.assertEquals(RemovedState.class, childNode.getCurrentNodeState().getClass()); } // Transactional pc.setPersistenceContextType(PersistenceContextType.TRANSACTION); storeNode = StoreBuilder.buildStoreNode(pc, state, CascadeType.PERSIST); state.handleRollback(storeNode); Assert.assertEquals(DetachedState.class, storeNode.getCurrentNodeState().getClass()); for (Node childNode : storeNode.getChildren().values()) { Assert.assertEquals(BillingCounter.class, childNode.getDataClass()); Assert.assertEquals(RemovedState.class, childNode.getCurrentNodeState().getClass()); } }