package fi.vtt.simantics.procore.internal;
-import gnu.trove.set.hash.TIntHashSet;
-
import java.io.ByteArrayInputStream;
import java.io.InputStream;
import java.util.Collection;
import org.simantics.db.procore.cluster.ClusterSmall;
import org.simantics.db.service.SerialisationSupport;
import org.simantics.utils.DataContainer;
+import org.slf4j.LoggerFactory;
+
+import gnu.trove.set.hash.TIntHashSet;
public class QuerySupportImpl implements QuerySupport {
-
+
+ private static final org.slf4j.Logger LOGGER = LoggerFactory.getLogger(QuerySupportImpl.class);
+
final SessionImplSocket session;
final State state;
final ClusterTable clusterTable;
try {
return serializationSupport.getResource(id);
} catch (DatabaseException e) {
- e.printStackTrace();
+ // TODO: consider changing this method to throw something
+ LOGGER.error("getResource(" + id + ") failed", e);
}
return null;
}
// int suggestSchedule = graph.processor.processor.resourceThread(id);
// if(graph.callerThread == suggestSchedule) {
- procedure.execute(graph, new ResourceImpl(resourceSupport, id));
+ try {
+ procedure.execute(graph, new ResourceImpl(resourceSupport, id));
+ } catch (DatabaseException e) {
+ LOGGER.error("Unexpected exception while handling object", e);
+ }
// } else {
// graph.processor.processor.schedule(graph.callerThread, new SessionTask(suggestSchedule) {
//
}
}
- procedure.finished(graph);
+ try {
+ procedure.finished(graph);
+ } catch (DatabaseException e) {
+ LOGGER.error("Unexpected exception while handling objects", e);
+ }
// graph.dec();
return;
final ClusterImpl cluster = (ClusterImpl)clusterTable.getClusterByResourceKey(subject);
if(!cluster.isLoaded()) {
- cluster.load(session.clusterTranslator, new Runnable() {
-
- @Override
- public void run() {
- getObjects4(graph, subject, procedure);
- }
-
- });
+ try {
+ cluster.load();
+ } catch (DatabaseException e) {
+ LOGGER.error("Unexpected exception while handling objects", e);
+ }
+ getObjects4(graph, subject, procedure);
return;
}
for(TransientGraph g : virtualGraphServerSupport.providers) {
for (final int id : g.getObjects(subject, procedure.predicateKey)) {
+ try {
+ procedure.execute(graph, new ResourceImpl(resourceSupport, id));
+ } catch (DatabaseException e) {
+ LOGGER.error("Unexpected exception while handling objects", e);
+ }
+
+
// int suggestSchedule = graph.processor.processor.resourceThread(id);
// if(graph.callerThread == suggestSchedule) {
- procedure.execute(graph, new ResourceImpl(resourceSupport, id));
// } else {
// graph.processor.processor.schedule(graph.callerThread, new SessionTask(suggestSchedule) {
//
// int suggestSchedule = graph.processor.processor.resourceThread(id);
// if(graph.callerThread == suggestSchedule) {
- procedure.execute(graph, context, new ResourceImpl(resourceSupport, id));
+
+ try {
+ procedure.execute(graph, context, new ResourceImpl(resourceSupport, id));
+ } catch (DatabaseException e) {
+ LOGGER.error("Unexpected exception while handling objects", e);
+ }
+
+
+
// } else {
// graph.processor.processor.schedule(graph.callerThread, new SessionTask(suggestSchedule) {
//
}
}
- procedure.finished(graph, context);
+
+ try {
+ procedure.finished(graph, context);
+ } catch (DatabaseException e) {
+ LOGGER.error("Unexpected exception while handling objects", e);
+ }
+
+
// graph.dec();
return;
for (final int id : g.getObjects(subject, procedure.predicateKey)) {
// int suggestSchedule = graph.processor.processor.resourceThread(id);
// if(graph.callerThread == suggestSchedule) {
- procedure.execute(graph, context, new ResourceImpl(resourceSupport, id));
+ try {
+ procedure.execute(graph, context, new ResourceImpl(resourceSupport, id));
+ } catch (DatabaseException e) {
+ LOGGER.error("Unexpected exception while handling objects", e);
+ }
// } else {
// graph.processor.processor.schedule(graph.callerThread, new SessionTask(suggestSchedule) {
//
}
-// @Override
-// public void getSingleSuperrelation(ReadGraphImpl graph, final int subject, final AsyncProcedure<Resource> procedure) {
-//
-// // Do not process this information for virtual resources
-// if(subject < 0) {
-// procedure.execute(graph, null);
-// graph.state.barrier.dec();
-// return;
-// }
-//
-// final ClusterI cluster = clusterTable.getClusterByResourceKey(subject);
-// if (cluster == null)
-// System.out.println("null cluster: " + Integer.toString(subject, 16));
-//
-// assert (cluster != null);
-//
-// if(!cluster.isLoaded()) {
-//
-// procedure.execute(graph, null);
-// graph.state.barrier.dec();
-// return;
-//
-//// queryProvider2.requestCluster(callerThread, cluster.getClusterId(), new Callback<Integer>() {
-////
-//// @Override
-//// public void run(Integer i) {
-////
-//// queryProvider2.schedule(i, callerThread, new Runnable() {
-////
-//// @Override
-//// public void run() {
-////
-//// try {
-////
-//// ClusterI.CompleteTypeEnum type = cluster.getCompleteType(callerThread, subject, SessionImplSocket.this);
-//// if(ClusterI.CompleteTypeEnum.SubrelationOf == type) {
-//// int result = cluster.getCompleteObjectKey(callerThread, subject, SessionImplSocket.this);
-//// assert(result > 0);
-//// procedure.execute(graph, getResourceByKey(result));
-//// } else {
-//// procedure.execute(graph, null);
-//// }
-//// graph.state.barrier.dec();
-////
-//// } catch (DatabaseException e) {
-//// e.printStackTrace();
-//// }
-////
-//// }
-////
-//// });
-////
-//// }
-////
-//// });
-//
-// } else {
-//
-// try {
-//
-// ClusterI.CompleteTypeEnum type = cluster.getCompleteType(graph.callerThread, subject, clusterSupport);
-// if(ClusterI.CompleteTypeEnum.SubrelationOf == type) {
-// int result = cluster.getCompleteObjectKey(graph.callerThread, subject, clusterSupport);
-// assert(result > 0);
-// procedure.execute(graph, new ResourceImpl(resourceSupport, result));
-// } else {
-// procedure.execute(graph, null);
-// }
-// graph.state.barrier.dec();
-//
-// } catch (DatabaseException e) {
-// e.printStackTrace();
-// }
-//
-// }
-//
-//
-// }
-
-// @Override
-// public void getObjects2(final int callerThread, final int subject, final int predicate, final IntProcedure procedure) {
-// ensureLoaded(callerThread, subject, predicate, new Runnable() {
-//
-// @Override
-// public void run() {
-// safeGetObjects2(callerThread, subject, predicate, procedure);
-// }
-//
-// });
-// }
-
-// public void safeGetObjects2(final ReadGraphImpl graph, final int subject, final int predicate, final IntProcedure procedure) {
-//
-// assert (subject != 0);
-// assert (predicate != 0);
-//// System.out.println("getObjects2: s=" + subject + "p=" + predicate);
-// Collection<TransientGraph> providers = virtualGraphServerSupport.getVirtualGraphs(subject);
-// if (providers != null) {
-//
-// final TIntHashSet result = new TIntHashSet(16);
-//
-// for (VirtualGraph provider : providers) {
-//
-// for (int id : ((VirtualGraphImpl)provider).getObjects(subject, predicate)) {
-//
-// if (result.add(id)) {
-// procedure.execute(graph, id);
-// }
-//
-// }
-//
-// }
-//
-// if (subject < 0)
-// return;
-//
-// final ClusterI cluster = clusterTable.getClusterByResourceKey(subject);
-//
-// assert (testCluster(subject, cluster));
-//
-// // wheels within wheels
-// final ClusterI.ObjectProcedure<Object> proc = new ClusterI.ObjectProcedure<Object>() {
-//
-// @Override
-// public boolean execute(int callerThread, Object context, int object) {
-//
-// if (result.add(object)) {
-// procedure.execute(graph.newAsync(callerThread), object);
-// }
-//
-// return false; // continue looping
-//
-// }
-//
-// @Override
-// public boolean found() {
-// throw new UnsupportedOperationException();
-// }
-//
-// };
-//
-// try {
-// cluster.forObjects(graph.callerThread, subject, predicate, proc, null, clusterSupport);
-// } catch (DatabaseException e) {
-// Logger.defaultLogError(e);
-// } catch (Throwable t) {
-// Logger.defaultLogError(t);
-// t.printStackTrace();
-// }
-// return;
-//
-// }
-//
-// assert(subject > 0);
-//
-// final ClusterI cluster = clusterTable.getClusterByResourceKey(subject);
-//
-// assert (testCluster(subject, cluster));
-//
-// try {
-// cluster.forObjects(graph.callerThread, subject, predicate, new Wheels(procedure), null, clusterSupport);
-// } catch (DatabaseException e) {
-// Logger.defaultLogError(e);
-// } catch (Throwable t) {
-// t.printStackTrace();
-// Logger.defaultLogError(t);
-// }
-//
-// }
-
@Override
- public boolean getObjects(final ReadGraphImpl graph, final int subject, final int predicate, final IntProcedure procedure) {
+ public boolean getObjects(final ReadGraphImpl graph, final int subject, final int predicate, final IntProcedure procedure) throws DatabaseException {
assert (subject != 0);
assert (predicate != 0);
found.set(true);
if (result.add(object)) {
- procedure.execute(graph, object);
+ try {
+ procedure.execute(graph, object);
+ } catch (DatabaseException e) {
+ Logger.defaultLogError(e);
+ }
}
return false; // continue looping
@Override
public boolean execute(Object context, int object) {
- found = true;
- procedure.execute(graph, object);
-
- return false; // continue looping
+ found = true;
+ try {
+ procedure.execute(graph, object);
+ } catch (DatabaseException e) {
+ Logger.defaultLogError(e);
+ }
+ return false; // continue looping
- }
+ }
public boolean found() {
return found;
try {
cluster.forObjects(subject, predicate, proc, null, clusterSupport);
} catch (DatabaseException e) {
- e.printStackTrace();
+ Logger.defaultLogError(e);
}
// This happens if resource is bogus
catch (Throwable t) {
}
-// @Override
-// public void getStatements(ReadGraphImpl graph, final int subject, final Procedure<DirectStatements> procedure) {
-//
-// procedure.exception(new DatabaseException("Not supported"));
-//
-// }
-
@Override
- public void getPredicates(final ReadGraphImpl graph, final int subject, final IntProcedure procedure) {
+ public void getPredicates(final ReadGraphImpl graph, final int subject, final IntProcedure procedure) throws DatabaseException {
final TIntHashSet result = new TIntHashSet(16);
}
ClusterI proxy = clusterTable.getClusterByResourceKey(subject);
-// if(!proxy.isLoaded()) {
-//
-// proxy.load(callerThread, session, new Runnable() {
-//
-// @Override
-// public void run() {
-// getPredicates(callerThread, subject, procedure);
-// }
-//
-// });
-// return;
-//
-// }
assert (proxy != null);
final DataContainer<Integer> got = new DataContainer<Integer>(0);
@Override
public boolean execute(Object context, int predicate, int oi) {
if (result.add(predicate)) {
- procedure.execute(graph, predicate);
+ try {
+ procedure.execute(graph, predicate);
+ } catch (DatabaseException e) {
+ Logger.defaultLogError(e);
+ }
}
got.set(got.get() + 1);
return false; // continue looping
} else {
- new Exception().printStackTrace();
+ //new Exception().printStackTrace();
cluster.load(session.clusterTranslator, new Runnable() {
} else {
// System.err.println("cluster not loaded " + subject);
- new Exception().printStackTrace();
+ //new Exception().printStackTrace();
cluster.load(session.clusterTranslator, new Runnable() {
try {
((ClusterSmall)cluster).check();
} catch (DatabaseException e) {
- e.printStackTrace();
+ LOGGER.error("ClusterSmall.check failed", e);
}
}