<commit_before>package de.unioninvestment.crud2go.testing.internal.db

import org.springframework.jdbc.datasource.DriverManagerDataSource;

import javax.sql.DataSource

class DatabaseSchemas {
	
	private Map<String,DataSource> dataSources = [:]
	
	private Properties props
	
	DatabaseSchemas() {
		props = new Properties()
        loadPropertiesIfExists("database-default.properties")
        loadPropertiesIfExists("database.properties")
	}

    private loadPropertiesIfExists(String resourceName) {
        def stream = DatabaseSchemas.class.classLoader.getResourceAsStream(resourceName);
        if (stream) {
            props.load(stream)
            stream.close()
        }
    }

    def propertyMissing(String name) {
		def dataSource = dataSources[name]
		if (!dataSource) {
			dataSource = createDataSource(name)
			dataSources[name] = dataSource
		}
		return dataSource
	}
	
	DataSource createDataSource(name) {
		def data = schemaData(name)
		assert data?.url : "DataSource $name not configured properly"
		new DriverManagerDataSource(url:data.url, driverClassName:data.driver, username:data.username, password:<PASSWORD>)
	}<commit_msg>Configurable schema configuration path and get() for type safety<commit_after>package de.unioninvestment.crud2go.testing.internal.db

import org.springframework.jdbc.datasource.DriverManagerDataSource;

import javax.sql.DataSource

class DatabaseSchemas {
	
	private Map<String,DataSource> dataSources = [:]
	
	private Properties props
	
	DatabaseSchemas() {
		props = new Properties()
        loadPropertiesIfExists("database-default.properties")
        loadPropertiesIfExists(System.getProperty('database.config', "database.properties"))
	}

    private loadPropertiesIfExists(String resourceName) {
        def stream = DatabaseSchemas.class.classLoader.getResourceAsStream(resourceName);
        if (stream) {
            props.load(stream)
            stream.close()
        }
    }

    def propertyMissing(String name) {
        get(name)
	}

    DataSource get(String name) {
        def dataSource = dataSources[name]
        if (!dataSource) {
            dataSource = createDataSource(name)
            dataSources[name] = dataSource
        }
        return dataSource
    }

	DataSource createDataSource(name) {
		def data = schemaData(name)
		assert data?.url : "DataSource $name not configured properly"
		new DriverManagerDataSource(url:data.url, driverClassName:data.driver, username:data.username, password:data.password)
	}
{'fraction_non_alphanumeric': 0.0914560770156438, 'fraction_numerical': 0.0008022462896109105, 'mean_word_length': 3.768642447418738, 'pattern_counts': {'":': 0, '<': 6, '<?xml version=': 0, '>': 6, 'https://': 0, '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': '1896592', 'n_tokens_mistral': 697, 'n_tokens_neox': 651, 'n_words': 135}