#265 - Add example for Spring Data Couchbase.
Original pull request: #275.
This commit is contained in:
committed by
Mark Paluch
parent
4b648b1d50
commit
5ba65308a7
@@ -0,0 +1,35 @@
|
||||
package example.springdata.couchbase;
|
||||
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.data.couchbase.config.AbstractCouchbaseConfiguration;
|
||||
import org.springframework.data.couchbase.repository.config.EnableCouchbaseRepositories;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Couchbase Configuration to connect to Couchbase data store
|
||||
*
|
||||
* @author Chandana Kithalagama
|
||||
*/
|
||||
@SpringBootApplication
|
||||
@Configuration
|
||||
@EnableCouchbaseRepositories
|
||||
public class CouchbaseConfiguration extends AbstractCouchbaseConfiguration {
|
||||
|
||||
@Override
|
||||
protected List<String> getBootstrapHosts() {
|
||||
return Collections.singletonList("192.168.99.100");
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String getBucketName() {
|
||||
return "travel-sample";
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String getBucketPassword() {
|
||||
return "";
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,40 @@
|
||||
package example.springdata.couchbase.model;
|
||||
|
||||
import com.couchbase.client.java.repository.annotation.Field;
|
||||
import com.couchbase.client.java.repository.annotation.Id;
|
||||
import lombok.*;
|
||||
import org.springframework.data.couchbase.core.mapping.Document;
|
||||
|
||||
/**
|
||||
* A domain object representing an Airline
|
||||
*
|
||||
* @author Chandana Kithalagama
|
||||
*/
|
||||
@Data
|
||||
@AllArgsConstructor
|
||||
@NoArgsConstructor
|
||||
@Document
|
||||
public class Airline {
|
||||
|
||||
@Id
|
||||
private int id;
|
||||
|
||||
@Field
|
||||
private String type;
|
||||
|
||||
@Field
|
||||
private String name;
|
||||
|
||||
@Field("iata")
|
||||
private String iataCode;
|
||||
|
||||
@Field
|
||||
private String icao;
|
||||
|
||||
@Field
|
||||
private String callsign;
|
||||
|
||||
@Field
|
||||
private String country;
|
||||
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
package example.springdata.couchbase.repository;
|
||||
|
||||
import example.springdata.couchbase.model.Airline;
|
||||
import org.springframework.data.couchbase.core.query.Query;
|
||||
import org.springframework.data.repository.CrudRepository;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Repository interface to manage {@link Airline} instances.
|
||||
*
|
||||
* @author Chandana Kithalagama
|
||||
*/
|
||||
public interface AirlineRepository extends CrudRepository<Airline, Integer>{
|
||||
|
||||
@Query("#{#n1ql.selectEntity} WHERE #{#n1ql.filter} AND name = $1")
|
||||
List<Airline> findAirlineByName(String name);
|
||||
}
|
||||
Reference in New Issue
Block a user