public byte[] loadByteArray(String dirName, String name) throws IOException { String fname = fname(dirName, name); if (logmon.isLoggable(BasicLevel.DEBUG)) logmon.log(BasicLevel.DEBUG, "DBTransaction, loadByteArray(" + fname + ")"); // Searchs in the log a new value for the object. Hashtable<String, DBOperation> log = perThreadContext.get().getLog(); DBOperation op = log.get(fname); if (op != null) { if (op.type == DBOperation.SAVE) { return op.value; } else if (op.type == DBOperation.DELETE) { // The object was deleted. return null; } } try { // Creating a statement lets us issue commands against the connection. Statement s = conn.createStatement(); // ResultSet rs = s.executeQuery("SELECT content FROM " + dbtable + " WHERE name='" + name + "'"); if (!rs.next()) return null; byte[] content = rs.getBytes(1); rs.close(); s.close(); return content; } catch (SQLException sqle) { throw new IOException(sqle.getMessage()); } }
public void initRepository() throws IOException { initDB(); try { insertStmt = conn.prepareStatement("INSERT INTO JoramDB VALUES (?, ?)"); updateStmt = conn.prepareStatement("UPDATE JoramDB SET content=? WHERE name=?"); deleteStmt = conn.prepareStatement("DELETE FROM JoramDB WHERE name=?"); } catch (SQLException sqle) { sqle.printStackTrace(); throw new IOException(sqle.getMessage()); } }
public byte[] loadByteArray(String dirName, String name) throws IOException { String fname = fname(dirName, name); if (logmon.isLoggable(BasicLevel.DEBUG)) logmon.log(BasicLevel.DEBUG, "DBTransaction, loadByteArray(" + fname + ")"); // Searchs in the log a new value for the object. Hashtable log = ((Context) perThreadContext.get()).getLog(); DBOperation op = (DBOperation) log.get(fname); if (op != null) { if (op.type == DBOperation.SAVE) { return op.value; } else if (op.type == DBOperation.DELETE) { // The object was deleted. return null; } } try { // Creating a statement lets us issue commands against the connection. Statement s = conn.createStatement(); // ResultSet rs = s.executeQuery("SELECT content FROM JoramDB WHERE name='" + name + "'"); if (!rs.next()) return null; byte[] content = rs.getBytes(1); rs.close(); s.close(); return content; } catch (SQLException sqle) { throw new IOException(sqle.getMessage()); } }
public void initRepository() throws IOException { dbtable = AgentServer.getProperty(TABLE_NAME_PROP, DFLT_TABLE_PREFIX + AgentServer.getServerId()); initDB(); try { insertStmt = conn.prepareStatement("INSERT INTO " + dbtable + " VALUES (?, ?)"); updateStmt = conn.prepareStatement("UPDATE " + dbtable + " SET content=? WHERE name=?"); deleteStmt = conn.prepareStatement("DELETE FROM " + dbtable + " WHERE name=?"); } catch (SQLException sqle) { sqle.printStackTrace(); throw new IOException(sqle.getMessage()); } }
public void delete(String dirName, String name) { String fname = fname(dirName, name); if (logmon.isLoggable(BasicLevel.DEBUG)) logmon.log(BasicLevel.DEBUG, "DBTransaction, delete(" + fname + ")"); Hashtable log = ((Context) perThreadContext.get()).getLog(); DBOperation op = DBOperation.alloc(DBOperation.DELETE, fname); op = (DBOperation) log.put(fname, op); if (op != null) op.free(); }
public void delete(String dirName, String name) { String fname = fname(dirName, name); if (logmon.isLoggable(BasicLevel.DEBUG)) logmon.log(BasicLevel.DEBUG, "DBTransaction, delete(" + fname + ")"); Hashtable<String, DBOperation> log = perThreadContext.get().getLog(); DBOperation op = DBOperation.alloc(DBOperation.DELETE, fname); op = log.put(fname, op); if (op != null) op.free(); }
protected final void saveInLog(byte[] buf, String dirName, String name, Hashtable log, boolean copy, boolean first) throws IOException { String fname = fname(dirName, name); if (logmon.isLoggable(BasicLevel.DEBUG)) logmon.log(BasicLevel.DEBUG, "DBTransaction, saveInLog(" + fname + ", " + copy + ", " + first + ")"); DBOperation op = DBOperation.alloc(DBOperation.SAVE, fname, buf); DBOperation old = (DBOperation) log.put(fname, op); if (copy) { if ((old != null) && (old.type == DBOperation.SAVE) && (old.value.length == buf.length)) { // reuse old buffer op.value = old.value; } else { // alloc a new one op.value = new byte[buf.length]; } System.arraycopy(buf, 0, op.value, 0, buf.length); } if (old != null) old.free(); }
protected final void saveInLog(byte[] buf, String dirName, String name, Hashtable log, boolean copy, boolean first) throws IOException { String fname = fname(dirName, name); if (logmon.isLoggable(BasicLevel.DEBUG)) logmon.log(BasicLevel.DEBUG, "DBTransaction, saveInLog(" + fname + ", " + copy + ", " + first + ")"); DBOperation op = DBOperation.alloc(DBOperation.SAVE, fname, buf); DBOperation old = (DBOperation) log.put(fname, op); if (copy) { if ((old != null) && (old.type == DBOperation.SAVE) && (old.value.length == buf.length)) { // reuse old buffer op.value = old.value; } else { // alloc a new one op.value = new byte[buf.length]; } System.arraycopy(buf, 0, op.value, 0, buf.length); } if (old != null) old.free(); }