Search in sources :

Example 86 with ResultSet

use of java.sql.ResultSet in project Openfire by igniterealtime.

the class ChatHistoryUtils method getNumberOfChatsAccepted.

/**
     * Returns the number of chat requests that were accepted.
     *
     * @param workgroupName the name of the workgroup where the request(s) were made.
     * @param startDate the start date.
     * @param endDate the end date.
     * @return the number of chats requests accepted by the workgroup.
     */
public static int getNumberOfChatsAccepted(String workgroupName, Date startDate, Date endDate) {
    Workgroup workgroup = null;
    try {
        workgroup = WorkgroupManager.getInstance().getWorkgroup(new JID(workgroupName));
    } catch (Exception ex) {
        Log.error(ex.getMessage(), ex);
    }
    if (workgroup == null) {
        return 0;
    }
    int count = 0;
    Connection con = null;
    PreparedStatement pstmt = null;
    ResultSet rs = null;
    try {
        con = DbConnectionManager.getConnection();
        pstmt = con.prepareStatement(ACCEPTED_CHATS_COUNT);
        pstmt.setLong(1, workgroup.getID());
        pstmt.setString(2, StringUtils.dateToMillis(startDate));
        pstmt.setString(3, StringUtils.dateToMillis(endDate));
        rs = pstmt.executeQuery();
        if (rs.next()) {
            count = rs.getInt(1);
        }
    } catch (Exception ex) {
        Log.error(ex.getMessage(), ex);
    } finally {
        DbConnectionManager.closeConnection(rs, pstmt, con);
    }
    return count;
}
Also used : JID(org.xmpp.packet.JID) Connection(java.sql.Connection) ResultSet(java.sql.ResultSet) PreparedStatement(java.sql.PreparedStatement) Workgroup(org.jivesoftware.xmpp.workgroup.Workgroup) UserNotFoundException(org.jivesoftware.openfire.user.UserNotFoundException) SQLException(java.sql.SQLException)

Example 87 with ResultSet

use of java.sql.ResultSet in project Openfire by igniterealtime.

the class ChatHistoryUtils method getNumberOfRequestsForWorkgroup.

/**
     * Returns the number of request made to a workgroup between
     * specified dates.
     *
     * @param workgroupName the workgroup to search
     * @param startDate the time to begin the search from.
     * @param endDate the time to end the search.
     * @return the total number of requests
     */
public static int getNumberOfRequestsForWorkgroup(String workgroupName, Date startDate, Date endDate) {
    Workgroup workgroup = getWorkgroup(workgroupName);
    if (workgroup == null) {
        return 0;
    }
    int count = 0;
    Connection con = null;
    PreparedStatement pstmt = null;
    ResultSet rs = null;
    try {
        con = DbConnectionManager.getConnection();
        pstmt = con.prepareStatement(WORKGROUP_REQUEST_COUNT);
        pstmt.setLong(1, workgroup.getID());
        pstmt.setString(2, StringUtils.dateToMillis(startDate));
        pstmt.setString(3, StringUtils.dateToMillis(endDate));
        rs = pstmt.executeQuery();
        if (rs.next()) {
            count = rs.getInt(1);
        }
    } catch (Exception ex) {
        Log.error(ex.getMessage(), ex);
    } finally {
        DbConnectionManager.closeConnection(rs, pstmt, con);
    }
    return count;
}
Also used : Connection(java.sql.Connection) ResultSet(java.sql.ResultSet) PreparedStatement(java.sql.PreparedStatement) Workgroup(org.jivesoftware.xmpp.workgroup.Workgroup) UserNotFoundException(org.jivesoftware.openfire.user.UserNotFoundException) SQLException(java.sql.SQLException)

Example 88 with ResultSet

use of java.sql.ResultSet in project Openfire by igniterealtime.

the class ChatHistoryUtils method getTotalRequestCountForSystem.

/**
     * Retruns the total number of requests.
     *
     * @return the total number of requests.
     */
public static int getTotalRequestCountForSystem() {
    int count = 0;
    Connection con = null;
    PreparedStatement pstmt = null;
    ResultSet rs = null;
    try {
        con = DbConnectionManager.getConnection();
        pstmt = con.prepareStatement(ALL_REQUESTS_COUNT);
        rs = pstmt.executeQuery();
        rs.next();
        count = rs.getInt(1);
    } catch (SQLException e) {
        Log.error(e.getMessage(), e);
    } finally {
        DbConnectionManager.closeConnection(rs, pstmt, con);
    }
    return count;
}
Also used : SQLException(java.sql.SQLException) Connection(java.sql.Connection) ResultSet(java.sql.ResultSet) PreparedStatement(java.sql.PreparedStatement)

Example 89 with ResultSet

use of java.sql.ResultSet in project Openfire by igniterealtime.

