Search in sources :

Example 1 with ImapFolder

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

the class DbImapFolder method createImapFolder.

public static ImapFolder createImapFolder(Mailbox mbox, DataSource ds, int itemId, String localPath, String remotePath, long uidValidity) throws ServiceException {
    DbConnection conn = null;
    PreparedStatement stmt = null;
    try {
        conn = DbPool.getConnection(mbox);
        ZimbraLog.datasource.debug("createImapFolder: itemId = %d, localPath = %s, remotePath = %s, uidValidity = %d", itemId, localPath, remotePath, uidValidity);
        stmt = conn.prepareStatement("INSERT INTO " + getTableName(mbox) + " (" + DbMailItem.MAILBOX_ID + "item_id, data_source_id, local_path, remote_path, uid_validity) " + "VALUES (" + DbMailItem.MAILBOX_ID_VALUE + "?, ?, ?, ?, ?)");
        int pos = 1;
        pos = DbMailItem.setMailboxId(stmt, mbox, pos);
        stmt.setInt(pos++, itemId);
        stmt.setString(pos++, ds.getId());
        stmt.setString(pos++, localPath);
        stmt.setString(pos++, remotePath);
        stmt.setLong(pos++, uidValidity);
        stmt.executeUpdate();
        conn.commit();
        return new ImapFolder(ds, itemId, remotePath, localPath, uidValidity);
    } catch (SQLException e) {
        throw ServiceException.FAILURE("Unable to store IMAP message data", e);
    } finally {
        DbPool.closeStatement(stmt);
        DbPool.quietClose(conn);
    }
}
Also used : ImapFolder(com.zimbra.cs.datasource.imap.ImapFolder) SQLException(java.sql.SQLException) PreparedStatement(java.sql.PreparedStatement) DbConnection(com.zimbra.cs.db.DbPool.DbConnection)

Example 2 with ImapFolder

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

the class DbImapFolder method getImapFolder.

public static ImapFolder getImapFolder(Mailbox mbox, DataSource ds, int itemId) throws ServiceException {
    DbConnection conn = null;
    PreparedStatement stmt = null;
    ResultSet rs = null;
    try {
        conn = DbPool.getConnection(mbox);
        stmt = conn.prepareStatement("SELECT local_path, remote_path, uid_validity" + " FROM " + getTableName(mbox) + " WHERE " + DbMailItem.IN_THIS_MAILBOX_AND + "item_id = ? ");
        int pos = DbMailItem.setMailboxId(stmt, mbox, 1);
        stmt.setInt(pos, itemId);
        rs = stmt.executeQuery();
        if (!rs.next())
            return null;
        String localPath = rs.getString("local_path");
        String remotePath = rs.getString("remote_path");
        Long uidValidity = rs.getLong("uid_validity");
        if (rs.wasNull()) {
            uidValidity = null;
        }
        return new ImapFolder(ds, itemId, remotePath, localPath, uidValidity);
    } catch (SQLException e) {
        throw ServiceException.FAILURE("Unable to get IMAP folder data", e);
    } finally {
        DbPool.closeResults(rs);
        DbPool.closeStatement(stmt);
        DbPool.quietClose(conn);
    }
}
Also used : ImapFolder(com.zimbra.cs.datasource.imap.ImapFolder) SQLException(java.sql.SQLException) ResultSet(java.sql.ResultSet) PreparedStatement(java.sql.PreparedStatement) DbConnection(com.zimbra.cs.db.DbPool.DbConnection)

Example 3 with ImapFolder

use of com.zimbra.cs.datasource.imap.ImapFolder 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)3 DbConnection (com.zimbra.cs.db.DbPool.DbConnection)3 PreparedStatement (java.sql.PreparedStatement)3 SQLException (java.sql.SQLException)3 ResultSet (java.sql.ResultSet)2 ImapFolderCollection (com.zimbra.cs.datasource.imap.ImapFolderCollection)1