use of org.apache.geode.management.internal.cli.domain.DataCommandResult.SelectResultRow in project geode by apache.
the class DataCommandFunction method select_SelectResults.
private void select_SelectResults(SelectResults selectResults, Object principal, List<SelectResultRow> list, AtomicInteger nestedObjectCount) throws GfJsonException {
for (Object object : selectResults) {
// Post processing
object = securityService.postProcess(principal, null, null, object, false);
if (object instanceof Struct) {
StructImpl impl = (StructImpl) object;
GfJsonObject jsonStruct = getJSONForStruct(impl, nestedObjectCount);
if (logger.isDebugEnabled()) {
logger.debug("SelectResults : Adding select json string : {}", jsonStruct);
}
list.add(new SelectResultRow(DataCommandResult.ROW_TYPE_STRUCT_RESULT, jsonStruct.toString()));
} else if (JsonUtil.isPrimitiveOrWrapper(object.getClass())) {
if (logger.isDebugEnabled()) {
logger.debug("SelectResults : Adding select primitive : {}", object);
}
list.add(new SelectResultRow(DataCommandResult.ROW_TYPE_PRIMITIVE, object));
} else {
if (logger.isDebugEnabled()) {
logger.debug("SelectResults : Bean Results class is {}", object.getClass());
}
String str = toJson(object);
GfJsonObject jsonBean;
try {
jsonBean = new GfJsonObject(str);
} catch (GfJsonException e) {
logger.error(e.getMessage(), e);
jsonBean = new GfJsonObject();
try {
jsonBean.put("msg", e.getMessage());
} catch (GfJsonException e1) {
logger.warn("Ignored GfJsonException:", e1);
}
}
if (logger.isDebugEnabled()) {
logger.debug("SelectResults : Adding bean json string : {}", jsonBean);
}
list.add(new SelectResultRow(DataCommandResult.ROW_TYPE_BEAN, jsonBean.toString()));
}
}
}
use of org.apache.geode.management.internal.cli.domain.DataCommandResult.SelectResultRow in project geode by apache.
the class DataCommandFunction method select.
@SuppressWarnings("rawtypes")
private DataCommandResult select(Object principal, String queryString) {
InternalCache cache = getCache();
AtomicInteger nestedObjectCount = new AtomicInteger(0);
if (StringUtils.isEmpty(queryString)) {
return DataCommandResult.createSelectInfoResult(null, null, -1, null, CliStrings.QUERY__MSG__QUERY_EMPTY, false);
}
QueryService qs = cache.getQueryService();
// TODO : Find out if is this optimised use. Can you have something equivalent of parsed
// queries with names where name can be retrieved to avoid parsing every-time
Query query = qs.newQuery(queryString);
DefaultQuery tracedQuery = (DefaultQuery) query;
WrappedIndexTrackingQueryObserver queryObserver = null;
String queryVerboseMsg = null;
long startTime = -1;
if (tracedQuery.isTraced()) {
startTime = NanoTimer.getTime();
queryObserver = new WrappedIndexTrackingQueryObserver();
QueryObserverHolder.setInstance(queryObserver);
}
List<SelectResultRow> list = new ArrayList<>();
try {
Object results = query.execute();
if (tracedQuery.isTraced()) {
queryVerboseMsg = getLogMessage(queryObserver, startTime, queryString);
queryObserver.reset2();
}
if (results instanceof SelectResults) {
select_SelectResults((SelectResults) results, principal, list, nestedObjectCount);
} else {
select_NonSelectResults(results, list);
}
return DataCommandResult.createSelectResult(queryString, list, queryVerboseMsg, null, null, true);
} catch (FunctionDomainException | GfJsonException | QueryInvocationTargetException | NameResolutionException | TypeMismatchException e) {
logger.warn(e.getMessage(), e);
return DataCommandResult.createSelectResult(queryString, null, queryVerboseMsg, e, e.getMessage(), false);
} finally {
if (queryObserver != null) {
QueryObserverHolder.reset();
}
}
}
use of org.apache.geode.management.internal.cli.domain.DataCommandResult.SelectResultRow in project geode by apache.
the class DataCommandFunction method select_NonSelectResults.
private void select_NonSelectResults(Object results, List<SelectResultRow> list) {
if (logger.isDebugEnabled()) {
logger.debug("BeanResults : Bean Results class is {}", results.getClass());
}
String str = toJson(results);
GfJsonObject jsonBean;
try {
jsonBean = new GfJsonObject(str);
} catch (GfJsonException e) {
logger.info("Exception occurred:", e);
jsonBean = new GfJsonObject();
try {
jsonBean.put("msg", e.getMessage());
} catch (GfJsonException e1) {
logger.warn("Ignored GfJsonException:", e1);
}
}
if (logger.isDebugEnabled()) {
logger.debug("BeanResults : Adding bean json string : {}", jsonBean);
}
list.add(new SelectResultRow(DataCommandResult.ROW_TYPE_BEAN, jsonBean.toString()));
}
Aggregations