All Downloads are FREE. Search and download functionalities are using the official Maven repository.

net.ymate.platform.module.JdbcModule Maven / Gradle / Ivy

There is a newer version: 1.1
Show newest version
/*
 * Copyright 2007-2107 the original author or authors.
 *
 * 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 net.ymate.platform.module;

import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;

import net.ymate.platform.base.AbstractModule;
import net.ymate.platform.commons.lang.BlurObject;
import net.ymate.platform.persistence.jdbc.IJdbcConfig;
import net.ymate.platform.persistence.jdbc.JDBC;
import net.ymate.platform.persistence.jdbc.support.JdbcDataSourceCfgMeta;

import org.apache.commons.lang.StringUtils;

/**
 * 

* JdbcModule *

*

* JDBC持久层框架模块加载器接口实现类; *

* * @author 刘镇([email protected]) * @version 0.0.0 * * * * * * * * * * * *
版本号动作修改人修改时间
0.0.0创建类刘镇2012-12-29下午2:19:18
*/ public class JdbcModule extends AbstractModule { /* (non-Javadoc) * @see net.ymate.platform.module.base.AbstractModule#initialize(java.util.Map) */ public void initialize(final Map moduleCfgs) throws Exception { final boolean _showSql = new BlurObject(moduleCfgs.get("base.show_sql")).toBooleanValue(); final Set _metas = new HashSet(); for (String _name : StringUtils.split(StringUtils.defaultIfEmpty(StringUtils.trimToEmpty(moduleCfgs.get("base.datasource_list")), "default"), "|")) { String _adaptorClass = moduleCfgs.get("datasource." + _name + ".adapter_class"); String _driverClass = moduleCfgs.get("datasource." + _name + ".driver_class"); String _connectionUrl = moduleCfgs.get("datasource." + _name + ".connection_url"); String _userName = moduleCfgs.get("datasource." + _name + ".username"); String _password = moduleCfgs.get("datasource." + _name + ".password"); // Map _params = new HashMap(); String _paramKey = "datasource." + _name + ".params."; for (String _cfgKey : moduleCfgs.keySet()) { if (_cfgKey.startsWith(_paramKey)) { _params.put(StringUtils.substringAfter(_cfgKey, _paramKey), moduleCfgs.get(_cfgKey)); } } _metas.add(new JdbcDataSourceCfgMeta(_name, _adaptorClass, _driverClass, _connectionUrl, _userName, _password, _params)); } JDBC.initialize(new IJdbcConfig() { public boolean isShowSql() { return _showSql; } public String getTablePrefix() { return moduleCfgs.get("base.table_prefix"); } public String getDefaultDataSourceName() { return moduleCfgs.get("base.datasource_default"); } public String[] getRepositoryPackages() { return StringUtils.split(moduleCfgs.get("base.repository_packages"), "|"); } public Set getDataSourceCfgMetas() { return _metas; } }); } /* (non-Javadoc) * @see net.ymate.platform.module.base.AbstractModule#destroy() */ public void destroy() throws Exception { JDBC.destroy(); } }




© 2015 - 2024 Weber Informatics LLC | Privacy Policy