Package org.openrdf.sail.inferencer

Examples of org.openrdf.sail.inferencer.InferencerConnection


 
  @Override
  public SailConnection getConnection()
    throws SailException {
    try {
      InferencerConnection con = (InferencerConnection)super.getConnection();
      this.con = new SameAsInferencerConnection(con);
      return this.con;
    }
    catch (ClassCastException e) {
      throw new SailException(e);
View Full Code Here


    if (Constants.isBaseUrl(url))
      return;
   
    RepositoryConnection dataConn = null;
    RepositoryConnection metaDataConn = null;
    InferencerConnection inferencerConn = null;
   
    try {
      dataConn = dataRepository.getConnection();
      inferencerConn = (InferencerConnection) dataRepository.getSail().getConnection();
      metaDataConn = metaDataRepository.getConnection();

      URI urlDataContext = dataRepository.getValueFactory().createURI(url);
      URI urlInferencerContext = dataRepository.getSail().getValueFactory().createURI(url);
      URI urlMetadata = metaDataRepository.getValueFactory().createURI(url);

      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);

      /* Commit */
//      inferencerConn.commit();
    } catch (RepositoryException e) {
      e.printStackTrace();
    } catch (SailException e) {
      e.printStackTrace();
    }
    finally {
      if (dataConn != null)
        try {
          dataConn.close();
        } catch (RepositoryException e) {
          e.printStackTrace();
        }
      if (metaDataConn != null)
        try {
          metaDataConn.close();
        } catch (RepositoryException e) {
          e.printStackTrace();
        }
      if (inferencerConn != null)
        try {
          inferencerConn.close();
        } catch (SailException e) {
          e.printStackTrace();
        }
    }
  }
View Full Code Here

   * @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 {
View Full Code Here

TOP

Related Classes of org.openrdf.sail.inferencer.InferencerConnection

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.