On 13/02/12 16:06, Emilio Miguelanez wrote:
Hello 'jena-users',
My question is related to the situation when I want to validate the (OntModel)
model after an update operation using the SPARQUL query.
If there are not conflicts, the model can go ahead a commit. But, what happen
when there are some conflicts?
See below my two methods: one for model consistency and another to update the
model using SPARUL API. However, in the latter, the abort() call does not work
obviously as the model does not support transaction.
Therefore, the question is what I could do in order to guarantee a consistent
model after model updates.
Lib being used: TDB-0.8.10 and Jena-2.7.0
1/ Don't put the updates in the base data until you check them. Use
union models.
2/ Use 0.9.0 SNAPSHOT - it supports transactions on datasets (not
individual models).
http://incubator.apache.org/jena/documentation/tdb/tdb_transactions.html
Andy
Regards,
Emilio
private static boolean modelConsistencyCheck() throws ConsistencyException {
boolean check;
ValidityReport validity = model.validate();
if (validity.isValid()) {
logger.info("Consistency Checking: OK");
check=true;
} else {
logger.warn("Consistency Checking: Conflicts");
for (Iterator i = validity.getReports(); i.hasNext();) {
logger.warn(" - " + i.next());
}
check=true;
throw new ConsistencyException("Model is INCONSISTENT> check logs
to see conflicts");
}
return check;
}
public String updateModel(String inputQuery) throws ConsistencyException,
QueryParseException, QueryExecException, IOException,
ConcurrentModificationException, Exception {
// Construct a SPARUL query
String queryResults = null;
model.enterCriticalSection(Lock.WRITE);
try {
UpdateRequest updateRequest = UpdateFactory.create(queryPrefix +
inputQuery);
UpdateAction.execute(updateRequest, model);
logger.debug("Consistency checking of UPDATED Model");
if (modelConsistencyCheck()) {
model.commit();
} else {
model.abort();
}
} finally {
TDB.sync(model);
queryResults = "Model Updated";
model.leaveCriticalSection();
}
return queryResults;
}