import java.util.Stack;
import org.simantics.db.ReadGraph;
-import org.simantics.db.Session;
+import org.simantics.db.RequestProcessor;
import org.simantics.db.WriteGraph;
import org.simantics.db.common.request.ReadRequest;
import org.simantics.db.common.request.WriteRequest;
import org.simantics.objmap.graph.IMappingListener;
import org.simantics.utils.datastructures.MapSet;
import org.simantics.utils.datastructures.Pair;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
/**
* NodeMap implementation used with SCL scripts.
*/
public abstract class ScriptNodeMap<DBObject,E extends INode> implements NodeMap<DBObject,Object,E>, IMappingListener, NodeListener {
- private static final boolean DEBUG = false;
+ private static final Logger LOGGER = LoggerFactory.getLogger(ScriptNodeMap.class);
- protected Session session;
+ protected RequestProcessor session;
protected IMapping<DBObject,INode> mapping;
protected ParentNode<E> rootNode;
private boolean dirty = false;
- public ScriptNodeMap(Session session, IMapping<DBObject,INode> mapping, ParentNode<E> rootNode) {
+ public ScriptNodeMap(RequestProcessor session, IMapping<DBObject,INode> mapping, ParentNode<E> rootNode) {
this.session = session;
this.mapping = mapping;
this.rootNode = rootNode;
@SuppressWarnings("unchecked")
private void receiveAdd(E node, String id, boolean db) {
- if (DEBUG) System.out.println("receiveAdd " + debugString(node) + " " + id + " " + db);
+ if (LOGGER.isTraceEnabled()) LOGGER.trace("receiveAdd " + debugString(node) + " " + id + " " + db);
synchronized (syncMutex) {
for (Pair<E, String> n : added) {
if (n.first.equals(node))
@SuppressWarnings("unchecked")
private void receiveRemove(E node, String id, boolean db) {
- if (DEBUG) System.out.println("receiveRemove " + debugString(node) + " " + id + " " + db);
+ if (LOGGER.isTraceEnabled()) LOGGER.trace("receiveRemove " + debugString(node) + " " + id + " " + db);
synchronized (syncMutex) {
for (Pair<E, String> n : removed) {
if (n.first.equals(node))
}
private void receiveUpdate(E node, String id, boolean db) {
- if (DEBUG) System.out.println("receiveUpdate " + debugString(node) + " " + id + " " + db);
+ if (LOGGER.isTraceEnabled()) LOGGER.trace("receiveUpdate " + debugString(node) + " " + id + " " + db);
synchronized (syncMutex) {
// for (Pair<E, String> n : updated) {
// if (n.first.equals(node))
@Override
public void perform(WriteGraph graph) throws DatabaseException {
- if (DEBUG) System.out.println("Commit " + commitMessage);
+ if (LOGGER.isTraceEnabled()) LOGGER.trace("Commit " + commitMessage);
if (commitMessage != null) {
Layer0Utils.addCommentMetadata(graph, commitMessage);
graph.markUndoPoint();
protected void commit(WriteGraph graph) throws DatabaseException {
synchronized(syncMutex) {
- if (DEBUG) System.out.println("Commit");
+ if (LOGGER.isTraceEnabled()) LOGGER.trace("Commit");
graphUpdates = true;
mapping.updateDomain(graph);
graphUpdates = false;
clearDeletes();
- if (DEBUG) System.out.println("Commit done");
+ if (LOGGER.isTraceEnabled()) LOGGER.trace("Commit done");
}
}
public void domainModified() {
if (graphUpdates)
return;
- if (DEBUG)System.out.println("domainModified");
+ if (LOGGER.isTraceEnabled()) LOGGER.trace("domainModified");
// FIXME : this is called by IMapping id DB thread
dirty = true;
// session.asyncRequest(new ReadRequest() {
}
protected void reset(ReadGraph graph) throws MappingException {
- if (DEBUG) System.out.println("Reset");
+ if (LOGGER.isTraceEnabled()) LOGGER.trace("Reset");
synchronized (syncMutex) {
graphUpdates = true;
mapping.getRangeModified().clear();
}
protected void update(ReadGraph graph) throws DatabaseException {
- if (DEBUG) System.out.println("Graph update start");
+ if (LOGGER.isTraceEnabled()) LOGGER.trace("Graph update start");
synchronized (syncMutex) {
graphUpdates = true;
for (DBObject domainObject : mapping.getDomainModified()) {
//if (mapping.isRangeModified() && !runUndo) // FIXME : redo?
if (mapping.isRangeModified())
commit((String)null);
- if (DEBUG) System.out.println("Graph update done");
+ if (LOGGER.isTraceEnabled()) LOGGER.trace("Graph update done");
}
@Override
for (Pair<E, String> n : added) {
deleteUC.remove(n.first);
}
- if (DEBUG && deleteUC.size() > 0) {
- System.out.println("Delete sync");
+ if (LOGGER.isTraceEnabled() && deleteUC.size() > 0) {
+ LOGGER.trace("Delete sync");
for (E n : delete) {
- System.out.println(debugString(n));
+ LOGGER.trace(debugString(n));
}
}
delete.addAll(deleteUC);
*/
@SuppressWarnings("unused")
protected void clearDeletes() {
- if (DEBUG && delete.size() > 0) System.out.println("Delete");
+ if (LOGGER.isTraceEnabled() && delete.size() > 0) LOGGER.trace("Delete");
for (E n : delete) {
- if (DEBUG) System.out.println(debugString(n));
+ if (LOGGER.isTraceEnabled()) LOGGER.trace(debugString(n));
mapping.getRange().remove(n);
}
delete.clear();
@Override
public <T extends INode> void nodeAdded(ParentNode<T> node, INode child,
String rel) {
- if (DEBUG) System.out.println("Node added " + child + " parent " + node);
+ if (LOGGER.isTraceEnabled()) LOGGER.trace("Node added " + child + " parent " + node);
//receiveAdd((E)child, rel ,graphUpdates);
receiveAdd((E)child, rel ,graphModified.contains(node));
@Override
public <T extends INode> void nodeRemoved(ParentNode<T> node, INode child,
String rel) {
- if (DEBUG) System.out.println("Node removed " + child + " parent " + node);
+ if (LOGGER.isTraceEnabled()) LOGGER.trace("Node removed " + child + " parent " + node);
//receiveRemove((E)child, rel, graphUpdates);
receiveRemove((E)child, rel, graphModified.contains(node));