Search in sources :

Example 76 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.v202205.ApproveOrders action = new com.google.api.ads.admanager.axis.v202205.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.v202205.Order) OrderPage(com.google.api.ads.admanager.axis.v202205.OrderPage) OrderServiceInterface(com.google.api.ads.admanager.axis.v202205.OrderServiceInterface) StatementBuilder(com.google.api.ads.admanager.axis.utils.v202205.StatementBuilder) UpdateResult(com.google.api.ads.admanager.axis.v202205.UpdateResult)

Example 77 with UpdateResult

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

the class DeactivatePlacements method runExample.

/**
 * Runs the example.
 *
 * @param adManagerServices the services factory.
 * @param session the session.
 * @param placementId the ID of the placement 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 placementId) throws RemoteException {
    // Get the PlacementService.
    PlacementServiceInterface placementService = adManagerServices.get(session, PlacementServiceInterface.class);
    // Create a statement to select a placement.
    StatementBuilder statementBuilder = new StatementBuilder().where("WHERE id = :id").orderBy("id ASC").limit(StatementBuilder.SUGGESTED_PAGE_LIMIT).withBindVariableValue("id", placementId);
    // Default for total result set size.
    int totalResultSetSize = 0;
    do {
        // Get placements by statement.
        PlacementPage page = placementService.getPlacementsByStatement(statementBuilder.toStatement());
        if (page.getResults() != null) {
            totalResultSetSize = page.getTotalResultSetSize();
            int i = page.getStartIndex();
            for (Placement placement : page.getResults()) {
                System.out.printf("%d) Placement with ID %d will be deactivated.%n", i++, placement.getId());
            }
        }
        statementBuilder.increaseOffsetBy(StatementBuilder.SUGGESTED_PAGE_LIMIT);
    } while (statementBuilder.getOffset() < totalResultSetSize);
    System.out.printf("Number of placements 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.v202205.DeactivatePlacements action = new com.google.api.ads.admanager.axis.v202205.DeactivatePlacements();
        // Perform action.
        UpdateResult result = placementService.performPlacementAction(action, statementBuilder.toStatement());
        if (result != null && result.getNumChanges() > 0) {
            System.out.printf("Number of placements deactivated: %d%n", result.getNumChanges());
        } else {
            System.out.println("No placements were deactivated.");
        }
    }
}
Also used : PlacementPage(com.google.api.ads.admanager.axis.v202205.PlacementPage) Placement(com.google.api.ads.admanager.axis.v202205.Placement) StatementBuilder(com.google.api.ads.admanager.axis.utils.v202205.StatementBuilder) PlacementServiceInterface(com.google.api.ads.admanager.axis.v202205.PlacementServiceInterface) UpdateResult(com.google.api.ads.admanager.axis.v202205.UpdateResult)

Example 78 with UpdateResult

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

the class ArchiveProposalLineItems method runExample.

/**
 * Runs the example.
 *
 * @param adManagerServices the services factory.
 * @param session the session.
 * @param proposalLineItemId the ID of the proposal line item to archive.
 * @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 proposalLineItemId) throws RemoteException {
    // Get the ProposalLineItemService.
    ProposalLineItemServiceInterface proposalLineItemService = adManagerServices.get(session, ProposalLineItemServiceInterface.class);
    // Create a statement to select a proposal line item.
    StatementBuilder statementBuilder = new StatementBuilder().where("WHERE id = :id").orderBy("id ASC").limit(StatementBuilder.SUGGESTED_PAGE_LIMIT).withBindVariableValue("id", proposalLineItemId);
    // Default for total result set size.
    int totalResultSetSize = 0;
    do {
        // Get proposal line items by statement.
        ProposalLineItemPage page = proposalLineItemService.getProposalLineItemsByStatement(statementBuilder.toStatement());
        if (page.getResults() != null) {
            totalResultSetSize = page.getTotalResultSetSize();
            int i = page.getStartIndex();
            for (ProposalLineItem proposalLineItem : page.getResults()) {
                System.out.printf("%d) Proposal line item with ID %d will be archived.%n", i++, proposalLineItem.getId());
            }
        }
        statementBuilder.increaseOffsetBy(StatementBuilder.SUGGESTED_PAGE_LIMIT);
    } while (statementBuilder.getOffset() < totalResultSetSize);
    System.out.printf("Number of proposal line items 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.v202205.ArchiveProposalLineItems action = new com.google.api.ads.admanager.axis.v202205.ArchiveProposalLineItems();
        // Perform action.
        UpdateResult result = proposalLineItemService.performProposalLineItemAction(action, statementBuilder.toStatement());
        if (result != null && result.getNumChanges() > 0) {
            System.out.printf("Number of proposal line items archived: %d%n", result.getNumChanges());
        } else {
            System.out.println("No proposal line items were archived.");
        }
    }
}
Also used : ProposalLineItemPage(com.google.api.ads.admanager.axis.v202205.ProposalLineItemPage) ProposalLineItem(com.google.api.ads.admanager.axis.v202205.ProposalLineItem) StatementBuilder(com.google.api.ads.admanager.axis.utils.v202205.StatementBuilder) UpdateResult(com.google.api.ads.admanager.axis.v202205.UpdateResult) ProposalLineItemServiceInterface(com.google.api.ads.admanager.axis.v202205.ProposalLineItemServiceInterface)

Example 79 with UpdateResult

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

the class RequestBuyerAcceptance method runExample.

/**
 * Runs the example.
 *
 * @param adManagerServices the services factory.
 * @param session the session.
 * @param proposalId the proposal ID to send.
 * @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 proposalId) throws RemoteException {
    // Get the ProposalService.
    ProposalServiceInterface proposalService = adManagerServices.get(session, ProposalServiceInterface.class);
    // Create a statement to only select a single proposal by ID.
    StatementBuilder statementBuilder = new StatementBuilder().where("WHERE id = :id").orderBy("id ASC").limit(StatementBuilder.SUGGESTED_PAGE_LIMIT).withBindVariableValue("id", proposalId);
    // Retrieve a small amount of proposals at a time, paging through until all
    // proposals have been retrieved.
    int totalResultSetSize = 0;
    do {
        ProposalPage page = proposalService.getProposalsByStatement(statementBuilder.toStatement());
        if (page.getResults() != null) {
            // Print out some information for each proposal.
            totalResultSetSize = page.getTotalResultSetSize();
            int i = page.getStartIndex();
            for (Proposal proposal : page.getResults()) {
                System.out.printf("%d) Proposal with ID %d and name '%s' will be sent to Marketplace for buyer " + "acceptance.%n", i++, proposal.getId(), proposal.getName());
            }
        }
        statementBuilder.increaseOffsetBy(StatementBuilder.SUGGESTED_PAGE_LIMIT);
    } while (statementBuilder.getOffset() < totalResultSetSize);
    System.out.printf("Number of proposals to be sent to Marketplace for buyer acceptance: %d%n", totalResultSetSize);
    if (totalResultSetSize > 0) {
        // Remove limit and offset from statement.
        statementBuilder.removeLimitAndOffset();
        // Create action.
        com.google.api.ads.admanager.axis.v202205.RequestBuyerAcceptance action = new com.google.api.ads.admanager.axis.v202205.RequestBuyerAcceptance();
        // Perform action.
        UpdateResult result = proposalService.performProposalAction(action, statementBuilder.toStatement());
        if (result != null && result.getNumChanges() > 0) {
            System.out.printf("Number of proposals that were sent to Marketplace for buyer acceptance: %d%n", result.getNumChanges());
        } else {
            System.out.println("No proposals were sent to Marketplace for buyer acceptance.");
        }
    }
}
Also used : ProposalServiceInterface(com.google.api.ads.admanager.axis.v202205.ProposalServiceInterface) ProposalPage(com.google.api.ads.admanager.axis.v202205.ProposalPage) StatementBuilder(com.google.api.ads.admanager.axis.utils.v202205.StatementBuilder) Proposal(com.google.api.ads.admanager.axis.v202205.Proposal) UpdateResult(com.google.api.ads.admanager.axis.v202205.UpdateResult)

Example 80 with UpdateResult

use of com.google.api.ads.admanager.axis.v202205.UpdateResult in project gridgain by gridgain.

the class GridMapQueryExecutor method onDmlRequest.

/**
 * @param node Node.
 * @param req DML request.
 */
public void onDmlRequest(final ClusterNode node, final GridH2DmlRequest req) {
    int[] parts = req.queryPartitions();
    List<Integer> cacheIds = req.caches();
    long reqId = req.requestId();
    AffinityTopologyVersion topVer = req.topologyVersion();
    PartitionReservation reserved = null;
    MapNodeResults nodeResults = resultsForNode(node.id());
    // We don't use try with resources on purpose - the catch block must also be executed in the context of this span.
    TraceSurroundings trace = MTC.support(ctx.tracing().create(SpanType.SQL_DML_QRY_EXEC_REQ, MTC.span()).addTag(SQL_QRY_TEXT, req::query));
    try {
        reserved = h2.partitionReservationManager().reservePartitions(cacheIds, topVer, parts, node.id(), reqId);
        if (reserved.failed()) {
            U.error(log, "Failed to reserve partitions for DML request. [localNodeId=" + ctx.localNodeId() + ", nodeId=" + node.id() + ", reqId=" + req.requestId() + ", cacheIds=" + cacheIds + ", topVer=" + topVer + ", parts=" + Arrays.toString(parts) + ']');
            sendUpdateResponse(node, reqId, null, "Failed to reserve partitions for DML request. " + reserved.error());
            return;
        }
        IndexingQueryFilter filter = h2.backupFilter(topVer, parts);
        GridQueryCancel cancel = nodeResults.putUpdate(reqId);
        SqlFieldsQuery fldsQry = new SqlFieldsQuery(req.query());
        if (req.parameters() != null)
            fldsQry.setArgs(req.parameters());
        fldsQry.setEnforceJoinOrder(req.isFlagSet(GridH2QueryRequest.FLAG_ENFORCE_JOIN_ORDER));
        fldsQry.setPageSize(req.pageSize());
        fldsQry.setLocal(true);
        if (req.timeout() > 0 || req.explicitTimeout())
            fldsQry.setTimeout(req.timeout(), TimeUnit.MILLISECONDS);
        boolean local = true;
        final boolean replicated = req.isFlagSet(GridH2QueryRequest.FLAG_REPLICATED);
        if (!replicated && !F.isEmpty(cacheIds) && CU.firstPartitioned(ctx.cache().context(), cacheIds).config().getQueryParallelism() > 1) {
            fldsQry.setDistributedJoins(true);
            local = false;
        }
        UpdateResult updRes = h2.executeUpdateOnDataNode(req.schemaName(), fldsQry, filter, cancel, local);
        GridCacheContext<?, ?> mainCctx = !F.isEmpty(cacheIds) ? ctx.cache().context().cacheContext(cacheIds.get(0)) : null;
        boolean evt = local && mainCctx != null && mainCctx.events().isRecordable(EVT_CACHE_QUERY_EXECUTED);
        if (evt) {
            ctx.event().record(new CacheQueryExecutedEvent<>(node, "SQL query executed.", EVT_CACHE_QUERY_EXECUTED, CacheQueryType.SQL.name(), mainCctx.name(), null, req.query(), null, null, req.parameters(), node.id(), null));
        }
        sendUpdateResponse(node, reqId, updRes, null);
    } catch (Exception e) {
        MTC.span().addTag(ERROR, e::getMessage);
        U.error(log, "Error processing dml request. [localNodeId=" + ctx.localNodeId() + ", nodeId=" + node.id() + ", req=" + req + ']', e);
        sendUpdateResponse(node, reqId, null, e.getMessage());
    } finally {
        if (reserved != null)
            reserved.release();
        nodeResults.removeUpdate(reqId);
        if (trace != null)
            trace.close();
    }
}
Also used : AffinityTopologyVersion(org.apache.ignite.internal.processors.affinity.AffinityTopologyVersion) IndexingQueryFilter(org.apache.ignite.spi.indexing.IndexingQueryFilter) TraceSurroundings(org.apache.ignite.internal.processors.tracing.MTC.TraceSurroundings) SqlFieldsQuery(org.apache.ignite.cache.query.SqlFieldsQuery) QueryCancelledException(org.apache.ignite.cache.query.QueryCancelledException) IgniteCheckedException(org.apache.ignite.IgniteCheckedException) IgniteException(org.apache.ignite.IgniteException) QueryRetryException(org.apache.ignite.cache.query.QueryRetryException) GridH2RetryException(org.apache.ignite.internal.processors.query.h2.opt.GridH2RetryException) SQLException(java.sql.SQLException) CacheException(javax.cache.CacheException) GridQueryCancel(org.apache.ignite.internal.processors.query.GridQueryCancel) UpdateResult(org.apache.ignite.internal.processors.query.h2.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