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