use of org.ballerinalang.model.values.BTable in project ballerina by ballerina-lang.
the class LoadToTable method response.
private static EventResult response(EventResult<List, EventContext> result) {
BStruct errorStruct;
BTable table;
EventContext eventContext = result.getContext();
Context context = eventContext.getContext();
Throwable error = eventContext.getError();
if (null != error) {
errorStruct = IOUtils.createError(context, error.getMessage());
context.setReturnValues(errorStruct);
} else {
try {
List records = result.getResponse();
table = getbTable(context, records);
context.setReturnValues(table);
} catch (Throwable e) {
errorStruct = IOUtils.createError(context, e.getMessage());
context.setReturnValues(errorStruct);
}
}
CallableUnitCallback callback = eventContext.getCallback();
callback.notifySuccess();
return result;
}
use of org.ballerinalang.model.values.BTable in project ballerina by ballerina-lang.
the class LoadToTable method getbTable.
private static BTable getbTable(Context context, List records) throws BallerinaIOException {
BTypeDescValue type = (BTypeDescValue) context.getRefArgument(0);
BTable table = new BTable(new BTableType(type.value()));
BStructType structType = (BStructType) type.value();
boolean skipHeaderLine = context.getBooleanArgument(0);
if (skipHeaderLine && !records.isEmpty()) {
records.remove(0);
}
for (Object obj : records) {
String[] fields = (String[]) obj;
final BStruct struct = getStruct(fields, structType);
if (struct != null) {
table.addData(struct);
}
}
return table;
}
use of org.ballerinalang.model.values.BTable in project ballerina by ballerina-lang.
the class GetNext method execute.
public void execute(Context context) {
BTable table = (BTable) context.getRefArgument(0);
context.setReturnValues(table.getNext());
}
use of org.ballerinalang.model.values.BTable in project ballerina by ballerina-lang.
the class HasNext method execute.
public void execute(Context context) {
BTable table = (BTable) context.getRefArgument(0);
context.setReturnValues(new BBoolean(table.hasNext(context.isInTransaction())));
}
use of org.ballerinalang.model.values.BTable in project ballerina by ballerina-lang.
the class Add method execute.
@Override
public void execute(Context context) {
BTable table = (BTable) context.getRefArgument(0);
BStruct data = (BStruct) context.getRefArgument(1);
table.addData(data);
context.setReturnValues();
}
Aggregations