• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

evolvedbinary / elemental / 982

29 Apr 2025 08:34PM UTC coverage: 56.409% (+0.007%) from 56.402%
982

push

circleci

adamretter
[feature] Improve README.md badges

28451 of 55847 branches covered (50.94%)

Branch coverage included in aggregate %.

77468 of 131924 relevant lines covered (58.72%)

0.59 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

69.7
/exist-core/src/main/java/org/exist/collections/Collection.java
1
/*
2
 * Elemental
3
 * Copyright (C) 2024, Evolved Binary Ltd
4
 *
5
 * admin@evolvedbinary.com
6
 * https://www.evolvedbinary.com | https://www.elemental.xyz
7
 *
8
 * Use of this software is governed by the Business Source License 1.1
9
 * included in the LICENSE file and at www.mariadb.com/bsl11.
10
 *
11
 * Change Date: 2028-04-27
12
 *
13
 * On the date above, in accordance with the Business Source License, use
14
 * of this software will be governed by the Apache License, Version 2.0.
15
 *
16
 * Additional Use Grant: Production use of the Licensed Work for a permitted
17
 * purpose. A Permitted Purpose is any purpose other than a Competing Use.
18
 * A Competing Use means making the Software available to others in a commercial
19
 * product or service that: substitutes for the Software; substitutes for any
20
 * other product or service we offer using the Software that exists as of the
21
 * date we make the Software available; or offers the same or substantially
22
 * similar functionality as the Software.
23
 *
24
 * NOTE: Parts of this file contain code from 'The eXist-db Authors'.
25
 *       The original license header is included below.
26
 *
27
 * =====================================================================
28
 *
29
 * eXist-db Open Source Native XML Database
30
 * Copyright (C) 2001 The eXist-db Authors
31
 *
32
 * info@exist-db.org
33
 * http://www.exist-db.org
34
 *
35
 * This library is free software; you can redistribute it and/or
36
 * modify it under the terms of the GNU Lesser General Public
37
 * License as published by the Free Software Foundation; either
38
 * version 2.1 of the License, or (at your option) any later version.
39
 *
40
 * This library is distributed in the hope that it will be useful,
41
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
42
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
43
 * Lesser General Public License for more details.
44
 *
45
 * You should have received a copy of the GNU Lesser General Public
46
 * License along with this library; if not, write to the Free Software
47
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
48
 */
49
package org.exist.collections;
50

51
import org.exist.EXistException;
52
import org.exist.Resource;
53
import org.exist.collections.triggers.TriggerException;
54
import org.exist.dom.QName;
55
import org.exist.dom.persistent.*;
56
import org.exist.security.*;
57
import org.exist.security.SecurityManager;
58
import org.exist.storage.*;
59
import org.exist.storage.io.VariableByteInput;
60
import org.exist.storage.io.VariableByteOutputStream;
61
import org.exist.storage.lock.*;
62
import org.exist.storage.lock.Lock.LockMode;
63
import org.exist.storage.txn.Txn;
64
import org.exist.util.LockException;
65
import org.exist.util.MimeType;
66
import org.exist.xmldb.XmldbURI;
67
import org.w3c.dom.DocumentType;
68
import org.w3c.dom.Node;
69
import org.xml.sax.InputSource;
70
import org.xml.sax.SAXException;
71
import org.xml.sax.XMLReader;
72

73
import javax.annotation.Nullable;
74
import java.io.IOException;
75
import java.io.InputStream;
76
import java.util.Date;
77
import java.util.Iterator;
78
import java.util.List;
79

80
import static org.exist.storage.lock.Lock.LockMode.READ_LOCK;
81
import static org.exist.storage.lock.Lock.LockMode.WRITE_LOCK;
82

83
/**
84
 * Represents a Collection in the database. A collection maintains a list of
85
 * child Collections and documents, and provides the methods to store/remove resources.
86
 *
87
 * Collections are shared between {@link org.exist.storage.DBBroker} instances. The caller
88
 * is responsible to lock/unlock the collection. Call {@link org.exist.storage.DBBroker#openCollection(org.exist.xmldb.XmldbURI, org.exist.storage.lock.Lock.LockMode)}
89
 * to get a collection with a read or write lock and {@link #close()} to release the lock.
90
 */
