コード例 #1
0
 private void doLoadRDFData(
     String modelName, String docLoc, String filePath, String language, ModelMaker modelMaker) {
   Model m = modelMaker.getModel(modelName);
   m.enterCriticalSection(Lock.WRITE);
   try {
     if ((docLoc != null) && (docLoc.length() > 0)) {
       m.read(docLoc, language);
     } else if ((filePath != null) && (filePath.length() > 0)) {
       File file = new File(filePath);
       File[] files;
       if (file.isDirectory()) {
         files = file.listFiles();
       } else {
         files = new File[1];
         files[0] = file;
       }
       for (int i = 0; i < files.length; i++) {
         File currentFile = files[i];
         log.info("Reading file " + currentFile.getName());
         FileInputStream fis;
         try {
           fis = new FileInputStream(currentFile);
           m.read(fis, null, language);
           fis.close();
         } catch (IOException ioe) {
           throw new RuntimeException(ioe);
         }
       }
     }
   } finally {
     m.leaveCriticalSection();
   }
 }
コード例 #2
0
 private void doAttachModel(String modelName, ModelMaker modelMaker) {
   if (attachedModels.containsKey(modelName)) {
     doDetachModel(modelName);
   }
   Model m = ModelFactory.createDefaultModel();
   m.add(modelMaker.getModel(modelName));
   ModelAccess.on(getServletContext()).getOntModel(TBOX_ASSERTIONS).addSubModel(m);
   attachedModels.put(modelName, m);
   log.info("Attached " + modelName + " (" + m.hashCode() + ") to webapp");
 }
コード例 #3
0
 private void doClearModel(String modelName, ModelMaker modelMaker) {
   Model m = modelMaker.getModel(modelName);
   OntModel o = ModelFactory.createOntologyModel(OntModelSpec.OWL_MEM, m);
   o.enterCriticalSection(Lock.WRITE);
   try {
     o.removeAll(null, null, null);
   } finally {
     o.leaveCriticalSection();
   }
   // removeAll() doesn't work with the listeners!
 }
コード例 #4
0
 protected void showModelList(VitroRequest vreq, ModelMaker maker, WhichService modelType) {
   vreq.setAttribute("modelType", modelType.toString());
   if (modelType == CONTENT) {
     vreq.setAttribute("infoLine", "Main Store models");
   } else {
     vreq.setAttribute("infoLine", "Configuration models");
   }
   vreq.setAttribute("modelNames", maker.listModels().toList());
   vreq.setAttribute("bodyAttr", "onLoad=\"init()\"");
   vreq.setAttribute("title", "Available Models");
   vreq.setAttribute("bodyJsp", LIST_MODELS_JSP);
 }
コード例 #5
0
  public static void main(String[] args) {
    try {
      String className = args[0];
      Class.forName(className);
      String DB_URL = args[1]; // URL of database
      String DB_NAME = args[2]; // DB name
      String DB_USER = args[3]; // database user id
      String DB_PASSWD = args[4]; // database password
      String DB = args[5]; // database type

      IDBConnection conn = new PagedDBConnection(DB_URL + DB_NAME, DB_USER, DB_PASSWD, DB);
      ModelMaker maker = ExtendedModelFactory.createPagedModelRDBMaker(conn);
      PagedModelRDB model = (PagedModelRDB) maker.createModel(args[6]);
      model.setDoDuplicateCheck(false);
      long startTime = System.currentTimeMillis();
      model.read(new FileInputStream(args[7]), null, "N3");
      long endTime = System.currentTimeMillis();
      System.out.println(
          "time to read in the model = " + (endTime - startTime) / 1000 + " seconds.\n");

      startTime = System.currentTimeMillis();
      long count = 0L;
      String queryString = " SELECT ?x ?y ?z " + " WHERE { ?x ?y ?z } ";
      QueryExecution qexec = QueryExecutionFactory.create(queryString, model);
      ResultSet rs = qexec.execSelect();
      while (rs.hasNext()) {
        count++;
        rs.nextSolution();
      }
      qexec.close();
      endTime = System.currentTimeMillis();
      System.out.println("count of found statements = " + count);
      System.out.println("time to query for results = " + (endTime - startTime) + " milliseconds.");

      conn.cleanDB();
      conn.close();
    } catch (Exception e) {
      e.printStackTrace();
    }
  }
