@Test public void testGetGroups() throws Exception { Database<Connection> db = open(false); Connection txn = db.startTransaction(); assertEquals(emptyList(), db.getGroups(txn, clientId, majorVersion)); db.addGroup(txn, group); assertEquals(singletonList(group), db.getGroups(txn, clientId, majorVersion)); db.removeGroup(txn, groupId); assertEquals(emptyList(), db.getGroups(txn, clientId, majorVersion)); db.commitTransaction(txn); db.close(); }
@Override public Collection<Group> getGroups(Connection txn, ClientId c, int majorVersion) throws DbException { PreparedStatement ps = null; ResultSet rs = null; try { String sql = "SELECT groupId, descriptor FROM groups" + " WHERE clientId = ? AND majorVersion = ?"; ps = txn.prepareStatement(sql); ps.setString(1, c.getString()); ps.setInt(2, majorVersion); rs = ps.executeQuery(); List<Group> groups = new ArrayList<>(); while (rs.next()) { GroupId id = new GroupId(rs.getBytes(1)); byte[] descriptor = rs.getBytes(2); groups.add(new Group(id, c, majorVersion, descriptor)); } rs.close(); ps.close(); return groups; } catch (SQLException e) { tryToClose(rs); tryToClose(ps); throw new DbException(e); } }
JdbcDatabase implements Database<Connection> { @Override public Collection<Group> getGroups(Connection txn, ClientId c, int majorVersion) throws DbException { PreparedStatement ps = null; ResultSet rs = null; try { String sql = "SELECT groupId, descriptor FROM groups" + " WHERE clientId = ? AND majorVersion = ?"; ps = txn.prepareStatement(sql); ps.setString(1, c.getString()); ps.setInt(2, majorVersion); rs = ps.executeQuery(); List<Group> groups = new ArrayList<>(); while (rs.next()) { GroupId id = new GroupId(rs.getBytes(1)); byte[] descriptor = rs.getBytes(2); groups.add(new Group(id, c, majorVersion, descriptor)); } rs.close(); ps.close(); return groups; } catch (SQLException e) { tryToClose(rs); tryToClose(ps); throw new DbException(e); } } }
JdbcDatabase implements Database<Connection> { @Override public Collection<Group> getGroups(Connection txn, ClientId c, int majorVersion) throws DbException { PreparedStatement ps = null; ResultSet rs = null; try { String sql = "SELECT groupId, descriptor FROM groups" + " WHERE clientId = ? AND majorVersion = ?"; ps = txn.prepareStatement(sql); ps.setString(1, c.getString()); ps.setInt(2, majorVersion); rs = ps.executeQuery(); List<Group> groups = new ArrayList<>(); while (rs.next()) { GroupId id = new GroupId(rs.getBytes(1)); byte[] descriptor = rs.getBytes(2); groups.add(new Group(id, c, majorVersion, descriptor)); } rs.close(); ps.close(); return groups; } catch (SQLException e) { tryToClose(rs); tryToClose(ps); throw new DbException(e); } } JdbcDatabase(String hashType, String secretType, String binaryType,
			String counterType, String stringType, Clock clock); }
JdbcDatabase implements Database<Connection> { @Override public Collection<Group> getGroups(Connection txn, ClientId c, int majorVersion) throws DbException { PreparedStatement ps = null; ResultSet rs = null; try { String sql = "SELECT groupId, descriptor FROM groups" + " WHERE clientId = ? AND majorVersion = ?"; ps = txn.prepareStatement(sql); ps.setString(1, c.getString()); ps.setInt(2, majorVersion); rs = ps.executeQuery(); List<Group> groups = new ArrayList<>(); while (rs.next()) { GroupId id = new GroupId(rs.getBytes(1)); byte[] descriptor = rs.getBytes(2); groups.add(new Group(id, c, majorVersion, descriptor)); } rs.close(); ps.close(); return groups; } catch (SQLException e) { tryToClose(rs); tryToClose(ps); throw new DbException(e); } } JdbcDatabase(String hashType, String secretType, String binaryType,
			String counterType, String stringType, Clock clock); @Override Connection startTransaction(); @Override void abortTransaction(Connection txn); @Override void commitTransaction(Connection txn); @Override ContactId addContact(Connection txn, Author remote, AuthorId local,
			boolean verified, boolean active); @Override void addGroup(Connection txn, Group g); @Override void addGroupVisibility(Connection txn, ContactId c, GroupId g,
			boolean groupShared); @Override void addLocalAuthor(Connection txn, LocalAuthor a); @Override void addMessage(Connection txn, Message m, State state,
			boolean messageShared, @Nullable ContactId sender); @Override void addOfferedMessage(Connection txn, ContactId c, MessageId m); @Override void addMessageDependency(Connection txn, Message dependent,
			MessageId dependency, State dependentState); @Override void addTransport(Connection txn, TransportId t, int maxLatency); @Override KeySetId addTransportKeys(Connection txn, ContactId c,
			TransportKeys k); @Override boolean containsContact(Connection txn, AuthorId remote,
			AuthorId local); @Override boolean containsContact(Connection txn, ContactId c); @Override boolean containsGroup(Connection txn, GroupId g); @Override boolean containsLocalAuthor(Connection txn, AuthorId a); @Override boolean containsMessage(Connection txn, MessageId m); @Override boolean containsTransport(Connection txn, TransportId t); @Override boolean containsVisibleMessage(Connection txn, ContactId c,
			MessageId m); @Override int countOfferedMessages(Connection txn, ContactId c); @Override void deleteMessage(Connection txn, MessageId m); @Override void deleteMessageMetadata(Connection txn, MessageId m); @Override Contact getContact(Connection txn, ContactId c); @Override Collection<Contact> getContacts(Connection txn); @Override Collection<ContactId> getContacts(Connection txn, AuthorId local); @Override Collection<Contact> getContactsByAuthorId(Connection txn,
			AuthorId remote); @Override Group getGroup(Connection txn, GroupId g); @Override Collection<Group> getGroups(Connection txn, ClientId c,
			int majorVersion); @Override Visibility getGroupVisibility(Connection txn, ContactId c, GroupId g); @Override Map<ContactId, Boolean> getGroupVisibility(Connection txn, GroupId g); @Override LocalAuthor getLocalAuthor(Connection txn, AuthorId a); @Override Collection<LocalAuthor> getLocalAuthors(Connection txn); @Override Collection<MessageId> getMessageIds(Connection txn, GroupId g); @Override Collection<MessageId> getMessageIds(Connection txn, GroupId g,
			Metadata query); @Override Map<MessageId, Metadata> getMessageMetadata(Connection txn,
			GroupId g); @Override Map<MessageId, Metadata> getMessageMetadata(Connection txn,
			GroupId g, Metadata query); @Override Metadata getGroupMetadata(Connection txn, GroupId g); @Override Metadata getMessageMetadata(Connection txn, MessageId m); @Override Metadata getMessageMetadataForValidator(Connection txn, MessageId m); @Override Collection<MessageStatus> getMessageStatus(Connection txn,
			ContactId c, GroupId g); @Override @Nullable MessageStatus getMessageStatus(Connection txn, ContactId c,
			MessageId m); @Override Map<MessageId, State> getMessageDependencies(Connection txn,
			MessageId m); @Override Map<MessageId, State> getMessageDependents(Connection txn,
			MessageId m); @Override State getMessageState(Connection txn, MessageId m); @Override Collection<MessageId> getMessagesToAck(Connection txn, ContactId c,
			int maxMessages); @Override Collection<MessageId> getMessagesToOffer(Connection txn,
			ContactId c, int maxMessages); @Override Collection<MessageId> getMessagesToRequest(Connection txn,
			ContactId c, int maxMessages); @Override Collection<MessageId> getMessagesToSend(Connection txn, ContactId c,
			int maxLength); @Override Collection<MessageId> getMessagesToValidate(Connection txn); @Override Collection<MessageId> getPendingMessages(Connection txn); @Override Collection<MessageId> getMessagesToShare(Connection txn); @Override long getNextSendTime(Connection txn, ContactId c); @Override @Nullable byte[] getRawMessage(Connection txn, MessageId m); @Override Collection<MessageId> getRequestedMessagesToSend(Connection txn,
			ContactId c, int maxLength); @Override Settings getSettings(Connection txn, String namespace); @Override Collection<KeySet> getTransportKeys(Connection txn, TransportId t); @Override void incrementStreamCounter(Connection txn, TransportId t,
			KeySetId k); @Override void lowerAckFlag(Connection txn, ContactId c,
			Collection<MessageId> acked); @Override void lowerRequestedFlag(Connection txn, ContactId c,
			Collection<MessageId> requested); @Override void mergeGroupMetadata(Connection txn, GroupId g, Metadata meta); @Override void mergeMessageMetadata(Connection txn, MessageId m,
			Metadata meta); @Override void mergeSettings(Connection txn, Settings s, String namespace); @Override void raiseAckFlag(Connection txn, ContactId c, MessageId m); @Override void raiseRequestedFlag(Connection txn, ContactId c, MessageId m); @Override void raiseSeenFlag(Connection txn, ContactId c, MessageId m); @Override void removeContact(Connection txn, ContactId c); @Override void removeGroup(Connection txn, GroupId g); @Override void removeGroupVisibility(Connection txn, ContactId c, GroupId g); @Override void removeLocalAuthor(Connection txn, AuthorId a); @Override void removeMessage(Connection txn, MessageId m); @Override void removeOfferedMessages(Connection txn, ContactId c,
			Collection<MessageId> requested); @Override void removeTransport(Connection txn, TransportId t); @Override void removeTransportKeys(Connection txn, TransportId t, KeySetId k); @Override void resetExpiryTime(Connection txn, ContactId c, MessageId m); @Override void setContactVerified(Connection txn, ContactId c); @Override void setContactActive(Connection txn, ContactId c, boolean active); @Override void setGroupVisibility(Connection txn, ContactId c, GroupId g,
			boolean shared); @Override void setMessageShared(Connection txn, MessageId m); @Override void setMessageState(Connection txn, MessageId m, State state); @Override void setReorderingWindow(Connection txn, KeySetId k, TransportId t,
			long rotationPeriod, long base, byte[] bitmap); @Override void setTransportKeysActive(Connection txn, TransportId t,
			KeySetId k); @Override void updateExpiryTime(Connection txn, ContactId c, MessageId m,
			int maxLatency); @Override void updateTransportKeys(Connection txn, KeySet ks); }
