nutzam / nutz

Nutz -- Web Framework(Mvc/Ioc/Aop/Dao/Json) for ALL Java developer
https://nutzam.com
Apache License 2.0
2.53k stars 942 forks source link

FileSqlManager实现动态扫描sql文件目录,使sql在编译完启动后依然能修改维护 #1350

Open jeasonsilver opened 7 years ago

jeasonsilver commented 7 years ago

继承FileSqlManager 类复写get方法。实现每次提交请求到后端查询sql文件下的语句之前都重新扫描sql文件目录下的所有sql,这样可以在项目在服务器运行时程序员动态维护优化sql语句并且不用从新百衲衣重启项目

import org.nutz.dao.SqlNotFoundException;
import org.nutz.dao.impl.FileSqlManager;
import org.nutz.ioc.loader.annotation.IocBean;

@IocBean
public class FileScanSqlManager extends FileSqlManager {

    public FileScanSqlManager() {
    }

    public FileScanSqlManager(String... paths) {
        this.paths = paths;
        super.refresh();
    }

    @Override
    public String get(String key) throws SqlNotFoundException {
        sqls.clear();
        super.refresh();
       return super.get(key);
    }
}
wendal commented 7 years ago

加个配置项,每次都reload

wendal commented 7 years ago

下个版本提升到JDK7的时候用watchable来实现更好一些