11/*
2- * Copyright (c) 2010-2025 Progress Software Corporation and/or its subsidiaries or affiliates. All Rights Reserved.
2+ * Copyright (c) 2010-2026 Progress Software Corporation and/or its subsidiaries or affiliates. All Rights Reserved.
33 */
44package com .marklogic .client .impl ;
55
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 .size () != 1 ||
54+ !Metadata .ALL .equals (metadataCategories .iterator ().next ());
55+ }
5856
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- }
57+ final private Set <Metadata > metadataCategories = new HashSet <>();
58+
59+ {
60+ // Initialize the default metadata to retrieve on a read.
61+ metadataCategories .add (Metadata .ALL );
62+ }
7063
7164 private RESTServices services ;
7265 private Format contentFormat ;
@@ -113,24 +106,25 @@ public void setContentFormat(Format format) {
113106 @ Override
114107 public void setMetadataCategories (Set <Metadata > categories ) {
115108 clearMetadataCategories ();
116- processedMetadata .addAll (categories );
109+ metadataCategories .addAll (categories );
117110 }
118111
119112 @ Override
120113 public void setMetadataCategories (Metadata ... categories ) {
121114 clearMetadataCategories ();
122- for (Metadata category : categories )
123- processedMetadata .add (category );
115+ for (Metadata category : categories ) {
116+ metadataCategories .add (category );
117+ }
124118 }
125119
126120 @ Override
127121 public Set <Metadata > getMetadataCategories () {
128- return processedMetadata ;
122+ return metadataCategories ;
129123 }
130124
131125 @ Override
132126 public void clearMetadataCategories () {
133- processedMetadata .clear ();
127+ metadataCategories .clear ();
134128 }
135129
136130 @ Override
@@ -374,7 +368,7 @@ public <T extends R> T read(DocumentDescriptor desc,
374368 requestLogger ,
375369 desc ,
376370 transaction ,
377- (metadataHandle != null ) ? processedMetadata : null ,
371+ (metadataHandle != null ) ? metadataCategories : null ,
378372 mergeTransformParameters ((transform != null ) ? transform
379373 : getReadTransform (), extraParams ), metadataHandle , contentHandle );
380374
@@ -446,9 +440,8 @@ public DocumentPage read(long serverTimestamp, ServerTransform transform, Transa
446440 requestLogger ,
447441 serverTimestamp ,
448442 transaction ,
449- // the default for bulk is no metadata, which differs from the normal
450- // default of ALL
451- (isProcessedMetadataModified || !withContent ) ? processedMetadata : null ,
443+ // the default for bulk is no metadata, which differs from the normal default of ALL
444+ (isMetadataCategoriesNotJustAll () || !withContent ) ? metadataCategories : null ,
452445 nonDocumentFormat ,
453446 mergeTransformParameters ((transform != null ) ? transform : getReadTransform (), extraParams ),
454447 withContent ,
@@ -542,10 +535,8 @@ private DocumentPage search(SearchQueryDefinition querydef, long start,
542535 }
543536 }
544537
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 ;
538+ // the default for bulk is no metadata, which differs from the normal default of ALL
539+ Set <Metadata > metadata = isMetadataCategoriesNotJustAll () ? metadataCategories : null ;
549540 return services .getBulkDocuments (requestLogger , serverTimestamp , querydef , start ,
550541 getPageLength (), transaction , searchHandle , searchView , metadata ,
551542 nonDocumentFormat , getReadTransform (), null , forestName );
@@ -943,7 +934,7 @@ protected TemporalDescriptor write(DocumentDescriptor desc, String temporalDocum
943934 requestLogger ,
944935 desc ,
945936 transaction ,
946- (metadataHandle != null ) ? processedMetadata : null ,
937+ (metadataHandle != null ) ? metadataCategories : null ,
947938 mergeTransformParameters ((transform != null ) ? transform
948939 : getWriteTransform (), extraParams ), metadataHandle , contentHandle );
949940 }
@@ -1266,7 +1257,7 @@ protected DocumentDescriptorImpl create(DocumentUriTemplate template,
12661257 requestLogger ,
12671258 template ,
12681259 transaction ,
1269- (metadataHandle != null ) ? processedMetadata : null ,
1260+ (metadataHandle != null ) ? metadataCategories : null ,
12701261 mergeTransformParameters ((transform != null ) ? transform
12711262 : getWriteTransform (), extraParams ), metadataHandle , contentHandle );
12721263 }
@@ -1326,7 +1317,7 @@ public void patch(DocumentDescriptor desc, DocumentPatchHandle patch,
13261317 DocumentPatchHandleImpl builtPatch = (patch instanceof DocumentPatchHandleImpl ) ? (DocumentPatchHandleImpl ) patch
13271318 : null ;
13281319 services .patchDocument (requestLogger , desc , transaction ,
1329- (builtPatch != null ) ? builtPatch .getMetadata () : processedMetadata ,
1320+ (builtPatch != null ) ? builtPatch .getMetadata () : metadataCategories ,
13301321 (builtPatch != null ) ? builtPatch .isOnContent () : true , patch );
13311322 }
13321323
@@ -1360,7 +1351,7 @@ public void patch(String uri, String temporalDocumentURI, String temporalCollec
13601351 extraParams = addTemporalParams (extraParams , temporalCollection , temporalDocumentURI , null );
13611352 DocumentPatchHandleImpl builtPatch = (patch instanceof DocumentPatchHandleImpl ) ? (DocumentPatchHandleImpl ) patch
13621353 : null ;
1363- services .patchDocument (requestLogger , new DocumentDescriptorImpl (uri , true ), transaction , (builtPatch != null ) ? builtPatch .getMetadata () : processedMetadata ,
1354+ services .patchDocument (requestLogger , new DocumentDescriptorImpl (uri , true ), transaction , (builtPatch != null ) ? builtPatch .getMetadata () : metadataCategories ,
13641355 (builtPatch != null ) ? builtPatch .isOnContent () : true , extraParams , sourceDocumentURI , patch );
13651356 }
13661357
@@ -1416,7 +1407,7 @@ public void writeDefaultMetadata(String uri, Transaction transaction)
14161407 logger .info ("Resetting metadata for {}" , uri );
14171408
14181409 services .deleteDocument (requestLogger ,
1419- new DocumentDescriptorImpl (uri , true ), transaction , processedMetadata ,
1410+ new DocumentDescriptorImpl (uri , true ), transaction , metadataCategories ,
14201411 getWriteParams ());
14211412 }
14221413
@@ -1433,7 +1424,7 @@ public void writeDefaultMetadata(Transaction transaction, String... uris)
14331424 if (uris .length == 0 )
14341425 throw new IllegalArgumentException (
14351426 "Resetting document metadata with empty identifier list" );
1436- services .delete (requestLogger , transaction , processedMetadata , uris );
1427+ services .delete (requestLogger , transaction , metadataCategories , uris );
14371428 }
14381429
14391430 @ Override
0 commit comments