예제 #1
0
  @Test
  public void shouldOverwriteExistingProperties()
      throws PropertyValueException, NodeNotFoundException {

    long nodeId;
    Transaction tx = database.getGraph().beginTx();
    try {
      Node node = database.getGraph().createNode();
      node.setProperty("remove me", "trash");
      nodeId = node.getId();
      tx.success();
    } finally {
      tx.finish();
    }
    Map<String, Object> properties = new HashMap<String, Object>();
    properties.put("foo", "bar");
    properties.put("baz", 17);
    actions.setAllNodeProperties(nodeId, properties);
    tx = database.getGraph().beginTx();
    try {
      Node node = database.getGraph().getNodeById(nodeId);
      assertHasProperties(node, properties);
      assertNull(node.getProperty("remove me", null));
    } finally {
      tx.finish();
    }
  }
 private void addPropertyToReferenceNode() {
   Transaction tx = db.getGraph().beginTx();
   Node n = db.getGraph().getReferenceNode();
   n.setProperty("monkey", "rock!");
   tx.success();
   tx.finish();
 }
예제 #3
0
  @Test
  public void shouldBeAbleToGetPropertiesOnRelationship() throws Exception {

    long relationshipId;
    Map<String, Object> properties = new HashMap<String, Object>();
    properties.put("foo", "bar");
    properties.put("neo", "Thomas A. Anderson");
    properties.put("number", 15L);
    Transaction tx = database.getGraph().beginTx();
    try {
      Node startNode = database.getGraph().createNode();
      Node endNode = database.getGraph().createNode();
      Relationship relationship =
          startNode.createRelationshipTo(endNode, DynamicRelationshipType.withName("knows"));
      for (Map.Entry<String, Object> entry : properties.entrySet()) {
        relationship.setProperty(entry.getKey(), entry.getValue());
      }
      relationshipId = relationship.getId();
      tx.success();
    } finally {
      tx.finish();
    }

    Map<String, Object> readProperties =
        serialize(actions.getAllRelationshipProperties(relationshipId));
    assertEquals(properties, readProperties);
  }
예제 #4
0
  public org.neo4j.server.database.RrdDbWrapper createRrdDbAndSampler(
      final Database db, JobScheduler scheduler) throws IOException {
    NodeManager nodeManager =
        db.getGraph().getDependencyResolver().resolveDependency(NodeManager.class);

    Sampleable[] primitives = {
      new NodeIdsInUseSampleable(nodeManager),
      new PropertyCountSampleable(nodeManager),
      new RelationshipCountSampleable(nodeManager)
    };

    Sampleable[] usage = {};

    final String rrdPath =
        config.getString(RRDB_LOCATION_PROPERTY_KEY, getDefaultRrdFile(db.getGraph()));
    final RrdDbWrapper rrdb =
        createRrdb(rrdPath, isEphemereal(db.getGraph()), join(primitives, usage));

    scheduler.scheduleAtFixedRate(
        new RrdJob(new RrdSamplerImpl(rrdb.get(), primitives)),
        RRD_THREAD_NAME + "[primitives]",
        SECONDS.toMillis(0),
        SECONDS.toMillis(3));

    return rrdb;
  }
예제 #5
0
  @Test
  public void createdNodeShouldBeInDatabase() throws Exception {
    NodeRepresentation noderep = actions.createNode(Collections.<String, Object>emptyMap());

    Transaction tx = database.getGraph().beginTx();
    try {
      assertNotNull(database.getGraph().getNodeById(noderep.getId()));
    } finally {
      tx.finish();
    }
  }
예제 #6
0
  private long createNode(Map<String, Object> properties) {

    long nodeId;
    Transaction tx = database.getGraph().beginTx();
    try {
      Node node = database.getGraph().createNode();
      for (Map.Entry<String, Object> entry : properties.entrySet()) {
        node.setProperty(entry.getKey(), entry.getValue());
      }
      nodeId = node.getId();
      tx.success();
    } finally {
      tx.finish();
    }
    return nodeId;
  }
예제 #7
0
  @Test
  public void shouldBeAbleToStorePropertiesInAnExistingNode()
      throws PropertyValueException, NodeNotFoundException {
    long nodeId = graphdbHelper.createNode();
    Map<String, Object> properties = new HashMap<String, Object>();
    properties.put("foo", "bar");
    properties.put("baz", 17);
    actions.setAllNodeProperties(nodeId, properties);

    Transaction tx = database.getGraph().beginTx();
    try {
      Node node = database.getGraph().getNodeById(nodeId);
      assertHasProperties(node, properties);
    } finally {
      tx.finish();
    }
  }
