package org.simantics.db.common.procedure.adapter;
import org.simantics.db.ReadGraph;
+import org.simantics.db.exception.DatabaseException;
import org.simantics.db.procedure.SyncListener;
import org.slf4j.LoggerFactory;
public abstract class SyncListenerAdapter<T> implements SyncListener<T> {
@Override
- public void exception(ReadGraph graph, Throwable t) {
+ public void exception(ReadGraph graph, Throwable t) throws DatabaseException {
LoggerFactory.getLogger(getClass()).error("Failed to listen", t);
}
@Override
- public void execute(ReadGraph graph, T result) {
+ public void execute(ReadGraph graph, T result) throws DatabaseException {
}
@Override
import org.simantics.db.common.request.BinaryRead;
import org.simantics.db.common.request.DelayedWriteRequest;
import org.simantics.db.common.request.ReadRequest;
+import org.simantics.db.common.request.UnaryRead;
import org.simantics.db.common.request.WriteRequest;
import org.simantics.db.common.request.WriteResultRequest;
import org.simantics.db.exception.DatabaseException;
}
- private static class Subquery implements Read<Object> {
- Function q;
+ private static class Subquery extends UnaryRead<Function, Object> {
public Subquery(Function q) {
- this.q = q;
+ super(q);
}
@Override
public Object perform(ReadGraph graph) throws DatabaseException {
- SCLContext sclContext = SCLContext.getCurrent();
- Object oldGraph = sclContext.put("graph", graph);
- try {
- return q.apply(Tuple0.INSTANCE);
- } catch (Throwable e) {
- if(e instanceof DatabaseException)
- throw (DatabaseException)e;
- else
- throw new DatabaseException(e);
- } finally {
- sclContext.put("graph", oldGraph);
- }
+ return Simantics.applySCLRead(graph, parameter, Tuple0.INSTANCE);
}
- @Override
- public int hashCode() {
- return q.hashCode();
- }
-
- @Override
- public boolean equals(Object obj) {
- if(this == obj)
- return true;
- if(obj == null || obj.getClass() != getClass())
- return false;
- Subquery other = (Subquery)obj;
- return q.equals(other.q);
- }
}
public static Object subquery(ReadGraph graph, Function q) throws DatabaseException {
public static void subqueryL(ReadGraph graph, Function query, Function executeCallback, Function1<Throwable, Tuple> exceptionCallback, Function1<Tuple0, Boolean> isDisposedCallback) throws DatabaseException {
graph.asyncRequest(new Subquery(query), new SyncListenerAdapter<Object>() {
-
@Override
- public void execute(ReadGraph graph, Object result) {
- executeCallback.apply(result);
+ public void execute(ReadGraph graph, Object result) throws DatabaseException {
+ Simantics.applySCLRead(graph, executeCallback, result);
}
@Override
- public void exception(ReadGraph graph, Throwable t) {
- exceptionCallback.apply(t);
+ public void exception(ReadGraph graph, Throwable t) throws DatabaseException {
+ Simantics.applySCLRead(graph, exceptionCallback, t);
}
@Override
import org.simantics.application.arguments.SimanticsArguments;
import org.simantics.db.ReadGraph;
import org.simantics.db.RequestProcessor;
-import org.simantics.db.RequestProcessorSpecific;
import org.simantics.db.Resource;
import org.simantics.db.Session;
import org.simantics.db.WriteGraph;
} catch (ValueNotFound e) {
throw new DatabaseException("SCL Value not found: " + e.name);
} catch (Throwable t) {
+ if (t instanceof DatabaseException)
+ throw (DatabaseException) t;
throw new DatabaseException(t);
}
}
- @SuppressWarnings({ "unchecked", "rawtypes" })
public static <T> T applySCL(String module, String function, ReadGraph graph, Object ... args) throws DatabaseException {
SCLContext sclContext = SCLContext.getCurrent();
Object oldGraph = sclContext.put("graph", graph);
try {
return (T)f.applyArray(args);
} catch (Throwable t) {
+ if (t instanceof DatabaseException)
+ throw (DatabaseException) t;
throw new DatabaseException(t);
} finally {
sclContext.put("graph", oldGraph);
try {
return (T)f.applyArray(args);
} catch (Throwable t) {
+ if (t instanceof DatabaseException)
+ throw (DatabaseException) t;
throw new DatabaseException(t);
} finally {
sclContext.put("graph", oldGraph);
try {
return function.apply(p0);
} catch (Throwable t) {
+ if (t instanceof DatabaseException)
+ throw (DatabaseException) t;
throw new DatabaseException(t);
} finally {
sclContext.put("graph", oldGraph);
try {
return function.apply(p0);
} catch (Throwable t) {
+ if (t instanceof DatabaseException)
+ throw (DatabaseException) t;
throw new DatabaseException(t);
} finally {
sclContext.put("graph", oldGraph);
try {
return function.apply(p0, p1);
} catch (Throwable t) {
+ if (t instanceof DatabaseException)
+ throw (DatabaseException) t;
throw new DatabaseException(t);
} finally {
sclContext.put("graph", oldGraph);