|
|
@ -179,6 +179,56 @@ public class SqlExecutor {
|
|
|
|
|
|
|
|
|
|
|
|
return queryResultBuilder.rows(rows).build();
|
|
|
|
return queryResultBuilder.rows(rows).build();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public static QueryResult executeUpdate(Connection conn, String sql, Object... parameters) throws SQLException {
|
|
|
|
|
|
|
|
log.trace("SQL: " + sql.trim());
|
|
|
|
|
|
|
|
String updateQuery = sql.replaceAll(";$", "").trim();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Cleanup
|
|
|
|
|
|
|
|
PreparedStatement stmt = conn.prepareStatement(updateQuery);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (parameters != null) {
|
|
|
|
|
|
|
|
int parameterIndex = 1;
|
|
|
|
|
|
|
|
for (Object object : parameters) {
|
|
|
|
|
|
|
|
if (object != null) {
|
|
|
|
|
|
|
|
if (object instanceof String) {
|
|
|
|
|
|
|
|
stmt.setString(parameterIndex, (String) object);
|
|
|
|
|
|
|
|
} else if (object instanceof Integer) {
|
|
|
|
|
|
|
|
stmt.setInt(parameterIndex, (Integer) object);
|
|
|
|
|
|
|
|
} else if (object instanceof Long) {
|
|
|
|
|
|
|
|
stmt.setLong(parameterIndex, (Long) object);
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
stmt.setString(parameterIndex, (String) object);
|
|
|
|
|
|
|
|
String message = String.format("Unhandled paramter type <%s>. Defaulting to String", object.getClass().getName());
|
|
|
|
|
|
|
|
log.warn(message);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
log.warn("parameter is null");
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
parameterIndex++;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
long affectedRows = 0L;
|
|
|
|
|
|
|
|
QueryResultBuilder queryResultBuilder = QueryResult.builder();
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
|
|
|
affectedRows = stmt.executeUpdate();
|
|
|
|
|
|
|
|
} catch (SQLException e) {
|
|
|
|
|
|
|
|
return queryResultBuilder //
|
|
|
|
|
|
|
|
.exception(e.getClass().getName()) //
|
|
|
|
|
|
|
|
.exceptionMessage(e.getMessage()) //
|
|
|
|
|
|
|
|
.build();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
|
|
|
handleUserErrors(conn, sql, stmt);
|
|
|
|
|
|
|
|
} catch (SqlExecutionException e) {
|
|
|
|
|
|
|
|
log.error(e.getMessage(), e);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return queryResultBuilder.userErrors(e.getUserErrors()).build();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return queryResultBuilder.affectedRows(affectedRows).build();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private static Vector<ColumnDefinition> getColumnDefinitions(ResultSetMetaData metaData) throws SQLException {
|
|
|
|
private static Vector<ColumnDefinition> getColumnDefinitions(ResultSetMetaData metaData) throws SQLException {
|
|
|
|
Vector<ColumnDefinition> columnDefinitions = new Vector<ColumnDefinition>();
|
|
|
|
Vector<ColumnDefinition> columnDefinitions = new Vector<ColumnDefinition>();
|
|
|
|