/** * Close the default connection given with getConnection(). * @param pool * * @param con */ public void closeConnection(DbPool pool, DbConnection con) { DbConnection c = (DbConnection) DbTransaction.getConnection(pool); if (c != null) return; con.close(); }
@Override public synchronized void close() { if (res == null) return; try { res.close(); } catch (Exception e) {} con.close(); res = null; con = null; }
@Override public synchronized void close() { if (res == null) return; try { res.close(); } catch (Exception e) {} con.close(); res = null; con = null; }
/** * {@inheritDoc} * * Close the pool and all connections. */ @Override public void close() { if (pool == null) return; log().t(getName(),"close"); synchronized (pool) { for (DbConnection con : pool) { con.close(); } pool = null; } }
@Override public PCaseInfo loadCaseInfo(UUID caseId) throws IOException { try { DbConnection con = pool.getConnection(); MProperties prop = new MProperties(); DbStatement sta = null; prop.put("id", caseId); sta = con.createStatement("SELECT "+CASE_COLUMNS+" FROM " + prefix + "_case_ WHERE id_=$id$"); DbResult res = sta.executeQuery(prop); if (!res.next()) { res.close(); con.close(); return null; } PCaseInfo out = newPCase(res); res.close(); con.close(); return out; } catch (Exception e) { throw new IOException(e); } }
@Override public boolean setNodeScope(UUID nodeId, int scope) throws IOException { try { DbConnection con = pool.getConnection(); MProperties prop = new MProperties(); DbStatement sta = null; prop.put("id", nodeId); prop.put("value", scope); sta = con.createStatement("UPDATE " + prefix + "_node_ SET scope_=$value$ WHERE id_=$id$"); int res = sta.executeUpdate(prop); con.close(); return res == 1; } catch (Exception e) { throw new IOException(e); } }
@Override public boolean setCasePriority(UUID caseId, int priority) throws IOException { try { DbConnection con = pool.getConnection(); MProperties prop = new MProperties(); DbStatement sta = null; prop.put("id", caseId); prop.put("value", priority); sta = con.createStatement("UPDATE " + prefix + "_case_ SET priority_=$value$ WHERE id_=$id$"); int res = sta.executeUpdate(prop); con.close(); return res == 1; } catch (Exception e) { throw new IOException(e); } }
@Override public boolean setNodePriority(UUID nodeId, int priority) throws IOException { try { DbConnection con = pool.getConnection(); MProperties prop = new MProperties(); DbStatement sta = null; prop.put("id", nodeId); prop.put("value", priority); sta = con.createStatement("UPDATE " + prefix + "_node_ SET priority_=$value$ WHERE id_=$id$"); int res = sta.executeUpdate(prop); con.close(); return res == 1; } catch (Exception e) { throw new IOException(e); } }
@Override public boolean setCaseScope(UUID caseId, int scope) throws IOException { try { DbConnection con = pool.getConnection(); MProperties prop = new MProperties(); DbStatement sta = null; prop.put("id", caseId); prop.put("value", scope); sta = con.createStatement("UPDATE " + prefix + "_case_ SET scope_=$value$ WHERE id_=$id$"); int res = sta.executeUpdate(prop); con.close(); return res == 1; } catch (Exception e) { throw new IOException(e); } }
public void init() { try { URL url = MSystem.locateResource(this, "SqlDbStorage.xml"); DbConnection con = pool.getConnection(); XmlConfigFile data = new XmlConfigFile(url.openStream()); data.setString("prefix", prefix); pool.getDialect().createStructure(data, con, null, false); con.close(); } catch (Exception e) { log().e(e); } }
@Override public PNodeInfo loadFlowNodeInfo(UUID nodeId) throws IOException { try { DbConnection con = pool.getConnection(); MProperties prop = new MProperties(); DbStatement sta = null; prop.put("id", nodeId); sta = con.createStatement("SELECT "+NODE_COLUMNS+" FROM " + prefix + "_node_ WHERE id_=$id$"); DbResult res = sta.executeQuery(prop); if (!res.next()) { res.close(); con.close(); return null; } PNodeInfo out = newPNode(res); res.close(); con.close(); return out; } catch (Exception e) { throw new IOException(e); } }
@Override public void deleteCaseAndFlowNodes(UUID id) throws IOException { try { DbConnection con = pool.getConnection(); MProperties prop = new MProperties(); prop.put("id", id); { DbStatement sta = con.createStatement("DELETE FROM " + prefix + "_case_ WHERE id_=$id$"); sta.execute(prop); } { DbStatement sta = con.createStatement("DELETE FROM " + prefix + "_node_ WHERE case_=$id$"); sta.execute(prop); } con.commit(); con.close(); } catch (Exception e) { throw new IOException(e); } }
con.close(); } catch (Exception e) { throw new IOException(e);
@Override public PEngine loadEngine() throws IOException, NotFoundException { PEngine engine = null; try { DbConnection con = pool.getConnection(); MProperties prop = new MProperties(); prop.put("id", "engine"); DbStatement sta = con.createStatement("SELECT content_ FROM " + prefix + "_engine_ WHERE id_=$id$"); DbResult res = sta.executeQuery(prop); if (res.next()) { InputStream in = res.getBinaryStream("content_"); engine = new PEngine(); engine.readExternal(new ObjectInputStream(in)); } res.close(); con.close(); } catch (Exception e) { throw new IOException(e); } if (engine == null) throw new NotFoundException("engine"); return engine; }
@Override public Result<PNodeInfo> getScheduledFlowNodes(STATE_NODE state, long scheduled) throws IOException { DbConnection con = null; try { con = pool.getConnection(); MProperties prop = new MProperties(); DbStatement sta = null; if (state == null) { prop.setLong("scheduled", scheduled); sta = con.createStatement("SELECT "+NODE_COLUMNS+" FROM " + prefix + "_node_ WHERE scheduled_ <= $scheduled$"); } else { prop.setLong("scheduled", scheduled); prop.put("state", state); sta = con.createStatement("SELECT "+NODE_COLUMNS+" FROM " + prefix + "_node_ WHERE state_=$state$ and scheduled_ <= $scheduled$"); } DbResult res = sta.executeQuery(prop); return new SqlResultNode(con,res); } catch (Exception e) { try { if (con != null) con.close(); } catch (Exception e2) {} throw new IOException(e); } }
@Override public PCase loadCase(UUID id) throws IOException, NotFoundException { PCase caze = null; try { DbConnection con = pool.getConnection(); MProperties prop = new MProperties(); prop.put("id", id); DbStatement sta = con.createStatement("SELECT content_ FROM " + prefix + "_case_ WHERE id_=$id$"); DbResult res = sta.executeQuery(prop); if (res.next()) { InputStream in = res.getBinaryStream("content_"); caze = new PCase(); caze.readExternal(new ObjectInputStream(in)); } res.close(); con.close(); } catch (Exception e) { throw new IOException(e); } if (caze == null) throw new NotFoundException("case",id); return caze; }
@Override public PNode loadFlowNode(UUID id) throws IOException, NotFoundException { PNode node = null; try { DbConnection con = pool.getConnection(); MProperties prop = new MProperties(); prop.put("id", id); DbStatement sta = con.createStatement("SELECT content_ FROM " + prefix + "_node_ WHERE id_=$id$"); DbResult res = sta.executeQuery(prop); if (res.next()) { InputStream in = res.getBinaryStream("content_"); node = new PNode(); try { node.readExternal(new ObjectInputStream(in)); } catch (java.io.EOFException eofe) { log().w(node,eofe); // most because of extended parameters } } res.close(); con.close(); } catch (Exception e) { throw new IOException(e); } if (node == null) throw new NotFoundException("node",id); return node; }
con.close(); } catch (MException t) { throw t;
try { if (myCon != null) myCon.close(); } catch (Throwable t) { log().w(query,alias,t);
con.close(); } catch (Exception e) { throw new IOException(e);