All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.github.iskrenyp.spockdbrepo.driver.IDataSourceRuler.groovy Maven / Gradle / Ivy

Go to download

A simple annotation driven local extension for Spock framework, which enables you to screen record your Specifications

The newest version!
package com.github.iskrenyp.spockdbrepo.driver

import com.github.iskrenyp.spockdbrepo.api.SqlDataSourceConfigObj
import com.github.iskrenyp.spockdbrepo.exception.DbRepoException
import groovy.sql.Sql
import groovy.util.logging.Slf4j
import java.sql.SQLException

@Slf4j
trait IDataSourceRuler {

    Sql sql

    IDataSourceRuler connect(SqlDataSourceConfigObj config) throws DbRepoException {
        log.info("Starting connection to $config.url")
        try {
            this.sql = Sql.newInstance(config.url, config.username, config.password, config.driver)
            return this
        } catch(ClassNotFoundException | SQLException e) {
            throw new DbRepoException("There was an error while connecting to $config.url", e)
        }
    }

    def disconnect() {
        if (this.sql) {
            log.info("Closing db connection")
            this.sql.close()
        }
    }

    def  T perform(Closure consumeSql) throws Exception {
        this.sql.with consumeSql
    }



}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy