package com.steering.jobface.Mcms;

import CoreFS.SA06.CoreReturnObject;
import CoreFS.SA08.CoreXmlSqlParsersFactory;
import CoreFS.SC01.CoreConstantData;
import com.steering.comm.converter.CoreConverter;
import com.steering.comm.db.DBCommon;
import com.steering.comm.tools.EntityTool;
import org.hsqldb.lib.StringUtil;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

/**
 * Created by 朱少波 on 2020/12/18.
 */
public class CarEffServer extends DBCommon {


    public void DoUpdateRecord() {

        Connection connection = this.getDao("TgDao")
                .getConnection();

        try {
            connection.setAutoCommit(false); //


            String sql = CoreXmlSqlParsersFactory
                    .getSql("CarEffServer.doUpdate");
            PreparedStatement pst = connection.prepareStatement(sql);
            pst.executeUpdate();
            pst.close();

            sql = CoreXmlSqlParsersFactory
                    .getSql("CarEffServer.doUpdate2");
             pst = connection.prepareStatement(sql);
            pst.executeUpdate();
            pst.close();

            connection.commit();

        } catch (Exception e) {

            if (connection != null) {
                try {
                    connection.rollback(); // 回滚事务
                } catch (Exception e2) {
                }
            }
        } finally {
            try {
                if (connection != null && !connection.isClosed()) {
                    connection.close();
                }
            } catch (Exception e2) {
            }
        }

    }


    public static List<CmmCarEffEntity> getCmmCarEff(Connection con) throws SQLException {
        String sql = CoreXmlSqlParsersFactory
                .getSql("CarEffServer.doQuery");
        PreparedStatement ps = con.prepareStatement(sql);
        ResultSet rs = ps.executeQuery();
        List<CmmCarEffEntity> resultEntities = EntityTool.getEntitysByRs(rs,
                CmmCarEffEntity.class);
        rs.close();
        ps.close();

        return resultEntities;
    }
}
