Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion buildSrc/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ repositories {
}

dependencies {
val kotlinVersion = "2.2.20"
val kotlinVersion = "2.2.21"

implementation("org.jetbrains.kotlin:kotlin-gradle-plugin:${kotlinVersion}")
implementation("org.jetbrains.kotlin:kotlin-serialization:${kotlinVersion}")
Expand Down
15 changes: 8 additions & 7 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,10 @@ errorProne = "2.35.1"
junit-jupiter = "5.10.3"
jackson = "2.18.1"
testcontainers = "1.20.3"
springBoot = "3.5.8"

[libraries]
uuidGenerator = { module = "com.fasterxml.uuid:java-uuid-generator", version = "5.1.0" }
uuidGenerator = { module = "com.fasterxml.uuid:java-uuid-generator", version = "5.1.1" }
jetbrains-annotations = { module = "org.jetbrains:annotations", version = "26.0.2" }
jackson-databind = { group = "com.fasterxml.jackson.core", name = "jackson-databind", version.ref = "jackson" }
jackson-annotations = { group = "com.fasterxml.jackson.core", name = "jackson-annotations", version.ref = "jackson" }
Expand All @@ -32,17 +33,17 @@ hibernate-orm-v62 = { group = "org.hibernate.orm", name = "hibernate-core", vers
hibernate-orm-v63 = { group = "org.hibernate.orm", name = "hibernate-core", version = "6.3.2.Final" }
hibernate-orm-v64 = { group = "org.hibernate.orm", name = "hibernate-core", version = "6.4.10.Final" }
hibernate-orm-v65 = { group = "org.hibernate.orm", name = "hibernate-core", version = "6.5.3.Final" }
hibernate-orm-v66 = { group = "org.hibernate.orm", name = "hibernate-core", version = "6.6.31.Final" }
hibernate-orm-v66 = { group = "org.hibernate.orm", name = "hibernate-core", version = "6.6.36.Final" }
hibernate-orm-v70 = { group = "org.hibernate.orm", name = "hibernate-core", version = "7.0.10.Final" }
hibernate-orm-v71 = { group = "org.hibernate.orm", name = "hibernate-core", version = "7.1.2.Final" }
hibernate-orm-v71 = { group = "org.hibernate.orm", name = "hibernate-core", version = "7.1.9.Final" }
hibernate-models-v70 = { group = "org.hibernate.models", name = "hibernate-models", version = "1.0.0" }
hypersistence-utils-hibernate61 = { group = "io.hypersistence", name = "hypersistence-utils-hibernate-60", version = "3.9.4" }
hypersistence-utils-hibernate62 = { group = "io.hypersistence", name = "hypersistence-utils-hibernate-62", version = "3.9.4" }
hypersistence-utils-hibernate63 = { group = "io.hypersistence", name = "hypersistence-utils-hibernate-63", version = "3.11.0" }
hypersistence-utils-hibernate70 = { group = "io.hypersistence", name = "hypersistence-utils-hibernate-70", version = "3.11.0" }
hypersistence-utils-hibernate71 = { group = "io.hypersistence", name = "hypersistence-utils-hibernate-71", version = "3.11.0" }
hypersistence-utils-hibernate63 = { group = "io.hypersistence", name = "hypersistence-utils-hibernate-63", version = "3.12.0" }
hypersistence-utils-hibernate70 = { group = "io.hypersistence", name = "hypersistence-utils-hibernate-70", version = "3.12.0" }
hypersistence-utils-hibernate71 = { group = "io.hypersistence", name = "hypersistence-utils-hibernate-71", version = "3.12.0" }
hypersistence-tsid = { module = "io.hypersistence:hypersistence-tsid", version = "2.1.4" }
kotlinx-serialization = { module = "org.jetbrains.kotlinx:kotlinx-serialization-json", version = "1.7.0" }
swagger-v3-core-jakarta = { module = "io.swagger.core.v3:swagger-core-jakarta", version = "2.2.35" }
springdoc-openapi-starter-common = { module = "org.springdoc:springdoc-openapi-starter-common", version = "2.1.0" }
springdoc-openapi-spring-configuration-processor = { module = "org.springframework.boot:spring-boot-configuration-processor", version = "3.0.5" }
springdoc-openapi-spring-configuration-processor = { module = "org.springframework.boot:spring-boot-configuration-processor", version.ref = "springBoot" }
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ plugins {
dependencies {
implementation(project(":typed-ids-hibernate-63"))

api(platform("org.springframework.boot:spring-boot-dependencies:3.4.10"))
api(platform("org.springframework.boot:spring-boot-dependencies:3.5.8"))
api("org.springframework.boot:spring-boot-starter-data-jpa")

annotationProcessor(project(":typed-ids-index-java-classes-processor"))
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
plugins {
id("framefork.java")
}

dependencies {
implementation(project(":typed-ids-hibernate-70"))

api(platform("org.springframework.boot:spring-boot-dependencies:4.0.0"))
api("org.springframework.boot:spring-boot-starter-data-jpa")

annotationProcessor(project(":typed-ids-index-java-classes-processor"))
testAnnotationProcessor(project(":typed-ids-index-java-classes-processor"))

testImplementation(project(":typed-ids-hibernate-70-testing"))
testImplementation("org.springframework.boot:spring-boot-starter-test")
testImplementation("org.springframework.boot:spring-boot-starter-data-jpa-test")
testImplementation("org.springframework.boot:spring-boot-starter-data-jdbc-test")
testImplementation("org.springframework.boot:spring-boot-testcontainers")
testImplementation("org.testcontainers:junit-jupiter")
testRuntimeOnly("org.junit.platform:junit-platform-launcher")
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package org.framefork.typedIds.bigint.springData;

import org.framefork.typedIds.bigint.hibernate.basic.BigIntAppGeneratedExplicitMappingEntity;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.stereotype.Repository;

@Repository
public interface BigIntAppGeneratedExplicitMappingEntityRepository extends JpaRepository<BigIntAppGeneratedExplicitMappingEntity, BigIntAppGeneratedExplicitMappingEntity.Id>
{

BigIntAppGeneratedExplicitMappingEntity findByTitle(String title);

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package org.framefork.typedIds.bigint.springData;

import org.framefork.typedIds.bigint.hibernate.basic.BigIntDbAutoGeneratedExplicitMappingEntity;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.stereotype.Repository;

@Repository
public interface BigIntDbAutoGeneratedExplicitMappingEntityRepository extends JpaRepository<BigIntDbAutoGeneratedExplicitMappingEntity, BigIntDbAutoGeneratedExplicitMappingEntity.Id>
{

BigIntDbAutoGeneratedExplicitMappingEntity findByTitle(String title);

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package org.framefork.typedIds.bigint.springData;

import org.framefork.typedIds.bigint.hibernate.basic.BigIntDbIdentityGeneratedExplicitMappingEntity;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.stereotype.Repository;

@Repository
public interface BigIntDbIdentityGeneratedExplicitMappingEntityRepository extends JpaRepository<BigIntDbIdentityGeneratedExplicitMappingEntity, BigIntDbIdentityGeneratedExplicitMappingEntity.Id>
{

BigIntDbIdentityGeneratedExplicitMappingEntity findByTitle(String title);

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package org.framefork.typedIds.bigint.springData;

import org.framefork.typedIds.bigint.hibernate.basic.BigIntDbSequenceGeneratedExplicitMappingEntity;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.stereotype.Repository;

@Repository
public interface BigIntDbSequenceGeneratedExplicitMappingEntityRepository extends JpaRepository<BigIntDbSequenceGeneratedExplicitMappingEntity, BigIntDbSequenceGeneratedExplicitMappingEntity.Id>
{

BigIntDbSequenceGeneratedExplicitMappingEntity findByTitle(String title);

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,193 @@
package org.framefork.typedIds.bigint.springData;

import jakarta.persistence.EntityManager;
import jakarta.persistence.Tuple;
import org.framefork.typedIds.bigint.hibernate.basic.BigIntAppGeneratedExplicitMappingEntity;
import org.framefork.typedIds.bigint.hibernate.basic.BigIntDbAutoGeneratedExplicitMappingEntity;
import org.framefork.typedIds.bigint.hibernate.basic.BigIntDbIdentityGeneratedExplicitMappingEntity;
import org.framefork.typedIds.bigint.hibernate.basic.BigIntDbSequenceGeneratedExplicitMappingEntity;
import org.framefork.typedIds.springData.AbstractSpringDataMySQLTest;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;

import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Objects;

import static org.assertj.core.api.Assertions.assertThat;

@Transactional
class ObjectBigIntIdTypeIndexedSpringDataJpaMySQLTest extends AbstractSpringDataMySQLTest
{

@Autowired
private EntityManager entityManager;

@Autowired
private BigIntAppGeneratedExplicitMappingEntityRepository appGeneratedRepository;

@Autowired
private BigIntDbAutoGeneratedExplicitMappingEntityRepository dbAutoGeneratedRepository;

@Autowired
private BigIntDbIdentityGeneratedExplicitMappingEntityRepository dbIdentityGeneratedRepository;

@Autowired
private BigIntDbSequenceGeneratedExplicitMappingEntityRepository dbSequenceGeneratedRepository;

@Test
public void testSchema()
{
var table1 = getIdColumnInfo(entityManager, BigIntAppGeneratedExplicitMappingEntity.TABLE_NAME);
assertThat(table1.get("data_type", String.class)).isEqualToIgnoringCase("bigint");
assertThat(table1.get("column_type", String.class)).isEqualToIgnoringCase("bigint");

var table2 = getIdColumnInfo(entityManager, BigIntDbAutoGeneratedExplicitMappingEntity.TABLE_NAME);
assertThat(table2.get("data_type", String.class)).isEqualToIgnoringCase("bigint");
assertThat(table2.get("column_type", String.class)).isEqualToIgnoringCase("bigint");

var table3 = getIdColumnInfo(entityManager, BigIntDbIdentityGeneratedExplicitMappingEntity.TABLE_NAME);
assertThat(table3.get("data_type", String.class)).isEqualToIgnoringCase("bigint");
assertThat(table3.get("column_type", String.class)).isEqualToIgnoringCase("bigint");

var table4 = getIdColumnInfo(entityManager, BigIntDbSequenceGeneratedExplicitMappingEntity.TABLE_NAME);
assertThat(table4.get("data_type", String.class)).isEqualToIgnoringCase("bigint");
assertThat(table4.get("column_type", String.class)).isEqualToIgnoringCase("bigint");
}

private static Tuple getIdColumnInfo(final EntityManager em, final String tableName)
{
return (Tuple) em.createNativeQuery("SELECT * FROM INFORMATION_SCHEMA.COLUMNS WHERE table_name = :table_name AND column_name = :column_name", Tuple.class)
.setParameter("table_name", tableName)
.setParameter("column_name", "id")
.getSingleResult();
}

@Test
public void testUsageAppGenerated()
{
Map<String, BigIntAppGeneratedExplicitMappingEntity.Id> idsByTitle = new HashMap<>();

var articles = List.of(
new BigIntAppGeneratedExplicitMappingEntity("one"),
new BigIntAppGeneratedExplicitMappingEntity("two"),
new BigIntAppGeneratedExplicitMappingEntity("three")
);

appGeneratedRepository.saveAll(articles);
flushAndClear();

articles.forEach(article -> idsByTitle.put(article.getTitle(), article.getId()));

var idOfTwo = Objects.requireNonNull(idsByTitle.get("two"), "id must not be null");

var article = appGeneratedRepository.findById(idOfTwo).orElseThrow();
Assertions.assertEquals("two", article.getTitle());

var articleByTitle = appGeneratedRepository.findByTitle("two");
Assertions.assertEquals(idOfTwo, articleByTitle.getId());

var allArticles = appGeneratedRepository.findAllById(idsByTitle.values());
Assertions.assertEquals(3, allArticles.size());
}

@Test
public void testUsageDbAutoGenerated()
{
Map<String, BigIntDbAutoGeneratedExplicitMappingEntity.Id> idsByTitle = new HashMap<>();

var articles = List.of(
new BigIntDbAutoGeneratedExplicitMappingEntity("one"),
new BigIntDbAutoGeneratedExplicitMappingEntity("two"),
new BigIntDbAutoGeneratedExplicitMappingEntity("three")
);

articles.forEach(article -> Assertions.assertNull(article.getId()));

dbAutoGeneratedRepository.saveAll(articles);
flushAndClear();

articles.forEach(article -> Assertions.assertNotNull(article.getId()));

articles.forEach(article -> idsByTitle.put(article.getTitle(), article.getId()));

var idOfTwo = Objects.requireNonNull(idsByTitle.get("two"), "id must not be null");

var article = dbAutoGeneratedRepository.findById(idOfTwo).orElseThrow();
Assertions.assertEquals("two", article.getTitle());

var articleByTitle = dbAutoGeneratedRepository.findByTitle("two");
Assertions.assertEquals(idOfTwo, articleByTitle.getId());

var allArticles = dbAutoGeneratedRepository.findAllById(idsByTitle.values());
Assertions.assertEquals(3, allArticles.size());
}

@Test
public void testUsageDbIdentityGenerated()
{
Map<String, BigIntDbIdentityGeneratedExplicitMappingEntity.Id> idsByTitle = new HashMap<>();

var articles = List.of(
new BigIntDbIdentityGeneratedExplicitMappingEntity("one"),
new BigIntDbIdentityGeneratedExplicitMappingEntity("two"),
new BigIntDbIdentityGeneratedExplicitMappingEntity("three")
);

articles.forEach(article -> Assertions.assertNull(article.getId()));

dbIdentityGeneratedRepository.saveAll(articles);
flushAndClear();

articles.forEach(article -> Assertions.assertNotNull(article.getId()));

articles.forEach(article -> idsByTitle.put(article.getTitle(), article.getId()));

var idOfTwo = Objects.requireNonNull(idsByTitle.get("two"), "id must not be null");

var article = dbIdentityGeneratedRepository.findById(idOfTwo).orElseThrow();
Assertions.assertEquals("two", article.getTitle());

var articleByTitle = dbIdentityGeneratedRepository.findByTitle("two");
Assertions.assertEquals(idOfTwo, articleByTitle.getId());

var allArticles = dbIdentityGeneratedRepository.findAllById(idsByTitle.values());
Assertions.assertEquals(3, allArticles.size());
}

@Test
public void testUsageDbSequenceGenerated()
{
Map<String, BigIntDbSequenceGeneratedExplicitMappingEntity.Id> idsByTitle = new HashMap<>();

var articles = List.of(
new BigIntDbSequenceGeneratedExplicitMappingEntity("one"),
new BigIntDbSequenceGeneratedExplicitMappingEntity("two"),
new BigIntDbSequenceGeneratedExplicitMappingEntity("three")
);

articles.forEach(article -> Assertions.assertNull(article.getId()));

dbSequenceGeneratedRepository.saveAll(articles);
flushAndClear();

articles.forEach(article -> Assertions.assertNotNull(article.getId()));

articles.forEach(article -> idsByTitle.put(article.getTitle(), article.getId()));

var idOfTwo = Objects.requireNonNull(idsByTitle.get("two"), "id must not be null");

var article = dbSequenceGeneratedRepository.findById(idOfTwo).orElseThrow();
Assertions.assertEquals("two", article.getTitle());

var articleByTitle = dbSequenceGeneratedRepository.findByTitle("two");
Assertions.assertEquals(idOfTwo, articleByTitle.getId());

var allArticles = dbSequenceGeneratedRepository.findAllById(idsByTitle.values());
Assertions.assertEquals(3, allArticles.size());
}

}
Loading