/*
* Copyright 2013 Sławomir Śledź <slawomir.sledz@sof-tech.pl>.
*
* 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 pl.softech.eav.example;
import javax.sql.DataSource;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.orm.jpa.JpaVendorAdapter;
import org.springframework.orm.jpa.vendor.Database;
import org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter;
import com.mchange.v2.c3p0.ComboPooledDataSource;
/**
* @author Sławomir Śledź <slawomir.sledz@sof-tech.pl>
* @since 1.2
*/
@Configuration
public class MySqlDsConfig {
@Bean
public DataSource dataSource(@Value("${mysql.db.username}") final String username, @Value("${mysql.db.password}") final String password,
@Value("${mysql.db.url}") final String url) {
final ComboPooledDataSource cpds = new ComboPooledDataSource();
cpds.setJdbcUrl(url);
cpds.setUser(username);
cpds.setPassword(password);
return cpds;
}
@Bean
public JpaVendorAdapter jpaVendorAdapter(@Value("${mysql.generate_ddl}") final boolean generateDDl) {
final HibernateJpaVendorAdapter jpaVendorAdapter = new HibernateJpaVendorAdapter();
jpaVendorAdapter.setDatabase(Database.MYSQL);
return jpaVendorAdapter;
}
}