Search in sources :

Example 31 with TypedIdList

use of com.zimbra.cs.mailbox.util.TypedIdList in project zm-mailbox by Zimbra.

the class DbMailItem method listCalendarItems.

/**
 * @param start     start time of range, in milliseconds. {@code -1} means to leave the start time unconstrained.
 * @param end       end time of range, in milliseconds. {@code -1} means to leave the end time unconstrained.
 */
public static TypedIdList listCalendarItems(Mailbox mbox, MailItem.Type type, long start, long end, int folderId, int[] excludeFolderIds) throws ServiceException {
    DbConnection conn = mbox.getOperationConnection();
    PreparedStatement stmt = null;
    ResultSet rs = null;
    try {
        stmt = calendarItemStatement(conn, "mi.id, mi.type, mi.uuid", mbox, type, start, end, folderId, excludeFolderIds);
        rs = stmt.executeQuery();
        TypedIdList result = new TypedIdList();
        while (rs.next()) {
            result.add(MailItem.Type.of(rs.getByte(2)), rs.getInt(1), rs.getString(3));
        }
        return result;
    } catch (SQLException e) {
        throw ServiceException.FAILURE("listing calendar items for mailbox " + mbox.getId(), e);
    } finally {
        DbPool.closeResults(rs);
        DbPool.closeStatement(stmt);
    }
}
Also used : SQLException(java.sql.SQLException) ResultSet(java.sql.ResultSet) PreparedStatement(java.sql.PreparedStatement) TypedIdList(com.zimbra.cs.mailbox.util.TypedIdList) DbConnection(com.zimbra.cs.db.DbPool.DbConnection)

Example 32 with TypedIdList

use of com.zimbra.cs.mailbox.util.TypedIdList in project zm-mailbox by Zimbra.

the class DbMailItem method populateWithResultSetData.

/**
 * @param visible
 * @param modified
 * @param missed
 * @param stmt
 * @return
 * @throws SQLException
 * @throws ServiceException
 */
private static Pair<List<Integer>, TypedIdList> populateWithResultSetData(Set<Integer> visible, PreparedStatement stmt, int lastDeleteSync) throws SQLException, ServiceException {
    List<Integer> modified = new ArrayList<Integer>();
    TypedIdList missed = new TypedIdList();
    ResultSet rs = null;
    try {
        rs = stmt.executeQuery();
        while (rs.next()) {
            if (visible == null || visible.contains(rs.getInt(3))) {
                modified.add(rs.getInt(1));
            } else {
                int modSeq = rs.getInt(5);
                if (modSeq > lastDeleteSync) {
                    missed.add(MailItem.Type.of(rs.getByte(2)), rs.getInt(1), rs.getString(4), modSeq, rs.getString(6));
                }
            }
        }
    } finally {
        DbPool.closeResults(rs);
    }
    return new Pair<List<Integer>, TypedIdList>(modified, missed);
}
Also used : ArrayList(java.util.ArrayList) ResultSet(java.sql.ResultSet) TypedIdList(com.zimbra.cs.mailbox.util.TypedIdList) Pair(com.zimbra.common.util.Pair)

Example 33 with TypedIdList

use of com.zimbra.cs.mailbox.util.TypedIdList in project zm-mailbox by Zimbra.

the class DbMailItem method listConvItems.

/**
 * Return the conversation ids corresponds to messages with given cutoff time.
 * @param folder
 * @param messageSyncStart
 * @param type
 * @param descending
 * @param older
 * @return
 * @throws ServiceException
 */
public static TypedIdList listConvItems(Folder folder, long messageSyncStart, MailItem.Type type, boolean descending, boolean older) throws ServiceException {
    Mailbox mbox = folder.getMailbox();
    assert Db.supports(Db.Capability.ROW_LEVEL_LOCKING) || Thread.holdsLock(mbox);
    TypedIdList result = new TypedIdList();
    DbConnection conn = mbox.getOperationConnection();
    PreparedStatement stmt = null;
    ResultSet rs = null;
    try {
        if (older) {
            stmt = conn.prepareStatement("SELECT parent_id  FROM " + getMailItemTableName(folder) + " WHERE " + IN_THIS_MAILBOX_AND + " type = ? AND date < ?" + " ORDER BY date" + (descending ? " DESC" : ""));
        } else {
            stmt = conn.prepareStatement("SELECT parent_id  FROM " + getMailItemTableName(folder) + " WHERE " + IN_THIS_MAILBOX_AND + " type = ? AND date >= ?" + " ORDER BY date" + (descending ? " DESC" : ""));
        }
        int pos = 1;
        pos = setMailboxId(stmt, mbox, pos);
        // message's parent_id is always conversation..
        stmt.setByte(pos++, MailItem.Type.MESSAGE.toByte());
        stmt.setLong(pos++, messageSyncStart);
        rs = stmt.executeQuery();
        while (rs.next()) {
            int id = rs.getInt(1);
            if (id != 0 && !result.contains(id)) {
                result.add(MailItem.Type.CONVERSATION, id, "");
            }
        }
        return result;
    } catch (SQLException e) {
        throw ServiceException.FAILURE("fetching item list for folder " + folder.getId(), e);
    } finally {
        DbPool.closeResults(rs);
        DbPool.closeStatement(stmt);
    }
}
Also used : Mailbox(com.zimbra.cs.mailbox.Mailbox) SQLException(java.sql.SQLException) ResultSet(java.sql.ResultSet) PreparedStatement(java.sql.PreparedStatement) TypedIdList(com.zimbra.cs.mailbox.util.TypedIdList) DbConnection(com.zimbra.cs.db.DbPool.DbConnection)

Aggregations

TypedIdList (com.zimbra.cs.mailbox.util.TypedIdList)33 MailItem (com.zimbra.cs.mailbox.MailItem)10 Test (org.junit.Test)8 DbConnection (com.zimbra.cs.db.DbPool.DbConnection)6 Folder (com.zimbra.cs.mailbox.Folder)6 MailServiceException (com.zimbra.cs.mailbox.MailServiceException)6 Mailbox (com.zimbra.cs.mailbox.Mailbox)6 ResultSet (java.sql.ResultSet)6 ServiceException (com.zimbra.common.service.ServiceException)5 PreparedStatement (java.sql.PreparedStatement)5 SQLException (java.sql.SQLException)5 List (java.util.List)5 ZFolder (com.zimbra.client.ZFolder)4 Element (com.zimbra.common.soap.Element)4 PagedDelete (com.zimbra.cs.mailbox.util.PagedDelete)4 ArrayList (java.util.ArrayList)4 Pair (com.zimbra.common.util.Pair)3 Account (com.zimbra.cs.account.Account)3 CustomMetadata (com.zimbra.cs.mailbox.MailItem.CustomMetadata)3 Type (com.zimbra.cs.mailbox.MailItem.Type)3