}
}
public void storeBinary(java.lang.String sessionId, byte[] data, XmldbURI path, java.lang.String mimeType, boolean replace) throws java.rmi.RemoteException {
DBBroker broker = null;
final Session session = getSession(sessionId);
Collection collection = null;
final TransactionManager transact = pool.getTransactionManager();
final Txn txn = transact.beginTransaction();
try {
broker = pool.get(session.getUser());
final XmldbURI collectionUri = path.removeLastSegment();
final XmldbURI docUri = path.lastSegment();
if (collectionUri==null || docUri==null) {
transact.abort(txn);
throw new EXistException("Illegal document path");
}
collection = broker.openCollection(collectionUri, Lock.WRITE_LOCK);
if (collection == null)
{throw new EXistException("Collection " + collectionUri
+ " not found");}
if (!replace) {
final DocumentImpl old = collection.getDocument(broker, docUri);
if (old != null)
{throw new PermissionDeniedException(
"Old document exists and overwrite is not allowed");}
}
LOG.debug("Storing binary resource to collection " + collection.getURI());
/*DocumentImpl doc = */
collection.addBinaryResource(txn, broker, docUri, data, mimeType);
// if (created != null)
// doc.setCreated(created.getTime());
// if (modified != null)
// doc.setLastModified(modified.getTime());
transact.commit(txn);
} catch (final Exception e) {
transact.abort(txn);
throw new RemoteException(e.getMessage(), e);
} finally {
transact.close(txn);
if(collection != null)
{collection.release(Lock.WRITE_LOCK);}
pool.release(broker);
}
// documentCache.clear();
// return doc != null;
}