import java.io.PrintStream;
import java.lang.reflect.Array;
import java.lang.reflect.InvocationTargetException;
-import java.nio.BufferUnderflowException;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import org.simantics.databoard.util.binary.BinaryFile;
import org.simantics.databoard.util.binary.RandomAccessBinary;
import org.simantics.db.AsyncReadGraph;
+import org.simantics.db.ComputationalValue;
import org.simantics.db.DevelopmentKeys;
import org.simantics.db.ExternalValueSupport;
import org.simantics.db.ReadGraph;
import org.simantics.db.exception.ResourceNotFoundException;
import org.simantics.db.exception.ServiceException;
import org.simantics.db.exception.ValidationException;
-import org.simantics.db.impl.BlockingAsyncProcedure;
import org.simantics.db.impl.RelationContextImpl;
import org.simantics.db.impl.ResourceImpl;
import org.simantics.db.impl.internal.RandomAccessValueSupport;
assert (subject != null);
+ byte[] bytes = null;
try {
- byte[] bytes = processor.getValue(this, subject);
+ bytes = processor.getValue(this, subject);
if (bytes == null) throw new DoesNotContainValueException("No value for resource " + subject);
Serializer serializer = getSerializer(binding);
throw new DoesNotContainValueException(e);
- } catch (IOException e) {
-
- throw new ServiceException(e);
-
- } catch (DatabaseException e) {
-
- throw new ServiceException(e);
-
- } catch (BufferUnderflowException e) {
- // This is sometimes thrown when deserialize fails because wrong format.
- // For callers of this method this is just an service exception.
- throw new ServiceException(e);
- }
-
+ } catch (Throwable t) {
+ throw new ServiceException("Could not getValue for subject " + debugString(subject) + " and binding " + String.valueOf(binding) + " with bytes " + safeArrayToString(bytes), t);
+ }
}
@Override
}
- final private <T> void syncRequest(final AsyncRead<T> request, final AsyncReadProcedure<T> procedure) throws DatabaseException {
-
- assert (request != null);
-
- ListenerBase listener = getListenerBase(procedure);
- assert(listener == null);
-
- BlockingAsyncProcedure<T> ap = new BlockingAsyncProcedure<>(this, procedure, request);
-
- QueryCache.runnerAsyncReadEntry(this, request, parent, listener, ap, true);
-
- ap.get();
-
- }
-
@Override
public <T> T syncRequest(AsyncRead<T> request,
final SyncProcedure<T> procedure) throws DatabaseException {
// else
procedure.execute(graph, (T) obj);
- } catch (IOException e) {
- procedure.exception(graph, e);
- } catch (BufferUnderflowException e) {
- procedure.exception(graph, e);
} catch (Throwable t) {
- procedure.exception(graph, t);
+ procedure.exception(graph, new ServiceException("Could not forValue for subject " + debugString(resource) + " and binding " + String.valueOf(binding) + " with bytes " + safeArrayToString(result), t));
}
-
}
@Override
});
}
+
+ private static String safeArrayToString(byte[] a) {
+ if (a == null)
+ return "null";
+ int iMax = a.length - 1;
+ if (iMax == -1)
+ return "[]";
+
+ StringBuilder b = new StringBuilder();
+ b.append('[');
+ for (int i = 0; i < 100; i++) { // limit to first 100 items
+ b.append(a[i]);
+ if (i == iMax)
+ return b.append(']').toString();
+ b.append(", ");
+ }
+ return b.append(", ... (" + a.length + ")]").toString();
+ }
@Override
public <T> void forValue(Resource subject, Binding binding,
else
procedure.execute(graph, (T) obj);
- } catch (IOException e) {
- procedure.exception(graph, e);
- } catch (BufferUnderflowException e) {
- procedure.exception(graph, e);
} catch (Throwable t) {
- procedure.exception(graph, t);
+ procedure.exception(graph, new ServiceException("Could not forValue for subject " + debugString(resource) + " and binding " + String.valueOf(binding) + " with bytes " + safeArrayToString(result), t));
}
-
}
@Override
processor.schedule(new SessionTask(this) {
@Override
- public void run(int thread) {
+ public void run0(int thread) {
try {
final ListenerBase listener = getListenerBase(procedure);
QueryCache.runnerReadEntry(ReadGraphImpl.this, request, parent, listener, procedure, false);
processor.schedule(new SessionTask(this) {
@Override
- public void run(int thread) {
+ public void run0(int thread) {
try {
final ListenerBase listener = getListenerBase(procedure);
QueryCache.runnerAsyncReadEntry(ReadGraphImpl.this, request, parent, listener, procedure, false);
this.parentGraph = parentGraph;
this.parent = parent;
this.processor = support;
- this.asyncBarrier = new AsyncBarrierImpl(parentGraph != null ? parentGraph.asyncBarrier : null);
+ this.asyncBarrier = new AsyncBarrierImpl(parentGraph != null ? parentGraph.asyncBarrier : null, parent);
}
ReadGraphImpl(ReadGraphImpl graph, CacheEntry parent) {
return getValue(r, binding);
}
} else if(types.contains(L0.ExternalValue)) {
- try {
- return (T)ReflectionUtils.getValue(getURI(r)).getValue();
- } catch(ValueNotFoundException e) {
- throw new DatabaseException(e);
- } catch(ClassCastException e) {
- throw new DatabaseException(e);
+ ComputationalValue cv = syncRequest(new PossibleAdapter<ComputationalValue>(r, ComputationalValue.class), TransientCacheAsyncListener.instance());
+ if(cv != null) {
+ return cv.getValue(this, r);
+ } else {
+ // This should not even be possible since L0 defines an adapter for all values
+ try {
+ return (T)ReflectionUtils.getValue(getURI(r)).getValue();
+ } catch(ValueNotFoundException e) {
+ throw new DatabaseException(e);
+ } catch(ClassCastException e) {
+ throw new DatabaseException(e);
+ }
}
}
else {