Search in sources :

Example 61 with Record

use of nikita.model.noark5.v4.Record in project cypher-for-gremlin by opencypher.

the class GremlinNeo4jDriverTest method returnPath.

@Test
public void returnPath() {
    Driver driver = GremlinDatabase.driver("//localhost:" + server.getPort());
    try (Session session = driver.session()) {
        StatementResult setup = session.run("CREATE (n1:Person {name: 'Anders'})-[r:knows]->(n2:Person)" + "RETURN n1,r,n2");
        Record createdNodes = setup.single();
        Node n1 = createdNodes.get("n1").asNode();
        Node n2 = createdNodes.get("n2").asNode();
        Relationship r = createdNodes.get("r").asRelationship();
        StatementResult result = session.run("MATCH p =(b1 { name: 'Anders' })-->()" + "RETURN p");
        Path path = result.single().get("p").asPath();
        assertThat(path.contains(n1)).isTrue();
        assertThat(path.contains(n2)).isTrue();
        assertThat(path.contains(r)).isTrue();
        assertThat(path.relationships()).hasSize(1);
        assertThat(path.nodes()).hasSize(2);
    }
}
Also used : Path(org.neo4j.driver.v1.types.Path) StatementResult(org.neo4j.driver.v1.StatementResult) Node(org.neo4j.driver.v1.types.Node) Relationship(org.neo4j.driver.v1.types.Relationship) Driver(org.neo4j.driver.v1.Driver) Record(org.neo4j.driver.v1.Record) Session(org.neo4j.driver.v1.Session) Test(org.junit.Test)

Example 62 with Record

use of nikita.model.noark5.v4.Record in project structr by structr.

the class SessionTransaction method getStrings.

public QueryResult<String> getStrings(final String statement, final Map<String, Object> map) {
    final long t0 = System.currentTimeMillis();
    try {
        final StatementResult result = tx.run(statement, map);
        final Record record = result.next();
        final Value value = record.get(0);
        return new QueryResult<String>() {

            @Override
            public void close() {
                result.consume();
            }

            @Override
            public Iterator<String> iterator() {
                return value.asList(Values.ofString()).iterator();
            }
        };
    } catch (TransientException tex) {
        closed = true;
        throw new RetryException(tex);
    } catch (NoSuchRecordException nex) {
        throw new NotFoundException(nex);
    } catch (ServiceUnavailableException ex) {
        throw new NetworkException(ex.getMessage(), ex);
    } finally {
        logQuery(statement, map, t0);
    }
}
Also used : StatementResult(org.neo4j.driver.v1.StatementResult) QueryResult(org.structr.api.QueryResult) TransientException(org.neo4j.driver.v1.exceptions.TransientException) Value(org.neo4j.driver.v1.Value) NotFoundException(org.structr.api.NotFoundException) Record(org.neo4j.driver.v1.Record) ServiceUnavailableException(org.neo4j.driver.v1.exceptions.ServiceUnavailableException) RetryException(org.structr.api.RetryException) NetworkException(org.structr.api.NetworkException) NoSuchRecordException(org.neo4j.driver.v1.exceptions.NoSuchRecordException)

Example 63 with Record

use of nikita.model.noark5.v4.Record in project wildfly-swarm by wildfly-swarm.

the class BMTStatefulTestBean method twoTransactions.

