X-Git-Url: https://gerrit.simantics.org/r/gitweb?a=blobdiff_plain;f=org.simantics.interop.mapping%2Fsrc%2Forg%2Fsimantics%2Finterop%2Fmapping%2FMapper.java;h=063f8acdfc713379f547ab118f2c87a4e90767af;hb=HEAD;hp=3414d4d05f17aafada5b733579783ae245974865;hpb=45e54f2af73bfbe7c43e95c7fe7d8d3d8164a2cc;p=simantics%2Finterop.git diff --git a/org.simantics.interop.mapping/src/org/simantics/interop/mapping/Mapper.java b/org.simantics.interop.mapping/src/org/simantics/interop/mapping/Mapper.java index 3414d4d..063f8ac 100644 --- a/org.simantics.interop.mapping/src/org/simantics/interop/mapping/Mapper.java +++ b/org.simantics.interop.mapping/src/org/simantics/interop/mapping/Mapper.java @@ -17,7 +17,6 @@ import org.simantics.db.common.request.WriteRequest; import org.simantics.db.common.request.WriteResultRequest; import org.simantics.db.common.utils.NameUtils; import org.simantics.db.exception.DatabaseException; -import org.simantics.db.exception.ServiceException; import org.simantics.db.layer0.util.SessionGarbageCollection; import org.simantics.db.request.Read; import org.simantics.interop.mapping.data.GraphNode; @@ -27,6 +26,8 @@ import org.simantics.interop.mapping.data.ResourceIdentifiable; import org.simantics.ui.jobs.SessionGarbageCollectorJob; import org.simantics.utils.datastructures.MapList; import org.simantics.utils.datastructures.Pair; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; /** * @@ -34,7 +35,9 @@ import org.simantics.utils.datastructures.Pair; * */ public class Mapper { - + + private static final Logger LOGGER = LoggerFactory.getLogger(Mapper.class); + public static final boolean USE_SPLIT_TRANSACTIONS = false; // Split transactions public static int OBJECTS_PER_TRANSACTION = 5000; // number of objects handled per transaction (split mode) private static boolean SLEEP_BETWEEN_WRITES = false; // sleep between transactions (split mode) @@ -320,7 +323,7 @@ public class Mapper { - private void applyGenerations(WriteGraph graph, Collection> nodes, IProgressMonitor monitor) throws Exception { + protected void applyGenerations(WriteGraph graph, Collection> nodes, IProgressMonitor monitor) throws Exception { int size = nodes.size(); int count = 0; @@ -353,9 +356,11 @@ public class Mapper { for (GraphNode n : nodes) { MapList priRules = n.getHint(MappingHints.KEY_GENERATION_RULES); - List rules = priRules.getValues(stage); - for (GenerationRule r : rules) { - r.generate(graph, n); + if (priRules != null) { + List rules = priRules.getValues(stage); + for (GenerationRule r : rules) { + r.generate(graph, n); + } } monitor.subTask("Generating objects, stage " + stage + " : ("+ (++count) + "/" + size + ")"); @@ -368,7 +373,7 @@ public class Mapper { } } - private void applyConnections(WriteGraph g, Collection> nodes, IProgressMonitor monitor) throws Exception { + protected void applyConnections(WriteGraph g, Collection> nodes, IProgressMonitor monitor) throws Exception { int size = nodes.size(); int count = 0; @@ -396,7 +401,7 @@ public class Mapper { - private void initializeRules(Session session, VirtualGraph vg, final Resource model ) throws DatabaseException{ + protected void initializeRules(Session session, VirtualGraph vg, final Resource model ) throws DatabaseException{ session.syncRequest(new WriteRequest(vg) { @Override public void perform(WriteGraph g) throws DatabaseException { @@ -408,7 +413,7 @@ public class Mapper { } - private void collect(ReadGraph g) throws DatabaseException { + protected void collect(ReadGraph g) throws DatabaseException { if (vg != null) return; SessionGarbageCollection.gc(g, 0, -1); @@ -416,7 +421,7 @@ public class Mapper { int collect = 0; - private void collect2(ReadGraph g) throws DatabaseException { + protected void collect2(ReadGraph g) throws DatabaseException { if (vg != null) return; @@ -428,7 +433,7 @@ public class Mapper { } } - private void applyModifications(Session session, final Collection> nodes, final IProgressMonitor monitor) throws Exception { + protected void applyModifications(Session session, final Collection> nodes, final IProgressMonitor monitor) throws Exception { @@ -544,7 +549,7 @@ public class Mapper { }); } - private void applyGenerations(Session session, VirtualGraph vg, Collection> nodes, IProgressMonitor monitor) throws Exception { + protected void applyGenerations(Session session, VirtualGraph vg, Collection> nodes, IProgressMonitor monitor) throws Exception { int size = nodes.size(); int count = 0; @@ -677,7 +682,7 @@ public class Mapper { } } - private void applyConnections(Session session, VirtualGraph vg, Collection> nodes, IProgressMonitor monitor) throws Exception { + protected void applyConnections(Session session, VirtualGraph vg, Collection> nodes, IProgressMonitor monitor) throws Exception { int size = nodes.size(); int count = 0; @@ -729,7 +734,7 @@ public class Mapper { }); } - private void applyModifications(ReadGraph g, GraphNode n, Pair modRule, Collection> ruleModified) throws Exception { + protected void applyModifications(ReadGraph g, GraphNode n, Pair modRule, Collection> ruleModified) throws Exception { if (!n.isDisposed() && modRule.first.matches(g, n)) { // we have to check Collection> perRule = new ArrayList>(); perRule.add(n); @@ -737,13 +742,13 @@ public class Mapper { } } - private void applyConnections(WriteGraph g, GraphNode node) throws Exception { + protected void applyConnections(WriteGraph g, GraphNode node) throws Exception { for (Link link : node.getLinks()) { if (link.isMain()) { for (Pair r : connectionRules) { if (r.first.mathces(g, node, link.to(), link)) { - Logger.defaultLogInfo("Connecting " + getName(g, node.getData()) + " to " + getName(g, link.to().getData()) + " " + link.getName() + "/"+link.getInverseName()); + LOGGER.info("Connecting " + getName(g, node.getData()) + " to " + getName(g, link.to().getData()) + " " + link.getName() + "/"+link.getInverseName()); r.second.generate(g, node, link.to(), link); break; }