listener.setCurrentResource(name);
if(currentCollection instanceof Observable) {
listener.observe((Observable)currentCollection);
}
final TransactionManager txnManager = broker.getDatabase().getTransactionManager();
final Txn txn = txnManager.beginTransaction();
DocumentImpl resource = null;
try {
if ("XMLResource".equals(type)) {
// store as xml resource
final IndexInfo info = currentCollection.validateXMLResource(txn, broker, docUri, is);
resource = info.getDocument();
final DocumentMetadata meta = resource.getMetadata();
meta.setMimeType(mimetype);
meta.setCreated(date_created.getTime());
meta.setLastModified(date_modified.getTime());
if((publicid != null) || (systemid != null)) {
final DocumentType docType = new DocumentTypeImpl(namedoctype, publicid, systemid);
meta.setDocType(docType);
}
rh.startDocumentRestore(resource, atts);
currentCollection.store(txn, broker, info, is, false);
} else {
// store as binary resource
resource = currentCollection.validateBinaryResource(txn, broker, docUri, is.getByteStream(), mimetype, is.getByteStreamLength() , date_created, date_modified);
rh.startDocumentRestore(resource, atts);
resource = currentCollection.addBinaryResource(txn, broker, (BinaryDocument)resource, is.getByteStream(), mimetype, is.getByteStreamLength() , date_created, date_modified);
}
txnManager.commit(txn);
final DeferredPermission deferredPermission;
if(name.startsWith(XmldbURI.SYSTEM_COLLECTION)) {
//prevents restore of a backup from changing system collection resource ownership
deferredPermission = new ResourceDeferredPermission(listener, resource, SecurityManager.SYSTEM, SecurityManager.DBA_GROUP, Integer.parseInt(perms, 8));
} else {
deferredPermission = new ResourceDeferredPermission(listener, resource, owner, group, Integer.parseInt(perms, 8));
}
rh.endDocumentRestore(resource);
listener.restored(name);
return deferredPermission;
} catch (final Exception e) {
txnManager.abort(txn);
throw new IOException(e);
} finally {
txnManager.close(txn);
// if (resource != null)
// resource.getUpdateLock().release(Lock.READ_LOCK);
}
} catch(final Exception e) {