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;
}
use of com.zimbra.cs.mailbox.Metadata in project zm-mailbox by Zimbra.
the class CreateInvite method deserializeData.
@Override
protected void deserializeData(RedoLogInput in) throws IOException {
mCalendarItemId = in.readInt();
if (getVersion().atLeast(1, 1))
mCalendarItemPartStat = in.readUTF();
mFolderId = in.readInt();
if (getVersion().atLeast(1, 0))
in.readShort();
// keep this for backward compatibility when there was mForce field
in.readBoolean();
// in this class
int dataLen = in.readInt();
if (dataLen > 0) {
mData = new byte[dataLen];
in.readFully(mData);
}
try {
ICalTimeZone localTz = Util.decodeTimeZoneFromMetadata(new Metadata(in.readUTF()));
mInvite = Invite.decodeMetadata(getMailboxId(), new Metadata(in.readUTF()), null, localTz);
} catch (ServiceException ex) {
ex.printStackTrace();
throw new IOException("Cannot read serialized entry for CreateInvite " + ex.toString());
}
if (getVersion().atLeast(1, 22)) {
mPreserveExistingAlarms = in.readBoolean();
mDiscardExistingInvites = in.readBoolean();
} else {
mPreserveExistingAlarms = false;
mDiscardExistingInvites = false;
}
if (getVersion().atLeast(1, 23))
mAddRevision = in.readBoolean();
else
mAddRevision = false;
}
Aggregations