Search in sources :

Example 1 with StorageScheme

use of v7db.files.spi.StorageScheme in project v7files by thiloplanz.

the class MongoContentStorage method getContent.

@SuppressWarnings("unchecked")
private Content getContent(BSONObject data) throws IOException {
    if (data == null)
        return null;
    data.removeField("_id");
    String store = BSONUtils.getString(data, "store");
    if (store == null || "raw".equals(store)) {
        return InlineContent.deserialize(data.toMap());
    }
    StorageScheme s = storageSchemes.get(store);
    if (s != null)
        return s.getContent(this, data.toMap());
    throw new UnsupportedOperationException(store);
}
Also used : StorageScheme(v7db.files.spi.StorageScheme)

Example 2 with StorageScheme

use of v7db.files.spi.StorageScheme in project v7files by thiloplanz.

the class MongoContentStorage method getContent.

/**
 * Supported formats: 1) Serialized ContentPointers, e.g.
 *
 * <pre>
 * { in: [bytes] }
 * </pre>
 *
 * and
 *
 * <pre>
 * { sha: <sha>, length: 123 }
 * </pre>
 *
 * 2) Internal StorageScheme representations (must have {store: something}")
 */
public Content getContent(Map<String, Object> data) throws IOException {
    if (data == null)
        return null;
    String store = MapUtils.getString(data, "store");
    if (store == null || "raw".equals(store)) {
        if (data.containsKey("in"))
            return InlineContent.deserialize(data);
        if (data.containsKey("sha")) {
            return new StoredContent((byte[]) data.get("sha"), MapUtils.getRequiredLong(data, "length")).loadOrLazyLoad(this, 8 * 1024);
        }
        throw new UnsupportedOperationException(data.toString());
    }
    StorageScheme s = storageSchemes.get(store);
    if (s == null)
        throw new UnsupportedOperationException(store);
    return s.getContent(this, data);
}
Also used : StorageScheme(v7db.files.spi.StorageScheme) StoredContent(v7db.files.spi.StoredContent)

Example 3 with StorageScheme

use of v7db.files.spi.StorageScheme in project v7files by thiloplanz.

the class MongoContentStorage method storeContent.

public ContentPointer storeContent(Map<String, Object> storageScheme) throws IOException {
    StorageScheme s = storageSchemes.get(storageScheme.get("store"));
    if (s == null)
        throw new UnsupportedOperationException(storageScheme.toString());
    DBObject x = new BasicDBObject();
    for (Map.Entry<String, Object> e : storageScheme.entrySet()) {
        x.put(e.getKey(), e.getValue());
    }
    long length = BSONUtils.getRequiredLong(x, "length");
    byte[] sha = DigestUtils.sha(s.getContent(this, storageScheme).getInputStream());
    long existing = contentCollection.count(new BasicDBObject(_ID, sha));
    if (existing == 0) {
        x.put(_ID, sha);
        contentCollection.insert(x, WriteConcern.SAFE);
    }
    return new StoredContent(sha, length);
}
Also used : BasicDBObject(com.mongodb.BasicDBObject) StorageScheme(v7db.files.spi.StorageScheme) DBObject(com.mongodb.DBObject) BasicDBObject(com.mongodb.BasicDBObject) BSONObject(org.bson.BSONObject) StoredContent(v7db.files.spi.StoredContent) DBObject(com.mongodb.DBObject) BasicDBObject(com.mongodb.BasicDBObject) HashMap(java.util.HashMap) Map(java.util.Map)

Aggregations

StorageScheme (v7db.files.spi.StorageScheme)3 StoredContent (v7db.files.spi.StoredContent)2 BasicDBObject (com.mongodb.BasicDBObject)1 DBObject (com.mongodb.DBObject)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 BSONObject (org.bson.BSONObject)1