📄 htdldtrwlbdao.java
字号:
//selectFzxx
public List selectFzxx() throws TaxBaseSystemException {
return selectAll("T_HTDL_DTDDRW.selectFzxx", null);
}
//更新指定任务的当前状态
//rw_xh: 指定的任务序号
//zt:新的任务状态
public int updateZt(String zt, String rw_xh) throws TaxBaseSystemException {
HashMap para = new HashMap();
para.put("zt", new String(zt));
para.put("rw_xh", new String(rw_xh));
return update("T_HTDL_DTDDRW.updateZt", para);
}
//查询当天任务列表中是否存在当前状态为“执行中...”的任务,返回记录个数
public int countDtrwbyZt(String zt, ArrayList rwList) throws
TaxBaseSystemException {
List tmpList = null;
HashMap para = new HashMap();
para.put("zt", zt);
if (rwList != null) {
StringBuffer rwxh = new StringBuffer();
for (int i = 0; i < rwList.size(); i++) {
rwxh.append("'");
rwxh.append(rwList.get(i));
rwxh.append("'");
if (i != rwList.size() - 1) {
rwxh.append(",");
}
}
System.out.println(rwxh.toString());
para.put("rwList", new String(rwxh));
} else {
para.put("rwList", new String(""));
}
tmpList = selectAll("T_HTDL_DTDDRW.countDtrwbyZt", para);
return ((Integer) tmpList.get(0)).intValue();
}
//删除当天任务表中指定任务序号的任务
public int deleteDtrwBatch(ArrayList rwList) throws TaxBaseSystemException {
StringBuffer rwxh = new StringBuffer();
for (int i = 0; i < rwList.size(); i++) {
rwxh.append("'");
rwxh.append(rwList.get(i));
rwxh.append("'");
if (i != rwList.size() - 1) {
rwxh.append(",");
}
}
return delete("T_HTDL_DTDDRW.delDtrwBatch", new String(rwxh));
}
//取属于分组fz的第一条记录(按照优先级从高到低排列)
public List getOneDtrwByFz(String fz) throws TaxBaseSystemException {
return selectAll("T_HTDL_DTDDRW.getOneDtrwByFz", fz);
}
//取属于分组fz的第一条未执行的任务(按照优先级从高到低排列),同时更新该任务的状态为“执行中”
//取数的时候锁定该记录
// to be modified
public HTDLdtrwVO getOneDtrwByFz_synchronize(String fz) throws TaxBaseSystemException {
HTDLdtrwVO retVO = null;
this.getSqlMapClient(); //用父类方法获取sqlMap对象
Connection connection = null;
boolean defaultCommit = false;
try {
connection = JDBCLocator.getInstance().getJDBCConnection();
sqlMap.setUserConnection(connection);
defaultCommit = connection.getAutoCommit();
connection.setAutoCommit(false);
//得到第一条未执行的任务,并锁定该条记录(select * for update)
System.out.println("===============before lock recorders: select * for update in get the first task!========================");
sqlMap.queryForList("T_HTDL_DTDDRW.getOneDtrwByFz_lock", fz); //lock recorders
retVO = (HTDLdtrwVO) sqlMap.queryForObject(
"T_HTDL_DTDDRW.getOneDtrwByFz", fz);
System.out.println("==============return from get the first task===========================");
// HashMap param = new HashMap();
// param.put("zb",new String(fz));
// param.put("xh",new String(""));
// sqlMap.queryForObject("T_HTDL_DTDDRW.getOneDtrwByFz_update",param);
// System.out.println("====================xh:"+param.get("xh"));
//如果有记录的话,则修改该任务的状态为“执行中”
if (retVO != null) {
String rwxh = retVO.getRw_xh();
System.out.println("==============the first task is:"+rwxh+"===============");
HashMap para = new HashMap();
para.put("zt", new String("1")); //执行中
para.put("rw_xh", new String(rwxh));
int rows = sqlMap.update("T_HTDL_DTDDRW.updateZt", para);
System.out.println("=============after update task "+rwxh+" zt=============================");
} else {
System.out.println("==============the first task is null===============");
}
connection.commit();
System.out.println("==============unlock the recorders after commit.===============");
} catch (SQLException e) {
LogWritter.sysError("Exception in getOneDtrwByFz2!" + e.getMessage());
try {
if (connection != null) {
connection.rollback();
}
} catch (SQLException ex) {
LogWritter.sysError("YCHTDL:Exception in getOneDtrwByFz2!!" +
e.getMessage()); //mod
}
} finally {
try {
if (connection != null) {
connection.commit();
connection.setAutoCommit(defaultCommit);
connection.close();
}
} catch (SQLException e) {
LogWritter.sysError("YCHTDL:Exception in getOneDtrwByFz2!!" +
e.getMessage()); //mod
}
}
return retVO;
}
//查询用于自动调度的定时器是否启动,如果启动则返回true,否则为false
public boolean isTimerRunning() throws TaxBaseSystemException {
boolean result = false;
String state = (String) select2("T_HTDL_DTDDRW.getTimerState", null);
if ("1".equals(state)) {
result = true;
}
return result;
}
//如果定时器的启动标记为“未启动”,则更改数据库中定时器的启动标记为“已启动”,并返回true
//否则返回false
public boolean setTimerStarted() {
boolean result = false;
String state;
System.out.println(
"==================1 in setTimerStarted!==============");
this.getSqlMapClient(); //用父类方法获取SqlMap对象
System.out.println(
"==================in setTimerStarted!==============");
Connection connection = null;
boolean defaultCommit = false;
try {
connection = JDBCLocator.getInstance().getJDBCConnection();
sqlMap.setUserConnection(connection);
defaultCommit = connection.getAutoCommit();
connection.setAutoCommit(false);
//先lock table
System.out.println("==================before lock!==============");
sqlMap.queryForObject("T_HTDL_DTDDRW.lockTable", null);
System.out.println("==================after lock!==============");
//检查定时器是否启动
state = (String) sqlMap.queryForObject(
"T_HTDL_DTDDRW.getTimerState", null);
System.out.println("&&&&&&&&&&&&&&&&&&state:" + state);
//"未启动"
if (!("1".equals(state))) {
result = true;
sqlMap.update("T_HTDL_DTDDRW.changeTimerState", "1");
}
connection.commit();
// result = true;
} catch (SQLException e) {
System.out.println("==================in catch 1!==============");
LogWritter.sysError("Exception in setTimerStarted!" + e.getMessage());
try {
if (connection != null) {
connection.rollback();
}
} catch (SQLException ex) {
LogWritter.sysError("YCHTDL:Exception in setTimerStarted!!" +
e.getMessage()); //mod
}
} finally {
System.out.println("==================in finally!==============");
try {
if (connection != null) {
connection.setAutoCommit(defaultCommit);
connection.close();
}
} catch (SQLException e) {
LogWritter.sysError("YCHTDL:Exception in setTimerStarted!!" +
e.getMessage()); //mod
}
}
return result;
}
//如果定时器的启动标记为“已启动”,则更改数据库中定时器的启动标记为“未启动”,并返回true
//否则返回false
public boolean setTimerStopped() {
boolean result = false;
String state;
this.getSqlMapClient(); //用父类方法获取SqlMap对象
System.out.println(
"=================in setTimerStopped!==========================");
Connection connection = null;
try {
connection = JDBCLocator.getInstance().getJDBCConnection();
sqlMap.setUserConnection(connection);
//先lock table
sqlMap.queryForObject("T_HTDL_DTDDRW.lockTable", null);
//检查定时器是否启动
state = (String) sqlMap.queryForObject(
"T_HTDL_DTDDRW.getTimerState", null);
System.out.println("&&&&&&&&&&&&&&&&&&state:" + state +
"&&&&&&&&&&&&&&&");
//"已启动"
if (!("0".equals(state))) {
result = true;
sqlMap.update("T_HTDL_DTDDRW.changeTimerState", "0");
}
connection.commit(); //commit的时候会unlock table
} catch (SQLException e) {
LogWritter.sysError("Exception in setTimerStopped!" + e.getMessage());
try {
if (connection != null) {
connection.rollback();
}
} catch (SQLException ex) {
LogWritter.sysError("YCHTDL:Exception in setTimerStopped!" +
e.getMessage()); //mod
}
} finally {
try {
if (connection != null) {
connection.close();
}
} catch (SQLException e) {
LogWritter.sysError("YCHTDL:Exception in setTimerStopped!" +
e.getMessage()); //mod
}
}
return result;
}
//
// public boolean resetCleaner()
//for test
public static void main(String args[]) throws TaxBaseSystemException {
HTDLdtrwlbDAO dtrwlbDAO = new HTDLdtrwlbDAO();
// HTDLreturnVO retVO = new HTDLreturnVO();
// retVO.setProcName("test01");
// try {
// dtrwlbDAO.execDtrw(retVO);
// } catch (Exception e) {
// System.out.println("------in exception ---------");
// System.out.println(e.toString());
// }
// System.out.println(retVO.getStatus());
// System.out.println(retVO.getDetail());
// List fzList = dtrwlbDAO.selectFzxx();
// System.out.println("共有"+fzList.size()+"个分组信息");
//
// ArrayList tmp = new ArrayList();
// tmp.add(new String("152"));
// int result = dtrwlbDAO.countDtrwbyZt("1",tmp);
// System.out.println(result);
boolean result = dtrwlbDAO.setTimerStarted();
if (result) {
System.out.println("success");
} else {
System.out.println("failure");
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -