Examples of GraphDatabaseService


Examples of org.neo4j.graphdb.GraphDatabaseService

    @Override
    public Datastore<?, ?, ?> createDatastore(CdoUnit cdoUnit) {
        URL url = cdoUnit.getUrl();
        String protocol = url.getProtocol().toLowerCase();
        if ("file".equals(protocol)) {
            GraphDatabaseService graphDatabaseService = new GraphDatabaseFactory().newEmbeddedDatabase(url.getPath());
            return new EmbeddedNeo4jDatastore(graphDatabaseService);
        } else if ("http".equals(protocol) || "https".equals(protocol)) {
            return new RestNeo4jDatastore(url.toExternalForm());
        }
        return null;
View Full Code Here

Examples of org.neo4j.graphdb.GraphDatabaseService

   */
  public static void main(String[] args) {
    if (args.length < 4) {
      System.out.println("Usage: osmtoshp databasedir exportdir osmdataset layerspec <..layerspecs..>");
    } else {
      GraphDatabaseService db = new GraphDatabaseFactory().newEmbeddedDatabase((new File(args[0])).getAbsolutePath());
      SpatialDatabaseService spatial = new SpatialDatabaseService(db);
      OSMLayer layer = (OSMLayer) spatial.getLayer(args[2]);
      if (layer != null) {
        ShapefileExporter exporter = new ShapefileExporter(db);
        exporter.setExportDir(args[1]+File.separator+layer.getName());
        for (int i = 3; i < args.length; i++) {
          String[] fields = args[i].split("[\\.\\-]");
          HashMap<String, String> tags = new HashMap<String, String>();
          String key = fields[0];
          String name = key;
          if (fields.length > 1) {
            String value = fields.length > 1 ? fields[1] : null;
            name = key + "-" + value;
            tags.put(key, value);
          }

          try {
            if (layer.getLayerNames().contains(name)) {
              System.out.println("Exporting previously existing layer: "+name);
              exporter.exportLayer(name);
            } else {
              System.out.println("Creating and exporting new layer: "+name);
              layer.addDynamicLayerOnWayTags(name, Constants.GTYPE_LINESTRING, tags);
              exporter.exportLayer(name);
            }
          } catch (Exception e) {
            System.err.println("Failed to export dynamic layer " + name + ": " + e);
            e.printStackTrace(System.err);
          }
        }
      } else {
        System.err.println("No such layer: " + args[2]);
      }
      db.shutdown();
    }
  }
View Full Code Here

Examples of org.neo4j.graphdb.GraphDatabaseService

    return node;
  }

  private Node makeOSMWay(Geometry geometry, Node geomNode, int gtype) {
    wayId++;
    GraphDatabaseService db = geomNode.getGraphDatabase();
    Node way = db.createNode();
    // TODO: Generate a valid osm id
    way.setProperty(OSMId.WAY.toString(), wayId);
    way.setProperty("timestamp", getTimestamp());
    // TODO: Add other common properties, like changeset, uid, user,
    // version, name
    way.createRelationshipTo(geomNode, OSMRelation.GEOM);
    // TODO: if this way is a part of a complex geometry, the sub-geometries
    // are not indexed
    geomNode.setProperty(PROP_TYPE, gtype);
    Node prev = null;
    for (Coordinate coord : geometry.getCoordinates()) {
      Node node = makeOSMNode(coord, db);
      Node proxyNode = db.createNode();
      proxyNode.createRelationshipTo(node, OSMRelation.NODE);
      if (prev == null) {
        way.createRelationshipTo(proxyNode, OSMRelation.FIRST_NODE);
      } else {
        prev.createRelationshipTo(proxyNode, OSMRelation.NEXT);
View Full Code Here

Examples of org.neo4j.graphdb.GraphDatabaseService

    }

    @Test
    public void testBasicRepositoryFunctionality() {
        startJavaBasedAppCtx();
        GraphDatabaseService graphDatabaseService = appCtx.getBean(GraphDatabaseService.class);
        PersonRepository personRepository = appCtx.getBean(PersonRepository.class);
        try (Transaction tx = graphDatabaseService.beginTx()) {
            Person person = new Person("Howdy",50);
            personRepository.save(person);
            assertNotNull(person.getId());
            tx.success();
        }
View Full Code Here

Examples of org.neo4j.graphdb.GraphDatabaseService

import java.net.URI;

public class MemoryDatastoreFactory implements DatastoreFactory<EmbeddedNeo4jDatastore> {

    @Override public EmbeddedNeo4jDatastore createGraphDatabaseService(URI uri) {
        GraphDatabaseService graphDatabaseService = new TestGraphDatabaseFactory().newImpermanentDatabase();
        return new EmbeddedNeo4jDatastore(graphDatabaseService);
    }
View Full Code Here

Examples of org.neo4j.graphdb.GraphDatabaseService

public class FileDatastoreFactory implements DatastoreFactory<EmbeddedNeo4jDatastore> {

    @Override
    public EmbeddedNeo4jDatastore createGraphDatabaseService(URI uri) throws MalformedURLException {
        GraphDatabaseService graphDatabaseService = new GraphDatabaseFactory().newEmbeddedDatabase(uri.toURL().getPath());
        registerShutdownHook(graphDatabaseService);
        return new EmbeddedNeo4jDatastore(graphDatabaseService);
    }
View Full Code Here

Examples of org.neo4j.graphdb.GraphDatabaseService

    if (! url.startsWith("file://")) {
      throw new IllegalArgumentException("Only URLs for file protocol (starting with 'file://') are supported");
    }
    String path = url.substring("file://".length());
   
    GraphDatabaseService db = map.get(url);
   
    if (db == null) {
      Map<String, String> config = getConfig();
      DatabaseFactoryType factoryType = DatabaseFactoryType.getForLabel(databaseType);
     
View Full Code Here

Examples of org.neo4j.graphdb.GraphDatabaseService

    propertyName = rel.sourceAttributes().get(0).name();
  }
 
  public Iterator<Node> retrieve(Relationship rel) {
    long nodeId = ((Number) rel.getProperty(propertyName)).longValue();
    GraphDatabaseService db = rel.getGraphDatabase();
   
    return Iterators.singleton(db.getNodeById(nodeId));
  }
View Full Code Here

Examples of org.neo4j.graphdb.GraphDatabaseService

    verifyDeserialized( deserialized, version );
  }

  @Nonnull
  private T deserialize( @Nonnull AbstractNeo4jSerializer<T> serializer, @Nonnull String serialized ) throws IOException {
    GraphDatabaseService db = neo4jRule.createDb();

    //Fill the db initially
    try ( Transaction tx = db.beginTx() ) {
      ExecutionResult result = new ExecutionEngine( db ).execute( serialized );
      tx.success();
    }

    try ( Transaction tx = db.beginTx() ) {
      return serializer.deserialize( db.getNodeById( 0 ) );
    }
  }
View Full Code Here

Examples of org.neo4j.graphdb.GraphDatabaseService

    verifyDeserialized( deserialize( serializer, serialized ), entry.getObject() );
  }

  @Nonnull
  private T deserialize( @Nonnull AbstractNeo4jSerializer<T> serializer, @Nonnull String serialized ) throws IOException {
    GraphDatabaseService db = neo4jRule.createDb();

    //Fill the db initially
    try ( Transaction tx = db.beginTx() ) {
      ExecutionResult result = new ExecutionEngine( db ).execute( serialized );
      tx.success();
    }

    try ( Transaction tx = db.beginTx() ) {
      return serializer.deserialize( db.getNodeById( 0 ) );
    }
  }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.