Search in sources :

Example 6 with LocalDataSet

use of org.apache.geode.internal.cache.LocalDataSet in project geode by apache.

the class DefaultQuery method execute.

@Override
public Object execute(RegionFunctionContext context, Object[] params) throws FunctionDomainException, TypeMismatchException, NameResolutionException, QueryInvocationTargetException {
    // Supported only with RegionFunctionContext
    if (context == null) {
        throw new IllegalArgumentException(LocalizedStrings.DefaultQuery_FUNCTIONCONTEXT_CANNOT_BE_NULL.toLocalizedString());
    }
    this.isQueryWithFunctionContext = true;
    if (params == null) {
        throw new IllegalArgumentException(LocalizedStrings.DefaultQuery_PARAMETERS_CANNOT_BE_NULL.toLocalizedString());
    }
    long startTime = 0L;
    if (this.traceOn && this.cache != null) {
        startTime = NanoTimer.getTime();
    }
    QueryObserver indexObserver = null;
    QueryExecutor qe = checkQueryOnPR(params);
    Object result = null;
    try {
        indexObserver = startTrace();
        if (qe != null) {
            LocalDataSet localDataSet = (LocalDataSet) PartitionRegionHelper.getLocalDataForContext(context);
            Set<Integer> buckets = localDataSet.getBucketSet();
            result = qe.executeQuery(this, params, buckets);
            return result;
        } else {
            // Not supported on regions other than PartitionRegion.
            throw new IllegalArgumentException(LocalizedStrings.DefaultQuery_API_ONLY_FOR_PR.toLocalizedString());
        }
    } finally {
        this.endTrace(indexObserver, startTime, result);
    }
}
Also used : LocalDataSet(org.apache.geode.internal.cache.LocalDataSet)

Example 7 with LocalDataSet

use of org.apache.geode.internal.cache.LocalDataSet in project geode by apache.

the class QueryUsingFunctionContextDUnitTest method runQueryOnServerLDS.

protected ArrayList runQueryOnServerLDS(String queryStr, Set filter) {
    Set buckets = getBucketsForFilter(filter);
    Region localDataSet = new LocalDataSet((PartitionedRegion) CacheFactory.getAnyInstance().getRegion(PartitionedRegionName1), buckets);
    QueryService qservice = CacheFactory.getAnyInstance().getQueryService();
    Query query = qservice.newQuery(queryStr);
    SelectResults results;
    try {
        results = (SelectResults) ((LocalDataSet) localDataSet).executeQuery((DefaultQuery) query, null, buckets);
        return (ArrayList) results.asList();
    } catch (Exception e) {
        e.printStackTrace();
    }
    return null;
}
Also used : LocalDataSet(org.apache.geode.internal.cache.LocalDataSet) Set(java.util.Set) StructSetOrResultsSet(org.apache.geode.cache.query.functional.StructSetOrResultsSet) HashSet(java.util.HashSet) SelectResults(org.apache.geode.cache.query.SelectResults) DefaultQuery(org.apache.geode.cache.query.internal.DefaultQuery) Query(org.apache.geode.cache.query.Query) LocalDataSet(org.apache.geode.internal.cache.LocalDataSet) QueryService(org.apache.geode.cache.query.QueryService) ArrayList(java.util.ArrayList) PartitionedRegion(org.apache.geode.internal.cache.PartitionedRegion) Region(org.apache.geode.cache.Region) QueryInvocationTargetException(org.apache.geode.cache.query.QueryInvocationTargetException) IgnoredException(org.apache.geode.test.dunit.IgnoredException) FunctionException(org.apache.geode.cache.execute.FunctionException) ServerConnectivityException(org.apache.geode.cache.client.ServerConnectivityException) CacheException(org.apache.geode.cache.CacheException)

Example 8 with LocalDataSet

use of org.apache.geode.internal.cache.LocalDataSet in project geode by apache.

the class QRegion method getEntries.

/**
   * Returns the entries as an unmodifiable SelectResults. This is the preferred method that is
   * invoked when accessing the attribute "entries".
   */
