Search in sources :

Example 1 with PropertyContainer

use of org.neo4j.graphdb.PropertyContainer in project neo4j by neo4j.

the class TestGraphProperties method basicProperties.

@Test
public void basicProperties() throws Exception {
    GraphDatabaseAPI db = (GraphDatabaseAPI) factory.newImpermanentDatabase();
    PropertyContainer graphProperties = properties(db);
    assertThat(graphProperties, inTx(db, not(hasProperty("test"))));
    Transaction tx = db.beginTx();
    graphProperties.setProperty("test", "yo");
    assertEquals("yo", graphProperties.getProperty("test"));
    tx.success();
    tx.close();
    assertThat(graphProperties, inTx(db, hasProperty("test").withValue("yo")));
    tx = db.beginTx();
    assertNull(graphProperties.removeProperty("something non existent"));
    assertEquals("yo", graphProperties.removeProperty("test"));
    assertNull(graphProperties.getProperty("test", null));
    graphProperties.setProperty("other", 10);
    assertEquals(10, graphProperties.getProperty("other"));
    graphProperties.setProperty("new", "third");
    tx.success();
    tx.close();
    assertThat(graphProperties, inTx(db, not(hasProperty("test"))));
    assertThat(graphProperties, inTx(db, hasProperty("other").withValue(10)));
    assertThat(getPropertyKeys(db, graphProperties), containsOnly("other", "new"));
    tx = db.beginTx();
    graphProperties.setProperty("rollback", true);
    assertEquals(true, graphProperties.getProperty("rollback"));
    tx.close();
    assertThat(graphProperties, inTx(db, not(hasProperty("rollback"))));
    db.shutdown();
}
Also used : PropertyContainer(org.neo4j.graphdb.PropertyContainer) GraphDatabaseAPI(org.neo4j.kernel.internal.GraphDatabaseAPI) Transaction(org.neo4j.graphdb.Transaction) Test(org.junit.Test)

Example 2 with PropertyContainer

use of org.neo4j.graphdb.PropertyContainer in project neo4j by neo4j.

the class TestGraphProperties method shouldBeAbleToCreateLongGraphPropertyChainsAndReadTheCorrectNextPointerFromTheStore.

@Test
public void shouldBeAbleToCreateLongGraphPropertyChainsAndReadTheCorrectNextPointerFromTheStore() {
    GraphDatabaseService database = factory.newImpermanentDatabase();
    PropertyContainer graphProperties = properties((GraphDatabaseAPI) database);
    try (Transaction tx = database.beginTx()) {
        graphProperties.setProperty("a", new String[] { "A", "B", "C", "D", "E" });
        graphProperties.setProperty("b", true);
        graphProperties.setProperty("c", "C");
        tx.success();
    }
    try (Transaction tx = database.beginTx()) {
        graphProperties.setProperty("d", new String[] { "A", "F" });
        graphProperties.setProperty("e", true);
        graphProperties.setProperty("f", "F");
        tx.success();
    }
    try (Transaction tx = database.beginTx()) {
        graphProperties.setProperty("g", new String[] { "F" });
        graphProperties.setProperty("h", false);
        graphProperties.setProperty("i", "I");
        tx.success();
    }
    try (Transaction tx = database.beginTx()) {
        assertArrayEquals(new String[] { "A", "B", "C", "D", "E" }, (String[]) graphProperties.getProperty("a"));
        assertTrue((boolean) graphProperties.getProperty("b"));
        assertEquals("C", graphProperties.getProperty("c"));
        assertArrayEquals(new String[] { "A", "F" }, (String[]) graphProperties.getProperty("d"));
        assertTrue((boolean) graphProperties.getProperty("e"));
        assertEquals("F", graphProperties.getProperty("f"));
        assertArrayEquals(new String[] { "F" }, (String[]) graphProperties.getProperty("g"));
        assertFalse((boolean) graphProperties.getProperty("h"));
        assertEquals("I", graphProperties.getProperty("i"));
        tx.success();
    }
    database.shutdown();
}
Also used : GraphDatabaseService(org.neo4j.graphdb.GraphDatabaseService) PropertyContainer(org.neo4j.graphdb.PropertyContainer) Transaction(org.neo4j.graphdb.Transaction) Test(org.junit.Test)

Example 3 with PropertyContainer

use of org.neo4j.graphdb.PropertyContainer in project neo4j by neo4j.

the class TestGraphProperties method graphPropertiesAreLockedPerTx.

@Test
public void graphPropertiesAreLockedPerTx() throws Exception {
    GraphDatabaseAPI db = (GraphDatabaseAPI) factory.newImpermanentDatabase();
    Worker worker1 = new Worker("W1", new State(db));
    Worker worker2 = new Worker("W2", new State(db));
    PropertyContainer properties = properties(db);
    worker1.beginTx();
    worker2.beginTx();
    String key1 = "name";
    String value1 = "Value 1";
    String key2 = "some other property";
    String value2 = "Value 2";
    String key3 = "say";
    String value3 = "hello";
    worker1.setProperty(key1, value1).get();
    assertThat(properties, inTx(db, not(hasProperty(key1))));
    assertFalse(worker2.hasProperty(key1));
    Future<Void> blockedSetProperty = worker2.setProperty(key2, value2);
    assertThat(properties, inTx(db, not(hasProperty(key1))));
    assertThat(properties, inTx(db, not(hasProperty(key2))));
    worker1.setProperty(key3, value3).get();
    assertFalse(blockedSetProperty.isDone());
    assertThat(properties, inTx(db, not(hasProperty(key1))));
    assertThat(properties, inTx(db, not(hasProperty(key2))));
    assertThat(properties, inTx(db, not(hasProperty(key3))));
    worker1.commitTx();
    assertThat(properties, inTx(db, hasProperty(key1)));
    assertThat(properties, inTx(db, not(hasProperty(key2))));
    assertThat(properties, inTx(db, hasProperty(key3)));
    blockedSetProperty.get();
    assertTrue(blockedSetProperty.isDone());
    worker2.commitTx();
    assertThat(properties, inTx(db, hasProperty(key1).withValue(value1)));
    assertThat(properties, inTx(db, hasProperty(key2).withValue(value2)));
    assertThat(properties, inTx(db, hasProperty(key3).withValue(value3)));
    worker1.close();
    worker2.close();
    db.shutdown();
}
Also used : PropertyContainer(org.neo4j.graphdb.PropertyContainer) GraphDatabaseAPI(org.neo4j.kernel.internal.GraphDatabaseAPI) Test(org.junit.Test)

