use of org.ballerinalang.model.values.BRefValueArray in project ballerina by ballerina-lang.
the class BatchUpdate method execute.
@Override
public void execute(Context context) {
try {
BStruct bConnector = (BStruct) context.getRefArgument(0);
String query = context.getStringArgument(0);
BRefValueArray parameters = (BRefValueArray) context.getNullableRefArgument(1);
SQLDatasource datasource = (SQLDatasource) bConnector.getNativeData(Constants.CLIENT_CONNECTOR);
Map<String, String> tags = new HashMap<>();
tags.put(TAG_KEY_DB_STATEMENT, query);
tags.put(TAG_KEY_DB_TYPE, TAG_DB_TYPE_SQL);
TraceUtil.getTracer(context.getParentWorkerExecutionContext()).addTags(tags);
executeBatchUpdate(context, datasource, query, parameters);
} catch (Throwable e) {
context.setReturnValues(SQLDatasourceUtils.getSQLConnectorError(context, e));
SQLDatasourceUtils.handleErrorOnTransaction(context);
}
}
use of org.ballerinalang.model.values.BRefValueArray in project ballerina by ballerina-lang.
the class Update method execute.
@Override
public void execute(Context context) {
try {
BStruct bConnector = (BStruct) context.getRefArgument(0);
String query = context.getStringArgument(0);
BRefValueArray parameters = (BRefValueArray) context.getNullableRefArgument(1);
SQLDatasource datasource = (SQLDatasource) bConnector.getNativeData(Constants.CLIENT_CONNECTOR);
Map<String, String> tags = new HashMap<>();
tags.put(TAG_KEY_DB_STATEMENT, query);
tags.put(TAG_KEY_DB_TYPE, TAG_DB_TYPE_SQL);
TraceUtil.getTracer(context.getParentWorkerExecutionContext()).addTags(tags);
executeUpdate(context, datasource, query, parameters);
} catch (Throwable e) {
context.setReturnValues(SQLDatasourceUtils.getSQLConnectorError(context, e));
SQLDatasourceUtils.handleErrorOnTransaction(context);
}
}
use of org.ballerinalang.model.values.BRefValueArray in project ballerina by ballerina-lang.
the class BTestRunner method extractArguments.
/**
* Extract function arguments from the values sets.
* @param valueSets user provided value sets
* @return a list of function arguments
*/
private List<BValue[]> extractArguments(BValue[] valueSets) {
List<BValue[]> argsList = new ArrayList<>();
for (BValue value : valueSets) {
if (value instanceof BRefValueArray) {
BRefValueArray array = (BRefValueArray) value;
for (BIterator it = array.newIterator(); it.hasNext(); ) {
BValue[] vals = it.getNext(0);
if (vals[1] instanceof BNewArray) {
BNewArray bNewArray = (BNewArray) vals[1];
BValue[] args = new BValue[(int) bNewArray.size()];
for (int j = 0; j < bNewArray.size(); j++) {
args[j] = bNewArray.getBValue(j);
}
argsList.add(args);
} else {
// cannot happen due to validations done at annotation processor
}
}
} else if (value instanceof BJSON) {
BJSON jsonArrayOfArrays = (BJSON) value;
for (BIterator it = jsonArrayOfArrays.newIterator(); it.hasNext(); ) {
BValue[] vals = it.getNext(0);
if (vals[1] instanceof BJSON) {
List<BValue> args = new ArrayList<>();
BJSON jsonArray = (BJSON) vals[1];
for (BIterator it2 = jsonArray.newIterator(); it2.hasNext(); ) {
BValue[] vals2 = it2.getNext(0);
args.add(vals2[1]);
}
argsList.add(args.toArray(new BValue[0]));
} else {
// cannot happen due to validations done at annotation processor
}
}
} else {
argsList.add(new BValue[] { value });
}
}
return argsList;
}
use of org.ballerinalang.model.values.BRefValueArray in project ballerina by ballerina-lang.
the class StartForever method execute.
@Override
public void execute(Context context) {
context.setReturnValues();
String siddhiApp = context.getStringArgument(0);
SiddhiAppRuntime siddhiAppRuntime = StreamingRuntimeManager.getInstance().createSiddhiAppRuntime(siddhiApp);
Set<String> streamIds = siddhiAppRuntime.getStreamDefinitionMap().keySet();
Map<String, InputHandler> streamSpecificInputHandlerMap = new HashMap<>();
for (String streamId : streamIds) {
streamSpecificInputHandlerMap.put(streamId, siddhiAppRuntime.getInputHandler(streamId));
}
BRefValueArray inputStreamReferenceArray = (BRefValueArray) context.getRefArgument(0);
BRefValueArray functionPointerArray = (BRefValueArray) context.getRefArgument(4);
for (int i = 0; i < inputStreamReferenceArray.size(); i++) {
BStream stream = (BStream) inputStreamReferenceArray.get(i);
InputHandler inputHandler = streamSpecificInputHandlerMap.get(stream.getStreamId());
stream.subscribe(inputHandler);
}
for (int i = 0; i < functionPointerArray.size(); i++) {
BFunctionPointer functionPointer = (BFunctionPointer) functionPointerArray.get(i);
String functionName = functionPointer.value().getFunctionName();
String streamId = "stream" + functionName.replaceAll("\\$", "_");
StreamingRuntimeManager.getInstance().addCallback(streamId, functionPointer, siddhiAppRuntime);
}
}
use of org.ballerinalang.model.values.BRefValueArray in project ballerina by ballerina-lang.
the class VectorNegativeTest method testRemoveIndexOutOfRange.
@Test(description = "Test case for testing removal of elements from outside of the bounds of a vector.")
public void testRemoveIndexOutOfRange() {
long vectorSize = 10;
long[] indices = new long[] { 0, vectorSize - 1, -1 };
long[] expectedFinalValues = new long[] { 20, 30, 40, 50, 60, 70, 80, 90, 100 };
String[] expectedErrMsgs = new String[] { "Index out of range: 9", "Index out of range: -1" };
BValue[] returns = BRunUtil.invoke(compileResult, "testRemoveIndexOutOfRange", new BValue[] { buildIntArray(indices), new BInteger(vectorSize) });
Assert.assertNotNull(returns);
BStruct vector = (BStruct) returns[0];
BRefValueArray vectorEntries = (BRefValueArray) vector.getRefField(0);
long finalVectorSize = vector.getIntField(0);
Assert.assertEquals(finalVectorSize, expectedFinalValues.length);
for (int i = 0; i < finalVectorSize; i++) {
Assert.assertEquals(vectorEntries.get(i).value(), expectedFinalValues[i]);
}
BRefValueArray removedVals = (BRefValueArray) returns[1];
// only 1 valid index
Assert.assertEquals(removedVals.size(), 1);
Assert.assertEquals(((BInteger) removedVals.get(0)).intValue(), 10);
BRefValueArray errors = (BRefValueArray) returns[2];
Assert.assertEquals(errors.size(), expectedErrMsgs.length);
for (int i = 0; i < expectedErrMsgs.length; i++) {
Assert.assertTrue(errors.get(i).stringValue().contains(expectedErrMsgs[i]));
}
}
Aggregations