List of usage examples for org.hibernate StatelessSession close
void close();
From source file:org.squashtest.tm.service.internal.testcase.coercers.extenders.TestCaseLibraryExtender.java
License:Open Source License
@Override public Collection<? extends Serializable> doCoerce(Collection<? extends Serializable> ids) { StatelessSession s = hibernateStatelessSessionHelper.openStatelessSession(); Transaction tx = s.beginTransaction(); try {/*from ww w .j a v a 2 s . c o m*/ Query q = s.createQuery( "select distinct l.id from TestCaseLibrary l join l.rootContent c where c.id in (:tclnIds) "); q.setParameterList("tclnIds", ids); return q.list(); } finally { tx.commit(); s.close(); } }
From source file:org.squashtest.tm.service.internal.testcase.coercers.extenders.TestCaseLibraryNodePathEdgeExtender.java
License:Open Source License
@Override public Collection<? extends Serializable> doCoerce(Collection<? extends Serializable> coercedIds) { StatelessSession s = hibernateStatelessSessionHelper.openStatelessSession(); Transaction tx = s.beginTransaction(); try {//from www .j a v a2s. co m Query q = s.createQuery( "select distinct edge.ancestorId from TestCasePathEdge edge where edge.descendantId in (:tclnIds) and depth=1"); q.setParameterList("tclnIds", coercedIds); coercedIds.addAll(q.list()); return coercedIds; } finally { tx.commit(); s.close(); } }
From source file:vault.queryrouter.rewrite.impl.Test.java
License:Apache License
public static void main(String[] args) { StatelessSession session = factory.openStatelessSession(); UUID uuid = UUID.randomUUID(); try {/* w ww .j a v a2 s . com*/ while (true) { TenantUpdateJob pendingQuery = JobQueueDAO.getPendingQueryLock(session, uuid.toString()); // Thread.sleep(5000); } } catch (Exception e) { session.close(); logger.info("Exception:", e); } finally { } }
From source file:vault.queryrouter.servlet.TenantServiceAPI.java
License:Apache License
/*************************************************** * URL: /jsonservlet//from www. j av a 2 s . co m * doPost(): receives JSON data, parse it, map it and send back as JSON ****************************************************/ protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { /*************************************************** * URL: /jsonservlet/query ****************************************************/ if (request.getPathInfo().equals("/query")) { UUID queryId; QueryRequest queryRequest; StatelessSession session = factory.openStatelessSession(); try { //Convert received JSON to QueryRequest Object queryRequest = mapper.readValue(request.getInputStream(), QueryRequest.class); logger.info("connection id: " + queryRequest.getConnectionId()); //Obtain queryId for polling the query result queryId = manager.processQuery(session, queryRequest.getSql(), queryRequest.getMppdbId(), queryRequest.getUserId(), queryRequest.getTenantMppdbId(), queryRequest.getFileName(), queryRequest.getCommandType(), queryRequest.getConnectionId()); queryRequest.setQueryId(queryId.toString()); //Set response type to JSON response.setContentType("application/json"); //Send List<QueryRequest> as JSON to client mapper.writeValue(response.getOutputStream(), queryRequest); } catch (Exception e) { logger.error("Failed to process", e); response.setStatus(500); } finally { session.close(); } } /*************************************************** * URL: /jsonservlet/poll ****************************************************/ else if (request.getPathInfo().equals("/poll")) { String fileName; PollRequest pollRequest = null; StatelessSession session = factory.openStatelessSession(); response.setContentType("application/json"); try { pollRequest = mapper.readValue(request.getInputStream(), PollRequest.class); //Execution is finished if (manager.checkFinishExecution(session, pollRequest.getQueryId()) .equals(QueryLogStatus.Success.toString())) { fileName = manager.getResult(pollRequest.getQueryId()); pollRequest.setFileName(fileName); } // Execution is still processing else { pollRequest.setFileName(Constant.RETURN_PROCESSING_FILE_NAME); } //Set response type to JSON response.setContentType("application/json"); //Send List<QueryRequest> as JSON to client mapper.writeValue(response.getOutputStream(), pollRequest); } catch (Exception e) { logger.error("Failed to process", e); exceptionHandle(e, response); } finally { session.close(); } } /*************************************************** * URL: /jsonservlet/connection ****************************************************/ else if (request.getPathInfo().equals("/connection")) { ConnectionRequest connectionRequest = null; StatelessSession session = factory.openStatelessSession(); try { connectionRequest = mapper.readValue(request.getInputStream(), ConnectionRequest.class); String connection_id = ConnectionManager.getInstance().createConnection(session, connectionRequest); logger.debug(connection_id); connectionRequest.setConnectionId(connection_id); response.setContentType("application/json"); mapper.writeValue(response.getOutputStream(), connectionRequest); } catch (Exception e) { logger.error("Fail to connect DB connection", e); exceptionHandle(e, response); } finally { session.close(); } } /*************************************************** * URL: /jsonservlet/disconnection ****************************************************/ else if (request.getPathInfo().equals("/disconnection")) { ConnectionRequest connectionRequest = null; connectionRequest = mapper.readValue(request.getInputStream(), ConnectionRequest.class); //close the connection object try { ConnectionManager.getInstance().closeConnection(connectionRequest.getConnectionId()); } catch (Exception e) { logger.error("Fail to disconnect DB connection", e); exceptionHandle(e, response); } } }
From source file:vn.edu.vnu.uet.fit.model.GenericModel.java
public void create(T entity) throws JDBCException, Exception { StatelessSession session = HibernateUtil.getSessionFactory().openStatelessSession(); Transaction trans = session.getTransaction(); try {//w w w.ja va 2s . c o m trans.begin(); session.insert(entity); //session.save(entity); trans.commit(); } catch (JDBCException ex) { trans.rollback(); throw ex; } catch (Exception ex) { trans.rollback(); throw ex; } session.close(); }
From source file:vn.edu.vnu.uet.fit.model.GenericModel.java
public void update(T entity) throws JDBCException, Exception { StatelessSession session = HibernateUtil.getSessionFactory().openStatelessSession(); Transaction trans = session.getTransaction(); try {/* w ww.j av a 2s.c om*/ trans.begin(); session.update(entity); trans.commit(); } catch (JDBCException ex) { trans.rollback(); throw ex; } catch (Exception ex) { trans.rollback(); throw ex; } session.close(); }