use of com.google.api.ads.admanager.axis.v202108.UpdateResult in project ignite by apache.
the class DistributedUpdateRun method handleResponse.
/**
* Handle response from remote node.
*
* @param id Node id.
* @param msg Response message.
*/
void handleResponse(UUID id, GridH2DmlResponse msg) {
synchronized (this) {
if (!rspNodes.add(id))
// ignore duplicated messages
return;
String err = msg.error();
if (err != null) {
fut.onDone(new IgniteCheckedException("Update failed. " + (F.isEmpty(err) ? "" : err) + "[reqId=" + msg.requestId() + ", node=" + id + "]."));
return;
}
if (!F.isEmpty(msg.errorKeys())) {
List<Object> errList = Arrays.asList(msg.errorKeys());
if (errorKeys == null)
errorKeys = new HashSet<>(errList);
else
errorKeys.addAll(errList);
}
updCntr += msg.updateCounter();
if (rspNodes.size() == nodeCount)
fut.onDone(new UpdateResult(updCntr, errorKeys == null ? null : errorKeys.toArray()));
}
}
use of com.google.api.ads.admanager.axis.v202108.UpdateResult in project ignite by apache.
the class DmlDistributedUpdateRun method handleResponse.
/**
* Handle response from remote node.
*
* @param id Node id.
* @param msg Response message.
*/
public void handleResponse(UUID id, GridH2DmlResponse msg) {
synchronized (this) {
if (!rspNodes.add(id))
// ignore duplicated messages
return;
String err = msg.error();
if (err != null) {
fut.onDone(new IgniteCheckedException("Update failed. " + (F.isEmpty(err) ? "" : err) + "[reqId=" + msg.requestId() + ", node=" + id + "]."));
return;
}
if (!F.isEmpty(msg.errorKeys())) {
List<Object> errList = Arrays.asList(msg.errorKeys());
if (errorKeys == null)
errorKeys = new HashSet<>(errList);
else
errorKeys.addAll(errList);
}
updCntr += msg.updateCounter();
if (rspNodes.size() == nodeCount)
fut.onDone(new UpdateResult(updCntr, errorKeys == null ? null : errorKeys.toArray()));
}
}
use of com.google.api.ads.admanager.axis.v202108.UpdateResult in project ignite by apache.
the class DmlUtils method doUpdate.
/**
* Perform UPDATE operation on top of results of SELECT.
* @param cursor SELECT results.
* @param pageSize Batch size for streaming, anything <= 0 for single page operations.
* @return Pair [cursor corresponding to results of UPDATE (contains number of items affected); keys whose values
* had been modified concurrently (arguments for a re-run)].
*/
private static UpdateResult doUpdate(UpdatePlan plan, Iterable<List<?>> cursor, int pageSize) throws IgniteCheckedException {
GridCacheContext cctx = plan.cacheContext();
DmlBatchSender sender = new DmlBatchSender(cctx, pageSize, 1);
for (List<?> row : cursor) {
T3<Object, Object, Object> row0 = plan.processRowForUpdate(row);
Object key = row0.get1();
Object oldVal = row0.get2();
Object newVal = row0.get3();
sender.add(key, new DmlStatementsProcessor.ModifyingEntryProcessor(oldVal, new DmlStatementsProcessor.EntryValueUpdater(newVal)), 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 UPDATE some keys because they had been modified concurrently " + "[keys=" + sender.failedKeys() + ']';
SQLException dupEx = createJdbcSqlException(msg, IgniteQueryErrorCode.CONCURRENT_UPDATE);
dupEx.setNextException(resEx);
resEx = dupEx;
}
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.v202108.UpdateResult in project ignite by apache.
the class DmlUtils method doInsertBatched.
/**
* Execute INSERT statement plan.
*
* @param plan Plan to execute.
* @param cursor Cursor to take inserted data from. I.e. list of batch arguments for each query.
* @param pageSize Batch size for streaming, anything <= 0 for single page operations.
* @return Number of items affected.
* @throws IgniteCheckedException if failed, particularly in case of duplicate keys.
*/
private static List<UpdateResult> doInsertBatched(UpdatePlan plan, List<List<List<?>>> cursor, int pageSize) throws IgniteCheckedException {
GridCacheContext cctx = plan.cacheContext();
DmlBatchSender snd = new DmlBatchSender(cctx, pageSize, cursor.size());
int rowNum = 0;
SQLException resEx = null;
for (List<List<?>> qryRow : cursor) {
for (List<?> row : qryRow) {
try {
final IgniteBiTuple keyValPair = plan.processRow(row);
snd.add(keyValPair.getKey(), new DmlStatementsProcessor.InsertEntryProcessor(keyValPair.getValue()), rowNum);
} catch (Exception e) {
String sqlState;
int code;
if (e instanceof IgniteSQLException) {
sqlState = ((IgniteSQLException) e).sqlState();
code = ((IgniteSQLException) e).statusCode();
} else {
sqlState = SqlStateCode.INTERNAL_ERROR;
code = IgniteQueryErrorCode.UNKNOWN;
}
resEx = chainException(resEx, new SQLException(e.getMessage(), sqlState, code, e));
snd.setFailed(rowNum);
}
}
rowNum++;
}
try {
snd.flush();
} catch (Exception e) {
resEx = chainException(resEx, new SQLException(e.getMessage(), SqlStateCode.INTERNAL_ERROR, IgniteQueryErrorCode.UNKNOWN, e));
}
resEx = chainException(resEx, snd.error());
if (!F.isEmpty(snd.failedKeys())) {
SQLException e = new SQLException("Failed to INSERT some keys because they are already in cache [keys=" + snd.failedKeys() + ']', SqlStateCode.CONSTRAINT_VIOLATION, DUPLICATE_KEY);
resEx = chainException(resEx, e);
}
if (resEx != null) {
BatchUpdateException e = new BatchUpdateException(resEx.getMessage(), resEx.getSQLState(), resEx.getErrorCode(), snd.perRowCounterAsArray(), resEx);
throw new IgniteCheckedException(e);
}
int[] cntPerRow = snd.perRowCounterAsArray();
List<UpdateResult> res = new ArrayList<>(cntPerRow.length);
for (int i = 0; i < cntPerRow.length; i++) {
int cnt = cntPerRow[i];
res.add(new UpdateResult(cnt, X.EMPTY_OBJECT_ARRAY));
}
return res;
}
use of com.google.api.ads.admanager.axis.v202108.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.v202111.RequestBuyerAcceptance action = new com.google.api.ads.admanager.axis.v202111.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.");
}
}
}
Aggregations