Search in sources :

Example 96 with DbConnection

use of com.zimbra.cs.db.DbPool.DbConnection in project zm-mailbox by Zimbra.

the class DbTag method debugConsistencyCheck.

@VisibleForTesting
public static void debugConsistencyCheck(Mailbox mbox) throws ServiceException {
    DbConnection conn = mbox.lock.isWriteLockedByCurrentThread() ? mbox.getOperationConnection() : DbPool.getConnection(mbox);
    PreparedStatement stmt = null;
    ResultSet rs = null;
    try {
        Map<Integer, UnderlyingData> tdata = Maps.newHashMap();
        // make sure the item counts match the tag totals
        stmt = conn.prepareStatement("SELECT " + TAG_FIELDS + " FROM " + getTagTableName(mbox) + " WHERE " + DbMailItem.IN_THIS_MAILBOX_AND + "id > 0");
        DbMailItem.setMailboxId(stmt, mbox, 1);
        rs = stmt.executeQuery();
        while (rs.next()) {
            UnderlyingData data = asUnderlyingData(rs);
            tdata.put(data.id, data);
        }
        DbPool.closeResults(rs);
        rs = null;
        DbPool.closeStatement(stmt);
        stmt = null;
        // catch spurious TAGGED_ITEM entries
        validateTaggedItem(conn, mbox, tdata);
        // make sure the TAGGED_ITEM table is accurate
        verifyTaggedItem(conn, mbox, tdata);
        // make sure the item counts match the tag totals
        verifyTagCounts(conn, mbox, tdata);
    } catch (SQLException e) {
        throw ServiceException.FAILURE("consistency checking tags/flags for mailbox " + mbox.getId(), e);
    } finally {
        DbPool.closeResults(rs);
        DbPool.closeStatement(stmt);
        if (!mbox.lock.isWriteLockedByCurrentThread()) {
            conn.close();
        }
    }
}
Also used : SQLException(java.sql.SQLException) UnderlyingData(com.zimbra.cs.mailbox.MailItem.UnderlyingData) ResultSet(java.sql.ResultSet) PreparedStatement(java.sql.PreparedStatement) DbConnection(com.zimbra.cs.db.DbPool.DbConnection) VisibleForTesting(com.google.common.annotations.VisibleForTesting)

Example 97 with DbConnection

use of com.zimbra.cs.db.DbPool.DbConnection in project zm-mailbox by Zimbra.

the class DbPendingAclPush method getEntries.

public static Multimap<Integer, Integer> getEntries(Date uptoTime) throws ServiceException {
    Multimap<Integer, Integer> mboxIdToItemIds = HashMultimap.create();
    DbConnection conn = null;
    PreparedStatement stmt = null;
    ResultSet rs = null;
    ZimbraLog.misc.debug("Getting entries recorded before %s for ACL push", uptoTime);
    try {
        conn = DbPool.getConnection();
        stmt = conn.prepareStatement("SELECT mailbox_id, item_id FROM " + TABLE_PENDING_ACL_PUSH + " WHERE date < ?");
        stmt.setLong(1, uptoTime.getTime());
        rs = stmt.executeQuery();
        while (rs.next()) {
            mboxIdToItemIds.put(rs.getInt(1), rs.getInt(2));
        }
    } catch (SQLException e) {
        throw ServiceException.FAILURE("Unable to get entries recorded before " + uptoTime + " for ACL push", e);
    } finally {
        DbPool.closeResults(rs);
        DbPool.closeStatement(stmt);
        DbPool.quietClose(conn);
    }
    return mboxIdToItemIds;
}
Also used : SQLException(java.sql.SQLException) ResultSet(java.sql.ResultSet) PreparedStatement(java.sql.PreparedStatement) DbConnection(com.zimbra.cs.db.DbPool.DbConnection)

Example 98 with DbConnection

use of com.zimbra.cs.db.DbPool.DbConnection in project zm-mailbox by Zimbra.

the class VolumeManager method create.

public Volume create(Volume volume, boolean noRedo) throws ServiceException {
    CreateVolume redoRecorder = null;
    if (!noRedo) {
        redoRecorder = new CreateVolume(volume);
        redoRecorder.start(System.currentTimeMillis());
    }
    boolean success = false;
    DbConnection conn = DbPool.getConnection();
    try {
        volume = DbVolume.create(conn, volume);
        success = true;
        if (!noRedo) {
            redoRecorder.setId(volume.getId());
            redoRecorder.log();
        }
        return volume;
    } finally {
        endTransaction(success, conn, redoRecorder);
        if (success) {
            synchronized (this) {
                id2volume.put(volume.getId(), volume);
                updateSweptDirectories();
            }
        }
    }
}
Also used : CreateVolume(com.zimbra.cs.redolog.op.CreateVolume) DbConnection(com.zimbra.cs.db.DbPool.DbConnection)

