mirror of
https://gitee.com/devlive-community/datacap.git
synced 2024-11-29 18:48:23 +08:00
plugin: Add sqlserver
This commit is contained in:
parent
83ef4aaa75
commit
2dfee9b40d
@ -75,6 +75,9 @@ Here are some of the major database solutions that are supported:
|
||||
</a>
|
||||
<a href="https://www.h2database.com/html/main.html" target="_blank">
|
||||
<img src="assets/plugin/h2.png" alt="H2" height="50" />
|
||||
</a>
|
||||
<a href="https://www.microsoft.com/sql-server" target="_blank">
|
||||
<img src="assets/plugin/sqlserver.svg" alt="SqlServer" height="60" />
|
||||
</a>
|
||||
</p>
|
||||
|
||||
|
1
assets/plugin/sqlserver.svg
Normal file
1
assets/plugin/sqlserver.svg
Normal file
File diff suppressed because one or more lines are too long
After Width: | Height: | Size: 24 KiB |
@ -32,5 +32,6 @@
|
||||
<module>monetdb</module>
|
||||
<module>phoenix</module>
|
||||
<module>h2</module>
|
||||
<module>sqlserver</module>
|
||||
</modules>
|
||||
</project>
|
61
plugin/jdbc/sqlserver/pom.xml
Normal file
61
plugin/jdbc/sqlserver/pom.xml
Normal file
@ -0,0 +1,61 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<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/xsd/maven-4.0.0.xsd">
|
||||
<parent>
|
||||
<artifactId>datacap-plugin-jdbc</artifactId>
|
||||
<groupId>io.edurt.datacap.plugin.jdbc</groupId>
|
||||
<version>1.1.0.20221115-SNAPSHOT</version>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
<artifactId>datacap-plugin-jdbc-sqlserver</artifactId>
|
||||
<name>DataCap plugin for jdbc (SqlServer)</name>
|
||||
|
||||
<properties>
|
||||
<sqlserver.version>11.2.1.jre8</sqlserver.version>
|
||||
<plugin.name>jdbc-sqlserver</plugin.name>
|
||||
</properties>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>io.edurt.datacap</groupId>
|
||||
<artifactId>datacap-spi</artifactId>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>commons-beanutils</groupId>
|
||||
<artifactId>commons-beanutils</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.microsoft.sqlserver</groupId>
|
||||
<artifactId>mssql-jdbc</artifactId>
|
||||
<version>${sqlserver.version}</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<artifactId>maven-assembly-plugin</artifactId>
|
||||
<version>${assembly-plugin.version}</version>
|
||||
<configuration>
|
||||
<finalName>${plugin.name}</finalName>
|
||||
<descriptors>
|
||||
<descriptor>../../../configure/assembly/assembly-plugin.xml</descriptor>
|
||||
</descriptors>
|
||||
<outputDirectory>../../../dist/plugins/${plugin.name}</outputDirectory>
|
||||
</configuration>
|
||||
<executions>
|
||||
<execution>
|
||||
<id>make-assembly</id>
|
||||
<phase>package</phase>
|
||||
<goals>
|
||||
<goal>single</goal>
|
||||
</goals>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
</project>
|
@ -0,0 +1,13 @@
|
||||
package io.edurt.datacap.plugin.jdbc.sqlserver;
|
||||
|
||||
import io.edurt.datacap.spi.adapter.JdbcAdapter;
|
||||
import io.edurt.datacap.spi.connection.JdbcConnection;
|
||||
|
||||
public class SqlServerAdapter
|
||||
extends JdbcAdapter
|
||||
{
|
||||
public SqlServerAdapter(JdbcConnection jdbcConnection)
|
||||
{
|
||||
super(jdbcConnection);
|
||||
}
|
||||
}
|
@ -0,0 +1,77 @@
|
||||
package io.edurt.datacap.plugin.jdbc.sqlserver;
|
||||
|
||||
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 SqlServerPlugin
|
||||
implements Plugin
|
||||
{
|
||||
private JdbcConfigure jdbcConfigure;
|
||||
private JdbcConnection connection;
|
||||
private Response response;
|
||||
|
||||
@Override
|
||||
public String name()
|
||||
{
|
||||
return "SqlServer";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String description()
|
||||
{
|
||||
return "Integrate Microsoft SqlServer 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("com.microsoft.sqlserver.jdbc.SQLServerDriver");
|
||||
this.jdbcConfigure.setJdbcType("sqlserver");
|
||||
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 sqlserver plugin logic started");
|
||||
this.response = this.connection.getResponse();
|
||||
JdbcAdapter processor = new SqlServerAdapter(this.connection);
|
||||
this.response = processor.handlerExecute(content);
|
||||
log.info("Execute sqlserver plugin logic end");
|
||||
}
|
||||
return this.response;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void destroy()
|
||||
{
|
||||
if (ObjectUtils.isNotEmpty(this.connection)) {
|
||||
this.connection.destroy();
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,38 @@
|
||||
package io.edurt.datacap.plugin.jdbc.sqlserver;
|
||||
|
||||
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 SqlServerPluginModule
|
||||
extends AbstractPluginModule
|
||||
implements PluginModule
|
||||
{
|
||||
@Override
|
||||
public String getName()
|
||||
{
|
||||
return "SqlServer";
|
||||
}
|
||||
|
||||
@Override
|
||||
public PluginType getType()
|
||||
{
|
||||
return PluginType.SOURCE;
|
||||
}
|
||||
|
||||
@Override
|
||||
public AbstractPluginModule get()
|
||||
{
|
||||
return this;
|
||||
}
|
||||
|
||||
protected void configure()
|
||||
{
|
||||
Multibinder<String> module = Multibinder.newSetBinder(this.binder(), String.class);
|
||||
module.addBinding().toInstance(this.getClass().getSimpleName());
|
||||
Multibinder<Plugin> plugin = Multibinder.newSetBinder(this.binder(), Plugin.class);
|
||||
plugin.addBinding().to(SqlServerPlugin.class);
|
||||
}
|
||||
}
|
@ -0,0 +1 @@
|
||||
io.edurt.datacap.plugin.jdbc.sqlserver.SqlServerPluginModule
|
@ -0,0 +1,30 @@
|
||||
package io.edurt.datacap.plugin.jdbc.sqlserver;
|
||||
|
||||
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 SqlServerPluginModuleTest
|
||||
{
|
||||
private Injector injector;
|
||||
|
||||
@Before
|
||||
public void before()
|
||||
{
|
||||
this.injector = Guice.createInjector(new SqlServerPluginModule());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test()
|
||||
{
|
||||
Set<Plugin> plugins = injector.getInstance(Key.get(new TypeLiteral<Set<Plugin>>() {}));
|
||||
Assert.assertTrue(plugins.size() > 0);
|
||||
}
|
||||
}
|
@ -0,0 +1,44 @@
|
||||
package io.edurt.datacap.plugin.jdbc.sqlserver;
|
||||
|
||||
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 SqlServerPluginTest
|
||||
{
|
||||
private Injector injector;
|
||||
private Configure configure;
|
||||
|
||||
@Before
|
||||
public void before()
|
||||
{
|
||||
injector = Guice.createInjector(new SqlServerPluginModule());
|
||||
configure = new Configure();
|
||||
configure.setHost("127.0.0.1");
|
||||
configure.setPort(1433);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test()
|
||||
{
|
||||
Set<Plugin> plugins = injector.getInstance(Key.get(new TypeLiteral<Set<Plugin>>() {}));
|
||||
Optional<Plugin> pluginOptional = plugins.stream()
|
||||
.filter(v -> v.name().equalsIgnoreCase("SqlServer"))
|
||||
.findFirst();
|
||||
if (pluginOptional.isPresent()) {
|
||||
Plugin plugin = pluginOptional.get();
|
||||
plugin.connect(configure);
|
||||
Assert.assertNotNull(plugin.execute(plugin.validator()).getConnection());
|
||||
plugin.destroy();
|
||||
}
|
||||
}
|
||||
}
|
@ -179,6 +179,11 @@
|
||||
<artifactId>datacap-plugin-jdbc-h2</artifactId>
|
||||
<version>${project.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>io.edurt.datacap.plugin.jdbc</groupId>
|
||||
<artifactId>datacap-plugin-jdbc-sqlserver</artifactId>
|
||||
<version>${project.version}</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
|
@ -11,6 +11,7 @@ import io.edurt.datacap.server.repository.SourceRepository;
|
||||
import io.edurt.datacap.server.service.ExecuteService;
|
||||
import io.edurt.datacap.spi.Plugin;
|
||||
import io.edurt.datacap.spi.model.Configure;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.Optional;
|
||||
@ -49,7 +50,8 @@ public class ExecuteServiceImpl
|
||||
_configure.setPort(entity.getPort());
|
||||
_configure.setUsername(Optional.ofNullable(entity.getUsername()));
|
||||
_configure.setPassword(Optional.ofNullable(entity.getPassword()));
|
||||
_configure.setDatabase(Optional.ofNullable(entity.getDatabase()));
|
||||
Optional<String> _database = StringUtils.isNotEmpty(entity.getDatabase()) ? Optional.ofNullable(entity.getDatabase()) : Optional.empty();
|
||||
_configure.setDatabase(_database);
|
||||
_configure.setSsl(Optional.ofNullable(entity.getSsl()));
|
||||
_configure.setEnv(Optional.ofNullable(entity.getConfigures()));
|
||||
_configure.setFormat(configure.getFormat());
|
||||
|
@ -21,6 +21,7 @@ import io.edurt.datacap.spi.FormatType;
|
||||
import io.edurt.datacap.spi.Plugin;
|
||||
import io.edurt.datacap.spi.PluginType;
|
||||
import io.edurt.datacap.spi.model.Configure;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.springframework.data.domain.Pageable;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
@ -81,7 +82,8 @@ public class SourceServiceImpl
|
||||
_configure.setPort(configure.getPort());
|
||||
_configure.setUsername(Optional.ofNullable(configure.getUsername()));
|
||||
_configure.setPassword(Optional.ofNullable(configure.getPassword()));
|
||||
_configure.setDatabase(Optional.ofNullable(configure.getDatabase()));
|
||||
Optional<String> _database = StringUtils.isNotEmpty(configure.getDatabase()) ? Optional.ofNullable(configure.getDatabase()) : Optional.empty();
|
||||
_configure.setDatabase(_database);
|
||||
_configure.setEnv(Optional.ofNullable(configure.getConfigures()));
|
||||
_configure.setSsl(Optional.ofNullable(configure.getSsl()));
|
||||
_configure.setFormat(FormatType.JSON);
|
||||
|
Loading…
Reference in New Issue
Block a user