/** * <p>existsObject.</p> * * @param con a {@link de.mhus.lib.sql.DbConnection} object. * @param keys an array of {@link java.lang.Object} objects. * @return a boolean. * @throws java.lang.Exception if any. */ public boolean existsObject(DbConnection con, Object[] keys) throws Exception { HashMap<String, Object> attributes = new HashMap<String, Object>(); int nr = 0; for (Object key : keys) { attributes.put(String.valueOf(nr), key); nr++; } DbResult ret = sqlPrimary.getStatement(con).executeQuery(attributes); if (!ret.next()) { ret.close(); return false; } ret.close(); return true; }
protected static PCaseInfo newPCase(DbResult res) throws Exception { PCaseInfo out = new PCaseInfo(UUID.fromString( res.getString("id_")), res.getString("uri_"), res.getString("name_"), toCaseState(res.getInt("state_")), res.getString("custom_"), res.getString("customer_"), res.getTimestamp("created_").getTime(), res.getTimestamp("modified_").getTime(), res.getInt("priority_"), res.getInt("score_"), new String[] { res.getString("index0_"), res.getString("index1_"), res.getString("index2_"), res.getString("index3_"), res.getString("index4_"), res.getString("index5_"), res.getString("index6_"), res.getString("index7_"), res.getString("index8_"), res.getString("index9_") }, res.getString("milestone_") ); return out; }
public void dumpCases() { try { DbConnection con = pool.getConnection(); MProperties prop = new MProperties(); DbStatement sta = con.createStatement("SELECT * FROM " + prefix + "_case_"); DbResult res = sta.executeQuery(prop); while(res.next()) { System.out.println("CASE:"); for (String name : res.getColumnNames()) if (!name.toLowerCase().equals("content_")) System.out.println(" " + name + ": " + res.getString(name)); } } catch (Exception e) { throw new RuntimeException(e); } }
return different(obj, res.getInt(name) ); else if (retDbType.equals(DbType.TYPE.LONG.name())) return different(obj, res.getLong(name) ); else if (retDbType.equals(DbType.TYPE.BOOL.name())) return different(obj, res.getBoolean(name) ); else if (retDbType.equals(DbType.TYPE.DATETIME.name())) { if (attribute.getType() == Date.class) return different(obj, res.getTimestamp(name) ); else return different(obj, new MDate( res.getTimestamp(name) ).toCalendar() ); } else if (retDbType.equals(DbType.TYPE.DOUBLE.name())) return different(obj, res.getDouble(name) ); else if (retDbType.equals(DbType.TYPE.FLOAT.name())) return different(obj, res.getFloat(name) ); else if (retDbType.equals(DbType.TYPE.STRING.name())) return different(obj, res.getString(name) ); else if (retDbType.equals(DbType.TYPE.UUID.name())) { String o = res.getString(name); if (o == null) return different(obj, (UUID)null ); InputStream st = res.getBinaryStream(name);
@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; }
public SqlResultNode(DbConnection con, DbResult res) throws Exception { this.con = con; this.res = res; hasNext = res.next(); }
@Override public synchronized void close() { if (res == null) return; try { res.close(); } catch (Exception e) {} con.close(); res = null; con = null; }
set(obj, res.getInt(name) ); else if (retDbType.equals(DbType.TYPE.LONG.name())) set(obj, res.getLong(name) ); else if (retDbType.equals(DbType.TYPE.BOOL.name())) set(obj, res.getBoolean(name) ); else if (retDbType.equals(DbType.TYPE.DATETIME.name())) { try { if (attribute.getType() == Date.class) set(obj, res.getTimestamp(name) ); else if (attribute.getType() == java.sql.Date.class) { Timestamp time = res.getTimestamp(name); set(obj, time == null ? null : new java.sql.Date( time.getTime() ) ); } else set(obj, new MDate( res.getTimestamp(name) ).toCalendar() ); } catch (java.sql.SQLException sqle) { set(obj, res.getDouble(name) ); else if (retDbType.equals(DbType.TYPE.BIGDECIMAL.name())) set(obj, res.getBigDecimal(name) ); else if (retDbType.equals(DbType.TYPE.FLOAT.name())) set(obj, res.getFloat(name) ); else if (retDbType.equals(DbType.TYPE.STRING.name()))
@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; }
public SqlResultCase(DbConnection con, DbResult res) throws Exception { this.con = con; this.res = res; hasNext = res.next(); }
@Override public synchronized void close() { if (res == null) return; try { res.close(); } catch (Exception e) {} con.close(); res = null; con = 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 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; }
protected static PNodeInfo newPNode(DbResult res) throws Exception { PNodeInfo out = new PNodeInfo( UUID.fromString(res.getString("id_")), UUID.fromString(res.getString("case_")), res.getString("name_"), res.getString("assigned_"), toNodeState(res.getInt("state_")), toNodeType(res.getInt("type_")), res.getString("uri_"), res.getString("custom_"), res.getString("customer_"), res.getTimestamp("created_").getTime(), res.getTimestamp("modified_").getTime(), res.getInt("priority_"), res.getInt("score_"), res.getString("actor_"), new String[] { res.getString("index0_"), res.getString("index1_"), res.getString("index2_"), res.getString("index3_"), res.getString("index4_"), res.getString("index5_"), res.getString("index6_"), res.getString("index7_"), res.getString("index8_"), res.getString("index9_")
public void dumpNodes() { try { DbConnection con = pool.getConnection(); MProperties prop = new MProperties(); DbStatement sta = con.createStatement("SELECT * FROM " + prefix + "_node_"); DbResult res = sta.executeQuery(prop); while(res.next()) { System.out.println("NODE:"); for (String name : res.getColumnNames()) if (!name.toLowerCase().equals("content_")) System.out.println(" " + name + ": " + res.getString(name)); } } catch (Exception e) { throw new RuntimeException(e); } }
@Override public PNodeInfo next() { if (res == null) return null; try { PNodeInfo out = newPNode(res); hasNext = res.next(); return out; } catch (Exception e) { throw new MRuntimeException(e); } } }
@Override public void close() { if (res != null) { try { res.close(); } catch (Exception e) { log().w(e); } res = null; next = null; hasNext = false; object = null; } if (con != null) { if (ownConnection) manager.getSchema().closeConnection(pool,con); con = null; } }
@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); } }