예제 #8
0
  @Test
  public void shouldRemoveNodeWithNoRelationsFromDBOnDelete()
      throws NodeNotFoundException, OperationFailureException {
    long nodeId;
    Transaction tx = database.getGraph().beginTx();
    try {
      Node node = database.getGraph().createNode();
      nodeId = node.getId();
      tx.success();
    } finally {
      tx.finish();
    }

    int nodeCount = graphdbHelper.getNumberOfNodes();
    actions.deleteNode(nodeId);
    assertEquals(nodeCount - 1, graphdbHelper.getNumberOfNodes());
  }
예제 #9
0
  @Test
  public void shouldBeAbleToRemoveNodeProperties() throws Exception {
    Map<String, Object> properties = new HashMap<String, Object>();
    properties.put("foo", "bar");
    properties.put("number", 15);
    long nodeId = createNode(properties);
    actions.removeAllNodeProperties(nodeId);

    Transaction tx = database.getGraph().beginTx();
    try {
      Node node = database.getGraph().getNodeById(nodeId);
      assertEquals(false, node.getPropertyKeys().iterator().hasNext());
      tx.success();
    } finally {
      tx.finish();
    }
  }
  private void addNodeIntoGraph() {
    Transaction tx = db.getGraph().beginTx();
    Node referenceNode = db.getGraph().getReferenceNode();
    Node myNewNode = db.getGraph().createNode();
    myNewNode.setProperty("id", UUID.randomUUID().toString());
    myNewNode.createRelationshipTo(
        referenceNode,
        new RelationshipType() {
          @Override
          public String name() {
            return "knows_about";
          }
        });

    tx.success();
    tx.finish();
  }
예제 #11
0
 public void addRelationshipToIndex(
     String indexName, String key, String value, long relationshipId) {
   Index<Relationship> index = database.getRelationshipIndex(indexName);
   Transaction tx = database.graph.beginTx();
   try {
     index.add(database.graph.getRelationshipById(relationshipId), key, value);
     tx.success();
   } finally {
     tx.finish();
   }
 }
예제 #12
0
 public void addNodeToIndex(String indexName, String key, Object value, long id)
     throws DatabaseBlockedException {
   Index<Node> index = database.getNodeIndex(indexName);
   Transaction tx = database.graph.beginTx();
   try {
     index.add(database.graph.getNodeById(id), key, value);
     tx.success();
   } finally {
     tx.finish();
   }
 }
 @Before
 public void startDatabase() throws IOException {
   graph = (InternalAbstractGraphDatabase) new TestGraphDatabaseFactory().newImpermanentDatabase();
   database = new WrappedDatabase(graph);
   helper = new GraphDbHelper(database);
   output = new EntityOutputFormat(new JsonFormat(), URI.create(BASE_URI), null);
   leaseManager = new LeaseManager(new FakeClock());
   service =
       new RestfulGraphDatabase(
           new JsonFormat(), output, new DatabaseActions(leaseManager, true, database.getGraph()));
   service = new TransactionWrappingRestfulGraphDatabase(graph, service);
 }
  private long createListOfNodes(int numberOfNodes) {
    Transaction tx = database.getGraph().beginTx();
    try {
      long zerothNode = helper.createNode(MapUtil.map("name", String.valueOf(0)));
      long previousNodeId = zerothNode;
      for (int i = 1; i < numberOfNodes; i++) {
        long currentNodeId = helper.createNode(MapUtil.map("name", String.valueOf(i)));
        database
            .getGraph()
            .getNodeById(previousNodeId)
            .createRelationshipTo(
                database.getGraph().getNodeById(currentNodeId),
                DynamicRelationshipType.withName("PRECEDES"));
        previousNodeId = currentNodeId;
      }

      tx.success();
      return zerothNode;
    } finally {
      tx.finish();
    }
  }
예제 #15
0
  @Test
  public void shouldBeAbleToGetPropertiesOnNode() throws NodeNotFoundException {

    long nodeId;
    Map<String, Object> properties = new HashMap<String, Object>();
    properties.put("foo", "bar");
    properties.put("neo", "Thomas A. Anderson");
    properties.put("number", 15L);
    Transaction tx = database.getGraph().beginTx();
    try {
      Node node = database.getGraph().createNode();
      for (Map.Entry<String, Object> entry : properties.entrySet()) {
        node.setProperty(entry.getKey(), entry.getValue());
      }
      nodeId = node.getId();
      tx.success();
    } finally {
      tx.finish();
    }

    Map<String, Object> readProperties = serialize(actions.getAllNodeProperties(nodeId));
    assertEquals(properties, readProperties);
  }
