Search in sources :

Example 11 with TypedIdList

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

the class DbMailItem method listByFolder.

public static TypedIdList listByFolder(Folder folder, boolean descending) throws ServiceException {
    Mailbox mbox = folder.getMailbox();
    TypedIdList result = new TypedIdList();
    DbConnection conn = mbox.getOperationConnection();
    PreparedStatement stmt = null;
    ResultSet rs = null;
    try {
        stmt = conn.prepareStatement("SELECT id, type, uuid FROM " + getMailItemTableName(folder) + " WHERE " + IN_THIS_MAILBOX_AND + "folder_id = ?" + " ORDER BY date" + (descending ? " DESC" : ""));
        int pos = 1;
        pos = setMailboxId(stmt, mbox, pos);
        stmt.setInt(pos++, folder.getId());
        rs = stmt.executeQuery();
        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("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)

Example 12 with TypedIdList

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

the class Mailbox method getTombstones.

public TypedIdList getTombstones(int lastSync, boolean equalModSeq) throws ServiceException {
    lock.lock(false);
    try {
        if (!isTrackingSync()) {
            throw ServiceException.FAILURE("not tracking sync", null);
        } else if (lastSync < getSyncCutoff()) {
            throw MailServiceException.TOMBSTONES_EXPIRED();
        }
        boolean success = false;
        try {
            beginReadTransaction("getTombstones", null);
            TypedIdList tombstones = DbMailItem.readTombstones(this, lastSync, equalModSeq);
            success = true;
            return tombstones;
        } finally {
            endTransaction(success);
        }
    } finally {
        lock.release();
    }
}
Also used : TypedIdList(com.zimbra.cs.mailbox.util.TypedIdList)

Example 13 with TypedIdList

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

the class Mailbox method listItemsForSync.

public TypedIdList listItemsForSync(OperationContext octxt, int folderId, MailItem.Type type, long messageSyncStart) throws ServiceException {
    if (folderId == ID_AUTO_INCREMENT) {
        return new TypedIdList();
    }
    boolean success = false;
    try {
        beginTransaction("listMessageItemsforgivenDate", octxt);
        // if they specified a folder, make sure it actually exists
        Folder folder = getFolderById(folderId);
        TypedIdList ids = DbMailItem.listItems(folder, messageSyncStart, type, true, false);
        success = true;
        return ids;
    } finally {
        endTransaction(success);
    }
}
Also used : CreateFolder(com.zimbra.cs.redolog.op.CreateFolder) ZFolder(com.zimbra.client.ZFolder) TypedIdList(com.zimbra.cs.mailbox.util.TypedIdList)

Example 14 with TypedIdList

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

the class Mailbox method listConvItemsForSync.

public TypedIdList listConvItemsForSync(OperationContext octxt, int folderId, MailItem.Type type, long messageSyncStart) throws ServiceException {
    if (folderId == ID_AUTO_INCREMENT) {
        return new TypedIdList();
    }
    boolean success = false;
    try {
        beginTransaction("listMessageItemsforgivenDate", octxt);
        // if they specified a folder, make sure it actually exists
        Folder folder = getFolderById(folderId);
        TypedIdList ids = DbMailItem.listConvItems(folder, messageSyncStart, type, true, false);
        success = true;
        return ids;
    } finally {
        endTransaction(success);
    }
}
Also used : CreateFolder(com.zimbra.cs.redolog.op.CreateFolder) ZFolder(com.zimbra.client.ZFolder) TypedIdList(com.zimbra.cs.mailbox.util.TypedIdList)

Example 15 with TypedIdList

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

the class CalendarUtils method migrateAppointmentsAndTasks.

/**
     * Move appointments from TASKS type folders to Calendar folder.
     * Also, move tasks from APPOINTMENT type folders to Tasks folder.
     * @param mbox
     * @throws ServiceException
     */
public static void migrateAppointmentsAndTasks(Mailbox mbox) throws ServiceException {
    // get the list of folders.
    List<Folder> folderList = mbox.getFolderList(null, SortBy.NONE);
    for (Folder folder : folderList) {
        int targetId;
        TypedIdList idlist;
        MailItem.Type type;
        if (folder.getDefaultView() == MailItem.Type.APPOINTMENT) {
            // get tasks from this folder and move them to TASKS folder.
            idlist = mbox.listCalendarItemsForRange(null, MailItem.Type.TASK, -1, -1, folder.getId());
            targetId = Mailbox.ID_FOLDER_TASKS;
            type = MailItem.Type.TASK;
        } else if (folder.getDefaultView() == MailItem.Type.TASK) {
            // get appointments from this folder and move them to Calendar folder.
            idlist = mbox.listCalendarItemsForRange(null, MailItem.Type.APPOINTMENT, -1, -1, folder.getId());
            targetId = Mailbox.ID_FOLDER_CALENDAR;
            type = MailItem.Type.APPOINTMENT;
        } else {
            continue;
        }
        if (!idlist.isEmpty()) {
            if (type == MailItem.Type.APPOINTMENT)
                ZimbraLog.calendar.info("Migrating " + idlist.size() + " Appointment(s) from '" + folder.getName() + "' to 'Calendar' folder for mailbox " + mbox.getId());
            else
                ZimbraLog.calendar.info("Migrating " + idlist.size() + " Task(s) from '" + folder.getName() + "' to 'Tasks' folder for mailbox " + mbox.getId());
            int[] items = new int[idlist.size()];
            int i = 0;
            for (Integer id : idlist.getAllIds()) {
                items[i] = id.intValue();
                i++;
            }
            mbox.move(null, items, type, targetId, null);
        }
    }
}
Also used : MailItem(com.zimbra.cs.mailbox.MailItem) Folder(com.zimbra.cs.mailbox.Folder) TypedIdList(com.zimbra.cs.mailbox.util.TypedIdList)

Aggregations

TypedIdList (com.zimbra.cs.mailbox.util.TypedIdList)25 ResultSet (java.sql.ResultSet)7 DbConnection (com.zimbra.cs.db.DbPool.DbConnection)6 PreparedStatement (java.sql.PreparedStatement)6 SQLException (java.sql.SQLException)6 Test (org.junit.Test)6 MailItem (com.zimbra.cs.mailbox.MailItem)5 PagedDelete (com.zimbra.cs.mailbox.util.PagedDelete)5 ZFolder (com.zimbra.client.ZFolder)4 CreateFolder (com.zimbra.cs.redolog.op.CreateFolder)4 ArrayList (java.util.ArrayList)4 List (java.util.List)4 Pair (com.zimbra.common.util.Pair)3 Folder (com.zimbra.cs.mailbox.Folder)3 Type (com.zimbra.cs.mailbox.MailItem.Type)3 Mailbox (com.zimbra.cs.mailbox.Mailbox)3 Element (com.zimbra.common.soap.Element)2 DbTag (com.zimbra.cs.db.DbTag)2 TargetConstraint (com.zimbra.cs.mailbox.MailItem.TargetConstraint)2 AlterItemTag (com.zimbra.cs.redolog.op.AlterItemTag)2