]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/org.simantics.db.testing/src/org/simantics/db/testing/common/WriteQuery.java
Added missing org.simantics.db.{tests,testing} plug-ins.
[simantics/platform.git] / bundles / org.simantics.db.testing / src / org / simantics / db / testing / common / WriteQuery.java
1 package org.simantics.db.testing.common;
2
3 import org.simantics.db.WriteGraph;
4 import org.simantics.db.common.request.WriteRequest;
5 import org.simantics.db.exception.DatabaseException;
6
7 public abstract class WriteQuery extends WriteRequest {
8         
9         /**
10          * 
11          */
12         private final TestBase testBase;
13
14         /**
15          * @param testBase
16          */
17         public WriteQuery(TestBase testBase) {
18                 this.testBase = testBase;
19         }
20
21         /**
22          * Since some SimpleGraphRequest can only handle Exceptions, we need to wrap other Throwables inside Exceptions
23          * @throws Exception 
24          */
25         @Override
26         public final void perform(WriteGraph g) throws DatabaseException {
27                 try {
28                         run(g);
29                 } catch(Throwable t) {
30             new Exception().printStackTrace();
31                         t.printStackTrace();
32                 if (null == this.testBase.exception2)
33                         this.testBase.exception2 = t;
34                 if (t instanceof Exception)
35                         throw new DatabaseException(t);
36                 throw new DatabaseException("Wrapping thrown non exception to exception.", t);
37                 }
38         }
39         
40         public abstract void run(WriteGraph g) throws Throwable;
41         
42 }