protected void close(ResultSet rs) { try { rs.close(); } catch (SQLException e) { throw configuration.translate(e); } }
protected void close(Statement stmt) { try { stmt.close(); } catch (SQLException e) { throw configuration.translate(e); } }
@Override public void close() { try{ try { if (rs != null) { rs.close(); } } finally { if (stmt != null) { stmt.close(); } } }catch(SQLException e) { throw configuration.translate(e); } }
@Override public long count() { try { return unsafeCount(); } catch (SQLException e) { String error = "Caught " + e.getClass().getName(); logger.error(error, e); throw configuration.translate(e); } }
@Override public <R> R execute(final QuerydslCallable<R> callable) { try (Connection connection = dataSource.getConnection()) { return callable.call(connection, configuration); } catch (SQLException e) { throw configuration.translate(e); } } }
@Override public boolean hasNext() { if (next == null) { try { next = rs.next(); } catch (SQLException e) { close(); throw configuration.translate(e); } } return next; }
@Override public <R> R execute(final QuerydslCallable<R> callable) { try (Connection connection = dataSource.getConnection()) { return callable.call(connection, configuration); } catch (SQLException e) { throw configuration.translate(e); } } }
@Override public long execute() { PreparedStatement stmt = null; try { stmt = connection.prepareStatement(toString()); if (parameter != null) { stmt.setString(1, parameter); } return 1; } catch (SQLException e) { List<Object> bindings = parameter != null ? ImmutableList.<Object>of(parameter) : ImmutableList.of(); throw configuration.translate(queryString, bindings, e); } finally { if (stmt != null) { close(stmt); } } }
protected void setParameters(PreparedStatement stmt, List<?> objects, List<Path<?>> constantPaths, Map<ParamExpression<?>, ?> params) { if (objects.size() != constantPaths.size()) { throw new IllegalArgumentException("Expected " + objects.size() + " paths, but got " + constantPaths.size()); } for (int i = 0; i < objects.size(); i++) { Object o = objects.get(i); try { if (o instanceof ParamExpression) { if (!params.containsKey(o)) { throw new ParamNotSetException((ParamExpression<?>) o); } o = params.get(o); } set(stmt, constantPaths.get(i), i+1, o); } catch (SQLException e) { throw configuration.translate(e); } } }
/** * Set the parameters to the given PreparedStatement * * @param stmt preparedStatement to be populated * @param objects list of constants * @param constantPaths list of paths related to the constants * @param params map of param to value for param resolving */ protected void setParameters(PreparedStatement stmt, List<?> objects, List<Path<?>> constantPaths, Map<ParamExpression<?>, ?> params) { if (objects.size() != constantPaths.size()) { throw new IllegalArgumentException("Expected " + objects.size() + " paths, " + "but got " + constantPaths.size()); } for (int i = 0; i < objects.size(); i++) { Object o = objects.get(i); try { if (o instanceof ParamExpression) { if (!params.containsKey(o)) { throw new ParamNotSetException((ParamExpression<?>) o); } o = params.get(o); } configuration.set(stmt, constantPaths.get(i), i+1, o); } catch (SQLException e) { throw configuration.translate(e); } } }
@Override public void remove() { try { rs.deleteRow(); } catch (SQLException e) { close(); throw configuration.translate(e); } }
private <T> T executeWithKey(Class<T> type, @Nullable Path<T> path) { ResultSet rs = executeWithKeys(); try{ if (rs.next()) { return configuration.get(rs, path, 1, type); } else { return null; } } catch (SQLException e) { throw configuration.translate(e); }finally{ close(rs); } }
private <T> List<T> executeWithKeys(Class<T> type, @Nullable Path<T> path) { ResultSet rs = null; try{ rs = executeWithKeys(); List<T> rv = new ArrayList<T>(); while (rs.next()) { rv.add(configuration.get(rs, path, 1, type)); } return rv; } catch (SQLException e) { throw configuration.translate(e); }finally { if (rs != null) { close(rs); } reset(); } }
private <T> List<T> executeWithKeys(Class<T> type, @Nullable Path<T> path) { ResultSet rs = null; try { rs = executeWithKeys(); List<T> rv = new ArrayList<T>(); while (rs.next()) { rv.add(configuration.get(rs, path, 1, type)); } return rv; } catch (SQLException e) { throw configuration.translate(e); } finally { if (rs != null) { close(rs); } reset(); } }
private <T> T executeWithKey(Class<T> type, @Nullable Path<T> path) { ResultSet rs = null; try { rs = executeWithKeys(); if (rs.next()) { return configuration.get(rs, path, 1, type); } else { return null; } } catch (SQLException e) { throw configuration.translate(e); } finally { if (rs != null) { close(rs); } reset(); } }
@Override public T next() { if (hasNext()) { next = null; try { return produceNext(rs); } catch (SQLException e) { close(); throw configuration.translate(e); } catch (Exception e) { close(); throw new QueryException(e); } } else { throw new NoSuchElementException(); } }
throw configuration.translate(queryString, constants, e); } finally { if (stmt != null) {
throw configuration.translate(queryString, constants, e); } finally { if (stmt != null) {
throw configuration.translate(queryString, constants, e); } finally { if (stmt != null) {
throw configuration.translate(queryString, constants, e); } finally { if (stmt != null) {