public BinaryValue storeValue( InputStream stream, boolean markAsUnused ) throws BinaryStoreException {
// store into temporary file system store and get SHA-1
BinaryValue temp = cache.storeValue(stream, markAsUnused);
try {
// prepare new binary key based on SHA-1
BinaryKey key = new BinaryKey(temp.getKey().toString());
// check for duplicate content
if (this.contentExists(key, ALIVE)) {
return new StoredBinaryValue(this, key, temp.getSize());
}
// check unused content
if (this.contentExists(key, UNUSED)) {
if (!markAsUnused) {
// mark it as used
session.execute("UPDATE modeshape.binary SET usage=1 WHERE cid='" + key + "';");
}
return new StoredBinaryValue(this, key, temp.getSize());
}
if (!markAsUnused) {
// store content as used
String stmt = "INSERT INTO modeshape.binary (cid, payload, usage) VALUES (?,?,1)";
PreparedStatement preparedStatement = session.prepare(stmt);
BoundStatement statement = new BoundStatement(preparedStatement);
session.execute(statement.bind(key.toString(), buffer(stream)));
} else {
// store content as un-used
String stmt = "INSERT INTO modeshape.binary (cid, usage_time, payload, usage) VALUES (?,?,?,0)";
PreparedStatement preparedStatement = session.prepare(stmt);
BoundStatement statement = new BoundStatement(preparedStatement);
session.execute(statement.bind(key.toString(), new Date(), buffer(stream)));
}
return new StoredBinaryValue(this, key, temp.getSize());
} catch (BinaryStoreException e) {
throw e;
} catch (Exception e) {