예제 #16
0
  @Test
  public void shouldStoreSuppliedPropertiesWhenCreatingRelationship() throws Exception {
    Map<String, Object> properties = new HashMap<String, Object>();
    properties.put("string", "value");
    properties.put("integer", 17);
    long relId =
        actions
            .createRelationship(
                graphdbHelper.createNode(), graphdbHelper.createNode(), "LOVES", properties)
            .getId();

    Transaction tx = database.getGraph().beginTx();
    try {
      Relationship rel = database.getGraph().getRelationshipById(relId);
      for (String key : rel.getPropertyKeys()) {
        assertTrue("extra property stored", properties.containsKey(key));
      }
      for (Map.Entry<String, Object> entry : properties.entrySet()) {
        assertEquals(entry.getValue(), rel.getProperty(entry.getKey()));
      }
    } finally {
      tx.finish();
    }
  }
예제 #17
0
 public Collection<Long> queryIndexedNodes(String indexName, String key, Object value)
     throws DatabaseBlockedException {
   // TODO: refactor this and getIndexedNodes to avoid dupe code
   Index<Node> index = database.getNodeIndex(indexName);
   Transaction tx = database.graph.beginTx();
   try {
     Collection<Long> result = new ArrayList<Long>();
     for (Node node : index.query(key, value)) {
       result.add(node.getId());
     }
     tx.success();
     return result;
   } finally {
     tx.finish();
   }
 }
예제 #18
0
  public Collection<Long> getIndexedRelationships(String indexName, String key, Object value)
      throws DatabaseBlockedException {

    Index<Relationship> index = database.getRelationshipIndex(indexName);
    Transaction tx = database.graph.beginTx();
    try {
      Collection<Long> result = new ArrayList<Long>();
      for (Relationship relationship : index.get(key, value)) {
        result.add(relationship.getId());
      }
      tx.success();
      return result;
    } finally {
      tx.finish();
    }
  }
예제 #19
0
 @SuppressWarnings("unchecked")
 public ConsoleService(
     @Context Configuration config,
     @Context Database database,
     @Context HttpServletRequest req,
     @Context OutputFormat output,
     @Context CypherExecutor cypherExecutor) {
   this(
       new SessionFactoryImpl(
           req.getSession(true),
           config.getList(MANAGEMENT_CONSOLE_ENGINES, DEFAULT_MANAGEMENT_CONSOLE_ENGINES),
           cypherExecutor),
       database,
       database.getLogging(),
       output);
 }
예제 #20
0
 public Index<Node> createNodeIndex(String named) {
   return database.getIndexManager().forNodes(named);
 }
예제 #21
0
 public String[] getRelationshipIndexes() {
   return database.getIndexManager().relationshipIndexNames();
 }
예제 #22
0
 public Index<Relationship> getRelationshipIndex(String indexName) {
   return database.getIndexManager().forRelationships(indexName);
 }
예제 #23
0
 @After
 public void tearDown() {
   db.getGraph().shutdown();
 }
예제 #24
0
 public Index<Node> createNodeFullTextIndex(String named) {
   return database
       .getIndexManager()
       .forNodes(named, MapUtil.stringMap(IndexManager.PROVIDER, "lucene", "type", "fulltext"));
 }
예제 #25
0
 @AfterClass
 public static void shutdownDatabase() throws Throwable {
   database.stop();
 }
 @After
 public void shutdownDatabase() throws Throwable {
   db.getGraph().shutdown();
 }
예제 #27
0
 public Index<Relationship> createRelationshipFullTextIndex(String named) {
   return database
       .getIndexManager()
       .forRelationships(
           named, MapUtil.stringMap(IndexManager.PROVIDER, "lucene", "type", "fulltext"));
 }
예제 #28
0
 public Index<Relationship> createRelationshipIndex(String named) {
   return database.getIndexManager().forRelationships(named);
 }
 @Before
 public void setUp() throws Exception {
   db = new WrappingDatabase(new ImpermanentGraphDatabase());
   sampleable = new PropertyCountSampleable(db.getGraph());
 }
예제 #30
0
 public Index<Node> getNodeIndex(String indexName) {
   return database.getIndexManager().forNodes(indexName);
 }