*/
protected void save(Object data, String targetGraphID) throws IOException {
log.debug("Attempt saving in target graph {}", targetGraphID);
final long startSave = System.currentTimeMillis();
LockableMGraph mGraph;
UriRef graphUriRef = new UriRef(targetGraphID);
// tcManager must be synchronized
synchronized (tcManager) {
try {
// Check whether the graph already exists
mGraph = tcManager.getMGraph(graphUriRef);
} catch (NoSuchEntityException e) {
mGraph = tcManager.createMGraph(graphUriRef);
}
}
// We lock the graph before proceed
Lock writeLock = mGraph.getLock().writeLock();
boolean saved = false;
if (data instanceof Model) {
MGraph m = JenaToClerezzaConverter.jenaModelToClerezzaMGraph((Model) data);
writeLock.lock();
saved = mGraph.addAll(m);
writeLock.unlock();
} else if (data instanceof OWLOntology) {
MGraph m = (MGraph) OWLAPIToClerezzaConverter.owlOntologyToClerezzaMGraph((OWLOntology) data);
writeLock.lock();
saved = mGraph.addAll(m);
writeLock.unlock();
}
if (!saved) throw new IOException("Cannot save the result in clerezza!");
final long endSave = System.currentTimeMillis();
log.debug("Saved in time: {}ms", (endSave - startSave));