Search in sources :

Example 1 with ImapFolderCollection

use of com.zimbra.cs.datasource.imap.ImapFolderCollection in project zm-mailbox by Zimbra.

the class DbImapFolder method getImapFolders.

/**
     * Returns a <tt>List</tt> of <tt>ImapFolders</tt> for the given <tt>DataSource</tt>.
     */
public static ImapFolderCollection getImapFolders(Mailbox mbox, DataSource ds) throws ServiceException {
    ImapFolderCollection imapFolders = new ImapFolderCollection();
    DbConnection conn = null;
    PreparedStatement stmt = null;
    ResultSet rs = null;
    try {
        conn = DbPool.getConnection(mbox);
        stmt = conn.prepareStatement("SELECT item_id, local_path, remote_path, uid_validity" + " FROM " + getTableName(mbox) + " WHERE " + DbMailItem.IN_THIS_MAILBOX_AND + "data_source_id = ?");
        int pos = 1;
        pos = DbMailItem.setMailboxId(stmt, mbox, pos);
        stmt.setString(pos++, ds.getId());
        rs = stmt.executeQuery();
        while (rs.next()) {
            int itemId = rs.getInt("item_id");
            String localPath = rs.getString("local_path");
            String remotePath = rs.getString("remote_path");
            Long uidValidity = rs.getLong("uid_validity");
            if (rs.wasNull())
                uidValidity = null;
            ImapFolder imapFolder = new ImapFolder(ds, itemId, remotePath, localPath, uidValidity);
            imapFolders.add(imapFolder);
        }
    } catch (SQLException e) {
        throw ServiceException.FAILURE("Unable to get IMAP folder data", e);
    } finally {
        DbPool.closeResults(rs);
        DbPool.closeStatement(stmt);
        DbPool.quietClose(conn);
    }
    ZimbraLog.datasource.debug("Found %d folders for %s", imapFolders.size(), ds);
    return imapFolders;
}
Also used : ImapFolder(com.zimbra.cs.datasource.imap.ImapFolder) SQLException(java.sql.SQLException) ResultSet(java.sql.ResultSet) PreparedStatement(java.sql.PreparedStatement) ImapFolderCollection(com.zimbra.cs.datasource.imap.ImapFolderCollection) DbConnection(com.zimbra.cs.db.DbPool.DbConnection)

Aggregations

ImapFolder (com.zimbra.cs.datasource.imap.ImapFolder)1 ImapFolderCollection (com.zimbra.cs.datasource.imap.ImapFolderCollection)1 DbConnection (com.zimbra.cs.db.DbPool.DbConnection)1 PreparedStatement (java.sql.PreparedStatement)1 ResultSet (java.sql.ResultSet)1 SQLException (java.sql.SQLException)1