Skip to content

Commit 9a3572b

Browse files
committed
fixed the israeli-palestinian conflict (C) whatthecommit.com
1 parent 3b335c5 commit 9a3572b

File tree

7 files changed

+97
-3
lines changed

7 files changed

+97
-3
lines changed

.travis.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ jobs:
3636
jdk: openjdk11
3737
name: many-to-many
3838
before_script:
39-
- cd $TRAVIS_BUILD_DIR && ./mvnw -f refs
39+
- cd $TRAVIS_BUILD_DIR/many-to-many && ./mvnw
4040
- java -jar $TRAVIS_BUILD_DIR/many-to-many/target/*.jar &
4141
- wait_for 8080
4242
script:

refs/pom.xml

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,10 +32,20 @@
3232
<scope>runtime</scope>
3333
<optional>true</optional>
3434
</dependency>
35-
<dependency>
35+
<!--<dependency>
3636
<groupId>org.hsqldb</groupId>
3737
<artifactId>hsqldb</artifactId>
3838
<scope>runtime</scope>
39+
</dependency>-->
40+
<dependency>
41+
<groupId>com.h2database</groupId>
42+
<artifactId>h2</artifactId>
43+
<scope>runtime</scope>
44+
</dependency>
45+
<!-- console -->
46+
<dependency>
47+
<groupId>org.springframework.boot</groupId>
48+
<artifactId>spring-boot-starter-web</artifactId>
3949
</dependency>
4050
<dependency>
4151
<groupId>org.projectlombok</groupId>

refs/src/main/java/com/example/springdatajdbcmanyref/MessagingApp.java

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,19 @@
44
import lombok.RequiredArgsConstructor;
55
import lombok.Value;
66
import lombok.With;
7+
import lombok.extern.log4j.Log4j2;
8+
import org.springframework.boot.ApplicationRunner;
9+
import org.springframework.context.annotation.Bean;
710
import org.springframework.context.annotation.Configuration;
811
import org.springframework.data.annotation.Id;
912
import org.springframework.data.annotation.PersistenceConstructor;
1013
import org.springframework.data.relational.core.mapping.Table;
1114
import org.springframework.data.repository.CrudRepository;
1215

16+
import java.util.Iterator;
1317
import java.util.Objects;
18+
import java.util.stream.Collectors;
19+
import java.util.stream.Stream;
1420

1521
@With
1622
@Value
@@ -49,5 +55,30 @@ public static UserRef of(User user) {
4955

5056
interface MessageRepository extends CrudRepository<Message, Long> {}
5157

58+
@Log4j2
5259
@Configuration
53-
public class MessagingApp { /* stub */ }
60+
public class MessagingApp {
61+
/* stub */
62+
@Bean
63+
ApplicationRunner applicationRunner(UserRepository userRepository,
64+
MessageRepository messageRepository) {
65+
return args -> {
66+
Iterable<User> users = userRepository.saveAll(
67+
Stream.of("lola", "bola")
68+
.map(name -> new User(null, name))
69+
.collect(Collectors.toList()));
70+
log.info("saved: {}", users);
71+
72+
Iterator<User> iterator = userRepository.findAll()
73+
.iterator();
74+
User from = iterator.next();
75+
User to = iterator.next();
76+
77+
Iterable<Message> messages = messageRepository.saveAll(
78+
Stream.of("ololo", "trololo")
79+
.map(body -> new Message(null, body, UserRef.of(from), UserRef.of(to)))
80+
.collect(Collectors.toList()));
81+
log.info(messages);
82+
};
83+
}
84+
}

refs/src/main/resources/application.properties

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
spring.output.ansi.enabled=always
2+
spring.h2.console.enabled=true
23
#spring.datasource.url=jdbc:hsqldb:file:./target/db
34
spring.datasource.initialization-mode=embedded
5+
spring.datasource.url=jdbc:h2:./target/db;DATABASE_TO_LOWER=TRUE
46
spring.datasource.schema=\
57
classpath*:/separated.sql, \
68
classpath*:/together.sql, \
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,33 @@
1+
-- h2
12
-- when books and authors are separated
3+
drop table if exists user;
24
create table user (
35
id bigint identity primary key,
46
name varchar(255) not null
57
);
8+
drop table if exists message;
69
create table message (
710
id bigint identity primary key,
811
body varchar(255)
912
);
13+
drop table if exists user_ref;
1014
create table user_ref (
1115
message bigint not null,
1216
user bigint not null,
1317
constraint message_user_pk primary key (message, user)
1418
);
19+
-- -- hsqldb
20+
-- -- when books and authors are separated
21+
-- create table user (
22+
-- id bigint identity primary key,
23+
-- name varchar(255) not null
24+
-- );
25+
-- create table message (
26+
-- id bigint identity primary key,
27+
-- body varchar(255)
28+
-- );
29+
-- create table user_ref (
30+
-- message bigint not null,
31+
-- user bigint not null,
32+
-- constraint message_user_pk primary key (message, user)
33+
-- );
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,22 @@
1+
-- h2
12
-- when books and authors are separated
3+
drop table if exists author;
24
create table author (
35
id bigint identity primary key,
46
name varchar(255) not null
57
);
8+
drop table if exists book;
69
create table book (
710
id bigint identity primary key,
811
title varchar(255)
912
);
13+
-- -- hsqldb
14+
-- -- when books and authors are separated
15+
-- create table author (
16+
-- id bigint identity primary key,
17+
-- name varchar(255) not null
18+
-- );
19+
-- create table book (
20+
-- id bigint identity primary key,
21+
-- title varchar(255)
22+
-- );
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,33 @@
1+
-- h2
12
-- when books with authors all together
3+
drop table if exists author_of_book;
24
create table author_of_book (
35
id bigint identity primary key,
46
name varchar(255) not null
57
);
8+
drop table if exists book_with_authors;
69
create table book_with_authors (
710
id bigint identity primary key,
811
title varchar(255)
912
);
13+
drop table if exists author_of_book_ref;
1014
create table author_of_book_ref (
1115
book_with_authors bigint not null,
1216
author bigint not null,
1317
constraint actor_of_book_ref_pk primary key (book_with_authors, author)
1418
);
19+
-- -- hsqldb
20+
-- -- when books with authors all together
21+
-- create table author_of_book (
22+
-- id bigint identity primary key,
23+
-- name varchar(255) not null
24+
-- );
25+
-- create table book_with_authors (
26+
-- id bigint identity primary key,
27+
-- title varchar(255)
28+
-- );
29+
-- create table author_of_book_ref (
30+
-- book_with_authors bigint not null,
31+
-- author bigint not null,
32+
-- constraint actor_of_book_ref_pk primary key (book_with_authors, author)
33+
-- );

0 commit comments

Comments
 (0)