parent
655bffb8eb
commit
8a95d5d798
@ -1,45 +0,0 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
|
||||||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
|
||||||
<modelVersion>4.0.0</modelVersion>
|
|
||||||
<parent>
|
|
||||||
<!-- Your own application should inherit from spring-boot-starter-parent -->
|
|
||||||
<groupId>org.springframework.boot</groupId>
|
|
||||||
<artifactId>spring-boot-samples</artifactId>
|
|
||||||
<version>2.0.0.BUILD-SNAPSHOT</version>
|
|
||||||
</parent>
|
|
||||||
<artifactId>spring-boot-sample-data-gemfire</artifactId>
|
|
||||||
<name>Spring Boot Data GemFire Sample</name>
|
|
||||||
<description>Spring Boot Data GemFire Sample</description>
|
|
||||||
<url>http://projects.spring.io/spring-boot/</url>
|
|
||||||
<organization>
|
|
||||||
<name>Pivotal Software, Inc.</name>
|
|
||||||
<url>http://www.spring.io</url>
|
|
||||||
</organization>
|
|
||||||
<properties>
|
|
||||||
<main.basedir>${basedir}/../..</main.basedir>
|
|
||||||
</properties>
|
|
||||||
<dependencies>
|
|
||||||
<dependency>
|
|
||||||
<groupId>org.springframework.boot</groupId>
|
|
||||||
<artifactId>spring-boot-starter-data-gemfire</artifactId>
|
|
||||||
</dependency>
|
|
||||||
<dependency>
|
|
||||||
<groupId>org.springframework.boot</groupId>
|
|
||||||
<artifactId>spring-boot-configuration-processor</artifactId>
|
|
||||||
<optional>true</optional>
|
|
||||||
</dependency>
|
|
||||||
<dependency>
|
|
||||||
<groupId>org.springframework.boot</groupId>
|
|
||||||
<artifactId>spring-boot-starter-test</artifactId>
|
|
||||||
<scope>test</scope>
|
|
||||||
</dependency>
|
|
||||||
</dependencies>
|
|
||||||
<build>
|
|
||||||
<plugins>
|
|
||||||
<plugin>
|
|
||||||
<groupId>org.springframework.boot</groupId>
|
|
||||||
<artifactId>spring-boot-maven-plugin</artifactId>
|
|
||||||
</plugin>
|
|
||||||
</plugins>
|
|
||||||
</build>
|
|
||||||
</project>
|
|
@ -1,107 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright 2012-2016 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 sample.data.gemfire;
|
|
||||||
|
|
||||||
import java.util.Properties;
|
|
||||||
|
|
||||||
import com.gemstone.gemfire.cache.Cache;
|
|
||||||
import com.gemstone.gemfire.cache.RegionAttributes;
|
|
||||||
import sample.data.gemfire.config.SampleDataGemFireProperties;
|
|
||||||
import sample.data.gemfire.domain.Gemstone;
|
|
||||||
|
|
||||||
import org.springframework.boot.SpringApplication;
|
|
||||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
|
||||||
import org.springframework.boot.context.properties.EnableConfigurationProperties;
|
|
||||||
import org.springframework.context.annotation.Bean;
|
|
||||||
import org.springframework.data.gemfire.CacheFactoryBean;
|
|
||||||
import org.springframework.data.gemfire.GemfireTransactionManager;
|
|
||||||
import org.springframework.data.gemfire.RegionAttributesFactoryBean;
|
|
||||||
import org.springframework.data.gemfire.ReplicatedRegionFactoryBean;
|
|
||||||
import org.springframework.data.gemfire.repository.config.EnableGemfireRepositories;
|
|
||||||
import org.springframework.transaction.annotation.EnableTransactionManagement;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* The GemstoneAppConfiguration class for allowing Spring Boot to pick up additional
|
|
||||||
* application Spring configuration meta-data for GemFire, which must be specified in
|
|
||||||
* Spring Data GemFire's XML namespace.
|
|
||||||
*
|
|
||||||
* @author John Blum
|
|
||||||
*/
|
|
||||||
@SpringBootApplication
|
|
||||||
@EnableGemfireRepositories
|
|
||||||
@EnableTransactionManagement
|
|
||||||
@EnableConfigurationProperties(SampleDataGemFireProperties.class)
|
|
||||||
public class SampleDataGemFireApplication {
|
|
||||||
|
|
||||||
private static final String GEMSTONES_REGION_NAME = "Gemstones";
|
|
||||||
|
|
||||||
private final SampleDataGemFireProperties properties;
|
|
||||||
|
|
||||||
public SampleDataGemFireApplication(
|
|
||||||
SampleDataGemFireProperties applicationProperties) {
|
|
||||||
this.properties = applicationProperties;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Bean
|
|
||||||
public CacheFactoryBean gemfireCache() {
|
|
||||||
CacheFactoryBean cache = new CacheFactoryBean();
|
|
||||||
cache.setClose(true);
|
|
||||||
cache.setProperties(getCacheProperties());
|
|
||||||
return cache;
|
|
||||||
}
|
|
||||||
|
|
||||||
private Properties getCacheProperties() {
|
|
||||||
Properties properties = new Properties();
|
|
||||||
properties.setProperty("name",
|
|
||||||
SampleDataGemFireApplication.class.getSimpleName());
|
|
||||||
properties.setProperty("mcast-port", "0");
|
|
||||||
properties.setProperty("locators", "");
|
|
||||||
properties.setProperty("log-level", this.properties.getLogLevel());
|
|
||||||
return properties;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Bean(name = GEMSTONES_REGION_NAME)
|
|
||||||
public ReplicatedRegionFactoryBean<Long, Gemstone> gemstonesRegion(Cache cache,
|
|
||||||
RegionAttributes<Long, Gemstone> attributes) {
|
|
||||||
ReplicatedRegionFactoryBean<Long, Gemstone> region = new ReplicatedRegionFactoryBean<Long, Gemstone>();
|
|
||||||
region.setAttributes(attributes);
|
|
||||||
region.setClose(false);
|
|
||||||
region.setCache(cache);
|
|
||||||
region.setName(GEMSTONES_REGION_NAME);
|
|
||||||
region.setPersistent(false);
|
|
||||||
return region;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Bean
|
|
||||||
@SuppressWarnings({ "unchecked", "deprecation" })
|
|
||||||
public RegionAttributesFactoryBean gemstonesRegionAttributes() {
|
|
||||||
RegionAttributesFactoryBean attributes = new RegionAttributesFactoryBean();
|
|
||||||
attributes.setKeyConstraint(Long.class);
|
|
||||||
attributes.setValueConstraint(Gemstone.class);
|
|
||||||
return attributes;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Bean
|
|
||||||
public GemfireTransactionManager gemfireTransactionManager(Cache gemfireCache) {
|
|
||||||
return new GemfireTransactionManager(gemfireCache);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void main(final String[] args) {
|
|
||||||
SpringApplication.run(SampleDataGemFireApplication.class, args);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
@ -1,42 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright 2012-2016 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 sample.data.gemfire.config;
|
|
||||||
|
|
||||||
import org.springframework.boot.context.properties.ConfigurationProperties;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Configuration properties for Gemfire sample.
|
|
||||||
*
|
|
||||||
* @author John Blum
|
|
||||||
*/
|
|
||||||
@ConfigurationProperties(prefix = "sample.data.gemfire")
|
|
||||||
public class SampleDataGemFireProperties {
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Caching log level.
|
|
||||||
*/
|
|
||||||
private String logLevel = "config";
|
|
||||||
|
|
||||||
public String getLogLevel() {
|
|
||||||
return this.logLevel;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setLogLevel(String logLevel) {
|
|
||||||
this.logLevel = logLevel;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
@ -1,92 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright 2012-2016 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 sample.data.gemfire.domain;
|
|
||||||
|
|
||||||
import java.io.Serializable;
|
|
||||||
|
|
||||||
import org.springframework.core.style.ToStringCreator;
|
|
||||||
import org.springframework.data.annotation.Id;
|
|
||||||
import org.springframework.data.gemfire.mapping.Region;
|
|
||||||
import org.springframework.util.ObjectUtils;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* The Gemstone class is an abstract data type modeling a Gemstone, such as a diamond or a
|
|
||||||
* ruby.
|
|
||||||
*
|
|
||||||
* @author John Blum
|
|
||||||
*/
|
|
||||||
@Region("Gemstones")
|
|
||||||
public class Gemstone implements Serializable {
|
|
||||||
|
|
||||||
@Id
|
|
||||||
private Long id;
|
|
||||||
|
|
||||||
private String name;
|
|
||||||
|
|
||||||
public Gemstone() {
|
|
||||||
}
|
|
||||||
|
|
||||||
public Gemstone(Long id) {
|
|
||||||
this.id = id;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Gemstone(Long id, String name) {
|
|
||||||
this.id = id;
|
|
||||||
this.name = name;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Long getId() {
|
|
||||||
return this.id;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setId(Long id) {
|
|
||||||
this.id = id;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getName() {
|
|
||||||
return this.name;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setName(String name) {
|
|
||||||
this.name = name;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean equals(Object obj) {
|
|
||||||
if (obj == this) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
if (obj == null || !obj.getClass().equals(getClass())) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
return ObjectUtils.nullSafeEquals(this.getName(), ((Gemstone) obj).getName());
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public int hashCode() {
|
|
||||||
return ObjectUtils.nullSafeHashCode(getName());
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String toString() {
|
|
||||||
ToStringCreator creator = new ToStringCreator(this);
|
|
||||||
creator.append("id", this.id);
|
|
||||||
creator.append("name", this.name);
|
|
||||||
return creator.toString();
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
@ -1,41 +0,0 @@
|
|||||||
/*
|
|
||||||
* 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 sample.data.gemfire.service;
|
|
||||||
|
|
||||||
import sample.data.gemfire.domain.Gemstone;
|
|
||||||
|
|
||||||
import org.springframework.data.gemfire.repository.GemfireRepository;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* The GemstoneRepository interface is an extension of the GemfireRepository abstraction
|
|
||||||
* for encapsulating data access and persistence operations (CRUD) on Gemstone domain
|
|
||||||
* objects.
|
|
||||||
*
|
|
||||||
* @author John Blum
|
|
||||||
*/
|
|
||||||
public interface GemstoneRepository extends GemfireRepository<Gemstone, Long> {
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Finds a particular Gemstone in the GemFire Cache by name.
|
|
||||||
* @param <T> the Class type of the Gemstone domain object to find.
|
|
||||||
* @param name a String value indicating the name of the Gemstone to find.
|
|
||||||
* @return a Gemstone by name.
|
|
||||||
* @see sample.data.gemfire.domain.Gemstone
|
|
||||||
*/
|
|
||||||
<T extends Gemstone> T findByName(String name);
|
|
||||||
|
|
||||||
}
|
|
@ -1,68 +0,0 @@
|
|||||||
/*
|
|
||||||
* 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 sample.data.gemfire.service;
|
|
||||||
|
|
||||||
import sample.data.gemfire.domain.Gemstone;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* The GemstoneService interface is a Service interface object contract defining business
|
|
||||||
* operations for processing Gemstone domain objects.
|
|
||||||
*
|
|
||||||
* @author John Blum
|
|
||||||
*/
|
|
||||||
public interface GemstoneService {
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns a count of the number of Gemstones in the GemFire Cache.
|
|
||||||
* @return a long value indicating the number of Gemstones in the GemFire Cache.
|
|
||||||
*/
|
|
||||||
long count();
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Gets a Gemstone by ID.
|
|
||||||
* @param id a long value indicating the identifier of the Gemstone.
|
|
||||||
* @return a Gemstone with ID, or null if no Gemstone exists with ID.
|
|
||||||
* @see sample.data.gemfire.domain.Gemstone
|
|
||||||
*/
|
|
||||||
Gemstone get(Long id);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Gets a Gemstone by name.
|
|
||||||
* @param name a String value indicating the name of the Gemstone.
|
|
||||||
* @return a Gemstone with name, or null if no Gemstone exists with name.
|
|
||||||
* @see sample.data.gemfire.domain.Gemstone
|
|
||||||
*/
|
|
||||||
Gemstone get(String name);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Return a listing of Gemstones currently stored in the GemFire Cache.
|
|
||||||
* @return an Iterable object to iterate over the list of Gemstones currently stored
|
|
||||||
* in the GemFire Cache.
|
|
||||||
* @see java.lang.Iterable
|
|
||||||
* @see sample.data.gemfire.domain.Gemstone
|
|
||||||
*/
|
|
||||||
Iterable<Gemstone> list();
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Saves the specified Gemstone to the GemFire Cache.
|
|
||||||
* @param gemstone the Gemstone to save in the GemFire Cache.
|
|
||||||
* @return the saved Gemstone.
|
|
||||||
* @see sample.data.gemfire.domain.Gemstone
|
|
||||||
*/
|
|
||||||
Gemstone save(Gemstone gemstone);
|
|
||||||
|
|
||||||
}
|
|
@ -1,139 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright 2012-2016 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 sample.data.gemfire.service;
|
|
||||||
|
|
||||||
import java.util.Arrays;
|
|
||||||
import java.util.Collections;
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
import javax.annotation.PostConstruct;
|
|
||||||
|
|
||||||
import sample.data.gemfire.domain.Gemstone;
|
|
||||||
|
|
||||||
import org.springframework.stereotype.Service;
|
|
||||||
import org.springframework.transaction.annotation.Transactional;
|
|
||||||
import org.springframework.util.Assert;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* The GemstoneServiceImpl class is a Service object implementing the GemstoneService
|
|
||||||
* interface containing business logic and rules in addition to data services for
|
|
||||||
* processing Gemstones.
|
|
||||||
*
|
|
||||||
* @author John Blum
|
|
||||||
*/
|
|
||||||
@Service("gemstoneService")
|
|
||||||
public class GemstoneServiceImpl implements GemstoneService {
|
|
||||||
|
|
||||||
protected static final List<String> APPROVED_GEMS;
|
|
||||||
|
|
||||||
static {
|
|
||||||
APPROVED_GEMS = Collections.unmodifiableList(
|
|
||||||
Arrays.asList(("ALEXANDRITE,AQUAMARINE,DIAMOND,OPAL,PEARL,"
|
|
||||||
+ "RUBY,SAPPHIRE,SPINEL,TOPAZ").split(",")));
|
|
||||||
}
|
|
||||||
|
|
||||||
private final GemstoneRepository repository;
|
|
||||||
|
|
||||||
public GemstoneServiceImpl(GemstoneRepository gemstoneRepository) {
|
|
||||||
this.repository = gemstoneRepository;
|
|
||||||
}
|
|
||||||
|
|
||||||
@PostConstruct
|
|
||||||
public void init() {
|
|
||||||
System.out.printf("[%1$s] initialized!%n", getClass().getSimpleName());
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns a count of the number of Gemstones in the GemFire Cache.
|
|
||||||
* @return a long value indicating the number of Gemstones in the GemFire Cache.
|
|
||||||
*/
|
|
||||||
@Override
|
|
||||||
@Transactional(readOnly = true)
|
|
||||||
public long count() {
|
|
||||||
return this.repository.count();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Gets a Gemstone by ID.
|
|
||||||
* @param id a long value indicating the identifier of the Gemstone.
|
|
||||||
* @return a Gemstone with ID, or null if no Gemstone exists with ID.
|
|
||||||
* @see sample.data.gemfire.domain.Gemstone
|
|
||||||
*/
|
|
||||||
@Override
|
|
||||||
@Transactional(readOnly = true)
|
|
||||||
public Gemstone get(Long id) {
|
|
||||||
return this.repository.findOne(id);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Gets a Gemstone by name.
|
|
||||||
* @param name a String value indicating the name of the Gemstone.
|
|
||||||
* @return a Gemstone with name, or null if no Gemstone exists with name.
|
|
||||||
* @see sample.data.gemfire.domain.Gemstone
|
|
||||||
*/
|
|
||||||
@Override
|
|
||||||
@Transactional(readOnly = true)
|
|
||||||
public Gemstone get(String name) {
|
|
||||||
return this.repository.findByName(name);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Return a listing of Gemstones currently stored in the GemFire Cache.
|
|
||||||
* @return an Iterable object to iterate over the list of Gemstones currently stored
|
|
||||||
* in the GemFire Cache.
|
|
||||||
* @see java.lang.Iterable
|
|
||||||
* @see sample.data.gemfire.domain.Gemstone
|
|
||||||
*/
|
|
||||||
@Override
|
|
||||||
@Transactional(readOnly = true)
|
|
||||||
public Iterable<Gemstone> list() {
|
|
||||||
return this.repository.findAll();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Saves the specified Gemstone to the GemFire Cache.
|
|
||||||
* @param gemstone the Gemstone to save in the GemFire Cache.
|
|
||||||
* @return the saved Gemstone.
|
|
||||||
* @see sample.data.gemfire.domain.Gemstone
|
|
||||||
*/
|
|
||||||
@Override
|
|
||||||
@Transactional
|
|
||||||
public Gemstone save(Gemstone gemstone) {
|
|
||||||
Assert.notNull(gemstone, "The Gemstone to save must not be null!");
|
|
||||||
Assert.notNull(gemstone.getName(), "The name of the Gemstone must be specified!");
|
|
||||||
// NOTE deliberately (& naively) validate the Gemstone after mutating data access
|
|
||||||
// in GemFire rather than before to demonstrate transactions in GemFire.
|
|
||||||
Gemstone savedGemstone = validate(this.repository.save(gemstone));
|
|
||||||
Assert.state(savedGemstone.equals(get(gemstone.getId())),
|
|
||||||
String.format("Failed to find Gemstone (%1$s) in "
|
|
||||||
+ "GemFire's Cache Region 'Gemstones'!", gemstone));
|
|
||||||
System.out.printf("Saved Gemstone [%1$s]%n", savedGemstone.getName());
|
|
||||||
return gemstone;
|
|
||||||
}
|
|
||||||
|
|
||||||
Gemstone validate(Gemstone gemstone) {
|
|
||||||
if (!APPROVED_GEMS.contains(gemstone.getName().toUpperCase())) {
|
|
||||||
// NOTE if the Gemstone is not valid, throw error...
|
|
||||||
// Should cause transaction to rollback in GemFire!
|
|
||||||
System.err.printf("Illegal Gemstone [%1$s]!%n", gemstone.getName());
|
|
||||||
throw new IllegalGemstoneException(
|
|
||||||
String.format("[%1$s] is not a valid Gemstone!", gemstone.getName()));
|
|
||||||
}
|
|
||||||
return gemstone;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
@ -1,30 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright 2012-2016 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 sample.data.gemfire.service;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Exception thrown from {@link GemstoneService}.
|
|
||||||
*
|
|
||||||
* @author John Blum
|
|
||||||
*/
|
|
||||||
public class IllegalGemstoneException extends IllegalArgumentException {
|
|
||||||
|
|
||||||
public IllegalGemstoneException(String message) {
|
|
||||||
super(message);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
@ -1,97 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright 2012-2016 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 sample.data.gemfire;
|
|
||||||
|
|
||||||
import java.util.concurrent.atomic.AtomicLong;
|
|
||||||
|
|
||||||
import org.junit.Test;
|
|
||||||
import org.junit.runner.RunWith;
|
|
||||||
import sample.data.gemfire.domain.Gemstone;
|
|
||||||
import sample.data.gemfire.service.GemstoneService;
|
|
||||||
import sample.data.gemfire.service.IllegalGemstoneException;
|
|
||||||
|
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
|
||||||
import org.springframework.boot.test.context.SpringBootTest;
|
|
||||||
import org.springframework.test.context.junit4.SpringRunner;
|
|
||||||
|
|
||||||
import static org.assertj.core.api.Assertions.assertThat;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Tests for {@link SampleDataGemFireApplication}.
|
|
||||||
*
|
|
||||||
* @author John Blum
|
|
||||||
*/
|
|
||||||
@RunWith(SpringRunner.class)
|
|
||||||
@SpringBootTest
|
|
||||||
public class SampleDataGemFireApplicationTests {
|
|
||||||
|
|
||||||
@Autowired
|
|
||||||
private GemstoneService service;
|
|
||||||
|
|
||||||
private final AtomicLong idGenerator = new AtomicLong(0L);
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void gemstonesAppServiceEndpoints() {
|
|
||||||
assertThat(this.service.count()).isEqualTo(0);
|
|
||||||
assertThat(this.service.list()).isEmpty();
|
|
||||||
this.service.save(createGemstone("Diamond"));
|
|
||||||
this.service.save(createGemstone("Ruby"));
|
|
||||||
assertThat(this.service.count()).isEqualTo(2);
|
|
||||||
assertThat(this.service.list()).contains(getGemstones("Diamond", "Ruby"));
|
|
||||||
try {
|
|
||||||
this.service.save(createGemstone("Coal"));
|
|
||||||
}
|
|
||||||
catch (IllegalGemstoneException ignore) {
|
|
||||||
// expected
|
|
||||||
}
|
|
||||||
assertThat(this.service.count()).isEqualTo(2);
|
|
||||||
assertThat(this.service.list()).contains(getGemstones("Diamond", "Ruby"));
|
|
||||||
this.service.save(createGemstone("Pearl"));
|
|
||||||
this.service.save(createGemstone("Sapphire"));
|
|
||||||
assertThat(this.service.count()).isEqualTo(4);
|
|
||||||
assertThat(this.service.list())
|
|
||||||
.contains(getGemstones("Diamond", "Ruby", "Pearl", "Sapphire"));
|
|
||||||
try {
|
|
||||||
this.service.save(createGemstone("Quartz"));
|
|
||||||
}
|
|
||||||
catch (IllegalGemstoneException ignore) {
|
|
||||||
// expected
|
|
||||||
}
|
|
||||||
assertThat(this.service.count()).isEqualTo(4);
|
|
||||||
assertThat(this.service.list())
|
|
||||||
.contains(getGemstones("Diamond", "Ruby", "Pearl", "Sapphire"));
|
|
||||||
assertThat(this.service.get("Diamond")).isEqualTo(createGemstone("Diamond"));
|
|
||||||
assertThat(this.service.get("Pearl")).isEqualTo(createGemstone("Pearl"));
|
|
||||||
}
|
|
||||||
|
|
||||||
private Gemstone[] getGemstones(String... names) {
|
|
||||||
Gemstone[] gemstones = new Gemstone[names.length];
|
|
||||||
for (int i = 0; i < names.length; i++) {
|
|
||||||
gemstones[i] = createGemstone(null, names[i]);
|
|
||||||
}
|
|
||||||
return gemstones;
|
|
||||||
}
|
|
||||||
|
|
||||||
private Gemstone createGemstone(String name) {
|
|
||||||
return createGemstone(this.idGenerator.incrementAndGet(), name);
|
|
||||||
}
|
|
||||||
|
|
||||||
private Gemstone createGemstone(Long id, String name) {
|
|
||||||
return new Gemstone(id, name);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
@ -1,71 +0,0 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
|
||||||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
|
||||||
<modelVersion>4.0.0</modelVersion>
|
|
||||||
<parent>
|
|
||||||
<groupId>org.springframework.boot</groupId>
|
|
||||||
<artifactId>spring-boot-starters</artifactId>
|
|
||||||
<version>2.0.0.BUILD-SNAPSHOT</version>
|
|
||||||
</parent>
|
|
||||||
<artifactId>spring-boot-starter-data-gemfire</artifactId>
|
|
||||||
<name>Spring Boot Data GemFire Starter</name>
|
|
||||||
<description>Starter for using GemFire distributed data store and Spring Data
|
|
||||||
GemFire</description>
|
|
||||||
<url>http://projects.spring.io/spring-boot/</url>
|
|
||||||
<organization>
|
|
||||||
<name>Pivotal Software, Inc.</name>
|
|
||||||
<url>http://www.spring.io</url>
|
|
||||||
</organization>
|
|
||||||
<properties>
|
|
||||||
<main.basedir>${basedir}/../..</main.basedir>
|
|
||||||
</properties>
|
|
||||||
<dependencies>
|
|
||||||
<dependency>
|
|
||||||
<groupId>org.springframework.boot</groupId>
|
|
||||||
<artifactId>spring-boot-starter</artifactId>
|
|
||||||
</dependency>
|
|
||||||
<dependency>
|
|
||||||
<groupId>org.springframework.data</groupId>
|
|
||||||
<artifactId>spring-data-gemfire</artifactId>
|
|
||||||
<exclusions>
|
|
||||||
<exclusion>
|
|
||||||
<groupId>commons-logging</groupId>
|
|
||||||
<artifactId>commons-logging</artifactId>
|
|
||||||
</exclusion>
|
|
||||||
</exclusions>
|
|
||||||
</dependency>
|
|
||||||
</dependencies>
|
|
||||||
<repositories>
|
|
||||||
<repository>
|
|
||||||
<id>repo.spring.io</id>
|
|
||||||
<url>http://repo.spring.io/libs-release</url>
|
|
||||||
<releases>
|
|
||||||
<enabled>true</enabled>
|
|
||||||
</releases>
|
|
||||||
<snapshots>
|
|
||||||
<enabled>false</enabled>
|
|
||||||
</snapshots>
|
|
||||||
</repository>
|
|
||||||
</repositories>
|
|
||||||
<build>
|
|
||||||
<plugins>
|
|
||||||
<plugin>
|
|
||||||
<groupId>org.basepom.maven</groupId>
|
|
||||||
<artifactId>duplicate-finder-maven-plugin</artifactId>
|
|
||||||
<executions>
|
|
||||||
<execution>
|
|
||||||
<id>duplicate-dependencies</id>
|
|
||||||
<phase>validate</phase>
|
|
||||||
<goals>
|
|
||||||
<goal>check</goal>
|
|
||||||
</goals>
|
|
||||||
<configuration>
|
|
||||||
<ignoredResourcePatterns>
|
|
||||||
<ignoredResourcePattern>changelog.txt</ignoredResourcePattern>
|
|
||||||
</ignoredResourcePatterns>
|
|
||||||
</configuration>
|
|
||||||
</execution>
|
|
||||||
</executions>
|
|
||||||
</plugin>
|
|
||||||
</plugins>
|
|
||||||
</build>
|
|
||||||
</project>
|
|
@ -1 +0,0 @@
|
|||||||
provides: spring-data-gemfire
|
|
Loading…
Reference in New Issue