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