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

blade.plugin.sql2o.Sql2oPlugin Maven / Gradle / Ivy

package blade.plugin.sql2o;

import javax.sql.DataSource;

import blade.kit.StringKit;
import blade.log.Logger;
import blade.plugin.Plugin;
import blade.plugin.sql2o.connection.ConnectionManager;

/**
 * sql2o数据库插件
 * 
 * @author	biezhi
 * @since	1.0
 */
public class Sql2oPlugin implements Plugin {

	private static final Logger LOGGER = Logger.getLogger(Sql2oPlugin.class);
	
	private static DBConfig dbConfig;
	
	/**
	 * 设置数据库配置
	 * 
	 * @param url
	 * @param driver
	 * @param user
	 * @param pass
	 */
	public void config(String url, String driver, String user, String pass){
		
		if(StringKit.isNotEmpty(url) && StringKit.isNotEmpty(driver)
				&& StringKit.isNotEmpty(user) && StringKit.isNotEmpty(pass)){
		
			dbConfig = new DBConfig(driver, url,  user, pass);
		}
	}
	
	public static DBConfig getDbConfig(){
		return dbConfig;
	}
	
	@Override
	public void run() {
		DataSource dataSource = ConnectionManager.getDataSource();
		if(null != dataSource){
			Model.sql2o(dataSource);
			LOGGER.debug("数据库插件配置成功...");
		} else {
			LOGGER.error("数据库插件配置失败");
		}
	}

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy