Search in sources :

Example 11 with TypedJson

use of org.apache.geode.management.internal.cli.json.TypedJson in project geode by apache.

the class TypedJsonJUnitTest method testUserObject.

@Test
public void testUserObject() {
    Portfolio p = new Portfolio(2);
    TypedJson tjson = new TypedJson(RESULT, p);
    System.out.println(tjson);
}
Also used : Portfolio(org.apache.geode.cache.query.data.Portfolio) TypedJson(org.apache.geode.management.internal.cli.json.TypedJson) Test(org.junit.Test) IntegrationTest(org.apache.geode.test.junit.categories.IntegrationTest)

Example 12 with TypedJson

use of org.apache.geode.management.internal.cli.json.TypedJson in project geode by apache.

the class TypedJsonJUnitTest method testArray.

@Test
public void testArray() {
    int[] arr = new int[3];
    for (int i = 0; i < 3; i++) {
        arr[i] = i;
    }
    TypedJson tjson = new TypedJson(RESULT, arr);
    checkResult(tjson);
}
Also used : TypedJson(org.apache.geode.management.internal.cli.json.TypedJson) Test(org.junit.Test) IntegrationTest(org.apache.geode.test.junit.categories.IntegrationTest)

Example 13 with TypedJson

use of org.apache.geode.management.internal.cli.json.TypedJson in project geode by apache.

the class TypedJsonJUnitTest method testArrayList.

@Test
public void testArrayList() {
    List<String> ls = new ArrayList<String>();
    ls.add("ONE");
    ls.add("TWO");
    ls.add("THREE");
    TypedJson tjson = new TypedJson(RESULT, ls);
    checkResult(tjson);
}
Also used : TypedJson(org.apache.geode.management.internal.cli.json.TypedJson) Test(org.junit.Test) IntegrationTest(org.apache.geode.test.junit.categories.IntegrationTest)

Example 14 with TypedJson

use of org.apache.geode.management.internal.cli.json.TypedJson in project geode by apache.

the class TypedJsonJUnitTest method testBigList.

@Test
public void testBigList() {
    List<String> ls = new ArrayList<String>();
    for (int i = 0; i < 1000; i++) {
        ls.add("BIG_COLL_" + i);
    }
    TypedJson tjson = new TypedJson(RESULT, ls);
    checkResult(tjson);
}
Also used : TypedJson(org.apache.geode.management.internal.cli.json.TypedJson) Test(org.junit.Test) IntegrationTest(org.apache.geode.test.junit.categories.IntegrationTest)

Example 15 with TypedJson

use of org.apache.geode.management.internal.cli.json.TypedJson in project geode by apache.

the class QueryDataFunction method selectWithType.

private QueryDataFunctionResult selectWithType(final FunctionContext context, String queryString, final boolean showMember, final String regionName, final int limit, final int queryResultSetLimit, final int queryCollectionsDepth) throws Exception {
    InternalCache cache = getCache();
    Function localQueryFunc = new LocalQueryFunction("LocalQueryFunction", regionName, showMember).setOptimizeForWrite(true);
    queryString = applyLimitClause(queryString, limit, queryResultSetLimit);
    try {
        TypedJson result = new TypedJson(queryCollectionsDepth);
        Region region = cache.getRegion(regionName);
        if (region == null) {
            throw new Exception(ManagementStrings.QUERY__MSG__REGIONS_NOT_FOUND_ON_MEMBER.toLocalizedString(regionName, cache.getDistributedSystem().getDistributedMember().getId()));
        }
        Object results = null;
        boolean noDataFound = true;
        if (region.getAttributes().getDataPolicy() == DataPolicy.NORMAL) {
            QueryService queryService = cache.getQueryService();
            Query query = queryService.newQuery(queryString);
            results = query.execute();
        } else {
            ResultCollector rcollector;
            PartitionedRegion parRegion = PartitionedRegionHelper.getPartitionedRegion(regionName, cache);
            if (parRegion != null && showMember) {
                if (parRegion.isDataStore()) {
                    Set<BucketRegion> localPrimaryBucketRegions = parRegion.getDataStore().getAllLocalPrimaryBucketRegions();
                    Set<Integer> localPrimaryBucketSet = new HashSet<>();
                    for (BucketRegion bRegion : localPrimaryBucketRegions) {
                        localPrimaryBucketSet.add(bRegion.getId());
                    }
                    LocalDataSet lds = new LocalDataSet(parRegion, localPrimaryBucketSet);
                    DefaultQuery query = (DefaultQuery) cache.getQueryService().newQuery(queryString);
                    results = (SelectResults) lds.executeQuery(query, null, localPrimaryBucketSet);
                }
            } else {
                rcollector = FunctionService.onRegion(cache.getRegion(regionName)).setArguments(queryString).execute(localQueryFunc);
                results = rcollector.getResult();
            }
        }
        if (results != null && results instanceof SelectResults) {
            SelectResults selectResults = (SelectResults) results;
            for (Object object : selectResults) {
                result.add(RESULT_KEY, object);
                noDataFound = false;
            }
        } else if (results != null && results instanceof ArrayList) {
            ArrayList listResults = (ArrayList) results;
            ArrayList actualResult = (ArrayList) listResults.get(0);
            for (Object object : actualResult) {
                result.add(RESULT_KEY, object);
                noDataFound = false;
            }
        }
        if (!noDataFound && showMember) {
            result.add(MEMBER_KEY, cache.getDistributedSystem().getDistributedMember().getId());
        }
        if (noDataFound) {
            return new QueryDataFunctionResult(QUERY_EXEC_SUCCESS, BeanUtilFuncs.compress(new JsonisedErrorMessage(NO_DATA_FOUND).toString()));
        }
        return new QueryDataFunctionResult(QUERY_EXEC_SUCCESS, BeanUtilFuncs.compress(result.toString()));
    } catch (Exception e) {
        logger.warn(e.getMessage(), e);
        throw e;
    }
}
Also used : DefaultQuery(org.apache.geode.cache.query.internal.DefaultQuery) Query(org.apache.geode.cache.query.Query) DefaultQuery(org.apache.geode.cache.query.internal.DefaultQuery) TypedJson(org.apache.geode.management.internal.cli.json.TypedJson) ArrayList(java.util.ArrayList) InternalCache(org.apache.geode.internal.cache.InternalCache) GfJsonException(org.apache.geode.management.internal.cli.json.GfJsonException) FunctionException(org.apache.geode.cache.execute.FunctionException) QueryInvalidException(org.apache.geode.cache.query.QueryInvalidException) Function(org.apache.geode.cache.execute.Function) SelectResults(org.apache.geode.cache.query.SelectResults) BucketRegion(org.apache.geode.internal.cache.BucketRegion) QueryService(org.apache.geode.cache.query.QueryService) LocalDataSet(org.apache.geode.internal.cache.LocalDataSet) PartitionedRegion(org.apache.geode.internal.cache.PartitionedRegion) BucketRegion(org.apache.geode.internal.cache.BucketRegion) Region(org.apache.geode.cache.Region) PartitionedRegion(org.apache.geode.internal.cache.PartitionedRegion) GfJsonObject(org.apache.geode.management.internal.cli.json.GfJsonObject) ResultCollector(org.apache.geode.cache.execute.ResultCollector) HashSet(java.util.HashSet)

Aggregations

TypedJson (org.apache.geode.management.internal.cli.json.TypedJson)15 IntegrationTest (org.apache.geode.test.junit.categories.IntegrationTest)14 Test (org.junit.Test)14 Portfolio (org.apache.geode.cache.query.data.Portfolio)5 Cache (org.apache.geode.cache.Cache)2 CacheFactory (org.apache.geode.cache.CacheFactory)2 GfJsonObject (org.apache.geode.management.internal.cli.json.GfJsonObject)2 PdxInstance (org.apache.geode.pdx.PdxInstance)2 PdxInstanceFactory (org.apache.geode.pdx.PdxInstanceFactory)2 ArrayList (java.util.ArrayList)1 HashSet (java.util.HashSet)1 Region (org.apache.geode.cache.Region)1 Function (org.apache.geode.cache.execute.Function)1 FunctionException (org.apache.geode.cache.execute.FunctionException)1 ResultCollector (org.apache.geode.cache.execute.ResultCollector)1 Query (org.apache.geode.cache.query.Query)1 QueryInvalidException (org.apache.geode.cache.query.QueryInvalidException)1 QueryService (org.apache.geode.cache.query.QueryService)1 SelectResults (org.apache.geode.cache.query.SelectResults)1 DefaultQuery (org.apache.geode.cache.query.internal.DefaultQuery)1