Search in sources :

Example 6 with AuditLogEvent

use of com.dexels.navajo.events.types.AuditLogEvent in project navajo by Dexels.

the class AuditLog method log.

public static final void log(final String subsystem, final String message) {
    logToSlf(message, subsystem, Level.INFO);
    publishEvent(new AuditLogEvent(subsystem.toUpperCase(), message, Level.INFO));
}
Also used : AuditLogEvent(com.dexels.navajo.events.types.AuditLogEvent)

Example 7 with AuditLogEvent

use of com.dexels.navajo.events.types.AuditLogEvent in project navajo by Dexels.

the class SQLMap method getResultSet.

protected ResultSetMap[] getResultSet(boolean updateOnly) throws UserException {
    requestCount++;
    ResultSet rs = null;
    long start = 0;
    if (debug || timeAlert > 0) {
        start = System.currentTimeMillis();
    }
    try {
        if (resultSet == null) {
            rs = getDBResultSet(updateOnly);
        }
        if (debug) {
            Access.writeToConsole(myAccess, "SQLMAP, QUERY HAS BEEN EXECUTED, RETRIEVING RESULTSET\n");
        }
        if (rs != null) {
            int columns = 0;
            ResultSetMetaData meta = null;
            try {
                meta = rs.getMetaData();
                columns = meta.getColumnCount();
            } catch (Exception e) {
                throw new UserException(-1, "Error getting metadata / columns", e);
            }
            ArrayList dummy = new ArrayList();
            int index = 1;
            remainCount = 0;
            rowCount = 0;
            while (rs.next()) {
                if ((index >= startIndex) && (index <= endIndex)) {
                    ResultSetMap rm = getResultSetMap(meta, columns, rs);
                    dummy.add(rm);
                    viewCount++;
                }
                // else if (index >= startIndex) {
                // remainCount++;
                // }
                rowCount++;
                index++;
            }
            if (debug) {
                Access.writeToConsole(myAccess, "GOT RESULTSET\n");
            }
            resultSet = new ResultSetMap[dummy.size()];
            resultSet = (ResultSetMap[]) dummy.toArray(resultSet);
        }
    } catch (SQLException sqle) {
        logger.error("The following query failed: {}", this.getQuery());
        AuditLog.log("SQLMap", sqle.getMessage(), sqle, Level.SEVERE, (myAccess != null ? (myAccess != null ? myAccess.accessID : "unknown access") : "unknown access"));
        throw new UserException(-1, sqle.getMessage(), sqle);
    } catch (Exception sqle) {
        AuditLog.log("SQLMap", sqle.getMessage(), sqle, Level.SEVERE, (myAccess != null ? (myAccess != null ? myAccess.accessID : "unknown access") : "unknown access"));
        throw new UserException(-1, sqle.getMessage(), sqle);
    } finally {
        if (rs != null) {
            try {
                rs.close();
            } catch (Exception e) {
                e.printStackTrace(Access.getConsoleWriter(myAccess));
            }
            rs = null;
        }
        this.resetAll();
    }
    if (debug || timeAlert > 0) {
        long end = System.currentTimeMillis();
        double total = (end - start) / 1000.0;
        if (timeAlert > 0 && (int) (end - start) > timeAlert) {
            AuditLogEvent ale = new AuditLogEvent("SQLMAPTIMEALERT", "Query took " + (end - start) + " millis:\n" + (query != null ? query : update), Level.WARNING);
            ale.setAccessId(myAccess.accessID);
            NavajoEventRegistry.getInstance().publishEvent(ale);
        }
    // Log total if needed....
    // totaltiming += total;
    }
    return resultSet;
}
Also used : ResultSetMetaData(java.sql.ResultSetMetaData) AuditLogEvent(com.dexels.navajo.events.types.AuditLogEvent) SQLException(java.sql.SQLException) ResultSet(java.sql.ResultSet) ArrayList(java.util.ArrayList) ResultSetMap(com.dexels.navajo.adapter.sqlmap.ResultSetMap) UserException(com.dexels.navajo.script.api.UserException) NavajoException(com.dexels.navajo.document.NavajoException) UserException(com.dexels.navajo.script.api.UserException) MappableException(com.dexels.navajo.script.api.MappableException) SQLException(java.sql.SQLException)

Aggregations

AuditLogEvent (com.dexels.navajo.events.types.AuditLogEvent)7 Test (org.junit.Test)2 ResultSetMap (com.dexels.navajo.adapter.sqlmap.ResultSetMap)1 NavajoException (com.dexels.navajo.document.NavajoException)1 MappableException (com.dexels.navajo.script.api.MappableException)1 UserException (com.dexels.navajo.script.api.UserException)1 ResultSet (java.sql.ResultSet)1 ResultSetMetaData (java.sql.ResultSetMetaData)1 SQLException (java.sql.SQLException)1 ArrayList (java.util.ArrayList)1