use of com.zimbra.cs.mailbox.Metadata in project zm-mailbox by Zimbra.
the class DbTag method asUnderlyingData.
private static UnderlyingData asUnderlyingData(ResultSet rs) throws SQLException, ServiceException {
UnderlyingData data = new UnderlyingData();
data.id = rs.getInt(1);
data.type = MailItem.Type.TAG.toByte();
data.folderId = Mailbox.ID_FOLDER_TAGS;
data.name = rs.getString(2);
data.size = rs.getInt(4);
data.unreadCount = rs.getInt(5);
boolean listed = rs.getBoolean(6);
String policy = rs.getString(8);
RetentionPolicy rp = policy == null ? null : RetentionPolicyManager.retentionPolicyFromMetadata(new Metadata(policy), true);
long c = rs.getLong(3);
Color color = rs.wasNull() ? null : Color.fromMetadata(c);
// FIXME: if Tag weren't a subclass of MailItem, this step wouldn't be necessary
data.metadata = Tag.encodeMetadata(color, 1, 1, rp, listed);
data.modMetadata = rs.getInt(7);
data.modContent = data.modMetadata;
return data;
}
use of com.zimbra.cs.mailbox.Metadata in project zm-mailbox by Zimbra.
the class DbDataSource method getAllMappingsInFolder.
public static Collection<DataSourceItem> getAllMappingsInFolder(DataSource ds, int folderId) throws ServiceException {
Mailbox mbox = DataSourceManager.getInstance().getMailbox(ds);
ArrayList<DataSourceItem> items = new ArrayList<DataSourceItem>();
ZimbraLog.datasource.debug("Get all mappings for %s in folder %d", ds.getName(), folderId);
DbConnection conn = null;
PreparedStatement stmt = null;
ResultSet rs = null;
try {
conn = DbPool.getConnection(mbox);
String thisTable = getTableName(mbox);
String IN_THIS_MAILBOX_AND = DebugConfig.disableMailboxGroups ? "" : thisTable + ".mailbox_id = ? AND ";
StringBuilder sb = new StringBuilder();
sb.append("SELECT item_id, remote_id, ").append(thisTable).append(".metadata FROM ");
sb.append(thisTable);
sb.append(" WHERE ");
sb.append(IN_THIS_MAILBOX_AND);
sb.append(" data_source_id = ? AND folder_id = ?");
stmt = conn.prepareStatement(sb.toString());
int pos = 1;
pos = DbMailItem.setMailboxId(stmt, mbox, pos);
stmt.setString(pos++, ds.getId());
stmt.setInt(pos++, folderId);
rs = stmt.executeQuery();
while (rs.next()) {
Metadata md = null;
String buf = DbMailItem.decodeMetadata(rs.getString(3));
if (buf != null)
md = new Metadata(buf);
items.add(new DataSourceItem(folderId, rs.getInt(1), rs.getString(2), md));
}
rs.close();
stmt.close();
} catch (SQLException e) {
throw ServiceException.FAILURE("Unable to get mapping for dataSource " + ds.getName(), e);
} finally {
DbPool.closeResults(rs);
DbPool.closeStatement(stmt);
DbPool.quietClose(conn);
}
return items;
}
use of com.zimbra.cs.mailbox.Metadata in project zm-mailbox by Zimbra.
the class DbDataSource method getMappings.
public static Collection<DataSourceItem> getMappings(DataSource ds, Collection<Integer> ids) throws ServiceException {
Mailbox mbox = DataSourceManager.getInstance().getMailbox(ds);
int folderId = 0;
int itemId = 0;
String remoteId = null;
Metadata md = null;
List<List<Integer>> splitIds = ListUtil.split(ids, Db.getINClauseBatchSize());
ArrayList<DataSourceItem> items = new ArrayList<DataSourceItem>();
ZimbraLog.datasource.debug("Get mappings for %s", ds.getName());
DbConnection conn = null;
PreparedStatement stmt = null;
ResultSet rs = null;
try {
conn = DbPool.getConnection(mbox);
for (List<Integer> curIds : splitIds) {
StringBuilder sb = new StringBuilder();
sb.append("SELECT item_id, remote_id, folder_id, metadata FROM ");
sb.append(getTableName(mbox));
sb.append(" WHERE ");
sb.append(DbMailItem.IN_THIS_MAILBOX_AND);
sb.append(" data_source_id = ? AND ");
sb.append(DbUtil.whereIn("item_id", curIds.size()));
stmt = conn.prepareStatement(sb.toString());
int i = 1;
i = DbMailItem.setMailboxId(stmt, mbox, i);
stmt.setString(i++, ds.getId());
for (int uid : curIds) stmt.setInt(i++, uid);
rs = stmt.executeQuery();
while (rs.next()) {
itemId = rs.getInt(1);
remoteId = rs.getString(2);
folderId = rs.getInt(3);
String buf = DbMailItem.decodeMetadata(rs.getString(4));
if (buf != null)
md = new Metadata(buf);
items.add(new DataSourceItem(folderId, itemId, remoteId, md));
}
rs.close();
stmt.close();
}
} catch (SQLException e) {
throw ServiceException.FAILURE("Unable to get mapping for dataSource " + ds.getName(), e);
} finally {
DbPool.closeResults(rs);
DbPool.closeStatement(stmt);
DbPool.quietClose(conn);
}
return items;
}
use of com.zimbra.cs.mailbox.Metadata in project zm-mailbox by Zimbra.
the class DbDataSource method getReverseMappings.
public static Collection<DataSourceItem> getReverseMappings(DataSource ds, Collection<String> remoteIds) throws ServiceException {
Mailbox mbox = DataSourceManager.getInstance().getMailbox(ds);
int folderId = 0;
int itemId = 0;
String remoteId;
Metadata md = null;
List<List<String>> splitIds = ListUtil.split(remoteIds, Db.getINClauseBatchSize());
ArrayList<DataSourceItem> items = new ArrayList<DataSourceItem>();
ZimbraLog.datasource.debug("Get reverse mappings for %s", ds.getName());
DbConnection conn = null;
PreparedStatement stmt = null;
ResultSet rs = null;
try {
conn = DbPool.getConnection(mbox);
for (List<String> curIds : splitIds) {
StringBuilder sb = new StringBuilder();
sb.append("SELECT item_id, remote_id, folder_id, metadata FROM ");
sb.append(getTableName(mbox));
sb.append(" WHERE ");
sb.append(DbMailItem.IN_THIS_MAILBOX_AND);
sb.append(" data_source_id = ? AND ");
sb.append(DbUtil.whereIn("remote_id", curIds.size()));
stmt = conn.prepareStatement(sb.toString());
int i = 1;
i = DbMailItem.setMailboxId(stmt, mbox, i);
stmt.setString(i++, ds.getId());
for (String uid : curIds) stmt.setString(i++, uid);
rs = stmt.executeQuery();
while (rs.next()) {
itemId = rs.getInt(1);
remoteId = rs.getString(2);
folderId = rs.getInt(3);
String buf = DbMailItem.decodeMetadata(rs.getString(4));
if (buf != null)
md = new Metadata(buf);
items.add(new DataSourceItem(folderId, itemId, remoteId, md));
}
rs.close();
stmt.close();
}
} catch (SQLException e) {
throw ServiceException.FAILURE("Unable to get reverse mapping for dataSource " + ds.getName(), e);
} finally {
DbPool.closeResults(rs);
DbPool.closeStatement(stmt);
DbPool.quietClose(conn);
}
return items;
}
use of com.zimbra.cs.mailbox.Metadata in project zm-mailbox by Zimbra.
the class DbDataSource method getAllMappingsForRemoteIdPrefix.
public static Collection<DataSourceItem> getAllMappingsForRemoteIdPrefix(DataSource ds, int folderId, String prefix) throws ServiceException {
Mailbox mbox = DataSourceManager.getInstance().getMailbox(ds);
List<DataSourceItem> items = new ArrayList<DataSourceItem>();
DbConnection conn = null;
PreparedStatement stmt = null;
ResultSet rs = null;
try {
conn = DbPool.getConnection(mbox);
String db = DbMailbox.getDatabaseName(mbox);
String dst = db + ".data_source_item";
String mit = db + ".mail_item";
Formatter fmt = new Formatter();
fmt.format("SELECT item_id, remote_id, %s.metadata FROM %s", dst, dst);
fmt.format(" INNER JOIN %s ON %s.item_id = %s.id", mit, dst, mit);
fmt.format(" WHERE %s.mailbox_id = ?", dst);
fmt.format(" AND data_source_id = ? AND folder_id = ?");
if (prefix != null) {
fmt.format(" AND remote_id LIKE '%s%%'", prefix);
}
stmt = conn.prepareStatement(fmt.toString());
stmt.setInt(1, mbox.getId());
stmt.setString(2, ds.getId());
stmt.setInt(3, folderId);
rs = stmt.executeQuery();
while (rs.next()) {
String s = DbMailItem.decodeMetadata(rs.getString(3));
Metadata md = s != null ? new Metadata(s) : null;
items.add(new DataSourceItem(folderId, rs.getInt(1), rs.getString(2), md));
}
} catch (SQLException e) {
throw ServiceException.FAILURE("Unable to get mapping for data source " + ds.getName(), e);
} finally {
DbPool.closeResults(rs);
DbPool.closeStatement(stmt);
DbPool.quietClose(conn);
}
return items;
}
Aggregations