Search in sources :

Example 61 with Statement

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

the class UpdateCreatives method runExample.

/**
 * Runs the example.
 *
 * @param adManagerServices the services factory.
 * @param session the session.
 * @param creativeId the ID of the creative to update.
 * @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, long creativeId) throws RemoteException {
    // Get the CreativeService.
    CreativeServiceInterface creativeService = adManagerServices.get(session, CreativeServiceInterface.class);
    // Create a statement to only select a single creative by ID.
    StatementBuilder statementBuilder = new StatementBuilder().where("id = :id").orderBy("id ASC").limit(1).withBindVariableValue("id", creativeId);
    // Get the creative.
    CreativePage page = creativeService.getCreativesByStatement(statementBuilder.toStatement());
    Creative creative = Iterables.getOnlyElement(Arrays.asList(page.getResults()));
    // Only update the destination URL if it has one.
    if (creative instanceof HasDestinationUrlCreative) {
        HasDestinationUrlCreative hasDestinationUrlCreative = (HasDestinationUrlCreative) creative;
        // Update the destination URL of the creative.
        hasDestinationUrlCreative.setDestinationUrl("http://news.google.com");
        // Update the creative on the server.
        Creative[] creatives = creativeService.updateCreatives(new Creative[] { creative });
        for (Creative updatedCreative : creatives) {
            System.out.printf("Creative with ID %d and name '%s' was updated.%n", updatedCreative.getId(), updatedCreative.getName());
        }
    } else {
        System.out.println("No creatives were updated.");
    }
}
Also used : HasDestinationUrlCreative(com.google.api.ads.admanager.axis.v202108.HasDestinationUrlCreative) Creative(com.google.api.ads.admanager.axis.v202108.Creative) HasDestinationUrlCreative(com.google.api.ads.admanager.axis.v202108.HasDestinationUrlCreative) CreativeServiceInterface(com.google.api.ads.admanager.axis.v202108.CreativeServiceInterface) StatementBuilder(com.google.api.ads.admanager.axis.utils.v202108.StatementBuilder) CreativePage(com.google.api.ads.admanager.axis.v202108.CreativePage)

Example 62 with Statement

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

Example 63 with Statement

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

the class StatementBuilderTest method testOrderBy.

@Test
public void testOrderBy() {
    StatementBuilder statementBuilder = new StatementBuilder();
    Statement statement = statementBuilder.orderBy("id ASC").toStatement();
    assertEquals("ORDER BY id ASC", statement.getQuery());
}
Also used : Statement(com.google.api.ads.admanager.axis.v202105.Statement) Test(org.junit.Test)

Example 64 with Statement

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

the class StatementBuilderTest method testFrom.

@Test
public void testFrom() {
    StatementBuilder statementBuilder = new StatementBuilder();
    Statement statement = statementBuilder.from("line_item").toStatement();
    assertEquals("FROM line_item", statement.getQuery());
}
Also used : Statement(com.google.api.ads.admanager.axis.v202105.Statement) Test(org.junit.Test)

Example 65 with Statement

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

the class StatementBuilderTest method testBindVariables_bool.

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

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