private Session acquireAndBindSession() throws HibernateException { debug("Opening and binding session."); Session session = factory.openSession(); bindSession(session); return session; }
/** * delegates to {@link HibernateInterceptor} or manages sessions internally, * based on the type of service. */ public Object invoke(final MethodInvocation invocation) throws Throwable { Object obj = getThis(invocation); // Stateless; normal semantics. if (!StatefulServiceInterface.class.isAssignableFrom( obj.getClass())) { throw new InternalException( "Stateless service configured as stateful."); } // Stateful; let's get to work. debug("Performing action in stateful session."); return doStateful(invocation); }
private void resetThreadSession() { if (isSessionBoundToThread()) { debug("Session bound to thread. Resetting."); TransactionSynchronizationManager.unbindResource(factory); TransactionSynchronizationManager.bindResource(factory, DUMMY); } else { debug("Session not bound to thread. No need to reset."); } }
private SessionStatus newOrRestoredSession(MethodInvocation invocation) throws HibernateException { SessionStatus status = getStatus(invocation); Session previousSession = nullOrSessionBoundToThread(); if (!isCloseSession(invocation)) { previousSession.close(); Session currentSession = acquireAndBindSession(); status = new SessionStatus(currentSession); putStatus(invocation, status); debug("Binding and reconnecting session."); bindSession(status.session);
status = newOrRestoredSession(invocation); status.session.setFlushMode(FlushMode.COMMIT); if (isCloseSession(invocation)) { ctx.publishMessage(new RegisterServiceCleanupMessage(this, invocation.getThis()) { resetThreadSession(); } catch (Exception e) { log.error("Could not cleanup thread session.", e);
private SessionStatus getStatus(MethodInvocation invocation) { return __sessions.get(getThis(invocation)); }
public Object invoke(MethodInvocation arg0) throws Throwable { int d = depth.get().intValue(); if (d == 0) { sessions.cleanThread(); } Object result; d++; depth.set(d); try { result = arg0.proceed(); if (!StatefulServiceInterface.class.isAssignableFrom(arg0 .getThis().getClass())) { result = new ProxyCleanupFilter(acl, current) .filter(null, result); } } finally { d--; depth.set(d); } return result; } }
private void bindSession(Session session) { debug("Binding session to thread."); SessionHolder sessionHolder = new SessionHolder(session); sessionHolder.setTransaction(sessionHolder.getSession() .beginTransaction()); // FIXME TODO // If we reach this point, it's ok to bind the new SessionHolder, // however the DUMMY EmptySessionHolder may be present so unbind // just in case. if (TransactionSynchronizationManager.hasResource(factory)) { TransactionSynchronizationManager.unbindResource(factory); } TransactionSynchronizationManager.bindResource(factory, sessionHolder); if (!TransactionSynchronizationManager.isSynchronizationActive()) { throw new InternalException("Synchronization not active for " + "TransactionSynchronizationManager"); } }
protected void putStatus(MethodInvocation invocation, SessionStatus status) { __sessions.put(getThis(invocation), status); }
protected SessionStatus removeStatus(final MethodInvocation invocation) { return __sessions.remove(getThis(invocation)); }