Skip to content

Commit cea5e12

Browse files
committed
add typed-ids-hibernate-61 with support for Hibernate 6.1
[Closes #9]
1 parent 44752fa commit cea5e12

File tree

40 files changed

+3602
-0
lines changed

40 files changed

+3602
-0
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ For seamless type support in Hibernate ORM, you should pick one of the following
1616
|-------------------------------|----------------------------------------------------------------------------------------------------------------------|
1717
| 6.6, 6.5, 6.4, and 6.3 | [org.framefork:typed-ids-hibernate-63](https://central.sonatype.com/artifact/org.framefork/typed-ids-hibernate-63) |
1818
| 6.2 | [org.framefork:typed-ids-hibernate-62](https://central.sonatype.com/artifact/org.framefork/typed-ids-hibernate-62) |
19+
| 6.1 | [org.framefork:typed-ids-hibernate-61](https://central.sonatype.com/artifact/org.framefork/typed-ids-hibernate-61) |
1920

2021
Find the latest version in this project's GitHub releases or on Maven Central.
2122

gradle/libs.versions.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,13 @@ datasource-proxy = { module = "net.ttddyy:datasource-proxy", version = "1.10" }
2626
postgresql = { module = "org.postgresql:postgresql", version = "42.7.4" }
2727
mysql = { module = "com.mysql:mysql-connector-j", version = "8.3.0" }
2828
logback-classic = { module = "ch.qos.logback:logback-classic", version = "1.5.12" }
29+
hibernate-orm-v61 = { group = "org.hibernate.orm", name = "hibernate-core", version = "6.1.7.Final" }
2930
hibernate-orm-v62 = { group = "org.hibernate.orm", name = "hibernate-core", version = "6.2.36.Final" }
3031
hibernate-orm-v63 = { group = "org.hibernate.orm", name = "hibernate-core", version = "6.3.2.Final" }
3132
hibernate-orm-v64 = { group = "org.hibernate.orm", name = "hibernate-core", version = "6.4.10.Final" }
3233
hibernate-orm-v65 = { group = "org.hibernate.orm", name = "hibernate-core", version = "6.5.3.Final" }
3334
hibernate-orm-v66 = { group = "org.hibernate.orm", name = "hibernate-core", version = "6.6.12.Final" }
35+
hypersistence-utils-hibernate61 = { group = "io.hypersistence", name = "hypersistence-utils-hibernate-60", version = "3.9.4" }
3436
hypersistence-utils-hibernate62 = { group = "io.hypersistence", name = "hypersistence-utils-hibernate-62", version = "3.9.4" }
3537
hypersistence-utils-hibernate63 = { group = "io.hypersistence", name = "hypersistence-utils-hibernate-63", version = "3.9.9" }
3638
hypersistence-tsid = { module = "io.hypersistence:hypersistence-tsid", version = "2.1.4" }
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
plugins {
2+
id("framefork.java")
3+
}
4+
5+
dependencies {
6+
api(project(":typed-ids-testing"))
7+
8+
api(libs.hibernate.orm.v61)
9+
api(libs.hypersistence.utils.hibernate61)
10+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
package org.framefork.typedIds.hibernate.tests;
2+
3+
import io.hypersistence.utils.test.providers.DataSourceProvider;
4+
import org.testcontainers.containers.JdbcDatabaseContainer;
5+
6+
import javax.sql.DataSource;
7+
import java.util.Objects;
8+
import java.util.concurrent.atomic.AtomicReference;
9+
10+
public abstract class AbstractContainerDataSourceProvider implements DataSourceProvider
11+
{
12+
13+
private final AtomicReference<JdbcDatabaseContainer<?>> container = new AtomicReference<>();
14+
15+
public JdbcDatabaseContainer<?> getContainer()
16+
{
17+
if (container.get() == null) {
18+
synchronized (container) {
19+
if (container.get() == null) {
20+
container.set(initContainer());
21+
}
22+
}
23+
}
24+
25+
return Objects.requireNonNull(container.get(), "database container must not be null");
26+
}
27+
28+
private JdbcDatabaseContainer<?> initContainer()
29+
{
30+
var newContainer = (JdbcDatabaseContainer<?>) newJdbcDatabaseContainer();
31+
32+
if (supportsDatabaseName()) {
33+
newContainer.withDatabaseName(databaseName());
34+
}
35+
if (supportsCredentials()) {
36+
newContainer.withUsername(username()).withPassword(password());
37+
}
38+
39+
newContainer.withReuse(true).start();
40+
41+
return newContainer;
42+
}
43+
44+
@Override
45+
public final DataSource dataSource()
46+
{
47+
getContainer(); // force init
48+
return newDataSource();
49+
}
50+
51+
@Override
52+
public final String url()
53+
{
54+
return getContainer().getJdbcUrl();
55+
}
56+
57+
public String databaseName()
58+
{
59+
return "framefork";
60+
}
61+
62+
protected abstract DataSource newDataSource();
63+
64+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
package org.framefork.typedIds.hibernate.tests;
2+
3+
import io.hypersistence.utils.test.AbstractHibernateTest;
4+
import io.hypersistence.utils.test.providers.DataSourceProvider;
5+
import org.junit.jupiter.api.AfterEach;
6+
import org.junit.jupiter.api.BeforeEach;
7+
8+
public abstract class AbstractMySQLIntegrationTest extends AbstractHibernateTest
9+
{
10+
11+
@BeforeEach
12+
@Override
13+
public void init()
14+
{
15+
super.init();
16+
}
17+
18+
@AfterEach
19+
@Override
20+
public void destroy()
21+
{
22+
super.destroy();
23+
}
24+
25+
@Override
26+
protected DataSourceProvider dataSourceProvider()
27+
{
28+
return MySQLDataSourceProvider.V8;
29+
}
30+
31+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
package org.framefork.typedIds.hibernate.tests;
2+
3+
import io.hypersistence.utils.test.AbstractHibernateTest;
4+
import io.hypersistence.utils.test.providers.DataSourceProvider;
5+
import org.junit.jupiter.api.AfterEach;
6+
import org.junit.jupiter.api.BeforeEach;
7+
8+
public abstract class AbstractPostgreSQLIntegrationTest extends AbstractHibernateTest
9+
{
10+
11+
@BeforeEach
12+
@Override
13+
public void init()
14+
{
15+
super.init();
16+
}
17+
18+
@AfterEach
19+
@Override
20+
public void destroy()
21+
{
22+
super.destroy();
23+
}
24+
25+
@Override
26+
protected DataSourceProvider dataSourceProvider()
27+
{
28+
return PostgreSQLDataSourceProvider.V16;
29+
}
30+
31+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
package org.framefork.typedIds.hibernate.tests;
2+
3+
import com.mysql.cj.jdbc.MysqlDataSource;
4+
import org.hibernate.dialect.Database;
5+
import org.hibernate.dialect.MySQLDialect;
6+
import org.testcontainers.containers.JdbcDatabaseContainer;
7+
import org.testcontainers.containers.MySQLContainer;
8+
9+
import javax.sql.DataSource;
10+
import java.util.Map;
11+
12+
public final class MySQLDataSourceProvider extends AbstractContainerDataSourceProvider
13+
{
14+
15+
public static final MySQLDataSourceProvider V8 = new MySQLDataSourceProvider("8.4");
16+
17+
private final String version;
18+
19+
private MySQLDataSourceProvider(final String version)
20+
{
21+
this.version = version;
22+
}
23+
24+
@Override
25+
public Database database()
26+
{
27+
return Database.MYSQL;
28+
}
29+
30+
@Override
31+
public String hibernateDialect()
32+
{
33+
return MySQLDialect.class.getName();
34+
}
35+
36+
@Override
37+
protected DataSource newDataSource()
38+
{
39+
var dataSource = new MysqlDataSource();
40+
dataSource.setURL(url());
41+
dataSource.setUser(username());
42+
dataSource.setPassword(password());
43+
return dataSource;
44+
}
45+
46+
@Override
47+
public String username()
48+
{
49+
return "mysql";
50+
}
51+
52+
@Override
53+
public String password()
54+
{
55+
return "admin";
56+
}
57+
58+
@SuppressWarnings({"rawtypes", "unchecked"})
59+
@Override
60+
public JdbcDatabaseContainer newJdbcDatabaseContainer()
61+
{
62+
var container = new MySQLContainer("mysql:" + version);
63+
container.withTmpFs(Map.of("/var/lib/mysql", "rw"));
64+
return container;
65+
}
66+
67+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
package org.framefork.typedIds.hibernate.tests;
2+
3+
import org.hibernate.dialect.Database;
4+
import org.hibernate.dialect.PostgreSQLDialect;
5+
import org.postgresql.ds.PGSimpleDataSource;
6+
import org.testcontainers.containers.JdbcDatabaseContainer;
7+
import org.testcontainers.containers.PostgreSQLContainer;
8+
9+
import javax.sql.DataSource;
10+
import java.util.Map;
11+
12+
public final class PostgreSQLDataSourceProvider extends AbstractContainerDataSourceProvider
13+
{
14+
15+
public static final PostgreSQLDataSourceProvider V16 = new PostgreSQLDataSourceProvider("16.4");
16+
17+
private final String version;
18+
19+
private PostgreSQLDataSourceProvider(final String version)
20+
{
21+
this.version = version;
22+
}
23+
24+
@Override
25+
public Database database()
26+
{
27+
return Database.POSTGRESQL;
28+
}
29+
30+
@Override
31+
public String hibernateDialect()
32+
{
33+
return PostgreSQLDialect.class.getName();
34+
}
35+
36+
@Override
37+
protected DataSource newDataSource()
38+
{
39+
var dataSource = new PGSimpleDataSource();
40+
dataSource.setURL(url());
41+
dataSource.setUser(username());
42+
dataSource.setPassword(password());
43+
44+
return dataSource;
45+
}
46+
47+
@Override
48+
public String username()
49+
{
50+
return "postgres";
51+
}
52+
53+
@Override
54+
public String password()
55+
{
56+
return "admin";
57+
}
58+
59+
@SuppressWarnings({"rawtypes", "unchecked"})
60+
@Override
61+
public JdbcDatabaseContainer newJdbcDatabaseContainer()
62+
{
63+
var container = new PostgreSQLContainer("postgres:" + version);
64+
container.withCommand("postgres", "-c", "fsync=off", "-c", "random_page_cost=1.0", "-c", "synchronous_commit=off", "-c", "full_page_writes=off");
65+
container.withEnv(Map.of("PGDATA", "/var/lib/postgresql/data"));
66+
container.withTmpFs(Map.of("/var/lib/postgresql/data", "rw"));
67+
return container;
68+
}
69+
70+
}
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
plugins {
2+
id("framefork.java-public")
3+
}
4+
5+
dependencies {
6+
api(project(":typed-ids"))
7+
api(libs.hibernate.orm.v61)
8+
api(libs.hypersistence.utils.hibernate61)
9+
compileOnly("org.jboss:jandex") {
10+
version {
11+
require(
12+
configurations.getByName("runtimeClasspath").resolvedConfiguration
13+
.resolvedArtifacts.find { it.moduleVersion.id.toString().contains("org.jboss:jandex") }
14+
?.moduleVersion?.id?.version ?: "unknown"
15+
)
16+
}
17+
}
18+
19+
compileOnly(libs.jetbrains.annotations)
20+
21+
compileOnly(libs.autoService.annotations)
22+
annotationProcessor(libs.autoService.processor)
23+
24+
testImplementation(project(":typed-ids-hibernate-61-testing"))
25+
testRuntimeOnly("org.junit.platform:junit-platform-launcher")
26+
}
27+
28+
project.description = "TypeIds seamless integration into Hibernate ORMs type system"

0 commit comments

Comments
 (0)