From 991f855b563f59a0214d1b35950a54d04ad13633 Mon Sep 17 00:00:00 2001 From: Aaron Coburn Date: Mon, 6 Jul 2020 14:20:16 -0400 Subject: [PATCH] Adjust binary table columns --- .../src/main/resources/db/migration/V0.6__Trellis.sql | 4 ++-- .../main/resources/org/trellisldp/jdbc/migrations.yml | 7 ++++--- .../java/org/trellisldp/http/impl/DeleteHandler.java | 11 ++++++++--- 3 files changed, 14 insertions(+), 8 deletions(-) diff --git a/components/jdbc/src/main/resources/db/migration/V0.6__Trellis.sql b/components/jdbc/src/main/resources/db/migration/V0.6__Trellis.sql index 722bdfdde..3ace0468c 100644 --- a/components/jdbc/src/main/resources/db/migration/V0.6__Trellis.sql +++ b/components/jdbc/src/main/resources/db/migration/V0.6__Trellis.sql @@ -3,12 +3,12 @@ -- CREATE TABLE public.binary ( - resource_id bigint NOT NULL, + id character varying(1024) PRIMARY KEY, data bytea NOT NULL ); COMMENT ON TABLE public.binary IS 'This table can be used to store binary data for a resource.'; -COMMENT ON COLUMN public.binary.resource_id IS 'This value points to the relevant row in the resource table.'; +COMMENT ON COLUMN public.binary.id IS 'This value is the unique identifier for the binary.'; COMMENT ON COLUMN public.binary.data IS 'This holds the binary data itself, limited to 1GB in size'; diff --git a/components/jdbc/src/main/resources/org/trellisldp/jdbc/migrations.yml b/components/jdbc/src/main/resources/org/trellisldp/jdbc/migrations.yml index 431c62ba4..75ac3f938 100644 --- a/components/jdbc/src/main/resources/org/trellisldp/jdbc/migrations.yml +++ b/components/jdbc/src/main/resources/org/trellisldp/jdbc/migrations.yml @@ -535,10 +535,11 @@ databaseChangeLog: remarks: This table can be used to store binary data for a resource. columns: - column: - name: resource_id - type: BIGINT - remarks: This value points to the relevant row in the resource table. + name: id + type: VARCHAR(${id.length}) + remarks: This value is the unique identifier for the binary. constraints: + primaryKey: true nullable: false - column: name: data diff --git a/core/http/src/main/java/org/trellisldp/http/impl/DeleteHandler.java b/core/http/src/main/java/org/trellisldp/http/impl/DeleteHandler.java index 0328fd43a..bdcd45800 100644 --- a/core/http/src/main/java/org/trellisldp/http/impl/DeleteHandler.java +++ b/core/http/src/main/java/org/trellisldp/http/impl/DeleteHandler.java @@ -43,6 +43,7 @@ import org.apache.commons.rdf.api.IRI; import org.apache.commons.rdf.api.Quad; import org.slf4j.Logger; +import org.trellisldp.api.BinaryMetadata; import org.trellisldp.api.Metadata; import org.trellisldp.api.Resource; import org.trellisldp.http.core.ServiceBundler; @@ -166,16 +167,20 @@ private CompletionStage handleResourceDeletion(final Dataset immutable) { .map(skolemizeQuads(getServices().getResourceService(), getBaseUrl())) .forEachOrdered(immutable::add); + + final CompletionStage binaryPromise = getBinaryPurgePromise(); + // delete the resource return allOf( - getBinaryPurgePromise().toCompletableFuture(), + binaryPromise.toCompletableFuture(), getServices().getResourceService().delete(Metadata.builder(getResource()).build()).toCompletableFuture(), getServices().getResourceService().add(getResource().getIdentifier(), immutable).toCompletableFuture()); } private CompletionStage getBinaryPurgePromise() { - if (purgeBinaries && LDP.NonRDFSource.equals(getResource().getInteractionModel())) { - return getServices().getBinaryService().purgeContent(getResource().getIdentifier()); + if (purgeBinaries) { + return getResource().getBinaryMetadata().map(BinaryMetadata::getIdentifier) + .map(getServices().getBinaryService()::purgeContent).orElseGet(() -> completedFuture(null)); } return completedFuture(null); }