This is an automated email from the ASF dual-hosted git repository.

borinquenkid pushed a commit to branch 8.0.x-hibernate7-dev
in repository https://gitbox.apache.org/repos/asf/grails-core.git

commit 7756c3b0f3e4a779b071fd74952a23d6c1af6a4f
Author: Walter Duque de Estrada <[email protected]>
AuthorDate: Tue Mar 10 18:02:47 2026 -0500

    hibernate 7:  added GormDatabaseSpec
---
 .../liquibase/GormDatabase.groovy                  | 36 ++++-----
 .../liquibase/GormDatabaseSpec.groovy              | 89 ++++++++++++++++++++++
 2 files changed, 108 insertions(+), 17 deletions(-)

diff --git 
a/grails-data-hibernate7/dbmigration/src/main/groovy/org/grails/plugins/databasemigration/liquibase/GormDatabase.groovy
 
b/grails-data-hibernate7/dbmigration/src/main/groovy/org/grails/plugins/databasemigration/liquibase/GormDatabase.groovy
index a378c38f25..a25ae7ebc8 100644
--- 
a/grails-data-hibernate7/dbmigration/src/main/groovy/org/grails/plugins/databasemigration/liquibase/GormDatabase.groovy
+++ 
b/grails-data-hibernate7/dbmigration/src/main/groovy/org/grails/plugins/databasemigration/liquibase/GormDatabase.groovy
@@ -19,21 +19,22 @@
 package org.grails.plugins.databasemigration.liquibase
 
 import groovy.transform.CompileStatic
-
 import liquibase.database.DatabaseConnection
-import liquibase.database.OfflineConnection
 import liquibase.exception.DatabaseException
 import liquibase.ext.hibernate.database.HibernateDatabase
-import liquibase.snapshot.DatabaseSnapshot
-import liquibase.snapshot.JdbcDatabaseSnapshot
-import liquibase.snapshot.SnapshotControl
-import liquibase.structure.DatabaseObject
+import liquibase.database.jvm.JdbcConnection
+import liquibase.ext.hibernate.database.connection.HibernateConnection
+import org.grails.orm.hibernate.HibernateDatastore
 import org.hibernate.boot.Metadata
 import org.hibernate.boot.MetadataSources
 import org.hibernate.dialect.Dialect
 
-import org.grails.orm.hibernate.HibernateDatastore
-
+/**
+ * A Liquibase database implementation that uses GORM's metadata.
+ *
+ * @author Graeme Rocher
+ * @since 2.0
+ */
 @CompileStatic
 class GormDatabase extends HibernateDatabase {
 
@@ -46,25 +47,26 @@ class GormDatabase extends HibernateDatabase {
         super()
         this.dialect = dialect
         this.gormDatastore = hibernateDatastore
-        SnapshotControl snapshotControl = new SnapshotControl(this, null, null)
-        GormDatabase database = this
-        OfflineConnection connection = new OfflineConnection('offline:gorm', 
null) {
-            DatabaseSnapshot getSnapshot(DatabaseObject[] examples) {
-                new JdbcDatabaseSnapshot(examples, database, snapshotControl)
-            }
-        }
-        setConnection(connection)
+        setConnection(new JdbcConnection(new 
HibernateConnection('hibernate:gorm', null)))
+    }
+
+    @Override
+    protected String findDialectName() {
+        dialect?.getClass()?.getName()
     }
 
     /**
      * Return the hibernate {@link Metadata} used by this database.
      */
-
     @Override
     Metadata getMetadata() {
         gormDatastore.getMetadata()
     }
 
+    DatabaseConnection getDatabaseConnection() {
+        return super.getConnection()
+    }
+
     HibernateDatastore getGormDatastore() {
         gormDatastore
     }
diff --git 
a/grails-data-hibernate7/dbmigration/src/test/groovy/org/grails/plugins/databasemigration/liquibase/GormDatabaseSpec.groovy
 
b/grails-data-hibernate7/dbmigration/src/test/groovy/org/grails/plugins/databasemigration/liquibase/GormDatabaseSpec.groovy
new file mode 100644
index 0000000000..7a5b153708
--- /dev/null
+++ 
b/grails-data-hibernate7/dbmigration/src/test/groovy/org/grails/plugins/databasemigration/liquibase/GormDatabaseSpec.groovy
@@ -0,0 +1,89 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you under the Apache License, Version 2.0 (the
+ *  "License"); you may not use this file except in compliance
+ *  with the License.  You may obtain a copy of the License at
+ *
+ *    https://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing,
+ *  software distributed under the License is distributed on an
+ *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ *  KIND, either express or implied.  See the License for the
+ *  specific language governing permissions and limitations
+ *  under the License.
+ */
+package org.grails.plugins.databasemigration.liquibase
+
+import liquibase.database.DatabaseConnection
+import liquibase.database.jvm.JdbcConnection
+import liquibase.snapshot.DatabaseSnapshot
+import liquibase.snapshot.JdbcDatabaseSnapshot
+import liquibase.structure.DatabaseObject
+
+import org.grails.orm.hibernate.HibernateDatastore
+import org.hibernate.boot.Metadata
+import org.hibernate.boot.MetadataSources
+import org.hibernate.boot.internal.MetadataBuilderImpl
+import org.hibernate.boot.registry.StandardServiceRegistryBuilder
+import org.hibernate.dialect.H2Dialect
+import spock.lang.Specification
+
+class GormDatabaseSpec extends Specification {
+
+    protected Metadata createRealMetadata() {
+        def serviceRegistry = new StandardServiceRegistryBuilder()
+                .applySetting("hibernate.dialect", H2Dialect.class.getName())
+                .build()
+        return new MetadataBuilderImpl(
+                new MetadataSources(serviceRegistry)
+        ).build()
+    }
+
+    def "test GormDatabase initialization and properties"() {
+        given:
+        def dialect = new H2Dialect()
+        Metadata metadata = createRealMetadata()
+        HibernateDatastore datastore = Mock {
+            getMetadata() >> metadata
+        }
+
+        when:
+        GormDatabase gormDb = Spy(GormDatabase, constructorArgs: [dialect, 
datastore])
+        gormDb.getMetadata() >> metadata
+
+        then:
+        gormDb.getDialect().getClass() == dialect.getClass()
+        gormDb.getMetadata() == metadata
+        gormDb.getGormDatastore() == datastore
+        gormDb.getShortName() == 'GORM'
+        gormDb.getDefaultDatabaseProductName() == 
'getDefaultDatabaseProductName'
+        gormDb.supportsAutoIncrement()
+        !gormDb.isCorrectDatabaseImplementation(Mock(DatabaseConnection))
+    }
+
+    def "test GormDatabase connection and snapshot"() {
+        given:
+        def dialect = new H2Dialect()
+        Metadata metadata = createRealMetadata()
+        HibernateDatastore datastore = Mock()
+        datastore.getMetadata() >> metadata
+
+        when:
+        GormDatabase gormDb = new GormDatabase(dialect, datastore)
+
+        then:
+        gormDb.getDatabaseConnection() instanceof JdbcConnection
+        gormDb.getDatabaseConnection().getURL() == 'hibernate:gorm'
+
+        when: "creating a snapshot for the database"
+        def snapshot = new JdbcDatabaseSnapshot([] as DatabaseObject[], gormDb)
+
+        then: "it returns a DatabaseSnapshot"
+        snapshot instanceof DatabaseSnapshot
+        snapshot.database == gormDb
+    }
+}

Reply via email to