⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 dboconfig.java

📁  EasyDBO是一个超轻量级对象-关系映射(Object/Relation Mapping
💻 JAVA
字号:
package com.easyjf.dbo.config;

import com.easyjf.dbo.*;

import java.util.*;

import javax.sql.*;
/**
 * 
 * <p>
 * Title:
 * </p>
 * 
 * <p>
 * Description:
 * </p>
 * 
 * <p>
 * Copyright: Copyright (c) 2006
 * </p>
 * 
 * <p>
 * Company: EasyJF开源团队-EasyDBO项目组
 * </p>
 * 
 * @author not attributable
 * @version 1.0
 */
public class DBOConfig {
	public static DBOConfig config;

	private static DataSource dataSource;

	private final Map tables = new HashMap();

	private final Map dialects = new HashMap();

	private boolean optimize;

	private boolean show_sql;

	private boolean enableCache;

	private String cacheName;


	public DBOConfig() {
		
	}

	public void addDialect(String name, String dialect) {
		this.dialects.put(name, dialect);
	}
/**
 * 
 * @throws EasyDBOException
 */
	public void init() throws EasyDBOException {
		System.out.println(new Date().toString() + "配置文件初始化!");
		synchronized (DBOConfig.class) { // 保证只有一个用户访问
			if (tables != null) {
				tables.clear();
			}
			//过滤Boolean型自动使用默认值的数据,此处为临时的解决方案,类型转换将在后期作统一的处理,不使用BeanUtils
			//取消Boolean的默认值
			//BeanUtilsBean.getInstance().getConvertUtils().deregister(Boolean.class);
			//使用null作为Boolean对象的默认值
			//BeanUtilsBean.getInstance().getConvertUtils().register(new org.apache.commons.beanutils.converters.BooleanConverter(null),Boolean.class);
			
			IConfigFactory icf = XMLConfigFactory.getInstance(); // (IConfigFactory)Class.forName("com.easyjf.dbo.config.XMLConfigFactory").newInstance();
			icf.init(this);
			DBMapping dbMapping = DBMapping.getInstance();
			if (!dbMapping.getMap().isEmpty()) {
				dbMapping.getMap().clear();
			}
			Iterator it = tables.keySet().iterator();
			while (it.hasNext()) {
				String className = (String) it.next();				
				try{		
					if(className!=null){
					Class clz=Class.forName(className);
					dbMapping.getMap().put(clz, tables.get(className));
					}
				}
				catch(Exception e)
				{
					throw new EasyDBOException("配置文件错误",e);
				}
				
			}
		}
	}

	// ~--- get methods --------------------------------------------------------

	public DataSource getDataSource() throws EasyDBOException {
		if (dataSource == null) {
			DBOConfig.getInstance().init();
		}

		if (dataSource == null) {
			throw new EasyDBOException("找不到数据资源,请确认配置文件是否正确!");
		}

		return dataSource;
	}

	public String getDialect() {
		String ret = "";
		Object obj = dialects.get("default");

		if (obj == null) {
			if (dialects.values() != null) {
				Iterator it = dialects.values().iterator();

				if (it.hasNext()) {
					ret = (String) it.next();
				}
			}
		} else {
			ret = (String) obj;
		}

		return ret;
	}

	public String getDialect(String name) {
		String ret = "";

		if (dialects != null) {
			Object obj = dialects.get(name);

			if (obj != null) {
				ret = (String) obj;
			}
		}

		return ret;
	}

	public static DBOConfig getInstance() throws EasyDBOException {
		if (config == null) {
			config = new DBOConfig();
			config.init();
		}
		return config;
	}

	public Map getTables() {
		return tables;
	}

	public boolean isOptimize() {
		return optimize;
	}

	public boolean isShow_sql() {
		return show_sql;
	}

	public boolean isEnableCache() {
		return enableCache;
	}

	public void setEnableCache(boolean enableCache) {
		this.enableCache = enableCache;
	}

	public void setDataSource(DataSource dataSource) {
		DBOConfig.dataSource = dataSource;
	}

	public void setDialect(String dialect) {
		this.dialects.put("default", dialect);
	}

	public void setOptimize(boolean optimize) {
		this.optimize = optimize;
	}

	public void setShow_sql(boolean show_sql) {
		this.show_sql = show_sql;
	}

	public String getCacheName() {
		return cacheName;
	}

	public void setCacheName(String cacheName) {
		this.cacheName = cacheName;
	}
	
	
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -