com.jfinal.plugin.activerecord.generator.Generator Java Examples

The following examples show how to use com.jfinal.plugin.activerecord.generator.Generator. 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: ModelGenerator.java    From NewsRecommendSystem with MIT License 6 votes vote down vote up
/**
 * @param dataSource
 * @param baseModelPackageName
 * @param baseModelOutputDir
 * @param modelPackageName
 * @param modelOutputDir
 */
public static void main(String[] args)
{
	// base model 所使用的包名
	String baseModelPackageName = "top.qianxinyao.model.base";
	// base model 文件保存路径
	String baseModelOutputDir = PathKit.getRootClassPath() + "/../../src/top/qianxinyao/model/base";
	System.out.println("rootclasspath:"+baseModelOutputDir);
	// model 所使用的包名 (MappingKit 默认使用的包名)
	String modelPackageName = "top.qianxinyao.model";
	// model 文件保存路径 (MappingKit 与 DataDictionary 文件默认保存路径)
	String modelOutputDir = baseModelOutputDir+"/..";
	System.out.println(baseModelOutputDir);
	// 创建生成器
	Generator gernerator = new Generator(DBKit.getDataSource(), baseModelPackageName, baseModelOutputDir,
			modelPackageName, modelOutputDir);
	gernerator.setDialect(new MysqlDialect());
	// 设置是否在 Model 中生成 dao 对象
	gernerator.setGenerateDaoInModel(true);
	// 设置是否生成字典文件
	gernerator.setGenerateDataDictionary(false);
	// 生成
	gernerator.generate();
}
 
Example #2
Source File: JfinalModelClient.java    From my_curd with Apache License 2.0 6 votes vote down vote up
public static void main(String[] args) {
    Generator generator = new Generator(MysqlDataSourceUtils.getDataSource(), baseModelPkg, baseModelDir, modelPkg, modelDir);
    generator.setDialect(new MysqlDialect());
    // 链式
    generator.setGenerateChainSetter(true);
    // model 中生成 dao 对象
    generator.setGenerateDaoInModel(true);

    // 数据字典
    generator.setGenerateDataDictionary(true);
    generator.setDataDictionaryFileName("dict.txt");
    generator.setDataDictionaryOutputDir(baseModelDir); // base 包下
    generator.setGenerateRemarks(true); // baseModel 字段是否生成注释

    // 添加不需要生成的表名
    // generator.addExcludedTable("adv");
    // 设置需要被移除的表名前缀用于生成modelName。例如表名 "osc_user",移除前缀 "osc_"后生成的model名为 "User"而非 OscUser
    // generator.setRemovedTableNamePrefixes("t_");
    //generator.addExcludedTable("SYS_USER_BAK");

    generator.generate();
}
 
Example #3
Source File: _JFinalDemoGenerator.java    From sqlhelper with GNU Lesser General Public License v3.0 5 votes vote down vote up
public static void main(String[] args) {
	// base model 所使用的包名
	String baseModelPackageName = "com.demo.common.model.base";
	// base model 文件保存路径
	String baseModelOutputDir = PathKit.getWebRootPath() + "/src/main/java/com/demo/common/model/base";
	
	// model 所使用的包名 (MappingKit 默认使用的包名)
	String modelPackageName = "com.demo.common.model";
	// model 文件保存路径 (MappingKit 与 DataDictionary 文件默认保存路径)
	String modelOutputDir = baseModelOutputDir + "/..";
	
	// 创建生成器
	Generator generator = new Generator(getDataSource(), baseModelPackageName, baseModelOutputDir, modelPackageName, modelOutputDir);
	
	// 配置是否生成备注
	generator.setGenerateRemarks(true);
	
	// 设置数据库方言
	generator.setDialect(new MysqlDialect());
	
	// 设置是否生成链式 setter 方法
	generator.setGenerateChainSetter(false);
	
	// 添加不需要生成的表名
	generator.addExcludedTable("adv");
	
	// 设置是否在 Model 中生成 dao 对象
	generator.setGenerateDaoInModel(false);
	
	// 设置是否生成字典文件
	generator.setGenerateDataDictionary(false);
	
	// 设置需要被移除的表名前缀用于生成modelName。例如表名 "osc_user",移除前缀 "osc_"后生成的model名为 "User"而非 OscUser
	generator.setRemovedTableNamePrefixes("t_");
	
	// 生成
	generator.generate();
}
 
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 void main(String[] args) {

        String rootPath = PathKit.getWebRootPath();

		// base model 所使用的包名
		String baseModelPackageName = "io."+PK_NAME+".model.base";
		// base model 文件保存路径
		String baseModelOutputDir = rootPath + "/src/main/java/io/"+PK_NAME+"/model/base";


		// model 所使用的包名 (MappingKit 默认使用的包名)
		String modelPackageName = "io."+PK_NAME+".model";
		// model 文件保存路径 (MappingKit 与 DataDictionary 文件默认保存路径)
		String modelOutputDir = baseModelOutputDir + "/..";

		// 创建生成器
		Generator gernerator = new Generator(getDataSource(), baseModelPackageName, baseModelOutputDir, modelPackageName, modelOutputDir);


		MetaBuilder mataBuilder = new MetaBuilder(getDataSource());

		mataBuilder.addExcludedTable(excludedTable);

		gernerator.setMetaBuilder(mataBuilder);

		// 添加不需要生成的表名
//		gernerator.addExcludedTable("order_coupon");
		// 设置是否在 Model 中生成 dao 对象
		gernerator.setGenerateDaoInModel(true);
		// 设置是否生成字典文件
		gernerator.setGenerateDataDictionary(false);
		// 设置需要被移除的表名前缀用于生成modelName。例如表名 "osc_user",移除前缀 "osc_"后生成的model名为 "User"而非 OscUser
		gernerator.setRemovedTableNamePrefixes("tb_");
		gernerator.generate();

		//代码生成
        _JFCodeGenerator.me.generate();
	}