Skip to content
Open
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
3 changes: 1 addition & 2 deletions java/buildconf/build-props.xml
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,7 @@

<property name="hibernatedeps"
value="${jpa} ${hibernate-core} ${hibernate-models} slf4j/api ${byte-buddy} jboss-logging ${jcache}
${ehcache} classmate/classmate hypersistence-utils/hypersistence-utils-hibernate-71 jackson-databind
jackson-core jackson-annotations"/>
${ehcache} classmate/classmate jackson-databind jackson-core jackson-annotations"/>

<property name="c3p0" value="mchange-commons/mchange-commons-java c3p0"/>

Expand Down
15 changes: 7 additions & 8 deletions java/buildconf/ivy/ivy-suse.xml
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@
<dependency org="suse" name="hibernate-models" rev="1.0.1" />
<dependency org="suse" name="hibernate-core" rev="7.1.6" />
<dependency org="suse" name="hibernate-jcache" rev="7.1.6" />
<dependency org="suse" name="hypersistence-utils-hibernate-71" rev="3.11.0" />
<dependency org="suse" name="httpasyncclient" rev="4.1.4" />
<dependency org="suse" name="httpclient" rev="4.5.14" />
<dependency org="suse" name="httpcore" rev="4.4.14" />
Expand All @@ -60,13 +59,13 @@
<dependency org="suse" name="jsch" rev="0.2.22" />
<dependency org="suse" name="jctools-core" rev="4.0.5" />
<dependency org="suse" name="mchange-commons-java" rev="0.2.20" />
<dependency org="suse" name="netty-buffer" rev="4.1.130" />
<dependency org="suse" name="netty-codec" rev="4.1.130" />
<dependency org="suse" name="netty-common" rev="4.1.130" />
<dependency org="suse" name="netty-handler" rev="4.1.130" />
<dependency org="suse" name="netty-resolver" rev="4.1.130" />
<dependency org="suse" name="netty-transport" rev="4.1.130" />
<dependency org="suse" name="netty-transport-native-unix-common" rev="4.1.130" />
<dependency org="suse" name="netty-buffer" rev="4.1.132" />
<dependency org="suse" name="netty-codec" rev="4.1.132" />
<dependency org="suse" name="netty-common" rev="4.1.132" />
<dependency org="suse" name="netty-handler" rev="4.1.132" />
<dependency org="suse" name="netty-resolver" rev="4.1.132" />
<dependency org="suse" name="netty-transport" rev="4.1.132" />
<dependency org="suse" name="netty-transport-native-unix-common" rev="4.1.132" />
<dependency org="suse" name="oro" rev="2.0.8" />
<dependency org="suse" name="pgjdbc-ng" rev="0.8.7" />
<dependency org="suse" name="postgresql" rev="42.2.25" />
Expand Down
3 changes: 0 additions & 3 deletions java/buildconf/ivy/obs-maven-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -92,9 +92,6 @@ artifacts:
package: hibernate-c3p0
jar: hibernate-c3p0
repository: Uyuni
- artifact: hypersistence-utils-hibernate-71
package: hypersistence-utils-hibernate-71
repository: Uyuni
- artifact: jackson-annotations
repository: Leap_sle
- artifact: jackson-core
Expand Down
6 changes: 1 addition & 5 deletions java/core/pom.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<!--
~ Copyright (c) 2025 SUSE LLC
~ Copyright (c) 2025-2026 SUSE LLC
~
~ This software is licensed to you under the GNU General Public License,
~ version 2 (GPLv2). There is NO WARRANTY for this software, express or
Expand Down Expand Up @@ -117,10 +117,6 @@
<groupId>org.hibernate.orm</groupId>
<artifactId>hibernate-jcache</artifactId>
</dependency>
<dependency>
<groupId>io.hypersistence</groupId>
<artifactId>hypersistence-utils-hibernate-71</artifactId>
</dependency>
<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpasyncclient</artifactId>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2025 SUSE LLC
* Copyright (c) 2025--2026 SUSE LLC
* Copyright (c) 2009--2013 Red Hat, Inc.
*
* This software is licensed to you under the GNU General Public License,
Expand All @@ -19,12 +19,12 @@

