<commit_before>/*
 * Copyright 2016 Bridje Framework.
 *
 * Licensed 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
 *
 *      http://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.bridje.jdbc.impl;

import java.io.IOException;
import java.io.InputStream;
import java.sql.SQLException;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.annotation.PostConstruct;
import javax.sql.DataSource;
import javax.xml.bind.JAXBException;
import org.bridje.ioc.Component;
import org.bridje.jdbc.JdbcService;
import org.bridje.jdbc.config.DataSourceConfig;
import org.bridje.jdbc.config.JdbcConfig;
import org.bridje.vfs.VFile;
import org.bridje.vfs.VFileInputStream;

@Component
class JdbcServiceImpl implements JdbcService
{
    private static final Logger LOG = Logger.getLogger(JdbcServiceImpl.class.getName());
    
    private Map<String, DataSourceImpl> dsMap;
    
    private Map<String, DataSourceImpl> schemaMap;
    
    private JdbcConfig config;
    
    @PostConstruct
    public void init()
    {
        try
        {
            dsMap = new ConcurrentHashMap<>();
            schemaMap = new ConcurrentHashMap<>();
            initConfig();
            config.getDataSources().forEach(cfg -> dsMap.put(cfg.getName(), new DataSourceImpl(cfg)) );
            config.getSchemas().forEach(cfg -> schemaMap.put(cfg.getName(), dsMap.get(cfg.getDataSource())));
        }
        catch (IOException e)
        {
            LOG.log(Level.SEVERE, e.getMessage(), e);
        }
    }
    
    @Override
    public DataSource getDataSourceBySchema(String schemaName)
    {
        DataSource result = schemaMap.get(schemaName);
        if(result == null) LOG.log(Level.WARNING, String.format("Could not find the DataSource for the schema %s.", schemaName));
        return null;
    }

    @Override
    public DataSource getDataSource(String name)
    {
        DataSource result = dsMap.get(name);
        if(result == null) LOG.log(Level.WARNING, String.format("The DataSource %s does not exists.", name));
        return result;
    }<commit_msg>Adding schema configuration to JDBC.<commit_after>/*
 * Copyright 2016 Bridje Framework.
 *
 * Licensed 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
 *
 *      http://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.bridje.jdbc.impl;

import java.io.IOException;
import java.io.InputStream;
import java.sql.SQLException;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.annotation.PostConstruct;
import javax.sql.DataSource;
import javax.xml.bind.JAXBException;
import org.bridje.ioc.Component;
import org.bridje.jdbc.JdbcService;
import org.bridje.jdbc.config.DataSourceConfig;
import org.bridje.jdbc.config.JdbcConfig;
import org.bridje.vfs.VFile;
import org.bridje.vfs.VFileInputStream;

@Component
class JdbcServiceImpl implements JdbcService
{
    private static final Logger LOG = Logger.getLogger(JdbcServiceImpl.class.getName());
    
    private Map<String, DataSourceImpl> dsMap;
    
    private Map<String, DataSourceImpl> schemaMap;
    
    private JdbcConfig config;
    
    @PostConstruct
    public void init()
    {
        try
        {
            dsMap = new ConcurrentHashMap<>();
            schemaMap = new ConcurrentHashMap<>();
            initConfig();
            config.getDataSources().forEach(cfg -> dsMap.put(cfg.getName(), new DataSourceImpl(cfg)) );
            config.getSchemas().forEach(cfg -> schemaMap.put(cfg.getName(), dsMap.get(cfg.getDataSource())));
        }
        catch (IOException e)
        {
            LOG.log(Level.SEVERE, e.getMessage(), e);
        }
    }
    
    @Override
    public DataSource getDataSourceBySchema(String schemaName)
    {
        DataSource result = schemaMap.get(schemaName);
        if(result == null) LOG.log(Level.WARNING, String.format("Could not find the DataSource for the schema %s.", schemaName));
        return result;
    }

    @Override
    public DataSource getDataSource(String name)
    {
        DataSource result = dsMap.get(name);
        if(result == null) LOG.log(Level.WARNING, String.format("The DataSource %s does not exists.", name));
        return result;
    }
{'fraction_non_alphanumeric': 0.10117105010558648, 'fraction_numerical': 0.0030716068343252063, 'mean_word_length': 3.242671009771987, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 15, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 2}, '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': '5831971', 'n_tokens_mistral': 1456, 'n_tokens_neox': 1436, 'n_words': 418}