public ConnectionTrace(DbConnection con) { id = con.getInstanceId(); time = System.currentTimeMillis(); stackTrace = Thread.currentThread().getStackTrace(); }
public DbConnectionProxy(DbPool pool, DbConnection instance) { if (traceCaller.value()) { this.pool = pool; pool.getStackTraces().put(MSystem.getObjectId(this), new ConnectionTrace(this)); // instance.setUsedTrace(createStackTrace); } this.instance = instance; log().t(id,"created",instance.getInstanceId()); }
@Override public void close() { if (instance == null) return; log().t(id,"close",instance.getInstanceId()); setUsed(false); // close of the proxy will free the connection if (traceCaller.value()) pool.getStackTraces().remove(MSystem.getObjectId(this)); }
@Override protected void finalize() throws Throwable { log().t(id,"finalized",instance.getInstanceId()); if (instance != null) { log().i(id,"final closed", instance.getInstanceId() ); ConnectionTrace trace = pool.getStackTraces().get(MSystem.getObjectId(this)); if (trace != null) trace.log(log()); setUsed(false); } if (traceCaller.value()) pool.getStackTraces().remove(MSystem.getObjectId(this)); super.finalize(); }
/** * Return the result of an select query. * * @param attributes * @return x * @throws Exception */ @Override public DbResult executeQuery(Map<String, Object> attributes) throws Exception { validateSth(); String query = this.query.execute(attributes); log().t(query); preparedSth = prepareStatement(attributes, sth, query); long start = System.currentTimeMillis(); try { ResultSet result = preparedSth == null ? sth.executeQuery(query) : preparedSth.executeQuery(); SqlAnalytics.trace(getConnection().getInstanceId(), original, query, start, null); return new JdbcResult(this, result ); } catch (Throwable t) { SqlAnalytics.trace(getConnection().getInstanceId(), original, query, start, t); log().e(query); throw t; } }
/** * Return the result of an update query. In the attributes InputStreams are allowed (blobs). * * @param attributes * @return x * @throws Exception */ @Override public int executeUpdate(Map<String, Object> attributes) throws Exception { validateSth(); String query = this.query.execute(attributes); log().t(query); preparedSth = prepareStatement(attributes, sth, query); long start = System.currentTimeMillis(); try { int result = preparedSth == null ? sth.executeUpdate(query) : preparedSth.executeUpdate(); SqlAnalytics.trace(getConnection().getInstanceId(), original, query, start, null); return result; } catch (Throwable t) { SqlAnalytics.trace(getConnection().getInstanceId(), original, query, start, t); log().e(query); throw t; } }
/** * Executes the given SQL statement, which may return multiple results. In this statement * InputStream as attribute values are allowed. * * @See Statement.execute * @param attributes * @return x * @throws Exception */ @Override public boolean execute(Map<String, Object> attributes) throws Exception { validateSth(); String query = this.query.execute(attributes); log().t(query); long start = System.currentTimeMillis(); try { preparedSth = prepareStatement(attributes, sth, query); boolean result = preparedSth == null ? sth.execute(query) : preparedSth.execute(); SqlAnalytics.trace(getConnection().getInstanceId(), original, query, start, null); return result; } catch (Throwable e) { SqlAnalytics.trace(getConnection().getInstanceId(), original, query, start, e); log().e(query); throw e; } }