fd1a527be5e5d0afaf634cf11127887f7d56d7cd.svn-base 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  1. package com.sinosoft.cm.impl;
  2. import java.sql.Connection;
  3. import java.sql.PreparedStatement;
  4. import java.sql.ResultSet;
  5. import java.sql.SQLException;
  6. import java.util.HashMap;
  7. import java.util.List;
  8. import java.util.Map;
  9. import org.apache.log4j.Logger;
  10. import com.sinosoft.cm.CMTemplate;
  11. import com.sinosoft.cm.DBUtils;
  12. import com.sinosoft.cm.common.StringUtils;
  13. import com.sinosoft.cm.ex.SQLStringException;
  14. public class IntelligenceDao {
  15. private CMTemplate cmt=null;
  16. private Map<String,String> map=null;
  17. private Logger log=Logger.getLogger(this.getClass());
  18. public IntelligenceDao() {
  19. cmt=new CMTemplate();
  20. map=new HashMap<String, String>();
  21. map.put("getIntelligen", "SELECT A.FD_OBJECTID FD_OBJECTID,A.PLANKINFO PLANKINFO,A.PLANKDATE PLANKDATE,B.TITLENAME TITLENAME "
  22. + "FROM NWYJ.ECM_CM_PLANKINFO A,NWYJ.ECM_CM_PLANKTITLE B "
  23. + "WHERE A.PLANKTITLEID=B.FD_OBJECTID AND B.UPDATEDATE IN "
  24. + "(SELECT MAX(UPDATEDATE) FROM NWYJ.ECM_CM_PLANKTITLE WHERE IS_DEL='0') ORDER BY A.UPDATEDATE ASC;");
  25. map.put("findTitle", "SELECT FD_OBJECTID,TITLENAME,IS_DEL,UPDATEDATE FROM NWYJ.ECM_CM_PLANKTITLE WHERE IS_DEL='0' AND TITLENAME=?;");
  26. map.put("getTitle", "SELECT TITLENAME,FD_OBJECTID FROM NWYJ.ECM_CM_PLANKTITLE WHERE IS_DEL='0'");
  27. map.put("getIntelligence", "SELECT A.FD_OBJECTID FD_OBJECTID,A.PLANKINFO PLANKINFO,A.PLANKDATE PLANKDATE,B.TITLENAME TITLENAME "
  28. + "FROM NWYJ.ECM_CM_PLANKINFO A,NWYJ.ECM_CM_PLANKTITLE B WHERE B.FD_OBJECTID=A.PLANKTITLEID AND B.FD_OBJECTID=? ");
  29. map.put("insertInfo", "INSERT INTO NWYJ.ECM_CM_PLANKINFO(FD_OBJECTID, PLANKTITLEID, PLANKINFO, PLANKDATE, UPDATEDATE)"
  30. + " VALUES(sq_num.NEXTVAL,?,?,?,SYSDATE());");
  31. map.put("getInfo", "SELECT FD_OBJECTID,PLANKTITLEID,PLANKINFO,PLANKDATE,IS_DEL,UPDATEDATE "
  32. + "FROM NWYJ.ECM_CM_PLANKINFO WHERE FD_OBJECTID=?;");
  33. map.put("update","UPDATE NWYJ.ECM_CM_PLANKINFO SET PLANKINFO=?,PLANKDATE=? WHERE FD_OBJECTID=?");
  34. map.put("delete","DELETE NWYJ.ECM_CM_PLANKINFO WHERE FD_OBJECTID in (_?_)");
  35. }
  36. public int updateIN(String sqlName ,String args){
  37. try {
  38. log.info("======update(String sqlName ,Object ...args)==sql="+map.get(sqlName));
  39. if(map.get(sqlName).toLowerCase()==null&&"".equals(map.get(sqlName).trim()))
  40. throw new SQLStringException("查询语句为空");
  41. return cmt.update(map.get(sqlName).replace("_?_", args));
  42. } catch (SQLException e) {
  43. e.printStackTrace();
  44. return 0;
  45. }
  46. }
  47. public int update(String sqlName ,Object ...args){
  48. try {
  49. log.info("======update(String sqlName ,Object ...args)==sql="+map.get(sqlName));
  50. if(map.get(sqlName).toLowerCase()==null&&"".equals(map.get(sqlName).trim()))
  51. throw new SQLStringException("查询语句为空");
  52. return cmt.update(map.get(sqlName), args);
  53. } catch (SQLException e) {
  54. e.printStackTrace();
  55. return 0;
  56. }
  57. }
  58. public List<Map<String,String>> findAll(String sqlName,Object...args) throws SQLStringException{
  59. List<String> list=StringUtils.sqlStringToListLabel(map.get(sqlName).trim().toUpperCase(), ",");
  60. log.info("======findAll(String sqlName,Object...args)==sqlLabel="+list);
  61. if(map.get(sqlName).toLowerCase()==null&&"".equals(map.get(sqlName).trim()))
  62. throw new SQLStringException("查询语句为空");
  63. log.info("======findAll(String sqlName,Object...args)==sql="+map.get(sqlName).trim().toUpperCase());
  64. return cmt.queryMoreTypeToMap(map.get(sqlName), list, args);
  65. }
  66. public String insert(String title)throws SQLStringException{
  67. //没有当前title自动添加
  68. String setDel="UPDATE NWYJ.ECM_CM_PLANKTITLE SET IS_DEL='1';";
  69. //自动插入
  70. String insertTitle="INSERT INTO NWYJ.ECM_CM_PLANKTITLE(FD_OBJECTID,TITLENAME,IS_DEL,UPDATEDATE) VALUES(sq_num.NEXTVAL,?,'0',SYSDATE());";
  71. //查找
  72. String findTitle="SELECT FD_OBJECTID FROM NWYJ.ECM_CM_PLANKTITLE WHERE TITLENAME=? AND IS_DEL='0'";
  73. Connection conn=null;
  74. PreparedStatement ps=null;
  75. ResultSet rs=null;
  76. String result=null;
  77. try {
  78. conn=DBUtils.getConnection();
  79. conn.setAutoCommit(false);
  80. ps=conn.prepareStatement(setDel);
  81. ps.executeUpdate();
  82. ps=conn.prepareStatement(insertTitle);
  83. ps.setString(1, title);
  84. ps.executeUpdate();
  85. ps=conn.prepareStatement(findTitle);
  86. ps.setString(1, title);
  87. rs=ps.executeQuery();
  88. while(rs.next()){
  89. result=rs.getString(1);
  90. }
  91. conn.commit();
  92. } catch (Exception e) {
  93. log.info(e.getMessage());
  94. try {
  95. conn.rollback();
  96. } catch (SQLException e1) {
  97. log.info(e1.getMessage());
  98. }
  99. return null;
  100. }finally{
  101. DBUtils.close(rs, ps, conn);
  102. return result;
  103. }
  104. }
  105. public static void main(String[] args) {
  106. IntelligenceDao dao=new IntelligenceDao();
  107. try {
  108. System.out.println("===="+dao.insert("ASDFASDF"));
  109. } catch (SQLStringException e) {
  110. // TODO Auto-generated catch block
  111. e.printStackTrace();
  112. }
  113. }
  114. }