Skip to content

Commit dd44c0b

Browse files
author
mpv1989
committed
Upgrade to spring data 2.0
1 parent 74c8e8b commit dd44c0b

File tree

6 files changed

+469
-465
lines changed

6 files changed

+469
-465
lines changed

pom.xml

Lines changed: 36 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,36 @@
1-
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
2-
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
3-
<modelVersion>4.0.0</modelVersion>
4-
5-
<groupId>com.arangodb</groupId>
6-
<artifactId>spring-data-demo</artifactId>
7-
<version>0.0.1-SNAPSHOT</version>
8-
<packaging>jar</packaging>
9-
10-
<name>spring-data-demo</name>
11-
<url>https://github.com/arangodb/spring-data-demo</url>
12-
13-
<parent>
14-
<groupId>org.springframework.boot</groupId>
15-
<artifactId>spring-boot-starter-parent</artifactId>
16-
<version>1.5.6.RELEASE</version>
17-
</parent>
18-
19-
<properties>
20-
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
21-
<java.version>1.8</java.version>
22-
</properties>
23-
24-
<dependencies>
25-
<dependency>
26-
<groupId>org.springframework.boot</groupId>
27-
<artifactId>spring-boot-starter</artifactId>
28-
</dependency>
29-
<dependency>
30-
<groupId>com.arangodb</groupId>
31-
<artifactId>arangodb-spring-data</artifactId>
32-
<version>1.0.0</version>
33-
</dependency>
34-
</dependencies>
35-
36-
</project>
1+
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
2+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
3+
<modelVersion>4.0.0</modelVersion>
4+
5+
<groupId>com.arangodb</groupId>
6+
<artifactId>spring-data-demo</artifactId>
7+
<version>0.0.1-SNAPSHOT</version>
8+
<packaging>jar</packaging>
9+
10+
<name>spring-data-demo</name>
11+
<url>https://github.com/arangodb/spring-data-demo</url>
12+
13+
<parent>
14+
<groupId>org.springframework.boot</groupId>
15+
<artifactId>spring-boot-starter-parent</artifactId>
16+
<version>2.0.1.RELEASE</version>
17+
</parent>
18+
19+
<properties>
20+
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
21+
<java.version>1.8</java.version>
22+
</properties>
23+
24+
<dependencies>
25+
<dependency>
26+
<groupId>org.springframework.boot</groupId>
27+
<artifactId>spring-boot-starter</artifactId>
28+
</dependency>
29+
<dependency>
30+
<groupId>com.arangodb</groupId>
31+
<artifactId>arangodb-spring-data</artifactId>
32+
<version>2.1.3</version>
33+
</dependency>
34+
</dependencies>
35+
36+
</project>
Lines changed: 45 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -1,46 +1,46 @@
1-
/*
2-
* DISCLAIMER
3-
*
4-
* Copyright 2017 ArangoDB GmbH, Cologne, Germany
5-
*
6-
* Licensed under the Apache License, Version 2.0 (the "License");
7-
* you may not use this file except in compliance with the License.
8-
* You may obtain a copy of the License at
9-
*
10-
* http://www.apache.org/licenses/LICENSE-2.0
11-
*
12-
* Unless required by applicable law or agreed to in writing, software
13-
* distributed under the License is distributed on an "AS IS" BASIS,
14-
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15-
* See the License for the specific language governing permissions and
16-
* limitations under the License.
17-
*
18-
* Copyright holder is ArangoDB GmbH, Cologne, Germany
19-
*/
20-
21-
package com.arangodb.spring.demo;
22-
23-
import org.springframework.boot.SpringApplication;
24-
import org.springframework.boot.autoconfigure.SpringBootApplication;
25-
26-
import com.arangodb.spring.demo.runner.AQLRunner;
27-
import com.arangodb.spring.demo.runner.ByExampleRunner;
28-
import com.arangodb.spring.demo.runner.CrudRunner;
29-
import com.arangodb.spring.demo.runner.DerivedQueryRunner;
30-
import com.arangodb.spring.demo.runner.GeospatialRunner;
31-
import com.arangodb.spring.demo.runner.RelationsRunner;
32-
33-
/**
34-
* @author Mark Vollmary
35-
*
36-
*/
37-
@SpringBootApplication
38-
public class DemoApplication {
39-
40-
public static void main(final String... args) {
41-
final Object[] runner = new Object[] { CrudRunner.class, ByExampleRunner.class, DerivedQueryRunner.class,
42-
RelationsRunner.class, AQLRunner.class, GeospatialRunner.class };
43-
System.exit(SpringApplication.exit(SpringApplication.run(runner, args)));
44-
}
45-
1+
/*
2+
* DISCLAIMER
3+
*
4+
* Copyright 2017 ArangoDB GmbH, Cologne, Germany
5+
*
6+
* Licensed under the Apache License, Version 2.0 (the "License");
7+
* you may not use this file except in compliance with the License.
8+
* You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing, software
13+
* distributed under the License is distributed on an "AS IS" BASIS,
14+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
* See the License for the specific language governing permissions and
16+
* limitations under the License.
17+
*
18+
* Copyright holder is ArangoDB GmbH, Cologne, Germany
19+
*/
20+
21+
package com.arangodb.spring.demo;
22+
23+
import org.springframework.boot.SpringApplication;
24+
import org.springframework.boot.autoconfigure.SpringBootApplication;
25+
26+
import com.arangodb.spring.demo.runner.AQLRunner;
27+
import com.arangodb.spring.demo.runner.ByExampleRunner;
28+
import com.arangodb.spring.demo.runner.CrudRunner;
29+
import com.arangodb.spring.demo.runner.DerivedQueryRunner;
30+
import com.arangodb.spring.demo.runner.GeospatialRunner;
31+
import com.arangodb.spring.demo.runner.RelationsRunner;
32+
33+
/**
34+
* @author Mark Vollmary
35+
*
36+
*/
37+
@SpringBootApplication
38+
public class DemoApplication {
39+
40+
public static void main(final String... args) {
41+
final Class<?>[] runner = new Class<?>[] { CrudRunner.class, ByExampleRunner.class, DerivedQueryRunner.class,
42+
RelationsRunner.class, AQLRunner.class, GeospatialRunner.class };
43+
System.exit(SpringApplication.exit(SpringApplication.run(runner, args)));
44+
}
45+
4646
}
Lines changed: 78 additions & 75 deletions
Original file line numberDiff line numberDiff line change
@@ -1,75 +1,78 @@
1-
/*
2-
* DISCLAIMER
3-
*
4-
* Copyright 2017 ArangoDB GmbH, Cologne, Germany
5-
*
6-
* Licensed under the Apache License, Version 2.0 (the "License");
7-
* you may not use this file except in compliance with the License.
8-
* You may obtain a copy of the License at
9-
*
10-
* http://www.apache.org/licenses/LICENSE-2.0
11-
*
12-
* Unless required by applicable law or agreed to in writing, software
13-
* distributed under the License is distributed on an "AS IS" BASIS,
14-
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15-
* See the License for the specific language governing permissions and
16-
* limitations under the License.
17-
*
18-
* Copyright holder is ArangoDB GmbH, Cologne, Germany
19-
*/
20-
21-
package com.arangodb.spring.demo.runner;
22-
23-
import org.springframework.beans.factory.annotation.Autowired;
24-
import org.springframework.boot.CommandLineRunner;
25-
import org.springframework.context.annotation.ComponentScan;
26-
import org.springframework.data.domain.Example;
27-
import org.springframework.data.domain.ExampleMatcher;
28-
29-
import com.arangodb.spring.demo.entity.Character;
30-
import com.arangodb.spring.demo.repository.CharacterRepository;
31-
32-
/**
33-
* @author Mark Vollmary
34-
*
35-
*/
36-
@ComponentScan("com.arangodb.spring.demo")
37-
public class ByExampleRunner implements CommandLineRunner {
38-
39-
@Autowired
40-
private CharacterRepository repository;
41-
42-
@Override
43-
public void run(final String... args) throws Exception {
44-
System.out.println("# Query by example");
45-
46-
final Character nedStark = new Character("Ned", "Stark", false, 41);
47-
48-
System.out.println(String.format("## Find character which match %s", nedStark));
49-
final Character foundNedStark = repository.findOne(Example.of(nedStark));
50-
System.out.println(String.format("Found %s", foundNedStark));
51-
52-
System.out.println("## Find all dead Starks");
53-
// because we only care of surname and alive in our entity we have to ignore the other
54-
// fields in our ExampleMatcher
55-
final Iterable<Character> allDeadStarks = repository
56-
.findAll(Example.of(new Character(null, "Stark", false), ExampleMatcher.matchingAll()
57-
.withMatcher("surname", match -> match.exact()).withIgnorePaths("name", "age")));
58-
allDeadStarks.forEach(System.out::println);
59-
60-
System.out.println("## Find all Starks which are 30 years younger than Ned Stark");
61-
// instead of changing the age for the Ned Stark entity use a transformer within the ExampleMatcher.
62-
// Because we are using the entity fetched from the db we have to ignore the field 'id' which isn't null.
63-
final Iterable<Character> allYoungerStarks = repository.findAll(
64-
Example.of(foundNedStark, ExampleMatcher.matchingAll().withMatcher("surname", match -> match.exact())
65-
.withIgnorePaths("id", "name", "alive").withTransformer("age", age -> ((int) age) - 30)));
66-
allYoungerStarks.forEach(System.out::println);
67-
68-
System.out.println("## Find all character which surname ends with 'ark' (ignore case)");
69-
final Iterable<Character> ark = repository.findAll(Example.of(new Character(null, "ark", false),
70-
ExampleMatcher.matchingAll().withMatcher("surname", match -> match.endsWith()).withIgnoreCase()
71-
.withIgnorePaths("name", "alive", "age")));
72-
ark.forEach(System.out::println);
73-
}
74-
75-
}
1+
/*
2+
* DISCLAIMER
3+
*
4+
* Copyright 2017 ArangoDB GmbH, Cologne, Germany
5+
*
6+
* Licensed under the Apache License, Version 2.0 (the "License");
7+
* you may not use this file except in compliance with the License.
8+
* You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing, software
13+
* distributed under the License is distributed on an "AS IS" BASIS,
14+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
* See the License for the specific language governing permissions and
16+
* limitations under the License.
17+
*
18+
* Copyright holder is ArangoDB GmbH, Cologne, Germany
19+
*/
20+
21+
package com.arangodb.spring.demo.runner;
22+
23+
import java.util.Optional;
24+
25+
import org.springframework.beans.factory.annotation.Autowired;
26+
import org.springframework.boot.CommandLineRunner;
27+
import org.springframework.context.annotation.ComponentScan;
28+
import org.springframework.data.domain.Example;
29+
import org.springframework.data.domain.ExampleMatcher;
30+
31+
import com.arangodb.spring.demo.entity.Character;
32+
import com.arangodb.spring.demo.repository.CharacterRepository;
33+
34+
/**
35+
* @author Mark Vollmary
36+
*
37+
*/
38+
@ComponentScan("com.arangodb.spring.demo")
39+
public class ByExampleRunner implements CommandLineRunner {
40+
41+
@Autowired
42+
private CharacterRepository repository;
43+
44+
@Override
45+
public void run(final String... args) throws Exception {
46+
System.out.println("# Query by example");
47+
48+
final Character nedStark = new Character("Ned", "Stark", false, 41);
49+
50+
System.out.println(String.format("## Find character which match %s", nedStark));
51+
final Character foundNedStark = repository.findOne(Example.of(nedStark)).get();
52+
System.out.println(String.format("Found %s", foundNedStark));
53+
54+
System.out.println("## Find all dead Starks");
55+
// because we only care of surname and alive in our entity we have to ignore the other
56+
// fields in our ExampleMatcher
57+
final Iterable<Character> allDeadStarks = repository
58+
.findAll(Example.of(new Character(null, "Stark", false), ExampleMatcher.matchingAll()
59+
.withMatcher("surname", match -> match.exact()).withIgnorePaths("name", "age")));
60+
allDeadStarks.forEach(System.out::println);
61+
62+
System.out.println("## Find all Starks which are 30 years younger than Ned Stark");
63+
// instead of changing the age for the Ned Stark entity use a transformer within the ExampleMatcher.
64+
// Because we are using the entity fetched from the db we have to ignore the field 'id' which isn't null.
65+
final Iterable<Character> allYoungerStarks = repository.findAll(Example.of(foundNedStark,
66+
ExampleMatcher.matchingAll().withMatcher("surname", match -> match.exact())
67+
.withIgnorePaths("id", "name", "alive")
68+
.withTransformer("age", age -> Optional.of(((int) age.get()) - 30))));
69+
allYoungerStarks.forEach(System.out::println);
70+
71+
System.out.println("## Find all character which surname ends with 'ark' (ignore case)");
72+
final Iterable<Character> ark = repository.findAll(Example.of(new Character(null, "ark", false),
73+
ExampleMatcher.matchingAll().withMatcher("surname", match -> match.endsWith()).withIgnoreCase()
74+
.withIgnorePaths("name", "alive", "age")));
75+
ark.forEach(System.out::println);
76+
}
77+
78+
}

0 commit comments

Comments
 (0)