Skip to content

Commit 77a7560

Browse files
committed
XCOMMONS-3250: Make as easy as possible for various features to use an object store
* First draft of module structure, API and filesystem implementation.
1 parent e8ea461 commit 77a7560

File tree

18 files changed

+1106
-0
lines changed

18 files changed

+1106
-0
lines changed

xwiki-commons-core/pom.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@
5858
<module>xwiki-commons-properties</module>
5959
<module>xwiki-commons-repository</module>
6060
<module>xwiki-commons-script</module>
61+
<module>xwiki-commons-store</module>
6162
<module>xwiki-commons-stability</module>
6263
<module>xwiki-commons-text</module>
6364
<module>xwiki-commons-velocity</module>
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
3+
<!--
4+
* See the NOTICE file distributed with this work for additional
5+
* information regarding copyright ownership.
6+
*
7+
* This is free software; you can redistribute it and/or modify it
8+
* under the terms of the GNU Lesser General Public License as
9+
* published by the Free Software Foundation; either version 2.1 of
10+
* the License, or (at your option) any later version.
11+
*
12+
* This software is distributed in the hope that it will be useful,
13+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
14+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15+
* Lesser General Public License for more details.
16+
*
17+
* You should have received a copy of the GNU Lesser General Public
18+
* License along with this software; if not, write to the Free
19+
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
20+
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
21+
-->
22+
23+
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
24+
<modelVersion>4.0.0</modelVersion>
25+
<parent>
26+
<groupId>org.xwiki.commons</groupId>
27+
<artifactId>xwiki-commons-core</artifactId>
28+
<version>17.7.0-SNAPSHOT</version>
29+
</parent>
30+
<artifactId>xwiki-commons-store</artifactId>
31+
<name>XWiki Commons - Store</name>
32+
<packaging>pom</packaging>
33+
<description>XWiki Commons - Store</description>
34+
<modules>
35+
<module>xwiki-commons-store-api</module>
36+
<module>xwiki-commons-store-blob</module>
37+
</modules>
38+
</project>
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
3+
<!--
4+
* See the NOTICE file distributed with this work for additional
5+
* information regarding copyright ownership.
6+
*
7+
* This is free software; you can redistribute it and/or modify it
8+
* under the terms of the GNU Lesser General Public License as
9+
* published by the Free Software Foundation; either version 2.1 of
10+
* the License, or (at your option) any later version.
11+
*
12+
* This software is distributed in the hope that it will be useful,
13+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
14+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15+
* Lesser General Public License for more details.
16+
*
17+
* You should have received a copy of the GNU Lesser General Public
18+
* License along with this software; if not, write to the Free
19+
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
20+
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
21+
-->
22+
23+
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
24+
<modelVersion>4.0.0</modelVersion>
25+
<parent>
26+
<groupId>org.xwiki.commons</groupId>
27+
<artifactId>xwiki-commons-store</artifactId>
28+
<version>17.7.0-SNAPSHOT</version>
29+
</parent>
30+
<artifactId>xwiki-commons-store-api</artifactId>
31+
<name>XWiki Commons - Store - API</name>
32+
<packaging>jar</packaging>
33+
<description>Storage API for accessing data in a storage backend</description>
34+
<properties>
35+
<xwiki.jacoco.instructionRatio>0.76</xwiki.jacoco.instructionRatio>
36+
</properties>
37+
<dependencies>
38+
<dependency>
39+
<groupId>org.xwiki.commons</groupId>
40+
<artifactId>xwiki-commons-component-api</artifactId>
41+
<version>${project.version}</version>
42+
</dependency>
43+
<!-- Testing dependencies -->
44+
<dependency>
45+
<groupId>org.xwiki.commons</groupId>
46+
<artifactId>xwiki-commons-tool-test-simple</artifactId>
47+
<version>${project.version}</version>
48+
<scope>test</scope>
49+
</dependency>
50+
</dependencies>
51+
</project>
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
/*
2+
* See the NOTICE file distributed with this work for additional
3+
* information regarding copyright ownership.
4+
*
5+
* This is free software; you can redistribute it and/or modify it
6+
* under the terms of the GNU Lesser General Public License as
7+
* published by the Free Software Foundation; either version 2.1 of
8+
* the License, or (at your option) any later version.
9+
*
10+
* This software is distributed in the hope that it will be useful,
11+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
12+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13+
* Lesser General Public License for more details.
14+
*
15+
* You should have received a copy of the GNU Lesser General Public
16+
* License along with this software; if not, write to the Free
17+
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
18+
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
19+
*/
20+
package org.xwiki.store;
21+
22+
import java.io.Serial;
23+
24+
import org.xwiki.stability.Unstable;
25+
26+
/**
27+
* Base exception for store related APIs.
28+
*
29+
* @version $Id$
30+
* @since 17.1.0RC1
31+
*/
32+
@Unstable
33+
public class StoreException extends Exception
34+
{
35+
/**
36+
* Serialization identifier.
37+
*/
38+
@Serial
39+
private static final long serialVersionUID = 1L;
40+
41+
/**
42+
* @param message exception message
43+
*/
44+
public StoreException(String message)
45+
{
46+
super(message);
47+
}
48+
49+
/**
50+
* @param message exception message
51+
* @param cause nested exception
52+
*/
53+
public StoreException(String message, Throwable cause)
54+
{
55+
super(message, cause);
56+
}
57+
}
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
/*
2+
* See the NOTICE file distributed with this work for additional
3+
* information regarding copyright ownership.
4+
*
5+
* This is free software; you can redistribute it and/or modify it
6+
* under the terms of the GNU Lesser General Public License as
7+
* published by the Free Software Foundation; either version 2.1 of
8+
* the License, or (at your option) any later version.
9+
*
10+
* This software is distributed in the hope that it will be useful,
11+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
12+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13+
* Lesser General Public License for more details.
14+
*
15+
* You should have received a copy of the GNU Lesser General Public
16+
* License along with this software; if not, write to the Free
17+
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
18+
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
19+
*/
20+
package org.xwiki.store;
21+
22+
import java.io.InputStream;
23+
24+
/**
25+
* A generic thing which provides access to an InputStream on demand.
26+
*
27+
* @version $Id$
28+
* @since 3.0M2
29+
*/
30+
public interface StreamProvider
31+
{
32+
/**
33+
* Get the stream provided by this StreamProvider.
34+
*
35+
* @return the stream which this StreamProvider provides.
36+
* @throws Exception if something goes wrong while trying to get the stream.
37+
*/
38+
InputStream getStream() throws Exception;
39+
}
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
3+
<!--
4+
* See the NOTICE file distributed with this work for additional
5+
* information regarding copyright ownership.
6+
*
7+
* This is free software; you can redistribute it and/or modify it
8+
* under the terms of the GNU Lesser General Public License as
9+
* published by the Free Software Foundation; either version 2.1 of
10+
* the License, or (at your option) any later version.
11+
*
12+
* This software is distributed in the hope that it will be useful,
13+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
14+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15+
* Lesser General Public License for more details.
16+
*
17+
* You should have received a copy of the GNU Lesser General Public
18+
* License along with this software; if not, write to the Free
19+
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
20+
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
21+
-->
22+
23+
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
24+
<modelVersion>4.0.0</modelVersion>
25+
<parent>
26+
<groupId>org.xwiki.commons</groupId>
27+
<artifactId>xwiki-commons-store</artifactId>
28+
<version>17.7.0-SNAPSHOT</version>
29+
</parent>
30+
<artifactId>xwiki-commons-store-blob</artifactId>
31+
<name>XWiki Commons - Store - Blob</name>
32+
<packaging>pom</packaging>
33+
<description>Blob storage</description>
34+
<modules>
35+
<module>xwiki-commons-store-blob-api</module>
36+
<module>xwiki-commons-store-blob-filesystem</module>
37+
<module>xwiki-commons-store-blob-s3</module>
38+
</modules>
39+
</project>
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
3+
<!--
4+
* See the NOTICE file distributed with this work for additional
5+
* information regarding copyright ownership.
6+
*
7+
* This is free software; you can redistribute it and/or modify it
8+
* under the terms of the GNU Lesser General Public License as
9+
* published by the Free Software Foundation; either version 2.1 of
10+
* the License, or (at your option) any later version.
11+
*
12+
* This software is distributed in the hope that it will be useful,
13+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
14+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15+
* Lesser General Public License for more details.
16+
*
17+
* You should have received a copy of the GNU Lesser General Public
18+
* License along with this software; if not, write to the Free
19+
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
20+
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
21+
-->
22+
23+
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
24+
<modelVersion>4.0.0</modelVersion>
25+
<parent>
26+
<groupId>org.xwiki.commons</groupId>
27+
<artifactId>xwiki-commons-store-blob</artifactId>
28+
<version>17.7.0-SNAPSHOT</version>
29+
</parent>
30+
<artifactId>xwiki-commons-store-blob-api</artifactId>
31+
<name>XWiki Commons - Store - Blob - API</name>
32+
<packaging>jar</packaging>
33+
<description>Storage API for managing blobs of data.</description>
34+
<properties>
35+
<xwiki.jacoco.instructionRatio>0.76</xwiki.jacoco.instructionRatio>
36+
</properties>
37+
<dependencies>
38+
<dependency>
39+
<groupId>org.xwiki.commons</groupId>
40+
<artifactId>xwiki-commons-component-api</artifactId>
41+
<version>${project.version}</version>
42+
</dependency>
43+
<dependency>
44+
<groupId>org.xwiki.commons</groupId>
45+
<artifactId>xwiki-commons-configuration-api</artifactId>
46+
<version>${project.version}</version>
47+
</dependency>
48+
<dependency>
49+
<groupId>org.xwiki.commons</groupId>
50+
<artifactId>xwiki-commons-store-api</artifactId>
51+
<version>${project.version}</version>
52+
</dependency>
53+
<!-- Testing dependencies -->
54+
<dependency>
55+
<groupId>org.xwiki.commons</groupId>
56+
<artifactId>xwiki-commons-tool-test-simple</artifactId>
57+
<version>${project.version}</version>
58+
<scope>test</scope>
59+
</dependency>
60+
</dependencies>
61+
</project>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
/*
2+
* See the NOTICE file distributed with this work for additional
3+
* information regarding copyright ownership.
4+
*
5+
* This is free software; you can redistribute it and/or modify it
6+
* under the terms of the GNU Lesser General Public License as
7+
* published by the Free Software Foundation; either version 2.1 of
8+
* the License, or (at your option) any later version.
9+
*
10+
* This software is distributed in the hope that it will be useful,
11+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
12+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13+
* Lesser General Public License for more details.
14+
*
15+
* You should have received a copy of the GNU Lesser General Public
16+
* License along with this software; if not, write to the Free
17+
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
18+
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
19+
*/
20+
package org.xwiki.store.blob;
21+
22+
import java.io.InputStream;
23+
import java.io.OutputStream;
24+
import java.nio.file.Path;
25+
26+
import org.xwiki.stability.Unstable;
27+
import org.xwiki.store.StreamProvider;
28+
29+
/**
30+
* A Blob is a piece of data stored in a BlobStore.
31+
*
32+
* @version $Id$
33+
* @since 17.7.0RC1
34+
*/
35+
@Unstable
36+
public interface Blob extends StreamProvider
37+
{
38+
/**
39+
* @return the store where this blob is stored
40+
*/
41+
BlobStore getStore();
42+
43+
/**
44+
* @return the path of this blob inside its store
45+
*/
46+
Path getPath();
47+
48+
/**
49+
* @return true if the blob exists, false otherwise
50+
*/
51+
boolean exists();
52+
53+
/**
54+
* Get the size of this blob.
55+
*
56+
* @return the size of this blob in bytes, or -1 if the blob doesn't exist
57+
* @throws BlobStoreException when the size cannot be determined
58+
*/
59+
long getSize() throws BlobStoreException;
60+
61+
/**
62+
* @return an OutputStream to write data to this blob
63+
* @throws BlobStoreException if the blob cannot be written, for example because its name is invalid. There is no
64+
* guarantee that in such a case an exception will be thrown, the exception could also only be thrown when data
65+
* is written to the stream, or when the stream is closed.
66+
*/
67+
OutputStream getOutputStream() throws BlobStoreException;
68+
69+
/**
70+
* Write the content of the given InputStream to this blob.
71+
*
72+
* @param inputStream the InputStream to read data from
73+
* @throws BlobStoreException if the InputStream cannot be read or the blob cannot be written, for example because
74+
* its name is invalid.
75+
*/
76+
void writeFromStream(InputStream inputStream) throws BlobStoreException;
77+
78+
/**
79+
* Copy this blob to another path within the same store.
80+
*
81+
* @param targetPath the target path for the copy
82+
* @return the new blob at the target path
83+
* @throws BlobStoreException if the copy operation fails, for example because this blob doesn't exist
84+
*/
85+
default Blob copyTo(Path targetPath) throws BlobStoreException
86+
{
87+
return getStore().copyBlob(getPath(), targetPath);
88+
}
89+
90+
/**
91+
* Delete this blob from the store if it exists.
92+
*
93+
* @throws BlobStoreException if the deletion fails
94+
*/
95+
default void delete() throws BlobStoreException
96+
{
97+
getStore().deleteBlob(getPath());
98+
}
99+
}

0 commit comments

Comments
 (0)