Search in sources :

Example 1 with SelectResultRow

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()));
        }
    }
}
Also used : StructImpl(org.apache.geode.cache.query.internal.StructImpl) GfJsonObject(org.apache.geode.management.internal.cli.json.GfJsonObject) SelectResultRow(org.apache.geode.management.internal.cli.domain.DataCommandResult.SelectResultRow) GfJsonException(org.apache.geode.management.internal.cli.json.GfJsonException) GfJsonObject(org.apache.geode.management.internal.cli.json.GfJsonObject) Struct(org.apache.geode.cache.query.Struct)

Example 2 with SelectResultRow

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();
        }
    }
}
Also used : DefaultQuery(org.apache.geode.cache.query.internal.DefaultQuery) DefaultQuery(org.apache.geode.cache.query.internal.DefaultQuery) Query(org.apache.geode.cache.query.Query) TypeMismatchException(org.apache.geode.cache.query.TypeMismatchException) ArrayList(java.util.ArrayList) GfJsonException(org.apache.geode.management.internal.cli.json.GfJsonException) InternalCache(org.apache.geode.internal.cache.InternalCache) QueryInvocationTargetException(org.apache.geode.cache.query.QueryInvocationTargetException) NameResolutionException(org.apache.geode.cache.query.NameResolutionException) SelectResults(org.apache.geode.cache.query.SelectResults) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) QueryService(org.apache.geode.cache.query.QueryService) FunctionDomainException(org.apache.geode.cache.query.FunctionDomainException) SelectResultRow(org.apache.geode.management.internal.cli.domain.DataCommandResult.SelectResultRow) GfJsonObject(org.apache.geode.management.internal.cli.json.GfJsonObject)

Example 3 with SelectResultRow

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()));
}
Also used : GfJsonObject(org.apache.geode.management.internal.cli.json.GfJsonObject) SelectResultRow(org.apache.geode.management.internal.cli.domain.DataCommandResult.SelectResultRow) GfJsonException(org.apache.geode.management.internal.cli.json.GfJsonException)

Aggregations

SelectResultRow (org.apache.geode.management.internal.cli.domain.DataCommandResult.SelectResultRow)3 GfJsonException (org.apache.geode.management.internal.cli.json.GfJsonException)3 GfJsonObject (org.apache.geode.management.internal.cli.json.GfJsonObject)3 ArrayList (java.util.ArrayList)1 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)1 FunctionDomainException (org.apache.geode.cache.query.FunctionDomainException)1 NameResolutionException (org.apache.geode.cache.query.NameResolutionException)1 Query (org.apache.geode.cache.query.Query)1 QueryInvocationTargetException (org.apache.geode.cache.query.QueryInvocationTargetException)1 QueryService (org.apache.geode.cache.query.QueryService)1 SelectResults (org.apache.geode.cache.query.SelectResults)1 Struct (org.apache.geode.cache.query.Struct)1 TypeMismatchException (org.apache.geode.cache.query.TypeMismatchException)1 DefaultQuery (org.apache.geode.cache.query.internal.DefaultQuery)1 StructImpl (org.apache.geode.cache.query.internal.StructImpl)1 InternalCache (org.apache.geode.internal.cache.InternalCache)1