com.jfinal.plugin.druid.DruidPlugin Java Examples

The following examples show how to use com.jfinal.plugin.druid.DruidPlugin. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: JFinalConfigExt.java    From jfinal-ext3 with Apache License 2.0 6 votes vote down vote up
/**
 * 获取ActiveRecordPlugin 
 * @param dp DruidPlugin
 * @return
 */
private ActiveRecordPlugin getActiveRecordPlugin(String ds, DruidPlugin dp){
	ActiveRecordPlugin arp = new ActiveRecordPlugin(ds, dp);
	arp.setShowSql(this.getPropertyToBoolean("db.showsql"));

	// auto mapping
	if (!this.geRuned) {
		try {
			Class<?> clazz = Class.forName(this.getModelPackage()+"."+ds.toUpperCase()+this.getMappingKitClassName());
			Method mapping = clazz.getMethod("mapping", ActiveRecordPlugin.class);
			mapping.invoke(clazz, arp);
		} catch (ClassNotFoundException | NoSuchMethodException | SecurityException | IllegalAccessException
				| IllegalArgumentException | InvocationTargetException e) {
			throw (new RuntimeException(String.valueOf(e) + ",may be your table is not contain `PrimaryKey`."));
		}
	}
	return arp;
}
 
Example #2
Source File: DemoConfig.java    From sqlhelper with GNU Lesser General Public License v3.0 5 votes vote down vote up
/**
 * 配置插件
 */
public void configPlugin(Plugins me) {
	// 配置 druid 数据库连接池插件
	DruidPlugin druidPlugin = new DruidPlugin(p.get("jdbcUrl"), p.get("user"), p.get("password").trim());
	me.add(druidPlugin);
	
	// 配置ActiveRecord插件
	ActiveRecordPlugin arp = new ActiveRecordPlugin(druidPlugin);
	arp.setDialect(new JFinalCommonDialect("h2"));
	// 所有映射在 MappingKit 中自动化搞定
	_MappingKit.mapping(arp);
	me.add(arp);
}
 
Example #3
Source File: JFinalConfigExt.java    From jfinal-ext3 with Apache License 2.0 5 votes vote down vote up
/**
 * Config plugin
 */
public void configPlugin(Plugins me) {
	String[] dses = this.getDataSource();
	for (String ds : dses) {
		if (!this.getDbActiveState(ds)) {
			continue;
		}
		DruidPlugin drp = this.getDruidPlugin(ds);
		me.add(drp);
		ActiveRecordPlugin arp = this.getActiveRecordPlugin(ds, drp);
		me.add(arp);
	}
	// config ModelRedisPlugin
	String[] caches = this.getRedisCaches();
	for (String cache : caches) {
		if (!this.getRedisActiveState(cache)) {
			continue;
		}
		// conf redis plguin
		RedisPlugin rp = null;
		String redisPassword = this.getRedisPassword(cache);
		if (StrKit.isBlank(redisPassword)) {
			rp = new RedisPlugin(cache, this.getRedisHost(cache), this.getRedisPort(cache));
		} else {
			rp = new RedisPlugin(cache, this.getRedisHost(cache), this.getRedisPort(cache), this.getRedisPassword(cache));
		}
		me.add(rp);
		// conf redis model plugin
		ModelRedisPlugin mrp = new ModelRedisPlugin(cache, this.getRedisCacheTables(cache));
		me.add(mrp);
	}
	// config others
	configMorePlugins(me);
}
 
Example #4
Source File: JFinalConfigExt.java    From jfinal-ext3 with Apache License 2.0 5 votes vote down vote up
/**
 * DruidPlugin
 * @param prop : property
 * @return
 */
private DruidPlugin getDruidPlugin(String ds) {
	String url = this.getProperty(String.format("db.%s.url", ds));
	url = String.format(URL_TEMPLATE, ds, url);
	String endsWith = "?characterEncoding=UTF8&zeroDateTimeBehavior=CONVERT_TO_NULL";
	if (!url.endsWith(endsWith)) {
		url += endsWith;
	}
	
	String password = this.getProperty(String.format(PASSWORD_TEMPLATE, ds));
	String pkey = this.getProperty(String.format(PASSWORD_PKEY_TEMPLATE, ds));
	String user = this.getProperty(String.format(USER_TEMPLATE, ds));
	
	DruidPlugin dp = new DruidPlugin(url, user, password);
	dp.setPublicKey(pkey);
	dp.setFilters("config,stat,wall");
	dp.setInitialSize(this.getPropertyToInt(String.format(INITSIZE_TEMPLATE, ds)));
	dp.setMaxActive(this.getPropertyToInt(String.format(MAXSIZE_TEMPLATE, ds)));
	
	if (this.geRuned) {
		dp.start();
		BaseModelGenerator baseGe = new BaseModelGenerator(this.getBaseModelPackage(), this.getBaseModelOutDir());
		baseGe.setGenerateChainSetter(true);
		baseGe.setTemplate(base_model_template);
		ModelGenerator modelGe = new ModelGenerator(this.getModelPackage(), this.getBaseModelPackage(), this.getModelOutDir());
		modelGe.setGenerateDaoInModel(this.getGeDaoInModel());
		modelGe.setTemplate(model_template);
		Generator ge = new Generator(dp.getDataSource(), baseGe, modelGe);
		MappingKitGenerator mappingKitGe = new MappingKitGenerator(this.getModelPackage(), this.getModelOutDir());
		mappingKitGe.setMappingKitClassName(ds.toUpperCase()+this.getMappingKitClassName());
		mappingKitGe.setTemplate(mapping_kit_template);
		ge.setMappingKitGenerator(mappingKitGe);
		ge.setGenerateDataDictionary(this.getGeDictionary());
		ge.generate();
	}
	
	return dp;
}
 
Example #5
Source File: _JFinalGenerator.java    From sdb-mall with Apache License 2.0 5 votes vote down vote up
public static DataSource getDataSource() {
	String jdbcUrl = "jdbc:mysql://127.0.0.1:3306/"+DB_NAME+"?useUnicode=true&characterEncoding=UTF-8";
	String user = DB_USER_NAME;
	String password = DB_USER_PWD;
	DruidPlugin druidPlugin = new DruidPlugin(jdbcUrl, user, password);
	druidPlugin.start();
	return druidPlugin.getDataSource();
}
 
Example #6
Source File: Test.java    From my_curd with Apache License 2.0 5 votes vote down vote up
static void init() {
    Prop jdbcProp = PropKit.use("config-dev.txt");
    DruidPlugin dp = new DruidPlugin(jdbcProp.get("oa.jdbc.url"),
            jdbcProp.get("oa.jdbc.user"), jdbcProp.get("oa.jdbc.password"), jdbcProp.get("oa.jdbc.driver"));
    dp.start();
    ActiveRecordPlugin arp = new ActiveRecordPlugin(ActivitiConfig.DATASOURCE_NAME, dp);
    arp.setDialect(new MysqlDialect());
    arp.setShowSql(true);
    arp.start();
    ActivitiPlugin ap = new ActivitiPlugin();
    ap.start();
}
 
Example #7
Source File: MysqlDataSourceUtils.java    From my_curd with Apache License 2.0 5 votes vote down vote up
/**
 * 获得数据库数据源,用于代码生成器
 *
 * @return 数据源
 */
public static DataSource getDataSource() {
    // 根据实际情况配置
    Prop configProp = PropKit.use("jdbc.properties");
    DruidPlugin dp = new DruidPlugin(configProp.get("jdbc.url"), configProp.get("jdbc.user"),
            configProp.get("jdbc.password"), configProp.get("jdbc.driver"));
    dp.start();
    return dp.getDataSource();
}
 
