2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
6 * ================================================================================
7 * Copyright (C) 2017 Amdocs
8 * =============================================================================
9 * Licensed under the Apache License, Version 2.0 (the "License");
10 * you may not use this file except in compliance with the License.
11 * You may obtain a copy of the License at
13 * http://www.apache.org/licenses/LICENSE-2.0
15 * Unless required by applicable law or agreed to in writing, software
16 * distributed under the License is distributed on an "AS IS" BASIS,
17 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18 * See the License for the specific language governing permissions and
19 * limitations under the License.
21 * ECOMP is a trademark and service mark of AT&T Intellectual Property.
22 * ============LICENSE_END=========================================================
25 package org.onap.appc.transactionrecorder.impl;
27 import org.onap.appc.dao.util.DBUtils;
28 import org.onap.appc.transactionrecorder.TransactionRecorder;
29 import org.onap.appc.transactionrecorder.objects.TransactionRecord;
30 import org.slf4j.Logger;
31 import org.slf4j.LoggerFactory;
33 import java.sql.Connection;
34 import java.sql.PreparedStatement;
35 import java.sql.SQLException;
39 public class TransactionRecorderImpl implements TransactionRecorder {
41 private static String APPCCTL_SCHEMA = "appcctl";
43 private static final Logger logger = LoggerFactory.getLogger(TransactionRecorderImpl.class);
46 * Stores transaction record to appc database by calling APPC Dao layer.
47 * @param record Transaction record data.
50 public void store(TransactionRecord record) {
51 Connection connection = null;
52 PreparedStatement stmt = null;
53 String queryString = "INSERT INTO transactions VALUES (?,?,?,?,?,?,?,?,?,?)";
55 if (logger.isDebugEnabled()) {
56 logger.debug("Transaction Data started Inserting Successfully into DB");
58 connection = DBUtils.getConnection(APPCCTL_SCHEMA);
59 stmt = connection.prepareStatement(queryString);
60 stmt.setTimestamp(1, new java.sql.Timestamp(record.getTimeStamp().toEpochMilli()));
61 stmt.setString(2, record.getRequestID());
62 stmt.setTimestamp(3, new java.sql.Timestamp(record.getStartTime().toEpochMilli()));
63 stmt.setTimestamp(4, new java.sql.Timestamp(record.getEndTime().toEpochMilli()));
64 stmt.setString(5, record.getTargetID());
65 stmt.setString(6, record.getTargetType());
66 stmt.setString(7, record.getSubComponent());
67 stmt.setString(8, record.getOperation());
68 stmt.setString(9, record.getResultCode());
69 stmt.setString(10, record.getDescription());
71 if (logger.isDebugEnabled()) {
72 logger.debug("Transaction Data Inserted Successfully into DB");
74 } catch (SQLException e) {
75 logger.error("Error Accessing Database " + e);
76 throw new RuntimeException(e);
78 DBUtils.clearResources(null, stmt, connection);