コード例 #6
0
 private void processPermanentURIRequest(VitroRequest vreq, ModelMaker maker) {
   String modelName = vreq.getParameter("modelName");
   String oldModel = vreq.getParameter("oldModel");
   String newModel = vreq.getParameter("newModel");
   String oldNamespace = vreq.getParameter("oldNamespace");
   String newNamespace = vreq.getParameter("newNamespace");
   String dNamespace = vreq.getParameter("defaultNamespace");
   newNamespace = (newNamespace == null || newNamespace.isEmpty()) ? oldNamespace : newNamespace;
   newNamespace = (dNamespace != null) ? dNamespace : newNamespace;
   if (modelName != null) {
     Model m = maker.getModel(modelName);
     List<String> namespaceList = new ArrayList<>();
     ResIterator resItr = m.listResourcesWithProperty((Property) null);
     if (resItr != null) {
       while (resItr.hasNext()) {
         String namespace = resItr.nextResource().getNameSpace();
         if (!namespaceList.contains(namespace)) {
           namespaceList.add(namespace);
         }
       }
     } else {
       namespaceList.add("no resources present");
     }
     String defaultNamespace = vreq.getUnfilteredWebappDaoFactory().getDefaultNamespace();
     vreq.setAttribute("modelName", modelName);
     vreq.setAttribute("defaultNamespace", defaultNamespace);
     vreq.setAttribute("namespaceList", namespaceList);
     vreq.setAttribute("title", "Permanent URI");
     vreq.setAttribute("bodyJsp", PERMANENT_URI);
   } else if (oldModel != null) {
     JenaIngestUtils utils = new JenaIngestUtils();
     utils.doPermanentURI(oldModel, newModel, oldNamespace, newNamespace, maker, vreq);
     vreq.setAttribute("title", "Ingest Menu");
     vreq.setAttribute("bodyJsp", INGEST_MENU_JSP);
   }
 }
コード例 #7
0
 private void processRenameBNodesRequest(VitroRequest vreq, ModelMaker maker) {
   String[] sourceModel = vreq.getParameterValues("sourceModelName");
   JenaIngestUtils utils = new JenaIngestUtils();
   if (sourceModel != null && sourceModel.length != 0) {
     List<Model> sourceModelList = new ArrayList<Model>();
     for (int i = 0; i < sourceModel.length; i++) {
       Model m = maker.getModel(sourceModel[i]);
       if (m != null) {
         sourceModelList.add(m);
       }
     }
     Map<String, LinkedList<String>> propertyMap =
         utils.generatePropertyMap(sourceModelList, maker);
     List<String> sourceModelNameList = Arrays.asList(sourceModel);
     vreq.setAttribute("sourceModel", sourceModelNameList);
     vreq.setAttribute("propertyMap", propertyMap);
     vreq.setAttribute("enablePropertyPatternURIs", !propertyMap.isEmpty());
     vreq.setAttribute("title", "URI Select");
     vreq.setAttribute("bodyJsp", RENAME_BNODES_URI_SELECT_JSP);
   } else {
     vreq.setAttribute("title", "Rename Blank Nodes");
     vreq.setAttribute("bodyJsp", RENAME_BNODES_JSP);
   }
 }
コード例 #8
0
 private void doRemoveModel(String modelName, ModelMaker modelMaker) {
   // Try to detach first since it cause problems to remove an attached model.
   doDetachModel(modelName);
   log.debug("Removing " + modelName + " from webapp");
   modelMaker.removeModel(modelName);
 }
コード例 #9
0
 private void doCreateModel(String modelName, ModelMaker modelMaker) {
   modelMaker.createModel(modelName);
 }
コード例 #10
0
  @Override
  public void doGet(HttpServletRequest request, HttpServletResponse response)
      throws ServletException, IOException {
    if (!isAuthorizedToDisplayPage(
        request, response, SimplePermission.USE_ADVANCED_DATA_TOOLS_PAGES.ACTION)) {
      return;
    }

    VitroRequest vreq = new VitroRequest(request);
    ModelMaker maker = getModelMaker(vreq);
    WhichService modelType = getModelType(vreq);

    String actionStr = vreq.getParameter("action");
    actionStr = (actionStr != null) ? actionStr : "";

    if ("listModels".equals(actionStr)) {
      processListModelsRequest(vreq, maker, modelType);
    } else if ("configModels".equals(actionStr)) {
      processConfigModelsRequest(vreq);
    } else if ("contentModels".equals(actionStr)) {
      processContentModelsRequest(vreq);
    } else if ("createModel".equals(actionStr)) {
      processCreateModelRequest(vreq, maker, modelType);
    } else if ("removeModel".equals(actionStr)) {
      processRemoveModelRequest(vreq, maker, modelType);
    } else if ("loadRDFData".equals(actionStr)) {
      processLoadRDFDataRequest(vreq, maker);
    } else if ("cleanLiterals".equals(actionStr)) {
      processCleanLiteralsRequest(vreq);
    } else if ("outputModel".equals(actionStr)) {
      processOutputModelRequest(vreq, response);
      return; // don't attempt to display a JSP
    } else if ("clearModel".equals(actionStr)) {
      processClearModelRequest(vreq, maker, modelType);
    } else if ("attachModel".equals(actionStr)) {
      processAttachModelRequest(vreq, maker, modelType);
    } else if ("detachModel".equals(actionStr)) {
      processDetachModelRequest(vreq, maker, modelType);
    } else if ("renameBNodes".equals(actionStr)) {
      processRenameBNodesRequest(vreq, maker);
    } else if ("renameBNodesURISelect".equals(actionStr)) {
      processRenameBNodesURISelectRequest(vreq, maker);
    } else if ("smushSingleModel".equals(actionStr)) {
      processSmushSingleModelRequest(vreq);
    } else if ("csv2rdf".equals(actionStr)) {
      processCsv2rdfRequest(vreq);
    } else if ("processStrings".equals(actionStr)) {
      processProcessStringsRequest(vreq);
    } else if ("splitPropertyValues".equals(actionStr)) {
      processSplitPropertyValuesRequest(vreq);
    } else if ("subtractModels".equals(actionStr)) {
      processSubtractModelRequest(vreq);
    } else if ("executeWorkflow".equals(actionStr)) {
      processExecuteWorkflowRequest(vreq);
    } else if ("executeSparql".equals(actionStr)) {
      processExecuteSparqlRequest(vreq);
    } else if ("generateTBox".equals(actionStr)) {
      processGenerateTBoxRequest(vreq);
    } else if ("permanentURI".equals(actionStr)) {
      processPermanentURIRequest(vreq, maker);
    } else if ("mergeResources".equals(actionStr)) {
      processMergeResourceRequest(vreq);
    } else if ("renameResource".equals(actionStr)) {
      processRenameResourceRequest(vreq);
    } else if ("mergeResult".equals(actionStr)) {
      processMergeResultRequest(vreq, response);
      return;
    } else if ("dumpRestore".equals(actionStr)) {
      processDumpRestore(vreq, response);
      return;
    } else {
      request.setAttribute("title", "Ingest Menu");
      request.setAttribute("bodyJsp", INGEST_MENU_JSP);
    }

    maker = getModelMaker(vreq);
    request.setAttribute("modelNames", maker.listModels().toList());

    RequestDispatcher rd = request.getRequestDispatcher(Controllers.BASIC_JSP);
    try {
      rd.forward(request, response);
    } catch (Exception e) {
      log.error(e, e);
      throw new ServletException(e);
    }
  }
コード例 #11
0
ファイル: JenaGraph.java プロジェクト: GlearDev/nuxeo
 /**
  * Gets the Jena graph using options.
  *
  * <p>The Jena "Convenient" reification style is used when opening models: it allows to ignore
  * reification quadlets when calling the statements list.
  *
  * @param forceReload boolean stating if the jena graph has to be reloaded using options
  * @return the Jena graph (model)
  */
 protected synchronized GraphConnection openGraph(boolean forceReload) {
   // create model given backend
   if (backend.equals("memory")) {
     if (memoryGraph == null || forceReload) {
       memoryGraph = ModelFactory.createDefaultModel(ModelFactory.Convenient);
       memoryGraph.setNsPrefixes(namespaces);
     }
     return new GraphConnection((Connection) null, memoryGraph);
   } else if (backend.equals("sql")) {
     if (datasource == null) {
       throw new IllegalArgumentException("Missing datasource for sql graph : " + name);
     }
     // create a database connection
     Connection baseConnection;
     try {
       // try single-datasource non-XA mode
       baseConnection = ConnectionHelper.getConnection(datasource);
       if (baseConnection == null) {
         // standard datasource usage
         DataSource ds = DataSourceHelper.getDataSource(datasource);
         baseConnection = ds.getConnection();
       }
     } catch (NamingException e) {
       throw new IllegalArgumentException(String.format("Datasource %s not found", datasource), e);
     } catch (SQLException e) {
       throw new IllegalArgumentException(
           String.format("SQLException while opening %s", datasource), e);
     }
     /*
      * We have to wrap the connection to disallow any commit() or setAutoCommit() on it. Jena calls these
      * methods without regard to the fact that the connection may be managed by an external transaction.
      */
     Connection wrappedConnection =
         (Connection)
             Proxy.newProxyInstance(
                 Connection.class.getClassLoader(),
                 new Class[] {Connection.class},
                 new ConnectionFixInvocationHandler(baseConnection));
     DBConnection connection = new DBConnection(wrappedConnection, databaseType);
     // check if named model already exists
     Model graph;
     if (connection.containsModel(name)) {
       ModelMaker m = ModelFactory.createModelRDBMaker(connection, ModelFactory.Convenient);
       graph = m.openModel(name);
     } else {
       // create it
       // check if other models already exist for that connection.
       if (connection.getAllModelNames().hasNext()) {
         // other models already exist => do not set parameters
         // on driver.
         if (databaseDoCompressUri != connection.getDriver().getDoCompressURI()) {
           log.warn(
               String.format(
                   "Cannot set databaseDoCompressUri attribute to %s "
                       + "for model %s, other models already "
                       + "exist with value %s",
                   databaseDoCompressUri, name, connection.getDriver().getDoCompressURI()));
         }
         if (databaseTransactionEnabled != connection.getDriver().getIsTransactionDb()) {
           log.warn(
               String.format(
                   "Cannot set databaseTransactionEnabled attribute to %s "
                       + "for model %s, other models already "
                       + "exist with value %s",
                   databaseTransactionEnabled, name, connection.getDriver().getIsTransactionDb()));
         }
       } else {
         if (databaseDoCompressUri) {
           connection.getDriver().setDoCompressURI(true);
         }
         if (databaseTransactionEnabled) {
           connection.getDriver().setIsTransactionDb(true);
         }
       }
       ModelMaker m = ModelFactory.createModelRDBMaker(connection, ModelFactory.Convenient);
       graph = m.createModel(name);
     }
     graph.setNsPrefixes(namespaces);
     // use baseConnection so that it is closed instead of the jena one
     // (to let the pool handled closure).
     if (baseConnection != null) {
       return new GraphConnection(baseConnection, graph);
     }
     return new GraphConnection(connection, graph);
   } else {
     throw new IllegalArgumentException("Unknown backend type " + backend);
   }
 }