// // 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; } public int insertRecord(final String oper, final String sndr) { KeyHolder keyHolder = new GeneratedKeyHolder(); this.jdbcTemplate.update(new PreparedStatementCreator() { public PreparedStatement createPreparedStatement(Connection connection) throws SQLException { DaoImpl.logger.info("oper=" + oper + " sndr=" + sndr); String sql = "insert into T_ETL_MESSAGE(OPER,SNDR,SNTM,content) values(?,?,sysdate,empty_clob())"; PreparedStatement ps = connection.prepareStatement(sql, new String[]{"FID"}); ps.setString(1, oper); ps.setString(2, sndr); return ps; } }, keyHolder); int generatedId = keyHolder.getKey().intValue(); return generatedId; } public void saveRecord(String messaegType, String sndr, String xmlContent) throws Exception { Connection conn = null; Statement stmt = null; ResultSet rs = null; int fid = -100; try { fid = this.insertRecord(messaegType, sndr); conn = this.jdbcTemplate.getDataSource().getConnection(); conn.setAutoCommit(false); stmt = conn.createStatement(); String SQL = "select CONTENT from T_ETL_MESSAGE where FID=" + fid + " and SNDR='FIMS' for update"; 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) { this.jdbcTemplate.update("delete from T_ETL_MESSAGE where fid=" + fid); } public int getMaxFID() { 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); } public List<MessageBak> getRecordByFID(int fid) { String SQL_FMT = "select FID,CONTENT 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 "; //从配置文件读取sql语句 String sql_select=ConfigUtils.SQl; String sql = String.format(sql_select, fid, fid, ConfigUtils.RECORD_COUNT); //这里修改从FID_INDEX文件读取的FID ,改为取搜索结果的rownum 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 = ""; int rownum=0; while(rs.next()) { int fid = rs.getInt(1); content = lobHandler.getClobAsString(rs, "CONTENT"); rownum = rs.getInt("rownum_"); if (content != null) { MessageBak obj = new MessageBak(fid, content,rownum); xmlList.add(obj); } else { DaoImpl.logger.error("FID=" + fid + " content is NULL"); } } } }); } catch (EmptyResultDataAccessException var7) { var7.printStackTrace(); } return xmlList; } public int getRecordCount() { return this.jdbcTemplate.queryForInt("select count(*) from T_ETL_MESSAGE where SNDR='FIMS' "); } public void update(int fid, int times) { String sql = String.format("update T_ETL_MESSAGE set OUTFLAG=%s ,OUTTM=sysdate where FID=%s", times, fid); logger.info("sql=" + sql); this.jdbcTemplate.update(sql); } }