use of com.google.api.ads.admanager.axis.v202205.UpdateResult in project gridgain by gridgain.
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 if (e instanceof SqlCacheException) {
sqlState = ((SqlCacheException) e).sqlState();
code = ((SqlCacheException) 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.v202205.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.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.v202108.DeactivateUsers action = new com.google.api.ads.admanager.axis.v202108.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.");
}
}
}
use of com.google.api.ads.admanager.axis.v202205.UpdateResult in project googleads-java-lib by googleads.
the class DeleteUserTeamAssociations method runExample.
/**
* Runs the example.
*
* @param adManagerServices the services factory.
* @param session the session.
* @param userId the ID of the user to delete user team associations 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 userId) throws RemoteException {
// Get the UserTeamAssociationService.
UserTeamAssociationServiceInterface userTeamAssociationService = adManagerServices.get(session, UserTeamAssociationServiceInterface.class);
// Create a statement to get all user team associations for a user.
StatementBuilder statementBuilder = new StatementBuilder().where("WHERE userId = :userId ").orderBy("userId ASC, teamid ASC").limit(StatementBuilder.SUGGESTED_PAGE_LIMIT).withBindVariableValue("userId", userId);
// Default for total result set size.
int totalResultSetSize = 0;
do {
// Get user team associations by statement.
UserTeamAssociationPage page = userTeamAssociationService.getUserTeamAssociationsByStatement(statementBuilder.toStatement());
if (page.getResults() != null) {
totalResultSetSize = page.getTotalResultSetSize();
int i = page.getStartIndex();
for (UserTeamAssociation userTeamAssociation : page.getResults()) {
System.out.printf("%d) User team association with user ID %d and " + "team ID %d will be deleted.%n", i++, userTeamAssociation.getUserId(), userTeamAssociation.getTeamId());
}
}
statementBuilder.increaseOffsetBy(StatementBuilder.SUGGESTED_PAGE_LIMIT);
} while (statementBuilder.getOffset() < totalResultSetSize);
System.out.printf("Number of user team associations 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.v202108.DeleteUserTeamAssociations action = new com.google.api.ads.admanager.axis.v202108.DeleteUserTeamAssociations();
// Perform action.
UpdateResult result = userTeamAssociationService.performUserTeamAssociationAction(action, statementBuilder.toStatement());
if (result != null && result.getNumChanges() > 0) {
System.out.printf("Number of user team associations deleted: %d%n", result.getNumChanges());
} else {
System.out.println("No user team associations were deleted.");
}
}
}
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.v202108.RequestBuyerAcceptance action = new com.google.api.ads.admanager.axis.v202108.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