2 * Copyright © 2017-2018 AT&T Intellectual Property.
\r
4 * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
\r
5 * in compliance with the License. You may obtain a copy of the License at
\r
7 * http://www.apache.org/licenses/LICENSE-2.0
\r
9 * Unless required by applicable law or agreed to in writing, software distributed under the License
\r
10 * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
\r
11 * or implied. See the License for the specific language governing permissions and limitations under
\r
15 package org.onap.ccsdk.config.data.adaptor.dao;
\r
17 import java.sql.ResultSet;
\r
18 import java.sql.SQLException;
\r
19 import java.util.List;
\r
20 import org.apache.commons.lang3.StringUtils;
\r
21 import org.onap.ccsdk.config.data.adaptor.domain.TransactionLog;
\r
22 import org.onap.ccsdk.sli.core.sli.SvcLogicException;
\r
23 import org.springframework.jdbc.core.JdbcTemplate;
\r
24 import org.springframework.jdbc.core.RowMapper;
\r
25 import com.att.eelf.configuration.EELFLogger;
\r
26 import com.att.eelf.configuration.EELFManager;
\r
28 public class TransactionLogDaoImpl implements TransactionLogDao {
\r
30 private static EELFLogger logger = EELFManager.getInstance().getLogger(TransactionLogDaoImpl.class);
\r
32 private JdbcTemplate jdbcTemplate;
\r
34 public TransactionLogDaoImpl(JdbcTemplate jdbcTemplate) {
\r
35 this.jdbcTemplate = jdbcTemplate;
\r
39 public void save(TransactionLog transactionLog) throws SvcLogicException {
\r
40 if (transactionLog != null && StringUtils.isNotBlank(transactionLog.getRequestId())) {
\r
42 "INSERT INTO CONFIG_TRANSACTION_LOG ( config_transaction_log_id, request_id, message_type, message ) VALUES (?, ?, ?, ?) ";
\r
43 jdbcTemplate.update(addSql, transactionLog.getUniqueId(), transactionLog.getRequestId(),
\r
44 transactionLog.getMessageType(), transactionLog.getMessage());
\r
45 logger.trace("TransactionLog Updated Successfully for message_type {}", transactionLog.getMessageType());
\r
51 public List<TransactionLog> getTransactionsByRequestId(String requestId) throws SvcLogicException {
\r
52 if (StringUtils.isNotBlank(requestId)) {
\r
53 String selectByRequestIdSql =
\r
54 "SELECT * FROM CONFIG_TRANSACTION_LOG WHERE request_id = ? ORDER BY creation_date DESC";
\r
55 return this.jdbcTemplate.query(selectByRequestIdSql, new Object[] {requestId}, new TransactionLogMapper());
\r
57 throw new SvcLogicException("TransactionLog Request id (" + requestId + ")is missing ");
\r
62 public List<TransactionLog> getTransactionsByRequestId(String requestId, String messageType)
\r
63 throws SvcLogicException {
\r
64 if (StringUtils.isNotBlank(requestId)) {
\r
65 String selectByRequestIdSql =
\r
66 "SELECT * FROM CONFIG_TRANSACTION_LOG WHERE request_id = ? and message_type = ? ORDER BY creation_date DESC";
\r
67 return this.jdbcTemplate.query(selectByRequestIdSql, new Object[] {requestId, messageType},
\r
68 new TransactionLogMapper());
\r
70 throw new SvcLogicException("TransactionLog Request id (" + requestId + ")is missing ");
\r
74 private static final class TransactionLogMapper implements RowMapper<TransactionLog> {
\r
76 public TransactionLog mapRow(ResultSet rs, int rowNum) throws SQLException {
\r
77 TransactionLog transactionLog = new TransactionLog();
\r
78 transactionLog.setCreationDate(rs.getDate("creation_date"));
\r
79 transactionLog.setMessage(rs.getString("message"));
\r
80 transactionLog.setMessageType(rs.getString("message_type"));
\r
81 transactionLog.setRequestId(rs.getString("request_id"));
\r
82 transactionLog.setTransactionLogId(rs.getString("config_transaction_log_id"));
\r
83 return transactionLog;
\r