+
+ private static class Subquery implements Read<Object> {
+ Function q;
+
+ public Subquery(Function q) {
+ this.q = 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);
+ }
+ }
+
+ @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 {
+ return graph.syncRequest(new Subquery(q));
+ }
+
+ public static Object subqueryC(ReadGraph graph, Function q) throws DatabaseException {
+ return graph.syncRequest(new Subquery(q), TransientCacheAsyncListener.<Object>instance());
+ }
+
+ public static Object possibleFromDynamic(Type expectedType, String moduleName, Object value) {
+
+ try {
+
+
+ Failable<Module> failable = SCLOsgi.MODULE_REPOSITORY.getModule(moduleName);
+ Module module = failable.getResult();
+
+ RuntimeEnvironment env = SCLOsgi.MODULE_REPOSITORY.createRuntimeEnvironment(
+ EnvironmentSpecification.of(moduleName, ""), module.getParentClassLoader());
+
+ JavaTypeTranslator tr = new JavaTypeTranslator(env.getEnvironment());
+ TypeDesc desc = tr.toTypeDesc(expectedType);
+ String className = desc.getFullName();
+ Class<?> clazz = env.getMutableClassLoader().loadClass(className);
+ if (!clazz.isAssignableFrom(value.getClass()))
+ return null;
+
+ } catch (ImportFailureException | ClassNotFoundException e) {
+ }
+ return value;
+ }
+