You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
60 lines
2.2 KiB
60 lines
2.2 KiB
9 months ago
|
package com.dsideal.base.Test;
|
||
|
|
||
|
import com.dsideal.base.Plugin.YamlProp;
|
||
|
import com.jfinal.kit.Kv;
|
||
|
import com.jfinal.kit.Prop;
|
||
|
import com.jfinal.plugin.activerecord.ActiveRecordPlugin;
|
||
|
import com.jfinal.plugin.activerecord.Db;
|
||
|
import com.jfinal.plugin.activerecord.SqlPara;
|
||
|
import com.jfinal.plugin.activerecord.dialect.MysqlDialect;
|
||
|
import com.jfinal.plugin.hikaricp.HikariCpPlugin;
|
||
|
import com.jfinal.plugin.activerecord.Record;
|
||
|
|
||
|
import java.io.File;
|
||
|
import java.util.List;
|
||
|
|
||
|
public class TestDataSet {
|
||
|
public static void main(String[] args) {
|
||
|
//加载配置文件
|
||
|
String configFile = "application_dataease.yaml";
|
||
|
Prop PropKit = new YamlProp(configFile);
|
||
|
HikariCpPlugin arpPlugin = new HikariCpPlugin(PropKit.get("mysql.jdbcUrl"), PropKit.get("mysql.user"),
|
||
|
PropKit.get("mysql.password").trim(), PropKit.get("mysql.driverClassName"));
|
||
|
arpPlugin.start();
|
||
|
|
||
|
// 配置ActiveRecord插件
|
||
|
ActiveRecordPlugin arp = new ActiveRecordPlugin("master", arpPlugin);
|
||
|
arp.setDialect(new MysqlDialect());
|
||
|
|
||
|
//遍历sql目录下所有的sql文件
|
||
|
File sqlDir;
|
||
|
String basePath = TestDataSet.class.getResource("/").getPath();
|
||
|
sqlDir = new File(basePath + "/Sql");
|
||
|
File[] sqlFiles = sqlDir.listFiles();
|
||
|
for (File sqlFile : sqlFiles != null ? sqlFiles : new File[0]) {
|
||
|
//只加载.sql文件
|
||
|
if (sqlFile.getName().indexOf(".sql") > 0) {
|
||
|
arp.addSqlTemplate("/Sql/" + sqlFile.getName());
|
||
|
}
|
||
|
}
|
||
|
arp.start();
|
||
|
|
||
|
//1、获取树根
|
||
|
SqlPara sqlPara = Db.getSqlPara("DataEase.getTreeRoot");
|
||
|
Record rRoot = Db.findFirst(sqlPara);
|
||
|
long rootId = rRoot.getLong("id");
|
||
|
|
||
|
//2、查询有哪些数据集
|
||
|
Kv kv = Kv.by("id", rootId);
|
||
|
kv.set("dataset",true);
|
||
|
sqlPara = Db.getSqlPara("DataEase.getAllDataSet", kv);
|
||
|
List<Record> list= Db.find(sqlPara);
|
||
|
|
||
|
for (Record record : list) {
|
||
|
long id= record.getLong("id");
|
||
|
String name= record.getStr("name");
|
||
|
System.out.println(name);
|
||
|
}
|
||
|
}
|
||
|
}
|