Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update H2DataBase to 2.x and drop support for H2Database 1.x #19964

Merged
merged 2 commits into from
Aug 8, 2022
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 pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@
<opengauss.version>3.0.0</opengauss.version>
<mysql-connector-java.version>5.1.47</mysql-connector-java.version>
<mariadb-java-client.version>2.4.2</mariadb-java-client.version>
<h2.version>1.4.196</h2.version>
<h2.version>2.1.214</h2.version>
<mssql.version>6.1.7.jre8-preview</mssql.version>

<hikari-cp.version>3.4.2</hikari-cp.version>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -346,7 +346,7 @@ The text of each license is also included at licenses/LICENSE-[project].txt.
logback-classic 1.2.10: https://github.com/qos-ch/logback, EPL 1.0
logback-core 1.2.10: https://github.com/qos-ch/logback, EPL 1.0
mchange-commons-java 0.2.15: https://github.com/swaldman/mchange-commons-java, EPL 1.0
h2 1.4.196: https://github.com/h2database/h2database, EPL 1.0
h2 2.1.214: https://github.com/h2database/h2database, EPL 1.0

========================================================================
MIT licenses
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
*/
public final class H2SchemaMetaDataLoader implements DialectSchemaMetaDataLoader {

private static final String TABLE_META_DATA_NO_ORDER = "SELECT TABLE_CATALOG, TABLE_NAME, COLUMN_NAME, DATA_TYPE, TYPE_NAME, ORDINAL_POSITION FROM INFORMATION_SCHEMA.COLUMNS "
private static final String TABLE_META_DATA_NO_ORDER = "SELECT TABLE_CATALOG, TABLE_NAME, COLUMN_NAME, DATA_TYPE, ORDINAL_POSITION FROM INFORMATION_SCHEMA.COLUMNS "
+ "WHERE TABLE_CATALOG=? AND TABLE_SCHEMA=?";

private static final String ORDER_BY_ORDINAL_POSITION = " ORDER BY ORDINAL_POSITION";
Expand All @@ -52,17 +52,18 @@ public final class H2SchemaMetaDataLoader implements DialectSchemaMetaDataLoader

private static final String TABLE_META_DATA_SQL_IN_TABLES = TABLE_META_DATA_NO_ORDER + " AND TABLE_NAME IN (%s)" + ORDER_BY_ORDINAL_POSITION;

private static final String INDEX_META_DATA_SQL = "SELECT TABLE_CATALOG, TABLE_NAME, INDEX_NAME, COLUMN_NAME FROM INFORMATION_SCHEMA.INDEXES"
private static final String INDEX_META_DATA_SQL = "SELECT TABLE_CATALOG, TABLE_NAME, INDEX_NAME FROM INFORMATION_SCHEMA.INDEXES"
+ " WHERE TABLE_CATALOG=? AND TABLE_SCHEMA=? AND TABLE_NAME IN (%s)";

private static final String PRIMARY_KEY_META_DATA_SQL = "SELECT TABLE_NAME, COLUMN_NAME FROM INFORMATION_SCHEMA.INDEXES WHERE TABLE_CATALOG=? AND TABLE_SCHEMA=? AND PRIMARY_KEY = TRUE";
private static final String PRIMARY_KEY_META_DATA_SQL = "SELECT TABLE_NAME, INDEX_NAME FROM INFORMATION_SCHEMA.INDEXES WHERE TABLE_CATALOG=? AND TABLE_SCHEMA=?"
+ " AND INDEX_TYPE_NAME = 'PRIMARY KEY'";

private static final String PRIMARY_KEY_META_DATA_SQL_IN_TABLES = PRIMARY_KEY_META_DATA_SQL + " AND TABLE_NAME IN (%s)";

private static final String GENERATED_INFO_SQL = "SELECT C.TABLE_NAME TABLE_NAME, C.COLUMN_NAME COLUMN_NAME, COALESCE(S.IS_GENERATED, FALSE) IS_GENERATED FROM INFORMATION_SCHEMA.COLUMNS C"
+ " RIGHT JOIN INFORMATION_SCHEMA.SEQUENCES S ON C.SEQUENCE_NAME=S.SEQUENCE_NAME WHERE C.TABLE_CATALOG=? AND C.TABLE_SCHEMA=?";
private static final String GENERATED_INFO_SQL = "SELECT C.TABLE_NAME TABLE_NAME, C.COLUMN_NAME COLUMN_NAME, COALESCE(I.IS_GENERATED, FALSE) IS_GENERATED FROM INFORMATION_SCHEMA.COLUMNS C"
+ " RIGHT JOIN INFORMATION_SCHEMA.INDEXES I ON C.TABLE_NAME=I.TABLE_NAME WHERE C.TABLE_CATALOG=? AND C.TABLE_SCHEMA=?";

private static final String GENERATED_INFO_SQL_IN_TABLES = GENERATED_INFO_SQL + " AND TABLE_NAME IN (%s)";
private static final String GENERATED_INFO_SQL_IN_TABLES = GENERATED_INFO_SQL + " AND C.TABLE_NAME IN (%s)";

@Override
public Collection<SchemaMetaData> load(final DataSource dataSource, final Collection<String> tables, final String defaultSchemaName) throws SQLException {
Expand Down Expand Up @@ -104,11 +105,10 @@ private Map<String, Collection<ColumnMetaData>> loadColumnMetaDataMap(final Conn
private ColumnMetaData loadColumnMetaData(final Map<String, Integer> dataTypeMap, final ResultSet resultSet, final Collection<String> primaryKeys,
final Map<String, Boolean> tableGenerated) throws SQLException {
String columnName = resultSet.getString("COLUMN_NAME");
String typeName = resultSet.getString("TYPE_NAME");
String dataType = resultSet.getString("DATA_TYPE");
boolean primaryKey = primaryKeys.contains(columnName);
boolean generated = tableGenerated.getOrDefault(columnName, Boolean.FALSE);
// H2 database case sensitive is always true
return new ColumnMetaData(columnName, dataTypeMap.get(typeName), primaryKey, generated, true, true);
linghengqian marked this conversation as resolved.
Show resolved Hide resolved
return new ColumnMetaData(columnName, dataTypeMap.get(dataType), primaryKey, generated, false, true);
}

private String getTableMetaDataSQL(final Collection<String> tables) {
Expand Down Expand Up @@ -151,9 +151,9 @@ private Map<String, Collection<String>> loadTablePrimaryKeys(final Connection co
preparedStatement.setString(2, "PUBLIC");
try (ResultSet resultSet = preparedStatement.executeQuery()) {
while (resultSet.next()) {
String columnName = resultSet.getString("COLUMN_NAME");
String indexName = resultSet.getString("INDEX_NAME");
String tableName = resultSet.getString("TABLE_NAME");
result.computeIfAbsent(tableName, k -> new LinkedList<>()).add(columnName);
result.computeIfAbsent(tableName, k -> new LinkedList<>()).add(indexName);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,21 +48,21 @@ public void assertLoadWithoutTables() throws SQLException {
DataSource dataSource = mockDataSource();
ResultSet resultSet = mockTableMetaDataResultSet();
when(dataSource.getConnection().prepareStatement(
"SELECT TABLE_CATALOG, TABLE_NAME, COLUMN_NAME, DATA_TYPE, TYPE_NAME, ORDINAL_POSITION FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_CATALOG=? AND TABLE_SCHEMA=? "
"SELECT TABLE_CATALOG, TABLE_NAME, COLUMN_NAME, DATA_TYPE, ORDINAL_POSITION FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_CATALOG=? AND TABLE_SCHEMA=? "
+ "ORDER BY ORDINAL_POSITION")
.executeQuery()).thenReturn(resultSet);
ResultSet indexResultSet = mockIndexMetaDataResultSet();
when(dataSource.getConnection().prepareStatement(
"SELECT TABLE_CATALOG, TABLE_NAME, INDEX_NAME, COLUMN_NAME FROM INFORMATION_SCHEMA.INDEXES WHERE TABLE_CATALOG=? AND TABLE_SCHEMA=? AND TABLE_NAME IN ('tbl')")
"SELECT TABLE_CATALOG, TABLE_NAME, INDEX_NAME FROM INFORMATION_SCHEMA.INDEXES WHERE TABLE_CATALOG=? AND TABLE_SCHEMA=? AND TABLE_NAME IN ('tbl')")
.executeQuery())
.thenReturn(indexResultSet);
ResultSet primaryKeys = mockPrimaryKeysMetaDataResultSet();
when(dataSource.getConnection().prepareStatement(
"SELECT TABLE_NAME, COLUMN_NAME FROM INFORMATION_SCHEMA.INDEXES WHERE TABLE_CATALOG=? AND TABLE_SCHEMA=? AND PRIMARY_KEY = TRUE").executeQuery()).thenReturn(primaryKeys);
"SELECT TABLE_NAME, INDEX_NAME FROM INFORMATION_SCHEMA.INDEXES WHERE TABLE_CATALOG=? AND TABLE_SCHEMA=? AND INDEX_TYPE_NAME = 'PRIMARY KEY'").executeQuery()).thenReturn(primaryKeys);
ResultSet generatedInfo = mockGeneratedInfoResultSet();
when(dataSource.getConnection().prepareStatement(
"SELECT C.TABLE_NAME TABLE_NAME, C.COLUMN_NAME COLUMN_NAME, COALESCE(S.IS_GENERATED, FALSE) IS_GENERATED FROM INFORMATION_SCHEMA.COLUMNS C RIGHT JOIN"
+ " INFORMATION_SCHEMA.SEQUENCES S ON C.SEQUENCE_NAME=S.SEQUENCE_NAME WHERE C.TABLE_CATALOG=? AND C.TABLE_SCHEMA=?")
"SELECT C.TABLE_NAME TABLE_NAME, C.COLUMN_NAME COLUMN_NAME, COALESCE(I.IS_GENERATED, FALSE) IS_GENERATED FROM INFORMATION_SCHEMA.COLUMNS C RIGHT JOIN"
+ " INFORMATION_SCHEMA.INDEXES I ON C.TABLE_NAME=I.TABLE_NAME WHERE C.TABLE_CATALOG=? AND C.TABLE_SCHEMA=?")
.executeQuery()).thenReturn(generatedInfo);
assertTableMetaDataMap(getDialectTableMetaDataLoader().load(dataSource, Collections.emptyList(), "sharding_db"));
}
Expand All @@ -72,22 +72,22 @@ public void assertLoadWithTables() throws SQLException {
DataSource dataSource = mockDataSource();
ResultSet resultSet = mockTableMetaDataResultSet();
when(dataSource.getConnection().prepareStatement(
"SELECT TABLE_CATALOG, TABLE_NAME, COLUMN_NAME, DATA_TYPE, TYPE_NAME, ORDINAL_POSITION FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_CATALOG=? AND TABLE_SCHEMA=? "
"SELECT TABLE_CATALOG, TABLE_NAME, COLUMN_NAME, DATA_TYPE, ORDINAL_POSITION FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_CATALOG=? AND TABLE_SCHEMA=? "
+ "AND TABLE_NAME IN ('tbl') ORDER BY ORDINAL_POSITION")
.executeQuery()).thenReturn(resultSet);
ResultSet indexResultSet = mockIndexMetaDataResultSet();
when(dataSource.getConnection().prepareStatement(
"SELECT TABLE_CATALOG, TABLE_NAME, INDEX_NAME, COLUMN_NAME FROM INFORMATION_SCHEMA.INDEXES WHERE TABLE_CATALOG=? AND TABLE_SCHEMA=? AND TABLE_NAME IN ('tbl')")
"SELECT TABLE_CATALOG, TABLE_NAME, INDEX_NAME FROM INFORMATION_SCHEMA.INDEXES WHERE TABLE_CATALOG=? AND TABLE_SCHEMA=? AND TABLE_NAME IN ('tbl')")
.executeQuery()).thenReturn(indexResultSet);
ResultSet primaryKeys = mockPrimaryKeysMetaDataResultSet();
when(dataSource.getConnection().prepareStatement(
"SELECT TABLE_NAME, COLUMN_NAME FROM INFORMATION_SCHEMA.INDEXES WHERE TABLE_CATALOG=? AND TABLE_SCHEMA=? AND PRIMARY_KEY = TRUE AND TABLE_NAME IN ('tbl')")
"SELECT TABLE_NAME, INDEX_NAME FROM INFORMATION_SCHEMA.INDEXES WHERE TABLE_CATALOG=? AND TABLE_SCHEMA=? AND INDEX_TYPE_NAME = 'PRIMARY KEY' AND TABLE_NAME IN ('tbl')")
.executeQuery())
.thenReturn(primaryKeys);
ResultSet generatedInfo = mockGeneratedInfoResultSet();
when(dataSource.getConnection().prepareStatement(
"SELECT C.TABLE_NAME TABLE_NAME, C.COLUMN_NAME COLUMN_NAME, COALESCE(S.IS_GENERATED, FALSE) IS_GENERATED FROM INFORMATION_SCHEMA.COLUMNS C"
+ " RIGHT JOIN INFORMATION_SCHEMA.SEQUENCES S ON C.SEQUENCE_NAME=S.SEQUENCE_NAME WHERE C.TABLE_CATALOG=? AND C.TABLE_SCHEMA=? AND TABLE_NAME IN ('tbl')")
"SELECT C.TABLE_NAME TABLE_NAME, C.COLUMN_NAME COLUMN_NAME, COALESCE(I.IS_GENERATED, FALSE) IS_GENERATED FROM INFORMATION_SCHEMA.COLUMNS C"
+ " RIGHT JOIN INFORMATION_SCHEMA.INDEXES I ON C.TABLE_NAME=I.TABLE_NAME WHERE C.TABLE_CATALOG=? AND C.TABLE_SCHEMA=? AND C.TABLE_NAME IN ('tbl')")
.executeQuery())
.thenReturn(generatedInfo);
assertTableMetaDataMap(getDialectTableMetaDataLoader().load(dataSource, Collections.singletonList("tbl"), "sharding_db"));
Expand All @@ -113,7 +113,7 @@ private ResultSet mockTableMetaDataResultSet() throws SQLException {
when(result.next()).thenReturn(true, true, false);
when(result.getString("TABLE_NAME")).thenReturn("tbl");
when(result.getString("COLUMN_NAME")).thenReturn("id", "name");
when(result.getString("TYPE_NAME")).thenReturn("int", "varchar");
when(result.getString("DATA_TYPE")).thenReturn("int", "varchar");
when(result.getString("COLUMN_KEY")).thenReturn("PRI", "");
when(result.getString("EXTRA")).thenReturn("auto_increment", "");
when(result.getString("COLLATION_NAME")).thenReturn("utf8_general_ci", "utf8");
Expand All @@ -124,7 +124,7 @@ private ResultSet mockPrimaryKeysMetaDataResultSet() throws SQLException {
ResultSet result = mock(ResultSet.class);
when(result.next()).thenReturn(true, false);
when(result.getString("TABLE_NAME")).thenReturn("tbl");
when(result.getString("COLUMN_NAME")).thenReturn("id");
when(result.getString("INDEX_NAME")).thenReturn("id");
return result;
}

Expand Down Expand Up @@ -156,8 +156,8 @@ private void assertTableMetaDataMap(final Collection<SchemaMetaData> schemaMetaD
TableMetaData actualTableMetaData = schemaMetaDataList.iterator().next().getTables().iterator().next();
assertThat(actualTableMetaData.getColumns().size(), is(2));
Iterator<ColumnMetaData> columnsIterator = actualTableMetaData.getColumns().iterator();
assertThat(columnsIterator.next(), is(new ColumnMetaData("id", 4, true, false, true, true)));
assertThat(columnsIterator.next(), is(new ColumnMetaData("name", 12, false, false, true, true)));
assertThat(columnsIterator.next(), is(new ColumnMetaData("id", 4, true, false, false, true)));
assertThat(columnsIterator.next(), is(new ColumnMetaData("name", 12, false, false, false, true)));
assertThat(actualTableMetaData.getIndexes().size(), is(1));
Iterator<IndexMetaData> indexesIterator = actualTableMetaData.getIndexes().iterator();
assertThat(indexesIterator.next(), is(new IndexMetaData("id")));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ public void assertSelectWithMetaData() throws SQLException {
assertThat(metaData.getColumnCount(), is(2));
for (int i = 0; i < metaData.getColumnCount(); i++) {
assertThat(metaData.getColumnLabel(1), is("id"));
assertThat(metaData.getColumnLabel(2), is("PWD"));
assertThat(metaData.getColumnLabel(2), is("pwd"));
}
}
}
Expand Down Expand Up @@ -219,7 +219,7 @@ public void assertSelectWithInOperator() throws SQLException {
assertThat(metaData.getColumnCount(), is(2));
for (int i = 0; i < metaData.getColumnCount(); i++) {
assertThat(metaData.getColumnLabel(1), is("id"));
assertThat(metaData.getColumnLabel(2), is("PWD"));
assertThat(metaData.getColumnLabel(2), is("pwd"));
}
}
}
Expand All @@ -232,8 +232,8 @@ public void assertSelectWithPlainColumnForContainsColumn() throws SQLException {
assertThat(metaData.getColumnCount(), is(3));
for (int i = 0; i < metaData.getColumnCount(); i++) {
assertThat(metaData.getColumnLabel(1), is("id"));
assertThat(metaData.getColumnLabel(2), is("PLAIN_PWD"));
assertThat(metaData.getColumnLabel(3), is("PLAIN_PWD2"));
assertThat(metaData.getColumnLabel(2), is("plain_pwd"));
assertThat(metaData.getColumnLabel(3), is("plain_pwd2"));
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ public void assertSelectWithMetaData() throws SQLException {
assertThat(metaData.getColumnCount(), is(2));
for (int i = 0; i < metaData.getColumnCount(); i++) {
assertThat(metaData.getColumnLabel(1), is("id"));
assertThat(metaData.getColumnLabel(2), is("PWD"));
assertThat(metaData.getColumnLabel(2), is("pwd"));
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -430,7 +430,7 @@ public void assertAddOnDuplicateKey() throws SQLException {
preparedStatement.setString(8, status);
preparedStatement.setString(9, updatedStatus);
int result = preparedStatement.executeUpdate();
assertThat(result, is(2));
assertThat(result, is(4));
linghengqian marked this conversation as resolved.
Show resolved Hide resolved
queryStatement.setInt(1, orderId);
queryStatement.setInt(2, userId1);
try (ResultSet resultSet = queryStatement.executeQuery()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ public void assertGetGeneratedKeys() throws SQLException {
generatedKeysResultSet = statement.getGeneratedKeys();
assertTrue(generatedKeysResultSet.next());
assertThat(generatedKeysResultSet.getLong(1), is(6L));
assertFalse(statement.execute(String.format(sql, 1, 1, "init"), new String[]{"no"}));
assertFalse(statement.execute(String.format(sql, 1, 1, "init"), new String[]{"status"}));
linghengqian marked this conversation as resolved.
Show resolved Hide resolved
generatedKeysResultSet = statement.getGeneratedKeys();
assertTrue(generatedKeysResultSet.next());
assertThat(generatedKeysResultSet.getLong(1), is(7L));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,8 @@ private List<DataSetColumn> getActualColumns(final Connection connection, final
while (resultSet.next()) {
DataSetColumn each = new DataSetColumn();
each.setName(resultSet.getString("COLUMN_NAME"));
each.setType(resultSet.getString("TYPE_NAME").toLowerCase());
String typeName = resultSet.getString("TYPE_NAME");
each.setType("CHARACTER VARYING".equals(typeName) ? "VARCHAR".toLowerCase() : typeName.toLowerCase());
result.add(each);
}
return result;
Expand Down