protected void closePreparedSth() { if (preparedSth != null) { xquery = null; try { preparedSth.close(); } catch (SQLException e) { log().t(e); } preparedSth = null; } }
@Override public void close() { closePreparedSth(); if (sth == null) return; try { if (sth!=null && !sth.isClosed()) { sth.close(); } } catch (Exception e) { log().i(e); } sth = null; }
/** * 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; } }
/** * 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; } }
/** * 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; } }