Example #8
Source File: _JFinalDemoGenerator.java    From sqlhelper with GNU Lesser General Public License v3.0 4 votes vote down vote up
public static DataSource getDataSource() {
	DruidPlugin druidPlugin = DemoConfig.createDruidPlugin();
	druidPlugin.start();
	return druidPlugin.getDataSource();
}
 
Example #9
Source File: DemoConfig.java    From sqlhelper with GNU Lesser General Public License v3.0 4 votes vote down vote up
public static DruidPlugin createDruidPlugin() {
	loadConfig();
	
	return new DruidPlugin(p.get("jdbcUrl"), p.get("user"), p.get("password").trim());
}
 
Example #10
Source File: AppConfig.java    From my_curd with Apache License 2.0 4 votes vote down vote up
@SuppressWarnings("Duplicates")
    @Override
    public void configPlugin(Plugins me) {
        // 数据源 1 (用户权限、组织机构、主数据 等) main
        DruidPlugin sysDruid = new DruidPlugin(configProp.get("jdbc.url"), configProp.get("jdbc.user"), configProp.get("jdbc.password"), configProp.get("jdbc.driver"));
        sysDruid.setInitialSize(configProp.getInt("jdbc.initialSize"));
        sysDruid.setMaxActive(configProp.getInt("jdbc.maxActive"));
        sysDruid.setMinIdle(configProp.getInt("jdbc.minIdle"));
        StatFilter statFilter = new StatFilter();
        WallFilter wall = new WallFilter();
        wall.setDbType(configProp.get("jdbc.dbType"));
        sysDruid.addFilter(statFilter);
        sysDruid.addFilter(wall);
        me.add(sysDruid);
        ActiveRecordPlugin sysActiveRecord = new ActiveRecordPlugin(sysDruid);
        sysActiveRecord.setDialect(new MysqlDialect());
        sysActiveRecord.setShowSql(activeProfile.equalsIgnoreCase("dev"));
        SystemModelMapping.mapping(sysActiveRecord);  // system 模块
        ExampleModelMapping.mapping(sysActiveRecord); // example 模块
        me.add(sysActiveRecord);
        log.info("设置 数据源 sysDruid sysActiveRecord 成功");


        // 数据源2 (activiti表、流程表单) my_curd_oa
        DruidPlugin oaDruid = new DruidPlugin(configProp.get("oa.jdbc.url"), configProp.get("oa.jdbc.user"), configProp.get("oa.jdbc.password"), configProp.get("oa.jdbc.driver"));
        oaDruid.setInitialSize(configProp.getInt("oa.jdbc.initialSize"));
        oaDruid.setMaxActive(configProp.getInt("oa.jdbc.maxActive"));
        oaDruid.setMinIdle(configProp.getInt("oa.jdbc.minIdle"));
        oaDruid.addFilter(statFilter);
        oaDruid.addFilter(wall);
        me.add(oaDruid);
        ActiveRecordPlugin oaActiveRecord = new ActiveRecordPlugin(ActivitiConfig.DATASOURCE_NAME,oaDruid);
        oaActiveRecord.setDialect(new MysqlDialect());
        oaActiveRecord.setShowSql(activeProfile.equalsIgnoreCase("dev"));
        OaModelMapping.mapping(oaActiveRecord);
        me.add(oaActiveRecord);
        log.info("设置 数据源 oaDruid oaActiveRecord 成功");

        // activiti 插件
        ActivitiPlugin ap = new ActivitiPlugin();
        me.add(ap);
        log.info("加载 Activiti 插件 成功");

        // 定时任务
        Cron4jPlugin cp = new Cron4jPlugin(configProp, "cron4j");
        me.add(cp);
        log.info("加载 Corn4j 插件 成功");

        //         redis 插件
//        RedisPlugin userRedis = new RedisPlugin("user", configProp.get("redis.host"),configProp.getInt("redis.port")
//                ,configProp.getInt("redis.timeout"),configProp.get("redis.password"),configProp.getInt("redis.database"));
//        me.add(userRedis);
//        log.info("加载redis 插件成功");

    }