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);
}
}
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;
}
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;
}
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;
}
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()));
}
}
Aggregations