import org.simantics.db.common.procedure.wrapper.SyncToAsyncSetProcedure;
import org.simantics.db.common.request.AdaptValue;
import org.simantics.db.common.request.ResourceRead;
+import org.simantics.db.common.utils.Functions;
import org.simantics.db.common.utils.Logger;
import org.simantics.db.common.utils.NameUtils;
import org.simantics.db.common.validation.L0Validations;
import org.simantics.db.impl.procedure.ResultCallWrappedSingleQueryProcedure4;
import org.simantics.db.impl.query.CacheEntry;
import org.simantics.db.impl.query.QueryCache;
+import org.simantics.db.impl.query.QueryCacheBase;
import org.simantics.db.impl.query.QueryProcessor;
import org.simantics.db.impl.query.QuerySupport;
import org.simantics.db.impl.query.TripleIntProcedure;
import org.simantics.scl.compiler.types.exceptions.SCLTypeParseException;
import org.simantics.scl.reflection.ReflectionUtils;
import org.simantics.scl.reflection.ValueNotFoundException;
+import org.simantics.scl.runtime.function.Function1;
import org.simantics.scl.runtime.function.Function3;
import org.simantics.utils.DataContainer;
import org.simantics.utils.Development;
throw (DatabaseException) exception;
else
throw new DatabaseException(
- "Unexpected exception in ReadGraph.syncRequest(AsyncMultiRead)",
+ "Unexpected exception in ReadGraph.syncRequest(AsyncRead)",
exception);
}
}
final public <T> T syncRequest(final ExternalRead<T> request,
final Procedure<T> procedure) throws DatabaseException {
- assert (request != null);
-
- ListenerBase listener = getListenerBase(procedure);
-
- final DataContainer<Throwable> exception = new DataContainer<Throwable>();
- final DataContainer<T> result = new DataContainer<T>();
+ assert (request != null);
- processor.query(this, request, parent, new Procedure<T>() {
+ ListenerBase listener = procedure != null ? getListenerBase(procedure) : null;
+ return QueryCache.resultExternalReadEntry(this, request, parent, listener, procedure);
- @Override
- public void exception(Throwable throwable) {
- exception.set(throwable);
- procedure.exception(throwable);
- }
-
- @Override
- public void execute(T t) {
- result.set(t);
- procedure.execute(t);
- }
-
- }, listener);
+//
+// ListenerBase listener = getListenerBase(procedure);
+//
+// return QueryCache.resultExternalReadEntry(this, request, parent, listener, procedure);
+
+// assert (request != null);
+//
+// ListenerBase listener = getListenerBase(procedure);
+//
+// final DataContainer<Throwable> exception = new DataContainer<Throwable>();
+// final DataContainer<T> result = new DataContainer<T>();
+//
+// processor.query(this, request, parent, new Procedure<T>() {
+//
+// @Override
+// public void exception(Throwable throwable) {
+// exception.set(throwable);
+// procedure.exception(throwable);
+// }
+//
+// @Override
+// public void execute(T t) {
+// result.set(t);
+// procedure.execute(t);
+// }
+//
+// }, listener);
// }
//
// }
-
- Throwable t = exception.get();
- if (t != null) {
- if (t instanceof DatabaseException)
- throw (DatabaseException) t;
- else
- throw new DatabaseException(
- "Unexpected exception in ReadGraph.syncRequest(Read)",
- t);
- }
-
- return result.get();
+//
+// Throwable t = exception.get();
+// if (t != null) {
+// if (t instanceof DatabaseException)
+// throw (DatabaseException) t;
+// else
+// throw new DatabaseException(
+// "Unexpected exception in ReadGraph.syncRequest(Read)",
+// t);
+// }
+//
+// return result.get();
}
final public <T> void asyncRequest(final ExternalRead<T> request,
final Procedure<T> procedure) {
- assert (request != null);
- assert (procedure != null);
-
- ListenerBase listener = getListenerBase(procedure);
-
- if (parent != null || listener != null) {
-
- processor.query(this, request, parent, procedure, listener);
-
- } else {
-
- try {
+
+ assert (request != null);
+ assert (procedure != null);
- request.register(this, new Listener<T>() {
+ final ListenerBase listener = getListenerBase(procedure);
- @Override
- public void execute(T result) {
- procedure.execute(result);
- }
+ if (parent != null || listener != null) {
- @Override
- public void exception(Throwable t) {
- procedure.exception(t);
- }
+ try {
+ QueryCacheBase.resultExternalReadEntry(this, request, parent, listener, procedure);
+ //processor.query(this, request, parent, procedure,listener);
+ } catch (DatabaseException e) {
+ Logger.defaultLogError(e);
+ // This throwable has already been transferred to procedure at this point - do nothing about it
+ //
+ }
+
+ } else {
- @Override
- public String toString() {
- return "asyncRequest(PrimitiveRead) -> " + request;
- }
+ request.register(this, new Listener<T>() {
+ //
+ @Override
+ public void execute(T result) {
+ procedure.execute(result);
+ }
- @Override
- public boolean isDisposed() {
- return true;
- }
+ @Override
+ public void exception(Throwable t) {
+ procedure.exception(t);
+ }
- });
+ @Override
+ public String toString() {
+ return "asyncRequest(PrimitiveRead) -> " + request;
+ }
- } catch (Throwable t) {
+ @Override
+ public boolean isDisposed() {
+ return true;
+ }
- if (t instanceof DatabaseException)
- procedure.exception(t);
- else
- procedure
- .exception(new DatabaseException(
- "Unexpected exception in ReadGraph.asyncRequest(SingleAsyncRead, SingleProcedure)",
- t));
+ });
+
+// final ReadGraphImpl newGraph = newSync();
- }
+// try {
+//
+// T result = request.perform(this);
+//
+// try {
+// procedure.execute(this, result);
+// } catch (Throwable t) {
+// Logger.defaultLogError(t);
+// }
+//
+// } catch (Throwable t) {
+//
+// try {
+// procedure.exception(this, t);
+// } catch (Throwable t2) {
+// Logger.defaultLogError(t2);
+// }
+//
+// } finally {
+//
+// }
- }
+ }
+
+// assert (request != null);
+// assert (procedure != null);
+//
+// ListenerBase listener = getListenerBase(procedure);
+//
+// if (parent != null || listener != null) {
+//
+// processor.query(this, request, parent, procedure, listener);
+//
+// } else {
+//
+// try {
+//
+// request.register(this, new Listener<T>() {
+//
+// @Override
+// public void execute(T result) {
+// procedure.execute(result);
+// }
+//
+// @Override
+// public void exception(Throwable t) {
+// procedure.exception(t);
+// }
+//
+// @Override
+// public String toString() {
+// return "asyncRequest(PrimitiveRead) -> " + request;
+// }
+//
+// @Override
+// public boolean isDisposed() {
+// return true;
+// }
+//
+// });
+//
+// } catch (Throwable t) {
+//
+// if (t instanceof DatabaseException)
+// procedure.exception(t);
+// else
+// procedure
+// .exception(new DatabaseException(
+// "Unexpected exception in ReadGraph.asyncRequest(SingleAsyncRead, SingleProcedure)",
+// t));
+//
+// }
+//
+// }
}
return getValue(r);
}
}
+ else if(types.contains(L0.Function)) {
+ return Functions.exec(this, r, this, r, context);
+ }
else if(types.contains(L0.ExternalValue)) {
return (T)syncRequest(new AdaptValue(r), TransientCacheListener.<Object>instance());
}
return getVariantValue(r);
}
}
+ else if(types.contains(L0.Function)) {
+ Object value = Functions.exec(this, r, this, r, context);
+ try {
+ return new Variant(Bindings.OBJECT.getContentBinding(value), value);
+ } catch ( org.simantics.databoard.binding.error.BindingException e ) {
+ throw new BindingException( "No binding found for class " + value.getClass().getName(), e );
+ }
+ }
else if(types.contains(L0.ExternalValue)) {
Object value = syncRequest(new AdaptValue(r), TransientCacheListener.<Object>instance());
try {
} else {
return getValue(r, binding);
}
+ } else if(types.contains(L0.Function)) {
+ Object value = Functions.exec(this, r, this, r, context);
+ if(binding.isInstance(value)) return (T)value;
+ try {
+ Binding srcBinding = Bindings.OBJECT.getContentBinding(value);
+ return (T)Bindings.adapt(value, srcBinding, binding);
+ } catch(RuntimeException e) {
+ DatabaseException dte = findPossibleRootException(e);
+ if(dte != null) throw dte;
+ else throw new DatabaseException(e);
+ } catch (AdaptException e) {
+ throw new DatabaseException(e);
+ } catch (org.simantics.databoard.binding.error.BindingException e) {
+ throw new DatabaseException(e);
+ }
} else if(types.contains(L0.ExternalValue)) {
try {
ExternalValue ev = adapt(r, ExternalValue.class);
}
}
+ private static ThreadLocal<Boolean> syncGraph = new ThreadLocal<Boolean>() {
+ protected Boolean initialValue() {
+ return true;
+ }
+ };
+
@Override
public boolean setSynchronous(boolean value) {
- boolean old = processor.synch;
- processor.synch = value;
+ boolean old = getSynchronous();
+ syncGraph.set(value);
return old;
}
@Override
public boolean getSynchronous() {
- return processor.synch;
+ return syncGraph.get();
}
public void ensureLoaded(int resource) {