]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/org.simantics.mapping/src/org/simantics/mapping/rule/instructions/ProfileRuleInstruction.java
Fixed all line endings of the repository
[simantics/platform.git] / bundles / org.simantics.mapping / src / org / simantics / mapping / rule / instructions / ProfileRuleInstruction.java
1 /*******************************************************************************
2  * Copyright (c) 2007, 2010 Association for Decentralized Information Management
3  * in Industry THTH ry.
4  * All rights reserved. This program and the accompanying materials
5  * are made available under the terms of the Eclipse Public License v1.0
6  * which accompanies this distribution, and is available at
7  * http://www.eclipse.org/legal/epl-v10.html
8  *
9  * Contributors:
10  *     VTT Technical Research Centre of Finland - initial API and implementation
11  *******************************************************************************/
12 package org.simantics.mapping.rule.instructions;
13
14 import gnu.trove.map.hash.TIntIntHashMap;
15 import gnu.trove.set.hash.TIntHashSet;
16
17 import org.simantics.db.ReadGraph;
18 import org.simantics.db.WriteGraph;
19 import org.simantics.db.exception.DatabaseException;
20 import org.simantics.layer0.utils.triggers.IModification;
21 import org.simantics.utils.threads.logger.ITask;
22 import org.simantics.utils.threads.logger.ThreadLogger;
23
24 public class ProfileRuleInstruction implements IRuleInstruction {
25
26         String name;
27         IRuleInstruction rule;          
28         
29         public ProfileRuleInstruction(String name, IRuleInstruction rule) {
30                 this.name = name;
31                 this.rule = rule;
32         }
33
34         @Override
35         public void collectVariables(TIntHashSet reads, TIntHashSet writes) {
36                 rule.collectVariables(reads, writes);           
37         }
38
39         @Override
40         public IModification execute(ReadGraph g, Object[] bindings) throws DatabaseException {
41                 ITask task = ThreadLogger.getInstance().begin(name+".execute");
42                 final IModification modi = rule.execute(g, bindings);
43                 task.finish();
44                 if(modi==null)
45                         return null;
46                 return new IModification() {
47
48                         @Override
49                         public void perform(WriteGraph g) throws DatabaseException {
50                                 ITask task = ThreadLogger.getInstance().begin(name + ".perform");
51                                 modi.perform(g);
52                                 task.finish();
53                         }
54                         
55                 };
56         }
57         
58         @Override
59         public void doExecute(WriteGraph g, Object[] bindings) throws DatabaseException {
60                 ITask task = ThreadLogger.getInstance().begin(name+".doExecute");
61                 rule.doExecute(g, bindings);            
62                 task.finish();
63         }
64
65         @Override
66         public void mapVariables(TIntIntHashMap map) {
67                 rule.mapVariables(map);         
68         }
69
70         @Override
71         public void toString(StringBuilder b, int indent) {
72                 rule.toString(b, indent);
73         }
74
75 }