Search in sources :

Example 6 with SQLDatasource

use of org.ballerinalang.nativeimpl.actions.data.sql.SQLDatasource in project ballerina by ballerina-lang.

the class Select 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);
        BStructType structType = getStructType(context);
        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);
        executeQuery(context, datasource, query, parameters, structType);
    } catch (Throwable e) {
        context.setReturnValues(SQLDatasourceUtils.getSQLConnectorError(context, e));
        SQLDatasourceUtils.handleErrorOnTransaction(context);
    }
}
Also used : BStructType(org.ballerinalang.model.types.BStructType) BStruct(org.ballerinalang.model.values.BStruct) HashMap(java.util.HashMap) BRefValueArray(org.ballerinalang.model.values.BRefValueArray) SQLDatasource(org.ballerinalang.nativeimpl.actions.data.sql.SQLDatasource)

Example 7 with SQLDatasource

use of org.ballerinalang.nativeimpl.actions.data.sql.SQLDatasource in project ballerina by ballerina-lang.

the class UpdateWithGeneratedKeys 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);
        BStringArray keyColumns = (BStringArray) context.getNullableRefArgument(2);
        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);
        executeUpdateWithKeys(context, datasource, query, keyColumns, parameters);
    } catch (Throwable e) {
        context.setReturnValues(SQLDatasourceUtils.getSQLConnectorError(context, e));
        SQLDatasourceUtils.handleErrorOnTransaction(context);
    }
}
Also used : BStruct(org.ballerinalang.model.values.BStruct) HashMap(java.util.HashMap) BRefValueArray(org.ballerinalang.model.values.BRefValueArray) SQLDatasource(org.ballerinalang.nativeimpl.actions.data.sql.SQLDatasource) BStringArray(org.ballerinalang.model.values.BStringArray)

Aggregations

BStruct (org.ballerinalang.model.values.BStruct)7 SQLDatasource (org.ballerinalang.nativeimpl.actions.data.sql.SQLDatasource)7 HashMap (java.util.HashMap)5 BRefValueArray (org.ballerinalang.model.values.BRefValueArray)5 BStructType (org.ballerinalang.model.types.BStructType)2 Struct (org.ballerinalang.connector.api.Struct)1 BStringArray (org.ballerinalang.model.values.BStringArray)1