public int getCount(String username) {
        // No cache: this needs to be more accurate than the 'size' method (that does have a cache).
        // Maintaining a cache would likely add more overhead than that the cache would save.
        int count = 0;
        Connection con = null;
        PreparedStatement pstmt = null;
        ResultSet rs = null;
        try {
            con = DbConnectionManager.getConnection();
            pstmt = con.prepareStatement(SELECT_COUNT_OFFLINE);
            pstmt.setString(1, username);
            rs = pstmt.executeQuery();
            if (rs.next()) {
                count = rs.getInt(1);
            }
        }
        catch (Exception e) {
            Log.error(LocaleUtils.getLocalizedString("admin.error"), e);
        }
        finally {
            DbConnectionManager.closeConnection(rs, pstmt, con);
        }
        return count;
    }
Returns the number of XML messages stored for a particular user.

@param username the username of the user.
@return the amount of stored messages.
xmppserver/src/main/java/org/jivesoftware/openfire/OfflineMessageStore.java