/** * Wraps the given integral intermediate session with a new instance of DBSession. * @param intermediateSession an intermediate session to wrap. * @return new instance of DBSession. */ @NotNull public static DBLeasedSession wrap(@NotNull final IntegralIntermediateSession intermediateSession) { if (intermediateSession.isClosed()) throw new DBSessionIsClosedException("The session is closed."); return new BaseSession(intermediateSession); }
@Override public synchronized DBLeasedSession leaseSession() { final IntegralIntermediateSession interSession = instantiateIntermediateSession(); final BaseSession baseSession = new BaseSession(interSession); return new DBLeasedSessionWrapper(baseSession); }
@Override public <R> R inSession(final InSession<R> operation) { if (operation == null) throw new IllegalArgumentException("The operation is null"); if (!isConnected()) throw new DBIsNotConnected("Facade is not connected."); final R result; final IntegralIntermediateSession interSession = instantiateIntermediateSession(); try { final BaseSession session = new BaseSession(interSession); result = operation.run(session); session.closeRunners(); } finally { interSession.close(); } return result; }
@Override public void inSession(final InSessionNoResult operation) { if (operation == null) return; if (!isConnected()) throw new DBIsNotConnected("Facade is not connected."); final IntegralIntermediateSession interSession = instantiateIntermediateSession(); try { final BaseSession session = new BaseSession(interSession); operation.run(session); session.closeRunners(); } finally { interSession.close(); } }