Search in sources :

Example 91 with Statement

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

the class StatementBuilderTest method testRemoveLimitAndOffset.

@Test
public void testRemoveLimitAndOffset() {
    StatementBuilder statementBuilder = new StatementBuilder();
    Statement initialOffset = statementBuilder.where("id = 1").limit(100).offset(100).toStatement();
    assertEquals("WHERE id = 1 LIMIT 100 OFFSET 100", initialOffset.getQuery());
    Statement removed = statementBuilder.removeLimitAndOffset().toStatement();
    assertEquals("WHERE id = 1", removed.getQuery());
}
Also used : Statement(com.google.api.ads.admanager.axis.v202108.Statement) Test(org.junit.Test)

Example 92 with Statement

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

the class StatementBuilderTest method testBindVariables_number.

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

Example 93 with Statement

use of com.google.api.ads.admanager.axis.v202111.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.v202111.String_ValueMapEntry) Statement(com.google.api.ads.admanager.axis.v202111.Statement)

Example 94 with Statement

use of com.google.api.ads.admanager.axis.v202111.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.v202202.String_ValueMapEntry) Statement(com.google.api.ads.admanager.axis.v202202.Statement)

Example 95 with Statement

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

the class GetRecentlyModifiedContent 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 ContentService.
    ContentServiceInterface contentService = adManagerServices.get(session, ContentServiceInterface.class);
    // Create a statement to get recently modified content based on lastModifiedDateTime.
    // Changes to content bundle associations will update the lastModifiedDateTime, but
    // CMS metadata changes may not change the lastModifiedDateTime.
    StatementBuilder statementBuilder = new StatementBuilder().where("lastModifiedDateTime > :lastModifiedDateTime").orderBy("id ASC").limit(StatementBuilder.SUGGESTED_PAGE_LIMIT).withBindVariableValue("lastModifiedDateTime", DateTimes.toDateTime(Instant.now().minus(Duration.standardDays(1L)), "America/New_York"));
    // Default for total result set size.
    int totalResultSetSize = 0;
    do {
        // Get content by statement.
        ContentPage page = contentService.getContentByStatement(statementBuilder.toStatement());
        if (page.getResults() != null) {
            totalResultSetSize = page.getTotalResultSetSize();
            int i = page.getStartIndex();
            for (Content content : page.getResults()) {
                String contentBundleIds = content.getContentBundleIds() == null ? "[]" : Arrays.toString(content.getContentBundleIds());
                System.out.printf("%d) Content with ID %d and name '%s' belonging to bundle IDs %s was found.%n", i++, content.getId(), content.getName(), contentBundleIds);
            }
        }
        statementBuilder.increaseOffsetBy(StatementBuilder.SUGGESTED_PAGE_LIMIT);
    } while (statementBuilder.getOffset() < totalResultSetSize);
    System.out.printf("Number of results found: %d%n", totalResultSetSize);
}
Also used : ContentServiceInterface(com.google.api.ads.admanager.axis.v202111.ContentServiceInterface) Content(com.google.api.ads.admanager.axis.v202111.Content) StatementBuilder(com.google.api.ads.admanager.axis.utils.v202111.StatementBuilder) ContentPage(com.google.api.ads.admanager.axis.v202111.ContentPage)

Aggregations

StatementBuilder (com.google.api.ads.admanager.axis.utils.v202111.StatementBuilder)119 Test (org.junit.Test)77 UpdateResult (com.google.api.ads.admanager.axis.v202111.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)16 Statement (com.google.api.ads.admanager.axis.v202205.Statement)16 CustomTargetingServiceInterface (com.google.api.ads.admanager.axis.v202111.CustomTargetingServiceInterface)8 InventoryServiceInterface (com.google.api.ads.admanager.axis.v202111.InventoryServiceInterface)8 AdUnit (com.google.api.ads.admanager.axis.v202111.AdUnit)7 AdUnitPage (com.google.api.ads.admanager.axis.v202111.AdUnitPage)7 PublisherQueryLanguageServiceInterface (com.google.api.ads.admanager.axis.v202111.PublisherQueryLanguageServiceInterface)7 ResultSet (com.google.api.ads.admanager.axis.v202111.ResultSet)7 ArrayList (java.util.ArrayList)6 ProposalServiceInterface (com.google.api.ads.admanager.axis.v202111.ProposalServiceInterface)5 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 LineItem (com.google.api.ads.admanager.axis.v202111.LineItem)4