@Test public void testStore(TestContext context) { ThumbnailMetadataRegistry registry = new ThumbnailMetadataRegistryOnPostgres(client); UUID id = UUID.randomUUID(); UUID videoId = UUID.randomUUID(); ThumbnailMetadata metadata = new ThumbnailMetadata(id, videoId, MimeType.valueOf("image/jpg"), 100, 320, 240, 0); Async async = context.async(); registry.store(metadata).subscribe(v -> async.complete(), context::fail); }
@Override public Single<ThumbnailMetadata> store(ThumbnailMetadata metadata) { return asyncSQLClient.getConnectionObservable() .flatMap(con -> { return con.updateWithParamsObservable(SQL_TO_INSERT, metadata.toJsonArray()) .doAfterTerminate(con::close); }) .toSingle() .map(ur -> { if (ur.getUpdated() != 1) { throw new IllegalArgumentException("Failed to store given thumbnail metadata: " + metadata); } return metadata; }); }
ThumbnailMetadataRegistryOnPostgres implements ThumbnailMetadataRegistry { @Override public Single<ThumbnailMetadata> store(ThumbnailMetadata metadata) { return asyncSQLClient.getConnectionObservable() .flatMap(con -> { return con.updateWithParamsObservable(SQL_TO_INSERT, metadata.toJsonArray()) .doAfterTerminate(con::close); }) .toSingle() .map(ur -> { if (ur.getUpdated() != 1) { throw new IllegalArgumentException("Failed to store given thumbnail metadata: " + metadata); } return metadata; }); } }
ThumbnailMetadataRegistryOnPostgres implements ThumbnailMetadataRegistry { @Override public Single<ThumbnailMetadata> store(ThumbnailMetadata metadata) { return asyncSQLClient.getConnectionObservable() .flatMap(con -> { return con.updateWithParamsObservable(SQL_TO_INSERT, metadata.toJsonArray()) .doAfterTerminate(con::close); }) .toSingle() .map(ur -> { if (ur.getUpdated() != 1) { throw new IllegalArgumentException("Failed to store given thumbnail metadata: " + metadata); } return metadata; }); }  }
ThumbnailMetadataRegistryOnPostgres implements ThumbnailMetadataRegistry { @Override public Single<ThumbnailMetadata> store(ThumbnailMetadata metadata) { return asyncSQLClient.getConnectionObservable() .flatMap(con -> { return con.updateWithParamsObservable(SQL_TO_INSERT, metadata.toJsonArray()) .doAfterTerminate(con::close); }) .toSingle() .map(ur -> { if (ur.getUpdated() != 1) { throw new IllegalArgumentException("Failed to store given thumbnail metadata: " + metadata); } return metadata; }); }  @Override Single<ThumbnailMetadata> store(ThumbnailMetadata metadata); @Override Observable<ThumbnailMetadata> search(UUID videoId); }
ThumbnailMetadataRegistryOnPostgres implements ThumbnailMetadataRegistry { @Override public Single<ThumbnailMetadata> store(ThumbnailMetadata metadata) { return asyncSQLClient.getConnectionObservable() .flatMap(con -> { return con.updateWithParamsObservable(SQL_TO_INSERT, metadata.toJsonArray()) .doAfterTerminate(con::close); }) .toSingle() .map(ur -> { if (ur.getUpdated() != 1) { throw new IllegalArgumentException("Failed to store given thumbnail metadata: " + metadata); } return metadata; }); }  @Override Single<ThumbnailMetadata> store(ThumbnailMetadata metadata); @Override Observable<ThumbnailMetadata> search(UUID videoId);  }