Example 99 with DbConnection

use of com.zimbra.cs.db.DbPool.DbConnection in project zm-mailbox by Zimbra.

the class VolumeManager method getVolume.

public Volume getVolume(short id) throws ServiceException {
    Volume vol = null;
    synchronized (this) {
        vol = id2volume.get(id);
    }
    if (vol != null) {
        return vol;
    }
    // Look up from db.
    DbConnection conn = DbPool.getConnection();
    try {
        vol = DbVolume.get(conn, id);
        if (vol != null) {
            synchronized (this) {
                id2volume.put(id, vol);
            }
            return vol;
        } else {
            throw VolumeServiceException.NO_SUCH_VOLUME(id);
        }
    } finally {
        conn.closeQuietly();
    }
}
Also used : DeleteVolume(com.zimbra.cs.redolog.op.DeleteVolume) ModifyVolume(com.zimbra.cs.redolog.op.ModifyVolume) DbVolume(com.zimbra.cs.db.DbVolume) CreateVolume(com.zimbra.cs.redolog.op.CreateVolume) SetCurrentVolume(com.zimbra.cs.redolog.op.SetCurrentVolume) DbConnection(com.zimbra.cs.db.DbPool.DbConnection)

Example 100 with DbConnection

use of com.zimbra.cs.db.DbPool.DbConnection in project zm-mailbox by Zimbra.

the class WikiDigestFixup method main.

public static void main(String[] args) {
    CliUtil.toolSetup("WARN");
    sStore = StoreManager.getInstance();
    DbPool.startup();
    DbConnection conn = null;
    try {
        int numFixed = 0;
        conn = DbPool.getConnection();
        System.out.println("Getting mailbox list...");
        List<Mbox> mboxList = getMboxList(conn);
        for (Mbox m : mboxList) {
            int mboxId = m.getId();
            System.out.println("Processing mailbox " + mboxId + " (" + m.getEmail() + ") ...");
            System.out.println("Getting wiki items needing fixup...");
            List<WikiDigest> digests = getWikiDigests(mboxId);
            int howmany = digests != null ? digests.size() : 0;
            System.out.println("Got " + howmany + " wiki items to fixup.");
            if (howmany > 0) {
                fixupItems(conn, mboxId, digests);
                numFixed += howmany;
            }
            System.out.println("Done with mailbox " + mboxId + ".");
        }
        System.out.println("Done.  Fixed " + numFixed + " wiki items.");
    } catch (Exception e) {
        System.err.println("Error: " + e.getMessage());
        e.printStackTrace(System.err);
    } finally {
        DbPool.quietClose(conn);
    }
}
Also used : DbConnection(com.zimbra.cs.db.DbPool.DbConnection) AccountServiceException(com.zimbra.cs.account.AccountServiceException) IOException(java.io.IOException) ServiceException(com.zimbra.common.service.ServiceException) SQLException(java.sql.SQLException)

Aggregations

DbConnection (com.zimbra.cs.db.DbPool.DbConnection)218 PreparedStatement (java.sql.PreparedStatement)165 SQLException (java.sql.SQLException)162 ResultSet (java.sql.ResultSet)85 Mailbox (com.zimbra.cs.mailbox.Mailbox)71 ArrayList (java.util.ArrayList)36 ServiceException (com.zimbra.common.service.ServiceException)23 UnderlyingData (com.zimbra.cs.mailbox.MailItem.UnderlyingData)18 HashMap (java.util.HashMap)10 Metadata (com.zimbra.cs.mailbox.Metadata)9 IOException (java.io.IOException)9 MailItem (com.zimbra.cs.mailbox.MailItem)8 TypedIdList (com.zimbra.cs.mailbox.util.TypedIdList)8 AccountServiceException (com.zimbra.cs.account.AccountServiceException)7 Folder (com.zimbra.cs.mailbox.Folder)7 List (java.util.List)6 DbVolume (com.zimbra.cs.db.DbVolume)5 PendingDelete (com.zimbra.cs.mailbox.MailItem.PendingDelete)5 VirtualConversation (com.zimbra.cs.mailbox.VirtualConversation)5 CreateVolume (com.zimbra.cs.redolog.op.CreateVolume)5