use of org.wso2.ballerinalang.compiler.semantics.model.iterable.Operation in project jaggery by wso2.
the class RegistryHostObject method jsFunction_get.
public static Scriptable jsFunction_get(Context cx, Scriptable thisObj, Object[] arguments, Function funObj) throws ScriptException {
RegistryHostObject rho = (RegistryHostObject) thisObj;
if (arguments.length == 1) {
if (arguments[0] instanceof String) {
try {
Scriptable hostObject;
Resource resource = rho.registry.get((String) arguments[0]);
if (resource instanceof Collection) {
hostObject = cx.newObject(rho, "Collection", new Object[] { resource });
} else {
hostObject = cx.newObject(rho, "Resource", new Object[] { resource });
}
return hostObject;
} catch (RegistryException e) {
throw new ScriptException("Registry error occurred while executing get() operation", e);
}
} else {
throw new ScriptException("Path argument of method get() should be a string");
}
} else if (arguments.length == 3) {
if (arguments[0] instanceof String && arguments[1] instanceof Number && arguments[2] instanceof Number) {
try {
Collection collection = rho.registry.get((String) arguments[0], ((Number) arguments[1]).intValue(), ((Number) arguments[2]).intValue());
CollectionHostObject cho = (CollectionHostObject) cx.newObject(rho, "Collection", new Object[] { collection });
return cho;
} catch (RegistryException e) {
throw new ScriptException("Registry error occurred while executing get() operation", e);
}
} else {
throw new ScriptException("Invalid argument types for get() method");
}
} else {
throw new ScriptException("Invalid no. of arguments for get() method");
}
}
use of org.wso2.ballerinalang.compiler.semantics.model.iterable.Operation in project siddhi by wso2.
the class SetUpdateOrInsertInMemoryTableTestCase method updateFromTableTest5.
@Test
public void updateFromTableTest5() throws InterruptedException, SQLException {
log.info("SET-InMemory-update-or-insert test case 5: assignment expression containing an output attribute " + "with a basic arithmatic operation.");
SiddhiManager siddhiManager = new SiddhiManager();
String streams = "" + "define stream StockStream (symbol string, price float, volume long); " + "define stream UpdateStockStream (symbol string, price float, volume long); " + "define table StockTable (symbol string, price float, volume long); ";
String query = "" + "@info(name = 'query1') " + "from StockStream " + "insert into StockTable ;" + "" + "@info(name = 'query2') " + "from UpdateStockStream " + "update or insert into StockTable " + "set StockTable.price = price + 100 " + " on StockTable.symbol == symbol ;";
SiddhiAppRuntime siddhiAppRuntime = siddhiManager.createSiddhiAppRuntime(streams + query);
InputHandler stockStream = siddhiAppRuntime.getInputHandler("StockStream");
InputHandler updateStockStream = siddhiAppRuntime.getInputHandler("UpdateStockStream");
siddhiAppRuntime.start();
stockStream.send(new Object[] { "WSO2", 55.6f, 100L });
stockStream.send(new Object[] { "IBM", 75.6f, 100L });
stockStream.send(new Object[] { "WSO2", 57.6f, 100L });
updateStockStream.send(new Object[] { "IBM", 100f, 100L });
Thread.sleep(1000);
siddhiAppRuntime.shutdown();
}
use of org.wso2.ballerinalang.compiler.semantics.model.iterable.Operation in project carbon-apimgt by wso2.
the class ApiDAOImpl method updateEndpoint.
/**
* Update an Endpoint
*
* @param endpoint Endpoint Object.
* @return Success of the update operation.
* @throws APIMgtDAOException If failed to update endpoint.
*/
@Override
public boolean updateEndpoint(Endpoint endpoint) throws APIMgtDAOException {
final String query = "UPDATE AM_ENDPOINT SET ENDPOINT_CONFIGURATION = ?,TPS = ?,TYPE = " + "?,SECURITY_CONFIGURATION =?, LAST_UPDATED_TIME = ?, GATEWAY_CONFIG = ? WHERE UUID = ?";
try (Connection connection = DAOUtil.getConnection()) {
connection.setAutoCommit(false);
try (PreparedStatement statement = connection.prepareStatement(query)) {
InputStream byteArrayInputStream = IOUtils.toInputStream(endpoint.getEndpointConfig());
statement.setBinaryStream(1, byteArrayInputStream);
if (endpoint.getMaxTps() != null) {
statement.setLong(2, endpoint.getMaxTps());
} else {
statement.setNull(2, Types.INTEGER);
}
statement.setString(3, endpoint.getType());
statement.setBinaryStream(4, IOUtils.toInputStream(endpoint.getSecurity()));
statement.setTimestamp(5, Timestamp.valueOf(LocalDateTime.now()));
statement.setBinaryStream(6, IOUtils.toInputStream(endpoint.getConfig()));
statement.setString(7, endpoint.getId());
statement.execute();
connection.commit();
return true;
} catch (SQLException e) {
connection.rollback();
throw new APIMgtDAOException(DAOUtil.DAO_ERROR_PREFIX + "updating Endpoint: " + endpoint.getName(), e);
} finally {
connection.setAutoCommit(DAOUtil.isAutoCommit());
}
} catch (SQLException e) {
throw new APIMgtDAOException(DAOUtil.DAO_ERROR_PREFIX + "updating Endpoint: " + endpoint.getName(), e);
}
}
use of org.wso2.ballerinalang.compiler.semantics.model.iterable.Operation in project carbon-apimgt by wso2.
the class ApiDAOImpl method deleteEndpoint.
/**
* Delete an Endpoint
*
* @param endpointId UUID of the endpoint.
* @return Success of the delete operation.
* @throws APIMgtDAOException If failed to delete endpoint.
*/
@Override
public boolean deleteEndpoint(String endpointId) throws APIMgtDAOException {
try (Connection connection = DAOUtil.getConnection()) {
try {
connection.setAutoCommit(false);
deleteEndpoint(connection, endpointId);
connection.commit();
return true;
} catch (SQLException e) {
connection.rollback();
throw new APIMgtDAOException(DAOUtil.DAO_ERROR_PREFIX + "deleting Endpoint: " + endpointId, e);
} finally {
connection.setAutoCommit(DAOUtil.isAutoCommit());
}
} catch (SQLException e) {
throw new APIMgtDAOException(DAOUtil.DAO_ERROR_PREFIX + "deleting Endpoint: " + endpointId, e);
}
}
use of org.wso2.ballerinalang.compiler.semantics.model.iterable.Operation in project carbon-apimgt by wso2.
the class APIDefinitionFromSwagger20 method setApiResourceBuilderProperties.
/**
* Extract properties in Operation entry and assign them to api resource builder properties.
*
* @param operationEntry Map entry to be extracted properties
* @param uriTemplateBuilder Uri template builder to assign related properties
* @param resourcePath resource path
* @return APIResource.Builder object
*/
private APIResource.Builder setApiResourceBuilderProperties(Map.Entry<HttpMethod, Operation> operationEntry, UriTemplate.UriTemplateBuilder uriTemplateBuilder, String resourcePath) {
Operation operation = operationEntry.getValue();
APIResource.Builder apiResourceBuilder = new APIResource.Builder();
List<String> producesList = operation.getProduces();
if (producesList != null) {
String produceSeparatedString = "\"";
produceSeparatedString += String.join("\",\"", producesList) + "\"";
apiResourceBuilder.produces(produceSeparatedString);
}
List<String> consumesList = operation.getConsumes();
if (consumesList != null) {
String consumesSeparatedString = "\"";
consumesSeparatedString += String.join("\",\"", consumesList) + "\"";
apiResourceBuilder.consumes(consumesSeparatedString);
}
if (operation.getOperationId() != null) {
uriTemplateBuilder.templateId(operation.getOperationId());
} else {
uriTemplateBuilder.templateId(APIUtils.generateOperationIdFromPath(resourcePath, operationEntry.getKey().name()));
}
uriTemplateBuilder.httpVerb(operationEntry.getKey().name());
apiResourceBuilder.uriTemplate(uriTemplateBuilder.build());
return apiResourceBuilder;
}
Aggregations