use of com.google.api.ads.admanager.axis.v202205.UpdateResult in project googleads-java-lib by googleads.
the class DeactivateCustomFields method runExample.
/**
* Runs the example.
*
* @param adManagerServices the services factory.
* @param session the session.
* @param customFieldId the ID of the custom field 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 customFieldId) throws RemoteException {
// Get the CustomFieldService.
CustomFieldServiceInterface customFieldService = adManagerServices.get(session, CustomFieldServiceInterface.class);
// Create a statement to select a custom field.
StatementBuilder statementBuilder = new StatementBuilder().where("WHERE id = :id").orderBy("id ASC").limit(StatementBuilder.SUGGESTED_PAGE_LIMIT).withBindVariableValue("id", customFieldId);
// Default for total result set size.
int totalResultSetSize = 0;
do {
// Get custom fields by statement.
CustomFieldPage page = customFieldService.getCustomFieldsByStatement(statementBuilder.toStatement());
if (page.getResults() != null) {
totalResultSetSize = page.getTotalResultSetSize();
int i = page.getStartIndex();
for (CustomField customField : page.getResults()) {
System.out.printf("%d) Custom field with ID %d will be deactivated.%n", i++, customField.getId());
}
}
statementBuilder.increaseOffsetBy(StatementBuilder.SUGGESTED_PAGE_LIMIT);
} while (statementBuilder.getOffset() < totalResultSetSize);
System.out.printf("Number of custom fields 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.v202108.DeactivateCustomFields action = new com.google.api.ads.admanager.axis.v202108.DeactivateCustomFields();
// Perform action.
UpdateResult result = customFieldService.performCustomFieldAction(action, statementBuilder.toStatement());
if (result != null && result.getNumChanges() > 0) {
System.out.printf("Number of custom fields deactivated: %d%n", result.getNumChanges());
} else {
System.out.println("No custom fields were deactivated.");
}
}
}
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.v202108.ArchiveAdUnits action = new com.google.api.ads.admanager.axis.v202108.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.");
}
}
}
use of com.google.api.ads.admanager.axis.v202205.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.v202205.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.v202205.UpdateResult in project googleads-java-lib by googleads.
the class ActivateCmsMetadataValues method runExample.
/**
* Runs the example.
*
* @param adManagerServices the services factory.
* @param session the session.
* @param cmsMetadataKeyId the ID of the CMS Metadata Key to activate values for.
* @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 cmsMetadataKeyId) throws RemoteException {
// Get the CmsMetadataService.
CmsMetadataServiceInterface cmsMetadataService = adManagerServices.get(session, CmsMetadataServiceInterface.class);
// Create a statement to select CMS Metadata Values.
StatementBuilder statementBuilder = new StatementBuilder().where("cmsKeyId = :cmsKeyId AND status = :status").limit(StatementBuilder.SUGGESTED_PAGE_LIMIT).withBindVariableValue("cmsKeyId", cmsMetadataKeyId).withBindVariableValue("status", CmsMetadataKeyStatus.INACTIVE.toString());
// Default for total result set size.
int totalResultSetSize = 0;
do {
// Get CMS Metadata Values by statement.
CmsMetadataValuePage page = cmsMetadataService.getCmsMetadataValuesByStatement(statementBuilder.toStatement());
if (page.getResults() != null) {
totalResultSetSize = page.getTotalResultSetSize();
int i = page.getStartIndex();
for (CmsMetadataValue cmsMetadataValue : page.getResults()) {
System.out.printf("%d) CMS Metadata Value with ID %d will be activated.%n", i++, cmsMetadataValue.getCmsMetadataValueId());
}
}
statementBuilder.increaseOffsetBy(StatementBuilder.SUGGESTED_PAGE_LIMIT);
} while (statementBuilder.getOffset() < totalResultSetSize);
System.out.printf("Number of CMS Metadata Values to be activated: %d%n", totalResultSetSize);
if (totalResultSetSize > 0) {
// Remove limit and offset from statement to activate all matching values.
statementBuilder.removeLimitAndOffset();
// Create action.
com.google.api.ads.admanager.axis.v202111.ActivateCmsMetadataValues action = new com.google.api.ads.admanager.axis.v202111.ActivateCmsMetadataValues();
// Perform action.
UpdateResult result = cmsMetadataService.performCmsMetadataValueAction(action, statementBuilder.toStatement());
if (result != null && result.getNumChanges() > 0) {
System.out.printf("Number of items activated: %d%n", result.getNumChanges());
} else {
System.out.println("No CMS Metadata Values were activated.");
}
}
}
Aggregations