atitit.新增编辑功能 跟orm的实现 attilax p31
1. 流程的实现 1
2. view的实现(dwr) 1
3. 获取表结构 1
4. grep filt req params 2
5. 转换成个atiorm map 3
6. 转换成个sql 4
7. 参考 4
1. 流程的实现
传统的orm的问题::不能动态insert... myeclipse到是容易的...要是eclispe走麻烦的兰...
在说,cant 动态添加字段,要同步修改domain文件...
所以,atiorm 使用表格结构来做orm不走ok兰???
获得req参数,组成对象...
过滤table不存在的字段...
转换为sql
add/update的实现不在ui上指定,使用模式,,通过oid来有判断力的add还是edit
作者:: 老哇的爪子 Attilax 艾龙, EMAIL:[email protected]
转载请注明来源: http://blog.csdn.net/attilax
2. view的实现(dwr)
隐藏控件_meth=orm
在的控件都是对象 fld
3. 获取表结构
位置:wechat4propty
public class DbX {
/**
@author attilax 老哇的爪子
@since p31 j_o_53
*/
public static List getColsList(Connection con, String table) {
List li=new ArrayList();
// TODO Auto-generated method stub
String tableName=table;
DatabaseMetaData dbmd;
try {
dbmd = con.getMetaData();
} catch (SQLException e2) {
// TODO Auto-generated catch block
e2.printStackTrace();
throw new RuntimeException(e2);
}
ResultSet rs;
try {
rs = dbmd.getColumns(con.getCatalog(), "%", tableName, null);
} catch (SQLException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
throw new RuntimeException(e1);
}
try {
while(rs.next()) {
String columnName = rs.getString("COLUMN_NAME");
li.add(columnName);
// String columnType = rs.getString("TYPE_NAME");
// int datasize = rs.getInt("COLUMN_SIZE");
// int digits = rs.getInt("DECIMAL_DIGITS");
// int nullable = rs.getInt("NULLABLE");
// System.out.println(columnName+" "+columnType+" "+datasize+" "+digits+" "+
// nullable);
// }
}
} catch (SQLException e) {
e.printStackTrace();
throw new RuntimeException(e);
}
return li;
}
4. grep filt req params
/**
* @author attilax 老哇的爪子
* @since p31 h_43_3
*/
private Map filtField(Map m) {
JSONObject metadata = JSONObject.fromObject(m.get("_metadata"));
String table = (String) metadata.get("table");
Connection conn = (Connection) core.retry3(new Closure() {
@Override
public Object execute(Object arg0) throws Exception {
Connection conn2 = AaaCfg.IocX.getBean(Connection.class);
boolean b = DbX.checkConn(conn2);
if (b)
return conn2;
else
throw new RuntimeException(" conn is close maybe ");
}
}, new errEventProcess() {
@Override
public Object execute(Object arg0) throws Exception {
// TODO Auto-generated method stub
return null;
}
}, "c:\\getconn");
List li = DbX.getColsList(conn, table);
Map m2 = Mapx.grep(m, li);
return m2;
}
5. 转换成个atiorm map
/**
* @author attilax 老哇的爪子
* @since p31 h_37_2
*/
protected Map convert2atiormMap(Object arg0) {
Map m = (Map) arg0;
Map m_filted_fld = filtField(m);
JSONObject metadata = JSONObject.fromObject(m.get("_metadata"));
Map m2 = new HashMap();
m2.put("datatype", metadata.get("table"));
m2.put("op", metadata.get("op"));
m2.put("field", m_filted_fld);
return m2;
}
6. 转换成个sql
Command.reg("orm", new Closure2() {
@Override
public Object execute(Object arg0) {
Map m2 = convert2atiormMap(m);
Object sql = new OrmX().convert2sql(core.toJsonStrO88(m2));
7. 参考
java 获取表结构 - HouYing - 博客频道 - CSDN.NET.htm