use of com.zimbra.cs.db.DbPool.DbConnection in project zm-mailbox by Zimbra.
the class DbTag method getLeafNodes.
public static PendingDelete getLeafNodes(Mailbox mbox, Tag tag, int before, Integer maxItems) throws ServiceException {
DbConnection conn = mbox.getOperationConnection();
PreparedStatement stmt = null;
ResultSet rs = null;
try {
String orderByLimit = "";
if (maxItems != null && Db.supports(Db.Capability.LIMIT_CLAUSE)) {
orderByLimit = " ORDER BY date " + Db.getInstance().limit(maxItems);
}
String mailboxesMatchAnd = DebugConfig.disableMailboxGroups ? "" : "mi.mailbox_id = ti.mailbox_id AND ";
stmt = conn.prepareStatement("SELECT " + DbMailItem.LEAF_NODE_FIELDS + " FROM " + DbMailItem.getMailItemTableName(mbox, "mi") + " INNER JOIN " + getTaggedItemTableName(mbox, "ti") + " ON " + mailboxesMatchAnd + "ti.item_id = mi.id" + " WHERE " + inThisMailboxAnd("ti") + "ti.tag_id = ? AND date < ? AND type NOT IN " + DbMailItem.NON_SEARCHABLE_TYPES + orderByLimit);
int pos = 1;
pos = DbMailItem.setMailboxId(stmt, mbox, pos);
stmt.setInt(pos++, tag.getId());
stmt.setInt(pos++, before);
PendingDelete info = DbMailItem.accumulateDeletionInfo(mbox, stmt);
stmt = null;
return info;
} catch (SQLException e) {
throw ServiceException.FAILURE("fetching list of items for purge", e);
} finally {
DbPool.closeResults(rs);
DbPool.closeStatement(stmt);
}
}
use of com.zimbra.cs.db.DbPool.DbConnection in project zm-mailbox by Zimbra.
the class DbTag method deleteTagRow.
public static void deleteTagRow(Mailbox mbox, int tagId) throws ServiceException {
DbConnection conn = mbox.getOperationConnection();
PreparedStatement stmt = null;
try {
// delete the TAG row, which automatically cascades into TAGGED_ITEM
stmt = conn.prepareStatement("DELETE FROM " + getTagTableName(mbox) + " WHERE " + DbMailItem.IN_THIS_MAILBOX_AND + "id = ?");
int pos = 1;
pos = DbMailItem.setMailboxId(stmt, mbox, pos);
stmt.setInt(pos++, tagId);
stmt.executeUpdate();
} catch (SQLException e) {
throw ServiceException.FAILURE("deleting tag row for tagId " + tagId, e);
} finally {
DbPool.closeStatement(stmt);
}
}
use of com.zimbra.cs.db.DbPool.DbConnection in project zm-mailbox by Zimbra.
the class DbPop3Message method getMatchingUids.
/**
* Returns the set of persisted UID's that are also in the <code>uids</code>
* collection.
*/
public static Set<String> getMatchingUids(Mailbox mbox, DataSource ds, Collection<String> uids) throws ServiceException {
ZimbraLog.mailbox.debug("%s: looking for uids that match a set of size %d", ds, uids.size());
List<List<String>> splitIds = ListUtil.split(uids, Db.getINClauseBatchSize());
Set<String> matchingUids = new HashSet<String>();
DbConnection conn = null;
PreparedStatement stmt = null;
ResultSet rs = null;
try {
conn = DbPool.getConnection(mbox);
for (List<String> curIds : splitIds) {
stmt = conn.prepareStatement("SELECT uid FROM " + getTableName(mbox) + " WHERE " + DbMailItem.IN_THIS_MAILBOX_AND + "data_source_id = ?" + " AND " + DbUtil.whereIn("uid", curIds.size()));
int pos = 1;
pos = DbMailItem.setMailboxId(stmt, mbox, pos);
stmt.setString(pos++, ds.getId());
for (String uid : curIds) stmt.setString(pos++, uid);
rs = stmt.executeQuery();
while (rs.next()) matchingUids.add(rs.getString(1));
rs.close();
rs = null;
stmt.close();
stmt = null;
}
} catch (SQLException e) {
throw ServiceException.FAILURE("Unable to get UID's", e);
} finally {
DbPool.closeResults(rs);
DbPool.closeStatement(stmt);
DbPool.quietClose(conn);
}
ZimbraLog.mailbox.debug("Found %d matching UID's", matchingUids.size());
return matchingUids;
}
use of com.zimbra.cs.db.DbPool.DbConnection in project zm-mailbox by Zimbra.
the class DbTag method getTag.
public static UnderlyingData getTag(Mailbox mbox, String name) throws ServiceException {
DbConnection conn = mbox.getOperationConnection();
PreparedStatement stmt = null;
ResultSet rs = null;
try {
stmt = conn.prepareStatement("SELECT " + TAG_FIELDS + " FROM " + getTagTableName(mbox) + " WHERE " + DbMailItem.IN_THIS_MAILBOX_AND + "name = ?");
int pos = 1;
pos = DbMailItem.setMailboxId(stmt, mbox, pos);
stmt.setString(pos++, name);
rs = stmt.executeQuery();
return rs.next() ? asUnderlyingData(rs) : null;
} catch (SQLException e) {
throw ServiceException.FAILURE("fetching tag " + name, e);
} finally {
DbPool.closeResults(rs);
DbPool.closeStatement(stmt);
}
}
use of com.zimbra.cs.db.DbPool.DbConnection in project zm-mailbox by Zimbra.
the class DbTag method persistCounts.
public static void persistCounts(Tag tag) throws ServiceException {
Mailbox mbox = tag.getMailbox();
DbConnection conn = mbox.getOperationConnection();
PreparedStatement stmt = null;
try {
stmt = conn.prepareStatement("UPDATE " + getTagTableName(mbox) + " SET item_count = ?, unread = ? WHERE " + DbMailItem.IN_THIS_MAILBOX_AND + "id = ?");
int pos = 1;
stmt.setInt(pos++, (int) tag.getSize());
stmt.setInt(pos++, tag.getUnreadCount());
pos = DbMailItem.setMailboxId(stmt, mbox, pos);
stmt.setInt(pos++, tag.getId());
stmt.executeUpdate();
} catch (SQLException e) {
throw ServiceException.FAILURE("updating counts for tag " + tag.getName(), e);
} finally {
DbPool.closeStatement(stmt);
}
}
Aggregations