Polish Spring Data Solr integration

This commit is contained in:
Andy Wilkinson
2014-05-22 08:45:41 +01:00
parent 6ed69709d7
commit e45ef06b56
13 changed files with 72 additions and 91 deletions

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2014 the original author or authors.
* Copyright 2012-2014 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.
@@ -23,9 +23,6 @@ import org.springframework.data.annotation.Id;
import org.springframework.data.solr.core.geo.Point;
import org.springframework.data.solr.core.mapping.SolrDocument;
/**
* @author Christoph Strobl
*/
@SolrDocument(solrCoreName = "collection1")
public class Product {
@@ -55,7 +52,7 @@ public class Product {
}
public String getId() {
return id;
return this.id;
}
public void setId(String id) {
@@ -63,7 +60,7 @@ public class Product {
}
public String getName() {
return name;
return this.name;
}
public void setName(String name) {
@@ -71,7 +68,7 @@ public class Product {
}
public Double getPrice() {
return price;
return this.price;
}
public void setPrice(Double price) {
@@ -79,7 +76,7 @@ public class Product {
}
public List<String> getCategory() {
return category;
return this.category;
}
public void setCategory(List<String> category) {
@@ -87,7 +84,7 @@ public class Product {
}
public Point getLocation() {
return location;
return this.location;
}
public void setLocation(Point location) {
@@ -96,8 +93,8 @@ public class Product {
@Override
public String toString() {
return "Product [id=" + id + ", name=" + name + ", price=" + price
+ ", category=" + category + ", location=" + location + "]";
return "Product [id=" + this.id + ", name=" + this.name + ", price=" + this.price
+ ", category=" + this.category + ", location=" + this.location + "]";
}
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2014 the original author or authors.
* Copyright 2012-2014 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.
@@ -20,9 +20,6 @@ import java.util.List;
import org.springframework.data.solr.repository.SolrCrudRepository;
/**
* @author Christoph Strobl
*/
public interface ProductRepository extends SolrCrudRepository<Product, String> {
List<Product> findByNameStartingWith(String name);

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2014 the original author or authors.
* Copyright 2012-2014 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.
@@ -23,9 +23,6 @@ import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
/**
* @author Christoph Strobl
*/
@Configuration
@EnableAutoConfiguration
@ComponentScan
@@ -37,17 +34,17 @@ public class SampleSolrApplication implements CommandLineRunner {
@Override
public void run(String... args) throws Exception {
repository.deleteAll();
this.repository.deleteAll();
// insert some products
repository.save(new Product("1", "Nintendo Entertainment System"));
repository.save(new Product("2", "Sega Megadrive"));
repository.save(new Product("3", "Sony Playstation"));
this.repository.save(new Product("1", "Nintendo Entertainment System"));
this.repository.save(new Product("2", "Sega Megadrive"));
this.repository.save(new Product("3", "Sony Playstation"));
// fetch all
System.out.println("Products found by findAll():");
System.out.println("----------------------------");
for (Product product : repository.findAll()) {
for (Product product : this.repository.findAll()) {
System.out.println(product);
}
System.out.println();
@@ -55,7 +52,7 @@ public class SampleSolrApplication implements CommandLineRunner {
// fetch a single product
System.out.println("Products founds with findByNameStartingWith('So'):");
System.out.println("--------------------------------");
for (Product product : repository.findByNameStartingWith("So")) {
for (Product product : this.repository.findByNameStartingWith("So")) {
System.out.println(product);
}
System.out.println();