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();
}
}
}
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;
}
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();
}
}
}
}
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();
}
}
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);
}
}
Aggregations