JdbcDatabase implements Database<Connection> { @Override public Collection<Group> getGroups(Connection txn, ClientId c, int majorVersion) throws DbException { PreparedStatement ps = null; ResultSet rs = null; try { String sql = "SELECT groupId, descriptor FROM groups" + " WHERE clientId = ? AND majorVersion = ?"; ps = txn.prepareStatement(sql); ps.setString(1, c.getString()); ps.setInt(2, majorVersion); rs = ps.executeQuery(); List<Group> groups = new ArrayList<>(); while (rs.next()) { GroupId id = new GroupId(rs.getBytes(1)); byte[] descriptor = rs.getBytes(2); groups.add(new Group(id, c, majorVersion, descriptor)); } rs.close(); ps.close(); return groups; } catch (SQLException e) { tryToClose(rs); tryToClose(ps); throw new DbException(e); } } JdbcDatabase(String hashType, String secretType, String binaryType,
			String counterType, String stringType, Clock clock); @Override Connection startTransaction(); @Override void abortTransaction(Connection txn); @Override void commitTransaction(Connection txn); @Override ContactId addContact(Connection txn, Author remote, AuthorId local,
			boolean verified, boolean active); @Override void addGroup(Connection txn, Group g); @Override void addGroupVisibility(Connection txn, ContactId c, GroupId g,
			boolean groupShared); @Override void addLocalAuthor(Connection txn, LocalAuthor a); @Override void addMessage(Connection txn, Message m, State state,
			boolean messageShared, @Nullable ContactId sender); @Override void addOfferedMessage(Connection txn, ContactId c, MessageId m); @Override void addMessageDependency(Connection txn, Message dependent,
			MessageId dependency, State dependentState); @Override void addTransport(Connection txn, TransportId t, int maxLatency); @Override KeySetId addTransportKeys(Connection txn, ContactId c,
			TransportKeys k); @Override boolean containsContact(Connection txn, AuthorId remote,
			AuthorId local); @Override boolean containsContact(Connection txn, ContactId c); @Override boolean containsGroup(Connection txn, GroupId g); @Override boolean containsLocalAuthor(Connection txn, AuthorId a); @Override boolean containsMessage(Connection txn, MessageId m); @Override boolean containsTransport(Connection txn, TransportId t); @Override boolean containsVisibleMessage(Connection txn, ContactId c,
			MessageId m); @Override int countOfferedMessages(Connection txn, ContactId c); @Override void deleteMessage(Connection txn, MessageId m); @Override void deleteMessageMetadata(Connection txn, MessageId m); @Override Contact getContact(Connection txn, ContactId c); @Override Collection<Contact> getContacts(Connection txn); @Override Collection<ContactId> getContacts(Connection txn, AuthorId local); @Override Collection<Contact> getContactsByAuthorId(Connection txn,
			AuthorId remote); @Override Group getGroup(Connection txn, GroupId g); @Override Collection<Group> getGroups(Connection txn, ClientId c,
			int majorVersion); @Override Visibility getGroupVisibility(Connection txn, ContactId c, GroupId g); @Override Map<ContactId, Boolean> getGroupVisibility(Connection txn, GroupId g); @Override LocalAuthor getLocalAuthor(Connection txn, AuthorId a); @Override Collection<LocalAuthor> getLocalAuthors(Connection txn); @Override Collection<MessageId> getMessageIds(Connection txn, GroupId g); @Override Collection<MessageId> getMessageIds(Connection txn, GroupId g,
			Metadata query); @Override Map<MessageId, Metadata> getMessageMetadata(Connection txn,
			GroupId g); @Override Map<MessageId, Metadata> getMessageMetadata(Connection txn,
			GroupId g, Metadata query); @Override Metadata getGroupMetadata(Connection txn, GroupId g); @Override Metadata getMessageMetadata(Connection txn, MessageId m); @Override Metadata getMessageMetadataForValidator(Connection txn, MessageId m); @Override Collection<MessageStatus> getMessageStatus(Connection txn,
			ContactId c, GroupId g); @Override @Nullable MessageStatus getMessageStatus(Connection txn, ContactId c,
			MessageId m); @Override Map<MessageId, State> getMessageDependencies(Connection txn,
			MessageId m); @Override Map<MessageId, State> getMessageDependents(Connection txn,
			MessageId m); @Override State getMessageState(Connection txn, MessageId m); @Override Collection<MessageId> getMessagesToAck(Connection txn, ContactId c,
			int maxMessages); @Override Collection<MessageId> getMessagesToOffer(Connection txn,
			ContactId c, int maxMessages); @Override Collection<MessageId> getMessagesToRequest(Connection txn,
			ContactId c, int maxMessages); @Override Collection<MessageId> getMessagesToSend(Connection txn, ContactId c,
			int maxLength); @Override Collection<MessageId> getMessagesToValidate(Connection txn); @Override Collection<MessageId> getPendingMessages(Connection txn); @Override Collection<MessageId> getMessagesToShare(Connection txn); @Override long getNextSendTime(Connection txn, ContactId c); @Override @Nullable byte[] getRawMessage(Connection txn, MessageId m); @Override Collection<MessageId> getRequestedMessagesToSend(Connection txn,
			ContactId c, int maxLength); @Override Settings getSettings(Connection txn, String namespace); @Override Collection<KeySet> getTransportKeys(Connection txn, TransportId t); @Override void incrementStreamCounter(Connection txn, TransportId t,
			KeySetId k); @Override void lowerAckFlag(Connection txn, ContactId c,
			Collection<MessageId> acked); @Override void lowerRequestedFlag(Connection txn, ContactId c,
			Collection<MessageId> requested); @Override void mergeGroupMetadata(Connection txn, GroupId g, Metadata meta); @Override void mergeMessageMetadata(Connection txn, MessageId m,
			Metadata meta); @Override void mergeSettings(Connection txn, Settings s, String namespace); @Override void raiseAckFlag(Connection txn, ContactId c, MessageId m); @Override void raiseRequestedFlag(Connection txn, ContactId c, MessageId m); @Override void raiseSeenFlag(Connection txn, ContactId c, MessageId m); @Override void removeContact(Connection txn, ContactId c); @Override void removeGroup(Connection txn, GroupId g); @Override void removeGroupVisibility(Connection txn, ContactId c, GroupId g); @Override void removeLocalAuthor(Connection txn, AuthorId a); @Override void removeMessage(Connection txn, MessageId m); @Override void removeOfferedMessages(Connection txn, ContactId c,
			Collection<MessageId> requested); @Override void removeTransport(Connection txn, TransportId t); @Override void removeTransportKeys(Connection txn, TransportId t, KeySetId k); @Override void resetExpiryTime(Connection txn, ContactId c, MessageId m); @Override void setContactVerified(Connection txn, ContactId c); @Override void setContactActive(Connection txn, ContactId c, boolean active); @Override void setGroupVisibility(Connection txn, ContactId c, GroupId g,
			boolean shared); @Override void setMessageShared(Connection txn, MessageId m); @Override void setMessageState(Connection txn, MessageId m, State state); @Override void setReorderingWindow(Connection txn, KeySetId k, TransportId t,
			long rotationPeriod, long base, byte[] bitmap); @Override void setTransportKeysActive(Connection txn, TransportId t,
			KeySetId k); @Override void updateExpiryTime(Connection txn, ContactId c, MessageId m,
			int maxLatency); @Override void updateTransportKeys(Connection txn, KeySet ks);  }