001/* 002 * (C) Copyright 2019 Nuxeo (http://nuxeo.com/) and others. 003 * 004 * Licensed under the Apache License, Version 2.0 (the "License"); 005 * you may not use this file except in compliance with the License. 006 * You may obtain a copy of the License at 007 * 008 * http://www.apache.org/licenses/LICENSE-2.0 009 * 010 * Unless required by applicable law or agreed to in writing, software 011 * distributed under the License is distributed on an "AS IS" BASIS, 012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 013 * See the License for the specific language governing permissions and 014 * limitations under the License. 015 * 016 * Contributors: 017 * Florent Guillaume 018 */ 019package org.nuxeo.ecm.core.blob; 020 021import java.io.IOException; 022import java.util.Map; 023 024/** 025 * Blob storage in memory, mostly for unit tests. 026 * 027 * @since 11.1 028 */ 029public class InMemoryBlobProvider extends BlobStoreBlobProvider { 030 031 protected DigestConfiguration digestConfiguration; 032 033 @Override 034 protected BlobStore getBlobStore(String blobProviderId, Map<String, String> properties) throws IOException { 035 digestConfiguration = new DigestConfiguration(null, properties); 036 PropertyBasedConfiguration config = new PropertyBasedConfiguration(null, properties); 037 KeyStrategy keyStrategy = getKeyStrategy(); 038 BlobStore store = new InMemoryBlobStore("mem", config, keyStrategy); 039 if (isTransactional()) { 040 BlobStore transientStore; 041 if (store.hasVersioning()) { 042 // if versioning is used, we don't need a separate transient store for transactions 043 transientStore = store; 044 } else { 045 transientStore = new InMemoryBlobStore("mem_tmp", keyStrategy); 046 } 047 store = new TransactionalBlobStore(store, transientStore); 048 } 049 if (config.getBooleanProperty("test-caching")) { // for tests 050 CachingConfiguration cachingConfiguration = new CachingConfiguration(null, properties); 051 store = new CachingBlobStore("Cache", store, cachingConfiguration); 052 } 053 return store; 054 } 055 056 @Override 057 public void close() { 058 // nothing 059 } 060 061 @Override 062 protected String getDigestAlgorithm() { 063 return digestConfiguration.digestAlgorithm; 064 } 065 066}