Skip to content

Commit fe32057

Browse files
authored
Merge pull request eugenp#14161 from Eredisse/master
BAEL-6024 Guide to YugabyteDB
2 parents c6dae27 + 24cfe65 commit fe32057

File tree

6 files changed

+142
-0
lines changed

6 files changed

+142
-0
lines changed

persistence-modules/pom.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,7 @@
105105
<module>spring-jooq</module>
106106
<module>spring-mybatis</module>
107107
<module>spring-persistence-simple</module>
108+
<module>spring-data-yugabytedb</module>
108109

109110
<module>fauna</module>
110111
<module>spring-data-rest</module>
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
3+
xmlns="http://maven.apache.org/POM/4.0.0"
4+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
5+
<modelVersion>4.0.0</modelVersion>
6+
<artifactId>spring-data-yugabytedb</artifactId>
7+
<version>1.0</version>
8+
<name>spring-data-yugabytedb</name>
9+
<packaging>jar</packaging>
10+
11+
<parent>
12+
<groupId>com.baeldung</groupId>
13+
<artifactId>parent-boot-2</artifactId>
14+
<version>0.0.1-SNAPSHOT</version>
15+
<relativePath>../../parent-boot-2</relativePath>
16+
</parent>
17+
18+
<dependencies>
19+
<dependency>
20+
<groupId>org.springframework.boot</groupId>
21+
<artifactId>spring-boot-starter-web</artifactId>
22+
</dependency>
23+
<dependency>
24+
<groupId>org.projectlombok</groupId>
25+
<artifactId>lombok</artifactId>
26+
</dependency>
27+
<dependency>
28+
<groupId>org.springframework</groupId>
29+
<artifactId>spring-test</artifactId>
30+
</dependency>
31+
<dependency>
32+
<groupId>org.springframework.boot</groupId>
33+
<artifactId>spring-boot-starter-test</artifactId>
34+
<scope>test</scope>
35+
</dependency>
36+
<dependency>
37+
<groupId>org.postgresql</groupId>
38+
<artifactId>postgresql</artifactId>
39+
</dependency>
40+
<dependency>
41+
<groupId>org.springframework.boot</groupId>
42+
<artifactId>spring-boot-starter-data-jpa</artifactId>
43+
</dependency>
44+
</dependencies>
45+
46+
<build>
47+
<plugins>
48+
<plugin>
49+
<groupId>org.apache.maven.plugins</groupId>
50+
<artifactId>maven-surefire-plugin</artifactId>
51+
</plugin>
52+
</plugins>
53+
</build>
54+
55+
</project>
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
package com.baeldung;
2+
3+
import org.springframework.beans.factory.annotation.Autowired;
4+
import org.springframework.boot.CommandLineRunner;
5+
import org.springframework.boot.SpringApplication;
6+
import org.springframework.boot.autoconfigure.SpringBootApplication;
7+
8+
@SpringBootApplication
9+
public class Main implements CommandLineRunner {
10+
11+
@Autowired
12+
private UserRepository userRepository;
13+
14+
public static void main(String[] args) {
15+
SpringApplication.run(Main.class, args);
16+
}
17+
18+
@Override
19+
public void run(String... args) throws InterruptedException {
20+
21+
int iterationCount = 1_000;
22+
int elementsPerIteration = 100;
23+
24+
for (int i = 0; i < iterationCount; i++) {
25+
for (long j = 0; j < elementsPerIteration; j++) {
26+
User user = new User();
27+
userRepository.save(user);
28+
}
29+
Thread.sleep(1000);
30+
}
31+
}
32+
}
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
package com.baeldung;
2+
3+
import javax.persistence.Column;
4+
import javax.persistence.Entity;
5+
import javax.persistence.GeneratedValue;
6+
import javax.persistence.GenerationType;
7+
import javax.persistence.Id;
8+
import javax.persistence.Table;
9+
10+
@Entity
11+
@Table(name = "users")
12+
public class User {
13+
14+
@Id
15+
@GeneratedValue(strategy = GenerationType.IDENTITY)
16+
private Long id;
17+
18+
@Column
19+
private String name;
20+
21+
Long getId() {
22+
return id;
23+
}
24+
25+
void setId(Long id) {
26+
this.id = id;
27+
}
28+
29+
String getName() {
30+
return name;
31+
}
32+
33+
void setName(String name) {
34+
this.name = name;
35+
}
36+
37+
@Override
38+
public String toString() {
39+
return "User{" +
40+
"id=" + id +
41+
", name='" + name + '\'' +
42+
'}';
43+
}
44+
}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
package com.baeldung;
2+
3+
import org.springframework.data.jpa.repository.JpaRepository;
4+
5+
public interface UserRepository extends JpaRepository<User, Long> {
6+
}
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
spring.datasource.url=jdbc:postgresql://localhost:5433/yugabyte
2+
spring.datasource.username=yugabyte
3+
spring.datasource.password=yugabyte
4+
spring.jpa.hibernate.ddl-auto=create

0 commit comments

Comments
 (0)