Adjusted CDATA to remove leading blank line. Ensured that all <programlisting>s are in <example>s.

This commit is contained in:
David Montag
2011-04-13 22:41:22 -07:00
parent 033c3ca3b4
commit d0d0a4625a
22 changed files with 76 additions and 126 deletions

View File

@@ -125,7 +125,9 @@ public class UserAccount {
All you need to do is to specify an <code>entityManagerFactory</code> in the XML namespace
<code>config</code> element, and Spring Data Graph will configure itself for cross-store use.
</para>
<programlisting language="xml" ><![CDATA[<beans xmlns="http://www.springframework.org/schema/beans"
<example>
<title>Cross-store Spring configuration</title>
<programlisting language="xml"><![CDATA[<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:datagraph="http://www.springframework.org/schema/data/graph"
@@ -150,6 +152,8 @@ public class UserAccount {
</bean>
</beans>
]]></programlisting>
</example>
</section>
</chapter>

View File

@@ -81,8 +81,7 @@
</para>
<example>
<title>Neo4j usage</title>
<programlisting language="java" ><![CDATA[
GraphDatabaseService graphDb = new EmbeddedGraphDatabase( "helloworld" );
<programlisting language="java" ><![CDATA[GraphDatabaseService graphDb = new EmbeddedGraphDatabase( "helloworld" );
Transaction tx = graphDb.beginTx();
try {
Node firstNode = graphDb.createNode();
@@ -110,8 +109,7 @@ try {
</para>
<example>
<title>Traversal usage</title>
<programlisting language="java" ><![CDATA[
TraversalDescription traversalDescription = Traversal.description()
<programlisting language="java" ><![CDATA[TraversalDescription traversalDescription = Traversal.description()
.depthFirst()
.relationships(KNOWS)
.relationships(LIKES, Direction.INCOMING)
@@ -139,9 +137,7 @@ for (Path position : traversalDescription.traverse(myStartNode)) {
</note>
<example>
<title>Index usage</title>
<programlisting language="java"><![CDATA[
IndexManager indexManager = graphDb.index();
<programlisting language="java"><![CDATA[IndexManager indexManager = graphDb.index();
Index<Node> nodeIndex = indexManager.forNodes("a-node-index");
Node node = ...;
Transaction tx = graphDb.beginTx();

View File

@@ -11,8 +11,7 @@
</para>
<example>
<title>Bean validation</title>
<programlisting language="java"><![CDATA[
@NodeEntity
<programlisting language="java"><![CDATA[@NodeEntity
class Person {
@Size(min = 3, max = 20)
String name;

View File

@@ -39,8 +39,7 @@
</para>
<example>
<title>Indexing entities</title>
<programlisting language="java"><![CDATA[
@NodeEntity
<programlisting language="java"><![CDATA[@NodeEntity
class Person {
@Indexed(indexName = "people") String name;
@Indexed int age;
@@ -80,8 +79,7 @@ for (Person middleAgedDeveloper : graphRepository.findAllByRange("age", 20, 40))
<para>
<example>
<title>Fulltext indexing</title>
<programlisting language="java"><![CDATA[
@NodeEntity
<programlisting language="java"><![CDATA[@NodeEntity
class Person {
@Indexed(indexName = "person-name", fulltext=true) String name;
}
@@ -111,8 +109,7 @@ Person mark = graphRepository.findAllByQuery("people-search", "name", "ma*");
</para>
<example>
<title>Manual index usage</title>
<programlisting language="java"><![CDATA[
@Autowired GraphDatabaseContext gdc;
<programlisting language="java"><![CDATA[@Autowired GraphDatabaseContext gdc;
// Default index
Index<Node> personIndex = gdc.getIndex(Person.class);

View File

@@ -24,9 +24,9 @@
reporting or auditing) and only project them to a concrete, more functional target type when the business
logic requires it.
</para>
<programlisting language="java"><![CDATA[
// not related to Person at all
@NodeEntity
<example>
<title>Projection of entities</title>
<programlisting language="java"><![CDATA[@NodeEntity
class Trainee {
String name;
@RelatedTo(elementClass=Training.class);
@@ -40,5 +40,7 @@ for (Person person : graphRepository.findAllByProperyValue("occupation","develop
}
}
]]></programlisting>
</example>
</section>

View File

@@ -24,8 +24,7 @@
<example>
<title>Single relationship field</title>
<programlisting language="java"><![CDATA[
@NodeEntity
<programlisting language="java"><![CDATA[@NodeEntity
public class Movie {
private Actor mostPaidActor;
}
@@ -42,8 +41,7 @@ public class Movie {
</para>
<example>
<title>Node entity with relationships</title>
<programlisting language="java"><![CDATA[
@NodeEntity
<programlisting language="java"><![CDATA[@NodeEntity
public class Actor {
@RelatedTo(type = "mostPaidActor", direction = Direction.INCOMING,
elementClass = Movie.class)
@@ -103,8 +101,7 @@ public class Actor {
</para>
<example>
<title>Relationship entity</title>
<programlisting language="java"><![CDATA[
@NodeEntity
<programlisting language="java"><![CDATA[@NodeEntity
public class Actor {
public Role playedIn(Movie movie, String title) {
return relatedTo(movie, Role.class, "ACTS_IN");
@@ -132,8 +129,7 @@ public class Role {
</para>
<example>
<title>Accessing relationship entities using @RelatedToVia</title>
<programlisting language="java"><![CDATA[
@NodeEntity
<programlisting language="java"><![CDATA[@NodeEntity
public class Actor {
@RelatedToVia(type = "ACTS_IN", elementClass = Role.class)
private Iterable<Role> roles;

View File

@@ -132,28 +132,27 @@
</para>
<example>
<title>Using GraphRepositories</title>
<programlisting language="java"><![CDATA[
GraphRepository<Person> graphRepository = graphRepositoryFactory
.createGraphRepository(Person.class);
<programlisting language="java"><![CDATA[GraphRepository<Person> graphRepository = graphRepositoryFactory
.createGraphRepository(Person.class);
Person michael = graphRepository.save(new Person("Michael", 36));
Person michael = graphRepository.save(new Person("Michael", 36));
Person dave = graphRepository.findOne(123);
Person dave = graphRepository.findOne(123);
Long numberOfPeople = graphRepository.count();
Long numberOfPeople = graphRepository.count();
Person mark = graphRepository.findByPropertyValue("name", "mark");
Person mark = graphRepository.findByPropertyValue("name", "mark");
Iterable<Person> devs = graphRepository.findAllByProperyValue("occupation", "developer");
Iterable<Person> devs = graphRepository.findAllByProperyValue("occupation", "developer");
Iterable<Person> middleAgedPeople = graphRepository.findAllByRange("age", 20, 40);
Iterable<Person> middleAgedPeople = graphRepository.findAllByRange("age", 20, 40);
Iterable<Person> aTeam = graphRepository.findAllByQuery("name", "A*");
Iterable<Person> aTeam = graphRepository.findAllByQuery("name", "A*");
Iterable<Person> davesFriends = graphRepository.findAllByTraversal(dave,
Traversal.description().pruneAfterDepth(1)
.relationships(KNOWS).filter(returnAllButStartNode()));
]]></programlisting>
Iterable<Person> davesFriends = graphRepository.findAllByTraversal(dave,
Traversal.description().pruneAfterDepth(1)
.relationships(KNOWS).filter(returnAllButStartNode()));
]]></programlisting>
</example>
</section>
@@ -167,8 +166,7 @@
</para>
<example>
<title>Composing repositories</title>
<programlisting language="java"><![CDATA[
public interface PersonRepository extends GraphRepository<Person>, PersonRepositoryExtension {}
<programlisting language="java"><![CDATA[public interface PersonRepository extends GraphRepository<Person>, PersonRepositoryExtension {}
// alternatively select some of the required repositories individually
public interface PersonRepository extends CRUDGraphRepository<Node,Person>,

View File

@@ -22,8 +22,7 @@
</note>
<example>
<title>Simple transaction manager configuration</title>
<programlisting language="xml"><![CDATA[
<bean id="transactionManager" class="org.springframework.transaction.jta.JtaTransactionManager">
<programlisting language="xml"><![CDATA[<bean id="transactionManager" class="org.springframework.transaction.jta.JtaTransactionManager">
<property name="transactionManager">
<bean class="org.neo4j.kernel.impl.transaction.SpringTransactionManager">
<constructor-arg ref="graphDatabaseService"/>
@@ -47,8 +46,7 @@
</para>
<example>
<title>Neo4j Spring integration</title>
<programlisting language="xml"><![CDATA[
<context:annotation-config />
<programlisting language="xml"><![CDATA[<context:annotation-config />
<context:spring-configured/>
<bean id="transactionManager" class="org.springframework.transaction.jta.JtaTransactionManager">
@@ -78,8 +76,7 @@
</para>
<example>
<title>ChainedTransactionManager example</title>
<programlisting language="xml"><![CDATA[
<bean id="jpaTransactionManager"
<programlisting language="xml"><![CDATA[<bean id="jpaTransactionManager"
class="org.springframework.orm.jpa.JpaTransactionManager">
<property name="entityManagerFactory" ref="entityManagerFactory"/>
</bean>

View File

@@ -33,8 +33,7 @@
<para>
<example>
<title>First test case</title>
<programlisting language="java" ><![CDATA[
@Autowired GraphDatabaseContext graphDatabaseContext;
<programlisting language="java" ><![CDATA[@Autowired GraphDatabaseContext graphDatabaseContext;
@Test public void persistedMovieShouldBeRetrievableFromGraphDb() {
Movie forrestGump = new Movie("Forrest Gump", 1994).persist();
@@ -56,8 +55,7 @@
Our domain model had now evolved.
<example>
<title>Movie class</title>
<programlisting language="java"><![CDATA[
@NodeEntity
<programlisting language="java"><![CDATA[@NodeEntity
class Movie {
int id;
String title;

View File

@@ -24,8 +24,7 @@
<para>
<example>
<title>Domain model</title>
<programlisting lang="java" language="java" role="java" ><![CDATA[
class Movie {
<programlisting lang="java" language="java" role="java" ><![CDATA[class Movie {
int id;
String title;
int year;

View File

@@ -12,8 +12,7 @@
<para>
<example>
<title>JSON movie response</title>
<programlisting language="javascript" ><![CDATA[
[{"popularity":3,
<programlisting language="javascript" ><![CDATA[[{"popularity":3,
"translated":true, "adult":false, "language":"en",
"original_name":"[Rec]", "name":"[Rec]", "alternative_name":"[REC]",
"movie_type":"movie",
@@ -60,8 +59,7 @@
</example>
<example>
<title>JSON actor response</title>
<programlisting language="javascript" ><![CDATA[
[{"popularity":3,
<programlisting language="javascript" ><![CDATA[[{"popularity":3,
"name":"Glenn Strange", "known_as":[{"name":"George Glenn Strange"}, {"name":"Glen Strange"},
{"name":"Glen 'Peewee' Strange"}, {"name":"Peewee Strange"}, {"name":"'Peewee' Strange"}],
"id":30112,
@@ -96,8 +94,7 @@
<para>
<example>
<title>Importing the data</title>
<programlisting language="java" ><![CDATA[
@Transactional
<programlisting language="java" ><![CDATA[@Transactional
public Movie importMovie(String movieId) {
Movie movie = repository.getMovie(movieId);
if (movie == null) { // Not found: Create fresh

View File

@@ -12,8 +12,7 @@
<para>
<example>
<title>Exact Indexing for Movie id</title>
<programlisting language="java" ><![CDATA[
@NodeEntity class Movie {
<programlisting language="java" ><![CDATA[@NodeEntity class Movie {
@Indexed int id;
String title;
int year;

View File

@@ -29,8 +29,7 @@
<para>
<example>
<title>Neo4j Maven dependency</title>
<programlisting language="xml" ><![CDATA[
<dependency>
<programlisting language="xml" ><![CDATA[<dependency>
<groupId>org.neo4j</groupId>
<artifactId>neo4j</artifactId>
<version>1.3.M05</version>
@@ -41,8 +40,7 @@
<para>
<example>
<title>Neo4j core API (transaction code omitted)</title>
<programlisting language="java" ><![CDATA[
enum RelationshipTypes implements RelationshipType { ACTS_IN };
<programlisting language="java" ><![CDATA[enum RelationshipTypes implements RelationshipType { ACTS_IN };
GraphDatabaseService gds = new EmbeddedGraphDatabase("/path/to/store");
Node forrest=gds.createNode();

View File

@@ -20,8 +20,7 @@
<para>
<example>
<title>Recommendations</title>
<programlisting language="java"><![CDATA[
public Map<Movie,Integer> recommendMovies(User user, final int ratingDistance) {
<programlisting language="java"><![CDATA[public Map<Movie,Integer> recommendMovies(User user, final int ratingDistance) {
final DynamicRelationshipType RATED = withName(User.RATED);
final Map<Long,int[]> ratings=new HashMap<Long, int[]>();
TraversalDescription traversal= Traversal.description().breadthFirst()

View File

@@ -19,8 +19,7 @@
<para>
<example>
<title>Role class</title>
<programlisting language="java"><![CDATA[
@RelationshipEntity
<programlisting language="java"><![CDATA[@RelationshipEntity
class Role {
@StartNode Actor actor;
@EndNode Movie movie;
@@ -40,8 +39,7 @@ class Role {
<para>
<example>
<title>Relating actors to movies</title>
<programlisting language="java" ><![CDATA[
class Actor {
<programlisting language="java" ><![CDATA[class Actor {
...
public Role playedIn(Movie movie, String roleName) {
Role role = relateTo(movie, Role.class, "ACTS_IN");
@@ -65,8 +63,7 @@ class Actor {
<para>
<example>
<title>@RelatedTo usage</title>
<programlisting language="java" ><![CDATA[
@NodeEntity
<programlisting language="java" ><![CDATA[@NodeEntity
class Movie {
@Indexed int id;
String title;
@@ -115,8 +112,7 @@ class Actor {
<para>
<example>
<title>@RelatedToVia usage</title>
<programlisting language="java" ><![CDATA[
@NodeEntity
<programlisting language="java" ><![CDATA[@NodeEntity
class Movie {
@Indexed int id;
String title;

View File

@@ -9,16 +9,14 @@
work with a named interface rather than different versions of a generic one.
<example>
<title>Movie repository</title>
<programlisting language="java"><![CDATA[
package org.neo4j.cineasts.repository;
<programlisting language="java"><![CDATA[package org.neo4j.cineasts.repository;
public interface MovieRepository extends GraphRepository<Movie> {}
]]></programlisting>
</example>
Then we added it to the Spring context configuration by simply adding:
<example>
<title>Repository context configuration</title>
<programlisting language="xml"><![CDATA[
<datagraph:repositories base-package="org.neo4j.cineasts.repository"/>
<programlisting language="xml"><![CDATA[<datagraph:repositories base-package="org.neo4j.cineasts.repository"/>
]]></programlisting>
</example>
We then created the domain-specific repository class, annotating it with <code>@Repository</code> and
@@ -27,8 +25,7 @@ public interface MovieRepository extends GraphRepository<Movie> {}
<para>
<example>
<title>Domain-specific repository</title>
<programlisting language="java"><![CDATA[
@Repository @Transactional
<programlisting language="java"><![CDATA[@Repository @Transactional
public class CineastsRepostory {
@Autowired MovieRepository movieRepository;

View File

@@ -17,8 +17,7 @@
<para>
<example>
<title>Populating the database - Controller</title>
<programlisting language="java"><![CDATA[
@Service
<programlisting language="java"><![CDATA[@Service
public class DatabasePopulator {
@Autowired GraphDatabaseContext ctx;
@@ -54,8 +53,7 @@ public class MovieController {
</example>
<example>
<title>Populating the database - JSP</title>
<programlisting language="jsp"><![CDATA[
<%@ page session="false" %>
<programlisting language="jsp"><![CDATA[<%@ page session="false" %>
<%@ taglib uri="http://www.springframework.org/tags" prefix="s" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
@@ -119,8 +117,7 @@ public class MovieController {
<para>
<example>
<title>Starting the Neo4j Shell</title>
<programlisting language="shell" ><![CDATA[
neo4j-shell -readonly -path data/graph.db
<programlisting language="shell" ><![CDATA[neo4j-shell -readonly -path data/graph.db
]]></programlisting>
</example>
</para>
@@ -132,8 +129,7 @@ neo4j-shell -readonly -path data/graph.db
<para>
<example>
<title>Neo4j Shell usage</title>
<programlisting language="shell" ><![CDATA[
neo4j-sh[readonly] (0)$ help
<programlisting language="shell" ><![CDATA[neo4j-sh[readonly] (0)$ help
Available commands: index dbinfo ls rm alias set eval mv gsh env rmrel mkrel
trav help pwd paths ... man cd
Use man <command> for info about each command.

View File

@@ -15,8 +15,7 @@
<para>
<example>
<title>Spring Security pom.xml</title>
<programlisting language="xml" ><![CDATA[
<dependency>
<programlisting language="xml" ><![CDATA[<dependency>
<groupId>org.springframework.security</groupId>
<artifactId>spring-security-web</artifactId>
<version>${spring.version}</version>
@@ -32,8 +31,7 @@
<para>
<example>
<title>Spring Security web.xml</title>
<programlisting language="xml" ><![CDATA[
<context-param>
<programlisting language="xml" ><![CDATA[<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>
/WEB-INF/applicationContext-security.xml
@@ -60,8 +58,7 @@
<para>
<example>
<title>Spring Security applicationContext-security.xml</title>
<programlisting language="xml" ><![CDATA[
<security:global-method-security secured-annotations="enabled">
<programlisting language="xml" ><![CDATA[<security:global-method-security secured-annotations="enabled">
</security:global-method-security>
<security:http auto-config="true" access-denied-page="/auth/denied"> <!-- use-expressions="true" -->
@@ -89,8 +86,7 @@
</example>
<example>
<title>UserDetailsService and UserDetails implementation</title>
<programlisting language="java" ><![CDATA[
@Service
<programlisting language="java" ><![CDATA[@Service
public class CineastsUserDetailsService implements UserDetailsService, InitializingBean {
@Autowired private UserRepository userRepository;

View File

@@ -32,8 +32,7 @@
<para>
<example>
<title>Project pom.xml</title>
<programlisting language="xml"><![CDATA[
<properties>
<programlisting language="xml"><![CDATA[<properties>
<spring.version>3.0.5.RELEASE</spring.version>
</properties>
@@ -69,8 +68,7 @@
<example>
<title>Project web.xml</title>
<programlisting language="xml"><![CDATA[
<listener>
<programlisting language="xml"><![CDATA[<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
@@ -99,8 +97,7 @@
<para>
<example>
<title>Project applicationContext.xml</title>
<programlisting language="xml"><![CDATA[
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<programlisting language="xml"><![CDATA[<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:tx="http://www.springframework.org/schema/tx"
@@ -124,8 +121,7 @@
</example>
<example>
<title>Project dispatcherServlet-servlet.xml</title>
<programlisting language="xml"><![CDATA[
<mvc:annotation-driven/>
<programlisting language="xml"><![CDATA[<mvc:annotation-driven/>
<mvc:resources mapping="/images/**" location="/images/"/>
<mvc:resources mapping="/resources/**" location="/resources/"/>
<context:component-scan base-package="org.neo4j.cineasts.controller"/>

View File

@@ -18,8 +18,7 @@
<para>
<example>
<title>Social entities</title>
<programlisting language="java" ><![CDATA[
@NodeEntity
<programlisting language="java" ><![CDATA[@NodeEntity
class User {
@Indexed String login;
String name;
@@ -59,8 +58,7 @@ class Rating {
<para>
<example>
<title>Populate users and ratings</title>
<programlisting language="java" ><![CDATA[
@Transactional
<programlisting language="java" ><![CDATA[@Transactional
public List<Movie> populateDatabase() {
Actor tomHanks = new Actor("1", "Tom Hanks").persist();
Movie forestGump = new Movie("1", "Forrest Gump").persist();
@@ -88,8 +86,7 @@ public List<Movie> populateDatabase() {
<para>
<example>
<title>Getting the rating of a movie</title>
<programlisting language="java" ><![CDATA[
class Movie {
<programlisting language="java" ><![CDATA[class Movie {
...
@RelatedToVia(elementClass=Rating.class, type="RATED", direction = Direction.INCOMING)

View File

@@ -18,9 +18,7 @@
The first step was to configure Maven:
<example>
<title>Spring Data Graph Maven configuration</title>
<programlisting language="xml"><![CDATA[
<properties>
<programlisting language="xml"><![CDATA[<properties>
<aspectj.version>1.6.11.RELEASE</aspectj.version>
</properties>
@@ -85,8 +83,7 @@
<para>
<example>
<title>Spring Data Graph context configuration</title>
<programlisting language="xml"><![CDATA[
<beans xmlns="http://www.springframework.org/schema/beans" ...
<programlisting language="xml"><![CDATA[<beans xmlns="http://www.springframework.org/schema/beans" ...
xmlns:datagraph="http://www.springframework.org/schema/data/graph"
xsi:schemaLocation="... http://www.springframework.org/schema/data/graph
http://www.springframework.org/schema/data/graph/datagraph-1.0.xsd">

View File

@@ -12,8 +12,7 @@
<para>
<example>
<title>Controller for showing movies</title>
<programlisting language="java"><![CDATA[
@RequestMapping(value = "/movies/{movieId}", method = RequestMethod.GET, headers = "Accept=text/html")
<programlisting language="java"><![CDATA[@RequestMapping(value = "/movies/{movieId}", method = RequestMethod.GET, headers = "Accept=text/html")
public String singleMovieView(final Model model, @PathVariable String movieId) {
Movie movie = repository.getMovie(movieId);
model.addAttribute("id", movieId);
@@ -51,8 +50,7 @@ public String singleMovieView(final Model model, @PathVariable String movieId) {
<para>
<example>
<title>Searching for movies</title>
<programlisting language="java"><![CDATA[
public class CineastRepository {
<programlisting language="java"><![CDATA[public class CineastRepository {
....
public void List<Movie> findMovies(String query, int count) {
List<Movie> movies=new ArrayList<Movie>(count);
@@ -79,8 +77,7 @@ public class CineastRepository {
<para>
<example>
<title>Search controller</title>
<programlisting language="java"><![CDATA[
@RequestMapping(value = "/movies", method = RequestMethod.GET, headers = "Accept=text/html")
<programlisting language="java"><![CDATA[@RequestMapping(value = "/movies", method = RequestMethod.GET, headers = "Accept=text/html")
public String findMovies(Model model, @RequestParam("q") String query) {
List<Movie> movies = repository.findMovies(query, 20);
model.addAttribute("movies", movies);
@@ -93,8 +90,7 @@ public String findMovies(Model model, @RequestParam("q") String query) {
<para>
<example>
<title>Search Results JSP</title>
<programlisting language="jsp" ><![CDATA[
<h2>Movies</h2>
<programlisting language="jsp" ><![CDATA[<h2>Movies</h2>
<c:choose>
<c:when test="${not empty movies}">