public String twoTransactions() throws Exception {
    // start the JTA transaction via javax.transaction.UserTransaction
    userTransaction.begin();
    try {
        // obtain session which will be enlisted into the JTA transaction.
        Session session = driver.session();
        if (session != driver.session()) {
            throw new RuntimeException("multiple calls to Driver.session() must return the same session within JTA transaction.");
        }
        // Calls to Session.beginTransaction() in a JTA transaction are expected to throw a RuntimeException
        try {
            Transaction transaction = session.beginTransaction();
            fail("Calling Session.beginTransaction in a JTA transaction should throw a RuntimeException.");
        } catch (RuntimeException expectedException) {
        // success
        }
        session.run("CREATE (a:Person {name:'BMT', title:'King'})");
        // calls to close the session should also be ignored, since the session is also considered to be enlisted into the JTA transaction
        session.close();
        if (session.isOpen() != true) {
            throw new RuntimeException("Session should be open since JTA transaction is still active.");
        }
        // commit the JTA transaction, which also calls org.neo4j.driver.v1.Transaction.success()/close().
        // if the JTA transaction rolls back, org.neo4j.driver.v1.Transaction.failure()/close() would instead be called.
        userTransaction.commit();
        if (session.isOpen() != false) {
            throw new RuntimeException("Session should now be closed since JTA transaction ended.");
        }
        // should be ignored
        session.close();
        // Start another JTA transaction, note that the session has to be obtained again
        userTransaction.begin();
        session = driver.session();
        if (session != driver.session()) {
            throw new RuntimeException("multiple calls to Driver.session() must return the same session within JTA transaction.");
        }
        // Calls to Session.beginTransaction() in a JTA transaction are expected to throw a RuntimeException
        try {
            Transaction transaction = session.beginTransaction();
            fail("Calling Session.beginTransaction in a JTA transaction should throw a RuntimeException.");
        } catch (RuntimeException expectedException) {
        // success
        }
        StatementResult result = session.run("MATCH (a:Person) WHERE a.name = 'BMT' RETURN a.name AS name, a.title AS title");
        Record record = result.next();
        return record.toString();
    } finally {
        if (userTransaction.getStatus() == Status.STATUS_ACTIVE) {
            // second JTA transaction is ended, which also closes the enlisted org.neo4j.driver.v1.Transaction/Session
            userTransaction.commit();
        }
        Session cleanupSession = driver.session();
        cleanupSession.run("MATCH (a:Person) delete a");
        cleanupSession.close();
    }
}
Also used : StatementResult(org.neo4j.driver.v1.StatementResult) UserTransaction(javax.transaction.UserTransaction) Transaction(org.neo4j.driver.v1.Transaction) Record(org.neo4j.driver.v1.Record) Session(org.neo4j.driver.v1.Session)

Example 64 with Record

use of nikita.model.noark5.v4.Record in project wildfly-swarm by wildfly-swarm.

the class StatefulTestBean method addPersonClassInstanceInjection.

public String addPersonClassInstanceInjection() {
    Session session = injectedDriver.session();
    try {
        session.run("CREATE (a:Person {name:'CDI', title:'King'})");
        StatementResult result = session.run("MATCH (a:Person) WHERE a.name = 'CDI' RETURN a.name AS name, a.title AS title");
        Record record = result.next();
        return record.toString();
    } finally {
        session.run("MATCH (a:Person) delete a");
        session.close();
    }
}
Also used : StatementResult(org.neo4j.driver.v1.StatementResult) Record(org.neo4j.driver.v1.Record) Session(org.neo4j.driver.v1.Session)

Example 65 with Record

use of nikita.model.noark5.v4.Record in project wildfly-swarm by wildfly-swarm.

the class StatefulTestBean method addPerson.

public String addPerson() {
    Session session = driver.session();
    try {
        session.run("CREATE (a:Person {name:'Arthur', title:'King'})");
        StatementResult result = session.run("MATCH (a:Person) WHERE a.name = 'Arthur' RETURN a.name AS name, a.title AS title");
        Record record = result.next();
        return record.toString();
    } finally {
        session.run("MATCH (a:Person) delete a");
        session.close();
    }
}
Also used : StatementResult(org.neo4j.driver.v1.StatementResult) Record(org.neo4j.driver.v1.Record) Session(org.neo4j.driver.v1.Session)

Aggregations

Test (org.junit.Test)72 Record (org.orcid.jaxb.model.record_v2.Record)62 Counted (com.codahale.metrics.annotation.Counted)28 ApiOperation (io.swagger.annotations.ApiOperation)27 ApiResponses (io.swagger.annotations.ApiResponses)27 ActivitiesSummary (org.orcid.jaxb.model.record.summary_v2.ActivitiesSummary)25 Person (org.orcid.jaxb.model.record_v2.Person)22 Email (org.orcid.jaxb.model.record_v2.Email)20 Record (nikita.model.noark5.v4.Record)19 WorkSummary (org.orcid.jaxb.model.record.summary_v2.WorkSummary)19 Address (org.orcid.jaxb.model.record_v2.Address)19 Name (org.orcid.jaxb.model.record_v2.Name)19 OtherName (org.orcid.jaxb.model.record_v2.OtherName)19 ResearcherUrl (org.orcid.jaxb.model.record_v2.ResearcherUrl)19 EducationSummary (org.orcid.jaxb.model.record.summary_v2.EducationSummary)18 EmploymentSummary (org.orcid.jaxb.model.record.summary_v2.EmploymentSummary)18 FundingSummary (org.orcid.jaxb.model.record.summary_v2.FundingSummary)18 Keyword (org.orcid.jaxb.model.record_v2.Keyword)18 PersonExternalIdentifier (org.orcid.jaxb.model.record_v2.PersonExternalIdentifier)18 Record (org.neo4j.driver.v1.Record)17