4343abstract class DocumentManagerImpl <R extends AbstractReadHandle , W extends AbstractWriteHandle >
4444 extends AbstractLoggingManager implements DocumentManager <R , W >,
4545 TemporalDocumentManager <R , W > {
46+
4647 static final private long DEFAULT_PAGE_LENGTH = 50 ;
4748
4849 static final private Logger logger = LoggerFactory
4950 .getLogger (DocumentManagerImpl .class );
5051
51- private boolean isProcessedMetadataModified = false ;
52- final private Set <Metadata > processedMetadata = new HashSet <Metadata >() {
53- @ Override
54- public boolean add (Metadata e ) {
55- isProcessedMetadataModified = true ;
56- return super .add (e );
57- }
52+ private boolean isMetadataCategoriesNotJustAll () {
53+ return metadataCategories == null ||
54+ metadataCategories .size () != 1 ||
55+ !Metadata .ALL .equals (metadataCategories .iterator ().next ());
56+ }
5857
59- @ Override
60- public boolean addAll (Collection <? extends Metadata > c ) {
61- isProcessedMetadataModified = true ;
62- return super .addAll (c );
63- }
64- };
65- {
66- processedMetadata .add (Metadata .ALL );
67- // we need to know if the user modifies after us
68- isProcessedMetadataModified = false ;
69- }
58+ final private Set <Metadata > metadataCategories = new HashSet <>();
59+
60+ {
61+ // Initialize the default metadata to retrieve on a read.
62+ metadataCategories .add (Metadata .ALL );
63+ }
7064
7165 private RESTServices services ;
7266 private Format contentFormat ;
@@ -113,24 +107,25 @@ public void setContentFormat(Format format) {
113107 @ Override
114108 public void setMetadataCategories (Set <Metadata > categories ) {
115109 clearMetadataCategories ();
116- processedMetadata .addAll (categories );
110+ metadataCategories .addAll (categories );
117111 }
118112
119113 @ Override
120114 public void setMetadataCategories (Metadata ... categories ) {
121115 clearMetadataCategories ();
122- for (Metadata category : categories )
123- processedMetadata .add (category );
116+ for (Metadata category : categories ) {
117+ metadataCategories .add (category );
118+ }
124119 }
125120
126121 @ Override
127122 public Set <Metadata > getMetadataCategories () {
128- return processedMetadata ;
123+ return metadataCategories ;
129124 }
130125
131126 @ Override
132127 public void clearMetadataCategories () {
133- processedMetadata .clear ();
128+ metadataCategories .clear ();
134129 }
135130
136131 @ Override
@@ -374,7 +369,7 @@ public <T extends R> T read(DocumentDescriptor desc,
374369 requestLogger ,
375370 desc ,
376371 transaction ,
377- (metadataHandle != null ) ? processedMetadata : null ,
372+ (metadataHandle != null ) ? metadataCategories : null ,
378373 mergeTransformParameters ((transform != null ) ? transform
379374 : getReadTransform (), extraParams ), metadataHandle , contentHandle );
380375
@@ -446,9 +441,8 @@ public DocumentPage read(long serverTimestamp, ServerTransform transform, Transa
446441 requestLogger ,
447442 serverTimestamp ,
448443 transaction ,
449- // the default for bulk is no metadata, which differs from the normal
450- // default of ALL
451- (isProcessedMetadataModified || !withContent ) ? processedMetadata : null ,
444+ // the default for bulk is no metadata, which differs from the normal default of ALL
445+ (isMetadataCategoriesNotJustAll () || !withContent ) ? metadataCategories : null ,
452446 nonDocumentFormat ,
453447 mergeTransformParameters ((transform != null ) ? transform : getReadTransform (), extraParams ),
454448 withContent ,
@@ -542,10 +536,8 @@ private DocumentPage search(SearchQueryDefinition querydef, long start,
542536 }
543537 }
544538
545- // the default for bulk is no metadata, which differs from the normal
546- // default of ALL
547- Set <Metadata > metadata = isProcessedMetadataModified ? processedMetadata
548- : null ;
539+ // the default for bulk is no metadata, which differs from the normal default of ALL
540+ Set <Metadata > metadata = isMetadataCategoriesNotJustAll () ? metadataCategories : null ;
549541 return services .getBulkDocuments (requestLogger , serverTimestamp , querydef , start ,
550542 getPageLength (), transaction , searchHandle , searchView , metadata ,
551543 nonDocumentFormat , getReadTransform (), null , forestName );
@@ -943,7 +935,7 @@ protected TemporalDescriptor write(DocumentDescriptor desc, String temporalDocum
943935 requestLogger ,
944936 desc ,
945937 transaction ,
946- (metadataHandle != null ) ? processedMetadata : null ,
938+ (metadataHandle != null ) ? metadataCategories : null ,
947939 mergeTransformParameters ((transform != null ) ? transform
948940 : getWriteTransform (), extraParams ), metadataHandle , contentHandle );
949941 }
@@ -1266,7 +1258,7 @@ protected DocumentDescriptorImpl create(DocumentUriTemplate template,
12661258 requestLogger ,
12671259 template ,
12681260 transaction ,
1269- (metadataHandle != null ) ? processedMetadata : null ,
1261+ (metadataHandle != null ) ? metadataCategories : null ,
12701262 mergeTransformParameters ((transform != null ) ? transform
12711263 : getWriteTransform (), extraParams ), metadataHandle , contentHandle );
12721264 }
@@ -1326,7 +1318,7 @@ public void patch(DocumentDescriptor desc, DocumentPatchHandle patch,
13261318 DocumentPatchHandleImpl builtPatch = (patch instanceof DocumentPatchHandleImpl ) ? (DocumentPatchHandleImpl ) patch
13271319 : null ;
13281320 services .patchDocument (requestLogger , desc , transaction ,
1329- (builtPatch != null ) ? builtPatch .getMetadata () : processedMetadata ,
1321+ (builtPatch != null ) ? builtPatch .getMetadata () : metadataCategories ,
13301322 (builtPatch != null ) ? builtPatch .isOnContent () : true , patch );
13311323 }
13321324
@@ -1360,7 +1352,7 @@ public void patch(String uri, String temporalDocumentURI, String temporalCollec
13601352 extraParams = addTemporalParams (extraParams , temporalCollection , temporalDocumentURI , null );
13611353 DocumentPatchHandleImpl builtPatch = (patch instanceof DocumentPatchHandleImpl ) ? (DocumentPatchHandleImpl ) patch
13621354 : null ;
1363- services .patchDocument (requestLogger , new DocumentDescriptorImpl (uri , true ), transaction , (builtPatch != null ) ? builtPatch .getMetadata () : processedMetadata ,
1355+ services .patchDocument (requestLogger , new DocumentDescriptorImpl (uri , true ), transaction , (builtPatch != null ) ? builtPatch .getMetadata () : metadataCategories ,
13641356 (builtPatch != null ) ? builtPatch .isOnContent () : true , extraParams , sourceDocumentURI , patch );
13651357 }
13661358
@@ -1416,7 +1408,7 @@ public void writeDefaultMetadata(String uri, Transaction transaction)
14161408 logger .info ("Resetting metadata for {}" , uri );
14171409
14181410 services .deleteDocument (requestLogger ,
1419- new DocumentDescriptorImpl (uri , true ), transaction , processedMetadata ,
1411+ new DocumentDescriptorImpl (uri , true ), transaction , metadataCategories ,
14201412 getWriteParams ());
14211413 }
14221414
@@ -1433,7 +1425,7 @@ public void writeDefaultMetadata(Transaction transaction, String... uris)
14331425 if (uris .length == 0 )
14341426 throw new IllegalArgumentException (
14351427 "Resetting document metadata with empty identifier list" );
1436- services .delete (requestLogger , transaction , processedMetadata , uris );
1428+ services .delete (requestLogger , transaction , metadataCategories , uris );
14371429 }
14381430
14391431 @ Override
0 commit comments