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

org.bdware.doip.audit.DOAuditRuleDB Maven / Gradle / Ivy

There is a newer version: 1.5.4
Show newest version
package org.bdware.doip.audit;

import java.sql.*;

public class DOAuditRuleDB extends BasicDB {
    public DOAuditRuleDB(String driverClass, String url, String user, String password) {
        super(driverClass, url, user, password);
    }

    public boolean add(String tableName, DOAuditRule doAuditRule) throws SQLException {
        Connection conn = getConn();
        Statement statement = conn.createStatement();
        String sql = "insert into ? values (?, ?)";
        PreparedStatement ps = conn.prepareStatement(sql);
        ps.setString(1, formatTableName(tableName));
        ps.setString(2, doAuditRule.doId);
        ps.setInt(3, doAuditRule.type);
        statement.executeUpdate(sql);
        return true;
    }

    public boolean remove(String tableName, String doId) throws SQLException {
        Connection conn = getConn();
        Statement statement = conn.createStatement();
        String sql = "delete from ? where ? = ?";
        PreparedStatement ps = conn.prepareStatement(sql);
        ps.setString(1, formatTableName(tableName));
        ps.setString(2, "doId");
        ps.setString(3, doId);
        statement.executeUpdate(sql);
        return true;
    }

    public boolean modify(String tableName, DOAuditRule doAuditRule) throws SQLException {
        Connection conn = getConn();
        Statement statement = conn.createStatement();
        String sql = "update ? set ? = ? where ? = ?";
        PreparedStatement ps = conn.prepareStatement(sql);
        ps.setString(1, formatTableName(tableName));
        ps.setString(2, "type");
        ps.setInt(3, doAuditRule.type);
        ps.setString(4, "doId");
        ps.setString(5, doAuditRule.doId);
        statement.executeUpdate(sql);
        return true;
    }

    public int retrieve(String tableName, String doId) throws SQLException {
        Connection conn = getConn();
        Statement statement = conn.createStatement();
        String sql = "select ? from ? where ? = ?";
        PreparedStatement ps = conn.prepareStatement(sql);
        ps.setString(1, "type");
        ps.setString(2, formatTableName(tableName));
        ps.setString(3, "doId");
        ps.setString(4, doId);
        ResultSet resultSet = statement.executeQuery(sql);
        return resultSet.getInt(1);
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy