<commit_before>package de.iteratec.osm.csi

import grails.buildtestdata.TestDataBuilder
import org.hibernate.boot.MetadataSources
import org.hibernate.boot.registry.StandardServiceRegistryBuilder
import org.hibernate.boot.spi.MetadataImplementor
import org.hibernate.tool.hbm2ddl.SchemaExport
import spock.lang.Shared
import spock.lang.Specification

import java.sql.Connection

/*
See https://stackoverflow.com/a/32227118
 */
class NonTransactionalIntegrationSpec extends Specification implements TestDataBuilder {

    @Shared
    private static MetadataSources metadata
    Connection connection//Wie krieg ich die? Datasource.getConnection


    @Shared
    def grailsApplication

    static transactional = false

    def cleanup() {
        if (!metadata) {
            metadata = new MetadataSources(new StandardServiceRegistryBuilder().applySetting(
                    "hibernate.dialect", "org.hibernate.dialect.MySQLDialect").build())
            // [...] adding annotated classes to metadata here...
            configuration.addAnnotatedClass()

            Properties properties = new Properties()
            properties.setProperty 'hibernate.connection.driver_class', grailsApplication.config.dataSource.driverClassName
            properties.setProperty 'hibernate.connection.username', grailsApplication.config.dataSource.username
            properties.setProperty 'hibernate.connection.password', grailsApplication.config.dataSource.password ?:""
            properties.setProperty 'hibernate.connection.url', grailsApplication.config.dataSource.url
            properties.setProperty 'hibernate.dialect', 'org.hibernate.dialect.H2Dialect'
        }
        new SchemaExport(
                (MetadataImplementor) metadata.buildMetadata(),
                connection // pre-configured Connection here
        ).create(false, true)
    }

}<commit_msg>New way of resetting database in cleanup of integration test<commit_after>package de.iteratec.osm.csi

import grails.buildtestdata.TestDataBuilder
import grails.core.GrailsApplication
import org.grails.datastore.mapping.core.connections.ConnectionSource
import org.grails.orm.hibernate.HibernateDatastore
import org.hibernate.boot.MetadataBuilder
import org.hibernate.boot.MetadataSources
import org.hibernate.boot.spi.MetadataImplementor
import org.hibernate.engine.spi.SessionFactoryImplementor
import org.hibernate.tool.hbm2ddl.SchemaExport
import spock.lang.Specification
/*
See https://stackoverflow.com/questions/16628929/grails-recreate-database-schema-for-integration-test
 */
class NonTransactionalIntegrationSpec extends Specification implements TestDataBuilder {
    static transactional = false

    GrailsApplication grailsApplication

    def cleanup() {
        HibernateDatastore hibernateDatastore = grailsApplication.mainContext.getBean("hibernateDatastore", HibernateDatastore)
        hibernateDatastore = hibernateDatastore.getDatastoreForConnection(ConnectionSource.DEFAULT)
        def serviceRegistry = ((SessionFactoryImplementor)hibernateDatastore.sessionFactory).getServiceRegistry()
                .getParentServiceRegistry()
        final MetadataSources metadataSources = new MetadataSources( serviceRegistry )
        final MetadataBuilder metadataBuilder = metadataSources.getMetadataBuilder()
        def metadata = (MetadataImplementor) metadataBuilder.build()

        def schemaExport = new SchemaExport(serviceRegistry, metadata)
        schemaExport.create(false, true)
    }

}
{'fraction_non_alphanumeric': 0.0768348623853211, 'fraction_numerical': 0.005447247706422019, 'mean_word_length': 4.146017699115045, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2501773', 'n_tokens_mistral': 930, 'n_tokens_neox': 853, 'n_words': 166}