Search in sources :

Example 86 with Statement

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

the class StatementBuilderTest method testBindVariables_text.

@Test
public void testBindVariables_text() {
    StatementBuilder statementBuilder = new StatementBuilder();
    Statement statement = statementBuilder.where("text = :text").withBindVariableValue("text", "foo").toStatement();
    String_ValueMapEntry entry = statement.getValues(0);
    assertEquals("text", entry.getKey());
    assertEquals(TextValue.class, entry.getValue().getClass());
    assertEquals("foo", ((TextValue) entry.getValue()).getValue());
}
Also used : String_ValueMapEntry(com.google.api.ads.admanager.axis.v202111.String_ValueMapEntry) Statement(com.google.api.ads.admanager.axis.v202111.Statement) Test(org.junit.Test)

Example 87 with Statement

use of com.google.api.ads.admanager.axis.v202108.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 88 with Statement

use of com.google.api.ads.admanager.axis.v202108.Statement in project eol-globi-data by jhpoelen.

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) 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) 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) 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 89 with Statement

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

the class GetAllCustomTargetingKeysAndValues method getAllCustomTargetingKeyIds.

/**
 * Gets all custom targeting key IDs.
 */
private static List<Long> getAllCustomTargetingKeyIds(AdManagerServices adManagerServices, AdManagerSession session) throws RemoteException {
    List<Long> customTargetingKeyIds = new ArrayList<>();
    // Get the CustomTargetingService.
    CustomTargetingServiceInterface customTargetingService = adManagerServices.get(session, CustomTargetingServiceInterface.class);
    // Create a statement to get all custom targeting keys.
    StatementBuilder statementBuilder = new StatementBuilder().orderBy("id ASC").limit(StatementBuilder.SUGGESTED_PAGE_LIMIT);
    // Default for total result set size.
    int totalResultSetSize = 0;
    do {
        // Get custom targeting keys by statement.
        CustomTargetingKeyPage page = customTargetingService.getCustomTargetingKeysByStatement(statementBuilder.toStatement());
        if (page.getResults() != null) {
            totalResultSetSize = page.getTotalResultSetSize();
            int i = page.getStartIndex();
            for (CustomTargetingKey customTargetingKey : page.getResults()) {
                System.out.printf("%d) Custom targeting key with ID %d, name '%s', and " + "display name '%s' was found.%n", i++, customTargetingKey.getId(), customTargetingKey.getName(), customTargetingKey.getDisplayName());
                customTargetingKeyIds.add(customTargetingKey.getId());
            }
        }
        statementBuilder.increaseOffsetBy(StatementBuilder.SUGGESTED_PAGE_LIMIT);
    } while (statementBuilder.getOffset() < totalResultSetSize);
    return customTargetingKeyIds;
}
Also used : CustomTargetingServiceInterface(com.google.api.ads.admanager.axis.v202108.CustomTargetingServiceInterface) CustomTargetingKey(com.google.api.ads.admanager.axis.v202108.CustomTargetingKey) StatementBuilder(com.google.api.ads.admanager.axis.utils.v202108.StatementBuilder) ArrayList(java.util.ArrayList) CustomTargetingKeyPage(com.google.api.ads.admanager.axis.v202108.CustomTargetingKeyPage)

Example 90 with Statement

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

the class GetAllCustomTargetingKeysAndValues method runExample.

/**
 * Runs the example.
 *
 * @param adManagerServices the services factory.
 * @param session the session.
 * @throws ApiException if the API request failed with one or more service errors.
 * @throws RemoteException if the API request failed due to other errors.
 */
public static void runExample(AdManagerServices adManagerServices, AdManagerSession session) throws RemoteException {
    // Get the CustomTargetingService.
    CustomTargetingServiceInterface customTargetingService = adManagerServices.get(session, CustomTargetingServiceInterface.class);
    // Get all custom targeting keys.
    List<Long> customTargetingKeyIds = getAllCustomTargetingKeyIds(adManagerServices, session);
    // Create a statement to get all custom targeting values for a custom
    // targeting key.
    StatementBuilder statementBuilder = new StatementBuilder().where("customTargetingKeyId = :customTargetingKeyId").orderBy("id ASC").limit(StatementBuilder.SUGGESTED_PAGE_LIMIT);
    int totalResultsCounter = 0;
    for (Long customTargetingKeyId : customTargetingKeyIds) {
        // Set the custom targeting key ID to select from.
        statementBuilder.withBindVariableValue("customTargetingKeyId", customTargetingKeyId);
        // Default for total result set size and offset.
        int totalResultSetSize = 0;
        statementBuilder.offset(0);
        do {
            // Get custom targeting values by statement.
            CustomTargetingValuePage page = customTargetingService.getCustomTargetingValuesByStatement(statementBuilder.toStatement());
            if (page.getResults() != null) {
                totalResultSetSize = page.getTotalResultSetSize();
                for (CustomTargetingValue customTargetingValue : page.getResults()) {
                    System.out.printf("%d) Custom targeting value with ID %d, belonging to key " + "with ID %d, name '%s' and display name '%s' was found.%n", totalResultsCounter++, customTargetingValue.getId(), customTargetingValue.getCustomTargetingKeyId(), customTargetingValue.getName(), customTargetingValue.getDisplayName());
                }
            }
            statementBuilder.increaseOffsetBy(StatementBuilder.SUGGESTED_PAGE_LIMIT);
        } while (statementBuilder.getOffset() < totalResultSetSize);
    }
    System.out.printf("Number of results found: %d%n", totalResultsCounter);
}
Also used : CustomTargetingValue(com.google.api.ads.admanager.axis.v202108.CustomTargetingValue) CustomTargetingServiceInterface(com.google.api.ads.admanager.axis.v202108.CustomTargetingServiceInterface) StatementBuilder(com.google.api.ads.admanager.axis.utils.v202108.StatementBuilder) CustomTargetingValuePage(com.google.api.ads.admanager.axis.v202108.CustomTargetingValuePage)

Aggregations

StatementBuilder (com.google.api.ads.admanager.axis.utils.v202108.StatementBuilder)119 Test (org.junit.Test)61 UpdateResult (com.google.api.ads.admanager.axis.v202108.UpdateResult)18 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)13 CustomTargetingServiceInterface (com.google.api.ads.admanager.axis.v202108.CustomTargetingServiceInterface)8 InventoryServiceInterface (com.google.api.ads.admanager.axis.v202108.InventoryServiceInterface)8 AdUnit (com.google.api.ads.admanager.axis.v202108.AdUnit)7 AdUnitPage (com.google.api.ads.admanager.axis.v202108.AdUnitPage)7 PublisherQueryLanguageServiceInterface (com.google.api.ads.admanager.axis.v202108.PublisherQueryLanguageServiceInterface)7 ResultSet (com.google.api.ads.admanager.axis.v202108.ResultSet)7 LineItem (com.google.api.ads.admanager.axis.v202108.LineItem)6 LineItemPage (com.google.api.ads.admanager.axis.v202108.LineItemPage)6 LineItemServiceInterface (com.google.api.ads.admanager.axis.v202108.LineItemServiceInterface)6 CustomFieldServiceInterface (com.google.api.ads.admanager.axis.v202108.CustomFieldServiceInterface)5 Creative (com.google.api.ads.admanager.axis.v202108.Creative)4 CreativeServiceInterface (com.google.api.ads.admanager.axis.v202108.CreativeServiceInterface)4 Label (com.google.api.ads.admanager.axis.v202108.Label)4