Search in sources :

Example 1 with BTable

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;
}
Also used : EventContext(org.ballerinalang.nativeimpl.io.events.EventContext) Context(org.ballerinalang.bre.Context) EventContext(org.ballerinalang.nativeimpl.io.events.EventContext) BTable(org.ballerinalang.model.values.BTable) BStruct(org.ballerinalang.model.values.BStruct) List(java.util.List) CallableUnitCallback(org.ballerinalang.bre.bvm.CallableUnitCallback)

Example 2 with BTable

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;
}
Also used : BStructType(org.ballerinalang.model.types.BStructType) BTypeDescValue(org.ballerinalang.model.values.BTypeDescValue) BTable(org.ballerinalang.model.values.BTable) BStruct(org.ballerinalang.model.values.BStruct) BTableType(org.ballerinalang.model.types.BTableType)

Example 3 with BTable

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());
}
Also used : BTable(org.ballerinalang.model.values.BTable)

Example 4 with BTable

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())));
}
Also used : BTable(org.ballerinalang.model.values.BTable) BBoolean(org.ballerinalang.model.values.BBoolean)

Example 5 with BTable

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();
}
Also used : BTable(org.ballerinalang.model.values.BTable) BStruct(org.ballerinalang.model.values.BStruct)

Aggregations

BTable (org.ballerinalang.model.values.BTable)13 BStruct (org.ballerinalang.model.values.BStruct)7 BRefValueArray (org.ballerinalang.model.values.BRefValueArray)3 BValue (org.ballerinalang.model.values.BValue)3 BJSON (org.ballerinalang.model.values.BJSON)2 BRefType (org.ballerinalang.model.values.BRefType)2 BString (org.ballerinalang.model.values.BString)2 BTypeDescValue (org.ballerinalang.model.values.BTypeDescValue)2 Test (org.testng.annotations.Test)2 List (java.util.List)1 StringJoiner (java.util.StringJoiner)1 Context (org.ballerinalang.bre.Context)1 CallableUnitCallback (org.ballerinalang.bre.bvm.CallableUnitCallback)1 BMapType (org.ballerinalang.model.types.BMapType)1 BStructType (org.ballerinalang.model.types.BStructType)1 BTableType (org.ballerinalang.model.types.BTableType)1 BBlobArray (org.ballerinalang.model.values.BBlobArray)1 BBoolean (org.ballerinalang.model.values.BBoolean)1 BBooleanArray (org.ballerinalang.model.values.BBooleanArray)1 BFloat (org.ballerinalang.model.values.BFloat)1