use of com.azure.cosmos.models.CosmosStoredProcedureResponse in project DataSpaceConnector by eclipse-dataspaceconnector.
the class CosmosTransferProcessStoreIntegrationTest method invokeStoreProcedure.
@Test
void invokeStoreProcedure() {
// create one item
var tp = createTransferProcess("proc1");
store.create(tp);
List<Object> procedureParams = Arrays.asList(100, 5, connectorId);
CosmosStoredProcedureRequestOptions options = new CosmosStoredProcedureRequestOptions();
options.setPartitionKey(PartitionKey.NONE);
CosmosStoredProcedureResponse sprocResponse = container.getScripts().getStoredProcedure("nextForState").execute(procedureParams, options);
var result = sprocResponse.getResponseAsString();
var l = typeManager.readValue(result, List.class);
List<TransferProcessDocument> documents = (List<TransferProcessDocument>) l.stream().map(o -> typeManager.writeValueAsString(o)).map(json -> typeManager.readValue(json.toString(), TransferProcessDocument.class)).collect(Collectors.toList());
assertThat(documents).allSatisfy(document -> {
assertThat(document.getLease()).isNotNull().hasFieldOrPropertyWithValue("leasedBy", connectorId).hasFieldOrProperty("leasedAt");
});
}
use of com.azure.cosmos.models.CosmosStoredProcedureResponse in project DataSpaceConnector by eclipse-dataspaceconnector.
the class CosmosDbApiImpl method invokeStoredProcedure.
@Override
public String invokeStoredProcedure(String procedureName, String partitionKey, Object... args) {
var sproc = getStoredProcedure(procedureName);
List<Object> params = Arrays.asList(args);
var options = new CosmosStoredProcedureRequestOptions();
options.setPartitionKey(new PartitionKey(partitionKey));
CosmosStoredProcedureResponse response = sproc.execute(params, options);
handleResponse(response.getStatusCode(), "Failed to invoke stored procedure: " + procedureName);
return response.getResponseAsString();
}
use of com.azure.cosmos.models.CosmosStoredProcedureResponse in project DataSpaceConnector by eclipse-dataspaceconnector.
the class CosmosTransferProcessStoreIntegrationTest method invokeStoredProcedure.
@Test
void invokeStoredProcedure() {
// create one item
var tp = createTransferProcess("proc1");
store.create(tp);
List<Object> procedureParams = Arrays.asList(100, 5, connectorId);
CosmosStoredProcedureRequestOptions options = new CosmosStoredProcedureRequestOptions();
options.setPartitionKey(PartitionKey.NONE);
CosmosStoredProcedureResponse sprocResponse = container.getScripts().getStoredProcedure("nextForState").execute(procedureParams, options);
var result = sprocResponse.getResponseAsString();
var l = typeManager.readValue(result, List.class);
List<TransferProcessDocument> documents = (List<TransferProcessDocument>) l.stream().map(o -> typeManager.writeValueAsString(o)).map(json -> typeManager.readValue(json.toString(), TransferProcessDocument.class)).collect(Collectors.toList());
assertThat(documents).allSatisfy(document -> {
assertThat(document.getLease()).isNotNull().hasFieldOrPropertyWithValue("leasedBy", connectorId).hasFieldOrProperty("leasedAt");
});
}
use of com.azure.cosmos.models.CosmosStoredProcedureResponse in project azure-cosmos-java-sql-api-samples by Azure-Samples.
the class SampleStoredProcedure method executeStoredProcedureArrayArg.
public void executeStoredProcedureArrayArg() throws Exception {
logger.info(String.format("Executing stored procedure %s...\n\n", sprocId + "ArrayArg"));
String partitionValue = "Seattle";
CosmosStoredProcedureRequestOptions options = new CosmosStoredProcedureRequestOptions();
options.setPartitionKey(new PartitionKey(partitionValue));
List<Object> pojos = new ArrayList<>();
pojos.add(new CustomPOJO("idA", partitionValue));
pojos.add(new CustomPOJO("idB", partitionValue));
pojos.add(new CustomPOJO("idC", partitionValue));
List<Object> sproc_args = new ArrayList<>();
sproc_args.add(OBJECT_MAPPER.writeValueAsString(pojos));
CosmosStoredProcedureResponse executeResponse = container.getScripts().getStoredProcedure(sprocId + "ArrayArg").execute(sproc_args, options);
logger.info(String.format("Stored procedure %s returned %s (HTTP %d), at cost %.3f RU.\n", sprocId + "ArrayArg", executeResponse.getResponseAsString(), executeResponse.getStatusCode(), executeResponse.getRequestCharge()));
}
use of com.azure.cosmos.models.CosmosStoredProcedureResponse in project azure-cosmos-java-sql-api-samples by Azure-Samples.
the class SampleStoredProcedure method executeStoredProcedure.
public void executeStoredProcedure() throws Exception {
logger.info(String.format("Executing stored procedure %s...\n\n", sprocId));
CosmosStoredProcedureRequestOptions options = new CosmosStoredProcedureRequestOptions();
options.setPartitionKey(new PartitionKey("Seattle"));
CosmosStoredProcedureResponse executeResponse = container.getScripts().getStoredProcedure(sprocId).execute(null, options);
logger.info(String.format("Stored procedure %s returned %s (HTTP %d), at cost %.3f RU.\n", sprocId, executeResponse.getResponseAsString(), executeResponse.getStatusCode(), executeResponse.getRequestCharge()));
}
Aggregations