diff --git a/src/docbkx/tutorial/import.xml b/src/docbkx/tutorial/import.xml index 618756541..e56ba4062 100644 --- a/src/docbkx/tutorial/import.xml +++ b/src/docbkx/tutorial/import.xml @@ -83,7 +83,7 @@ There an @Indexed annotation for fields. We wanted to try this out, and use it to guide the next test. We added an @Indexed to the id field of the movie. This field is intended to represent the external id that will be used in URIs and will stable over database imports and updates. This time we went with the - Finder to retrieve the indexed movie. + default NodeGraphRepository (previously Finder) to retrieve the indexed movie. @@ -18,12 +18,12 @@ class Movie { int year; } -@Autowired FinderFactory graphRepositoryFactory; +@Autowired DirectGraphRepositoryFactory graphRepositoryFactory; @Test [@Transactional] public void persistedMovieShouldBeRetrievableFromGraphDb() { int id=1; Movie forrestGump = new Movie(id, "Forrest Gump", 1994).persist(); - NodeFinder movieFinder = graphRepositoryFactory.createNodeEntityFinder(Movie.class); + NodeGraphRepository movieFinder = graphRepositoryFactory.createNodeEntityRepository(Movie.class); // REMINDER, the "null" stands for an optional index name Movie retrievedMovie = movieFinder.findByPropertyValue(null, "id",id); assertEqual("retrieved movie matches persisted one",forrestGump,retrievedMovie); diff --git a/src/docbkx/tutorial/repository.xml b/src/docbkx/tutorial/repository.xml index c6a0e521c..188c4ac05 100644 --- a/src/docbkx/tutorial/repository.xml +++ b/src/docbkx/tutorial/repository.xml @@ -3,22 +3,26 @@ Serving a good cause - Repository - That was the first method to add to the brand new repository. So we created a repository for the application, annotated - it with @Repository and @Transactional. We did the same for the Actor. + That was the first method to add to the brand new cineasts repository. + First step was to create an (still empty) repository interface for Movie (and Actor). We added the repository configuration + to our application context. + Then we created a repository for the application, annotated it with @Repository and @Transactional and injected the movie repository. + We did the same for the Actor. { + // findById(String id) - automatic derived finder for a future SDG release +} + + + @Repository @Transactional public class CineastsRepostory { - FinderFactory graphRepositoryFactory; - Finder movieFinder; - @Autowired - public CineastsRepostory(FinderFactory graphRepositoryFactory) { - this.graphRepositoryFactory = graphRepositoryFactory; - this.movieFinder = graphRepositoryFactory.createNodeEntityFinder(Movie.class); - } + @Autowired MovieRepository movieRepository; + public Movie getMovie(int id) { - return movieFinder.findByPropertyValue(null,"id", id); + return movieRepository.findByPropertyValue(null,"id", id); } } ]]> diff --git a/src/docbkx/tutorial/running.xml b/src/docbkx/tutorial/running.xml index 73202b3d5..65595340c 100644 --- a/src/docbkx/tutorial/running.xml +++ b/src/docbkx/tutorial/running.xml @@ -15,13 +15,12 @@ public class DatabasePopulator { @Autowired GraphDatabaseContext ctx; - @Autowired MoviesRepository repository; + @Autowired CineastsRepository repository; @Transactional public List populateDatabase() { Actor tomHanks = new Actor("1", "Tom Hanks").persist(); Movie forestGump = new Movie("1", "Forrest Gump").persist(); - forestGump.setYear(1994); tomHanks.playedIn(forestGump,"Forrest"); return asList(forestGump); }} diff --git a/src/docbkx/tutorial/security.xml b/src/docbkx/tutorial/security.xml index b23d4bb1c..410d1745d 100644 --- a/src/docbkx/tutorial/security.xml +++ b/src/docbkx/tutorial/security.xml @@ -90,13 +90,7 @@ in a separate applicationContext-security.xml. But first, as always, Maven and w @Service public class CineastsUserDetailsService implements UserDetailsService, InitializingBean { - @Autowired private FinderFactory graphRepositoryFactory; - private NodeFinder userFinder; - - @Override - public void afterPropertiesSet() throws Exception { - userFinder = graphRepositoryFactory.createNodeEntityFinder(User.class); - } + @Autowired private UserRepository userRepository; @Override public UserDetails loadUserByUsername(String login) throws UsernameNotFoundException, DataAccessException { @@ -106,7 +100,7 @@ public class CineastsUserDetailsService implements UserDetailsService, Initializ } public User findUser(String login) { - return userFinder.findByPropertyValue("users","login",login); + return userRepository.findByPropertyValue(null,"login",login); } public User getUserFromSession() { SecurityContext context = SecurityContextHolder.getContext(); diff --git a/src/docbkx/tutorial/webapp.xml b/src/docbkx/tutorial/webapp.xml index eceaad753..4c5405c07 100644 --- a/src/docbkx/tutorial/webapp.xml +++ b/src/docbkx/tutorial/webapp.xml @@ -9,7 +9,7 @@ and cast in a jsp was straightforward. Actually just using the repository to loo searchForMovie(String query, int count) { +public void List findMovies(String query, int count) { List movies=new ArrayList(count); - for (Movie movie : movieFinder.findAllByQuery("title", query)) { + for (Movie movie : movieRepository.findAllByQuery("title", query)) { movies.add(movie); if (count-- == 0) break; } @@ -62,7 +62,7 @@ domain classes. movies = moviesRepository.findMovies(query, 20); + List movies = repository.findMovies(query, 20); model.addAttribute("movies", movies); model.addAttribute("query", query); return "/movies/list";