/** * Disconnect a pre-existing Hibernate Session on transaction completion, * returning its database connection but preserving its entity state. * <p>The default implementation simply calls {@link Session#disconnect()}. * Subclasses may override this with a no-op or with fine-tuned disconnection logic. * @param session the Hibernate Session to disconnect * @see Session#disconnect() */ protected void disconnectOnCompletion(Session session) { session.disconnect(); }
/** * Disconnect a pre-existing Hibernate Session on transaction completion, * returning its database connection but preserving its entity state. * <p>The default implementation simply calls {@link Session#disconnect()}. * Subclasses may override this with a no-op or with fine-tuned disconnection logic. * @param session the Hibernate Session to disconnect * @see Session#disconnect() */ protected void disconnectOnCompletion(Session session) { session.disconnect(); }
@Override public void suspend() { if (this.holderActive) { TransactionSynchronizationManager.unbindResource(this.sessionFactory); // Eagerly disconnect the Session here, to make release mode "on_close" work on JBoss. getCurrentSession().disconnect(); } }
@Override public void suspend() { if (this.holderActive) { TransactionSynchronizationManager.unbindResource(this.sessionFactory); // Eagerly disconnect the Session here, to make release mode "on_close" work on JBoss. getCurrentSession().disconnect(); } }
session.disconnect(); } finally { channel.disconnect(); session.disconnect();
channel.disconnect(); System.out.println("Channel disconnected."); session.disconnect(); System.out.println("Host Session disconnected.");
@Override @SuppressWarnings("deprecation") public void beforeCompletion() { try { Session session = this.sessionHolder.getSession(); if (this.sessionHolder.getPreviousFlushMode() != null) { // In case of pre-bound Session, restore previous flush mode. session.setFlushMode(this.sessionHolder.getPreviousFlushMode()); } // Eagerly disconnect the Session here, to make release mode "on_close" work nicely. session.disconnect(); } finally { // Unbind at this point if it's a new Session... if (this.newSession) { TransactionSynchronizationManager.unbindResource(this.sessionFactory); this.holderActive = false; } } }
import com.jcraft.jsch.*; public class TestJSch { public static void main(String args[]) { JSch jsch = new JSch(); Session session = null; try { session = jsch.getSession("username", "127.0.0.1", 22); session.setConfig("StrictHostKeyChecking", "no"); session.setPassword("password"); session.connect(); Channel channel = session.openChannel("sftp"); channel.connect(); ChannelSftp sftpChannel = (ChannelSftp) channel; sftpChannel.get("remotefile.txt", "localfile.txt"); sftpChannel.exit(); session.disconnect(); } catch (JSchException e) { e.printStackTrace(); } catch (SftpException e) { e.printStackTrace(); } } }
Session session = null; Channel channel = null; try { JSch ssh = new JSch(); ssh.setKnownHosts("/path/of/known_hosts/file"); session = ssh.getSession("username", "host", 22); session.setPassword("password"); session.connect(); channel = session.openChannel("sftp"); channel.connect(); ChannelSftp sftp = (ChannelSftp) channel; sftp.put("/path/of/local/file", "/path/of/ftp/file"); } catch (JSchException e) { e.printStackTrace(); } catch (SftpException e) { e.printStackTrace(); } finally { if (channel != null) { channel.disconnect(); } if (session != null) { session.disconnect(); } }
session.disconnect();
@Override @SuppressWarnings("deprecation") public void beforeCompletion() { try { Session session = this.sessionHolder.getSession(); if (this.sessionHolder.getPreviousFlushMode() != null) { // In case of pre-bound Session, restore previous flush mode. session.setFlushMode(this.sessionHolder.getPreviousFlushMode()); } // Eagerly disconnect the Session here, to make release mode "on_close" work nicely. session.disconnect(); } finally { // Unbind at this point if it's a new Session... if (this.newSession) { TransactionSynchronizationManager.unbindResource(this.sessionFactory); this.holderActive = false; } } }
@Test @RequiresDialect(value = H2Dialect.class, comment = "this is more like a unit test") public void testUserProvidedConnection() throws Exception { ConnectionProvider dcp = ConnectionProviderBuilder.buildConnectionProvider(); Session s = sessionFactory().withOptions().connection( dcp.getConnection() ).openSession(); Transaction tx = s.beginTransaction(); s.createQuery( "from Fo" ).list(); tx.commit(); Connection c = s.disconnect(); assertTrue( c != null ); s.reconnect( c ); tx = s.beginTransaction(); s.createQuery( "from Fo" ).list(); tx.commit(); c.close(); }
s.disconnect(); SerializationHelper.deserialize( SerializationHelper.serialize(s) ); s.close();
txn2.commit(); s3.disconnect();
/** * Disconnect the session from its underlying JDBC connection. This is intended for use in cases * where the application has supplied the JDBC connection to the session and which require * long-sessions (aka, conversations). * <p> * It is considered an error to call this method on a session which was not opened by supplying * the JDBC connection and an exception will be thrown. * <p> * For non-user-supplied scenarios, normal transaction management already handles disconnection * and reconnection automatically. * * @return the application-supplied connection or {@code null} * @see #reconnect(Connection) */ Connection disconnect() { return getSession().disconnect(); }
session.disconnect();
public void paused(RequestContext context) { if (isPersistenceContext(context.getActiveFlow())) { Session session = getHibernateSession(context.getFlowExecutionContext().getActiveSession()); unbind(session); session.disconnect(); } }
JSch jsch = new JSch(); Session session = jsch.getSession(user, host); session.setConfig("StrictHostKeyChecking", "no"); session.setPassword(password); session.connect(timeout); Channel channel = session.openChannel("exec"); ChannelExec channelExec = (ChannelExec) channel; channelExec.setCommand(command); channel.connect(); // read channel.getInputStream() here if you want to capture the output channel.disconnect(); session.disconnect();
public void paused(RequestContext context) { if (isPersistenceContext(context.getActiveFlow())) { Session session = getHibernateSession(context.getFlowExecutionContext().getActiveSession()); unbind(session); session.disconnect(); } }