Java Code Examples for org.apache.tinkerpop.gremlin.structure.Transaction#open()

The following examples show how to use org.apache.tinkerpop.gremlin.structure.Transaction#open() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: MakePidsAbsoluteUrls.java    From timbuctoo with GNU General Public License v3.0 6 votes vote down vote up
@Override
public void execute(TinkerPopGraphManager graphWrapper) throws IOException {
  Transaction tx = graphWrapper.getGraph().tx();
  if (!tx.isOpen()) {
    tx.open();
  }

  graphWrapper.getGraph().traversal()
              .V()
              .has("pid")
              .filter(x -> !((String) x.get().value("pid")).startsWith("http://"))
              .forEachRemaining(it -> {
                String orig = it.value("pid");
                String replacement = "http://hdl.handle.net/11240/" + orig;
                if (Math.random() < 0.1) {
                  LOG.info(Logmarkers.migration, "Replacing " + orig + " with " + replacement);
                }
                it.property("pid", replacement);
              });
  tx.commit();
}
 
Example 2
Source File: AddPidsToWomenWritersEntities.java    From timbuctoo with GNU General Public License v3.0 6 votes vote down vote up
@Override
public void execute(ImmutableMultimap<String, String> parameters, PrintWriter output) throws Exception {
  final Graph graph = graphWrapper.getGraph();
  final Transaction tx = graph.tx();
  try {
    tx.open();
    addMissingPidsToEntities(graph, "wwpersons", "wwperson");
    addMissingPidsToEntities(graph, "wwdocuments", "wwdocument");
    tx.commit();
  } catch (Exception e) {
    LOG.error("Redirection uri creation failed", e);
    tx.rollback();
  } finally {
    tx.close();
  }
}
 
Example 3
Source File: FixDcarKeywordDisplayNameMigration.java    From timbuctoo with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void execute(TinkerPopGraphManager graphWrapper) throws IOException {
  final Graph graph = graphWrapper.getGraph();
  final GraphTraversal<Vertex, Vertex> dcarDisplayNameT = graph.traversal().V()
    .has(T.label, LabelP.of(Vre.DATABASE_LABEL))
    .has("name", "DutchCaribbean")
    .out("hasCollection")
    .has("collectionName", "dcarkeywords")
    .out("hasDisplayName");


  // Only apply this config change if this config actually exists in the current database
  if (dcarDisplayNameT.hasNext()) {
    LOG.info("Changing displayName configuration for dcarkeywords to dcarkeyword_value");
    final Vertex dcarDisplayName = dcarDisplayNameT.next();
    final Transaction transaction = graph.tx();
    if (!transaction.isOpen()) {
      transaction.open();
    }
    dcarDisplayName.property(LocalProperty.DATABASE_PROPERTY_NAME, "dcarkeyword_value");
    transaction.commit();
    transaction.close();
  } else {
    LOG.info("Skipping change for displayName configuration of dcarkeywords " +
      "as this collection does not exist in this database");
  }

}
 
Example 4
Source File: RelationTypeRdfUriMigration.java    From timbuctoo with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void execute(TinkerPopGraphManager graphWrapper) throws IOException {
  final Graph graph = graphWrapper.getGraph();
  final Transaction transaction = graph.tx();

  if (!transaction.isOpen()) {
    transaction.open();
  }

  final GraphDatabaseService graphDatabase = graphWrapper.getGraphDatabase();
  final Index<Node> rdfIndex = graphDatabase.index().forNodes(RDFINDEX_NAME);

  final String regularNameProp = "relationtype_regularName";
  final String inverseNameProp = "relationtype_inverseName";

  graph.traversal().V().has(regularNameProp).forEachRemaining(vertex -> {
    final String regularName = vertex.property(regularNameProp).isPresent() ?
      vertex.<String>property(regularNameProp).value() : "";

    final String inverseName = vertex.property(inverseNameProp).isPresent() ?
      vertex.<String>property(inverseNameProp).value() : "";

    final String rdfUri = TIMBUCTOO_NAMESPACE + regularName;
    final String[] rdfAlternatives = new String[]{ TIMBUCTOO_NAMESPACE + inverseName };

    LOG.info("setting rdfUri: \"{}\" and rdfAlternatives [{}] for relationType", rdfUri, rdfAlternatives);
    vertex.property(RDF_URI_PROP, rdfUri);
    vertex.property(RDF_SYNONYM_PROP, rdfAlternatives);

    LOG.info("indexing rdfUri: \"{}\" and rdfAlternatives [{}] for relationType", rdfUri, rdfAlternatives);
    org.neo4j.graphdb.Node neo4jNode = graphDatabase.getNodeById((Long) vertex.id());
    rdfIndex.add(neo4jNode, RelationTypeService.RELATIONTYPE_INDEX_NAME, rdfUri);
    rdfIndex.add(neo4jNode, RelationTypeService.RELATIONTYPE_INDEX_NAME, rdfAlternatives[0]);
  });

  transaction.commit();
  transaction.close();
}