-package org.simantics.db.common.utils;\r
-\r
-import java.lang.reflect.InvocationTargetException;\r
-\r
-import org.simantics.db.RequestProcessor;\r
-import org.simantics.db.Resource;\r
-import org.simantics.db.common.request.AdaptValue;\r
-import org.simantics.db.exception.DatabaseException;\r
-import org.simantics.scl.runtime.function.Function;\r
-\r
-public class Functions {\r
- \r
- private static DatabaseException findPossibleRootException(Throwable t) {\r
- if(t == null) return null;\r
- if(t instanceof DatabaseException) return (DatabaseException)t;\r
- if(t instanceof RuntimeException || t instanceof InvocationTargetException) {\r
- return findPossibleRootException(t.getCause());\r
- }\r
- return null;\r
- }\r
- \r
- public static <T> T exec(RequestProcessor rp, Resource function, Object ... parameters) throws DatabaseException {\r
- Object op = rp.syncRequest(new AdaptValue(function));\r
- try {\r
- return (T) ((Function)op).applyArray(parameters);\r
- } catch (RuntimeException e) {\r
- DatabaseException dte = findPossibleRootException(e);\r
- if(dte != null) throw dte;\r
- else throw new DatabaseException(e);\r
- }\r
- }\r
- \r
-}\r
+package org.simantics.db.common.utils;
+
+import java.lang.reflect.InvocationTargetException;
+
+import org.simantics.db.RequestProcessor;
+import org.simantics.db.Resource;
+import org.simantics.db.common.request.AdaptValue;
+import org.simantics.db.exception.DatabaseException;
+import org.simantics.scl.runtime.function.Function;
+
+public class Functions {
+
+ private static DatabaseException findPossibleRootException(Throwable t) {
+ if(t == null) return null;
+ if(t instanceof DatabaseException) return (DatabaseException)t;
+ if(t instanceof RuntimeException || t instanceof InvocationTargetException) {
+ return findPossibleRootException(t.getCause());
+ }
+ return null;
+ }
+
+ public static <T> T exec(RequestProcessor rp, Resource function, Object ... parameters) throws DatabaseException {
+ Object op = rp.syncRequest(new AdaptValue(function));
+ try {
+ return (T) ((Function)op).applyArray(parameters);
+ } catch (RuntimeException e) {
+ DatabaseException dte = findPossibleRootException(e);
+ if(dte != null) throw dte;
+ else throw new DatabaseException(e);
+ }
+ }
+
+}