/** * Copyright 2018 人人开源 http://www.renren.io *
* 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 io.renren.config; import io.renren.dao.*; import io.renren.utils.RRException; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Value; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Primary; /** * 数据库配置 * * @author Mark sunlightcs@gmail.com * @since 2018-07-24 */ @Configuration public class DbConfig { @Value("${renren.database: mysql}") private String database; @Autowired private MySQLGeneratorDao mySQLGeneratorDao; @Autowired private OracleGeneratorDao oracleGeneratorDao; @Autowired private SQLServerGeneratorDao sqlServerGeneratorDao; @Autowired private PostgreSQLGeneratorDao postgreSQLGeneratorDao; @Bean @Primary public GeneratorDao getGeneratorDao(){ if("mysql".equalsIgnoreCase(database)){ return mySQLGeneratorDao; }else if("oracle".equalsIgnoreCase(database)){ return oracleGeneratorDao; }else if("sqlserver".equalsIgnoreCase(database)){ return sqlServerGeneratorDao; }else if("postgresql".equalsIgnoreCase(database)){ return postgreSQLGeneratorDao; }else { throw new RRException("不支持当前数据库:" + database); } } }