* @param method Used to obtain metadata
*/
public synchronized void addURLData(String url, Graph data, HttpMethod method) {
RepositoryConnection dataConn = null;
InferencerConnection inferencerConn = null;
RepositoryConnection metaDataConn = null;
try {
dataConn = dataRepository.getConnection();
inferencerConn = (InferencerConnection) dataRepository.getSail().getConnection();
metaDataConn = metaDataRepository.getConnection();
URI urlDataContext = dataRepository.getValueFactory().createURI(url);
URI urlInferencerContext = dataRepository.getValueFactory().createURI(url);
URI urlMetadata = metaDataRepository.getValueFactory().createURI(url);
/* Remove cached data and previous metadata */
inferencerConn.removeInferredStatement((Resource)null, null, null, urlInferencerContext);
/*
* Because inferencerConn now holds the transaction lock on the store,
* we need to commit changes first or we'll run into a deadlock when removing statements
* using dataConn. They could be removed using dataConn; but the problem
* would remain for the adding of statements.
*/
inferencerConn.commit();
dataConn.remove((Resource)null, null, null, urlDataContext);
metaDataConn.remove(urlMetadata, null, null, contextCacheDataURI);
/* Add retrieved data */
if (data != null)
dataConn.add(data);
/* Add metadata */
if (method != null) {
for (String headerField : cachedHeaderFields) {
Header header;
if (null != (header = method.getResponseHeader(headerField))) {
metaDataConn.add(urlMetadata,
metaDataRepository.getValueFactory().createURI(Constants.nsHTTP, headerField),
metaDataRepository.getValueFactory().createLiteral(header.getValue()),
contextCacheDataURI);
}
}
/* Add status code */
if (null != method.getStatusLine()) /* or we'll run into a NullPointerException when calling getStatusCode() */
metaDataConn.add(urlMetadata,
metaDataRepository.getValueFactory().createURI(Constants.nsHTTP, "responseCode"),
metaDataRepository.getValueFactory().createLiteral(method.getStatusCode()),
contextCacheDataURI);
}
/* We'll make use of the date header to specify when the document was retrieved */
metaDataConn.add(urlMetadata,
metaDataRepository.getValueFactory().createURI(Constants.nsHTTP, "date"),
metaDataRepository.getValueFactory().createLiteral(DateUtil.formatDate(new Date())),
contextCacheDataURI);
/* Commit */
// inferencerConn.commit();
} catch (IllegalArgumentException e) {
e.printStackTrace();
} catch (RepositoryException e) {
e.printStackTrace();
} catch (SailException e) {
e.printStackTrace();
}
finally {
if (dataConn != null)
try {
dataConn.close();
} catch (RepositoryException e) {
e.printStackTrace();
}
if (inferencerConn != null)
try {
inferencerConn.close();
} catch (SailException e) {
e.printStackTrace();
}
if (metaDataConn != null)
try {