Updating licenses in all files
[appc.git] / appc-dispatcher / appc-dispatcher-common / transaction-recorder / src / main / java / org / openecomp / appc / transactionrecorder / impl / TransactionRecorderImpl.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * APPC
4  * ================================================================================
5  * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
6  * Copyright (C) 2017 Amdocs
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
11  * 
12  *      http://www.apache.org/licenses/LICENSE-2.0
13  * 
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=========================================================
20  * ECOMP is a trademark and service mark of AT&T Intellectual Property.
21  */
22
23 package org.openecomp.appc.transactionrecorder.impl;
24
25 import org.openecomp.appc.dao.util.DBUtils;
26 import org.openecomp.appc.transactionrecorder.TransactionRecorder;
27 import org.openecomp.appc.transactionrecorder.objects.TransactionRecord;
28 import org.slf4j.Logger;
29 import org.slf4j.LoggerFactory;
30
31 import java.sql.Connection;
32 import java.sql.PreparedStatement;
33 import java.sql.SQLException;
34
35
36
37 public class TransactionRecorderImpl implements TransactionRecorder {
38
39     private static String APPCCTL_SCHEMA = "appcctl";
40
41     private static final Logger logger = LoggerFactory.getLogger(TransactionRecorderImpl.class);
42
43     /**
44      * Stores transaction record to appc database by calling APPC Dao layer.
45      * @param record Transaction record data.
46      */
47     @Override
48     public void store(TransactionRecord record) {
49         Connection connection = null;
50         PreparedStatement stmt = null;
51         String queryString = "INSERT INTO transactions VALUES (?,?,?,?,?,?,?,?,?,?)";
52         try {
53             if (logger.isDebugEnabled()) {
54                 logger.debug("Transaction Data started Inserting Successfully into DB");
55             }
56             connection = DBUtils.getConnection(APPCCTL_SCHEMA);
57             stmt = connection.prepareStatement(queryString);
58             stmt.setTimestamp(1, new java.sql.Timestamp(record.getTimeStamp().toEpochMilli()));
59             stmt.setString(2, record.getRequestID());
60             stmt.setTimestamp(3, new java.sql.Timestamp(record.getStartTime().toEpochMilli()));
61             stmt.setTimestamp(4, new java.sql.Timestamp(record.getEndTime().toEpochMilli()));
62             stmt.setString(5, record.getTargetID());
63             stmt.setString(6, record.getTargetType());
64             stmt.setString(7, record.getSubComponent());
65             stmt.setString(8, record.getOperation());
66             stmt.setString(9, record.getResultCode());
67             stmt.setString(10, record.getDescription());
68             stmt.execute();
69             if (logger.isDebugEnabled()) {
70                 logger.debug("Transaction Data Inserted Successfully into DB");
71             }
72         } catch (SQLException e) {
73             logger.error("Error Accessing Database " + e);
74             throw new RuntimeException(e);
75         } finally {
76             DBUtils.clearResources(null, stmt, connection);
77         }
78     }
79 }