1 package org
.argeo
.cms
.internal
.jcr
;
3 import java
.io
.IOException
;
4 import java
.io
.InputStream
;
5 import java
.nio
.file
.Files
;
6 import java
.nio
.file
.Paths
;
8 import org
.apache
.jackrabbit
.core
.data
.DataIdentifier
;
9 import org
.apache
.jackrabbit
.core
.data
.DataRecord
;
10 import org
.apache
.jackrabbit
.core
.data
.DataStoreException
;
11 import org
.apache
.jackrabbit
.core
.data
.FileDataStore
;
14 * <b>experimental</b> Duplicate added entries in another directory (typically a
17 @SuppressWarnings("restriction")
18 public class LocalFsDataStore
extends FileDataStore
{
20 FileDataStore redundantStore
;
23 public void init(String homeDir
) {
27 if (redundantPath
!= null) {
28 // redundant directory must be created first
29 // TODO implement some polling?
30 if (Files
.exists(Paths
.get(redundantPath
))) {
31 redundantStore
= new FileDataStore();
32 redundantStore
.setPath(redundantPath
);
33 redundantStore
.init(homeDir
);
39 public DataRecord
addRecord(InputStream input
) throws DataStoreException
{
40 DataRecord dataRecord
= super.addRecord(input
);
41 syncRedundantRecord(dataRecord
);
46 public DataRecord
getRecord(DataIdentifier identifier
) throws DataStoreException
{
47 DataRecord dataRecord
= super.getRecord(identifier
);
48 syncRedundantRecord(dataRecord
);
52 protected void syncRedundantRecord(DataRecord dataRecord
) throws DataStoreException
{
53 if (redundantStore
== null)
55 if (redundantStore
.getRecordIfStored(dataRecord
.getIdentifier()) == null) {
56 try (InputStream redundant
= dataRecord
.getStream()) {
57 redundantStore
.addRecord(redundant
);
58 } catch (IOException e
) {
59 throw new DataStoreException("Cannot add redundant record.", e
);
64 public void setRedundantPath(String redundantPath
) {
65 this.redundantPath
= redundantPath
;