📄 commandbizatomstatement.java
字号:
package com.exp.bizatom.auto.statement;
import java.util.List;
import com.exp.bizatom.BizDataAdapter;
import com.exp.bizatom.SQLConverter;
import com.exp.bizatom.auto.BizAutoAtomLogic;
import com.exp.bizatom.auto.BizAutoAtomUtil;
import com.exp.bizatom.auto.FunctionStack;
import com.exp.dao.DBConnection;
import com.exp.dao.EXPSQLException;
import com.exp.dao.PageInfo;
import com.exp.fcl.vo.CommonVO;
import com.exp.fcl.vo.VOList;
import com.exp.fcl.xml.EXPXMLNode;
/**
*
* @author Administrator <BR>
* 数据库命令语句 <br>
* 格式: <BR>
* <command type="save|list|vo|page|seq|scaler" <br>
* id="SQL语句ID,对应sqls区;必须" <br>
* param="参数对象,可选" <br>
* set-var="操作结果存放变量,可选" <br>
* pagesize="分页查询时每页记录条数,可选" <br>
* pageindex="当前页码,可选" <br>
* />
*/
public class CommandBizAtomStatement extends BizAtomStatement {
protected String type;
protected String param;
protected String id;
protected String setVar;
protected String pageSize;
protected String pageIndex;
protected String dataSource = "";
protected void parse(EXPXMLNode node) {
this.type = node.getAttributeValue("type");
this.param = node.getAttributeValue("param");
this.id = node.getAttributeValue("id");
this.setVar = node.getAttributeValue("set-var");
this.pageSize = node.getAttributeValue("pagesize");
this.pageIndex = node.getAttributeValue("pageindex");
this.dataSource = node.getAttributeValue("datasource");
}
public Object create() {
CommandBizAtomStatement ret = new CommandBizAtomStatement();
ret.type = this.type;
ret.param = this.param;
ret.id = this.id;
ret.setVar = this.setVar;
ret.pageSize = this.pageSize;
ret.pageIndex = this.pageIndex;
return ret;
}
public int execute(BizAutoAtomLogic function, int row)
throws java.lang.Throwable {
boolean bCustomDS = false;
FunctionStack stack = function.getStack();
BizDataAdapter dataAdapter = function.getDataAdapter();
if (!"".equals(this.dataSource)) {
DBConnection connection = function.getOwner().newDBConnection(
this.dataSource);
dataAdapter.setDBConnection(connection);
bCustomDS = true;
}
try {
Object paramObj = BizAutoAtomUtil.getRealValue(stack, this.param);
if (type.equalsIgnoreCase("save")) {
stack.setVariable(this.setVar, handleSave(stack, dataAdapter,
paramObj));
} else if (type.equalsIgnoreCase("list")) {
stack.setVariable(this.setVar, dataAdapter
.getList(id, paramObj));
} else if (type.equalsIgnoreCase("vo")) {
stack.setVariable(this.setVar, dataAdapter.getVO(id, paramObj));
} else if (type.equalsIgnoreCase("scaler")) {
stack.setVariable(this.setVar, dataAdapter.getString(id,
paramObj));
} else if (type.equalsIgnoreCase("seq")) {
int sepIndex = this.setVar.indexOf(".");
if (sepIndex > 0) {
String pop = this.setVar.substring(sepIndex + 1);
Object lst = stack.getVariable(this.setVar.substring(0,
sepIndex));
if (lst != null && BizAutoAtomUtil.isList(lst)) {
if (lst instanceof VOList) {
VOList voList = (VOList) lst;
int size = voList.count();
for (int i = 0; i < size; i++) {
CommonVO vo = voList.get(i);
vo.setString(pop, dataAdapter.getSeq(id));
}
}
if (lst instanceof List) {
List tempList = (List) lst;
int size = tempList.size();
for (int i = 0; i < size; i++) {
Object vo = tempList.get(i);
SQLConverter.setProperty(pop, dataAdapter
.getSeq(id), vo);
}
}
} else {
SQLConverter.setProperty(pop, dataAdapter.getSeq(id),
lst);
}
} else {
stack.setVariable(this.setVar, dataAdapter.getSeq(id));
}
} else if (type.equalsIgnoreCase("page")) {
Object temp = BizAutoAtomUtil.getRealValue(stack,
this.pageIndex);
String realPageIndex = "1";
if (null != temp) {
realPageIndex = temp.toString();
if ("".equals(realPageIndex)) {
realPageIndex = "1";
}
}
temp = BizAutoAtomUtil.getRealValue(stack, this.pageSize);
String realPageSize = "";
if (temp != null) {
realPageSize = temp.toString();
}
PageInfo pageInfo = null;
if ("".equals(realPageSize)) {
pageInfo = dataAdapter.getPageData(this.id, paramObj,
Integer.valueOf(realPageIndex).intValue());
} else {
pageInfo = dataAdapter.getPageData(this.id, paramObj,
Integer.valueOf(realPageIndex).intValue(), Integer
.valueOf(realPageSize).intValue());
}
if (pageInfo != null) {
stack.setVariable(this.setVar, pageInfo.list);
stack.setVariable(this.setVar + "-pageinfo", pageInfo);
stack.setVariable(this.setVar + "-pagecount", ""
+ pageInfo.pageCount);
stack.setVariable(this.setVar + "-rowcount", ""
+ pageInfo.rowCount);
}
}
return 1;
} finally {
if (bCustomDS) {
dataAdapter.reset();
}
}
}
private String handleSave(FunctionStack stack, BizDataAdapter dataAdapter,
Object paramObj) throws EXPSQLException {
if (paramObj != null) {
return "" + dataAdapter.save(this.id, paramObj);
} else {
throw new RuntimeException("根据[" + this.param + "]定位不到可用变量!");
}
}
public String getId() {
return id;
}
public String getParam() {
return param;
}
public String getSetVar() {
return setVar;
}
public String getType() {
return type;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -