use of com.developmentontheedge.be5.query.impl.model.Be5QueryExecutor in project be5 by DevelopmentOnTheEdge.
the class QueryBuilder method select.
private void select(String sql, Request req, Injector injector) {
DocumentGenerator documentGenerator = injector.get(DocumentGenerator.class);
String userQBuilderQueryName = UserInfoHolder.getUserName() + "Query";
Map<String, String> parametersMap = req.getValuesFromJsonAsStrings(RestApiConstants.VALUES);
Entity entity = new Entity(entityName, injector.getProject().getApplication(), EntityType.TABLE);
DataElementUtils.save(entity);
Query query = new Query(userQBuilderQueryName, entity);
query.setType(QueryType.D1_UNKNOWN);
if (sql != null) {
query.setQuery(sql);
}
DataElementUtils.save(query);
try {
resourceDataList.add(new ResourceData("finalSql", FrontendConstants.STATIC_ACTION, new StaticPagePresentation("Final sql", new Be5QueryExecutor(query, parametersMap, injector).getFinalSql()), null));
} catch (Be5Exception e) {
errorModelList.add(new ErrorModel(e));
}
try {
JsonApiModel document = documentGenerator.getDocument(query, parametersMap);
// todo refactor documentGenerator
document.getData().setId("result");
resourceDataList.add(document.getData());
resourceDataList.addAll(Arrays.asList(document.getIncluded()));
} catch (Be5Exception e) {
errorModelList.add(new ErrorModel(e));
}
entity.getOrigin().remove(entityName);
}
use of com.developmentontheedge.be5.query.impl.model.Be5QueryExecutor in project be5 by DevelopmentOnTheEdge.
the class OperationHelper method getTagsFromCustomSelectionViewExecute.
//
// public Map<String, String> getTagsMapFromQuery( Map<String, String> parameters, String query, Object... params )
// {
// //return getTagsListFromQuery( Collections.emptyMap(), query, params );
// List<String[]> tags = db.selectList("SELECT " + valueColumnName + ", " + textColumnName + " FROM " + tableName,
// rs -> new String[]{rs.getString(valueColumnName), rs.getString(textColumnName)}
// );
// String[][] stockArr = new String[tags.size()][2];
// return tags.toArray(stockArr);
// }
private String[][] getTagsFromCustomSelectionViewExecute(Query query, Map<String, ?> parameters) {
String entityName = query.getEntity().getName();
// todo refactoring Be5QueryExecutor,
Map<String, String> stringStringMap = new HashMap<>();
// parameters.forEach((key, value) -> stringStringMap.put(key, value.toString()));
for (Map.Entry<String, ?> entry : parameters.entrySet()) {
if (entry.getValue() != null)
stringStringMap.put(entry.getKey(), entry.getValue().toString());
}
TableModel table = TableModel.from(query, stringStringMap, false, injector).limit(Integer.MAX_VALUE).build();
String[][] stockArr = new String[table.getRows().size()][2];
int i = 0;
for (TableModel.RowModel row : table.getRows()) {
String first = row.getCells().size() >= 1 ? row.getCells().get(0).content.toString() : "";
String second = row.getCells().size() >= 2 ? row.getCells().get(1).content.toString() : "";
stockArr[i++] = new String[] { first, userAwareMeta.getColumnTitle(entityName, second) };
}
return stockArr;
}
Aggregations