审查视图

src/java/com/airport/dao/impl/DaoImpl.java 6.0 KB
朱兆平 authored
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42
//
// Source code recreated from a .class file by IntelliJ IDEA
// (powered by Fernflower decompiler)
//

package com.airport.dao.impl;

import com.airport.bean.MessageBak;
import com.airport.dao.Dao;
import com.airport.util.ConfigUtils;
import java.io.IOException;
import java.io.Writer;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.ArrayList;
import java.util.List;
import oracle.sql.CLOB;
import org.apache.log4j.Logger;
import org.springframework.dao.DataAccessException;
import org.springframework.dao.EmptyResultDataAccessException;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.jdbc.core.PreparedStatementCreator;
import org.springframework.jdbc.core.support.AbstractLobStreamingResultSetExtractor;
import org.springframework.jdbc.support.GeneratedKeyHolder;
import org.springframework.jdbc.support.KeyHolder;
import org.springframework.jdbc.support.lob.DefaultLobHandler;
import org.springframework.jdbc.support.lob.LobHandler;

public class DaoImpl implements Dao {
    private static final Logger logger = Logger.getLogger(DaoImpl.class);
    private JdbcTemplate jdbcTemplate;

    public DaoImpl() {
    }

    public void setJdbcTemplate(JdbcTemplate jdbcTemplate) {
        this.jdbcTemplate = jdbcTemplate;
    }
朱兆平 authored
43
    public int insertRecord(final String oper, final String sndr,String type,String styp) {
朱兆平 authored
44 45 46
        KeyHolder keyHolder = new GeneratedKeyHolder();
        this.jdbcTemplate.update(new PreparedStatementCreator() {
            public PreparedStatement createPreparedStatement(Connection connection) throws SQLException {
朱兆平 authored
47 48
                DaoImpl.logger.info("oper=" + oper + " sndr=" + sndr+"type="+type+"styp="+styp);
                String sql = "insert into  T_ETL_MESSAGE(OPER,SNDR,SNTM,content,TYPE,STYP) values(?,?,sysdate,empty_clob(),?,?)";
朱兆平 authored
49 50 51
                PreparedStatement ps = connection.prepareStatement(sql, new String[]{"FID"});
                ps.setString(1, oper);
                ps.setString(2, sndr);
朱兆平 authored
52 53
                ps.setString(3, type);
                ps.setString(4, styp);
朱兆平 authored
54 55 56 57 58 59 60
                return ps;
            }
        }, keyHolder);
        int generatedId = keyHolder.getKey().intValue();
        return generatedId;
    }
朱兆平 authored
61
    public void saveRecord(String messaegType, String sndr, String xmlContent,String type,String styp) throws Exception {
朱兆平 authored
62 63 64 65 66 67
        Connection conn = null;
        Statement stmt = null;
        ResultSet rs = null;
        int fid = -100;

        try {
朱兆平 authored
68
            fid = this.insertRecord(messaegType, sndr,type,styp);
朱兆平 authored
69 70 71
            conn = this.jdbcTemplate.getDataSource().getConnection();
            conn.setAutoCommit(false);
            stmt = conn.createStatement();
朱兆平 authored
72
            String SQL = "select CONTENT from T_ETL_MESSAGE where FID=" + fid + " for update";
朱兆平 authored
73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112
            rs = stmt.executeQuery(SQL);

            while(rs.next()) {
                CLOB clob = (CLOB)rs.getClob(1);
                Writer os = clob.getCharacterOutputStream();
                os.write(xmlContent);
                os.flush();
                os.close();
            }

            conn.commit();
        } catch (SQLException var14) {
            if (fid > 0) {
                this.delete(fid);
            }

            var14.printStackTrace();
            conn.rollback();
        } finally {
            if (conn != null) {
                conn.setAutoCommit(true);
            }

            if (rs != null) {
                rs.close();
            }

            if (stmt != null) {
                stmt.close();
            }

            if (conn != null) {
                conn.close();
            }

        }

    }

    public void delete(int fid) {
113
        this.jdbcTemplate.update("delete from T_ETL_MESSAGE where fid=" + fid);
朱兆平 authored
114 115 116
    }

    public int getMaxFID() {
117 118 119
        String sqlmax = "select max(fid) from MESSAGE_BAK WHERE (FID>%s and FID<%s+%s) AND (TYPE='CLR' OR TYPE='ES1' OR TYPE='IS1' OR  STYP = 'BSTA' OR STYP = 'FZE_RCF' OR STYP = 'FSU_FOH' OR STYP = 'FSU_DEP' OR STYP = 'COST' OR STYP = 'ABME' OR STYP = 'FZE_DEP' OR STYP = 'FSU_RCF') ORDER BY FID\n";
        sqlmax = ConfigUtils.SQlMax;
        return this.jdbcTemplate.queryForInt(sqlmax);
朱兆平 authored
120 121 122
    }

    public List<MessageBak> getRecordByFID(int fid) {
123 124
        //从配置文件读取sql语句
        String sql_select=ConfigUtils.SQl;
朱兆平 authored
125
        String sql = String.format(sql_select, fid, fid, ConfigUtils.RECORD_COUNT); //这里修改从FID_INDEX文件读取的FID ,改为取搜索结果的rownum,此处FID代表ROWNUM
朱兆平 authored
126 127 128 129 130 131 132 133 134 135 136
        logger.info(sql);
        final LobHandler lobHandler = new DefaultLobHandler();
        final ArrayList xmlList = new ArrayList();

        try {
            this.jdbcTemplate.query(sql, new AbstractLobStreamingResultSetExtractor() {
                protected void streamData(ResultSet rs) throws SQLException, IOException, DataAccessException {
                    String content = "";
                    while(rs.next()) {
                        int fid = rs.getInt(1);
                        content = lobHandler.getClobAsString(rs, "CONTENT");
137
                        int rownum = rs.getInt("rownum_");
朱兆平 authored
138
                        if (content != null) {
139
                            MessageBak obj = new MessageBak(fid, content,rownum);
朱兆平 authored
140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155
                            xmlList.add(obj);
                        } else {
                            DaoImpl.logger.error("FID=" + fid + "  content is NULL");
                        }
                    }

                }
            });
        } catch (EmptyResultDataAccessException var7) {
            var7.printStackTrace();
        }

        return xmlList;
    }

    public int getRecordCount() {
156
        return this.jdbcTemplate.queryForInt("select count(*) from T_ETL_MESSAGE where SNDR='FIMS' ");
朱兆平 authored
157 158 159
    }

    public void update(int fid, int times) {
160
        String sql = String.format("update T_ETL_MESSAGE set OUTFLAG=%s ,OUTTM=sysdate  where  FID=%s", times, fid);
朱兆平 authored
161 162 163 164
        logger.info("sql=" + sql);
        this.jdbcTemplate.update(sql);
    }
}