11package de .bwaldvogel .mongo .backend ;
22
3- import static de .bwaldvogel .mongo .backend .Constants .ID_FIELD ;
4-
53import java .util .ArrayList ;
64import java .util .Collection ;
75import java .util .Collections ;
3331import de .bwaldvogel .mongo .exception .MongoServerException ;
3432import de .bwaldvogel .mongo .oplog .Oplog ;
3533
34+ import static de .bwaldvogel .mongo .backend .Constants .ID_FIELD ;
35+
3636public abstract class AbstractMongoCollection <P > implements MongoCollection <P > {
3737
3838 private static final Logger log = LoggerFactory .getLogger (AbstractMongoCollection .class );
@@ -217,7 +217,7 @@ public void addIndex(Index<P> index) {
217217 indexes .add (index );
218218 }
219219
220- private Index <P > findByName (String indexName ) {
220+ protected Index <P > findByName (String indexName ) {
221221 return indexes .stream ()
222222 .filter (index -> index .getName ().equals (indexName ))
223223 .findFirst ()
@@ -244,7 +244,7 @@ public void dropIndex(String indexName) {
244244 indexes .remove (indexToDrop );
245245 }
246246
247- private void modifyField (Document document , String modifier , Document update , ArrayFilters arrayFilters ,
247+ protected void modifyField (Document document , String modifier , Document update , ArrayFilters arrayFilters ,
248248 Integer matchPos , boolean isUpsert ) {
249249 Document change = (Document ) update .get (modifier );
250250 UpdateOperator updateOperator = getUpdateOperator (modifier , change );
@@ -256,7 +256,7 @@ protected String getIdField() {
256256 return options .getIdField ();
257257 }
258258
259- private UpdateOperator getUpdateOperator (String modifier , Document change ) {
259+ protected UpdateOperator getUpdateOperator (String modifier , Document change ) {
260260 final UpdateOperator op ;
261261 try {
262262 op = UpdateOperator .fromValue (modifier );
@@ -267,7 +267,7 @@ private UpdateOperator getUpdateOperator(String modifier, Document change) {
267267 return op ;
268268 }
269269
270- private void applyUpdate (Document oldDocument , Document newDocument ) {
270+ protected void applyUpdate (Document oldDocument , Document newDocument ) {
271271 if (newDocument .equals (oldDocument )) {
272272 return ;
273273 }
@@ -298,7 +298,7 @@ Object deriveDocumentId(Document selector) {
298298 return new ObjectId ();
299299 }
300300
301- private Object deriveIdFromExpression (Object value ) {
301+ protected Object deriveIdFromExpression (Object value ) {
302302 Document expression = (Document ) value ;
303303 for (String key : expression .keySet ()) {
304304 Object expressionValue = expression .get (key );
@@ -313,7 +313,7 @@ private Object deriveIdFromExpression(Object value) {
313313 return new ObjectId ();
314314 }
315315
316- private Document calculateUpdateDocument (Document oldDocument , Document update , ArrayFilters arrayFilters ,
316+ protected Document calculateUpdateDocument (Document oldDocument , Document update , ArrayFilters arrayFilters ,
317317 Integer matchPos , boolean isUpsert ) {
318318
319319 int numStartsWithDollar = 0 ;
@@ -469,7 +469,7 @@ public List<Document> insertDocuments(List<Document> documents, boolean isOrdere
469469 return writeErrors ;
470470 }
471471
472- private static Document toErrorDocument (MongoServerError e , int index ) {
472+ public static Document toErrorDocument (MongoServerError e , int index ) {
473473 Document error = new Document ();
474474 error .put ("index" , index );
475475 error .put ("errmsg" , e .getMessageWithoutErrorCode ());
@@ -555,7 +555,7 @@ public Document updateDocuments(Document selector, Document updateQuery, ArrayFi
555555 return result ;
556556 }
557557
558- private Document updateDocument (Document document , Document updateQuery ,
558+ protected Document updateDocument (Document document , Document updateQuery ,
559559 ArrayFilters arrayFilters , Integer matchPos ) {
560560 Document oldDocument = document .cloneDeeply ();
561561
@@ -596,7 +596,7 @@ private Document updateDocument(Document document, Document updateQuery,
596596 return oldDocument ;
597597 }
598598
599- private P getSinglePosition (Document document ) {
599+ protected P getSinglePosition (Document document ) {
600600 if (indexes .isEmpty ()) {
601601 return findDocumentPosition (document );
602602 }
@@ -609,7 +609,7 @@ private P getSinglePosition(Document document) {
609609
610610 protected abstract void handleUpdate (P position , Document oldDocument , Document newDocument );
611611
612- private Document handleUpsert (Document updateQuery , Document selector , ArrayFilters arrayFilters ) {
612+ protected Document handleUpsert (Document updateQuery , Document selector , ArrayFilters arrayFilters ) {
613613 Document document = convertSelectorToDocument (selector );
614614
615615 Document newDocument = calculateUpdateDocument (document , updateQuery , arrayFilters , null , true );
@@ -769,7 +769,7 @@ protected P findDocumentPosition(Document document) {
769769
770770 protected abstract Stream <DocumentWithPosition <P >> streamAllDocumentsWithPosition ();
771771
772- private boolean isSystemCollection () {
772+ protected boolean isSystemCollection () {
773773 return AbstractMongoDatabase .isSystemCollection (getCollectionName ());
774774 }
775775
0 commit comments