Example 4 with PropertyContainer

use of org.neo4j.graphdb.PropertyContainer in project neo4j by neo4j.

the class TestGraphProperties method testEquals.

@Test
public void testEquals() {
    GraphDatabaseAPI db = (GraphDatabaseAPI) factory.newImpermanentDatabase();
    PropertyContainer graphProperties = properties(db);
    try (Transaction tx = db.beginTx()) {
        graphProperties.setProperty("test", "test");
        tx.success();
    }
    assertEquals(graphProperties, properties(db));
    db.shutdown();
    db = (GraphDatabaseAPI) factory.newImpermanentDatabase();
    assertFalse(graphProperties.equals(properties(db)));
    db.shutdown();
}
Also used : PropertyContainer(org.neo4j.graphdb.PropertyContainer) GraphDatabaseAPI(org.neo4j.kernel.internal.GraphDatabaseAPI) Transaction(org.neo4j.graphdb.Transaction) Test(org.junit.Test)

Example 5 with PropertyContainer

use of org.neo4j.graphdb.PropertyContainer in project neo4j by neo4j.

the class IndexProviderShellApp method exec.

@Override
protected Continuation exec(AppCommandParser parser, Session session, Output out) throws ShellException, RemoteException {
    boolean doCd = parser.options().containsKey("cd");
    boolean doLs = parser.options().containsKey("ls");
    boolean query = parser.options().containsKey("q");
    boolean get = parser.options().containsKey("g") || query || doCd || doLs;
    boolean index = parser.options().containsKey("i");
    boolean remove = parser.options().containsKey("r");
    boolean getConfig = parser.options().containsKey("get-config");
    boolean create = parser.options().containsKey("create");
    boolean setConfig = parser.options().containsKey("set-config");
    boolean delete = parser.options().containsKey("delete");
    boolean indexes = parser.options().containsKey("indexes");
    int count = boolCount(get, index, remove, getConfig, create, setConfig, delete, indexes);
    if (count != 1) {
        throw new ShellException("Supply one of: -g, -i, -r, --get-config, --set-config, --create, --delete, --indexes");
    }
    if (get) {
        String commandToRun = parser.options().get("c");
        Collection<String> commandsToRun = new ArrayList<String>();
        boolean specialCommand = false;
        if (doCd || doLs) {
            specialCommand = true;
            if (doCd) {
                commandsToRun.add("cd -a $i");
            } else if (doLs) {
                commandsToRun.add("ls $i");
            }
        } else if (commandToRun != null) {
            commandsToRun.addAll(Arrays.asList(commandToRun.split(Pattern.quote("&&"))));
        }
        if (getIndex(getIndexName(parser), getEntityType(parser), out) == null) {
            return Continuation.INPUT_COMPLETE;
        }
        IndexHits<PropertyContainer> result = query ? query(parser, out) : get(parser, out);
        try {
            for (PropertyContainer hit : result) {
                printAndInterpretTemplateLines(commandsToRun, false, !specialCommand, NodeOrRelationship.wrap(hit), getServer(), session, out);
            }
        } finally {
            result.close();
        }
    } else if (index) {
        index(parser, session, out);
    } else if (remove) {
        if (getIndex(getIndexName(parser), Node.class, out) == null) {
            return null;
        }
        remove(parser, session, out);
    } else if (getConfig) {
        displayConfig(parser, out);
    } else if (create) {
        createIndex(parser, out);
    } else if (setConfig) {
        setConfig(parser, out);
    } else if (delete) {
        deleteIndex(parser, out);
    }
    if (indexes) {
        listIndexes(out);
    }
    return Continuation.INPUT_COMPLETE;
}
Also used : PropertyContainer(org.neo4j.graphdb.PropertyContainer) Node(org.neo4j.graphdb.Node) ArrayList(java.util.ArrayList) ShellException(org.neo4j.shell.ShellException)

Aggregations

PropertyContainer (org.neo4j.graphdb.PropertyContainer)36 Test (org.junit.Test)11 Node (org.neo4j.graphdb.Node)11 LinkedList (java.util.LinkedList)8 Relationship (org.neo4j.graphdb.Relationship)7 Transaction (org.neo4j.graphdb.Transaction)6 HashSet (java.util.HashSet)4 IOException (java.io.IOException)3 List (java.util.List)3 Map (java.util.Map)3 GraphDatabaseAPI (org.neo4j.kernel.GraphDatabaseAPI)3 GraphDatabaseAPI (org.neo4j.kernel.internal.GraphDatabaseAPI)3 HashMap (java.util.HashMap)2 SystemException (javax.transaction.SystemException)2 NotFoundException (org.neo4j.graphdb.NotFoundException)2 Path (org.neo4j.graphdb.Path)2 TransactionFailureException (org.neo4j.graphdb.TransactionFailureException)2 ArrayBackedList (apoc.util.ArrayBackedList)1 ArrayList (java.util.ArrayList)1 Collection (java.util.Collection)1