43
43
@ ComponentScan ("com.arangodb.spring.demo" )
44
44
public class CrudRunner implements CommandLineRunner {
45
45
46
+ static final Collection <Character > characters = createCharacters ();
47
+
46
48
@ Autowired
47
49
private ArangoOperations operations ;
48
50
@ Autowired
@@ -57,7 +59,9 @@ public void run(final String... args) throws Exception {
57
59
58
60
// save a single entity in the database
59
61
// there is no need of creating the collection first. This happen automatically
60
- final Character nedStark = new Character ("Ned" , "Stark" , true , 41 );
62
+ final Character nedStark = characters .stream ()
63
+ .filter (it -> "Ned" .equals (it .getName ()) && "Stark" .equals (it .getSurname ()))
64
+ .findFirst ().orElseThrow ();
61
65
repository .save (nedStark );
62
66
// the generated id from the database is set in the original entity
63
67
System .out .println (String .format ("Ned Stark saved in the database with id: '%s'" , nedStark .getId ()));
@@ -74,9 +78,8 @@ public void run(final String... args) throws Exception {
74
78
System .out .println (String .format ("Ned Stark after 'alive' flag was updated: %s" , deadNed ));
75
79
76
80
// lets save some additional characters
77
- final Collection <Character > createCharacters = createCharacters ();
78
- System .out .println (String .format ("Save %s additional characters" , createCharacters .size ()));
79
- repository .saveAll (createCharacters );
81
+ System .out .println (String .format ("Save %s additional characters" , characters .size ()));
82
+ repository .saveAll (characters );
80
83
81
84
final Iterable <Character > all = repository .findAll ();
82
85
final long count = StreamSupport .stream (Spliterators .spliteratorUnknownSize (all .iterator (), 0 ), false ).count ();
@@ -93,7 +96,7 @@ public void run(final String... args) throws Exception {
93
96
}
94
97
95
98
public static Collection <Character > createCharacters () {
96
- return Arrays .asList (new Character ("Ned" , "Stark" , false , 41 ), new Character ("Robert" , "Baratheon" , false ),
99
+ return Arrays .asList (new Character ("Ned" , "Stark" , true , 41 ), new Character ("Robert" , "Baratheon" , false ),
97
100
new Character ("Jaime" , "Lannister" , true , 36 ), new Character ("Catelyn" , "Stark" , false , 40 ),
98
101
new Character ("Cersei" , "Lannister" , true , 36 ), new Character ("Daenerys" , "Targaryen" , true , 16 ),
99
102
new Character ("Jorah" , "Mormont" , false ), new Character ("Petyr" , "Baelish" , false ),
0 commit comments