123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129 |
- package com.sinosoft.cm.impl;
- import java.sql.Connection;
- import java.sql.PreparedStatement;
- import java.sql.ResultSet;
- import java.sql.SQLException;
- import java.util.HashMap;
- import java.util.List;
- import java.util.Map;
- import org.apache.log4j.Logger;
- import com.sinosoft.cm.CMTemplate;
- import com.sinosoft.cm.DBUtils;
- import com.sinosoft.cm.common.StringUtils;
- import com.sinosoft.cm.ex.SQLStringException;
- public class IntelligenceDao {
- private CMTemplate cmt=null;
- private Map<String,String> map=null;
- private Logger log=Logger.getLogger(this.getClass());
- public IntelligenceDao() {
- cmt=new CMTemplate();
- map=new HashMap<String, String>();
- map.put("getIntelligen", "SELECT A.FD_OBJECTID FD_OBJECTID,A.PLANKINFO PLANKINFO,A.PLANKDATE PLANKDATE,B.TITLENAME TITLENAME "
- + "FROM NWYJ.ECM_CM_PLANKINFO A,NWYJ.ECM_CM_PLANKTITLE B "
- + "WHERE A.PLANKTITLEID=B.FD_OBJECTID AND B.UPDATEDATE IN "
- + "(SELECT MAX(UPDATEDATE) FROM NWYJ.ECM_CM_PLANKTITLE WHERE IS_DEL='0') ORDER BY A.UPDATEDATE ASC;");
- map.put("findTitle", "SELECT FD_OBJECTID,TITLENAME,IS_DEL,UPDATEDATE FROM NWYJ.ECM_CM_PLANKTITLE WHERE IS_DEL='0' AND TITLENAME=?;");
- map.put("getTitle", "SELECT TITLENAME,FD_OBJECTID FROM NWYJ.ECM_CM_PLANKTITLE WHERE IS_DEL='0'");
- map.put("getIntelligence", "SELECT A.FD_OBJECTID FD_OBJECTID,A.PLANKINFO PLANKINFO,A.PLANKDATE PLANKDATE,B.TITLENAME TITLENAME "
- + "FROM NWYJ.ECM_CM_PLANKINFO A,NWYJ.ECM_CM_PLANKTITLE B WHERE B.FD_OBJECTID=A.PLANKTITLEID AND B.FD_OBJECTID=? ");
- map.put("insertInfo", "INSERT INTO NWYJ.ECM_CM_PLANKINFO(FD_OBJECTID, PLANKTITLEID, PLANKINFO, PLANKDATE, UPDATEDATE)"
- + " VALUES(sq_num.NEXTVAL,?,?,?,SYSDATE());");
- map.put("getInfo", "SELECT FD_OBJECTID,PLANKTITLEID,PLANKINFO,PLANKDATE,IS_DEL,UPDATEDATE "
- + "FROM NWYJ.ECM_CM_PLANKINFO WHERE FD_OBJECTID=?;");
- map.put("update","UPDATE NWYJ.ECM_CM_PLANKINFO SET PLANKINFO=?,PLANKDATE=? WHERE FD_OBJECTID=?");
- map.put("delete","DELETE NWYJ.ECM_CM_PLANKINFO WHERE FD_OBJECTID in (_?_)");
-
- }
- public int updateIN(String sqlName ,String args){
- try {
- log.info("======update(String sqlName ,Object ...args)==sql="+map.get(sqlName));
- if(map.get(sqlName).toLowerCase()==null&&"".equals(map.get(sqlName).trim()))
- throw new SQLStringException("查询语句为空");
-
- return cmt.update(map.get(sqlName).replace("_?_", args));
- } catch (SQLException e) {
- e.printStackTrace();
- return 0;
- }
- }
-
-
-
- public int update(String sqlName ,Object ...args){
- try {
- log.info("======update(String sqlName ,Object ...args)==sql="+map.get(sqlName));
- if(map.get(sqlName).toLowerCase()==null&&"".equals(map.get(sqlName).trim()))
- throw new SQLStringException("查询语句为空");
- return cmt.update(map.get(sqlName), args);
- } catch (SQLException e) {
- e.printStackTrace();
- return 0;
- }
- }
- public List<Map<String,String>> findAll(String sqlName,Object...args) throws SQLStringException{
- List<String> list=StringUtils.sqlStringToListLabel(map.get(sqlName).trim().toUpperCase(), ",");
- log.info("======findAll(String sqlName,Object...args)==sqlLabel="+list);
- if(map.get(sqlName).toLowerCase()==null&&"".equals(map.get(sqlName).trim()))
- throw new SQLStringException("查询语句为空");
- log.info("======findAll(String sqlName,Object...args)==sql="+map.get(sqlName).trim().toUpperCase());
- return cmt.queryMoreTypeToMap(map.get(sqlName), list, args);
- }
-
- public String insert(String title)throws SQLStringException{
- //没有当前title自动添加
- String setDel="UPDATE NWYJ.ECM_CM_PLANKTITLE SET IS_DEL='1';";
- //自动插入
- String insertTitle="INSERT INTO NWYJ.ECM_CM_PLANKTITLE(FD_OBJECTID,TITLENAME,IS_DEL,UPDATEDATE) VALUES(sq_num.NEXTVAL,?,'0',SYSDATE());";
- //查找
- String findTitle="SELECT FD_OBJECTID FROM NWYJ.ECM_CM_PLANKTITLE WHERE TITLENAME=? AND IS_DEL='0'";
- Connection conn=null;
- PreparedStatement ps=null;
- ResultSet rs=null;
- String result=null;
- try {
- conn=DBUtils.getConnection();
- conn.setAutoCommit(false);
- ps=conn.prepareStatement(setDel);
- ps.executeUpdate();
- ps=conn.prepareStatement(insertTitle);
- ps.setString(1, title);
- ps.executeUpdate();
- ps=conn.prepareStatement(findTitle);
- ps.setString(1, title);
- rs=ps.executeQuery();
-
- while(rs.next()){
- result=rs.getString(1);
- }
- conn.commit();
- } catch (Exception e) {
- log.info(e.getMessage());
- try {
- conn.rollback();
- } catch (SQLException e1) {
- log.info(e1.getMessage());
- }
- return null;
- }finally{
- DBUtils.close(rs, ps, conn);
- return result;
- }
- }
-
- public static void main(String[] args) {
- IntelligenceDao dao=new IntelligenceDao();
- try {
- System.out.println("===="+dao.insert("ASDFASDF"));
- } catch (SQLStringException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
- }
- }
|