Search in sources :

Example 1 with Statement

use of com.google.api.ads.admanager.jaxws.v202205.Statement in project globalbioticinteractions by globalbioticinteractions.

the class CypherQueryExecutorIT method executeBoltQuery.

@Test
public void executeBoltQuery() {
    Driver driver = GraphDatabase.driver("bolt://preston:7687", AuthTokens.none());
    Session session = driver.session(AccessMode.READ);
    try (Transaction transaction = session.beginTransaction()) {
        String s = "CYPHER 2.3 START dataset = node:datasets({namespace}) RETURN dataset.namespace LIMIT 1";
        Statement statement = new Statement(s, new TreeMap<String, Object>() {

            {
                put("namespace", "namespace:\"globalbioticinteractions/template-dataset\"");
            }
        });
        StatementResult run = transaction.run(statement);
        run.stream().map(r -> r.asMap()).forEach(System.out::println);
        transaction.success();
    }
}
Also used : Driver(org.neo4j.driver.v1.Driver) CypherUtil(org.eol.globi.util.CypherUtil) AccessMode(org.neo4j.driver.v1.AccessMode) Assert.assertNotNull(org.junit.Assert.assertNotNull) AuthTokens(org.neo4j.driver.v1.AuthTokens) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) Test(org.junit.Test) IOException(java.io.IOException) Transaction(org.neo4j.driver.v1.Transaction) CypherQuery(org.eol.globi.util.CypherQuery) Is(org.hamcrest.core.Is) Statement(org.neo4j.driver.v1.Statement) StringContains.containsString(org.hamcrest.core.StringContains.containsString) Session(org.neo4j.driver.v1.Session) TreeMap(java.util.TreeMap) StatementResult(org.neo4j.driver.v1.StatementResult) MatcherAssert.assertThat(org.hamcrest.MatcherAssert.assertThat) GraphDatabase(org.neo4j.driver.v1.GraphDatabase) Collections(java.util.Collections) StatementResult(org.neo4j.driver.v1.StatementResult) Transaction(org.neo4j.driver.v1.Transaction) Statement(org.neo4j.driver.v1.Statement) Driver(org.neo4j.driver.v1.Driver) StringContains.containsString(org.hamcrest.core.StringContains.containsString) Session(org.neo4j.driver.v1.Session) Test(org.junit.Test)

Example 2 with Statement

use of com.google.api.ads.admanager.jaxws.v202205.Statement in project open-kilda by telstra.

the class NeoDriver method getPath.

/**
 * {@inheritDoc}
 */
@Override
public ImmutablePair<PathInfoData, PathInfoData> getPath(Flow flow, Strategy strategy) throws UnroutablePathException {
    long latency = 0L;
    List<PathNode> forwardNodes = new LinkedList<>();
    List<PathNode> reverseNodes = new LinkedList<>();
    if (!flow.isOneSwitchFlow()) {
        Statement statement = getPathQuery(flow, strategy);
        logger.debug("QUERY: {}", statement.toString());
        try (Session session = driver.session()) {
            StatementResult result = session.run(statement);
            try {
                Record record = result.next();
                LinkedList<Relationship> isls = new LinkedList<>();
                record.get(0).asPath().relationships().forEach(isls::add);
                int seqId = 0;
                for (Relationship isl : isls) {
                    latency += isl.get("latency").asLong();
                    forwardNodes.add(new PathNode(isl.get("src_switch").asString(), isl.get("src_port").asInt(), seqId, isl.get("latency").asLong()));
                    seqId++;
                    forwardNodes.add(new PathNode(isl.get("dst_switch").asString(), isl.get("dst_port").asInt(), seqId, 0L));
                    seqId++;
                }
                seqId = 0;
                Collections.reverse(isls);
                for (Relationship isl : isls) {
                    reverseNodes.add(new PathNode(isl.get("dst_switch").asString(), isl.get("dst_port").asInt(), seqId, isl.get("latency").asLong()));
                    seqId++;
                    reverseNodes.add(new PathNode(isl.get("src_switch").asString(), isl.get("src_port").asInt(), seqId, 0L));
                    seqId++;
                }
            } catch (NoSuchRecordException e) {
                throw new UnroutablePathException(flow);
            }
        }
    } else {
        logger.info("No path computation for one-switch flow");
    }
    return new ImmutablePair<>(new PathInfoData(latency, forwardNodes), new PathInfoData(latency, reverseNodes));
}
Also used : StatementResult(org.neo4j.driver.v1.StatementResult) Statement(org.neo4j.driver.v1.Statement) PathNode(org.openkilda.messaging.info.event.PathNode) PathInfoData(org.openkilda.messaging.info.event.PathInfoData) ImmutablePair(org.openkilda.messaging.model.ImmutablePair) Relationship(org.neo4j.driver.v1.types.Relationship) Record(org.neo4j.driver.v1.Record) NoSuchRecordException(org.neo4j.driver.v1.exceptions.NoSuchRecordException) Session(org.neo4j.driver.v1.Session)

