Skip to content

Commit

Permalink
Merge pull request #24663 from gsmet/h2-upgrade
Browse files Browse the repository at this point in the history
Upgrade H2 to 2.1.210
  • Loading branch information
Sanne authored Apr 6, 2022
2 parents 420eecd + 5a28812 commit 5296576
Show file tree
Hide file tree
Showing 26 changed files with 92 additions and 73 deletions.
2 changes: 1 addition & 1 deletion bom/application/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@
<httpasync.version>4.1.5</httpasync.version>
<cronutils.version>9.1.6</cronutils.version>
<quartz.version>2.3.2</quartz.version>
<h2.version>1.4.197</h2.version> <!-- keep 1.4.197 as newer versions have severe regressions -->
<h2.version>2.1.210</h2.version>
<postgresql-jdbc.version>42.3.3</postgresql-jdbc.version>
<mariadb-jdbc.version>3.0.4</mariadb-jdbc.version>
<mysql-jdbc.version>8.0.28</mysql-jdbc.version>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@ public RunningDevServicesDatasource startDatabase(Optional<String> username, Opt
OptionalInt port, LaunchMode launchMode, Optional<Duration> startupTimeout) {
try {
final Server tcpServer = Server.createTcpServer("-tcpPort",
port.isPresent() ? String.valueOf(port.getAsInt()) : "0");
port.isPresent() ? String.valueOf(port.getAsInt()) : "0",
"-ifNotExists");
tcpServer.start();

StringBuilder additionalArgs = new StringBuilder();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
import javax.inject.Inject;

import org.flywaydb.core.Flyway;
import org.h2.jdbc.JdbcSQLException;
import org.h2.jdbc.JdbcSQLSyntaxErrorException;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.RegisterExtension;
Expand Down Expand Up @@ -40,7 +40,7 @@ public void testFlywayConfigInjection() throws SQLException {
try (Connection connection = defaultDataSource.getConnection(); Statement stat = connection.createStatement()) {
try (ResultSet executeQuery = stat.executeQuery("select * from fake_existing_tbl")) {
fail("fake_existing_tbl should not exist");
} catch (JdbcSQLException e) {
} catch (JdbcSQLSyntaxErrorException e) {
// expected fake_existing_tbl does not exist
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

import org.flywaydb.core.Flyway;
import org.flywaydb.core.api.MigrationInfo;
import org.h2.jdbc.JdbcSQLException;
import org.h2.jdbc.JdbcSQLSyntaxErrorException;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.RegisterExtension;
Expand Down Expand Up @@ -41,7 +41,7 @@ public void testFlywayConfigInjection() throws SQLException {
try (Connection connection = defaultDataSource.getConnection(); Statement stat = connection.createStatement()) {
try (ResultSet executeQuery = stat.executeQuery("select * from fake_existing_tbl")) {
fail("fake_existing_tbl should not exist");
} catch (JdbcSQLException e) {
} catch (JdbcSQLSyntaxErrorException e) {
// expected fake_existing_tbl does not exist
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
import org.flywaydb.core.api.migration.BaseJavaMigration;
import org.flywaydb.core.api.migration.Context;
import org.flywaydb.core.api.migration.JavaMigration;
import org.h2.jdbc.JdbcSQLException;
import org.h2.jdbc.JdbcSQLSyntaxErrorException;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.RegisterExtension;
Expand Down Expand Up @@ -45,7 +45,7 @@ public void testFlywayConfigInjection() throws SQLException {
try (Connection connection = defaultDataSource.getConnection(); Statement stat = connection.createStatement()) {
try (ResultSet executeQuery = stat.executeQuery("select * from fake_existing_tbl")) {
fail("fake_existing_tbl should not exist. Clean was run at start");
} catch (JdbcSQLException e) {
} catch (JdbcSQLSyntaxErrorException e) {
// expected fake_existing_tbl does not exist
}
try (ResultSet countQuery = stat.executeQuery("select count(1) from quarked_flyway")) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public FlywayH2TestCustomizer withInitSqlFile(String initSqlFile) {

void startH2() {
try {
tcpServer = Server.createTcpServer("-tcpPort", String.valueOf(port));
tcpServer = Server.createTcpServer("-tcpPort", String.valueOf(port), "-ifNotExists");
tcpServer.start();
System.out.println("[INFO] Custom H2 database started in TCP server mode; server status: " + tcpServer.getStatus());
if (initSqlFile != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,10 @@
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.Table;

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

private long id;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,10 @@
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.Table;

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

private long id;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import java.util.List;

import javax.inject.Inject;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.EntityManager;
import javax.persistence.GeneratedValue;
Expand Down Expand Up @@ -157,6 +158,7 @@ public static class ContainedEntity {
@GeneratedValue
public long id;

@Column(name = "value_")
public String value;

@OneToOne
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import io.quarkus.deployment.annotations.BuildStep;
import io.quarkus.deployment.builditem.FeatureBuildItem;
import io.quarkus.deployment.builditem.SslNativeConfigBuildItem;
import io.quarkus.deployment.builditem.nativeimage.RuntimeInitializedClassBuildItem;
import io.quarkus.jdbc.h2.runtime.H2AgroalConnectionConfigurer;

public class JDBCH2Processor {
Expand Down Expand Up @@ -49,4 +50,9 @@ void configureAgroalConnection(BuildProducer<AdditionalBeanBuildItem> additional
void registerDefaultDbType(BuildProducer<DefaultDataSourceDbKindBuildItem> dbKind) {
dbKind.produce(new DefaultDataSourceDbKindBuildItem(DatabaseKind.H2));
}

@BuildStep
void runtimeInitializedClasses(BuildProducer<RuntimeInitializedClassBuildItem> runtimeInitializedClasses) {
runtimeInitializedClasses.produce(new RuntimeInitializedClassBuildItem("org.h2.store.fs.niomem.FileNioMemData"));
}
}
2 changes: 1 addition & 1 deletion extensions/jdbc/jdbc-h2/runtime/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
<dependency>
<groupId>org.locationtech.jts</groupId>
<artifactId>jts-core</artifactId>
<version>1.15.0</version>
<version>1.17.0</version>
<!--
TODO: Make this an optional dependency?
Graal compiler not happy with broken classpaths
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -11,18 +11,13 @@
public final class Engine {

@Substitute
public static Engine getInstance() {
return new Engine();
}

@Substitute
public Session createSession(ConnectionInfo ci) {
public static Session createSession(ConnectionInfo ci) {
throw new UnsupportedOperationException(
"H2 database compiled into a native-image is only functional as a client: can't create an Embedded Database Session");
}

@Substitute
void close(String name) {
static void close(String name) {
//no-op
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@
import com.oracle.svm.core.annotate.TargetClass;

/**
* The org.h2.engine.Session represents the "Embedded Database" in H2.
* The org.h2.engine.SessionLocal represents the "Embedded Database" in H2.
* We remove this explicitly as it pulls in various things we can't support;
* rather than address them individually it's simpler to make sure this
* Session doesn't get included by mistake: that will produce errors
* that are easier to manage.
*/
@TargetClass(className = "org.h2.engine.Session")
@TargetClass(className = "org.h2.engine.SessionLocal")
@Delete
public final class SessionDisable {
public final class SessionLocalDisable {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package io.quarkus.jdbc.h2.runtime.graal;

import org.h2.engine.ConnectionInfo;
import org.h2.engine.Session;

import com.oracle.svm.core.annotate.Alias;
import com.oracle.svm.core.annotate.Substitute;
import com.oracle.svm.core.annotate.TargetClass;

@TargetClass(className = "org.h2.engine.SessionRemote")
public final class SessionRemote {

@Alias
private ConnectionInfo connectionInfo;

/**
* Even if in SessionRemote, this method originally can instantiate a local engine.
* We don't want that as we don't support a local engine.
*/
@Substitute
public Session connectEmbeddedOrServer(boolean openNew) {
ConnectionInfo ci = connectionInfo;
if (ci.isRemote()) {
connectServer(ci);
return (Session) (Object) this;
}

throw new UnsupportedOperationException(
"H2 database compiled into a native-image is only functional as a client: can't create an Embedded Database Session");
}

@Alias
private void connectServer(ConnectionInfo ci) {
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
package io.quarkus.liquibase.test;

import static org.junit.jupiter.api.Assertions.*;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.fail;

import java.sql.Connection;
import java.sql.ResultSet;
Expand All @@ -9,7 +12,7 @@

import javax.inject.Inject;

import org.h2.jdbc.JdbcSQLException;
import org.h2.jdbc.JdbcSQLSyntaxErrorException;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.RegisterExtension;
Expand Down Expand Up @@ -42,7 +45,7 @@ public void testLiquibaseConfigInjection() throws Exception {
try (ResultSet executeQuery = stat
.executeQuery("select * from fake_existing_tbl")) {
fail("fake_existing_tbl should not exist");
} catch (JdbcSQLException e) {
} catch (JdbcSQLSyntaxErrorException e) {
// expected fake_existing_tbl does not exist
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
package io.quarkus.liquibase.test;

import static org.junit.jupiter.api.Assertions.*;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.junit.jupiter.api.Assertions.fail;

import java.sql.Connection;
import java.sql.ResultSet;
Expand All @@ -10,7 +12,7 @@

import javax.inject.Inject;

import org.h2.jdbc.JdbcSQLException;
import org.h2.jdbc.JdbcSQLSyntaxErrorException;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.RegisterExtension;
Expand Down Expand Up @@ -43,7 +45,7 @@ public void testLiquibaseConfigInjection() throws Exception {
try (ResultSet executeQuery = stat
.executeQuery("select * from fake_existing_tbl")) {
fail("fake_existing_tbl should not exist");
} catch (JdbcSQLException e) {
} catch (JdbcSQLSyntaxErrorException e) {
// expected fake_existing_tbl does not exist
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import java.util.TimeZone;
import java.util.UUID;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
Expand All @@ -24,6 +25,7 @@ public class BasicTypeData {
private TimeZone timeZone;
private java.net.URL url;
private Class clazz;
@Column(length = 16)
private java.util.UUID uuid;
private Duration duration;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,10 @@
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.OneToMany;
import javax.persistence.Table;

@Entity
@Table(name = "User_")
@NamedQuery(name = "User.getUserByFullNameUsingNamedQuery", query = "select u from User u where u.fullName=:name")
@NamedQueries(@NamedQuery(name = "User.getUserByFullNameUsingNamedQueries", query = "select u from User u where u.fullName=:name"))
public class User {
Expand Down
Original file line number Diff line number Diff line change
@@ -1 +1 @@
INSERT INTO user(userid, fullname, logincounter, active) VALUES ('JOHN', 'John Doe', 0, true);
INSERT INTO user_(userid, fullname, logincounter, active) VALUES ('JOHN', 'John Doe', 0, true);
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ class TestEndpointRunner {
}
con.close()

Assertions.assertEquals("VARCHAR", schema["PERSON2"]?.get("STATUS"), schema.toString())
Assertions.assertEquals("CHARACTER VARYING", schema["PERSON2"]?.get("STATUS"), schema.toString())

endpoint.testModelDao()
endpoint.testModel()
Expand Down
4 changes: 4 additions & 0 deletions integration-tests/main/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
<datasource.username></datasource.username>
<datasource.password></datasource.password>

<hibernate-orm.dialect>org.hibernate.dialect.H2Dialect</hibernate-orm.dialect>

<!-- do not update this dependency, it is only used for testing -->
<webjar.jquery-ui.version>1.13.0</webjar.jquery-ui.version>
</properties>
Expand Down Expand Up @@ -526,6 +528,8 @@
<datasource.url>${postgres.url}</datasource.url>
<datasource.username>hibernate_orm_test</datasource.username>
<datasource.password>hibernate_orm_test</datasource.password>

<hibernate-orm.dialect>org.hibernate.dialect.PostgreSQL10Dialect</hibernate-orm.dialect>
</properties>
<dependencies>
<dependency>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
<property name="hibernate.archive.autodetection" value="class, hbm"/>

<!-- Connection specific -->
<property name="hibernate.dialect" value="org.hibernate.dialect.PostgreSQL95Dialect"/>
<property name="hibernate.dialect" value="${hibernate-orm.dialect}"/>

<!-- Tuning and debugging -->
<property name="hibernate.connection.pool_size" value="2"/>
Expand Down
Loading

0 comments on commit 5296576

Please sign in to comment.