diff --git a/jdbc/spring-test-db/pom.xml b/jdbc/spring-test-db/pom.xml new file mode 100644 index 0000000..49cddc1 --- /dev/null +++ b/jdbc/spring-test-db/pom.xml @@ -0,0 +1,143 @@ + + 4.0.0 + + tech.ydb.jdbc.examples + ydb-jdbc-examples + 1.1.0-SNAPSHOT + + + spring-test-db + Spring Data Test Db Example + + 17 + 1.9.22 + 1.4.0 + 3.2.1 + + + + org.springframework.boot + spring-boot-starter-data-jpa + ${spring.boot.version} + + + org.springframework.data + spring-data-commons + ${spring.boot.version} + + + org.jetbrains.kotlin + kotlin-reflect + ${kotlin.version} + + + org.jetbrains.kotlin + kotlin-stdlib + ${kotlin.version} + + + tech.ydb.dialects + hibernate-ydb-dialect + ${hibernate.ydb.dialect.version} + + + tech.ydb.jdbc + ydb-jdbc-driver + + + com.github.javafaker + javafaker + 1.0.2 + + + org.jetbrains.kotlinx + kotlinx-coroutines-core + 1.7.3 + + + org.postgresql + postgresql + 42.7.3 + + + org.testcontainers + postgresql + 1.19.1 + test + + + + org.springframework.boot + spring-boot-starter-test + ${spring.boot.version} + test + + + tech.ydb.test + ydb-junit5-support + test + + + + ${project.basedir}/src/main/kotlin + ${project.basedir}/src/test/kotlin + + + org.apache.maven.plugins + maven-surefire-plugin + + + true + + + + + org.springframework.boot + spring-boot-maven-plugin + ${spring.boot.version} + + + org.jetbrains.kotlin + kotlin-maven-plugin + ${kotlin.version} + + + compile + compile + + compile + + + + test-compile + + test-compile + + + + + 17 + + -Xjsr305=strict + + + spring + jpa + + + + + org.jetbrains.kotlin + kotlin-maven-allopen + ${kotlin.version} + + + org.jetbrains.kotlin + kotlin-maven-noarg + ${kotlin.version} + + + + + + \ No newline at end of file diff --git a/jdbc/spring-test-db/src/main/kotlin/tech/ydb/testdb/TestDbApplication.kt b/jdbc/spring-test-db/src/main/kotlin/tech/ydb/testdb/TestDbApplication.kt new file mode 100644 index 0000000..f8bbee8 --- /dev/null +++ b/jdbc/spring-test-db/src/main/kotlin/tech/ydb/testdb/TestDbApplication.kt @@ -0,0 +1,49 @@ +package tech.ydb.testdb + +import jakarta.persistence.EntityManager +import org.slf4j.LoggerFactory +import org.springframework.beans.factory.annotation.Autowired +import org.springframework.boot.CommandLineRunner +import org.springframework.boot.autoconfigure.SpringBootApplication +import org.springframework.boot.runApplication +import java.time.Instant + +/** + * @author Kirill Kurdyukov + */ +@SpringBootApplication +class TestDbApplication : CommandLineRunner { + companion object { + private val log = LoggerFactory.getLogger(TestDbApplication::class.java) + } + + @Autowired + lateinit var entityManager: EntityManager + + override fun run(vararg args: String?) { + val testString = String(ByteArray(1024) { 'a'.code.toByte() }) + + var sink = 0 + val t0 = System.nanoTime() + val end = t0 + 10_000_000_000L + var count = 0 + while (System.nanoTime() < end) { + sink += getFixedString(testString).length + count++ + } + val elapsed = System.nanoTime() - t0 + val avgMs = elapsed.toDouble() / count / 1_000_000.0 + val opsPerSec = count * 1e9 / elapsed + log.info("avg={} ms/op, throughput={} ops/s", avgMs, opsPerSec) + } + + fun getFixedString(s: String): String { + return entityManager.createNativeQuery("SELECT ?1") + .setParameter(1, s) + .singleResult.toString() + } +} + +fun main(args: Array) { + runApplication(*args) +} \ No newline at end of file diff --git a/jdbc/spring-test-db/src/main/resources/application.properties b/jdbc/spring-test-db/src/main/resources/application.properties new file mode 100644 index 0000000..73bd993 --- /dev/null +++ b/jdbc/spring-test-db/src/main/resources/application.properties @@ -0,0 +1,4 @@ +spring.jpa.properties.hibernate.dialect=tech.ydb.hibernate.dialect.YdbDialect + +spring.datasource.driver-class-name=tech.ydb.jdbc.YdbDriver +spring.datasource.url=jdbc:ydb:grpc://localhost:2136/local