Example 3 with Statement

use of com.google.api.ads.admanager.jaxws.v202205.Statement in project googleads-java-lib by googleads.

the class StatementBuilder method toStatement.

/**
 * Gets the {@link Statement} representing the state of this statement builder.
 *
 * @return the {@link Statement}
 */
public Statement toStatement() {
    Statement statement = new Statement();
    statement.setQuery(queryBuilder.buildQuery());
    statement.setValues(Maps.toList(queryBuilder.getBindVariableMap(), String_ValueMapEntry.class).toArray(new String_ValueMapEntry[] {}));
    return statement;
}
Also used : String_ValueMapEntry(com.google.api.ads.admanager.axis.v202105.String_ValueMapEntry) Statement(com.google.api.ads.admanager.axis.v202105.Statement)

Example 4 with Statement

use of com.google.api.ads.admanager.jaxws.v202205.Statement in project googleads-java-lib by googleads.

the class StatementBuilderTest method testSelect.

@Test
public void testSelect() {
    StatementBuilder statementBuilder = new StatementBuilder();
    Statement statement = statementBuilder.select("id, name").toStatement();
    assertEquals("SELECT id, name", statement.getQuery());
}
Also used : Statement(com.google.api.ads.admanager.axis.v202105.Statement) Test(org.junit.Test)

Example 5 with Statement

use of com.google.api.ads.admanager.jaxws.v202205.Statement in project googleads-java-lib by googleads.

the class StatementBuilderTest method testWhere.

@Test
public void testWhere() {
    StatementBuilder statementBuilder = new StatementBuilder();
    Statement statement = statementBuilder.where("id = 12345").toStatement();
    assertEquals("WHERE id = 12345", statement.getQuery());
}
Also used : Statement(com.google.api.ads.admanager.axis.v202105.Statement) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)77 Statement (com.google.api.ads.admanager.axis.v202105.Statement)16 Statement (com.google.api.ads.admanager.axis.v202108.Statement)16 Statement (com.google.api.ads.admanager.axis.v202111.Statement)16 Statement (com.google.api.ads.admanager.axis.v202202.Statement)16 Statement (com.google.api.ads.admanager.axis.v202205.Statement)16 Statement (org.neo4j.driver.v1.Statement)5 String_ValueMapEntry (com.google.api.ads.admanager.axis.v202105.String_ValueMapEntry)4 String_ValueMapEntry (com.google.api.ads.admanager.axis.v202108.String_ValueMapEntry)4 String_ValueMapEntry (com.google.api.ads.admanager.axis.v202111.String_ValueMapEntry)4 String_ValueMapEntry (com.google.api.ads.admanager.axis.v202202.String_ValueMapEntry)4 String_ValueMapEntry (com.google.api.ads.admanager.axis.v202205.String_ValueMapEntry)4 Session (org.neo4j.driver.v1.Session)3 StatementResult (org.neo4j.driver.v1.StatementResult)3 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)2 Neo4JGraph (com.steelbridgelabs.oss.neo4j.structure.Neo4JGraph)2 IOException (java.io.IOException)2 Collections (java.util.Collections)2 TreeMap (java.util.TreeMap)2 CypherQuery (org.eol.globi.util.CypherQuery)2