public SelectResults getEntries() {
    ResultsCollectionWrapper res;
    if (this.region instanceof LocalDataSet) {
        LocalDataSet localData = (LocalDataSet) this.region;
        res = new ResultsCollectionWrapper(TypeUtils.getRegionEntryType(this.region), localData.localEntrySet());
    } else {
        res = new ResultsCollectionWrapper(TypeUtils.getRegionEntryType(this.region), this.region.entrySet(false));
    }
    res.setModifiable(false);
    return res;
}
Also used : LocalDataSet(org.apache.geode.internal.cache.LocalDataSet)

Example 9 with LocalDataSet

use of org.apache.geode.internal.cache.LocalDataSet in project geode by apache.

the class QRegion method getKeys.

/**
   * Returns unmodifiable SelectResults for keys. When the "keys" attribute is accessed, this is the
   * preferred method that will be executed.
   */
public SelectResults getKeys() {
    ResultsCollectionWrapper res;
    if (this.region instanceof LocalDataSet) {
        LocalDataSet localData = (LocalDataSet) this.region;
        res = new ResultsCollectionWrapper(getKeyType(), localData.localKeys());
    } else {
        res = new ResultsCollectionWrapper(getKeyType(), this.region.keySet());
    }
    res.setModifiable(false);
    return res;
}
Also used : LocalDataSet(org.apache.geode.internal.cache.LocalDataSet)

Example 10 with LocalDataSet

use of org.apache.geode.internal.cache.LocalDataSet in project geode by apache.

the class PartitionRegionHelper method getLocalData.

/**
   * Given a partitioned Region return a Region providing read access limited to the local heap,
   * writes using this Region have no constraints and behave the same as a partitioned Region.<br>
   * 
   * @param r a partitioned region
   * @throws IllegalStateException if the provided region is something other than a
   *         {@linkplain DataPolicy#PARTITION partitioned Region}
   * @return a Region for efficient reads
   * @since GemFire 6.0
   */
public static <K, V> Region<K, V> getLocalData(final Region<K, V> r) {
    if (isPartitionedRegion(r)) {
        PartitionedRegion pr = (PartitionedRegion) r;
        final Set<Integer> buckets;
        if (pr.getDataStore() != null) {
            buckets = pr.getDataStore().getAllLocalBucketIds();
        } else {
            buckets = Collections.emptySet();
        }
        return new LocalDataSet(pr, buckets);
    } else if (r instanceof LocalDataSet) {
        return r;
    } else {
        throw new IllegalArgumentException(LocalizedStrings.PartitionManager_REGION_0_IS_NOT_A_PARTITIONED_REGION.toLocalizedString(r.getFullPath()));
    }
}
Also used : LocalDataSet(org.apache.geode.internal.cache.LocalDataSet) PartitionedRegion(org.apache.geode.internal.cache.PartitionedRegion)

Aggregations

LocalDataSet (org.apache.geode.internal.cache.LocalDataSet)15 PartitionedRegion (org.apache.geode.internal.cache.PartitionedRegion)11 Region (org.apache.geode.cache.Region)6 DefaultQuery (org.apache.geode.cache.query.internal.DefaultQuery)5 ArrayList (java.util.ArrayList)4 RegionFunctionContext (org.apache.geode.cache.execute.RegionFunctionContext)4 Test (org.junit.Test)4 Serializable (java.io.Serializable)3 HashSet (java.util.HashSet)3 Set (java.util.Set)3 FunctionException (org.apache.geode.cache.execute.FunctionException)3 QueryService (org.apache.geode.cache.query.QueryService)3 SelectResults (org.apache.geode.cache.query.SelectResults)3 Map (java.util.Map)2 PartitionAttributesFactory (org.apache.geode.cache.PartitionAttributesFactory)2 Function (org.apache.geode.cache.execute.Function)2 FunctionAdapter (org.apache.geode.cache.execute.FunctionAdapter)2 FunctionContext (org.apache.geode.cache.execute.FunctionContext)2 Query (org.apache.geode.cache.query.Query)2 QueryInvocationTargetException (org.apache.geode.cache.query.QueryInvocationTargetException)2