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;
}
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;
}
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;
}
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;
}
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;
}
Aggregations