]> gerrit.simantics Code Review - simantics/3d.git/blobdiff - org.simantics.g3d/src/org/simantics/g3d/scl/ScriptNodeMap.java
Remove static DEBUG flags and use slf4j.Logger.trace()
[simantics/3d.git] / org.simantics.g3d / src / org / simantics / g3d / scl / ScriptNodeMap.java
index 3c1cd9f2cd235fed45870fed438ab23bfe97aed7..fc63fffc381cb2b5cb8da82d4ee349828496aa3d 100644 (file)
@@ -11,7 +11,7 @@ import java.util.Set;
 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;
@@ -27,6 +27,8 @@ import org.simantics.objmap.graph.IMapping;
 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.
@@ -44,9 +46,9 @@ import org.simantics.utils.datastructures.Pair;
  */
 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;
@@ -55,7 +57,7 @@ public abstract class ScriptNodeMap<DBObject,E extends INode> implements NodeMap
        
        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;
@@ -126,7 +128,7 @@ public abstract class ScriptNodeMap<DBObject,E extends INode> implements NodeMap
        
        @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))
@@ -143,7 +145,7 @@ public abstract class ScriptNodeMap<DBObject,E extends INode> implements NodeMap
        
        @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))
@@ -158,7 +160,7 @@ public abstract class ScriptNodeMap<DBObject,E extends INode> implements NodeMap
        }
        
        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))
@@ -190,7 +192,7 @@ public abstract class ScriptNodeMap<DBObject,E extends INode> implements NodeMap
                        
                        @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();
@@ -204,12 +206,12 @@ public abstract class ScriptNodeMap<DBObject,E extends INode> implements NodeMap
        
        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");
                }
        }
        
@@ -219,7 +221,7 @@ public abstract class ScriptNodeMap<DBObject,E extends INode> implements NodeMap
        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() {
@@ -234,7 +236,7 @@ public abstract class ScriptNodeMap<DBObject,E extends INode> implements NodeMap
        }
        
        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();
@@ -247,7 +249,7 @@ public abstract class ScriptNodeMap<DBObject,E extends INode> implements NodeMap
        }
        
        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()) {
@@ -267,7 +269,7 @@ public abstract class ScriptNodeMap<DBObject,E extends INode> implements NodeMap
                //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
@@ -324,10 +326,10 @@ public abstract class ScriptNodeMap<DBObject,E extends INode> implements NodeMap
                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);
@@ -339,9 +341,9 @@ public abstract class ScriptNodeMap<DBObject,E extends INode> implements NodeMap
         */
        @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();
@@ -512,7 +514,7 @@ public abstract class ScriptNodeMap<DBObject,E extends INode> implements NodeMap
        @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));
                
@@ -522,7 +524,7 @@ public abstract class ScriptNodeMap<DBObject,E extends INode> implements NodeMap
        @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));