Commit f1470f0c authored by Nico Mack's avatar Nico Mack

Minor changes to allow for insert and update queries to be used without

specifying results.
parent 8e7bd58d
......@@ -620,11 +620,16 @@ public class EquationSystemBuilder {
private void addResultDependencies(Element equation) throws EquationSystemException {
String equationName = this.getAttribute(equation, EquationSystemBundle.NAME_ATTRIBUTE);
List<Element> results = equation.getChild(EquationSystemBundle.RESULTS_ELEMENT).getChildren(EquationSystemBundle.RESULT_ELEMENT);
List<Declaration> declarations = new ArrayList<>();
HashMap<String, String> resultAttributes;
Element resultsNode = equation.getChild(EquationSystemBundle.RESULTS_ELEMENT);
if (resultsNode == null) {
equationResults.put(equationName, declarations);
return;
}
List<Element> results = resultsNode.getChildren(EquationSystemBundle.RESULT_ELEMENT);
for (Element result : results) {
resultAttributes = this.extractAttributesForVariables(result);
......
......@@ -49,29 +49,16 @@ import java.util.regex.Pattern;
*/
public class SqlExecutor extends Executor {
// private ComboPooledDataSource connectionPool;
private Map<String, Object> parameters;
// private String connectionUrl;
// private String driverClass;
// private String userName;
// private String password;
// private boolean autoCommit;
private List<Object[]> columnValues = null;
private List<Integer> columnTypes = null;
private List<String> columnNames = null;
// private static final String SQL_CONNECTION_URL = "sql.connection.url"; //$NON-NLS-1$
// private static final String SQL_DRIVER_CLASS = "sql.driver.class"; //$NON-NLS-1$
// private static final String SQL_USER_NAME = "sql.user.name"; //$NON-NLS-1$
// private static final String SQL_USER_PASSWORD = "sql.user.password"; //$NON-NLS-1$
// private static final String SQL_AUTO_COMMIT = "sql.autoCommit"; //$NON-NLS-1$
private static final Pattern SQL_VAR_PATTERN = Pattern.compile("([\\$@%])\\{([a-z0-9\\-_]+)\\}", Pattern.CASE_INSENSITIVE); //$NON-NLS-1$
private static final String SQL_PLACEHOLDER = "?"; //$NON-NLS-1$
private static final Logger LOGGER = LoggerFactory.getLogger(SqlExecutor.class.getSimpleName());
// private static final int MAX_CONNECTION_ATTEMPTS = 3;
private static HashMap<Class<?>, String> JavaToJdbcMapping = new HashMap<>();
static {
......@@ -97,14 +84,6 @@ public class SqlExecutor extends Executor {
super(properties);
this.parameters = new HashMap<>();
// connectionUrl = properties.getProperty(SQL_CONNECTION_URL);
// driverClass = properties.getProperty(SQL_DRIVER_CLASS);
// userName = properties.getProperty(SQL_USER_NAME);
// password = properties.getProperty(SQL_USER_PASSWORD);
// autoCommit = Boolean.parseBoolean(properties.getProperty(SQL_AUTO_COMMIT, "false"));
//
// connectionPool = this.setupConnectionPool();
}
// ---------------------------------------------------------------------------
......@@ -113,64 +92,6 @@ public class SqlExecutor extends Executor {
// ***************************************************************************
// ---------------------------------------------------------------------------
// private ComboPooledDataSource setupConnectionPool() {
// ComboPooledDataSource pool;
//
// pool = new ComboPooledDataSource();
// try {
// pool.setDriverClass(driverClass);
// pool.setJdbcUrl(connectionUrl);
// pool.setUser(userName);
// pool.setPassword(password);
// } catch (PropertyVetoException e) {
// LOGGER.error("Failed to setup connection pool for {} driver class!", driverClass); //$NON-NLS-1$
// }
// return pool;
// }
// ---------------------------------------------------------------------------
// private void tearDownConnectionPool(ComboPooledDataSource pool) {
// if (pool != null) {
// pool.close();
// LOGGER.info("Connection Pool successfully closed!"); //$NON-NLS-1$
// }
// }
// ---------------------------------------------------------------------------
// private Connection getConnectionFromPool() {
// Connection connection = null;
// int attempt = 0;
// int numberOfConnections = 0;
// do {
// try {
// connection = connectionPool.getConnection();
// connection.setAutoCommit(autoCommit);
// numberOfConnections = connectionPool.getNumConnections();
// } catch (SQLException p_Exception) {
// LOGGER.warn("Failed to acquire connection from Connection Pool for Datasource {}! Reconnection
// pool...", connectionUrl); //$NON-NLS-1$
// this.tearDownConnectionPool(connectionPool);
// connectionPool = this.setupConnectionPool();
// attempt++;
// }
// } while ((connection == null) && (attempt < MAX_CONNECTION_ATTEMPTS));
//
// if (attempt >= MAX_CONNECTION_ATTEMPTS) {
// LOGGER.error("Failed to acquire connection for {} attempts in a row. Giving up!",
// MAX_CONNECTION_ATTEMPTS); //$NON-NLS-1$
// return null;
// }
//
// LOGGER.info("Datasource {} currently has a pool of {} open connections!", connectionUrl,
// numberOfConnections); //$NON-NLS-1$
//
// return connection;
// }
// ---------------------------------------------------------------------------
private int appendPlaceholder(StringBuffer buffer, boolean positionalParameters, int positionalIndex) {
buffer.append(SQL_PLACEHOLDER);
if (positionalParameters)
......@@ -577,7 +498,6 @@ public class SqlExecutor extends Executor {
@Override
public boolean eval(String script) {
long elapsed = System.currentTimeMillis();
// Connection connection = this.getConnectionFromPool();
Connection connection = ((JdbcConnector) this.connector).getConnection();
List<String> variables = new ArrayList<String>();
String queryString = this.interpolate(script, variables, this.parameters, false);
......@@ -590,10 +510,13 @@ public class SqlExecutor extends Executor {
try {
query = connection.prepareStatement(queryString);
query = this.setStatementParameters(query, variables, this.parameters);
rows = query.executeQuery();
columnNames = this.getColumnNames(rows);
columnTypes = this.getColumnTypes(rows);
columnValues = this.convertResults(rows);
boolean generatedResults = query.execute();
if (generatedResults) {
rows = query.getResultSet();
columnNames = this.getColumnNames(rows);
columnTypes = this.getColumnTypes(rows);
columnValues = this.convertResults(rows);
}
elapsed = System.currentTimeMillis() - elapsed;
if (LOGGER.isInfoEnabled()) {
LOGGER.info("Eval took {} ms | {}", elapsed, script); //$NON-NLS-1$
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment