public void importa(BatchInserter inserter, LuceneBatchInserterIndexProvider indexProvider) {

    BatchInserterIndex pessoas =
        indexProvider.nodeIndex("pessoas", MapUtil.stringMap("type", "fulltext"));

    Scanner sc = new Scanner(ImportadorPessoas.class.getResourceAsStream("/import/pessoas"));

    System.out.println("Início da importação das pessoas");
    while (sc.hasNextLine()) {
      String linha = sc.nextLine();
      String[] informacoesDePessoa = linha.split(";");
      long id = Long.parseLong(informacoesDePessoa[0]);
      String nome = informacoesDePessoa[1];
      Integer idade = Integer.parseInt(informacoesDePessoa[2]);

      Map<String, Object> propriedades = MapUtil.map("nome", nome, "idade", idade);

      inserter.createNode(id, propriedades);
      pessoas.add(id, MapUtil.map("nome", nome));
      inserter.createRelationship(0, id, Relacionamentos.PESSOA, null);
    }

    pessoas.flush();

    System.out.println("Fim da importação das pessoas");
  }
Exemple #2
0
  public void importFromFile(String filePath) throws IOException {
    Map<String, Long> cache = new HashMap<String, Long>(COUNT);
    final File storeDir = new File(this.path);
    org.apache.commons.io.FileUtils.deleteDirectory(storeDir);
    BatchInserter batchInserter = new BatchInserterImpl(storeDir.getAbsolutePath());
    final BatchInserterIndexProvider indexProvider =
        new LuceneBatchInserterIndexProvider(batchInserter);
    final BatchInserterIndex index =
        indexProvider.nodeIndex("nodes", MapUtil.stringMap("type", "exact"));
    BufferedReader reader = new BufferedReader(new FileReader(filePath));
    String line = null;
    int nodes = 0;
    long time = System.currentTimeMillis();
    long batchTime = time;
    while ((line = reader.readLine()) != null) {
      final String[] nodeNames = line.split("\\|");
      final String name = nodeNames[0];
      final Map<String, Object> props = MapUtil.map("name", name);
      final long node = batchInserter.createNode(props);
      index.add(node, props);
      cache.put(name, node);
      nodes++;
      if ((nodes % REPORT_COUNT) == 0) {
        System.out.printf(
            "%d nodes created. Took %d %n", nodes, (System.currentTimeMillis() - batchTime));
        batchTime = System.currentTimeMillis();
      }
    }

    System.out.println("Creating nodes took " + (System.currentTimeMillis() - time) / 1000);
    index.flush();
    reader.close();
    reader = new BufferedReader(new FileReader(filePath));
    int rels = 0;
    time = System.currentTimeMillis();
    batchTime = time;
    String relationshipType = "KNOWS";
    while ((line = reader.readLine()) != null) {
      final String[] nodeNames = line.split("\\|");
      final String name = nodeNames[0];
      // final Long from = index.get("name", name).getSingle();
      Long from = cache.get(name);
      for (int j = 1; j < nodeNames.length; j++) {
        // final Long to = index.get("name", nodeNames[j]).getSingle();
        final Long to = cache.get(name);
        batchInserter.createRelationship(
            from, to, DynamicRelationshipType.withName(relationshipType), null);
      }
      rels++;
      if ((rels % REPORT_COUNT) == 0) {
        System.out.printf(
            "%d relationships created. Took %d %n", rels, (System.currentTimeMillis() - batchTime));
        batchTime = System.currentTimeMillis();
      }
    }
    System.out.println("Creating relationships took " + (System.currentTimeMillis() - time) / 1000);
    indexProvider.shutdown();
    batchInserter.shutdown();
  }
Exemple #3
0
  private static long createGenomeElementNode(
      String version,
      String comment,
      String definition,
      BatchInserter inserter,
      BatchInserterIndex index) {

    genomeElementProperties.put(GenomeElementNode.VERSION_PROPERTY, version);
    genomeElementProperties.put(GenomeElementNode.COMMENT_PROPERTY, comment);
    genomeElementProperties.put(GenomeElementNode.DEFINITION_PROPERTY, definition);

    long genomeElementId = inserter.createNode(genomeElementProperties);
    index.add(
        genomeElementId, MapUtil.map(GenomeElementNode.GENOME_ELEMENT_VERSION_INDEX, version));
    return genomeElementId;
  }