Search in sources :

Example 66 with UpdateResult

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

the class DeactivateUsers method runExample.

/**
 * Runs the example.
 *
 * @param adManagerServices the services factory.
 * @param session the session.
 * @param userId the ID of the user to deactivate.
 * @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 userId) throws RemoteException {
    // Get the UserService.
    UserServiceInterface userService = adManagerServices.get(session, UserServiceInterface.class);
    // Create a statement to select a user.
    StatementBuilder statementBuilder = new StatementBuilder().where("WHERE id = :id").orderBy("id ASC").limit(StatementBuilder.SUGGESTED_PAGE_LIMIT).withBindVariableValue("id", userId);
    // Default for total result set size.
    int totalResultSetSize = 0;
    do {
        // Get users by statement.
        UserPage page = userService.getUsersByStatement(statementBuilder.toStatement());
        if (page.getResults() != null) {
            totalResultSetSize = page.getTotalResultSetSize();
            int i = page.getStartIndex();
            for (User user : page.getResults()) {
                System.out.printf("%d) User with ID %d will be deactivated.%n", i++, user.getId());
            }
        }
        statementBuilder.increaseOffsetBy(StatementBuilder.SUGGESTED_PAGE_LIMIT);
    } while (statementBuilder.getOffset() < totalResultSetSize);
    System.out.printf("Number of users to be deactivated: %d%n", totalResultSetSize);
    if (totalResultSetSize > 0) {
        // Remove limit and offset from statement.
        statementBuilder.removeLimitAndOffset();
        // Create action.
        com.google.api.ads.admanager.axis.v202111.DeactivateUsers action = new com.google.api.ads.admanager.axis.v202111.DeactivateUsers();
        // Perform action.
        UpdateResult result = userService.performUserAction(action, statementBuilder.toStatement());
        if (result != null && result.getNumChanges() > 0) {
            System.out.printf("Number of users deactivated: %d%n", result.getNumChanges());
        } else {
            System.out.println("No users were deactivated.");
        }
    }
}
Also used : UserServiceInterface(com.google.api.ads.admanager.axis.v202111.UserServiceInterface) User(com.google.api.ads.admanager.axis.v202111.User) UserPage(com.google.api.ads.admanager.axis.v202111.UserPage) StatementBuilder(com.google.api.ads.admanager.axis.utils.v202111.StatementBuilder) UpdateResult(com.google.api.ads.admanager.axis.v202111.UpdateResult)

Example 67 with UpdateResult

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

the class PauseLineItems method runExample.

/**
 * Runs the example.
 *
 * @param adManagerServices the services factory.
 * @param session the session.
 * @param lineItemId the ID of the line item to pause.
 * @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 lineItemId) throws RemoteException {
    // Get the LineItemService.
    LineItemServiceInterface lineItemService = adManagerServices.get(session, LineItemServiceInterface.class);
    // Create a statement to select a line item.
    StatementBuilder statementBuilder = new StatementBuilder().where("WHERE id = :id").orderBy("id ASC").limit(StatementBuilder.SUGGESTED_PAGE_LIMIT).withBindVariableValue("id", lineItemId);
    // Default for total result set size.
    int totalResultSetSize = 0;
    do {
        // Get line items by statement.
        LineItemPage page = lineItemService.getLineItemsByStatement(statementBuilder.toStatement());
        if (page.getResults() != null) {
            totalResultSetSize = page.getTotalResultSetSize();
            int i = page.getStartIndex();
            for (LineItem lineItem : page.getResults()) {
                System.out.printf("%d) Line item with ID %d will be paused.%n", i++, lineItem.getId());
            }
        }
        statementBuilder.increaseOffsetBy(StatementBuilder.SUGGESTED_PAGE_LIMIT);
    } while (statementBuilder.getOffset() < totalResultSetSize);
    System.out.printf("Number of line items to be paused: %d%n", totalResultSetSize);
    if (totalResultSetSize > 0) {
        // Remove limit and offset from statement.
        statementBuilder.removeLimitAndOffset();
        // Create action.
        com.google.api.ads.admanager.axis.v202202.PauseLineItems action = new com.google.api.ads.admanager.axis.v202202.PauseLineItems();
        // Perform action.
        UpdateResult result = lineItemService.performLineItemAction(action, statementBuilder.toStatement());
        if (result != null && result.getNumChanges() > 0) {
            System.out.printf("Number of line items paused: %d%n", result.getNumChanges());
        } else {
            System.out.println("No line items were paused.");
        }
    }
}
Also used : LineItemServiceInterface(com.google.api.ads.admanager.axis.v202202.LineItemServiceInterface) LineItem(com.google.api.ads.admanager.axis.v202202.LineItem) LineItemPage(com.google.api.ads.admanager.axis.v202202.LineItemPage) StatementBuilder(com.google.api.ads.admanager.axis.utils.v202202.StatementBuilder) UpdateResult(com.google.api.ads.admanager.axis.v202202.UpdateResult)

Example 68 with UpdateResult

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

the class ApproveOrders method runExample.

/**
 * Runs the example.
 *
 * @param adManagerServices the services factory.
 * @param session the session.
 * @param orderId the ID of the order to approve.
 * @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 orderId) throws RemoteException {
    // Get the OrderService.
    OrderServiceInterface orderService = adManagerServices.get(session, OrderServiceInterface.class);
    // Create a statement to select an order.
    StatementBuilder statementBuilder = new StatementBuilder().where("WHERE id = :id").orderBy("id ASC").limit(StatementBuilder.SUGGESTED_PAGE_LIMIT).withBindVariableValue("id", orderId);
    // Default for total result set size.
    int totalResultSetSize = 0;
    do {
        // Get orders by statement.
        OrderPage page = orderService.getOrdersByStatement(statementBuilder.toStatement());
        if (page.getResults() != null) {
            totalResultSetSize = page.getTotalResultSetSize();
            int i = page.getStartIndex();
            for (Order order : page.getResults()) {
                System.out.printf("%d) Order with ID %d will be approved.%n", i++, order.getId());
            }
        }
        statementBuilder.increaseOffsetBy(StatementBuilder.SUGGESTED_PAGE_LIMIT);
    } while (statementBuilder.getOffset() < totalResultSetSize);
    System.out.printf("Number of orders to be approved: %d%n", totalResultSetSize);
    if (totalResultSetSize > 0) {
        // Remove limit and offset from statement.
        statementBuilder.removeLimitAndOffset();
        // Create action.
        com.google.api.ads.admanager.axis.v202202.ApproveOrders action = new com.google.api.ads.admanager.axis.v202202.ApproveOrders();
        // Perform action.
        UpdateResult result = orderService.performOrderAction(action, statementBuilder.toStatement());
        if (result != null && result.getNumChanges() > 0) {
            System.out.printf("Number of orders approved: %d%n", result.getNumChanges());
        } else {
            System.out.println("No orders were approved.");
        }
    }
}
Also used : Order(com.google.api.ads.admanager.axis.v202202.Order) OrderPage(com.google.api.ads.admanager.axis.v202202.OrderPage) OrderServiceInterface(com.google.api.ads.admanager.axis.v202202.OrderServiceInterface) StatementBuilder(com.google.api.ads.admanager.axis.utils.v202202.StatementBuilder) UpdateResult(com.google.api.ads.admanager.axis.v202202.UpdateResult)

Example 69 with UpdateResult

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

the class ArchiveAdUnits method runExample.

/**
 * Runs the example.
 *
 * @param adManagerServices the services factory.
 * @param session the session.
 * @param parentAdUnitId the ad unit ID to archive underneath.
 * @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, String parentAdUnitId) throws RemoteException {
    // Get the InventoryService.
    InventoryServiceInterface inventoryService = adManagerServices.get(session, InventoryServiceInterface.class);
    // Create a statement to select ad units under the parent ad unit and the
    // parent ad unit.
    StatementBuilder statementBuilder = new StatementBuilder().where("parentId = :parentId or id = :parentId").orderBy("id ASC").limit(StatementBuilder.SUGGESTED_PAGE_LIMIT).withBindVariableValue("parentId", parentAdUnitId);
    // Default for total result set size.
    int totalResultSetSize = 0;
    do {
        // Get ad units by statement.
        AdUnitPage page = inventoryService.getAdUnitsByStatement(statementBuilder.toStatement());
        if (page.getResults() != null) {
            totalResultSetSize = page.getTotalResultSetSize();
            int i = page.getStartIndex();
            for (AdUnit adUnit : page.getResults()) {
                System.out.printf("%d) Ad unit with ID '%s' and name '%s' will be archived.%n", i++, adUnit.getId(), adUnit.getName());
            }
        }
        statementBuilder.increaseOffsetBy(StatementBuilder.SUGGESTED_PAGE_LIMIT);
    } while (statementBuilder.getOffset() < totalResultSetSize);
    System.out.printf("Number of ad units to be archived: %d%n", totalResultSetSize);
    if (totalResultSetSize > 0) {
        // Remove limit and offset from statement.
        statementBuilder.removeLimitAndOffset();
        // Create action.
        com.google.api.ads.admanager.axis.v202202.ArchiveAdUnits action = new com.google.api.ads.admanager.axis.v202202.ArchiveAdUnits();
        // Perform action.
        UpdateResult result = inventoryService.performAdUnitAction(action, statementBuilder.toStatement());
        if (result != null && result.getNumChanges() > 0) {
            System.out.printf("Number of ad units archived: %d%n", result.getNumChanges());
        } else {
            System.out.println("No ad units were archived.");
        }
    }
}
Also used : AdUnitPage(com.google.api.ads.admanager.axis.v202202.AdUnitPage) AdUnit(com.google.api.ads.admanager.axis.v202202.AdUnit) InventoryServiceInterface(com.google.api.ads.admanager.axis.v202202.InventoryServiceInterface) StatementBuilder(com.google.api.ads.admanager.axis.utils.v202202.StatementBuilder) UpdateResult(com.google.api.ads.admanager.axis.v202202.UpdateResult)

Example 70 with UpdateResult

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

the class PushCreativeToDevices method runExample.

/**
 * Runs the example.
 *
 * @param adManagerServices the services factory.
 * @param session the session.
 * @param lineItemId the ID of the line item to push to a device.
 * @param creativeId the ID of the creative
 *       to push to a device.
 * @param linkedDeviceId the ID of the linked device to push the LICA to.
 * @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 lineItemId, long creativeId, long linkedDeviceId) throws RemoteException {
    // Get the LineItemCreativeAssociationService.
    LineItemCreativeAssociationServiceInterface licaService = adManagerServices.get(session, LineItemCreativeAssociationServiceInterface.class);
    // Create a statement to select a single linked device.
    // Linked devices can be read from the linked_device PQL table.
    StatementBuilder statementBuilder = new StatementBuilder().where("WHERE id = :linkedDeviceId").withBindVariableValue("linkedDeviceId", linkedDeviceId);
    CreativePushOptions options = new CreativePushOptions();
    options.setLineItemId(lineItemId);
    options.setCreativeId(creativeId);
    UpdateResult updateResult = licaService.pushCreativeToDevices(statementBuilder.toStatement(), options);
    System.out.printf("Pushed creative to %d devices%n", updateResult.getNumChanges());
}
Also used : CreativePushOptions(com.google.api.ads.admanager.axis.v202202.CreativePushOptions) StatementBuilder(com.google.api.ads.admanager.axis.utils.v202202.StatementBuilder) LineItemCreativeAssociationServiceInterface(com.google.api.ads.admanager.axis.v202202.LineItemCreativeAssociationServiceInterface) UpdateResult(com.google.api.ads.admanager.axis.v202202.UpdateResult)

Aggregations

StatementBuilder (com.google.api.ads.admanager.axis.utils.v202108.StatementBuilder)18 StatementBuilder (com.google.api.ads.admanager.axis.utils.v202111.StatementBuilder)18 StatementBuilder (com.google.api.ads.admanager.axis.utils.v202202.StatementBuilder)18 StatementBuilder (com.google.api.ads.admanager.axis.utils.v202205.StatementBuilder)18 UpdateResult (com.google.api.ads.admanager.axis.v202108.UpdateResult)18 UpdateResult (com.google.api.ads.admanager.axis.v202111.UpdateResult)18 UpdateResult (com.google.api.ads.admanager.axis.v202202.UpdateResult)18 UpdateResult (com.google.api.ads.admanager.axis.v202205.UpdateResult)18 UpdateResult (org.apache.ignite.internal.processors.query.h2.UpdateResult)11 SQLException (java.sql.SQLException)8 IgniteCheckedException (org.apache.ignite.IgniteCheckedException)7 IgniteSQLException (org.apache.ignite.internal.processors.query.IgniteSQLException)6 DmlStatementsProcessor (org.apache.ignite.internal.processors.query.h2.DmlStatementsProcessor)6 GridCacheContext (org.apache.ignite.internal.processors.cache.GridCacheContext)3 QueryCursorImpl (org.apache.ignite.internal.processors.cache.QueryCursorImpl)3 LineItemCreativeAssociationServiceInterface (com.google.api.ads.admanager.axis.v202108.LineItemCreativeAssociationServiceInterface)2 CustomTargetingServiceInterface (com.google.api.ads.admanager.axis.v202202.CustomTargetingServiceInterface)2 CustomTargetingServiceInterface (com.google.api.ads.admanager.axis.v202205.CustomTargetingServiceInterface)2 LineItemCreativeAssociationServiceInterface (com.google.api.ads.admanager.axis.v202205.LineItemCreativeAssociationServiceInterface)2 BatchUpdateException (java.sql.BatchUpdateException)2