91
public interface Collection extends Resource, Comparable<Collection>, AutoCloseable {
92

93
    /**
94
     * The length in bytes of the Collection ID
95
     */
96
    int LENGTH_COLLECTION_ID = 4; //sizeof int
97

98
    /**
99
     * The ID of an unknown Collection
100
     */
101
    int UNKNOWN_COLLECTION_ID = -1;
102

103
    /**
104
     * Get the internal id.
105
     *
106
     * @return The id of the Collection
107
     */
108
    int getId();
109

110
    /**
111
     * Get the URI path of the Collection
112
     *
113
     * @return The URI path of the Collection
114
     */
115
    XmldbURI getURI();
116

117
    /**
118
     * Set the URI path of the Collection.
119
     *
120
     * Simply calls {@link #setPath(XmldbURI, boolean)}
121
     * with updateChildren=false.
122
     *
123
     * @param path The URI path of the Collection
124
     */
125
    void setPath(XmldbURI path);
126

127
    /**
128
     * Set the URI path of the Collection
129
     *
130
     * @param path The URI path of the Collection
131
     * @param updateChildren true if paths of child documents and collections should be updated (if needed), false otherwise
132
     */
133
    void setPath(XmldbURI path, boolean updateChildren);
134

135
    /**
136
     * Get the metadata of the Collection
137
     *
138
     * @return The Collection metadata
139
     *
140
     * @deprecated Will be removed in eXist-db 6.0.0. Instead use the direct methods on this class.
141
     */
142
    @Deprecated
143
    CollectionMetadata getMetadata();
144

145
    /**
146
     * Get the Collection permissions
147
     *
148
     * @return The permissions of this Collection
149
     */
150
    Permission getPermissions();
151

152
    /**
153
     * Get the Collection permissions (without locking)
154
     *
155
     * @return The permissions of this Collection
156
     */
157
    Permission getPermissionsNoLock();
158

159
    /**
160
     * Set the mode of the Collection.
161
     *
162
     * @param broker The database broker.
163
     * @param mode The unix like mode of the Collection permissions
164
     * @throws LockException if dbbroker is locked
165
     * @throws PermissionDeniedException if use does not have required permissions
166
     */
167
    void setPermissions(DBBroker broker, int mode) throws LockException, PermissionDeniedException;
168

169
    /**
170
     * Gets the creation timestamp of this Collection
171
     *
172
     * @return timestamp the creation timestamp in milliseconds
173
     */
174
    long getCreated();
175

176
    /**
177
     * Sets the creation timestamp of this Collection
178
     *
179
     * @param timestamp the creation timestamp in milliseconds
180
     */
181
    @EnsureContainerLocked(mode=WRITE_LOCK) void setCreated(long timestamp);
182

183
    /**
184
     * Get the Collection Configuration of this Collection
185
     *
186
     * @param broker The database broker
187
     * @return CollectionConfiguration of this Collection
188
     */
189
    @Nullable CollectionConfiguration getConfiguration(DBBroker broker);
190

191
    /**
192
     * Get the index configuration for this collection
193
     *
194
     * @param broker The database broker
195
     * @return IndexSpec aka configuration for this collection
196
     */
197
    IndexSpec getIndexConfiguration(DBBroker broker);
198

199
    /**
200
     * Get the index configuration for a node path of this collection
201
     *
202
     * @param broker The database broker
203
     * @param nodePath The node path to get the index configuration for
204
     *
205
     * @return The index configuration
206
     */
207
    GeneralRangeIndexSpec getIndexByPathConfiguration(DBBroker broker, NodePath nodePath);
208

209
    /**
210
     * Get the index configuration for a node name of this collection
211
     *
212
     * @param broker The database broker
213
     * @param nodeName The node name to get the index configuration for
214
     *
215
     * @return The index configuration
216
     */
217
    QNameRangeIndexSpec getIndexByQNameConfiguration(final DBBroker broker, final QName nodeName);
218

219
    /**
220
     * Returns true if this is a temporary collection. By default,
221
     * the temporary collection is in /db/system/temp.
222
     *
223
     * @return true if the collection is temporary, false otherwise
224
     */
225
    boolean isTempCollection();
226

227
    /**
228
     * Returns the estimated amount of memory used by this collection
229
     * and its documents. This information is required by the
230
     * {@link org.exist.collections.CollectionCache} to be able
231
     * to resize the caches.
232
     *
233
     * @return estimated amount of memory in bytes
234
     */
235
    int getMemorySize();
236

237
    /**
238
     * Returns the estimated amount of memory used by this collection
239
     * and its documents. This information is required by the
240
     * {@link org.exist.collections.CollectionCache} to be able
241
     * to resize the caches.
242
     *
243
     * @return estimated amount of memory in bytes
244
     */
245
    int getMemorySizeNoLock();
246

247
    /**
248
     * Get the parent Collection.
249
     *
250
     * @return The parent Collection of this Collection
251
     * or null if this is the root Collection (i.e. /db).
252
     */
253
    XmldbURI getParentURI();
254

255
    /**
256
     * Determines if this Collection has any documents, or child Collections
257
     *
258
     * @param broker The database broker
259
     * @return true if the collection is empty, false otherwise
260
     * @throws PermissionDeniedException if user has not sufficient rights
261
     */
262
    boolean isEmpty(DBBroker broker) throws PermissionDeniedException;
263

264
    /**
265
     * Returns the number of documents in this Collection
266
     *
267
     * @param broker The database broker
268
     * @return The number of documents in the Collection, or -1 if the collection could not be locked
269
     * @throws PermissionDeniedException if user has not sufficient rights
270
     */
271
    int getDocumentCount(DBBroker broker) throws PermissionDeniedException;
272

273
    /**
274
     * Returns the number of documents in this Collection
275
     *
276
     * @param broker The database broker
277
     * @return The number of documents in the Collection
278
     * @throws PermissionDeniedException if user has not sufficient rights
279
     * @deprecated Use {@link #getDocumentCount(DBBroker)}
280
     */
281
    @Deprecated
282
    int getDocumentCountNoLock(DBBroker broker) throws PermissionDeniedException;
283

284
    /**
285
     * Return the number of child Collections within this Collection.
286
     *
287
     * @param broker The database broker
288
     * @throws PermissionDeniedException if user has not sufficient rights
289
     * @return The childCollectionCount value
290
     */
291
    int getChildCollectionCount(DBBroker broker) throws PermissionDeniedException;
292

293
    /**
294
     * Check if the Collection has a child document
295
     *
296
     * @param broker The database broker
297
     * @param name   the name (without path) of the document
298
     * @throws PermissionDeniedException if user has not sufficient rights
299
     * @return true when the collection has the document, false otherwise
300
     */
301
    boolean hasDocument(DBBroker broker, XmldbURI name) throws PermissionDeniedException;
302

303
    /**
304
     * Check if the collection has a child Collection
305
     *
306
     * @param broker The database broker
307
     * @param name   the name of the child Collection (without path)
308
     * @return true if the child Collection exists, false otherwise
309
     * @throws PermissionDeniedException if user has not sufficient rights
310
     * @throws LockException if broker is locked
311
     */
312
    boolean hasChildCollection(DBBroker broker, XmldbURI name) throws PermissionDeniedException, LockException;
313

314
    /**
315
     * Check if the collection has a child Collection
316
     *
317
     * @param broker The database broker
318
     * @param name   the name of the child Collection (without path)
319
     * @return true if the child Collection exists, false otherwise
320
     * @throws PermissionDeniedException if user has not sufficient rights
321
     * @deprecated Use {@link #hasChildCollection(DBBroker, XmldbURI)} instead
322
     */
323
    @Deprecated
324
    boolean hasChildCollectionNoLock(DBBroker broker, XmldbURI name) throws PermissionDeniedException;
325

326
    /**
327
     * Add a new child Collection to this Collection
328
     *
329
     * @param broker The database broker
330
     * @param child  The child Collection to add to this Collection
331
     * @throws PermissionDeniedException if user has not sufficient rights
332
     * @throws LockException if broker is locked
333
     */
334
    void addCollection(DBBroker broker, @EnsureLocked(mode=WRITE_LOCK) Collection child)
335
            throws PermissionDeniedException, LockException;
336

337
    /**
338
     * Get the Document and child Collection
339
     * entries of this Collection
340
     *
341
     * @param broker The database broker
342
     * @return A list of entries in this Collection
343
     * @throws PermissionDeniedException if user has not sufficient rights
344
     * @throws LockException if broker is locked
345
     * @throws IOException in case of I/O errors
346
     */
347
    List<CollectionEntry> getEntries(DBBroker broker)
348
            throws PermissionDeniedException, LockException, IOException;
349

350
    /**
351
     * Get the entry for a child Collection
352
     *
353
     * @param broker The database broker
354
     * @param name   The name of the child Collection
355
     * @return The child Collection entry
356
     * @throws PermissionDeniedException if user has not sufficient rights
357
     * @throws LockException if broker is locked
358
     * @throws IOException in case of I/O errors
359
     */
360
    CollectionEntry getChildCollectionEntry(DBBroker broker, String name)
361
            throws PermissionDeniedException, LockException, IOException;
362

363
    /**
364
     * Get the entry for a resource
365
     *
366
     * @param broker The database broker
367
     * @param name   The name of the resource
368
     * @return The resource entry
369
     * @throws PermissionDeniedException if user has not sufficient rights
370
     * @throws LockException if broker is locked
371
     * @throws IOException in case of I/O errors
372
     */
373
    CollectionEntry getResourceEntry(DBBroker broker, String name)
374
            throws PermissionDeniedException, LockException, IOException;
375

376
    /**
377
     * Add a document to the collection
378
     *
379
     * @param transaction The database transaction
380
     * @param broker      The database broker
381
     * @param doc         The document to add to the Collection
382
     * @throws PermissionDeniedException if user has not sufficient rights
383
     * @throws LockException if broker is locked
384
     */
385
    void addDocument(Txn transaction, DBBroker broker, DocumentImpl doc)
386
            throws PermissionDeniedException, LockException;
387

388
    /**
389
     * Removes the document from the internal list of resources, but
390
     * doesn't delete the document object itself.
391
     *
392
     * @param broker The database broker
393
     * @param doc    The document to unlink from the Collection
394
     * @throws PermissionDeniedException if user has not sufficient rights
395
     * @throws LockException if broker is locked
396
     */
397
    void unlinkDocument(DBBroker broker, @EnsureLocked(mode=WRITE_LOCK) DocumentImpl doc) throws PermissionDeniedException, LockException;
398

399
    /**
400
     * Return an iterator over all child Collections
401
     *
402
     * The list of child Collections is copied first, so modifications
403
     * via the iterator have no effect.
404
     *
405
     * @param broker The database broker
406
     * @return An iterator over the child Collections
407
     * @throws PermissionDeniedException if user has not sufficient rights
408
     * @throws LockException if broker is locked
409
     */
410
    Iterator<XmldbURI> collectionIterator(DBBroker broker) throws PermissionDeniedException, LockException;
411

412
    /**
413
     * Return an iterator over all child Collections.
414
     *
415
     * The list of child Collections is copied first, so modifications
416
     * via the iterator have no effect.
417
     *
418
     * @param broker The database broker
419
     * @return An iterator over the child Collections
420
     * @throws PermissionDeniedException if user has not sufficient rights
421
     * @deprecated The creation of the stable iterator may
422
     * throw an {@link java.lang.IndexOutOfBoundsException},
423
     * use {@link #collectionIterator(DBBroker)} instead
424
     */
425
    @Deprecated
426
    Iterator<XmldbURI> collectionIteratorNoLock(DBBroker broker) throws PermissionDeniedException;
427

428
    /**
429
     * Returns an iterator on the documents in this Collection
430
     *
431
     * @param broker The database broker
432
     * @return A iterator of all the documents in the Collection.
433
     * @throws PermissionDeniedException if user has not sufficient rights
434
     * @throws LockException if broker is locked
435
     */
436
    Iterator<DocumentImpl> iterator(DBBroker broker) throws PermissionDeniedException, LockException;
437

438
    /**
439
     * Returns an iterator on the documents in this Collection
440
     *
441
     * @param broker The database broker
442
     * @return A iterator of all the documents in the Collection.
443
     * @throws PermissionDeniedException if user has not sufficient rights
444
     * @deprecated This is not an atomic operation and
445
     * so there are no guarantees about which docs will be available to
446
     * the iterator. Use {@link #iterator(DBBroker)} instead
447
     */
448
    @Deprecated
449
    Iterator<DocumentImpl> iteratorNoLock(DBBroker broker) throws PermissionDeniedException;
450

451

452
    //TODO(AR) it is unlikely we need to pass the user as a parameter, fix this...
453

454
    /**
455
     * Return the Collections below this Collection
456
     *
457
     * @param broker The database broker
458
     * @param user   The user that is performing the operation
459
     * @return The List of descendant Collections
460
     * @throws PermissionDeniedException if user has not sufficient rights
461
     */
462
    List<Collection> getDescendants(DBBroker broker, Subject user) throws PermissionDeniedException;
463

464
    /**
465
     * Gets all of the documents from the Collection
466
     *
467
     * @param broker    The database broker
468
     * @param docs      A mutable document set which receives the documents
469
     * @param recursive true if we should get all descendants, false just retrieves the children
470
     * @return The mutable document set provided in {@code docs}
471
     * @throws PermissionDeniedException if user has not sufficient rights
472
     * @throws LockException if broker is locked
473
     */
474
    MutableDocumentSet allDocs(DBBroker broker, MutableDocumentSet docs, boolean recursive)
475
            throws PermissionDeniedException, LockException;
476

477
    /**
478
     * Gets all of the documents from the Collection
479
     *
480
     * @param broker    The database broker
481
     * @param docs      A mutable document set which receives the documents
482
     * @param recursive true if we should get all descendants, false just retrieves the children
483
     * @param lockMap   A map that receives the locks we have taken on documents
484
     * @return The mutable document set provided in {@code docs}
485
     * @throws PermissionDeniedException if user has not sufficient rights
486
     * @throws LockException if broker is locked
487
     */
488
    MutableDocumentSet allDocs(DBBroker broker, MutableDocumentSet docs, boolean recursive,
489
                               LockedDocumentMap lockMap) throws PermissionDeniedException, LockException;
490

491
    /**
492
     * Gets all of the documents from the Collection
493
     *
494
     * @param broker    The database broker
495
     * @param docs      A mutable document set which receives the documents
496
     * @param recursive true if we should get all descendants, false just retrieves the children
497
     * @param lockMap   A map that receives the locks we have taken on documents
498
     * @param lockType  The type of lock to acquire on the documents
499
     * @return The mutable document set provided in {@code docs}
500
     * @throws PermissionDeniedException if user has not sufficient rights
501
     * @throws LockException if broker is locked
502
     */
503
    DocumentSet allDocs(DBBroker broker, MutableDocumentSet docs, boolean recursive, LockedDocumentMap lockMap,
504
                        LockMode lockType) throws LockException, PermissionDeniedException;
505

506
    /**
507
     * Gets all of the documents from the Collection
508
     *
509
     * @param broker The database broker
510
     * @param docs   A mutable document set which receives the documents
511
     * @return The mutable document set provided in {@code docs}
512
     * @throws PermissionDeniedException if user has not sufficient rights
513
     * @throws LockException if broker is locked
514
     */
515
    DocumentSet getDocuments(DBBroker broker, MutableDocumentSet docs) throws PermissionDeniedException, LockException;
516

517
    /**
518
     * Gets all of the documents from the Collection (without locking)
519
     *
520
     * @param broker The database broker
521
     * @param docs   A mutable document set which receives the documents
522
     * @return The mutable document set provided in {@code docs}
523
     * @deprecated This is not an atomic operation and
524
     * so there are no guarantees about which docs will be added to
525
     * the document set. Use {@link #getDocuments(DBBroker, MutableDocumentSet)}
526
     * instead
527
     */
528
    @Deprecated
529
    DocumentSet getDocumentsNoLock(DBBroker broker, MutableDocumentSet docs);
530

531
    /**
532
     * Gets all of the documents from the Collection
533
     *
534
     * @param broker   The database broker
535
     * @param docs     A mutable document set which receives the documents
536
     * @param lockMap  A map that receives the locks we have taken on documents
537
     * @param lockType The type of lock to acquire on the documents
538
     * @return The mutable document set provided in {@code docs}
539
     * @throws PermissionDeniedException if user has not sufficient rights
540
     * @throws LockException if broker is locked*
541
     */
542
    DocumentSet getDocuments(DBBroker broker, MutableDocumentSet docs, LockedDocumentMap lockMap, LockMode lockType)
543
            throws LockException, PermissionDeniedException;
544

545
    /**
546
     * Get a child resource as identified by name. This method doesn't put
547
     * a lock on the document nor does it recognize locks held by other threads.
548
     * There's no guarantee that the document still exists when accessing it.
549
     *
550
     * @param broker The database broker
551
     * @param name   The name of the document (without collection path)
552
     * @return the document or null if it doesn't exist
553
     * @throws PermissionDeniedException if user has not sufficient rights
554
     */
555
    @Nullable @EnsureUnlocked DocumentImpl getDocument(DBBroker broker, XmldbURI name) throws PermissionDeniedException;
556

557
    /**
558
     * Retrieve a child resource after putting a read lock on it.
559
     * With this method, access to the received document object is safe.
560
     *
561
     * @param broker The database broker
562
     * @param name   The name of the document (without collection path)
563
     * @return The locked document or null if it doesn't exist
564
     * @throws PermissionDeniedException if user has not sufficient rights
565
     * @throws LockException if broker is locked
566
     *
567
     * @deprecated Use {@link #getDocumentWithLock(org.exist.storage.DBBroker, org.exist.xmldb.XmldbURI, org.exist.storage.lock.Lock.LockMode)}
568
     */
569
    @Deprecated
570
    @Nullable LockedDocument getDocumentWithLock(DBBroker broker, XmldbURI name)
571
            throws LockException, PermissionDeniedException;
572

573
    /**
574
     * Retrieve a child resource after putting a lock on it.
575
     * With this method, access to the received document object is safe.
576
     *
577
     * @param broker   The database broker
578
     * @param name     The name of the document (without collection path)
579
     * @param lockMode The mode of the lock to acquire
580
     * @return The locked document or null if it doesn't exist
581
     * @throws PermissionDeniedException if user has not sufficient rights
582
     * @throws LockException if broker is locked*
583
     */
584
    @Nullable LockedDocument getDocumentWithLock(DBBroker broker, XmldbURI name, LockMode lockMode)
585
            throws LockException, PermissionDeniedException;
586

587
    /**
588
     * Get a child resource as identified by path. This method doesn't put
589
     * a lock on the document nor does it recognize locks held by other threads.
590
     * There's no guarantee that the document still exists when accessing it.
591
     *
592
     * @param broker  The database broker
593
     * @param rawPath The path of the document
594
     * @return the document or null if it doesn't exist
595
     * @throws PermissionDeniedException if user has not sufficient rights
596
     * @deprecated Use {@link #getDocument(DBBroker, XmldbURI)} instead
597
     */
598
    @Deprecated
599
    @Nullable DocumentImpl getDocumentNoLock(DBBroker broker, String rawPath) throws PermissionDeniedException;
600

601
    /**
602
     * Remove the specified child Collection
603
     *
604
     * @param broker The database broker
605
     * @param name   the name of the child Collection (without path)
606
     * @throws PermissionDeniedException if user has not sufficient rights
607
     * @throws LockException if broker is locked
608
     */
609
    void removeCollection(DBBroker broker, XmldbURI name) throws LockException, PermissionDeniedException;
610

611
    /**
612
     * Removes a document from this Collection
613
     *
614
     * @param transaction The database transaction
615
     * @param broker      The database broker
616
     * @param doc         The document to remove
617
     * @throws PermissionDeniedException if user has not sufficient rights
618
     * @throws LockException if broker is locked
619
     * @throws IOException in case of I/O errors
620
     * @throws TriggerException in case of trigger error
621
     */
622
    void removeResource(Txn transaction, DBBroker broker, DocumentImpl doc)
623
            throws PermissionDeniedException, LockException, IOException, TriggerException;
624

625
    /**
626
     * Remove an XML document from this Collection
627
     *
628
     * @param transaction The database transaction
629
     * @param broker      The database broker
630
     * @param name        the name (without path) of the document
631
     * @throws PermissionDeniedException if user has not sufficient rights
632
     * @throws LockException if broker is locked
633
     * @throws IOException in case of I/O errors
634
     * @throws TriggerException in case of trigger error
635
     */
636
    void removeXMLResource(Txn transaction, DBBroker broker, XmldbURI name)
637
            throws PermissionDeniedException, TriggerException, LockException, IOException;
638

639
    /**
640
     * Remove a Binary document from this Collection
641
     *
642
     * @param transaction The database transaction
643
     * @param broker      The database broker
644
     * @param name        the name (without path) of the document
645
     * @throws PermissionDeniedException if user has not sufficient rights
646
     * @throws LockException if broker is locked
647
     * @throws TriggerException in case of trigger error
648
     */
649
    void removeBinaryResource(Txn transaction, DBBroker broker, XmldbURI name)
650
            throws PermissionDeniedException, LockException, TriggerException;
651

652
    /**
653
     * Remove a Binary document from this Collection
654
     *
655
     * @param transaction The database transaction
656
     * @param broker      The database broker
657
     * @param doc         the document to remove
658
     * @throws PermissionDeniedException if user has not sufficient rights
659
     * @throws LockException if broker is locked
660
     * @throws TriggerException in case of trigger error
661
     */
662
    void removeBinaryResource(Txn transaction, DBBroker broker, DocumentImpl doc)
663
            throws PermissionDeniedException, LockException, TriggerException;
664

665
    /**
666
     * Stores a document.
667
     * Since the process is dependent on the collection configuration,
668
     * the collection acquires a write lock during the process.
669
     *
670
     * NOTE: This should only be called from {@link NativeBroker#storeDocument(Txn, XmldbURI, InputSource, MimeType, Date, Date, Permission, DocumentType, XMLReader, Collection)}
671
     *
672
     * @param transaction The database transaction
673
     * @param broker      The database broker
674
     * @param name        The name (without path) of the document
675
     * @param source      The source of the content for the new document to store
676
     * @param mimeType    The mimeType of the document to store, or null if unknown.
677
     *
678
     * @throws PermissionDeniedException if user has not sufficient rights
679
     * @throws LockException if broker is locked
680
     * @throws IOException in case of I/O errors
681
     * @throws TriggerException in case of trigger error
682
     * @throws EXistException general exception
683
     * @throws SAXException internal SAXException
684
     */
685
    void storeDocument(Txn transaction, DBBroker broker, XmldbURI name, InputSource source, @Nullable MimeType mimeType) throws EXistException, PermissionDeniedException, TriggerException, SAXException, LockException, IOException;
686

687
    /**
688
     * Stores a document.
689
     * Since the process is dependent on the collection configuration,
690
     * the collection acquires a write lock during the process.
691
     *
692
     * NOTE: This should only be called from {@link NativeBroker#storeDocument(Txn, XmldbURI, InputSource, MimeType, Date, Date, Permission, DocumentType, XMLReader, Collection)}
693
     *
694
     * @param transaction The database transaction
695
     * @param broker      The database broker
696
     * @param name        The name (without path) of the document
697
     * @param source      The source of the content for the new document to store
698
     * @param mimeType    The mimeType of the document to store, or null if unknown.
699
     *                    If null, application/octet-stream will be used to store a binary document.
700
     * @param createdDate The created date to set for the document, or if null the date is set to 'now'
701
     * @param lastModifiedDate The lastModified date to set for the document, or if null the date is set to the {@code createdDate}
702
     * @param permission A specific permission to set on the document, or null for the default permission
703
     * @param documentType A document type declaration, or null if absent or a binary document is being stored
704
     * @param xmlReader A custom XML Reader (e.g. a HTML to XHTML converting reader), or null to use the default XML reader or if a binary document is being stored
705
     *
706
     * @throws PermissionDeniedException if user has not sufficient rights
707
     * @throws LockException if broker is locked
708
     * @throws IOException in case of I/O errors
709
     * @throws TriggerException in case of trigger error
710
     * @throws EXistException general exception
711
     * @throws SAXException internal SAXException
712
     */
713
    void storeDocument(Txn transaction, DBBroker broker, XmldbURI name, InputSource source, @Nullable MimeType mimeType, @Nullable Date createdDate, @Nullable Date lastModifiedDate, @Nullable Permission permission, @Nullable DocumentType documentType, @Nullable XMLReader xmlReader) throws EXistException, PermissionDeniedException, TriggerException, SAXException, LockException, IOException;
714

715
    /**
716
     * Stores a document.
717
     * Since the process is dependent on the collection configuration,
718
     * the collection acquires a write lock during the process.
719
     *
720
     * NOTE: This should only be called from {@link NativeBroker#storeDocument(Txn, XmldbURI, Node, MimeType, Collection)}
721
     *
722
     * @param transaction The database transaction
723
     * @param broker      The database broker
724
     * @param name        The name (without path) of the document
725
     * @param node        The DOM Node to store as a new document
726
     * @param mimeType    The mimeType of the document to store, or null if unknown.
727
     *
728
     * @throws PermissionDeniedException if user has not sufficient rights
729
     * @throws LockException if broker is locked
730
     * @throws IOException in case of I/O errors
731
     * @throws TriggerException in case of trigger error
732
     * @throws EXistException general exception
733
     * @throws SAXException internal SAXException
734
     */
735
    void storeDocument(Txn transaction, DBBroker broker, XmldbURI name, Node node, @Nullable MimeType mimeType) throws EXistException, PermissionDeniedException, TriggerException, SAXException, LockException, IOException;
736

737
    /**
738
     * Stores a document.
739
     * Since the process is dependent on the collection configuration,
740
     * the collection acquires a write lock during the process.
741
     *
742
     * NOTE: This should only be called from {@link NativeBroker#storeDocument(Txn, XmldbURI, Node, MimeType, Date, Date, Permission, DocumentType, XMLReader, Collection)}
743
     *
744
     * @param transaction The database transaction
745
     * @param broker      The database broker
746
     * @param name        The name (without path) of the document
747
     * @param node        The DOM Node to store as a new document
748
     * @param mimeType    The mimeType of the document to store, or null if unknown.
749
     *                    If null, application/octet-stream will be used to store a binary document.
750
     * @param createdDate The created date to set for the document, or if null the date is set to 'now'
751
     * @param lastModifiedDate The lastModified date to set for the document, or if null the date is set to the {@code createdDate}
752
     * @param permission A specific permission to set on the document, or null for the default permission
753
     * @param documentType A document type declaration, or null if absent or a binary document is being stored
754
     * @param xmlReader A custom XML Reader (e.g. a HTML to XHTML converting reader), or null to use the default XML reader or if a binary document is being stored
755
     *
756
     * @throws PermissionDeniedException if user has not sufficient rights
757
     * @throws LockException if broker is locked
758
     * @throws IOException in case of I/O errors
759
     * @throws TriggerException in case of trigger error
760
     * @throws EXistException general exception
761
     * @throws SAXException internal SAXException
762
     */
763
    void storeDocument(Txn transaction, DBBroker broker, XmldbURI name, Node node, @Nullable MimeType mimeType, @Nullable Date createdDate, @Nullable Date lastModifiedDate, @Nullable Permission permission, @Nullable DocumentType documentType, @Nullable XMLReader xmlReader) throws EXistException, PermissionDeniedException, TriggerException, SAXException, LockException, IOException;
764

765
    /**
766
     * Validates an XML document and prepares it for further storage.
767
     * Launches prepare and postValidate triggers.
768
     * Since the process is dependent from the collection configuration,
769
     * the collection acquires a write lock during the process.
770
     *
771
     * @param transaction The database transaction
772
     * @param broker      The database broker
773
     * @param name        the name (without path) of the document
774
     * @param source      The source of the document to store
775
     *
776
     * @return An {@link IndexInfo} with a write lock on the document
777
     *
778
     * @throws PermissionDeniedException if user has not sufficient rights
779
     * @throws LockException if broker is locked
780
     * @throws IOException in case of I/O errors
781
     * @throws TriggerException in case of trigger error
782
     * @throws EXistException general exception
783
     * @throws SAXException internal SAXException
784
     *
785
     * @deprecated Use {@link DBBroker#storeDocument(Txn, XmldbURI, InputSource, MimeType, Date, Date, Permission, DocumentType, XMLReader, Collection)} instead.
786
     */
787
    @Deprecated
788
    IndexInfo validateXMLResource(Txn transaction, DBBroker broker, XmldbURI name, InputSource source)
789
            throws EXistException, PermissionDeniedException, TriggerException, SAXException, LockException, IOException;
790

791

792
    /**
793
     * Validates an XML document and prepares it for further storage.
794
     * Launches prepare and postValidate triggers.
795
     * Since the process is dependent from the collection configuration,
796
     * the collection acquires a write lock during the process.
797
     *
798
     * @param transaction The database transaction
799
     * @param broker      The database broker
800
     * @param name        the name (without path) of the document
801
     * @param source      The source of the document to store
802
     * @param reader      The XML reader to use for reading the {@code source}
803
     *
804
     * @return An {@link IndexInfo} with a write lock on the document
805
     *
806
     * @throws PermissionDeniedException if user has not sufficient rights
807
     * @throws LockException if broker is locked
808
     * @throws IOException in case of I/O errors
809
     * @throws TriggerException in case of trigger error
810
     * @throws EXistException general exception
811
     * @throws SAXException internal SAXException
812
     *
813
     * @deprecated Use {@link DBBroker#storeDocument(Txn, XmldbURI, InputSource, MimeType, Date, Date, Permission, DocumentType, XMLReader, Collection)} instead.
814
     */
815
    @Deprecated
816
    IndexInfo validateXMLResource(Txn transaction, DBBroker broker, XmldbURI name, InputSource source, XMLReader reader)
817
            throws EXistException, PermissionDeniedException, TriggerException, SAXException, LockException, IOException;
818

819
    /**
820
     * Validates an XML document and prepares it for further storage.
821
     * Launches prepare and postValidate triggers.
822
     * Since the process is dependent from the collection configuration,
823
     * the collection acquires a write lock during the process.
824
     *
825
     * @param transaction The database transaction
826
     * @param broker      The database broker
827
     * @param name        the name (without path) of the document
828
     * @param data        The data of the document to store
829
     *
830
     * @return An {@link IndexInfo} with a write lock on the document
831
     *
832
     * @throws PermissionDeniedException if user has not sufficient rights
833
     * @throws LockException if broker is locked
834
     * @throws IOException in case of I/O errors
835
     * @throws TriggerException in case of trigger error
836
     * @throws EXistException general exception
837
     * @throws SAXException internal SAXException
838
     *
839
     * @deprecated Use {@link DBBroker#storeDocument(Txn, XmldbURI, InputSource, MimeType, Date, Date, Permission, DocumentType, XMLReader, Collection)} instead.
840
     */
841
    @Deprecated
842
    IndexInfo validateXMLResource(Txn transaction, DBBroker broker, XmldbURI name, String data)
843
            throws EXistException, PermissionDeniedException, TriggerException, SAXException, LockException, IOException;
844

845
    /**
846
     * Validates an XML document and prepares it for further storage.
847
     * Launches prepare and postValidate triggers.
848
     * Since the process is dependent from the collection configuration,
849
     * the collection acquires a write lock during the process.
850
     *
851
     * @param transaction The database transaction
852
     * @param broker      The database broker
853
     * @param name        the name (without path) of the document
854
     * @param node        The document node of the document to store
855
     *
856
     * @return An {@link IndexInfo} with a write lock on the document
857
     *
858
     * @throws PermissionDeniedException if user has not sufficient rights
859
     * @throws LockException if broker is locked
860
     * @throws IOException in case of I/O errors
861
     * @throws TriggerException in case of trigger error
862
     * @throws EXistException general exception
863
     * @throws SAXException internal SAXException
864
     *
865
     * @deprecated Use {@link DBBroker#storeDocument(Txn, XmldbURI, Node, MimeType, Date, Date, Permission, DocumentType, XMLReader, Collection)} instead.
866
     */
867
    @Deprecated
868
    IndexInfo validateXMLResource(Txn transaction, DBBroker broker, XmldbURI name, Node node)
869
            throws EXistException, PermissionDeniedException, TriggerException, SAXException, LockException, IOException;
870

871
    /**
872
     * Stores an XML document into the Collection
873
     *
874
     * {@link #validateXMLResource(Txn, DBBroker, XmldbURI, InputSource)} should have been called previously in order
875
     * to acquire a write lock for the document. Launches the finish trigger.
876
     *
877
     * @param transaction The database transaction
878
     * @param broker      The database broker
879
     * @param info        Tracks information between validate and store phases
880
     * @param source      The source of the document to store
881
     *
882
     * @throws PermissionDeniedException if user has not sufficient rights
883
     * @throws LockException if broker is locked
884
     * @throws TriggerException in case of trigger error
885
     * @throws EXistException general exception
886
     * @throws SAXException internal SAXException
887
     *
888
     * @deprecated Use {@link DBBroker#storeDocument(Txn, XmldbURI, InputSource, MimeType, Date, Date, Permission, DocumentType, XMLReader, Collection)} instead.
889
     */
890
    @Deprecated
891
    void store(Txn transaction, DBBroker broker, IndexInfo info, InputSource source)
892
            throws EXistException, PermissionDeniedException, TriggerException, SAXException, LockException;
893

894
    /**
895
     * Stores an XML document into the Collection
896
     *
897
     * {@link #validateXMLResource(Txn, DBBroker, XmldbURI, InputSource, XMLReader)} should have been called previously
898
     * in order to acquire a write lock for the document. Launches the finish trigger.
899
     *
900
     * @param transaction The database transaction
901
     * @param broker      The database broker
902
     * @param info        Tracks information between validate and store phases
903
     * @param source      The source of the document to store
904
     * @param reader      The XML reader to use for reading the {@code source}
905
     *
906
     * @throws PermissionDeniedException if user has not sufficient rights
907
     * @throws LockException if broker is locked*
908
     * @throws TriggerException in case of trigger error
909
     * @throws EXistException general exception
910
     * @throws SAXException internal SAXException
911
     *
912
     * @deprecated Use {@link DBBroker#storeDocument(Txn, XmldbURI, InputSource, MimeType, Date, Date, Permission, DocumentType, XMLReader, Collection)} instead.
913
     */
914
    @Deprecated
915
    void store(final Txn transaction, final DBBroker broker, final IndexInfo info, final InputSource source, final XMLReader reader)
916
            throws EXistException, PermissionDeniedException, TriggerException, SAXException, LockException;
917

918
    /**
919
     * Stores an XML document into the Collection
920
     *
921
     * {@link #validateXMLResource(Txn, DBBroker, XmldbURI, String)} should have been called previously in order to
922
     * acquire a write lock for the document. Launches the finish trigger.
923
     *
924
     * @param transaction The database transaction
925
     * @param broker      The database broker
926
     * @param info        Tracks information between validate and store phases
927
     * @param data        The data of the document to store
928
     *
929
     * @throws PermissionDeniedException if user has not sufficient rights
930
     * @throws LockException if broker is locked
931
     * @throws TriggerException in case of trigger error
932
     * @throws EXistException general exception
933
     * @throws SAXException internal SAXException
934
     *
935
     * @deprecated Use {@link DBBroker#storeDocument(Txn, XmldbURI, InputSource, MimeType, Date, Date, Permission, DocumentType, XMLReader, Collection)} instead.
936
     */
937
    @Deprecated
938
    void store(Txn transaction, DBBroker broker, IndexInfo info, String data)
939
            throws EXistException, PermissionDeniedException, TriggerException, SAXException, LockException;
940

941
    /**
942
     * Stores an XML document into the Collection
943
     *
944
     * {@link #validateXMLResource(Txn, DBBroker, XmldbURI, Node)} should have been called previously in order to
945
     * acquire a write lock for the document. Launches the finish trigger.
946
     *
947
     * @param transaction The database transaction
948
     * @param broker      The database broker
949
     * @param info        Tracks information between validate and store phases
950
     * @param node        The document node of the document to store
951
     *
952
     * @throws PermissionDeniedException if user has not sufficient rights
953
     * @throws LockException if broker is locked
954
     * @throws TriggerException in case of trigger error
955
     * @throws EXistException general exception
956
     * @throws SAXException internal SAXException
957
     *
958
     * @deprecated Use {@link DBBroker#storeDocument(Txn, XmldbURI, Node, MimeType, Date, Date, Permission, DocumentType, XMLReader, Collection)} instead.
959
     */
960
    @Deprecated
961
    void store(Txn transaction, DBBroker broker, IndexInfo info, Node node)
962
            throws EXistException, PermissionDeniedException, TriggerException, SAXException, LockException;
963

964
    /**
965
     * Creates a Binary Document object
966
     *
967
     * @param transaction The database transaction
968
     * @param broker      The database broker
969
     * @param name        the name (without path) of the document
970
     *
971
     * @return The Binary Document object
972
     *
973
     * @throws PermissionDeniedException if user has not sufficient rights
974
     * @throws LockException if broker is locked
975
     * @throws IOException in case of I/O errors
976
     * @throws TriggerException in case of trigger error
977
     *
978
     * @deprecated Use {@link DBBroker#storeDocument(Txn, XmldbURI, InputSource, MimeType, Date, Date, Permission, DocumentType, XMLReader, Collection)} instead.
979
     */
980
    @Deprecated
981
    BinaryDocument validateBinaryResource(Txn transaction, DBBroker broker, XmldbURI name)
982
            throws PermissionDeniedException, LockException, TriggerException, IOException;
983

984
    /**
985
     * Store a binary document into the Collection (streaming)
986
     *
987
     * Locks the collection while the resource is being saved. Triggers will be called after the collection
988
     * has been unlocked while keeping a lock on the resource to prevent modification.
989
     *
990
     * Callers should not lock the collection before calling this method as this may lead to deadlocks.
991
     *
992
     * @param transaction The database transaction
993
     * @param broker      The database broker
994
     * @param name        the name (without path) of the document
995
     * @param is          The content for the document
996
     * @param mimeType    The Internet Media Type of the document
997
     * @param size        The size in bytes of the document (unused - size is calculated during storage)
998
     * @param created     The created timestamp of the document
999
     * @param modified    The modified timestamp of the document
1000
     *
1001
     * @return The stored Binary Document object
1002
     *
1003
     * @throws PermissionDeniedException if user has not sufficient rights
1004
     * @throws LockException if broker is locked
1005
     * @throws IOException in case of I/O errors
1006
     * @throws TriggerException in case of trigger error
1007
     * @throws EXistException general exception*
1008
     *
1009
     * @deprecated Use {@link DBBroker#storeDocument(Txn, XmldbURI, InputSource, MimeType, Date, Date, Permission, DocumentType, XMLReader, Collection)} instead.
1010
     */
1011
    @Deprecated
1012
    BinaryDocument addBinaryResource(Txn transaction, DBBroker broker, XmldbURI name, InputStream is, String mimeType,
1013
            @Deprecated long size, Date created, Date modified) throws EXistException, PermissionDeniedException, LockException,
1014
            TriggerException, IOException;
1015

1016
    /**
1017
     * Store a binary document into the Collection (streaming)
1018
     *
1019
     * Locks the collection while the resource is being saved. Triggers will be called after the collection
1020
     * has been unlocked while keeping a lock on the resource to prevent modification.
1021
     *
1022
     * Callers should not lock the collection before calling this method as this may lead to deadlocks.
1023
     *
1024
     * @param transaction The database transaction
1025
     * @param broker      The database broker
1026
     * @param name        the name (without path) of the document
1027
     * @param is          The content for the document
1028
     * @param mimeType    The Internet Media Type of the document
1029
     * @param size        The size in bytes of the document (unused - size is calculated during storage)
1030
     * @param created     The created timestamp of the document
1031
     * @param modified    The modified timestamp of the document
1032
     * @param permission A specific permission to set on the document, or null for the default permission
1033
     *
1034
     * @return The stored Binary Document object
1035
     *
1036
     * @throws PermissionDeniedException if user has not sufficient rights
1037
     * @throws LockException if broker is locked
1038
     * @throws IOException in case of I/O errors
1039
     * @throws TriggerException in case of trigger error
1040
     * @throws EXistException general exception*
1041
     *
1042
     * @deprecated Use {@link DBBroker#storeDocument(Txn, XmldbURI, InputSource, MimeType, Date, Date, Permission, DocumentType, XMLReader, Collection)} instead.
1043
     */
1044
    @Deprecated
1045
    BinaryDocument addBinaryResource(Txn transaction, DBBroker broker, XmldbURI name, InputStream is, String mimeType,
1046
            @Deprecated long size, Date created, Date modified, @Nullable Permission permission) throws EXistException, PermissionDeniedException, LockException,
1047
            TriggerException, IOException;
1048

1049
    /**
1050
     * Store a binary document into the Collection
1051
     *
1052
     * Locks the collection while the resource is being saved. Triggers will be called after the collection
1053
     * has been unlocked while keeping a lock on the resource to prevent modification.
1054
     *
1055
     * Callers should not lock the collection before calling this method as this may lead to deadlocks.
1056
     *
1057
     * @param transaction The database transaction
1058
     * @param broker      The database broker
1059
     * @param name        the name (without path) of the document
1060
     * @param data        The content for the document
1061
     * @param mimeType    The Internet Media Type of the document
1062
     *
1063
     * @return The stored Binary Document object
1064
     *
1065
     * @throws PermissionDeniedException if user has not sufficient rights
1066
     * @throws LockException if broker is locked
1067
     * @throws IOException in case of I/O errors
1068
     * @throws TriggerException in case of trigger error
1069
     * @throws EXistException general exception
1070
     *
1071
     * @deprecated Use {@link #addBinaryResource(Txn, DBBroker, XmldbURI, InputStream, String, long)}
1072
     */
1073
    @Deprecated
1074
    BinaryDocument addBinaryResource(Txn transaction, DBBroker broker, XmldbURI name, byte[] data, String mimeType)
1075
            throws EXistException, PermissionDeniedException, LockException, TriggerException, IOException;
1076

1077
    /**
1078
     * Store a binary document into the Collection
1079
     *
1080
     * Locks the collection while the resource is being saved. Triggers will be called after the collection
1081
     * has been unlocked while keeping a lock on the resource to prevent modification.
1082
     *
1083
     * Callers should not lock the collection before calling this method as this may lead to deadlocks.
1084
     *
1085
     * @param transaction The database transaction
1086
     * @param broker      The database broker
1087
     * @param name        the name (without path) of the document
1088
     * @param data        The content for the document
1089
     * @param mimeType    The Internet Media Type of the document
1090
     * @param created     The created timestamp of the document
1091
     * @param modified    The modified timestamp of the document
1092
     *
1093
     * @return The stored Binary Document object
1094
     *
1095
     * @throws PermissionDeniedException if user has not sufficient rights
1096
     * @throws LockException if broker is locked
1097
     * @throws IOException in case of I/O errors
1098
     * @throws TriggerException in case of trigger error
1099
     * @throws EXistException general exception
1100
     *
1101
     * @deprecated Use {@link #addBinaryResource(Txn, DBBroker, BinaryDocument, InputStream, String, long, Date, Date)}
1102
     */
1103
    @Deprecated
1104
    BinaryDocument addBinaryResource(Txn transaction, DBBroker broker, XmldbURI name, byte[] data, String mimeType,
1105
            Date created, Date modified) throws EXistException, PermissionDeniedException, LockException,
1106
            TriggerException, IOException;
1107

1108
    /**
1109
     * Store a binary document into the Collection (streaming)
1110
     *
1111
     * Locks the collection while the resource is being saved. Triggers will be called after the collection
1112
     * has been unlocked while keeping a lock on the resource to prevent modification.
1113
     *
1114
     * Callers should not lock the collection before calling this method as this may lead to deadlocks.
1115
     *
1116
     * @param transaction The database transaction
1117
     * @param broker      The database broker
1118
     * @param name        the name (without path) of the document
1119
     * @param is          The content for the document
1120
     * @param mimeType    The Internet Media Type of the document
1121
     * @param size        The size in bytes of the document (unused - size is calculated during storage)
1122
     *
1123
     * @return The stored Binary Document object
1124
     *
1125
     * @throws PermissionDeniedException if user has not sufficient rights
1126
     * @throws LockException if broker is locked
1127
     * @throws IOException in case of I/O errors
1128
     * @throws TriggerException in case of trigger error
1129
     * @throws EXistException general exception
1130
     *
1131
     * @deprecated Use {@link DBBroker#storeDocument(Txn, XmldbURI, InputSource, MimeType, Date, Date, Permission, DocumentType, XMLReader, Collection)} instead.
1132
     */
1133
    @Deprecated
1134
    BinaryDocument addBinaryResource(Txn transaction, DBBroker broker, XmldbURI name, InputStream is,
1135
            String mimeType, @Deprecated long size) throws EXistException, PermissionDeniedException, LockException,
1136
            TriggerException, IOException;
1137

1138
    /**
1139
     * Store a binary document into the Collection (streaming)
1140
     *
1141
     * Locks the collection while the resource is being saved. Triggers will be called after the collection
1142
     * has been unlocked while keeping a lock on the resource to prevent modification.
1143
     *
1144
     * Callers should not lock the collection before calling this method as this may lead to deadlocks.
1145
     *
1146
     * @param transaction The database transaction
1147
     * @param broker      The database broker
1148
     * @param blob        the binary resource to store the data into
1149
     * @param is          The content for the document
1150
     * @param mimeType    The Internet Media Type of the document
1151
     * @param size        The size in bytes of the document (unused - size is calculated during storage)
1152
     * @param created     The created timestamp of the document
1153
     * @param modified    The modified timestamp of the document
1154
     *
1155
     * @return The stored Binary Document object
1156
     *
1157
     * @throws PermissionDeniedException if user has not sufficient rights
1158
     * @throws LockException if broker is locked
1159
     * @throws IOException in case of I/O errors
1160
     * @throws TriggerException in case of trigger error
1161
     * @throws EXistException general exception
1162
     *
1163
     * @deprecated Use {@link DBBroker#storeDocument(Txn, XmldbURI, InputSource, MimeType, Date, Date, Permission, DocumentType, XMLReader, Collection)} instead.
1164
     */
1165
    @Deprecated
1166
    BinaryDocument addBinaryResource(Txn transaction, DBBroker broker, BinaryDocument blob, InputStream is,
1167
            String mimeType, @Deprecated long size, Date created, Date modified) throws EXistException, PermissionDeniedException,
1168
            LockException, TriggerException, IOException;
1169

1170
    /**
1171
     * Store a binary document into the Collection (streaming)
1172
     *
1173
     * Locks the collection while the resource is being saved. Triggers will be called after the collection
1174
     * has been unlocked while keeping a lock on the resource to prevent modification.
1175
     *
1176
     * Callers should not lock the collection before calling this method as this may lead to deadlocks.
1177
     *
1178
     * @param transaction The database transaction
1179
     * @param broker      The database broker
1180
     * @param blob        the binary resource to store the data into
1181
     * @param is          The content for the document
1182
     * @param mimeType    The Internet Media Type of the document
1183
     * @param size        The size in bytes of the document (unused - size is calculated during storage)
1184
     * @param created     The created timestamp of the document
1185
     * @param modified    The modified timestamp of the document
1186
     * @param preserve    In the case of a copy, cause the copy process to preserve the following attributes of each
1187
     *                    source in the copy: modification time, file mode, user ID, and group ID, as allowed by
1188
     *                    permissions. Access Control Lists (ACLs) will also be preserved.
1189
     *
1190
     * @return The stored Binary Document object
1191
     *
1192
     * @throws PermissionDeniedException if user has not sufficient rights
1193
     * @throws LockException if broker is locked
1194
     * @throws IOException in case of I/O errors
1195
     * @throws TriggerException in case of trigger error
1196
     * @throws EXistException general exception
1197
     *
1198
     * @deprecated Use {@link DBBroker#storeDocument(Txn, XmldbURI, InputSource, MimeType, Date, Date, Permission, DocumentType, XMLReader, Collection)} instead.
1199
     */
1200
    @Deprecated
1201
    BinaryDocument addBinaryResource(Txn transaction, DBBroker broker, BinaryDocument blob, InputStream is,
1202
            String mimeType, @Deprecated long size, Date created, Date modified, DBBroker.PreserveType preserve)
1203
            throws EXistException, PermissionDeniedException, LockException, TriggerException, IOException;
1204

1205
    /**
1206
     * Serializes the Collection to a variable byte representation
1207
     *
1208
     * @param outputStream The output stream to write the collection contents to
1209
     * @throws LockException if broker is locked
1210
     * @throws IOException in case of I/O errors
1211

1212
     */
1213
    @EnsureContainerLocked(mode=READ_LOCK) void serialize(final VariableByteOutputStream outputStream) throws IOException, LockException;
1214

1215
    @Override void close();
1216

1217
    //TODO(AR) consider a better separation between Broker and Collection, possibly introduce a CollectionManager object
1218
    interface InternalAccess {
1219
        void addDocument(DocumentImpl doc) throws EXistException;
1220
        int getId();
1221
    }
1222

1223

1224
    //TODO(AR) remove specific implementation details from below - i.e. the read functions etc;
1225
    abstract class CollectionEntry {
1226
        private final XmldbURI uri;
1227
        private Permission permissions;
1228
        private long created = -1;
1✔
1229

1230
        protected CollectionEntry(final XmldbURI uri, final Permission permissions) {
1✔
1231
            this.uri = uri;
1✔
1232
            this.permissions = permissions;
1✔
1233
        }
1✔
1234

1235
        public abstract void readMetadata(DBBroker broker) throws IOException, LockException;
1236

1237
        public abstract void read(VariableByteInput is) throws IOException;
1238

1239
        public XmldbURI getUri() {
1240
            return uri;
1✔
1241
        }
1242

1243
        public long getCreated() {
1244
            return created;
1✔
1245
        }
1246

1247
        protected void setCreated(final long created) {
1248
            this.created = created;
1✔
1249
        }
1✔
1250

1251
        public Permission getPermissions() {
1252
            return permissions;
1✔
1253
        }
1254

1255
        protected void setPermissions(final Permission permissions) {
1256
            this.permissions = permissions;
1✔
1257
        }
1✔
1258
    }
1259

1260
    class SubCollectionEntry extends CollectionEntry {
1261
        public SubCollectionEntry(final SecurityManager sm, final XmldbURI uri) {
1262
            super(uri, PermissionFactory.getDefaultCollectionPermission(sm));
1✔
1263
        }
1✔
1264

1265
        @Override
1266
        public void readMetadata(final DBBroker broker) throws IOException, LockException {
1267
            broker.readCollectionEntry(this);
1✔
1268
        }
1✔
1269

1270
        @Override
1271
        public void read(final VariableByteInput is) throws IOException {
1272
            is.skip(1);
×
1273
            final int collLen = is.readInt();
×
1274
            for (int i = 0; i < collLen; i++) {
×
1275
                is.readUTF();
×
1276
            }
1277
            getPermissions().read(is);
×
1278
            setCreated(is.readLong());
×
1279
        }
×
1280

1281
        public void read(final Collection collection) {
1282
            setPermissions(collection.getPermissionsNoLock());
1✔
1283
            setCreated(collection.getCreated());
1✔
1284
        }
1✔
1285
    }
1286

1287
    class DocumentEntry extends CollectionEntry {
1288
        public DocumentEntry(final DocumentImpl document) {
1289
            super(document.getURI(), document.getPermissions());
1✔
1290
            setCreated(document.getCreated());
1✔
1291
        }
1✔
1292

1293
        @Override
1294
        public void readMetadata(final DBBroker broker) {
1295
        }
1✔
1296

1297
        @Override
1298
        public void read(final VariableByteInput is) {
1299
        }
×
1300
    }
1301
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc