ServiceFramework
ServiceFramework copied to clipboard
关于缓存和事务和jetty的问题
@allwefantasy
--) model和数据库交互之间是否有缓存的处理,可以先查缓存。 刚看到说可以使用hibernate的缓存 是通过配置文件还是什么方式实现
--) 事务的控制怎么实现的。有没有像AOP那样控制事务
--)有没有提供获取数据库连接的方法 通过@inject 获得MysqlClient或者MysqlClient client = ServiceFramwork.injector.getInstance(MysqlClient.class);方式获得mysqlclient 执行下面代码都会包getconnection()空指针。。 @At(path = "/user", types = POST) public void create_user() { MysqlClient client = ServiceFramwork.injector.getInstance(MysqlClient.class); String sql = "insert into user where name ="+param("name"); client.execute(sql); render(ok()); } client.execute(sql,params)这个方法怎么使用。。 --) jetty的部署是不是一定要内嵌到代码中么,这么仅仅是为了省去发布简化操作吗
- 对于缓存,我不建议使用Hibernate 的二级缓存。太复杂,局限太多。建议专门做个对象缓存或者结果缓存。
- 事务范围目前就是Action级别的(事实上应该能够满足大部分需求)。对事物的更多支持我也在思考中。欢迎探讨。
- 如果要使用Raw Sql 建议按如下方式使用:
List<Map> users = User.findBySql("select * from user where name=?","google");
//或者
User.nativeSqlClient().execute("insert into user where name = ?","google");
如果有更复杂的查询建议直接写成Model类一个方法或者放到Service里面去。 4 jetty 是和项目结合比较紧密的。目前不支持部署到tomcat 等容器中。因为ServiceFramework 目前是没有使用标准的Servlet 规范的。特点是 jetty 仅仅是一个模块,只做http 解析。
@allwefantasy --)无论是获得连接还是要执行sql必须要执行defaultMysqlServce()方法,不然会报空指针 例如 conn = nativeSqlClient.defaultMysqlService().dataSource().getConnection(); //所以 User.nativeSqlClient().execute("insert into user where name = ?","google");//我要写成才能执行 User.nativeSqlClient().defaultMysqlService().execute("insert into user where name = ?","google"); 请问是什么问题呢
--)client.execute(sql,params())第二个参数是params()方法获得的map 但此方法里面setParams(preparedStatement, params)的params是一个object数组的参数值 所以 nativeSqlClient.defaultMysqlService().execute(sql,params());会报错。我是把map中的value转换为object数组。 请问有便捷方法将参数动态传入吗
呵呵 你说的问题是存在的。这在于一些方法没有分开: MysqlClient 中 包含 "query" 且不包含 'execute '字样的方法都是 无需调用 defaultMysqlServic() 的。 凡是直接包含execute 则需要你说的那样调用,比如
User.nativeSqlClient().defaultMysqlService().execute("insert into user where name = ?","google");
这是设计的时候不严谨造成的。
关于参数传递的问题,因为设计的时候没有支持'命名参数',所以无法直接将map传入。而且将map中的value转换为数组 需要关心顺序问题。
至于更便捷的方式,就是添加命名参数,这样就能够直接接受 params()参数。方便程序使用。