diff --git a/README.md b/README.md index b2e313ea..a9f49fcd 100644 --- a/README.md +++ b/README.md @@ -80,6 +80,9 @@ Here are some of the major database solutions that are supported:   Phoenix +   + + H2

diff --git a/assets/plugin/h2.png b/assets/plugin/h2.png new file mode 100644 index 00000000..0a747d36 Binary files /dev/null and b/assets/plugin/h2.png differ diff --git a/plugin/jdbc/h2/pom.xml b/plugin/jdbc/h2/pom.xml new file mode 100644 index 00000000..c752ac14 --- /dev/null +++ b/plugin/jdbc/h2/pom.xml @@ -0,0 +1,61 @@ + + + + datacap-plugin-jdbc + io.edurt.datacap.plugin.jdbc + 1.1.0.20221115-SNAPSHOT + + 4.0.0 + + datacap-plugin-jdbc-h2 + DataCap plugin for jdbc (H2) + + + 2.1.214 + jdbc-h2 + + + + + io.edurt.datacap + datacap-spi + provided + + + commons-beanutils + commons-beanutils + + + com.h2database + h2 + ${h2.version} + + + + + + + maven-assembly-plugin + ${assembly-plugin.version} + + ${plugin.name} + + ../../../configure/assembly/assembly-plugin.xml + + ../../../dist/plugins/${plugin.name} + + + + make-assembly + package + + single + + + + + + + \ No newline at end of file diff --git a/plugin/jdbc/h2/src/main/java/io/edurt/datacap/plugin/jdbc/h2/H2Adapter.java b/plugin/jdbc/h2/src/main/java/io/edurt/datacap/plugin/jdbc/h2/H2Adapter.java new file mode 100644 index 00000000..06334ad3 --- /dev/null +++ b/plugin/jdbc/h2/src/main/java/io/edurt/datacap/plugin/jdbc/h2/H2Adapter.java @@ -0,0 +1,13 @@ +package io.edurt.datacap.plugin.jdbc.h2; + +import io.edurt.datacap.spi.adapter.JdbcAdapter; +import io.edurt.datacap.spi.connection.JdbcConnection; + +public class H2Adapter + extends JdbcAdapter +{ + public H2Adapter(JdbcConnection jdbcConnection) + { + super(jdbcConnection); + } +} diff --git a/plugin/jdbc/h2/src/main/java/io/edurt/datacap/plugin/jdbc/h2/H2Plugin.java b/plugin/jdbc/h2/src/main/java/io/edurt/datacap/plugin/jdbc/h2/H2Plugin.java new file mode 100644 index 00000000..b9317e5a --- /dev/null +++ b/plugin/jdbc/h2/src/main/java/io/edurt/datacap/plugin/jdbc/h2/H2Plugin.java @@ -0,0 +1,77 @@ +package io.edurt.datacap.plugin.jdbc.h2; + +import io.edurt.datacap.spi.Plugin; +import io.edurt.datacap.spi.PluginType; +import io.edurt.datacap.spi.adapter.JdbcAdapter; +import io.edurt.datacap.spi.connection.JdbcConfigure; +import io.edurt.datacap.spi.connection.JdbcConnection; +import io.edurt.datacap.spi.model.Configure; +import io.edurt.datacap.spi.model.Response; +import lombok.extern.slf4j.Slf4j; +import org.apache.commons.beanutils.BeanUtils; +import org.apache.commons.lang3.ObjectUtils; + +@Slf4j +public class H2Plugin + implements Plugin +{ + private JdbcConfigure jdbcConfigure; + private JdbcConnection connection; + private Response response; + + @Override + public String name() + { + return "H2"; + } + + @Override + public String description() + { + return "Integrate H2 data sources"; + } + + @Override + public PluginType type() + { + return PluginType.SOURCE; + } + + @Override + public void connect(Configure configure) + { + try { + this.response = new Response(); + this.jdbcConfigure = new JdbcConfigure(); + BeanUtils.copyProperties(this.jdbcConfigure, configure); + this.jdbcConfigure.setJdbcDriver("org.h2.Driver"); + this.jdbcConfigure.setJdbcType("h2:tcp"); + this.connection = new JdbcConnection(this.jdbcConfigure, this.response); + } + catch (Exception ex) { + this.response.setIsConnected(Boolean.FALSE); + this.response.setMessage(ex.getMessage()); + } + } + + @Override + public Response execute(String content) + { + if (ObjectUtils.isNotEmpty(this.connection)) { + log.info("Execute h2 plugin logic started"); + this.response = this.connection.getResponse(); + JdbcAdapter processor = new H2Adapter(this.connection); + this.response = processor.handlerExecute(content); + log.info("Execute h2 plugin logic end"); + } + return this.response; + } + + @Override + public void destroy() + { + if (ObjectUtils.isNotEmpty(this.connection)) { + this.connection.destroy(); + } + } +} diff --git a/plugin/jdbc/h2/src/main/java/io/edurt/datacap/plugin/jdbc/h2/H2PluginModule.java b/plugin/jdbc/h2/src/main/java/io/edurt/datacap/plugin/jdbc/h2/H2PluginModule.java new file mode 100644 index 00000000..12065b7f --- /dev/null +++ b/plugin/jdbc/h2/src/main/java/io/edurt/datacap/plugin/jdbc/h2/H2PluginModule.java @@ -0,0 +1,38 @@ +package io.edurt.datacap.plugin.jdbc.h2; + +import com.google.inject.multibindings.Multibinder; +import io.edurt.datacap.spi.AbstractPluginModule; +import io.edurt.datacap.spi.Plugin; +import io.edurt.datacap.spi.PluginModule; +import io.edurt.datacap.spi.PluginType; + +public class H2PluginModule + extends AbstractPluginModule + implements PluginModule +{ + @Override + public String getName() + { + return "H2"; + } + + @Override + public PluginType getType() + { + return PluginType.SOURCE; + } + + @Override + public AbstractPluginModule get() + { + return this; + } + + protected void configure() + { + Multibinder module = Multibinder.newSetBinder(this.binder(), String.class); + module.addBinding().toInstance(this.getClass().getSimpleName()); + Multibinder plugin = Multibinder.newSetBinder(this.binder(), Plugin.class); + plugin.addBinding().to(H2Plugin.class); + } +} diff --git a/plugin/jdbc/h2/src/main/resources/META-INF/services/io.edurt.datacap.spi.PluginModule b/plugin/jdbc/h2/src/main/resources/META-INF/services/io.edurt.datacap.spi.PluginModule new file mode 100644 index 00000000..d20140a1 --- /dev/null +++ b/plugin/jdbc/h2/src/main/resources/META-INF/services/io.edurt.datacap.spi.PluginModule @@ -0,0 +1 @@ +io.edurt.datacap.plugin.jdbc.h2.H2PluginModule diff --git a/plugin/jdbc/h2/src/test/java/io/edurt/datacap/plugin/jdbc/h2/H2PluginModuleTest.java b/plugin/jdbc/h2/src/test/java/io/edurt/datacap/plugin/jdbc/h2/H2PluginModuleTest.java new file mode 100644 index 00000000..69990feb --- /dev/null +++ b/plugin/jdbc/h2/src/test/java/io/edurt/datacap/plugin/jdbc/h2/H2PluginModuleTest.java @@ -0,0 +1,30 @@ +package io.edurt.datacap.plugin.jdbc.h2; + +import com.google.inject.Guice; +import com.google.inject.Injector; +import com.google.inject.Key; +import com.google.inject.TypeLiteral; +import io.edurt.datacap.spi.Plugin; +import org.junit.Assert; +import org.junit.Before; +import org.junit.Test; + +import java.util.Set; + +public class H2PluginModuleTest +{ + private Injector injector; + + @Before + public void before() + { + this.injector = Guice.createInjector(new H2PluginModule()); + } + + @Test + public void test() + { + Set plugins = injector.getInstance(Key.get(new TypeLiteral>() {})); + Assert.assertTrue(plugins.size() > 0); + } +} diff --git a/plugin/jdbc/h2/src/test/java/io/edurt/datacap/plugin/jdbc/h2/H2PluginTest.java b/plugin/jdbc/h2/src/test/java/io/edurt/datacap/plugin/jdbc/h2/H2PluginTest.java new file mode 100644 index 00000000..d82bb999 --- /dev/null +++ b/plugin/jdbc/h2/src/test/java/io/edurt/datacap/plugin/jdbc/h2/H2PluginTest.java @@ -0,0 +1,44 @@ +package io.edurt.datacap.plugin.jdbc.h2; + +import com.google.inject.Guice; +import com.google.inject.Injector; +import com.google.inject.Key; +import com.google.inject.TypeLiteral; +import io.edurt.datacap.spi.Plugin; +import io.edurt.datacap.spi.model.Configure; +import org.junit.Assert; +import org.junit.Before; +import org.junit.Test; + +import java.util.Optional; +import java.util.Set; + +public class H2PluginTest +{ + private Injector injector; + private Configure configure; + + @Before + public void before() + { + injector = Guice.createInjector(new H2PluginModule()); + configure = new Configure(); + configure.setHost("127.0.0.1"); + configure.setPort(9092); + } + + @Test + public void test() + { + Set plugins = injector.getInstance(Key.get(new TypeLiteral>() {})); + Optional pluginOptional = plugins.stream() + .filter(v -> v.name().equalsIgnoreCase("H2")) + .findFirst(); + if (pluginOptional.isPresent()) { + Plugin plugin = pluginOptional.get(); + plugin.connect(configure); + Assert.assertNotNull(plugin.execute(plugin.validator()).getConnection()); + plugin.destroy(); + } + } +} diff --git a/plugin/jdbc/pom.xml b/plugin/jdbc/pom.xml index 512cf8a6..a83417d7 100644 --- a/plugin/jdbc/pom.xml +++ b/plugin/jdbc/pom.xml @@ -31,5 +31,6 @@ dremio monetdb phoenix + h2 \ No newline at end of file diff --git a/server/pom.xml b/server/pom.xml index fa609d7f..8c0fd535 100644 --- a/server/pom.xml +++ b/server/pom.xml @@ -174,6 +174,11 @@ datacap-plugin-jdbc-phoenix ${project.version} + + io.edurt.datacap.plugin.jdbc + datacap-plugin-jdbc-h2 + ${project.version} +