use of org.ballerinalang.model.values.BRefValueArray in project ballerina by ballerina-lang.
the class SystemTest method testFormatBooleanFalse.
@Test
public void testFormatBooleanFalse() {
BRefValueArray fArgs = new BRefValueArray();
fArgs.add(0, new BBoolean(false));
BValue[] args = { new BString("%b"), fArgs };
BValue[] returns = BRunUtil.invoke(compileResult, "testSprintf", args);
Assert.assertEquals(returns[0].stringValue(), "false");
}
use of org.ballerinalang.model.values.BRefValueArray in project ballerina by ballerina-lang.
the class SystemTest method testFormatIntArray.
@Test
public void testFormatIntArray() {
BRefValueArray fArgs = new BRefValueArray();
BIntArray arr = new BIntArray();
arr.add(0, 111);
arr.add(1, 222);
arr.add(2, 333);
fArgs.add(0, arr);
BValue[] args = { new BString("%a"), fArgs };
BValue[] returns = BRunUtil.invoke(compileResult, "testSprintf", args);
Assert.assertEquals(returns[0].stringValue(), "[111, 222, 333]");
}
use of org.ballerinalang.model.values.BRefValueArray in project ballerina by ballerina-lang.
the class SystemTest method testFormatDecimal.
@Test
public void testFormatDecimal() {
BRefValueArray fArgs = new BRefValueArray();
fArgs.add(0, new BInteger(65));
BValue[] args = { new BString("%d"), fArgs };
BValue[] returns = BRunUtil.invoke(compileResult, "testSprintf", args);
Assert.assertEquals(returns[0].stringValue(), "65");
}
use of org.ballerinalang.model.values.BRefValueArray in project ballerina by ballerina-lang.
the class NativeConversionTest method testStructToMapWithRefTypeArray.
// Todo - Fix casting issue
@Test(enabled = false)
public void testStructToMapWithRefTypeArray() {
BValue[] returns = BRunUtil.invoke(compileResult, "testStructToMapWithRefTypeArray");
Assert.assertTrue(returns[0] instanceof BMap<?, ?>);
BMap<String, ?> map = (BMap<String, ?>) returns[0];
BValue name = map.get("title");
Assert.assertTrue(name instanceof BString);
Assert.assertEquals(name.stringValue(), "The Revenant");
BValue age = map.get("year");
Assert.assertTrue(age instanceof BInteger);
Assert.assertEquals(((BInteger) age).intValue(), 2015);
BValue marks = map.get("genre");
Assert.assertTrue(marks instanceof BStringArray);
BStringArray genreArray = (BStringArray) marks;
Assert.assertEquals(genreArray.get(0), "Adventure");
Assert.assertEquals(genreArray.get(1), "Drama");
Assert.assertEquals(genreArray.get(2), "Thriller");
BValue actors = map.get("actors");
Assert.assertTrue(actors instanceof BRefValueArray);
BRefValueArray actorsArray = (BRefValueArray) actors;
Assert.assertTrue(actorsArray.get(0) instanceof BStruct);
Assert.assertEquals(actorsArray.get(0).stringValue(), "{fname:\"Leonardo\", lname:\"DiCaprio\", age:35}");
}
use of org.ballerinalang.model.values.BRefValueArray in project ballerina by ballerina-lang.
the class AbstractSQLAction method executeUpdateWithKeys.
protected void executeUpdateWithKeys(Context context, SQLDatasource datasource, String query, BStringArray keyColumns, BRefValueArray parameters) {
Connection conn = null;
PreparedStatement stmt = null;
ResultSet rs = null;
boolean isInTransaction = context.isInTransaction();
try {
conn = getDatabaseConnection(context, datasource, isInTransaction);
String processedQuery = createProcessedQueryString(query, parameters);
int keyColumnCount = 0;
if (keyColumns != null) {
keyColumnCount = (int) keyColumns.size();
}
if (keyColumnCount > 0) {
String[] columnArray = new String[keyColumnCount];
for (int i = 0; i < keyColumnCount; i++) {
columnArray[i] = keyColumns.get(i);
}
stmt = conn.prepareStatement(processedQuery, columnArray);
} else {
stmt = conn.prepareStatement(processedQuery, Statement.RETURN_GENERATED_KEYS);
}
createProcessedStatement(conn, stmt, parameters);
int count = stmt.executeUpdate();
BInteger updatedCount = new BInteger(count);
rs = stmt.getGeneratedKeys();
/*The result set contains the auto generated keys. There can be multiple auto generated columns
in a table.*/
BStringArray generatedKeys = null;
if (rs.next()) {
generatedKeys = getGeneratedKeys(rs);
}
BRefValueArray tuple = new BRefValueArray(executeUpdateWithKeysTupleType);
tuple.add(0, updatedCount);
tuple.add(1, generatedKeys);
context.setReturnValues(tuple);
} catch (SQLException e) {
throw new BallerinaException("execute update with generated keys failed: " + e.getMessage(), e);
} finally {
SQLDatasourceUtils.cleanupConnection(rs, stmt, conn, isInTransaction);
}
}
Aggregations