use of com.zimbra.cs.db.DbPool.DbConnection in project zm-mailbox by Zimbra.
the class DbMailItem method getByName.
public static UnderlyingData getByName(Mailbox mbox, int folderId, String name, MailItem.Type type) throws ServiceException {
if (Mailbox.isCachedType(type)) {
throw ServiceException.INVALID_REQUEST("folders and tags must be retrieved from cache", null);
}
DbConnection conn = mbox.getOperationConnection();
PreparedStatement stmt = null;
ResultSet rs = null;
try {
stmt = conn.prepareStatement("SELECT " + DB_FIELDS + " FROM " + getMailItemTableName(mbox, "mi") + " WHERE " + IN_THIS_MAILBOX_AND + "folder_id = ? AND " + typeIn(type) + " AND " + Db.equalsSTRING("name"));
int pos = 1;
pos = setMailboxId(stmt, mbox, pos);
stmt.setInt(pos++, folderId);
stmt.setString(pos++, name);
rs = stmt.executeQuery();
if (!rs.next()) {
throw MailItem.noSuchItem(-1, type);
}
UnderlyingData data = constructItem(rs);
MailItem.Type resultType = MailItem.Type.of(data.type);
if (!MailItem.isAcceptableType(type, resultType)) {
throw MailItem.noSuchItem(data.id, type);
}
if (resultType == MailItem.Type.CONVERSATION) {
completeConversation(mbox, conn, data);
}
return data;
} catch (SQLException e) {
throw ServiceException.FAILURE("fetching item by name ('" + name + "' in folder " + folderId + ")", e);
} finally {
DbPool.closeResults(rs);
DbPool.closeStatement(stmt);
}
}
use of com.zimbra.cs.db.DbPool.DbConnection in project zm-mailbox by Zimbra.
the class DbMailItem method addToCalendarItemTable.
public static void addToCalendarItemTable(CalendarItem calItem) throws ServiceException {
Mailbox mbox = calItem.getMailbox();
long start = calItem.getStartTime();
long end = calItem.getEndTime();
Timestamp startTs = new Timestamp(start);
Timestamp endTs = getEnd(start, end);
DbConnection conn = mbox.getOperationConnection();
PreparedStatement stmt = null;
try {
String mailbox_id = DebugConfig.disableMailboxGroups ? "" : "mailbox_id, ";
stmt = conn.prepareStatement("INSERT INTO " + getCalendarItemTableName(mbox) + " (" + mailbox_id + "uid, item_id, start_time, end_time)" + " VALUES (" + (DebugConfig.disableMailboxGroups ? "" : "?, ") + "?, ?, ?, ?)");
int pos = 1;
pos = setMailboxId(stmt, mbox, pos);
stmt.setString(pos++, calItem.getUid());
stmt.setInt(pos++, calItem.getId());
stmt.setTimestamp(pos++, startTs);
stmt.setTimestamp(pos++, endTs);
stmt.executeUpdate();
} catch (SQLException e) {
throw ServiceException.FAILURE("writing invite to calendar item table: UID=" + calItem.getUid(), e);
} finally {
DbPool.closeStatement(stmt);
}
}
use of com.zimbra.cs.db.DbPool.DbConnection in project zm-mailbox by Zimbra.
the class DbMailbox method setSyncCutoff.
public static void setSyncCutoff(Mailbox mbox, int cutoff) throws ServiceException {
DbConnection conn = mbox.getOperationConnection();
PreparedStatement stmt = null;
try {
stmt = conn.prepareStatement("UPDATE " + qualifyZimbraTableName(mbox, TABLE_MAILBOX) + " SET tracking_sync = ? WHERE id = ? AND tracking_sync < ?");
stmt.setInt(1, cutoff);
stmt.setInt(2, mbox.getId());
stmt.setInt(3, cutoff);
stmt.executeUpdate();
} catch (SQLException e) {
throw ServiceException.FAILURE("turning on sync tracking for mailbox " + mbox.getId(), e);
} finally {
DbPool.closeStatement(stmt);
}
}
use of com.zimbra.cs.db.DbPool.DbConnection in project zm-mailbox by Zimbra.
the class DbMailbox method getConfig.
public static String getConfig(Mailbox mbox, String section) throws ServiceException {
DbConnection conn = mbox.getOperationConnection();
PreparedStatement stmt = null;
ResultSet rs = null;
try {
stmt = conn.prepareStatement("SELECT metadata FROM " + qualifyZimbraTableName(mbox, TABLE_METADATA) + " WHERE " + DbMailItem.IN_THIS_MAILBOX_AND + "section = ?");
int pos = 1;
if (!DebugConfig.disableMailboxGroups) {
stmt.setInt(pos++, mbox.getId());
}
stmt.setString(pos++, section);
rs = stmt.executeQuery();
if (rs.next()) {
return rs.getString(1);
}
return null;
} catch (SQLException e) {
throw ServiceException.FAILURE("getting metadata section '" + section + "' in mailbox " + mbox.getId(), e);
} finally {
DbPool.closeResults(rs);
DbPool.closeStatement(stmt);
}
}
use of com.zimbra.cs.db.DbPool.DbConnection in project zm-mailbox by Zimbra.
the class DbMailbox method updateVersion.
public static void updateVersion(Mailbox mbox, MailboxVersion version) throws ServiceException {
DbConnection conn = mbox.getOperationConnection();
PreparedStatement stmt = null;
try {
stmt = conn.prepareStatement("UPDATE " + qualifyZimbraTableName(mbox, TABLE_MAILBOX) + " SET version = ?" + (DebugConfig.disableMailboxGroups ? "" : " WHERE id = ?"));
int pos = 1;
stmt.setString(pos++, version == null ? null : version.toString());
pos = DbMailItem.setMailboxId(stmt, mbox, pos++);
stmt.executeUpdate();
} catch (SQLException e) {
throw ServiceException.FAILURE("setting mailbox version to '" + version + "' in mailbox " + mbox.getId(), e);
} finally {
DbPool.closeStatement(stmt);
}
}
Aggregations