public void init(NutConfig conf) {
Ioc ioc = conf.getIoc();
dao = ioc.get(Dao.class,"dao");
((NutDao) dao).setSqlManager(new FileSqlManager("sqls/base_views.sql","sqls/query.sql"));
// ecache
CacheManager cacheManager = ioc.get(CacheManager.class);
CachedNutDaoExecutor.DEBUG = true;// 开启详细日志
//log.debug("Ehcache CacheManager = " + cacheManager);
}
dao.js
var ioc = {
conf : {
type : "org.nutz.ioc.impl.PropertiesProxy",
fields : {
paths : [ "customer/" ]
// 获取customer文件下配置
}
},
dataSource : {
type : "com.alibaba.druid.pool.DruidDataSource",
events : {
create : "init",
depose : 'close'
},
fields : {
url : {
java : "$conf.get('db.url')"
},
username : {
java : "$conf.get('db.username')"
},
password : {
java : "$conf.get('db.password')"
},
testWhileIdle : true,
validationQuery : {
java : "$conf.get('db.validationQuery')"
},
maxActive : {
java : "$conf.get('db.maxActive')"
},
filters : "mergeStat",// mergeStat是带合并的sql状态过滤器
connectionProperties : "druid.stat.slowSqlMillis=2000"// 2000代表如果sql执行超过2秒,就输出日志
}
},
dao : {
type : "org.nutz.dao.impl.NutDao",
args : [ {
refer : "dataSource"
} ],
fields : {
executor : {
refer : "cacheExecutor"
}
}
},
cacheExecutor : {
type : "org.nutz.plugins.cache.dao.CachedNutDaoExecutor",
fields : {
cacheProvider : {
refer : "cacheProvider"
},
// 需要缓存的表名
cachedTableNames : [
// "accounts","users", "roles", "permissions", "role_permission","divisions","organs"
],
enableWhenTrans : false, // 事务作用域内是否启用,默认false
cache4Null : true // 是否缓存空值,默认true
}
},
/*
// 基于内存的简单LRU实现
cacheProvider : {
type : "org.nutz.plugins.cache.dao.impl.provider.MemoryDaoCacheProvider",
fields : {
cacheSize : 10000 // 缓存的对象数
},
events : {
create : "init"
}
}
*/
// 基于Ehcache的DaoCacheProvider
cacheProvider : {
type : "org.nutz.plugins.cache.dao.impl.provider.EhcacheDaoCacheProvider",
fields : {
cacheManager : {
refer : "cacheManager"
}
// 引用ehcache.js中定义的CacheManager
},
events : {
create : "init"
}
}
};