All Downloads are FREE. Search and download functionalities are using the official Maven repository.

base.jee.api.sql.ExpireLogEntries Maven / Gradle / Ivy

/**
 * Creative commons Attribution-NonCommercial license.
 *
 * http://creativecommons.org/licenses/by-nc/2.5/au/deed.en_GB
 *
 * NO WARRANTY IS GIVEN OR IMPLIED, USE AT YOUR OWN RISK.
 */
package base.jee.api.sql;

import base.Command;
import base.jee.api.Settings;

import javax.sql.DataSource;
import java.io.IOException;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.SQLException;
import java.util.Date;

import static base.jee.api.sql.util.Log.log;

public class ExpireLogEntries extends Command {

	private DataSource ds;
	private Settings settings;

	public ExpireLogEntries(DataSource ds, Settings settings) {
		this.ds = ds;
		this.settings = settings;
	}

	public ExpireLogEntries() {
	}

	@Override
	protected void execute() throws IOException {
		Connection c = null;
		PreparedStatement s = null;

		try {
			c = ds.getConnection();

			s = c.prepareStatement("delete from audit_event where level='DEBUG' and event_time 0) {
				log(c, "FINE", null, "Removed " + count + " old log messages.");
			}

			c.commit();
			c.close();
			c = null;
		} catch(SQLException e) {
		} catch(IOException e) {
		} finally {
			if(s != null) { try { s.close(); } catch(SQLException e) {} }
			if(c != null) { try { c.close(); } catch(SQLException e) {} }
		}

	}

	@Override
	public String getJsonParameters() {
		return "{}";
	}

}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy