@Test public void testLoad(TestContext context) { UUID fileId = UUID.randomUUID(); Async async = context.async(); FileMetadata metadata = new FileMetadata(fileId, "name", MimeType.valueOf("text/plain"), 6, Instant.now()); registry.store(metadata).flatMap(v -> { return registry.load(fileId); }).subscribe(loaded -> { context.assertEquals(metadata, loaded); async.complete(); }, context::fail); }
@Override public Single<FileMetadata> load(UUID fileId) { return postgreSQLClient.getConnectionObservable() .flatMap(con -> { return con.queryWithParamsObservable("SELECT name, mime_type, content_length, generated FROM file_metadata WHERE id = ?", new JsonArray().add(fileId.toString())) .doAfterTerminate(con::close); }).toSingle().map(rs -> { List<JsonArray> result = rs.getResults(); if (result.isEmpty()) { throw new BrownieFileNotFoundException(fileId); } else { JsonArray jsonObject = result.get(0); Instant generated = Instant.parse(jsonObject.getString(3) + "Z"); return new FileMetadata(fileId, jsonObject.getString(0), MimeType.valueOf(jsonObject.getString(1)), jsonObject.getLong(2), generated); } }); }
FileMetadataRegistryOnPostgres implements FileMetadataRegistry { @Override public Single<FileMetadata> load(UUID fileId) { return postgreSQLClient.getConnectionObservable() .flatMap(con -> { return con.queryWithParamsObservable("SELECT name, mime_type, content_length, generated FROM file_metadata WHERE id = ?", new JsonArray().add(fileId.toString())) .doAfterTerminate(con::close); }).toSingle().map(rs -> { List<JsonArray> result = rs.getResults(); if (result.isEmpty()) { throw new BrownieFileNotFoundException(fileId); } else { JsonArray jsonObject = result.get(0); Instant generated = Instant.parse(jsonObject.getString(3) + "Z"); return new FileMetadata(fileId, jsonObject.getString(0), MimeType.valueOf(jsonObject.getString(1)), jsonObject.getLong(2), generated); } }); } }
FileMetadataRegistryOnPostgres implements FileMetadataRegistry { @Override public Single<FileMetadata> load(UUID fileId) { return postgreSQLClient.getConnectionObservable() .flatMap(con -> { return con.queryWithParamsObservable("SELECT name, mime_type, content_length, generated FROM file_metadata WHERE id = ?", new JsonArray().add(fileId.toString())) .doAfterTerminate(con::close); }).toSingle().map(rs -> { List<JsonArray> result = rs.getResults(); if (result.isEmpty()) { throw new BrownieFileNotFoundException(fileId); } else { JsonArray jsonObject = result.get(0); Instant generated = Instant.parse(jsonObject.getString(3) + "Z"); return new FileMetadata(fileId, jsonObject.getString(0), MimeType.valueOf(jsonObject.getString(1)), jsonObject.getLong(2), generated); } }); }  }
FileMetadataRegistryOnPostgres implements FileMetadataRegistry { @Override public Single<FileMetadata> load(UUID fileId) { return postgreSQLClient.getConnectionObservable() .flatMap(con -> { return con.queryWithParamsObservable("SELECT name, mime_type, content_length, generated FROM file_metadata WHERE id = ?", new JsonArray().add(fileId.toString())) .doAfterTerminate(con::close); }).toSingle().map(rs -> { List<JsonArray> result = rs.getResults(); if (result.isEmpty()) { throw new BrownieFileNotFoundException(fileId); } else { JsonArray jsonObject = result.get(0); Instant generated = Instant.parse(jsonObject.getString(3) + "Z"); return new FileMetadata(fileId, jsonObject.getString(0), MimeType.valueOf(jsonObject.getString(1)), jsonObject.getLong(2), generated); } }); }  @Override Observable<FileMetadata> iterate(); @Override Single<FileMetadata> store(FileMetadata metadata); @Override Single<FileMetadata> update(FileMetadata metadata); @Override Single<FileMetadata> load(UUID fileId); @Override Single<UUID> delete(UUID fileId); }
FileMetadataRegistryOnPostgres implements FileMetadataRegistry { @Override public Single<FileMetadata> load(UUID fileId) { return postgreSQLClient.getConnectionObservable() .flatMap(con -> { return con.queryWithParamsObservable("SELECT name, mime_type, content_length, generated FROM file_metadata WHERE id = ?", new JsonArray().add(fileId.toString())) .doAfterTerminate(con::close); }).toSingle().map(rs -> { List<JsonArray> result = rs.getResults(); if (result.isEmpty()) { throw new BrownieFileNotFoundException(fileId); } else { JsonArray jsonObject = result.get(0); Instant generated = Instant.parse(jsonObject.getString(3) + "Z"); return new FileMetadata(fileId, jsonObject.getString(0), MimeType.valueOf(jsonObject.getString(1)), jsonObject.getLong(2), generated); } }); }  @Override Observable<FileMetadata> iterate(); @Override Single<FileMetadata> store(FileMetadata metadata); @Override Single<FileMetadata> update(FileMetadata metadata); @Override Single<FileMetadata> load(UUID fileId); @Override Single<UUID> delete(UUID fileId);  }