com.gantzgulch.sharing.configuration.DataSourceContextProduction.java Source code

Java tutorial

Introduction

Here is the source code for com.gantzgulch.sharing.configuration.DataSourceContextProduction.java

Source

/*
 * Copyright 2011 GantzGulch, Inc.
 * 
 * This file is part of GantzFileSharing.
 * 
 * GantzFileSharing is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 * 
 * GantzFileSharing is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License
 * along with GantzFileSharing.  If not, see <http://www.gnu.org/licenses/>. 
 */
package com.gantzgulch.sharing.configuration;

import javax.sql.DataSource;

import org.apache.commons.dbcp.BasicDataSource;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Profile;

@Configuration
@Profile("production")
public class DataSourceContextProduction {

    private static final Log LOG = LogFactory.getLog(DataSourceContextProduction.class);

    public DataSourceContextProduction() {
        LOG.debug("ctor");
    }

    @Autowired
    @Qualifier("storageLocation")
    private String storageLocation;

    @Bean(name = "sharingDS")
    public DataSource sharingDataSource() {
        BasicDataSource dataSource = new BasicDataSource();
        dataSource.setDriverClassName("org.hsqldb.jdbcDriver");
        dataSource.setUrl("jdbc:hsqldb:file:" + storageLocation + "/sharing_db");
        dataSource.setUsername("sa");
        dataSource.setPassword("");
        return dataSource;
    }

}