Repository: jclouds-labs Updated Branches: refs/heads/master 9cd3cfa50 -> 00500cbf2
JCLOUDS-826: Add H2 provider Project: http://git-wip-us.apache.org/repos/asf/jclouds-labs/repo Commit: http://git-wip-us.apache.org/repos/asf/jclouds-labs/commit/00500cbf Tree: http://git-wip-us.apache.org/repos/asf/jclouds-labs/tree/00500cbf Diff: http://git-wip-us.apache.org/repos/asf/jclouds-labs/diff/00500cbf Branch: refs/heads/master Commit: 00500cbf2c276d8b579f7d245a1e20f88c402141 Parents: 9cd3cfa Author: Roman Coedo <[email protected]> Authored: Sat Jun 27 17:24:59 2015 +0200 Committer: Zack Shoylev <[email protected]> Committed: Thu Aug 6 16:03:24 2015 -0500 ---------------------------------------------------------------------- .gitignore | 1 + h2-jdbc/README.md | 12 +++ h2-jdbc/pom.xml | 105 +++++++++++++++++++ .../jclouds/h2/jdbc/H2JdbcProviderMetadata.java | 67 ++++++++++++ .../config/H2JdbcBlobStoreContextModule.java | 38 +++++++ .../src/main/resources/META-INF/persistence.xml | 43 ++++++++ .../org/jclouds/h2/jdbc/H2JdbcProviderTest.java | 30 ++++++ .../blobstore/H2JdbcBlobIntegrationTest.java | 34 ++++++ .../H2JdbcContainerIntegrationTest.java | 34 ++++++ h2-jdbc/src/test/resources/log4j.properties | 25 +++++ 10 files changed, 389 insertions(+) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/jclouds-labs/blob/00500cbf/.gitignore ---------------------------------------------------------------------- diff --git a/.gitignore b/.gitignore index 8662fa4..0e7058d 100644 --- a/.gitignore +++ b/.gitignore @@ -23,3 +23,4 @@ velocity.log .factorypath Makefile .apt_generated +jclouds-db.* http://git-wip-us.apache.org/repos/asf/jclouds-labs/blob/00500cbf/h2-jdbc/README.md ---------------------------------------------------------------------- diff --git a/h2-jdbc/README.md b/h2-jdbc/README.md new file mode 100644 index 0000000..0c74dfa --- /dev/null +++ b/h2-jdbc/README.md @@ -0,0 +1,12 @@ +## H2 provider ## +h2-jdbc is a storage provider for the h2 embedded database. It is implemented using JPA and Hibernate. + +## Running the tests ## +To run the tests you can use this command +``` +mvn test +``` +You can also run the integration tests with +``` +mvn integration-test +``` http://git-wip-us.apache.org/repos/asf/jclouds-labs/blob/00500cbf/h2-jdbc/pom.xml ---------------------------------------------------------------------- diff --git a/h2-jdbc/pom.xml b/h2-jdbc/pom.xml new file mode 100644 index 0000000..54cb3bf --- /dev/null +++ b/h2-jdbc/pom.xml @@ -0,0 +1,105 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!-- + + Licensed to the Apache Software Foundation (ASF) under one or more + contributor license agreements. See the NOTICE file distributed with + this work for additional information regarding copyright ownership. + The ASF licenses this file to You under the Apache License, Version 2.0 + (the "License"); you may not use this file except in compliance with + the License. You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. + +--> +<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"> + <modelVersion>4.0.0</modelVersion> + <parent> + <groupId>org.apache.jclouds.labs</groupId> + <artifactId>jclouds-labs</artifactId> + <version>2.0.0-SNAPSHOT</version> + </parent> + <artifactId>h2-jdbc</artifactId> + <name>jclouds h2 jdbc provider</name> + <description>jclouds implementation to target h2 databases</description> + <packaging>bundle</packaging> + + <properties> + <jclouds.osgi.export>org.jclouds.jdbc*;version="${project.version}"</jclouds.osgi.export> + <jclouds.osgi.import>org.jclouds*;version="${project.version}",*</jclouds.osgi.import> + </properties> + + <dependencies> + <dependency> + <groupId>org.apache.jclouds.labs</groupId> + <artifactId>jdbc</artifactId> + <version>${project.version}</version> + <type>jar</type> + </dependency> + <dependency> + <groupId>org.apache.jclouds</groupId> + <artifactId>jclouds-blobstore</artifactId> + <version>${project.version}</version> + <type>jar</type> + </dependency> + <dependency> + <groupId>org.apache.jclouds</groupId> + <artifactId>jclouds-core</artifactId> + <version>${project.version}</version> + <type>test-jar</type> + <scope>test</scope> + </dependency> + <dependency> + <groupId>org.apache.jclouds</groupId> + <artifactId>jclouds-blobstore</artifactId> + <version>${project.version}</version> + <type>test-jar</type> + <scope>test</scope> + </dependency> + <dependency> + <groupId>org.apache.jclouds.driver</groupId> + <artifactId>jclouds-log4j</artifactId> + <version>${project.version}</version> + <scope>test</scope> + </dependency> + <dependency> + <groupId>com.google.auto.service</groupId> + <artifactId>auto-service</artifactId> + <scope>provided</scope> + </dependency> + <dependency> + <groupId>com.google.inject.extensions</groupId> + <artifactId>guice-persist</artifactId> + <version>4.0</version> + </dependency> + <dependency> + <groupId>org.hibernate.javax.persistence</groupId> + <artifactId>hibernate-jpa-2.1-api</artifactId> + <version>1.0.0.Final</version> + </dependency> + <dependency> + <groupId>org.hibernate</groupId> + <artifactId>hibernate-entitymanager</artifactId> + <version>4.3.9.Final</version> + </dependency> + <dependency> + <groupId>com.h2database</groupId> + <artifactId>h2</artifactId> + <version>1.4.187</version> + </dependency> + + <!-- Test Dependencies --> + <dependency> + <groupId>org.assertj</groupId> + <artifactId>assertj-core</artifactId> + <scope>test</scope> + </dependency> + </dependencies> + +</project> + http://git-wip-us.apache.org/repos/asf/jclouds-labs/blob/00500cbf/h2-jdbc/src/main/java/org/jclouds/h2/jdbc/H2JdbcProviderMetadata.java ---------------------------------------------------------------------- diff --git a/h2-jdbc/src/main/java/org/jclouds/h2/jdbc/H2JdbcProviderMetadata.java b/h2-jdbc/src/main/java/org/jclouds/h2/jdbc/H2JdbcProviderMetadata.java new file mode 100644 index 0000000..93aa6e7 --- /dev/null +++ b/h2-jdbc/src/main/java/org/jclouds/h2/jdbc/H2JdbcProviderMetadata.java @@ -0,0 +1,67 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.jclouds.h2.jdbc; + +import org.jclouds.h2.jdbc.config.H2JdbcBlobStoreContextModule; +import org.jclouds.jdbc.JdbcApiMetadata; +import org.jclouds.providers.ProviderMetadata; +import org.jclouds.providers.internal.BaseProviderMetadata; + +import com.google.auto.service.AutoService; + +@AutoService(ProviderMetadata.class) +public class H2JdbcProviderMetadata extends BaseProviderMetadata { + + public static Builder builder() { + return new Builder(); + } + + @Override + public Builder toBuilder() { + return builder().fromProviderMetadata(this); + } + + public H2JdbcProviderMetadata() { + super(builder()); + } + + public H2JdbcProviderMetadata(Builder builder) { + super(builder); + } + + public static class Builder extends BaseProviderMetadata.Builder { + protected Builder() { + id("h2-jdbc") + .name("H2 Jdbc") + .apiMetadata(new JdbcApiMetadata() + .toBuilder() + .defaultModule(H2JdbcBlobStoreContextModule.class) + .build()); + } + + @Override + public H2JdbcProviderMetadata build() { + return new H2JdbcProviderMetadata(this); + } + + @Override + public Builder fromProviderMetadata(ProviderMetadata in) { + super.fromProviderMetadata(in); + return this; + } + } +} http://git-wip-us.apache.org/repos/asf/jclouds-labs/blob/00500cbf/h2-jdbc/src/main/java/org/jclouds/h2/jdbc/config/H2JdbcBlobStoreContextModule.java ---------------------------------------------------------------------- diff --git a/h2-jdbc/src/main/java/org/jclouds/h2/jdbc/config/H2JdbcBlobStoreContextModule.java b/h2-jdbc/src/main/java/org/jclouds/h2/jdbc/config/H2JdbcBlobStoreContextModule.java new file mode 100644 index 0000000..30064d0 --- /dev/null +++ b/h2-jdbc/src/main/java/org/jclouds/h2/jdbc/config/H2JdbcBlobStoreContextModule.java @@ -0,0 +1,38 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.jclouds.h2.jdbc.config; + +import java.util.Properties; + +import org.jclouds.jdbc.config.JdbcBlobStoreContextModule; + +import com.google.inject.persist.jpa.JpaPersistModule; + +public class H2JdbcBlobStoreContextModule extends JdbcBlobStoreContextModule { + + private static final String DEFAULT_FILE = "./jclouds-db"; + + protected void configure() { + super.configure(); + + Properties properties = new Properties(); + properties.setProperty("hibernate.connection.url", "jdbc:h2:" + DEFAULT_FILE); + + install(new JpaPersistModule("jclouds-h2").properties(properties)); + } + +} http://git-wip-us.apache.org/repos/asf/jclouds-labs/blob/00500cbf/h2-jdbc/src/main/resources/META-INF/persistence.xml ---------------------------------------------------------------------- diff --git a/h2-jdbc/src/main/resources/META-INF/persistence.xml b/h2-jdbc/src/main/resources/META-INF/persistence.xml new file mode 100644 index 0000000..30a8b35 --- /dev/null +++ b/h2-jdbc/src/main/resources/META-INF/persistence.xml @@ -0,0 +1,43 @@ +<?xml version="1.0" encoding="UTF-8" ?> +<!-- + + Licensed to the Apache Software Foundation (ASF) under one or more + contributor license agreements. See the NOTICE file distributed with + this work for additional information regarding copyright ownership. + The ASF licenses this file to You under the Apache License, Version 2.0 + (the "License"); you may not use this file except in compliance with + the License. You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. + +--> +<persistence xmlns="http://java.sun.com/xml/ns/persistence" + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_1_0.xsd" + version="1.0"> + + <persistence-unit name="jclouds-h2" transaction-type="RESOURCE_LOCAL"> + <provider>org.hibernate.jpa.HibernatePersistenceProvider</provider> + + <class>org.jclouds.jdbc.entity.ContainerEntity</class> + <class>org.jclouds.jdbc.entity.BlobEntity</class> + <class>org.jclouds.jdbc.entity.ChunkEntity</class> + <class>org.jclouds.jdbc.entity.PayloadEntity</class> + <exclude-unlisted-classes>true</exclude-unlisted-classes> + + <properties> + <property name="hibernate.dialect" value="org.hibernate.dialect.H2Dialect" /> + <property name="hibernate.connection.driver_class" value="org.h2.Driver" /> + <property name="hibernate.connection.user" value="sa" /> + <!-- Allow hibernate to generate our schema --> + <property name="hibernate.hbm2ddl.auto" value="create" /> + </properties> + </persistence-unit> + +</persistence> http://git-wip-us.apache.org/repos/asf/jclouds-labs/blob/00500cbf/h2-jdbc/src/test/java/org/jclouds/h2/jdbc/H2JdbcProviderTest.java ---------------------------------------------------------------------- diff --git a/h2-jdbc/src/test/java/org/jclouds/h2/jdbc/H2JdbcProviderTest.java b/h2-jdbc/src/test/java/org/jclouds/h2/jdbc/H2JdbcProviderTest.java new file mode 100644 index 0000000..2330ad7 --- /dev/null +++ b/h2-jdbc/src/test/java/org/jclouds/h2/jdbc/H2JdbcProviderTest.java @@ -0,0 +1,30 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.jclouds.h2.jdbc; + +import org.jclouds.jdbc.JdbcApiMetadata; +import org.jclouds.providers.internal.BaseProviderMetadataTest; +import org.testng.annotations.Test; + +@Test(groups = "unit", testName = "H2JdbcProviderTest") +public class H2JdbcProviderTest extends BaseProviderMetadataTest { + + public H2JdbcProviderTest() { + super(new H2JdbcProviderMetadata(), new JdbcApiMetadata()); + } + +} http://git-wip-us.apache.org/repos/asf/jclouds-labs/blob/00500cbf/h2-jdbc/src/test/java/org/jclouds/h2/jdbc/blobstore/H2JdbcBlobIntegrationTest.java ---------------------------------------------------------------------- diff --git a/h2-jdbc/src/test/java/org/jclouds/h2/jdbc/blobstore/H2JdbcBlobIntegrationTest.java b/h2-jdbc/src/test/java/org/jclouds/h2/jdbc/blobstore/H2JdbcBlobIntegrationTest.java new file mode 100644 index 0000000..e698691 --- /dev/null +++ b/h2-jdbc/src/test/java/org/jclouds/h2/jdbc/blobstore/H2JdbcBlobIntegrationTest.java @@ -0,0 +1,34 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.jclouds.h2.jdbc.blobstore; + +import com.google.common.collect.ImmutableSet; +import com.google.inject.Module; +import org.jclouds.blobstore.integration.internal.BaseBlobIntegrationTest; +import org.testng.annotations.Test; + +@Test(groups = { "integration" }, singleThreaded = true, testName = "blobstore.H2JdbcBlobIntegrationTest") +public class H2JdbcBlobIntegrationTest extends BaseBlobIntegrationTest { + public H2JdbcBlobIntegrationTest() { + provider = "h2-jdbc"; + } + + @Override + protected Iterable<Module> setupModules() { + return ImmutableSet.<Module> of(this.getLoggingModule()); + } +} http://git-wip-us.apache.org/repos/asf/jclouds-labs/blob/00500cbf/h2-jdbc/src/test/java/org/jclouds/h2/jdbc/blobstore/H2JdbcContainerIntegrationTest.java ---------------------------------------------------------------------- diff --git a/h2-jdbc/src/test/java/org/jclouds/h2/jdbc/blobstore/H2JdbcContainerIntegrationTest.java b/h2-jdbc/src/test/java/org/jclouds/h2/jdbc/blobstore/H2JdbcContainerIntegrationTest.java new file mode 100644 index 0000000..98a2052 --- /dev/null +++ b/h2-jdbc/src/test/java/org/jclouds/h2/jdbc/blobstore/H2JdbcContainerIntegrationTest.java @@ -0,0 +1,34 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.jclouds.h2.jdbc.blobstore; + +import com.google.common.collect.ImmutableSet; +import com.google.inject.Module; +import org.jclouds.blobstore.integration.internal.BaseContainerIntegrationTest; +import org.testng.annotations.Test; + +@Test(groups = { "integration" }, singleThreaded = true, testName = "blobstore.H2JdbcContainerIntegrationTest") +public class H2JdbcContainerIntegrationTest extends BaseContainerIntegrationTest { + public H2JdbcContainerIntegrationTest() { + provider = "h2-jdbc"; + } + + @Override + protected Iterable<Module> setupModules() { + return ImmutableSet.<Module> of(this.getLoggingModule()); + } +} http://git-wip-us.apache.org/repos/asf/jclouds-labs/blob/00500cbf/h2-jdbc/src/test/resources/log4j.properties ---------------------------------------------------------------------- diff --git a/h2-jdbc/src/test/resources/log4j.properties b/h2-jdbc/src/test/resources/log4j.properties new file mode 100644 index 0000000..0815baa --- /dev/null +++ b/h2-jdbc/src/test/resources/log4j.properties @@ -0,0 +1,25 @@ +# +# +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. +# +# +log4j.rootLogger=WARN, A1 +log4j.appender.A1=org.apache.log4j.ConsoleAppender +log4j.appender.A1.layout=org.apache.log4j.PatternLayout +log4j.appender.A1.layout.ConversionPattern=%-4r [%t] %-5p %c %x - %m%n +log4j.logger.org.hibernate = ERROR
