entityManager.getTransaction().begin(); UnitOfWork unitOfWork = (UnitOfWork)((JpaEntityManager)entityManager.getDelegate()).getActiveSession(); unitOfWork.beginEarlyTransaction(); Accessor accessor = unitOfWork.getAccessor(); accessor.incrementCallCount(unitOfWork.getParent()); accessor.decrementCallCount(); java.sql.Connection connection = accessor.getConnection(); ... entityManager.getTransaction().commit();
@Override @Nullable public Object beginTransaction(EntityManager entityManager, TransactionDefinition definition) throws PersistenceException, SQLException, TransactionException { if (definition.getIsolationLevel() != TransactionDefinition.ISOLATION_DEFAULT) { // Pass custom isolation level on to EclipseLink's DatabaseLogin configuration // (since Spring 4.1.2) UnitOfWork uow = entityManager.unwrap(UnitOfWork.class); uow.getLogin().setTransactionIsolation(definition.getIsolationLevel()); } entityManager.getTransaction().begin(); if (!definition.isReadOnly() && !this.lazyDatabaseTransaction) { // Begin an early transaction to force EclipseLink to get a JDBC Connection // so that Spring can manage transactions with JDBC as well as EclipseLink. entityManager.unwrap(UnitOfWork.class).beginEarlyTransaction(); } return null; }
public Collection detach(Collection entities) { UnitOfWork uow = ((org.eclipse.persistence.internal.sessions.AbstractSession)getSharedSession()).acquireNonSynchronizedUnitOfWork(null); Collection copies = uow.registerAllObjects(entities); uow.release(); return copies; }
/** * Build a detached copy using a one-off UnitOfWork. * This simulates creation of a copy through serialization when using a * remote session bean if this copy process is not done the user of this * helper would return the shared copy from the cache that should not be * modified. These detachment methods *MUST* be used for local session * beans where the returned objects can be modified by the client. * * @param entity an existing persistent entity * @return a copy of the entity for use in a local client that may make changes to it */ public Object detach(Object entity) { UnitOfWork uow = ((org.eclipse.persistence.internal.sessions.AbstractSession)getSharedSession()).acquireNonSynchronizedUnitOfWork(null); Object copy = uow.registerObject(entity); uow.release(); return copy; }
public CompassSession getCurrentCompassSession(Session session) { if (session.isUnitOfWork()) { Session parentSession = ((UnitOfWork) session).getParent(); CompassSessionHolder sessionHolder = sessionsHolders.get(parentSession); if (sessionHolder != null) { return sessionHolder.session; } else { return beginCompassSessionAndTx(parentSession).session; } } else { CompassSessionHolder sessionHolder = sessionsHolders.get(session); if (sessionHolder != null) { return sessionHolder.session; } else { return beginCompassSessionAndTx(session).session; } } }
uow.executeQuery(query); uow.mergeClone(instance); uow.commit(); return null;
query.addArgumentValue(invocation.getParameter(param.getName())); toBeDeleted = uow.executeQuery(query); } else { executeArguments.add(invocation.getParameter(argName)); toBeDeleted = uow.executeQuery(query, executeArguments); uow.deleteObject(toBeDeleted); uow.commit();
@Override public void preBeginTransaction(SessionEvent event) { try { UnitOfWork work = event.getSession().acquireUnitOfWork(); try { work.executeNonSelectingSQL("set names utf8mb4"); work.commit(); work = null; } finally { if (work != null) work.release(); } } catch (Exception ex) { log.error("UTF8MB4", ex); } } });
/** * Execute <tt>INSERT</tt> operation on the database * @param xrService parent <code>XRService</code> that owns this <code>Operation</code> * @param invocation contains runtime argument values to be bound to the list of * {@link Parameter}'s. * @return result - <code>null</code> as the underlying <tt>INSERT</tt> operation on * the database does not return a value. * * @see {@link Operation} */ @Override public Object invoke(XRServiceAdapter xrService, Invocation invocation) { Object instance = invocation.getParameters().toArray()[0]; UnitOfWork uow = xrService.getORSession().acquireUnitOfWork(); uow.registerNewObject(instance); uow.commit(); return null; } }
((UnitOfWork) session).release();
boolean shouldLoadResultIntoSelectionObject = false; if (session.isUnitOfWork()) { shouldLoadResultIntoSelectionObject = !((UnitOfWork)session).isObjectRegistered(entity); } else { shouldLoadResultIntoSelectionObject = !session.getIdentityMapAccessor().containsObjectInIdentityMap(entity);
public Collection detach(Collection entities) { UnitOfWork uow = ((org.eclipse.persistence.internal.sessions.AbstractSession)getSharedSession()).acquireNonSynchronizedUnitOfWork(null); Collection copies = uow.registerAllObjects(entities); uow.release(); return copies; }
/** * Build a detached copy using a one-off UnitOfWork. * This simulates creation of a copy through serialization when using a * remote session bean if this copy process is not done the user of this * helper would return the shared copy from the cache that should not be * modified. These detachment methods *MUST* be used for local session * beans where the returned objects can be modified by the client. * * @param entity an existing persistent entity * @return a copy of the entity for use in a local client that may make changes to it */ public Object detach(Object entity) { UnitOfWork uow = ((org.eclipse.persistence.internal.sessions.AbstractSession)getSharedSession()).acquireNonSynchronizedUnitOfWork(null); Object copy = uow.registerObject(entity); uow.release(); return copy; }
UnitOfWork uow = sharedSession.getActiveUnitOfWork(); if (uow != null) { return uow.getParent();
uow.executeQuery(query); uow.mergeClone(instance); uow.commit(); return null;
query.addArgumentValue(invocation.getParameter(param.getName())); toBeDeleted = uow.executeQuery(query); } else { executeArguments.add(invocation.getParameter(argName)); toBeDeleted = uow.executeQuery(query, executeArguments); uow.deleteObject(toBeDeleted); uow.commit();
/** * Execute <tt>INSERT</tt> operation on the database * @param xrService parent <code>XRService</code> that owns this <code>Operation</code> * @param invocation contains runtime argument values to be bound to the list of * {@link Parameter}'s. * @return result - <code>null</code> as the underlying <tt>INSERT</tt> operation on * the database does not return a value. * * @see Operation */ @Override public Object invoke(XRServiceAdapter xrService, Invocation invocation) { Object instance = invocation.getParameters().toArray()[0]; UnitOfWork uow = xrService.getORSession().acquireUnitOfWork(); uow.registerNewObject(instance); uow.commit(); return null; } }
shouldLoadResultIntoSelectionObject = !((UnitOfWork)session).isObjectRegistered(entity); } else { shouldLoadResultIntoSelectionObject = !session.getIdentityMapAccessor().containsObjectInIdentityMap(entity);
@Override @Nullable public Object beginTransaction(EntityManager entityManager, TransactionDefinition definition) throws PersistenceException, SQLException, TransactionException { if (definition.getIsolationLevel() != TransactionDefinition.ISOLATION_DEFAULT) { // Pass custom isolation level on to EclipseLink's DatabaseLogin configuration // (since Spring 4.1.2) UnitOfWork uow = entityManager.unwrap(UnitOfWork.class); uow.getLogin().setTransactionIsolation(definition.getIsolationLevel()); } entityManager.getTransaction().begin(); if (!definition.isReadOnly() && !this.lazyDatabaseTransaction) { // Begin an early transaction to force EclipseLink to get a JDBC Connection // so that Spring can manage transactions with JDBC as well as EclipseLink. entityManager.unwrap(UnitOfWork.class).beginEarlyTransaction(); } return null; }
public Collection detach(Collection entities) { UnitOfWork uow = ((org.eclipse.persistence.internal.sessions.AbstractSession)getSharedSession()).acquireNonSynchronizedUnitOfWork(null); Collection copies = uow.registerAllObjects(entities); uow.release(); return copies; }