@Test public void testPersistKeyValue() { metadataStore.put("GemfireMetadataStoreTests-Spring", "Integration"); GemfireTemplate gemfireTemplate = new GemfireTemplate(region); assertEquals("Integration", gemfireTemplate.get("GemfireMetadataStoreTests-Spring")); }
@Test public void testBasicWrite() throws Exception { GemfireItemWriter<String, GemfireItemWriterBuilderTests.Foo> writer = new GemfireItemWriterBuilder<String, GemfireItemWriterBuilderTests.Foo>() .template(this.template).itemKeyMapper(this.itemKeyMapper).build(); writer.write(this.items); verify(this.template).put("val1", items.get(0)); verify(this.template).put("val2", items.get(1)); verify(this.template, never()).remove("val1"); verify(this.template, never()).remove("val2"); }
@Override public <K, V> void create(K key, V value) { try { getRegion().create(key, value); } catch (GemFireException cause) { throw convertGemFireAccessException(cause); } }
QueryService queryService = resolveQueryService(getRegion()); Query query = queryService.newQuery(queryString); Object result = query.execute(params); throw convertGemFireQueryException(cause); throw convertGemFireAccessException(cause); throw convertGemFireAccessException(caue);
@Override public <E> SelectResults<E> query(String query) { try { return this.getRegion().query(query); } catch (IndexInvalidException | QueryInvalidException cause) { throw convertGemFireQueryException(cause); } catch (GemFireCheckedException cause) { throw convertGemFireAccessException(cause); } catch (GemFireException cause) { throw convertGemFireAccessException(cause); } catch (RuntimeException cause) { if (GemfireCacheUtils.isCqInvalidException(cause)) { throw GemfireCacheUtils.convertCqInvalidException(cause); } throw cause; } }
@Override public Order get(long id) { return orderTemplate.get(id); } }
/** * Creates an instance of the GemfireTemplate for the given Pivotal GemFire Cache Region. * <p>Can be overridden in subclasses to provide a GemfireTemplate instance with different configuration, * or even a custom GemfireTemplate subclass. * * @param region the Pivotal GemFire Cache Region for which the GemfireTemplate is created. * @return a new GemfireTemplate instance configured with the given Pivotal GemFire Cache Region. * @see org.apache.geode.cache.Region * @see #setRegion */ protected GemfireTemplate createGemfireTemplate(Region<?, ?> region) { return new GemfireTemplate(region); }
@Override public boolean containsValue(Object value) { return getRegion().containsValue(value); }
@Override @SuppressWarnings({ "unchecked", "rawtypes" }) protected void handleMessageInternal(Message<?> message) { Object payload = message.getPayload(); Map<?, ?> cacheValues = (this.cacheEntryExpressions.size() > 0) ? evaluateCacheEntries(message) : null; if (cacheValues == null) { Assert.state(payload instanceof Map, "If cache entry expressions are not configured, then payload must be a Map"); cacheValues = (Map) payload; } final Map<?, ?> map = cacheValues; this.gemfireTemplate.execute(new GemfireCallback<Object>() { @Override public Object doInGemfire(Region region) throws GemFireCheckedException, GemFireException { region.putAll(map); return null; } }); }
@Override public <T> T execute(GemfireCallback<T> action) throws DataAccessException { return execute(action, isExposeNativeRegion()); }
public <K, V> GemfireTemplate(Region<K, V> region) { setRegion(region); afterPropertiesSet(); }
public List<PersistedResource> findResources(ResourceQuery q) { ApplicationName requiredApp = q.getRequiredApplication(); ServerName requiredSvr = q.getRequiredServer(); EndPointName requiredEp = q.getRequiredEndPoint(); ExternalResourceName requiredEx = q.getRequireExtResource(); String requiredType = q.getRequiredType() == null ? null : q.getRequiredType().getTypeName(); int maxResults = q.getMaxResults(); List<PersistedResource> res = new ArrayList<PersistedResource>(); for (PersistedResourceKey key : (Collection<PersistedResourceKey>)gemfire.getRegion().keySet()) { if (maxResults > 0 && res.size() == maxResults) break; ResourceKey k = key.getKey(); if (requiredApp != null && !requiredApp.equals(k.getApplicationName())) continue; if (requiredSvr != null && !requiredSvr.equals(k.getServerName())) continue; if (requiredEp != null && !requiredEp.equals(k.getEndPointName())) continue; if (requiredEx != null && !requiredEx.equals(k.getExternalResourceName())) continue; if (requiredType != null && !requiredType.equals(k.getType())) continue; res.add((PersistedResource) gemfire.get(key)); } return res; }
@Override public void afterPropertiesSet() { super.afterPropertiesSet(); this.regionProxy = createRegionProxy(getRegion()); }
@Override public List<Order> findCustomerOrders(long customerId) { SelectResults<Order> orders = orderTemplate.find("SELECT * from /Order WHERE customerId = $1", customerId); return (orders == null)?null : orders.asList(); }
@SuppressWarnings("rawtypes") public CacheWritingMessageHandler(Region region) { Assert.notNull(region, "region must not be null"); this.gemfireTemplate.setRegion(region); }
@Override protected void onInit() { super.onInit(); this.gemfireTemplate.afterPropertiesSet(); this.evaluationContext = ExpressionUtils.createStandardEvaluationContext(getBeanFactory()); }
@Override public <K, V> V remove(K key) { try { return this.<K, V>getRegion().remove(key); } catch (GemFireException cause) { throw convertGemFireAccessException(cause); } }