diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index fa7e5f0b..c6ce5625 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -60,7 +60,7 @@ jobs: strategy: fail-fast: false matrix: - java: [ 17, 19 ] + java: [ 17, 21 ] steps: - uses: actions/checkout@v4 @@ -100,7 +100,7 @@ jobs: strategy: fail-fast: false matrix: - hibernate: [ "6.0.2.Final", "6.1.7.Final" ] + hibernate: [ "6.0.2.Final", "6.1.7.Final", "6.2.7.Final", "6.3.1.Final" ] steps: - uses: actions/checkout@v4 diff --git a/pom.xml b/pom.xml index 4459353e..8268b70c 100644 --- a/pom.xml +++ b/pom.xml @@ -68,7 +68,7 @@ UTF-8 - 6.3.0.Final + 6.3.1.Final 6.0.12 4.23.2 @@ -226,23 +226,6 @@ build-helper-maven-plugin 3.4.0 - - - - - - - - - - - - - - - - - org.apache.maven.plugins maven-enforcer-plugin @@ -256,7 +239,7 @@ - 1.8 + 11 diff --git a/src/main/java/liquibase/ext/hibernate/snapshot/IndexSnapshotGenerator.java b/src/main/java/liquibase/ext/hibernate/snapshot/IndexSnapshotGenerator.java index cca4d72a..1bf59a7e 100644 --- a/src/main/java/liquibase/ext/hibernate/snapshot/IndexSnapshotGenerator.java +++ b/src/main/java/liquibase/ext/hibernate/snapshot/IndexSnapshotGenerator.java @@ -7,7 +7,7 @@ import liquibase.structure.DatabaseObject; import liquibase.structure.core.*; -import java.util.Iterator; +import java.util.Map; public class IndexSnapshotGenerator extends HibernateSnapshotGenerator { @@ -29,16 +29,13 @@ protected DatabaseObject snapshotObject(DatabaseObject example, DatabaseSnapshot if (hibernateTable == null) { return example; } - Iterator indexIterator = hibernateTable.getIndexIterator(); - while (indexIterator.hasNext()) { - org.hibernate.mapping.Index hibernateIndex = indexIterator.next(); + Map indexes = hibernateTable.getIndexes(); + for (org.hibernate.mapping.Index hibernateIndex : indexes.values()) { Index index = new Index(); index.setRelation(table); index.setName(hibernateIndex.getName()); index.setUnique(isUniqueIndex(hibernateIndex)); - Iterator columnIterator = hibernateIndex.getColumnIterator(); - while (columnIterator.hasNext()) { - org.hibernate.mapping.Column hibernateColumn = columnIterator.next(); + for (var hibernateColumn : hibernateIndex.getColumns()) { String hibernateOrder = hibernateIndex.getColumnOrderMap().get(hibernateColumn); Boolean descending = HIBERNATE_ORDER_ASC.equals(hibernateOrder) ? Boolean.FALSE @@ -67,16 +64,13 @@ protected void addTo(DatabaseObject foundObject, DatabaseSnapshot snapshot) thro if (hibernateTable == null) { return; } - Iterator indexIterator = hibernateTable.getIndexIterator(); - while (indexIterator.hasNext()) { - org.hibernate.mapping.Index hibernateIndex = indexIterator.next(); + for (var hibernateIndex : hibernateTable.getIndexes().values()) { Index index = new Index(); index.setRelation(table); index.setName(hibernateIndex.getName()); index.setUnique(isUniqueIndex(hibernateIndex)); - Iterator columnIterator = hibernateIndex.getColumnIterator(); - while (columnIterator.hasNext()) { - org.hibernate.mapping.Column hibernateColumn = columnIterator.next(); + + for (var hibernateColumn : hibernateIndex.getColumns()) { String hibernateOrder = hibernateIndex.getColumnOrderMap().get(hibernateColumn); Boolean descending = HIBERNATE_ORDER_ASC.equals(hibernateOrder) ? Boolean.FALSE @@ -95,7 +89,7 @@ private Boolean isUniqueIndex(org.hibernate.mapping.Index hibernateIndex) { actual diff in certain non-unique indexes */ if (hibernateIndex.getColumnSpan() == 1) { - org.hibernate.mapping.Column col = hibernateIndex.getColumnIterator().next(); + var col = hibernateIndex.getColumns().get(0); return col.isUnique(); } else { /* diff --git a/src/main/java/liquibase/ext/hibernate/snapshot/UniqueConstraintSnapshotGenerator.java b/src/main/java/liquibase/ext/hibernate/snapshot/UniqueConstraintSnapshotGenerator.java index 2e0aa74b..f1cd4b44 100644 --- a/src/main/java/liquibase/ext/hibernate/snapshot/UniqueConstraintSnapshotGenerator.java +++ b/src/main/java/liquibase/ext/hibernate/snapshot/UniqueConstraintSnapshotGenerator.java @@ -40,20 +40,15 @@ protected void addTo(DatabaseObject foundObject, DatabaseSnapshot snapshot) thro if (hibernateTable == null) { return; } - Iterator uniqueIterator = hibernateTable.getUniqueKeyIterator(); - while (uniqueIterator.hasNext()) { - org.hibernate.mapping.UniqueKey hibernateUnique = (org.hibernate.mapping.UniqueKey) uniqueIterator.next(); - + for (var hibernateUnique : hibernateTable.getUniqueKeys().values()) { UniqueConstraint uniqueConstraint = new UniqueConstraint(); uniqueConstraint.setName(hibernateUnique.getName()); uniqueConstraint.setRelation(table); uniqueConstraint.setClustered(false); // No way to set true via Hibernate - Iterator columnIterator = hibernateUnique.getColumnIterator(); + int i = 0; - while (columnIterator.hasNext()) { - org.hibernate.mapping.Column hibernateColumn = (org.hibernate.mapping.Column) columnIterator.next(); - uniqueConstraint.addColumn(i, new Column(hibernateColumn.getName()).setRelation(table)); - i++; + for (var hibernateColumn : hibernateUnique.getColumns()) { + uniqueConstraint.addColumn(i++, new Column(hibernateColumn.getName()).setRelation(table)); } Index index = getBackingIndex(uniqueConstraint, hibernateTable, snapshot); @@ -62,9 +57,7 @@ protected void addTo(DatabaseObject foundObject, DatabaseSnapshot snapshot) thro Scope.getCurrentScope().getLog(getClass()).info("Found unique constraint " + uniqueConstraint.toString()); table.getUniqueConstraints().add(uniqueConstraint); } - Iterator columnIterator = hibernateTable.getColumnIterator(); - while (columnIterator.hasNext()) { - org.hibernate.mapping.Column column = (org.hibernate.mapping.Column) columnIterator.next(); + for (var column : hibernateTable.getColumns()) { if (column.isUnique()) { UniqueConstraint uniqueConstraint = new UniqueConstraint(); uniqueConstraint.setRelation(table); @@ -84,9 +77,7 @@ protected void addTo(DatabaseObject foundObject, DatabaseSnapshot snapshot) thro } } - Iterator ucIter = table.getUniqueConstraints().iterator(); - while (ucIter.hasNext()) { - UniqueConstraint uc = ucIter.next(); + for (UniqueConstraint uc : table.getUniqueConstraints()) { if (uc.getName() == null || uc.getName().isEmpty()) { String name = table.getName() + uc.getColumnNames(); name = "UCIDX" + hashedName(name); diff --git a/src/test/java/liquibase/ext/hibernate/SpringPackageScanningIntegrationTest.java b/src/test/java/liquibase/ext/hibernate/SpringPackageScanningIntegrationTest.java index 9089e5c3..3a67e807 100644 --- a/src/test/java/liquibase/ext/hibernate/SpringPackageScanningIntegrationTest.java +++ b/src/test/java/liquibase/ext/hibernate/SpringPackageScanningIntegrationTest.java @@ -26,6 +26,7 @@ import org.junit.Test; import java.io.*; +import java.nio.charset.StandardCharsets; import java.sql.Connection; import java.sql.DriverManager; import java.util.HashSet; @@ -34,8 +35,7 @@ import java.util.Map.Entry; import java.util.Set; -import static junit.framework.TestCase.assertEquals; -import static junit.framework.TestCase.assertTrue; +import static junit.framework.TestCase.*; public class SpringPackageScanningIntegrationTest { private static final String PACKAGES = "com.example.ejb3.auction"; @@ -52,7 +52,7 @@ public void setUp() throws Exception { database = new HsqlDatabase(); database.setConnection(new JdbcConnection(connection)); - Set> typesToInclude = new HashSet>(); + Set> typesToInclude = new HashSet<>(); typesToInclude.add(Table.class); typesToInclude.add(Column.class); typesToInclude.add(PrimaryKey.class); @@ -95,16 +95,14 @@ public void runGeneratedChangeLog() throws Exception { DiffResult diffResult = liquibase.diff(hibernateDatabase, database, compareControl); boolean isTablePrefixWithZZ_ = diffResult.getMissingObjects().stream() - .filter(e -> e.getName().equals("zz_AuditedItem_AUD")) - .findAny() - .isPresent(); + .anyMatch(e -> e.getName().equals("zz_AuditedItem_AUD")); assertTrue(isTablePrefixWithZZ_); - assertTrue(diffResult.getMissingObjects().size() > 0); + assertFalse(diffResult.getMissingObjects().isEmpty()); File outFile = File.createTempFile("lb-test", ".xml"); OutputStream outChangeLog = new FileOutputStream(outFile); String changeLogString = toChangeLog(diffResult); - outChangeLog.write(changeLogString.getBytes("UTF-8")); + outChangeLog.write(changeLogString.getBytes(StandardCharsets.UTF_8)); outChangeLog.close(); Scope.getCurrentScope().getLog(getClass()).info("Changelog:\n" + changeLogString); @@ -287,21 +285,21 @@ private void hibernateSchemaExport(boolean enhancedId) throws Exception { private String toString(DiffResult diffResult) throws Exception { ByteArrayOutputStream out = new ByteArrayOutputStream(); - PrintStream printStream = new PrintStream(out, true, "UTF-8"); + PrintStream printStream = new PrintStream(out, true, StandardCharsets.UTF_8); DiffToReport diffToReport = new DiffToReport(diffResult, printStream); diffToReport.print(); printStream.close(); - return out.toString("UTF-8"); + return out.toString(StandardCharsets.UTF_8); } private String toChangeLog(DiffResult diffResult) throws Exception { ByteArrayOutputStream out = new ByteArrayOutputStream(); - PrintStream printStream = new PrintStream(out, true, "UTF-8"); + PrintStream printStream = new PrintStream(out, true, StandardCharsets.UTF_8); DiffToChangeLog diffToChangeLog = new DiffToChangeLog(diffResult, new DiffOutputControl().setIncludeCatalog(false).setIncludeSchema(false)); diffToChangeLog.print(printStream); printStream.close(); - return out.toString("UTF-8"); + return out.toString(StandardCharsets.UTF_8); } private void ignoreDatabaseChangeLogTable(DiffResult diffResult)