| | |
| | | import com.product.datasource.config.DataBaseType; |
| | | import com.product.datasource.config.ErrorCode; |
| | | import com.product.datasource.connection.ConnectionManager; |
| | | import com.product.datasource.dao.ConnectionInterface; |
| | | import com.product.datasource.dao.Dao; |
| | | import com.product.datasource.entity.BatchResultEntity; |
| | | import com.product.datasource.entity.DataBaseEntity; |
| | |
| | | import com.product.datasource.utils.BatchUtil; |
| | | import org.apache.commons.lang3.StringUtils; |
| | | |
| | | import javax.swing.*; |
| | | import java.sql.Connection; |
| | | import java.sql.PreparedStatement; |
| | | import java.sql.ResultSet; |
| | |
| | | */ |
| | | public class MysqlDaoImpl implements Dao { |
| | | |
| | | private DataBaseEntity dataBaseEntity; |
| | | |
| | | private Connection connection; |
| | | |
| | | private boolean outLog; |
| | | |
| | | private ConnectionInterface connectionInterface; |
| | | |
| | | public MysqlDaoImpl(DataBaseEntity dataBaseEntity) { |
| | | if (!DataBaseType.MYSQL.equals(dataBaseEntity.getDataBaseType())) { |
| | | throw new BaseException(ErrorCode.INIT_DAO_IMPL_TYPE_ERROR); |
| | | } |
| | | this.dataBaseEntity = dataBaseEntity; |
| | | this.outLog = "dev".equals(Global.getSystemConfig("spring.profiles.active", "prod")); |
| | | connectionInterface = () -> ConnectionManager.getConnection(dataBaseEntity); |
| | | } |
| | | |
| | | public MysqlDaoImpl(ConnectionInterface connectionInterface) { |
| | | this.connectionInterface = connectionInterface; |
| | | } |
| | | |
| | | private void info(String message) { |
| | |
| | | try { |
| | | if (this.connection == null || this.connection.isClosed()) { |
| | | //åå§åè¿æ¥ |
| | | this.connection = ConnectionManager.getConnection(dataBaseEntity); |
| | | this.connection = this.connectionInterface.getConnection(); |
| | | } |
| | | return this.connection; |
| | | } catch (Exception e) { |
| | |
| | | TimeInterval timer = DateUtil.timer(); |
| | | info("æ¹éæ°å¢æ°æ®æ¡æ°ä¸ºï¼" + data.getRows()); |
| | | BatchResultEntity batchResultEntity = new BatchResultEntity(data.getRows()); |
| | | // Connection connection = ConnectionManager.getConnection(dataBaseEntity); |
| | | // ConnectionInterface connection = ConnectionManager.getConnection(dataBaseEntity); |
| | | try { |
| | | StringBuilder insertSql = BatchUtil.getInsertSql(data.getMeta()); |
| | | info("SQL:" + insertSql); |
| | |
| | | info("æ§è¡æ¹éæäº¤æ°æ®å®æï¼å
±æäº¤ " + data.getRows() + " æ¡,èæ¶ï¼" + timer.intervalSecond() + " ç§ ï¼"); |
| | | pst.clearBatch(); |
| | | } catch (Exception e) { |
| | | SpringMVCContextHolder.getSystemLogger().error(e); |
| | | throw e; |
| | | } finally { |
| | | connection.setAutoCommit(true); |
| | |
| | | TimeInterval timer = DateUtil.timer(); |
| | | info("æ¹éæ´æ°æ°æ®æ¡æ°ä¸ºï¼" + data.getRows()); |
| | | BatchResultEntity batchResultEntity = new BatchResultEntity(data.getRows()); |
| | | // Connection connection = ConnectionManager.getConnection(dataBaseEntity); |
| | | // ConnectionInterface connection = ConnectionManager.getConnection(dataBaseEntity); |
| | | try { |
| | | StringBuilder updateSql = BatchUtil.getUpdateSql(data.getMeta(), updateFilter.getFilter()); |
| | | info("SQL: " + updateSql); |