use of org.ballerinalang.nativeimpl.actions.data.sql.SQLDatasource 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.nativeimpl.actions.data.sql.SQLDatasource 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.nativeimpl.actions.data.sql.SQLDatasource in project ballerina by ballerina-lang.
the class InitEndpoint method execute.
@Override
public void execute(Context context) {
Struct clientEndpoint = BLangConnectorSPIUtil.getConnectorEndpointStruct(context);
Struct clientEndpointConfig = clientEndpoint.getStructField(Constants.CLIENT_ENDPOINT_CONFIG);
// Extract parameters from the endpoint config
String database = clientEndpointConfig.getEnumField(Constants.EndpointConfig.DATABASE);
String host = clientEndpointConfig.getStringField(Constants.EndpointConfig.HOST);
int port = (int) clientEndpointConfig.getIntField(Constants.EndpointConfig.PORT);
String name = clientEndpointConfig.getStringField(Constants.EndpointConfig.NAME);
String username = clientEndpointConfig.getStringField(Constants.EndpointConfig.USERNAME);
String password = clientEndpointConfig.getStringField(Constants.EndpointConfig.PASSWORD);
Struct options = clientEndpointConfig.getStructField(Constants.EndpointConfig.OPTIONS);
SQLDatasource datasource = new SQLDatasource();
datasource.init(options, database, host, port, username, password, name);
BStruct ballerinaClientConnector;
if (clientEndpoint.getNativeData(Constants.B_CONNECTOR) != null) {
ballerinaClientConnector = (BStruct) clientEndpoint.getNativeData(Constants.B_CONNECTOR);
} else {
ballerinaClientConnector = BLangConnectorSPIUtil.createBStruct(context.getProgramFile(), Constants.SQL_PACKAGE_PATH, Constants.CLIENT_CONNECTOR, database, host, port, name, username, password, options, clientEndpointConfig);
clientEndpoint.addNativeData(Constants.B_CONNECTOR, ballerinaClientConnector);
}
ballerinaClientConnector.addNativeData(Constants.CLIENT_CONNECTOR, datasource);
context.setReturnValues();
}
use of org.ballerinalang.nativeimpl.actions.data.sql.SQLDatasource in project ballerina by ballerina-lang.
the class Call 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);
executeProcedure(context, datasource, query, parameters, structType);
} catch (Throwable e) {
context.setReturnValues(SQLDatasourceUtils.getSQLConnectorError(context, e));
SQLDatasourceUtils.handleErrorOnTransaction(context);
}
}
use of org.ballerinalang.nativeimpl.actions.data.sql.SQLDatasource in project ballerina by ballerina-lang.
the class Close method execute.
@Override
public void execute(Context context) {
try {
BStruct bConnector = (BStruct) context.getRefArgument(0);
SQLDatasource datasource = (SQLDatasource) bConnector.getNativeData(Constants.CLIENT_CONNECTOR);
closeConnections(datasource);
context.setReturnValues(null);
} catch (Throwable e) {
context.setReturnValues(SQLDatasourceUtils.getSQLConnectorError(context, e));
SQLDatasourceUtils.handleErrorOnTransaction(context);
}
}
Aggregations