/** * Gets Hibernate session. * * @param tx Cache transaction. * @return Session. */ Session session(@Nullable GridCacheTx tx) { Session ses; if (tx != null) { ses = tx.meta(ATTR_SES); if (ses == null) { ses = sesFactory.openSession(); ses.beginTransaction(); // Store session in transaction metadata, so it can be accessed // for other operations on the same transaction. tx.addMeta(ATTR_SES, ses); if (log.isDebugEnabled()) log.debug("Hibernate session open [ses=" + ses + ", tx=" + tx.xid() + "]"); } } else { ses = sesFactory.openSession(); ses.beginTransaction(); } return ses; }
/** {@inheritDoc} */ @Override public void onSessionStart(CacheStoreSession ses) { if (ses.attachment() == null) { try { Session hibSes = sesFactory.openSession(); ses.attach(hibSes); if (ses.isWithinTransaction()) hibSes.beginTransaction(); } catch (HibernateException e) { throw new CacheWriterException( "Failed to start store session [tx=" + ses.transaction() + ']', e); } } }
/** {@inheritDoc} */ @Override public void stop() throws IgniteException { if (closeSesOnStop && sesFactory != null && !sesFactory.isClosed()) sesFactory.close(); }
// main ..........(SL: now renamed)................................................. public void start() { // EditorServer server ; // // if(args.length == 1) // server = new EditorServer(args[0], "No Name", "No Description") ; // else // server = new EditorServer(null, args[0], args[1]) ; // final EditorServer self = server ; Session editorSession = null; this.textChannel = null; this.textChannelConsumer = null; URLString url = null; String sessionType = null; String hostname = null; int hostport = 0; if (EditorServer_Debug) System.err.println("EditorServer: main."); hostname = "localhost"; hostport = 4461; sessionType = "socket"; url = URLString.createSessionURL(hostname, hostport, sessionType, sessionName); if (EditorServer_Debug) System.err.println("EditorServer: main: url: " + url.toString()); try { /* Registry running? Start it if it isn't. */ if (RegistryFactory.registryExists(sessionType) == false) { RegistryFactory.startRegistry(sessionType); } /* Create a session, [re]bind it and create a channel. */ this.client = new NetworkedClient("Server"); editorSession = SessionFactory.createSession(this.client, url, true); // setup text channel this.textChannel = editorSession.createChannel(this.client, "TextChannel", true, true, true); this.textChannelConsumer = new TextChannelConsumer(this); this.textChannel.addConsumer(this.client, this.textChannelConsumer); // setup client channel this.clientChannel = editorSession.createChannel(this.client, "ClientChannel", true, true, true); this.clientChannelConsumer = new ClientChannelConsumer(this); this.clientChannel.addConsumer(this.client, this.clientChannelConsumer); this.clientChannel.addChannelListener( new ChannelAdaptor() { public void channelConsumerAdded(ChannelEvent event) { self.clientAppeared(); } }); System.err.println("Setup and bound Editor server."); } catch (JSDTException e) { System.err.println("EditorServer: main: shared data exception: " + e); if (EditorServer_Debug) { e.printStackTrace(); } } this.pack(); // on Linux, this seems to be the only way to set JFrame sizes // (i.e. resize it after packing (which seems to defeat the // purpose of packing)!) this.setSize(new Dimension(800, 600)); this.setVisible(true); }