Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance. Project price only 1 $
You can buy this project and download/modify it how often you want.
/*
* Copyright 2010-2013 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.data.gemfire;
import java.lang.reflect.InvocationHandler;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.lang.reflect.Proxy;
import java.util.Collection;
import java.util.Map;
import org.springframework.dao.DataAccessException;
import org.springframework.dao.InvalidDataAccessApiUsageException;
import org.springframework.util.Assert;
import org.springframework.util.ClassUtils;
import com.gemstone.gemfire.GemFireCheckedException;
import com.gemstone.gemfire.GemFireException;
import com.gemstone.gemfire.cache.Region;
import com.gemstone.gemfire.cache.Scope;
import com.gemstone.gemfire.cache.client.ClientCache;
import com.gemstone.gemfire.cache.query.IndexInvalidException;
import com.gemstone.gemfire.cache.query.Query;
import com.gemstone.gemfire.cache.query.QueryInvalidException;
import com.gemstone.gemfire.cache.query.QueryService;
import com.gemstone.gemfire.cache.query.SelectResults;
import com.gemstone.gemfire.internal.cache.LocalRegion;
/**
* Helper class that simplifies GemFire data access code and converts {@link GemFireCheckedException} and
* {@link GemFireException} into Spring {@link DataAccessException}, following the org.springframework.dao
* exception hierarchy.
*
*
* The central method is execute, supporting GemFire access code implementing the GemfireCallback interface.
* It provides dedicated handling such that neither the GemfireCallback implementation nor the calling code needs to
* explicitly care about handling {@link Region} life-cycle exceptions.
* Typically used to implement data access or business logic services that use GemFire within their implementation but
* are GemFire-agnostic in their interface. The latter or code calling the latter only have to deal with business
* objects, query objects, and org.springframework.dao exceptions.
*
* @author Costin Leau
*/
public class GemfireTemplate extends GemfireAccessor implements GemfireOperations {
private boolean exposeNativeRegion = false;
private Region, ?> regionProxy;
public GemfireTemplate() {
}
public GemfireTemplate(Region region) {
setRegion(region);
afterPropertiesSet();
}
@Override
public void afterPropertiesSet() {
super.afterPropertiesSet();
regionProxy = createRegionProxy(getRegion());
}
/**
* Sets whether to expose the native Gemfire Region to GemfireCallback
* code. Default is "false": a Region proxy will be returned,
* suppressing close calls.
*
As there is often a need to cast to a interface, the exposed proxy
* implements all interfaces implemented by the original {@link Region}.
* If this is not sufficient, turn this flag to "true".
* @see GemfireCallback
*/
public void setExposeNativeRegion(boolean exposeNativeRegion) {
this.exposeNativeRegion = exposeNativeRegion;
}
/**
* Returns whether to expose the native GemFire Region to GemfireCallback
* code, or rather a Region proxy.
*/
public boolean isExposeNativeRegion() {
return this.exposeNativeRegion;
}
/* (non-Javadoc)
* @see org.springframework.data.gemfire.GemfireOperations#containsKey(java.lang.Object)
*/
@Override
public boolean containsKey(final Object key) {
return execute(new GemfireCallback() {
public Boolean doInGemfire(Region,?> region) throws GemFireCheckedException, GemFireException {
return region.containsKey(key);
}
});
}
/* (non-Javadoc)
* @see org.springframework.data.gemfire.GemfireOperations#containsKeyOnServer(java.lang.Object)
*/
@Override
public boolean containsKeyOnServer(final Object key) {
return execute(new GemfireCallback() {
public Boolean doInGemfire(Region,?> region) throws GemFireCheckedException, GemFireException {
return region.containsKeyOnServer(key);
}
});
}
/* (non-Javadoc)
* @see org.springframework.data.gemfire.GemfireOperations#containsValue(java.lang.Object)
*/
@Override
public boolean containsValue(final Object value) {
return execute(new GemfireCallback() {
public Boolean doInGemfire(Region,?> region) throws GemFireCheckedException, GemFireException {
return region.containsValue(value);
}
});
}
/* (non-Javadoc)
* @see org.springframework.data.gemfire.GemfireOperations#containsValueForKey(java.lang.Object)
*/
@Override
public boolean containsValueForKey(final Object key) {
return execute(new GemfireCallback() {
public Boolean doInGemfire(Region,?> region) throws GemFireCheckedException, GemFireException {
return region.containsValueForKey(key);
}
});
}
/* (non-Javadoc)
* @see org.springframework.data.gemfire.GemfireOperations#create(K, V)
*/
@Override
public void create(final K key, final V value) {
execute(new GemfireCallback