JdbcInventory extends JdbcHelper implements Inventory { @Override public List<ObjectMessage> getObjects(long stream, long version, ObjectType... types) { StringBuilder query = new StringBuilder("SELECT data, version FROM Inventory WHERE 1=1"); if (stream > 0) { query.append(" AND stream = ").append(stream); } if (version > 0) { query.append(" AND version = ").append(version); } if (types.length > 0) { query.append(" AND type IN (").append(join(types)).append(')'); } try ( Connection connection = config.getConnection(); Statement stmt = connection.createStatement(); ResultSet rs = stmt.executeQuery(query.toString()) ) { List<ObjectMessage> result = new LinkedList<>(); while (rs.next()) { Blob data = rs.getBlob("data"); result.add(Factory.getObjectMessage(rs.getInt("version"), data.getBinaryStream(), (int) data.length())); } return result; } catch (Exception e) { LOG.error(e.getMessage(), e); throw new ApplicationException(e); } } JdbcInventory(JdbcConfig config); @Override List<InventoryVector> getInventory(long... streams); @Override List<InventoryVector> getMissing(List<InventoryVector> offer, long... streams); @Override ObjectMessage getObject(InventoryVector vector); @Override List<ObjectMessage> getObjects(long stream, long version, ObjectType... types); @Override void storeObject(ObjectMessage object); @Override boolean contains(ObjectMessage object); @Override void cleanup();  }
@Test public void testGetObjects() throws Exception { List<ObjectMessage> objects = inventory.getObjects(1, 4); assertEquals(2, objects.size()); objects = inventory.getObjects(1, 4, GET_PUBKEY); assertEquals(2, objects.size()); objects = inventory.getObjects(1, 4, MSG); assertEquals(0, objects.size()); }