2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
6 * ================================================================================
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
18 * ============LICENSE_END=========================================================
22 package org.onap.xacml.parser;
24 import java.text.Format;
25 import java.text.SimpleDateFormat;
26 import java.util.Date;
27 import java.util.TimerTask;
28 import java.sql.Connection;
29 import java.sql.SQLException;
32 import org.onap.policy.common.logging.flexlogger.FlexLogger;
34 public class CleanUpSystemLogDB extends TimerTask{
36 private static org.onap.policy.common.logging.flexlogger.Logger logger = FlexLogger.getLogger(CleanUpSystemLogDB.class.getName());
37 Connection localConnect = null;
38 int timeFrame = 5; //default
39 public CleanUpSystemLogDB(Connection dbConnect, int argTimeFrame) {
40 localConnect = dbConnect;
42 timeFrame = argTimeFrame;
45 String className = this.getClass().getSimpleName();
50 Date date = new Date();
51 Format formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
52 logger.debug("cleanLogDBTableEntries:Cleanup systemlogdb starts on date:" + formatter.format(date));
54 cleanLogDBTableEntries(localConnect, timeFrame);
55 } catch (SQLException e) {
59 logger.debug(className + " Cleanup systemlogdb done");
62 public static void cleanLogDBTableEntries(Connection dbConnect, int timeFrame) throws SQLException {
64 Connection connect = dbConnect;
65 if(dbConnect == null || dbConnect.isClosed()) {
66 connect = ParseLog.getDbConnection();
69 java.sql.PreparedStatement statement = connect
70 .prepareStatement("DELETE FROM SYSTEMLOGDB WHERE date < DATE_SUB(CURDATE(), INTERVAL ? DAY)");
73 statement.setInt(1, timeFrame);
75 int records = statement.executeUpdate();
77 logger.debug("cleanLogDBTableEntries:deleting Log files ended with " + records + " deleted.");
80 } catch (Exception e) {
81 logger.error("Failed to create SQLContainer for System Log Database", e);