the class ChatHistoryUtils method getTotalChatTimeForWorkgroup.

/**
     * Returns the total chat length of an individual workgroup.
     *
     * @param workgroupName the name of the workgroup.
     * @return the total length of all chats in the specified workgroup.
     */
public static long getTotalChatTimeForWorkgroup(String workgroupName) {
    Workgroup workgroup = null;
    try {
        workgroup = WorkgroupManager.getInstance().getWorkgroup(new JID(workgroupName));
    } catch (Exception ex) {
        Log.error(ex.getMessage(), ex);
    }
    int totalWorkgroupChatTime = 0;
    Connection con = null;
    PreparedStatement pstmt = null;
    ResultSet rs = null;
    try {
        con = DbConnectionManager.getConnection();
        pstmt = con.prepareStatement(CHAT_TIMES_FOR_WORKGROUPS);
        pstmt.setLong(1, workgroup.getID());
        rs = pstmt.executeQuery();
        while (rs.next()) {
            String startTimeString = rs.getString(1);
            String endTimeString = rs.getString(2);
            if ((startTimeString != null) && (startTimeString.trim().length() > 0) && (endTimeString != null) && (endTimeString.trim().length() > 0)) {
                long startLong = Long.parseLong(startTimeString);
                long endLong = Long.parseLong(endTimeString);
                totalWorkgroupChatTime += endLong - startLong;
            }
        }
    } catch (Exception ex) {
        Log.error(ex.getMessage(), ex);
    } finally {
        DbConnectionManager.closeConnection(rs, pstmt, con);
    }
    return totalWorkgroupChatTime;
}
Also used : JID(org.xmpp.packet.JID) Connection(java.sql.Connection) ResultSet(java.sql.ResultSet) PreparedStatement(java.sql.PreparedStatement) Workgroup(org.jivesoftware.xmpp.workgroup.Workgroup) UserNotFoundException(org.jivesoftware.openfire.user.UserNotFoundException) SQLException(java.sql.SQLException)

Example 90 with ResultSet

use of java.sql.ResultSet in project Openfire by igniterealtime.

the class ChatHistoryUtils method getTotalTimeForAllChatsInServer.

/**
     * Returns the total amount of time for all the chats in all workgroups.
     *
     * @return the total length of all chats in the system.
     */
public static long getTotalTimeForAllChatsInServer() {
    int totalWorkgroupChatTime = 0;
    Connection con = null;
    PreparedStatement pstmt = null;
    ResultSet rs = null;
    try {
        con = DbConnectionManager.getConnection();
        pstmt = con.prepareStatement(ALL_SESSION_TIMES);
        rs = pstmt.executeQuery();
        while (rs.next()) {
            try {
                String startTimeString = rs.getString(1);
                String endTimeString = rs.getString(2);
                if ((startTimeString != null) && (startTimeString.trim().length() > 0) && (endTimeString != null) && (endTimeString.trim().length() > 0)) {
                    long startLong = Long.parseLong(startTimeString);
                    long endLong = Long.parseLong(endTimeString);
                    totalWorkgroupChatTime += endLong - startLong;
                }
            } catch (SQLException e) {
                Log.error(e.getMessage(), e);
            } catch (NumberFormatException e) {
                Log.error(e.getMessage(), e);
            }
        }
    } catch (Exception ex) {
        Log.error(ex.getMessage(), ex);
    } finally {
        DbConnectionManager.closeConnection(rs, pstmt, con);
    }
    return totalWorkgroupChatTime;
}
Also used : SQLException(java.sql.SQLException) Connection(java.sql.Connection) ResultSet(java.sql.ResultSet) PreparedStatement(java.sql.PreparedStatement) UserNotFoundException(org.jivesoftware.openfire.user.UserNotFoundException) SQLException(java.sql.SQLException)

Aggregations

ResultSet (java.sql.ResultSet)15888 PreparedStatement (java.sql.PreparedStatement)9451 SQLException (java.sql.SQLException)6466 Connection (java.sql.Connection)6445 Statement (java.sql.Statement)4619 Test (org.junit.Test)3647 ArrayList (java.util.ArrayList)2376 Properties (java.util.Properties)1233 HashMap (java.util.HashMap)639 ResultSetMetaData (java.sql.ResultSetMetaData)620 CallableStatement (java.sql.CallableStatement)580 DatabaseMetaData (java.sql.DatabaseMetaData)499 IOException (java.io.IOException)438 List (java.util.List)433 PhoenixConnection (org.apache.phoenix.jdbc.PhoenixConnection)414 Timestamp (java.sql.Timestamp)363 Map (java.util.Map)359 BigDecimal (java.math.BigDecimal)350 CloudRuntimeException (com.cloud.utils.exception.CloudRuntimeException)292 HashSet (java.util.HashSet)247