use of com.google.api.ads.admanager.axis.v202111.UpdateResult in project googleads-java-lib by googleads.
the class DeleteCustomTargetingValues method runExample.
/**
* Runs the example.
*
* @param adManagerServices the services factory.
* @param session the session.
* @param customTargetingValueId the ID of the custom targeting value to delete.
* @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 customTargetingValueId) throws RemoteException {
// Get the CustomTargetingService.
CustomTargetingServiceInterface customTargetingService = adManagerServices.get(session, CustomTargetingServiceInterface.class);
// Create a statement to select custom targeting value.
StatementBuilder statementBuilder = new StatementBuilder().where("WHERE id = :id").orderBy("id ASC").limit(StatementBuilder.SUGGESTED_PAGE_LIMIT).withBindVariableValue("id", customTargetingValueId);
// Default for total result set size.
int totalResultSetSize = 0;
do {
// Get custom targeting values by statement.
CustomTargetingValuePage page = customTargetingService.getCustomTargetingValuesByStatement(statementBuilder.toStatement());
if (page.getResults() != null) {
totalResultSetSize = page.getTotalResultSetSize();
int i = page.getStartIndex();
for (CustomTargetingValue customTargetingValue : page.getResults()) {
System.out.printf("%d) Custom targeting value with ID %d" + " will be deleted.%n", i++, customTargetingValue.getId());
}
}
statementBuilder.increaseOffsetBy(StatementBuilder.SUGGESTED_PAGE_LIMIT);
} while (statementBuilder.getOffset() < totalResultSetSize);
System.out.printf("Number of custom targeting values to be deleted: %d%n", totalResultSetSize);
if (totalResultSetSize > 0) {
// Remove limit and offset from statement.
statementBuilder.removeLimitAndOffset();
// Create action.
com.google.api.ads.admanager.axis.v202202.DeleteCustomTargetingValues action = new com.google.api.ads.admanager.axis.v202202.DeleteCustomTargetingValues();
// Perform action.
UpdateResult result = customTargetingService.performCustomTargetingValueAction(action, statementBuilder.toStatement());
if (result != null && result.getNumChanges() > 0) {
System.out.printf("Number of custom targeting values deleted: %d%n", result.getNumChanges());
} else {
System.out.println("No custom targeting values deleted.");
}
}
}
use of com.google.api.ads.admanager.axis.v202111.UpdateResult in project ignite by apache.
the class DmlUtils method doDelete.
/**
* Perform DELETE operation on top of results of SELECT.
*
* @param cctx Cache context.
* @param cursor SELECT results.
* @param pageSize Batch size for streaming, anything <= 0 for single page operations.
* @return Results of DELETE (number of items affected AND keys that failed to be updated).
*/
private static UpdateResult doDelete(GridCacheContext cctx, Iterable<List<?>> cursor, int pageSize) throws IgniteCheckedException {
DmlBatchSender sender = new DmlBatchSender(cctx, pageSize, 1);
for (List<?> row : cursor) {
if (row.size() != 2)
continue;
Object key = row.get(0);
ClusterNode node = sender.primaryNodeByKey(key);
IgniteInClosure<MutableEntry<Object, Object>> rmvC = DmlStatementsProcessor.getRemoveClosure(node, key);
sender.add(key, new DmlStatementsProcessor.ModifyingEntryProcessor(row.get(1), rmvC), 0);
}
sender.flush();
SQLException resEx = sender.error();
if (resEx != null) {
if (!F.isEmpty(sender.failedKeys())) {
// Don't go for a re-run if processing of some keys yielded exceptions and report keys that
// had been modified concurrently right away.
String msg = "Failed to DELETE some keys because they had been modified concurrently " + "[keys=" + sender.failedKeys() + ']';
SQLException conEx = createJdbcSqlException(msg, IgniteQueryErrorCode.CONCURRENT_UPDATE);
conEx.setNextException(resEx);
resEx = conEx;
}
throw new IgniteSQLException(resEx);
}
return new UpdateResult(sender.updateCount(), sender.failedKeys().toArray(), cursor instanceof QueryCursorImpl ? ((QueryCursorImpl) cursor).partitionResult() : null);
}
use of com.google.api.ads.admanager.axis.v202111.UpdateResult in project ignite by apache.
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();
}
}
use of com.google.api.ads.admanager.axis.v202111.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());
}
use of com.google.api.ads.admanager.axis.v202111.UpdateResult in project googleads-java-lib by googleads.
the class DeactivateCreativeWrappersForLabel method runExample.
/**
* Runs the example.
*
* @param adManagerServices the services factory.
* @param session the session.
* @param labelId the ID of the creative wrapper label 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 labelId) throws RemoteException {
// Get the CreativeWrapperService.
CreativeWrapperServiceInterface creativeWrapperService = adManagerServices.get(session, CreativeWrapperServiceInterface.class);
// Create a statement to select the active creative wrappers for the
// given label.
StatementBuilder statementBuilder = new StatementBuilder().where("WHERE status = :status AND labelId = :labelId").orderBy("id ASC").limit(StatementBuilder.SUGGESTED_PAGE_LIMIT).withBindVariableValue("status", CreativeWrapperStatus.ACTIVE.toString()).withBindVariableValue("labelId", labelId);
// Default for total result set size.
int totalResultSetSize = 0;
do {
// Get creative wrappers by statement.
CreativeWrapperPage page = creativeWrapperService.getCreativeWrappersByStatement(statementBuilder.toStatement());
if (page.getResults() != null) {
totalResultSetSize = page.getTotalResultSetSize();
int i = page.getStartIndex();
for (CreativeWrapper creativeWrapper : page.getResults()) {
System.out.printf("%d) Creative wrapper with ID %d applying to label ID" + " %d will be deactivated.%n", i++, creativeWrapper.getId(), creativeWrapper.getLabelId());
}
}
statementBuilder.increaseOffsetBy(StatementBuilder.SUGGESTED_PAGE_LIMIT);
} while (statementBuilder.getOffset() < totalResultSetSize);
System.out.printf("Number of creative wrappers to be deactivated: %d%n", totalResultSetSize);
if (totalResultSetSize > 0) {
// Remove limit and offset from statement.
statementBuilder.removeLimitAndOffset();
// Create action.
DeactivateCreativeWrappers action = new DeactivateCreativeWrappers();
// Perform action.
UpdateResult result = creativeWrapperService.performCreativeWrapperAction(action, statementBuilder.toStatement());
if (result != null && result.getNumChanges() > 0) {
System.out.printf("Number of creative wrappers deactivated: %d%n", result.getNumChanges());
} else {
System.out.println("No creative wrappers were deactivated.");
}
}
}
Aggregations