use of org.exist.storage.txn.Txn in project exist by eXist-db.
the class MutableCollection method storeDocument.
@Override
public void storeDocument(final Txn transaction, final DBBroker broker, final XmldbURI name, final InputSource source, @Nullable MimeType mimeType, @Nullable final Date createdDate, @Nullable final Date lastModifiedDate, @Nullable final Permission permission, @Nullable final DocumentType documentType, @Nullable final XMLReader xmlReader) throws EXistException, PermissionDeniedException, SAXException, LockException, IOException {
if (mimeType == null) {
mimeType = MimeType.BINARY_TYPE;
}
if (mimeType.isXMLType()) {
// Store XML Document
final BiConsumer2E<XMLReader, IndexInfo, SAXException, EXistException> validatorFn = (xmlReader1, validateIndexInfo) -> {
validateIndexInfo.setReader(xmlReader1, null);
try {
xmlReader1.parse(source);
} catch (final SAXException e) {
throw new SAXException("The XML parser reported a problem: " + e.getMessage(), e);
} catch (final IOException e) {
throw new EXistException(e);
}
};
final BiConsumer2E<XMLReader, IndexInfo, SAXException, EXistException> parserFn = (xmlReader1, storeIndexInfo) -> {
try {
storeIndexInfo.setReader(xmlReader1, null);
xmlReader1.parse(source);
} catch (final IOException e) {
throw new EXistException(e);
}
};
storeXmlDocument(transaction, broker, name, mimeType, createdDate, lastModifiedDate, permission, documentType, xmlReader, validatorFn, parserFn);
} else {
// Store Binary Document
try (final InputStream is = source.getByteStream()) {
if (is == null) {
throw new IOException("storeDocument received a null InputStream when trying to store a Binary Document");
}
addBinaryResource(transaction, broker, name, is, mimeType.getName(), -1, createdDate, lastModifiedDate, permission);
}
}
}
use of org.exist.storage.txn.Txn in project exist by eXist-db.
the class CollectionConfigurationManager method checkRootCollectionConfig.
/**
* Create a stored default configuration document for the root collection
*
* @param broker The broker which will do the operation
* @throws EXistException if something goes wrong
* @throws PermissionDeniedException if user does not have sufficient rights
*/
public void checkRootCollectionConfig(DBBroker broker) throws EXistException, PermissionDeniedException {
// Copied from the legacy conf.xml in order to make the test suite work
// TODO : backward compatibility could be ensured by copying the
// relevant parts of conf.xml
final String configuration = "<collection xmlns=\"http://exist-db.org/collection-config/1.0\">" + " <index>" + " </index>" + "</collection>";
final TransactionManager transact = broker.getDatabase().getTransactionManager();
try (final Txn txn = transact.beginTransaction()) {
try (final Collection collection = broker.openCollection(XmldbURI.ROOT_COLLECTION_URI, LockMode.READ_LOCK)) {
if (collection == null) {
transact.abort(txn);
throw new EXistException("collection " + XmldbURI.ROOT_COLLECTION_URI + " not found!");
}
final CollectionConfiguration conf = getConfiguration(collection);
if (conf != null) {
// it
if (conf.getDocName() != null) {
transact.abort(txn);
return;
}
}
// Configure the root collection
addConfiguration(txn, broker, collection, configuration);
LOG.info("Configured '{}'", collection.getURI());
}
transact.commit(txn);
} catch (final CollectionConfigurationException e) {
throw new EXistException(e.getMessage());
}
}
use of org.exist.storage.txn.Txn in project exist by eXist-db.
the class RestoreHandler method setDeferredPermissions.
private void setDeferredPermissions() {
final DeferredPermission deferredPermission = deferredPermissions.pop();
try (final Txn transaction = beginTransaction()) {
deferredPermission.apply(broker, transaction);
transaction.commit();
} catch (final TransactionException e) {
final String msg = "ERROR: Failed to set permissions on: '" + deferredPermission.getTarget() + "'.";
LOG.error(msg, e);
listener.warn(msg);
}
}
use of org.exist.storage.txn.Txn in project exist by eXist-db.
the class SystemImportHandler method setDeferredPermissions.
private void setDeferredPermissions() {
final DeferredPermission deferredPermission = deferredPermissions.pop();
try (final Txn transaction = beginTransaction()) {
deferredPermission.apply(broker, transaction);
transaction.commit();
} catch (final TransactionException e) {
final String msg = "ERROR: Failed to set permissions on: '" + deferredPermission.getTarget() + "'.";
LOG.error(msg, e);
listener.warn(msg);
}
}
use of org.exist.storage.txn.Txn in project exist by eXist-db.
the class SystemImportHandler method mkcol.
private Collection mkcol(final XmldbURI collPath, final Date created) throws SAXException {
try (final Txn transaction = beginTransaction()) {
final Tuple2<Permission, Long> creationAttributes = Tuple(null, created.getTime());
final Collection col = broker.getOrCreateCollection(transaction, collPath, Optional.of(creationAttributes));
transaction.commit();
return col;
} catch (final Exception e) {
throw new SAXException(e);
}
}
Aggregations