Commit 48800409 authored by Nico Mack's avatar Nico Mack

Fixed minor issue with locking of nested equation. Fixed logging output

of SQLExecutor
parent 8dfaee8c
......@@ -99,8 +99,8 @@
<repository>
<id>Kenai</id>
<name>Kenai</name>
<url>https://svn.kenai.com/svn/javaoctave~maven-repository</url>
</repository>
<url>file:///Users/mack/.m2/repository</url>
</repository>
</repositories>
......
......@@ -93,11 +93,15 @@ public class Equation {
this.isolated = isolateIt;
}
public boolean isIsolated() {
return this.isolated;
}
/**
* Method called to evaluate the script of the equation with the variables provided by the
* mapping.
*/
public void evaluate() {
public synchronized void evaluate() {
LinkedHashSet<Variable<?>> dependentVariables;
String evaluationErrors;
......
......@@ -636,6 +636,8 @@ public class EquationSystemBuilder {
}
}
logger.info("Locking of nested Equations is {} for equation {}", (lockToNesting) ? "Enabled" : "Disabled", equationName); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
for (String identifier : equationResults.get(equationName)) {
if (dependentVariables.containsKey(identifier)) {
equationOutputs.add(dependentVariables.get(identifier));
......
......@@ -98,8 +98,8 @@ public class LinearEquationSystem extends System {
for (Equation equation : equations.values()) {
if (equation.catersTo(input.getSource())) {
if (LOGGER.isTraceEnabled()) {
LOGGER.trace("Equation {} triggered by variable {}...", equation.toString(), input.getSource().getName()); //$NON-NLS-1$
if (LOGGER.isInfoEnabled()) {
LOGGER.info("Equation {} triggered by variable {}...", equation.toString(), input.getSource().getName()); //$NON-NLS-1$
}
equation.evaluate();
}
......@@ -122,4 +122,10 @@ public class LinearEquationSystem extends System {
public ConcurrentHashMap<Mapping, Equation> getEquations() {
return equations;
}
@Override
public String toString() {
return this.equations.toString();
}
}
\ No newline at end of file
......@@ -25,6 +25,9 @@ import lu.list.itis.dkd.tui.cps.InputChangeListener;
import lu.list.itis.dkd.tui.cps.InputDriver;
import lu.list.itis.dkd.tui.cps.InputEvent;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.util.Vector;
/**
......@@ -40,6 +43,8 @@ public abstract class System implements InputDriver, InputChangeListener {
protected Vector<System> nestedSystems;
protected boolean lockSystemForNesting = true;
private static final Logger logger = LoggerFactory.getLogger(System.class.getSimpleName());
/**
* Constructor.
*/
......@@ -54,7 +59,12 @@ public abstract class System implements InputDriver, InputChangeListener {
* The {@link System} instance to add.
*/
public void nestSystem(System system) {
nestedSystems.add(system);
if (!nestedSystems.contains(system)) {
nestedSystems.add(system);
} else {
logger.trace("System {} is already known as a nested system!", system); //$NON-NLS-1$
}
}
/**
......@@ -66,11 +76,14 @@ public abstract class System implements InputDriver, InputChangeListener {
*/
@Override
public synchronized void inputChanged(InputEvent input) {
saveState();
for (System nestedSystem : nestedSystems) {
if (nestedSystem != null)
nestedSystem.saveState();
if (lockSystemForNesting) {
saveState();
for (System nestedSystem : nestedSystems) {
if (nestedSystem != null)
nestedSystem.saveState();
}
}
for (System nestedSystem : nestedSystems) {
......
......@@ -32,6 +32,8 @@ abstract public class Executor {
executionErrors.reset();
}
abstract public void resetContext();
@SuppressWarnings("unused")
public void resolve(List<Import> imports) {
LOGGER.warn("Imports not supported by Executor!"); //$NON-NLS-1$
......
......@@ -7,6 +7,8 @@ import org.slf4j.LoggerFactory;
import java.util.Properties;
import javax.script.Bindings;
import javax.script.ScriptContext;
import javax.script.ScriptEngine;
import javax.script.ScriptEngineManager;
import javax.script.ScriptException;
......@@ -61,4 +63,12 @@ public class JavascriptExecutor extends Executor {
}
return variable;
}
/** {@inheritDoc} */
@Override
public void resetContext() {
Bindings context = engine.getBindings(ScriptContext.ENGINE_SCOPE);
context.clear();
engine.setBindings(context, ScriptContext.ENGINE_SCOPE);
}
}
......@@ -74,4 +74,10 @@ public class OctaveExecutor extends Executor {
return variable;
}
/** {@inheritDoc} */
@Override
public void resetContext() {
// TODO figure out a way to clear engine context
}
}
......@@ -163,4 +163,10 @@ public class PythonExecutor extends Executor {
}
return variable;
}
/** {@inheritDoc} */
@Override
public void resetContext() {
// TODO figure out a way to clear engine context
}
}
......@@ -432,6 +432,11 @@ public class SqlExecutor extends Executor {
Object value = values[index];
vector.add(value);
}
if (LOGGER.isInfoEnabled()) {
LOGGER.info("Result <- {} = {}", variable.getName(), variable.getValue()); //$NON-NLS-1$
}
variable.suspendListenerNotification(false);
vector.notifyInputChangeListeners();
} else {
......@@ -441,16 +446,25 @@ public class SqlExecutor extends Executor {
// Column value is a scalar
if (columnValues.size() > 0) {
Object[] values = columnValues.get(0);
if (LOGGER.isInfoEnabled()) {
LOGGER.info("Result <- {} = {}", variable.getName(), values[index]); //$NON-NLS-1$
}
variable.setValueFromObject(values[index]);
} else {
LOGGER.info("Query returned no results!"); //$NON-NLS-1$
}
}
}
if (LOGGER.isInfoEnabled()) {
LOGGER.info("Result <- {} = {}", variable.getName(), variable.getValue()); //$NON-NLS-1$
}
return variable;
}
/** {@inheritDoc} */
@Override
public void resetContext() {
// TODO Auto-generated method stub
}
}
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