Skip to content

Commit

Permalink
Merge pull request eugenp#14161 from Eredisse/master
Browse files Browse the repository at this point in the history
BAEL-6024 Guide to YugabyteDB
  • Loading branch information
vinipx authored Jun 19, 2023
2 parents c6dae27 + 24cfe65 commit fe32057
Show file tree
Hide file tree
Showing 6 changed files with 142 additions and 0 deletions.
1 change: 1 addition & 0 deletions persistence-modules/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@
<module>spring-jooq</module>
<module>spring-mybatis</module>
<module>spring-persistence-simple</module>
<module>spring-data-yugabytedb</module>

<module>fauna</module>
<module>spring-data-rest</module>
Expand Down
55 changes: 55 additions & 0 deletions persistence-modules/spring-data-yugabytedb/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://maven.apache.org/POM/4.0.0"
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>
<artifactId>spring-data-yugabytedb</artifactId>
<version>1.0</version>
<name>spring-data-yugabytedb</name>
<packaging>jar</packaging>

<parent>
<groupId>com.baeldung</groupId>
<artifactId>parent-boot-2</artifactId>
<version>0.0.1-SNAPSHOT</version>
<relativePath>../../parent-boot-2</relativePath>
</parent>

<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-test</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.postgresql</groupId>
<artifactId>postgresql</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
</dependencies>

<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
</plugin>
</plugins>
</build>

</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package com.baeldung;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.CommandLineRunner;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;

@SpringBootApplication
public class Main implements CommandLineRunner {

@Autowired
private UserRepository userRepository;

public static void main(String[] args) {
SpringApplication.run(Main.class, args);
}

@Override
public void run(String... args) throws InterruptedException {

int iterationCount = 1_000;
int elementsPerIteration = 100;

for (int i = 0; i < iterationCount; i++) {
for (long j = 0; j < elementsPerIteration; j++) {
User user = new User();
userRepository.save(user);
}
Thread.sleep(1000);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
package com.baeldung;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.Table;

@Entity
@Table(name = "users")
public class User {

@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;

@Column
private String name;

Long getId() {
return id;
}

void setId(Long id) {
this.id = id;
}

String getName() {
return name;
}

void setName(String name) {
this.name = name;
}

@Override
public String toString() {
return "User{" +
"id=" + id +
", name='" + name + '\'' +
'}';
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package com.baeldung;

import org.springframework.data.jpa.repository.JpaRepository;

public interface UserRepository extends JpaRepository<User, Long> {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
spring.datasource.url=jdbc:postgresql://localhost:5433/yugabyte
spring.datasource.username=yugabyte
spring.datasource.password=yugabyte
spring.jpa.hibernate.ddl-auto=create

0 comments on commit fe32057

Please sign in to comment.