Пример #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);
 }