mirror of
https://github.com/OtusTeam/Spring.git
synced 2026-05-30 10:50:42 +00:00
Merge branch 'master' of https://github.com/OtusTeam/Spring
This commit is contained in:
+2
-2
@@ -5,8 +5,8 @@ import ru.otus.springdata.domain.Email;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public interface EmailRepository extends JpaRepository<Email, Long> {
|
||||
public interface EmailRepository {
|
||||
|
||||
@Override
|
||||
//@Override
|
||||
List<Email> findAll();
|
||||
}
|
||||
|
||||
@@ -0,0 +1,33 @@
|
||||
HELP.md
|
||||
target/
|
||||
!.mvn/wrapper/maven-wrapper.jar
|
||||
!**/src/main/**/target/
|
||||
!**/src/test/**/target/
|
||||
|
||||
### STS ###
|
||||
.apt_generated
|
||||
.classpath
|
||||
.factorypath
|
||||
.project
|
||||
.settings
|
||||
.springBeans
|
||||
.sts4-cache
|
||||
|
||||
### IntelliJ IDEA ###
|
||||
.idea
|
||||
*.iws
|
||||
*.iml
|
||||
*.ipr
|
||||
|
||||
### NetBeans ###
|
||||
/nbproject/private/
|
||||
/nbbuild/
|
||||
/dist/
|
||||
/nbdist/
|
||||
/.nb-gradle/
|
||||
build/
|
||||
!**/src/main/**/build/
|
||||
!**/src/test/**/build/
|
||||
|
||||
### VS Code ###
|
||||
.vscode/
|
||||
@@ -0,0 +1,17 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
<groupId>ru.otus</groupId>
|
||||
<artifactId>spring-30</artifactId>
|
||||
<version>1.0</version>
|
||||
|
||||
<packaging>pom</packaging>
|
||||
|
||||
<modules>
|
||||
<module>spring-30-exercise</module>
|
||||
<module>spring-30-solution</module>
|
||||
</modules>
|
||||
</project>
|
||||
@@ -0,0 +1,54 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
<groupId>ru.otus</groupId>
|
||||
<artifactId>spring-30-exercise</artifactId>
|
||||
<version>1.0-SNAPSHOT</version>
|
||||
|
||||
<parent>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-parent</artifactId>
|
||||
<version>2.7.9</version>
|
||||
<relativePath/>
|
||||
</parent>
|
||||
|
||||
<properties>
|
||||
<maven.compiler.target>11</maven.compiler.target>
|
||||
<maven.compiler.source>11</maven.compiler.source>
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
</properties>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-integration</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework</groupId>
|
||||
<artifactId>spring-messaging</artifactId>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-test</artifactId>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.projectlombok</groupId>
|
||||
<artifactId>lombok</artifactId>
|
||||
<optional>true</optional>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-maven-plugin</artifactId>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
</project>
|
||||
+70
@@ -0,0 +1,70 @@
|
||||
package ru.otus.spring.integration;
|
||||
|
||||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
import org.springframework.context.ConfigurableApplicationContext;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.integration.annotation.IntegrationComponentScan;
|
||||
import org.springframework.integration.channel.QueueChannel;
|
||||
import org.springframework.integration.dsl.MessageChannels;
|
||||
import org.springframework.integration.support.MessageBuilder;
|
||||
import org.springframework.messaging.PollableChannel;
|
||||
import org.springframework.messaging.SubscribableChannel;
|
||||
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
||||
|
||||
@SpringBootApplication
|
||||
@IntegrationComponentScan
|
||||
@Slf4j
|
||||
public class App {
|
||||
|
||||
public static void main(String[] args) throws InterruptedException {
|
||||
ConfigurableApplicationContext ctx = SpringApplication.run(App.class, args);
|
||||
|
||||
PollableChannel queueChannel = ctx.getBean("queueChannel", PollableChannel.class);
|
||||
SubscribableChannel directChannel = ctx.getBean("directChannel", SubscribableChannel.class);
|
||||
|
||||
|
||||
log.warn("INIT");
|
||||
for (int i = 0; i < 10; i++) {
|
||||
queueChannel.send(MessageBuilder.withPayload("Start " + i).build());
|
||||
}
|
||||
log.warn("INIT FINISH");
|
||||
Thread.sleep(5000);
|
||||
|
||||
log.warn("START");
|
||||
directChannel.subscribe((msg) -> log.warn("Receive msg: {}", msg));
|
||||
new Thread(() -> {
|
||||
while (true) {
|
||||
directChannel.send(queueChannel.receive());
|
||||
}
|
||||
}).start();
|
||||
log.warn("START FINISH");
|
||||
Thread.sleep(5000);
|
||||
|
||||
log.warn("");
|
||||
queueChannel.send(MessageBuilder.withPayload("Hello").build());
|
||||
Thread.sleep(5000);
|
||||
|
||||
log.warn("");
|
||||
queueChannel.send(MessageBuilder.withPayload("Hello2").build());
|
||||
Thread.sleep(5000);
|
||||
|
||||
log.warn("");
|
||||
queueChannel.send(MessageBuilder.withPayload("Hello3").build());
|
||||
|
||||
}
|
||||
|
||||
@Bean
|
||||
public PollableChannel queueChannel() {
|
||||
return new QueueChannel(10);
|
||||
}
|
||||
|
||||
@Bean
|
||||
public SubscribableChannel directChannel() {
|
||||
return MessageChannels.direct("channel2").get();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,5 @@
|
||||
logging:
|
||||
level:
|
||||
root: info
|
||||
|
||||
org.springframework.integration: debug
|
||||
+98
@@ -0,0 +1,98 @@
|
||||
package ru.otus.spring.integration;
|
||||
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.springframework.messaging.Message;
|
||||
import org.springframework.messaging.MessageHeaders;
|
||||
import org.springframework.messaging.support.ErrorMessage;
|
||||
import org.springframework.messaging.support.GenericMessage;
|
||||
import org.springframework.messaging.support.MessageBuilder;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertNotNull;
|
||||
|
||||
|
||||
@SuppressWarnings("all")
|
||||
public class MessagesTest {
|
||||
|
||||
@Test
|
||||
public void testCreateSimpleGenericMessage() {
|
||||
// TODO: Создайте сообщение с payload-ом "Hello" с помощью конструктора
|
||||
Message<String> message = null;
|
||||
|
||||
assertNotNull(message);
|
||||
assertEquals(GenericMessage.class, message.getClass());
|
||||
assertNotNull(message.getPayload());
|
||||
assertEquals("Hello", message.getPayload());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCreateGenericMessage() {
|
||||
// TODO: Создайте сообщение с пользователем с помощью конструктора
|
||||
Message<User> message = null;
|
||||
|
||||
assertNotNull(message);
|
||||
assertEquals(GenericMessage.class, message.getClass());
|
||||
assertNotNull(message.getPayload());
|
||||
assertEquals(new User("John", 23), message.getPayload());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGenericMessageWithHeaders() {
|
||||
// TODO: Создайте сообщение с payload-ом "Hello" и header-ом "to":"World"
|
||||
Map<String, Object> headers = null;
|
||||
Message<String> message = null;
|
||||
|
||||
assertNotNull(message);
|
||||
assertEquals("Hello", message.getPayload());
|
||||
assertEquals("World", message.getHeaders().get("to", String.class));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGenericMessageWithMessageHeaders() {
|
||||
// TODO: Создайте сообщение с payload-ом "Hello" и header-ом "to":"World"
|
||||
MessageHeaders headers = null;
|
||||
Message<String> message = null;
|
||||
|
||||
assertNotNull(message);
|
||||
assertEquals("Hello", message.getPayload());
|
||||
assertEquals("World", message.getHeaders().get("to", String.class));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testErrorMessage() {
|
||||
// TODO: Создайте сообщение об ошибки с объектом NullPointerException внутри
|
||||
Message errorMessage = null;
|
||||
|
||||
assertNotNull(errorMessage);
|
||||
assertEquals(ErrorMessage.class, errorMessage.getClass());
|
||||
assertEquals(NullPointerException.class, errorMessage.getPayload().getClass());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMessageBuilder() {
|
||||
// TODO: Создайте сообщение с payload-ом "Hello" и header-ом "to":"World" с помощью MessageBuilder
|
||||
Message message = null;
|
||||
|
||||
assertNotNull(message);
|
||||
assertEquals("Hello", message.getPayload());
|
||||
assertEquals("World", message.getHeaders().get("to", String.class));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testBuildFromMessage() {
|
||||
Message<User> original = MessageBuilder
|
||||
.withPayload(new User("Kate", 30))
|
||||
.setHeader("processor", "userService")
|
||||
.build();
|
||||
|
||||
// TODO: Создайте новое сообщение с теми же payload и header-ами c помощью MessageBuilder
|
||||
Message<User> newMessage = null;
|
||||
|
||||
assertNotNull(newMessage);
|
||||
assertEquals(original.getPayload(), newMessage.getPayload());
|
||||
assertEquals(original.getHeaders().get("processor"), newMessage.getHeaders().get("processor"));
|
||||
}
|
||||
}
|
||||
+36
@@ -0,0 +1,36 @@
|
||||
package ru.otus.spring.integration;
|
||||
|
||||
import java.util.Objects;
|
||||
|
||||
public class User {
|
||||
|
||||
private final String name;
|
||||
private final int age;
|
||||
|
||||
public User(String name, int age) {
|
||||
this.name = name;
|
||||
this.age = age;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public int getAge() {
|
||||
return age;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (this == o) return true;
|
||||
if (!(o instanceof User)) return false;
|
||||
User user = (User) o;
|
||||
return age == user.age &&
|
||||
Objects.equals(name, user.name);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return Objects.hash(name, age);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,52 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
<groupId>ru.otus</groupId>
|
||||
<artifactId>spring-30-solution</artifactId>
|
||||
<version>1.0-SNAPSHOT</version>
|
||||
|
||||
<parent>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-parent</artifactId>
|
||||
<version>2.7.9</version>
|
||||
</parent>
|
||||
|
||||
<properties>
|
||||
<maven.compiler.target>11</maven.compiler.target>
|
||||
<maven.compiler.source>11</maven.compiler.source>
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
</properties>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-integration</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework</groupId>
|
||||
<artifactId>spring-messaging</artifactId>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-test</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.projectlombok</groupId>
|
||||
<artifactId>lombok</artifactId>
|
||||
<optional>true</optional>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-maven-plugin</artifactId>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
</project>
|
||||
+70
@@ -0,0 +1,70 @@
|
||||
package ru.otus.spring.integration;
|
||||
|
||||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
import org.springframework.context.ConfigurableApplicationContext;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.integration.annotation.IntegrationComponentScan;
|
||||
import org.springframework.integration.channel.QueueChannel;
|
||||
import org.springframework.integration.dsl.MessageChannels;
|
||||
import org.springframework.integration.support.MessageBuilder;
|
||||
import org.springframework.messaging.PollableChannel;
|
||||
import org.springframework.messaging.SubscribableChannel;
|
||||
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
||||
|
||||
@SpringBootApplication
|
||||
@IntegrationComponentScan
|
||||
@Slf4j
|
||||
public class App {
|
||||
|
||||
public static void main(String[] args) throws InterruptedException {
|
||||
ConfigurableApplicationContext ctx = SpringApplication.run(App.class, args);
|
||||
|
||||
PollableChannel queueChannel = ctx.getBean("queueChannel", PollableChannel.class);
|
||||
SubscribableChannel directChannel = ctx.getBean("directChannel", SubscribableChannel.class);
|
||||
|
||||
|
||||
log.warn("INIT");
|
||||
for (int i = 0; i < 10; i++) {
|
||||
queueChannel.send(MessageBuilder.withPayload("Start " + i).build());
|
||||
}
|
||||
log.warn("INIT FINISH");
|
||||
Thread.sleep(5000);
|
||||
|
||||
log.warn("START");
|
||||
directChannel.subscribe((msg) -> log.warn("Receive msg: {}", msg));
|
||||
new Thread(() -> {
|
||||
while (true) {
|
||||
directChannel.send(queueChannel.receive());
|
||||
}
|
||||
}).start();
|
||||
log.warn("START FINISH");
|
||||
Thread.sleep(5000);
|
||||
|
||||
log.warn("");
|
||||
queueChannel.send(MessageBuilder.withPayload("Hello").build());
|
||||
Thread.sleep(5000);
|
||||
|
||||
log.warn("");
|
||||
queueChannel.send(MessageBuilder.withPayload("Hello2").build());
|
||||
Thread.sleep(5000);
|
||||
|
||||
log.warn("");
|
||||
queueChannel.send(MessageBuilder.withPayload("Hello3").build());
|
||||
|
||||
}
|
||||
|
||||
@Bean
|
||||
public PollableChannel queueChannel() {
|
||||
return new QueueChannel(10);
|
||||
}
|
||||
|
||||
@Bean
|
||||
public SubscribableChannel directChannel() {
|
||||
return MessageChannels.direct("channel2").get();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,5 @@
|
||||
logging:
|
||||
level:
|
||||
root: info
|
||||
|
||||
org.springframework.integration: debug
|
||||
+101
@@ -0,0 +1,101 @@
|
||||
package ru.otus.spring.integration;
|
||||
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.springframework.messaging.Message;
|
||||
import org.springframework.messaging.MessageHeaders;
|
||||
import org.springframework.messaging.support.ErrorMessage;
|
||||
import org.springframework.messaging.support.GenericMessage;
|
||||
import org.springframework.messaging.support.MessageBuilder;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.Map;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertNotNull;
|
||||
|
||||
|
||||
@SuppressWarnings("all")
|
||||
public class MessagesTest {
|
||||
|
||||
@Test
|
||||
public void testCreateSimpleGenericMessage() {
|
||||
// TODO: Создайте сообщение с payload-ом "Hello" с помощью конструктора
|
||||
Message<String> message = new GenericMessage<String>("Hello");
|
||||
|
||||
assertNotNull(message);
|
||||
assertEquals(GenericMessage.class, message.getClass());
|
||||
assertNotNull(message.getPayload());
|
||||
assertEquals("Hello", message.getPayload());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCreateGenericMessage() {
|
||||
// TODO: Создайте сообщение с пользователем с помощью конструктора
|
||||
Message<User> message = new GenericMessage<User>(new User("John", 23));
|
||||
|
||||
assertNotNull(message);
|
||||
assertEquals(GenericMessage.class, message.getClass());
|
||||
assertNotNull(message.getPayload());
|
||||
assertEquals(new User("John", 23), message.getPayload());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGenericMessageWithHeaders() {
|
||||
// TODO: Создайте сообщение с payload-ом "Hello" и header-ом "to":"World"
|
||||
Map<String, Object> headers = Collections.singletonMap("to", "World");
|
||||
Message<String> message = new GenericMessage<>("Hello", headers);
|
||||
|
||||
assertNotNull(message);
|
||||
assertEquals("Hello", message.getPayload());
|
||||
assertEquals("World", message.getHeaders().get("to", String.class));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGenericMessageWithMessageHeaders() {
|
||||
// TODO: Создайте сообщение с payload-ом "Hello" и header-ом "to":"World"
|
||||
MessageHeaders headers = new MessageHeaders(Collections.singletonMap("to", "World"));
|
||||
Message<String> message = new GenericMessage<>("Hello", headers);
|
||||
|
||||
assertNotNull(message);
|
||||
assertEquals("Hello", message.getPayload());
|
||||
assertEquals("World", message.getHeaders().get("to", String.class));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testErrorMessage() {
|
||||
// TODO: Создайте сообщение об ошибки с объектом NullPointerException внутри
|
||||
Message errorMessage = new ErrorMessage(new NullPointerException());
|
||||
|
||||
assertNotNull(errorMessage);
|
||||
assertEquals(ErrorMessage.class, errorMessage.getClass());
|
||||
assertEquals(NullPointerException.class, errorMessage.getPayload().getClass());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMessageBuilder() {
|
||||
// TODO: Создайте сообщение с payload-ом "Hello" и header-ом "to":"World" с помощью MessageBuilder
|
||||
Message message = MessageBuilder.withPayload("Hello")
|
||||
.setHeader("to", "World")
|
||||
.build();
|
||||
|
||||
assertNotNull(message);
|
||||
assertEquals("Hello", message.getPayload());
|
||||
assertEquals("World", message.getHeaders().get("to", String.class));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testBuildFromMessage() {
|
||||
Message<User> original = MessageBuilder
|
||||
.withPayload(new User("Kate", 30))
|
||||
.setHeader("processor", "userService")
|
||||
.build();
|
||||
|
||||
// TODO: Создайте новое сообщение с теми же payload и header-ами c помощью MessageBuilder
|
||||
Message<User> newMessage = MessageBuilder.fromMessage(original).build();
|
||||
|
||||
assertNotNull(newMessage);
|
||||
assertEquals(original.getPayload(), newMessage.getPayload());
|
||||
assertEquals(original.getHeaders().get("processor"), newMessage.getHeaders().get("processor"));
|
||||
}
|
||||
}
|
||||
+36
@@ -0,0 +1,36 @@
|
||||
package ru.otus.spring.integration;
|
||||
|
||||
import java.util.Objects;
|
||||
|
||||
public class User {
|
||||
|
||||
private final String name;
|
||||
private final int age;
|
||||
|
||||
public User(String name, int age) {
|
||||
this.name = name;
|
||||
this.age = age;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public int getAge() {
|
||||
return age;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (this == o) return true;
|
||||
if (!(o instanceof User)) return false;
|
||||
User user = (User) o;
|
||||
return age == user.age &&
|
||||
Objects.equals(name, user.name);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return Objects.hash(name, age);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
<groupId>ru.otus</groupId>
|
||||
<artifactId>spring-data-keyvalue-class-work</artifactId>
|
||||
<version>1.0</version>
|
||||
|
||||
<packaging>pom</packaging>
|
||||
|
||||
<modules>
|
||||
<module>spring-data-keyvalue-exercise</module>
|
||||
<module>spring-data-keyvalue-solution</module>
|
||||
</modules>
|
||||
</project>
|
||||
+43
@@ -0,0 +1,43 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
<groupId>ru.otus</groupId>
|
||||
<artifactId>spring-data-keyvalue-exercise</artifactId>
|
||||
<version>1.0-SNAPSHOT</version>
|
||||
|
||||
<parent>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-parent</artifactId>
|
||||
<version>2.2.1.RELEASE</version>
|
||||
<relativePath />
|
||||
</parent>
|
||||
|
||||
<properties>
|
||||
<maven.compiler.source>11</maven.compiler.source>
|
||||
<maven.compiler.target>11</maven.compiler.target>
|
||||
</properties>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter</artifactId>
|
||||
</dependency>
|
||||
<!--<dependency>-->
|
||||
<!--<groupId>org.springframework.data</groupId>-->
|
||||
<!--<artifactId>spring-data-keyvalue</artifactId>-->
|
||||
<!--<version>2.2.1.RELEASE</version>-->
|
||||
<!--</dependency>-->
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-maven-plugin</artifactId>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
</project>
|
||||
+29
@@ -0,0 +1,29 @@
|
||||
package ru.otus.spring;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
import org.springframework.data.map.repository.config.EnableMapRepositories;
|
||||
import ru.otus.spring.domain.Person;
|
||||
import ru.otus.spring.repostory.PersonRepository;
|
||||
|
||||
import javax.annotation.PostConstruct;
|
||||
|
||||
@SpringBootApplication
|
||||
public class Main {
|
||||
|
||||
public static void main(String[] args) {
|
||||
SpringApplication.run(Main.class);
|
||||
}
|
||||
|
||||
@SuppressWarnings("SpringJavaAutowiredFieldsWarningInspection")
|
||||
@Autowired
|
||||
private PersonRepository repository;
|
||||
|
||||
@PostConstruct
|
||||
public void init() {
|
||||
repository.save(new Person(1, "Pushkin"));
|
||||
|
||||
repository.findAll();
|
||||
}
|
||||
}
|
||||
+25
@@ -0,0 +1,25 @@
|
||||
package ru.otus.spring.domain;
|
||||
|
||||
public class Email {
|
||||
|
||||
private int id;
|
||||
|
||||
private String email;
|
||||
|
||||
public Email(String email) {
|
||||
this.email = email;
|
||||
}
|
||||
|
||||
public Email(int id, String email) {
|
||||
this.id = id;
|
||||
this.email = email;
|
||||
}
|
||||
|
||||
public int getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public String getEmail() {
|
||||
return email;
|
||||
}
|
||||
}
|
||||
+35
@@ -0,0 +1,35 @@
|
||||
package ru.otus.spring.domain;
|
||||
|
||||
import org.springframework.data.annotation.Id;
|
||||
import org.springframework.data.keyvalue.annotation.KeySpace;
|
||||
|
||||
public class Person {
|
||||
|
||||
private int id;
|
||||
private String name;
|
||||
|
||||
public Person(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public Person(int id, String name) {
|
||||
this.id = id;
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public int getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(int id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
}
|
||||
+11
@@ -0,0 +1,11 @@
|
||||
package ru.otus.spring.repostory;
|
||||
|
||||
import org.springframework.data.repository.CrudRepository;
|
||||
import ru.otus.spring.domain.Person;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public interface PersonRepository extends CrudRepository<Person, Integer> {
|
||||
|
||||
List<Person> findAll();
|
||||
}
|
||||
+43
@@ -0,0 +1,43 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
<groupId>ru.otus</groupId>
|
||||
<artifactId>spring-data-keyvalue-solution</artifactId>
|
||||
<version>1.0-SNAPSHOT</version>
|
||||
|
||||
<parent>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-parent</artifactId>
|
||||
<version>2.2.1.RELEASE</version>
|
||||
<relativePath />
|
||||
</parent>
|
||||
|
||||
<properties>
|
||||
<maven.compiler.source>11</maven.compiler.source>
|
||||
<maven.compiler.target>11</maven.compiler.target>
|
||||
</properties>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.data</groupId>
|
||||
<artifactId>spring-data-keyvalue</artifactId>
|
||||
<version>2.2.1.RELEASE</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-maven-plugin</artifactId>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
</project>
|
||||
+39
@@ -0,0 +1,39 @@
|
||||
package ru.otus.spring;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
import org.springframework.data.map.repository.config.EnableMapRepositories;
|
||||
import ru.otus.spring.domain.Email;
|
||||
import ru.otus.spring.domain.Person;
|
||||
import ru.otus.spring.repostory.EmailRepository;
|
||||
import ru.otus.spring.repostory.PersonRepository;
|
||||
|
||||
import javax.annotation.PostConstruct;
|
||||
|
||||
@SpringBootApplication
|
||||
@EnableMapRepositories
|
||||
public class Main {
|
||||
|
||||
public static void main(String[] args) {
|
||||
SpringApplication.run(Main.class);
|
||||
}
|
||||
|
||||
@SuppressWarnings("SpringJavaAutowiredFieldsWarningInspection")
|
||||
@Autowired
|
||||
private PersonRepository repository;
|
||||
|
||||
@Autowired
|
||||
private EmailRepository emailRepository;
|
||||
|
||||
@PostConstruct
|
||||
public void init() {
|
||||
repository.save(new Person(1, "Pushkin"));
|
||||
repository.save(new Person(2, "Lermontov"));
|
||||
System.out.println(repository.findAll());
|
||||
|
||||
emailRepository.save(new Email(1, "alex@pushkin.com"));
|
||||
emailRepository.save(new Email(2, "micha@pushkin.com"));
|
||||
System.out.println(emailRepository.findAll());
|
||||
}
|
||||
}
|
||||
+37
@@ -0,0 +1,37 @@
|
||||
package ru.otus.spring.domain;
|
||||
|
||||
import org.springframework.data.annotation.Id;
|
||||
import org.springframework.data.keyvalue.annotation.KeySpace;
|
||||
|
||||
@KeySpace("email")
|
||||
public class Email {
|
||||
@Id
|
||||
private int id;
|
||||
|
||||
private String email;
|
||||
|
||||
public Email(int id, String email) {
|
||||
this.id = id;
|
||||
this.email = email;
|
||||
}
|
||||
|
||||
public Email(String email) {
|
||||
this.email = email;
|
||||
}
|
||||
|
||||
public int getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public String getEmail() {
|
||||
return email;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "Email{" +
|
||||
"id=" + id +
|
||||
", email='" + email + '\'' +
|
||||
'}';
|
||||
}
|
||||
}
|
||||
+45
@@ -0,0 +1,45 @@
|
||||
package ru.otus.spring.domain;
|
||||
|
||||
import org.springframework.data.annotation.Id;
|
||||
import org.springframework.data.keyvalue.annotation.KeySpace;
|
||||
|
||||
@KeySpace("person")
|
||||
public class Person {
|
||||
|
||||
@Id
|
||||
private int id;
|
||||
private String name;
|
||||
|
||||
public Person(int id, String name) {
|
||||
this.id = id;
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public Person(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public int getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(int id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "Person{" +
|
||||
"id=" + id +
|
||||
", name='" + name + '\'' +
|
||||
'}';
|
||||
}
|
||||
}
|
||||
+14
@@ -0,0 +1,14 @@
|
||||
package ru.otus.spring.repostory;
|
||||
|
||||
import org.springframework.data.keyvalue.repository.KeyValueRepository;
|
||||
import org.springframework.stereotype.Repository;
|
||||
import ru.otus.spring.domain.Email;
|
||||
import ru.otus.spring.domain.Person;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public interface EmailRepository {
|
||||
|
||||
List<Email> findAll();
|
||||
Email save(Email email);
|
||||
}
|
||||
+27
@@ -0,0 +1,27 @@
|
||||
package ru.otus.spring.repostory;
|
||||
|
||||
import org.springframework.data.keyvalue.core.KeyValueOperations;
|
||||
import org.springframework.stereotype.Repository;
|
||||
import ru.otus.spring.domain.Email;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Repository
|
||||
public class EmailRepositoryImpl implements EmailRepository {
|
||||
|
||||
final private KeyValueOperations keyValueTemplate;
|
||||
|
||||
public EmailRepositoryImpl(KeyValueOperations keyValueTemplate) {
|
||||
this.keyValueTemplate = keyValueTemplate;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Email> findAll() {
|
||||
return (List<Email>) keyValueTemplate.findAll(Email.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Email save(Email email) {
|
||||
return keyValueTemplate.insert(email);
|
||||
}
|
||||
}
|
||||
+12
@@ -0,0 +1,12 @@
|
||||
package ru.otus.spring.repostory;
|
||||
|
||||
import org.springframework.data.keyvalue.repository.KeyValueRepository;
|
||||
import org.springframework.data.repository.CrudRepository;
|
||||
import ru.otus.spring.domain.Person;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public interface PersonRepository extends KeyValueRepository<Person, Integer> {
|
||||
|
||||
List<Person> findAll();
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
<groupId>ru.otus</groupId>
|
||||
<artifactId>spring-data-mongo-class-work</artifactId>
|
||||
<version>1.0</version>
|
||||
|
||||
<packaging>pom</packaging>
|
||||
|
||||
<modules>
|
||||
<module>spring-data-mongo-exercise</module>
|
||||
<module>spring-data-mongo-solution</module>
|
||||
</modules>
|
||||
</project>
|
||||
@@ -0,0 +1,46 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
<groupId>ru.otus</groupId>
|
||||
<artifactId>spring-data-mongo-exercise</artifactId>
|
||||
<version>1.0-SNAPSHOT</version>
|
||||
|
||||
<parent>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-parent</artifactId>
|
||||
<version>2.3.4.RELEASE</version>
|
||||
<relativePath />
|
||||
</parent>
|
||||
|
||||
<properties>
|
||||
<maven.compiler.source>11</maven.compiler.source>
|
||||
<maven.compiler.target>11</maven.compiler.target>
|
||||
</properties>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-data-mongodb</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>de.flapdoodle.embed</groupId>
|
||||
<artifactId>de.flapdoodle.embed.mongo</artifactId>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-maven-plugin</artifactId>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
</project>
|
||||
+31
@@ -0,0 +1,31 @@
|
||||
package ru.otus.spring;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
import org.springframework.context.ApplicationContext;
|
||||
import ru.otus.spring.domain.Person;
|
||||
import ru.otus.spring.repostory.PersonRepository;
|
||||
|
||||
@SpringBootApplication
|
||||
public class Main {
|
||||
|
||||
@SuppressWarnings("SpringJavaAutowiredFieldsWarningInspection")
|
||||
@Autowired
|
||||
private PersonRepository repository;
|
||||
|
||||
public static void main(String[] args) throws InterruptedException {
|
||||
ApplicationContext context = SpringApplication.run(Main.class);
|
||||
|
||||
PersonRepository repository = context.getBean(PersonRepository.class);
|
||||
|
||||
repository.save(new Person("Dostoevsky"));
|
||||
|
||||
Thread.sleep(3000);
|
||||
|
||||
System.out.println("\n\n\n----------------------------------------------\n\n");
|
||||
System.out.println("Авторы в БД:");
|
||||
repository.findAll().forEach(p -> System.out.println(p.getName()));
|
||||
System.out.println("\n\n----------------------------------------------\n\n\n");
|
||||
}
|
||||
}
|
||||
+27
@@ -0,0 +1,27 @@
|
||||
package ru.otus.spring.domain;
|
||||
|
||||
public class Person {
|
||||
|
||||
private String id;
|
||||
private String name;
|
||||
|
||||
public Person(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public String getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(String id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
}
|
||||
+12
@@ -0,0 +1,12 @@
|
||||
package ru.otus.spring.repostory;
|
||||
|
||||
import org.springframework.data.repository.CrudRepository;
|
||||
import ru.otus.spring.domain.Person;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
|
||||
public interface PersonRepository extends CrudRepository<Person, Integer> {
|
||||
|
||||
List<Person> findAll();
|
||||
}
|
||||
+4
@@ -0,0 +1,4 @@
|
||||
spring:
|
||||
data:
|
||||
mongodb:
|
||||
database: company
|
||||
@@ -0,0 +1,61 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
<groupId>ru.otus</groupId>
|
||||
<artifactId>spring-data-mongo-solution</artifactId>
|
||||
<version>1.0-SNAPSHOT</version>
|
||||
|
||||
<parent>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-parent</artifactId>
|
||||
<version>2.3.4.RELEASE</version>
|
||||
<relativePath />
|
||||
</parent>
|
||||
|
||||
<properties>
|
||||
<maven.compiler.source>11</maven.compiler.source>
|
||||
<maven.compiler.target>11</maven.compiler.target>
|
||||
<mongock.version>4.1.17</mongock.version>
|
||||
</properties>
|
||||
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-data-mongodb</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>de.flapdoodle.embed</groupId>
|
||||
<artifactId>de.flapdoodle.embed.mongo</artifactId>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>com.github.cloudyrock.mongock</groupId>
|
||||
<artifactId>mongock-spring-v5</artifactId>
|
||||
<version>${mongock.version}</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>com.github.cloudyrock.mongock</groupId>
|
||||
<artifactId>mongodb-springdata-v3-driver</artifactId>
|
||||
<version>${mongock.version}</version>
|
||||
</dependency>
|
||||
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-maven-plugin</artifactId>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
</project>
|
||||
+35
@@ -0,0 +1,35 @@
|
||||
package ru.otus.spring;
|
||||
|
||||
import com.github.cloudyrock.spring.v5.EnableMongock;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
import org.springframework.context.ApplicationContext;
|
||||
import org.springframework.data.mongodb.repository.config.EnableMongoRepositories;
|
||||
import ru.otus.spring.domain.Person;
|
||||
import ru.otus.spring.repostory.PersonRepository;
|
||||
|
||||
@EnableMongock
|
||||
@EnableMongoRepositories
|
||||
@SpringBootApplication
|
||||
public class Main {
|
||||
|
||||
@SuppressWarnings("SpringJavaAutowiredFieldsWarningInspection")
|
||||
@Autowired
|
||||
private PersonRepository repository;
|
||||
|
||||
public static void main(String[] args) throws InterruptedException {
|
||||
ApplicationContext context = SpringApplication.run(Main.class);
|
||||
|
||||
PersonRepository repository = context.getBean(PersonRepository.class);
|
||||
|
||||
repository.save(new Person("Dostoevsky"));
|
||||
|
||||
Thread.sleep(3000);
|
||||
|
||||
System.out.println("\n\n\n----------------------------------------------\n\n");
|
||||
System.out.println("Авторы в БД:");
|
||||
repository.findAll().forEach(p -> System.out.println(p.getName()));
|
||||
System.out.println("\n\n----------------------------------------------\n\n\n");
|
||||
}
|
||||
}
|
||||
+32
@@ -0,0 +1,32 @@
|
||||
package ru.otus.spring.domain;
|
||||
|
||||
import org.springframework.data.annotation.Id;
|
||||
import org.springframework.data.mongodb.core.mapping.Document;
|
||||
|
||||
@Document(collection = "persons")
|
||||
public class Person {
|
||||
|
||||
@Id
|
||||
private String id;
|
||||
private String name;
|
||||
|
||||
public Person(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public String getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(String id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
}
|
||||
+30
@@ -0,0 +1,30 @@
|
||||
package ru.otus.spring.mongock.changelog;
|
||||
|
||||
import com.github.cloudyrock.mongock.ChangeLog;
|
||||
import com.github.cloudyrock.mongock.ChangeSet;
|
||||
import com.mongodb.client.MongoCollection;
|
||||
import com.mongodb.client.MongoDatabase;
|
||||
import org.bson.Document;
|
||||
import ru.otus.spring.domain.Person;
|
||||
import ru.otus.spring.repostory.PersonRepository;
|
||||
|
||||
@ChangeLog
|
||||
public class DatabaseChangelog {
|
||||
|
||||
@ChangeSet(order = "001", id = "dropDb", author = "stvort", runAlways = true)
|
||||
public void dropDb(MongoDatabase db) {
|
||||
db.drop();
|
||||
}
|
||||
|
||||
@ChangeSet(order = "002", id = "insertLermontov", author = "ydvorzhetskiy")
|
||||
public void insertLermontov(MongoDatabase db) {
|
||||
MongoCollection<Document> myCollection = db.getCollection("persons");
|
||||
var doc = new Document().append("name", "Lermontov");
|
||||
myCollection.insertOne(doc);
|
||||
}
|
||||
|
||||
@ChangeSet(order = "003", id = "insertPushkin", author = "stvort")
|
||||
public void insertPushkin(PersonRepository repository) {
|
||||
repository.save(new Person("Pushkin"));
|
||||
}
|
||||
}
|
||||
+12
@@ -0,0 +1,12 @@
|
||||
package ru.otus.spring.repostory;
|
||||
|
||||
import org.springframework.data.repository.CrudRepository;
|
||||
import ru.otus.spring.domain.Person;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
|
||||
public interface PersonRepository extends CrudRepository<Person, Integer> {
|
||||
|
||||
List<Person> findAll();
|
||||
}
|
||||
+10
@@ -0,0 +1,10 @@
|
||||
spring:
|
||||
data:
|
||||
mongodb:
|
||||
database: company
|
||||
|
||||
mongock:
|
||||
runner-type: "ApplicationRunner" # default
|
||||
#runner-type: "InitializingBean"
|
||||
change-logs-scan-package:
|
||||
- ru.otus.spring.mongock.changelog
|
||||
Reference in New Issue
Block a user