Skip to content
This repository was archived by the owner on Jul 25, 2020. It is now read-only.

Commit 00500cb

Browse files
rc-mzzack-shoylev
authored andcommitted
JCLOUDS-826: Add H2 provider
1 parent 9cd3cfa commit 00500cb

File tree

10 files changed

+389
-0
lines changed

10 files changed

+389
-0
lines changed

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -23,3 +23,4 @@ velocity.log
2323
.factorypath
2424
Makefile
2525
.apt_generated
26+
jclouds-db.*

h2-jdbc/README.md

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
## H2 provider ##
2+
h2-jdbc is a storage provider for the h2 embedded database. It is implemented using JPA and Hibernate.
3+
4+
## Running the tests ##
5+
To run the tests you can use this command
6+
```
7+
mvn test
8+
```
9+
You can also run the integration tests with
10+
```
11+
mvn integration-test
12+
```

h2-jdbc/pom.xml

+105
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,105 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!--
3+
4+
Licensed to the Apache Software Foundation (ASF) under one or more
5+
contributor license agreements. See the NOTICE file distributed with
6+
this work for additional information regarding copyright ownership.
7+
The ASF licenses this file to You under the Apache License, Version 2.0
8+
(the "License"); you may not use this file except in compliance with
9+
the License. You may obtain a copy of the License at
10+
11+
http://www.apache.org/licenses/LICENSE-2.0
12+
13+
Unless required by applicable law or agreed to in writing, software
14+
distributed under the License is distributed on an "AS IS" BASIS,
15+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16+
See the License for the specific language governing permissions and
17+
limitations under the License.
18+
19+
-->
20+
<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">
21+
<modelVersion>4.0.0</modelVersion>
22+
<parent>
23+
<groupId>org.apache.jclouds.labs</groupId>
24+
<artifactId>jclouds-labs</artifactId>
25+
<version>2.0.0-SNAPSHOT</version>
26+
</parent>
27+
<artifactId>h2-jdbc</artifactId>
28+
<name>jclouds h2 jdbc provider</name>
29+
<description>jclouds implementation to target h2 databases</description>
30+
<packaging>bundle</packaging>
31+
32+
<properties>
33+
<jclouds.osgi.export>org.jclouds.jdbc*;version="${project.version}"</jclouds.osgi.export>
34+
<jclouds.osgi.import>org.jclouds*;version="${project.version}",*</jclouds.osgi.import>
35+
</properties>
36+
37+
<dependencies>
38+
<dependency>
39+
<groupId>org.apache.jclouds.labs</groupId>
40+
<artifactId>jdbc</artifactId>
41+
<version>${project.version}</version>
42+
<type>jar</type>
43+
</dependency>
44+
<dependency>
45+
<groupId>org.apache.jclouds</groupId>
46+
<artifactId>jclouds-blobstore</artifactId>
47+
<version>${project.version}</version>
48+
<type>jar</type>
49+
</dependency>
50+
<dependency>
51+
<groupId>org.apache.jclouds</groupId>
52+
<artifactId>jclouds-core</artifactId>
53+
<version>${project.version}</version>
54+
<type>test-jar</type>
55+
<scope>test</scope>
56+
</dependency>
57+
<dependency>
58+
<groupId>org.apache.jclouds</groupId>
59+
<artifactId>jclouds-blobstore</artifactId>
60+
<version>${project.version}</version>
61+
<type>test-jar</type>
62+
<scope>test</scope>
63+
</dependency>
64+
<dependency>
65+
<groupId>org.apache.jclouds.driver</groupId>
66+
<artifactId>jclouds-log4j</artifactId>
67+
<version>${project.version}</version>
68+
<scope>test</scope>
69+
</dependency>
70+
<dependency>
71+
<groupId>com.google.auto.service</groupId>
72+
<artifactId>auto-service</artifactId>
73+
<scope>provided</scope>
74+
</dependency>
75+
<dependency>
76+
<groupId>com.google.inject.extensions</groupId>
77+
<artifactId>guice-persist</artifactId>
78+
<version>4.0</version>
79+
</dependency>
80+
<dependency>
81+
<groupId>org.hibernate.javax.persistence</groupId>
82+
<artifactId>hibernate-jpa-2.1-api</artifactId>
83+
<version>1.0.0.Final</version>
84+
</dependency>
85+
<dependency>
86+
<groupId>org.hibernate</groupId>
87+
<artifactId>hibernate-entitymanager</artifactId>
88+
<version>4.3.9.Final</version>
89+
</dependency>
90+
<dependency>
91+
<groupId>com.h2database</groupId>
92+
<artifactId>h2</artifactId>
93+
<version>1.4.187</version>
94+
</dependency>
95+
96+
<!-- Test Dependencies -->
97+
<dependency>
98+
<groupId>org.assertj</groupId>
99+
<artifactId>assertj-core</artifactId>
100+
<scope>test</scope>
101+
</dependency>
102+
</dependencies>
103+
104+
</project>
105+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one or more
3+
* contributor license agreements. See the NOTICE file distributed with
4+
* this work for additional information regarding copyright ownership.
5+
* The ASF licenses this file to You under the Apache License, Version 2.0
6+
* (the "License"); you may not use this file except in compliance with
7+
* the License. You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
package org.jclouds.h2.jdbc;
18+
19+
import org.jclouds.h2.jdbc.config.H2JdbcBlobStoreContextModule;
20+
import org.jclouds.jdbc.JdbcApiMetadata;
21+
import org.jclouds.providers.ProviderMetadata;
22+
import org.jclouds.providers.internal.BaseProviderMetadata;
23+
24+
import com.google.auto.service.AutoService;
25+
26+
@AutoService(ProviderMetadata.class)
27+
public class H2JdbcProviderMetadata extends BaseProviderMetadata {
28+
29+
public static Builder builder() {
30+
return new Builder();
31+
}
32+
33+
@Override
34+
public Builder toBuilder() {
35+
return builder().fromProviderMetadata(this);
36+
}
37+
38+
public H2JdbcProviderMetadata() {
39+
super(builder());
40+
}
41+
42+
public H2JdbcProviderMetadata(Builder builder) {
43+
super(builder);
44+
}
45+
46+
public static class Builder extends BaseProviderMetadata.Builder {
47+
protected Builder() {
48+
id("h2-jdbc")
49+
.name("H2 Jdbc")
50+
.apiMetadata(new JdbcApiMetadata()
51+
.toBuilder()
52+
.defaultModule(H2JdbcBlobStoreContextModule.class)
53+
.build());
54+
}
55+
56+
@Override
57+
public H2JdbcProviderMetadata build() {
58+
return new H2JdbcProviderMetadata(this);
59+
}
60+
61+
@Override
62+
public Builder fromProviderMetadata(ProviderMetadata in) {
63+
super.fromProviderMetadata(in);
64+
return this;
65+
}
66+
}
67+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one or more
3+
* contributor license agreements. See the NOTICE file distributed with
4+
* this work for additional information regarding copyright ownership.
5+
* The ASF licenses this file to You under the Apache License, Version 2.0
6+
* (the "License"); you may not use this file except in compliance with
7+
* the License. You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
package org.jclouds.h2.jdbc.config;
18+
19+
import java.util.Properties;
20+
21+
import org.jclouds.jdbc.config.JdbcBlobStoreContextModule;
22+
23+
import com.google.inject.persist.jpa.JpaPersistModule;
24+
25+
public class H2JdbcBlobStoreContextModule extends JdbcBlobStoreContextModule {
26+
27+
private static final String DEFAULT_FILE = "./jclouds-db";
28+
29+
protected void configure() {
30+
super.configure();
31+
32+
Properties properties = new Properties();
33+
properties.setProperty("hibernate.connection.url", "jdbc:h2:" + DEFAULT_FILE);
34+
35+
install(new JpaPersistModule("jclouds-h2").properties(properties));
36+
}
37+
38+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
<?xml version="1.0" encoding="UTF-8" ?>
2+
<!--
3+
4+
Licensed to the Apache Software Foundation (ASF) under one or more
5+
contributor license agreements. See the NOTICE file distributed with
6+
this work for additional information regarding copyright ownership.
7+
The ASF licenses this file to You under the Apache License, Version 2.0
8+
(the "License"); you may not use this file except in compliance with
9+
the License. You may obtain a copy of the License at
10+
11+
http://www.apache.org/licenses/LICENSE-2.0
12+
13+
Unless required by applicable law or agreed to in writing, software
14+
distributed under the License is distributed on an "AS IS" BASIS,
15+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16+
See the License for the specific language governing permissions and
17+
limitations under the License.
18+
19+
-->
20+
<persistence xmlns="http://java.sun.com/xml/ns/persistence"
21+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
22+
xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_1_0.xsd"
23+
version="1.0">
24+
25+
<persistence-unit name="jclouds-h2" transaction-type="RESOURCE_LOCAL">
26+
<provider>org.hibernate.jpa.HibernatePersistenceProvider</provider>
27+
28+
<class>org.jclouds.jdbc.entity.ContainerEntity</class>
29+
<class>org.jclouds.jdbc.entity.BlobEntity</class>
30+
<class>org.jclouds.jdbc.entity.ChunkEntity</class>
31+
<class>org.jclouds.jdbc.entity.PayloadEntity</class>
32+
<exclude-unlisted-classes>true</exclude-unlisted-classes>
33+
34+
<properties>
35+
<property name="hibernate.dialect" value="org.hibernate.dialect.H2Dialect" />
36+
<property name="hibernate.connection.driver_class" value="org.h2.Driver" />
37+
<property name="hibernate.connection.user" value="sa" />
38+
<!-- Allow hibernate to generate our schema -->
39+
<property name="hibernate.hbm2ddl.auto" value="create" />
40+
</properties>
41+
</persistence-unit>
42+
43+
</persistence>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one or more
3+
* contributor license agreements. See the NOTICE file distributed with
4+
* this work for additional information regarding copyright ownership.
5+
* The ASF licenses this file to You under the Apache License, Version 2.0
6+
* (the "License"); you may not use this file except in compliance with
7+
* the License. You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
package org.jclouds.h2.jdbc;
18+
19+
import org.jclouds.jdbc.JdbcApiMetadata;
20+
import org.jclouds.providers.internal.BaseProviderMetadataTest;
21+
import org.testng.annotations.Test;
22+
23+
@Test(groups = "unit", testName = "H2JdbcProviderTest")
24+
public class H2JdbcProviderTest extends BaseProviderMetadataTest {
25+
26+
public H2JdbcProviderTest() {
27+
super(new H2JdbcProviderMetadata(), new JdbcApiMetadata());
28+
}
29+
30+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one or more
3+
* contributor license agreements. See the NOTICE file distributed with
4+
* this work for additional information regarding copyright ownership.
5+
* The ASF licenses this file to You under the Apache License, Version 2.0
6+
* (the "License"); you may not use this file except in compliance with
7+
* the License. You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
package org.jclouds.h2.jdbc.blobstore;
18+
19+
import com.google.common.collect.ImmutableSet;
20+
import com.google.inject.Module;
21+
import org.jclouds.blobstore.integration.internal.BaseBlobIntegrationTest;
22+
import org.testng.annotations.Test;
23+
24+
@Test(groups = { "integration" }, singleThreaded = true, testName = "blobstore.H2JdbcBlobIntegrationTest")
25+
public class H2JdbcBlobIntegrationTest extends BaseBlobIntegrationTest {
26+
public H2JdbcBlobIntegrationTest() {
27+
provider = "h2-jdbc";
28+
}
29+
30+
@Override
31+
protected Iterable<Module> setupModules() {
32+
return ImmutableSet.<Module> of(this.getLoggingModule());
33+
}
34+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one or more
3+
* contributor license agreements. See the NOTICE file distributed with
4+
* this work for additional information regarding copyright ownership.
5+
* The ASF licenses this file to You under the Apache License, Version 2.0
6+
* (the "License"); you may not use this file except in compliance with
7+
* the License. You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
package org.jclouds.h2.jdbc.blobstore;
18+
19+
import com.google.common.collect.ImmutableSet;
20+
import com.google.inject.Module;
21+
import org.jclouds.blobstore.integration.internal.BaseContainerIntegrationTest;
22+
import org.testng.annotations.Test;
23+
24+
@Test(groups = { "integration" }, singleThreaded = true, testName = "blobstore.H2JdbcContainerIntegrationTest")
25+
public class H2JdbcContainerIntegrationTest extends BaseContainerIntegrationTest {
26+
public H2JdbcContainerIntegrationTest() {
27+
provider = "h2-jdbc";
28+
}
29+
30+
@Override
31+
protected Iterable<Module> setupModules() {
32+
return ImmutableSet.<Module> of(this.getLoggingModule());
33+
}
34+
}

0 commit comments

Comments
 (0)