import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.hibernate.annotations.Type;
import org.hibernate.annotations.JdbcTypeCode;
import org.hibernate.type.SqlTypes;

import java.util.Map;
import java.util.TreeMap;

import io.hypersistence.utils.hibernate.type.json.JsonType;
import jakarta.persistence.Column;
import jakarta.persistence.Entity;
import jakarta.persistence.FetchType;
Expand Down Expand Up @@ -95,7 +95,7 @@ public class CPU extends BaseDomainHelper {
* JSONB, it is mapped here as a String due to limitations in XML mapping for
* JSON types.
*/
@Type(JsonType.class)
@JdbcTypeCode(SqlTypes.JSON)
@Column(name = "arch_specs", columnDefinition = "jsonb")
private Map<String, Object> archSpecs = new TreeMap<>();

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2021--2025 SUSE LLC
* Copyright (c) 2021--2026 SUSE LLC
*
* This software is licensed to you under the GNU General Public License,
* version 2 (GPLv2). There is NO WARRANTY for this software, express or
Expand All @@ -15,15 +15,15 @@
import com.redhat.rhn.domain.Identifiable;
import com.redhat.rhn.domain.org.Org;

import org.hibernate.annotations.Type;
import org.hibernate.annotations.JdbcTypeCode;
import org.hibernate.type.SqlTypes;

import java.io.Serializable;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.TreeMap;

import io.hypersistence.utils.hibernate.type.json.JsonType;
import jakarta.persistence.Column;
import jakarta.persistence.Entity;
import jakarta.persistence.GeneratedValue;
Expand Down Expand Up @@ -70,7 +70,7 @@ public class Pillar implements Identifiable, Serializable {
@Column(name = "category")
private String category;

@Type(JsonType.class)
@JdbcTypeCode(SqlTypes.JSON)
@Column(columnDefinition = "jsonb")
private Map<String, Object> pillar = new TreeMap<>();

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2024--2025 SUSE LLC
* Copyright (c) 2024--2026 SUSE LLC
*
* This software is licensed to you under the GNU General Public License,
* version 2 (GPLv2). There is NO WARRANTY for this software, express or
Expand All @@ -16,15 +16,15 @@

import org.apache.commons.lang3.builder.EqualsBuilder;
import org.apache.commons.lang3.builder.HashCodeBuilder;
import org.hibernate.annotations.Type;
import org.hibernate.annotations.JdbcTypeCode;
import org.hibernate.type.SqlTypes;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.TreeMap;

import io.hypersistence.utils.hibernate.type.json.JsonType;
import jakarta.persistence.Column;
import jakarta.persistence.Convert;
import jakarta.persistence.Entity;
Expand Down Expand Up @@ -95,13 +95,13 @@ public CoCoAttestationStatus getStatus() {
return status;
}

@Type(JsonType.class)
@JdbcTypeCode(SqlTypes.JSON)
@Column(columnDefinition = "jsonb", name = "in_data")
public Map<String, Object> getInData() {
return inData;
}

@Type(JsonType.class)
@JdbcTypeCode(SqlTypes.JSON)
@Column(columnDefinition = "jsonb", name = "out_data")
public Map<String, Object> getOutData() {
return outData;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2026 SUSE LCC
* Copyright (c) 2026 SUSE LLC
*
* This software is licensed to you under the GNU General Public License,
* version 2 (GPLv2). There is NO WARRANTY for this software, express or
Expand All @@ -13,16 +13,23 @@
import com.redhat.rhn.domain.TestFactory;
import com.redhat.rhn.testing.RhnBaseTestCase;

import org.apache.commons.lang3.StringUtils;
import org.apache.commons.lang3.Strings;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.BeforeEach;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.sql.Connection;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.Objects;
import java.util.stream.Collectors;

abstract class HibernateBaseTest extends RhnBaseTestCase {
private static final Logger LOG = LogManager.getLogger(HibernateBaseTest.class);
Expand Down Expand Up @@ -51,67 +58,15 @@ public void tearDown() {
@BeforeAll
public static void oneTimeSetup() {
TestFactory.getSession().doWork(connection -> {
Statement statement = null;
try {
statement = connection.createStatement();

// Always clean up and recreate to ensure schema is current
forceQuery(connection, "drop table if exists persist_test cascade");
forceQuery(connection, "drop sequence if exists persist_sequence");

statement.execute("create sequence persist_sequence");
statement.execute("""
create table persist_test(
foobar VarChar(32),
test_column VarChar(5),
pin numeric,
hidden VarChar(32),
id numeric constraint persist_test_pk primary key,
parent_id numeric,
created timestamp with time zone,
modified timestamp with time zone
)""");
statement.execute("insert into persist_test (foobar, id) " +
"values ('Blarg', nextval('persist_sequence'))");
statement.execute("insert into persist_test (foobar, id) " +
"values ('duplicate', nextval('persist_sequence'))");
statement.execute("insert into persist_test (foobar, id) " +
"values ('duplicate', nextval('persist_sequence'))");
statement.execute("insert into persist_test (foobar, hidden, id) " +
"values ('duplicate', 'xxxxx', nextval('persist_sequence'))");
statement.execute("insert into persist_test (foobar, id) " +
"values ('vito', nextval('persist_sequence'))");
statement.execute("insert into persist_test (foobar, id, parent_id) " +
"values ('sonny', nextval('persist_sequence'), " +
"(select id from persist_test where foobar='vito'))");
statement.execute("insert into persist_test (foobar, id, parent_id) " +
"values ('fredo', nextval('persist_sequence'), " +
"(select id from persist_test where foobar='vito'))");
statement.execute("insert into persist_test (foobar, id, parent_id) " +
"values ('michael', nextval('persist_sequence'), " +
"(select id from persist_test where foobar='vito'))");

connection.commit();
}
finally {
HibernateHelper.cleanupDB(statement);
}
executeSqlScript(connection, "create_test_db.sql");
connection.commit();
});
}

@AfterAll
public static void oneTimeTeardown() {
TestFactory.getSession().doWork(connection -> {
Statement statement = null;
try {
statement = connection.createStatement();
// Couldn't select 1, so the table didn't exist, create it
forceQuery(connection, "drop sequence persist_sequence");
forceQuery(connection, "drop table persist_test");
}
finally {
HibernateHelper.cleanupDB(statement);
}
executeSqlScript(connection, "drop_test_db.sql");
});
}

Expand All @@ -125,4 +80,33 @@ private static void forceQuery(Connection c, String query) {
}
}

private static void executeSqlScript(Connection c, String scriptPath) {
try (var is = HibernateBaseTest.class.getResourceAsStream(scriptPath);
var reader = new BufferedReader(new InputStreamReader(Objects.requireNonNull(is)))) {

// Read the file and split by semicolon
String[] queries = reader.lines()
.filter(line -> StringUtils.isNotEmpty(line) && !Strings.CI.startsWithAny(line, "--", "//"))
.collect(Collectors.joining("\n"))
.split(";");

try (Statement statement = c.createStatement()) {
for (String query : queries) {
if (!query.trim().isEmpty()) {
statement.addBatch(query);
}
}
statement.executeBatch();
}
}
catch (IOException ex) {
LOG.error("Unable to read SQL script {}", scriptPath, ex);
throw new RuntimeException("Unable to read SQL script " + scriptPath, ex);
}
catch (SQLException ex) {
LOG.error("Unable to execute SQL script {}", scriptPath, ex);
throw new RuntimeException("Unable to execute SQL script " + scriptPath, ex);
}
}

}
Loading
Loading