From e122cdd29e4e6ce04e51e84e2d809a3183e86b78 Mon Sep 17 00:00:00 2001 From: scx567888 Date: Mon, 14 Oct 2024 16:54:11 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=20SQLServer=20=E6=94=AF?= =?UTF-8?q?=E6=8C=81=20(#100)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pom.xml | 9 +++ scx-jdbc-sql-server/pom.xml | 52 +++++++++++++ .../scx/jdbc/sql_server/SQLServerDialect.java | 74 +++++++++++++++++++ .../services/cool.scx.jdbc.dialect.Dialect | 1 + .../cool/scx/jdbc/sql_server/test/Test.java | 9 +++ .../src/test/resources/.gitkeep | 0 6 files changed, 145 insertions(+) create mode 100644 scx-jdbc-sql-server/pom.xml create mode 100644 scx-jdbc-sql-server/src/main/java/cool/scx/jdbc/sql_server/SQLServerDialect.java create mode 100644 scx-jdbc-sql-server/src/main/resources/META-INF/services/cool.scx.jdbc.dialect.Dialect create mode 100644 scx-jdbc-sql-server/src/test/java/cool/scx/jdbc/sql_server/test/Test.java create mode 100644 scx-jdbc-sql-server/src/test/resources/.gitkeep diff --git a/pom.xml b/pom.xml index edbbaa9e..47d7b61b 100644 --- a/pom.xml +++ b/pom.xml @@ -63,6 +63,7 @@ scx-scheduling scx-net scx-io + scx-jdbc-sql-server @@ -190,6 +191,13 @@ ${mysql-connector-j.version} + + + com.microsoft.sqlserver + mssql-jdbc + ${mssql-jdbc.version} + + org.xerial @@ -234,6 +242,7 @@ 1.9.3 9.2.1 9.0.0 + 12.8.1.jre11 3.46.1.3 2.0.16 2.24.1 diff --git a/scx-jdbc-sql-server/pom.xml b/scx-jdbc-sql-server/pom.xml new file mode 100644 index 00000000..a3acc109 --- /dev/null +++ b/scx-jdbc-sql-server/pom.xml @@ -0,0 +1,52 @@ + + + 4.0.0 + + + cool.scx + scx + 3.1.7 + + + scx-jdbc-sql-server + jar + + SCX JDBC SQL Server + https://github.com/scx567888/scx + + SCX JDBC SQL Server + + + + + + ${project.groupId} + scx-jdbc + ${project.version} + + + + + com.microsoft.sqlserver + mssql-jdbc + + + + + + ${project.groupId} + scx-logging + ${project.version} + test + + + + org.testng + testng + test + + + + + diff --git a/scx-jdbc-sql-server/src/main/java/cool/scx/jdbc/sql_server/SQLServerDialect.java b/scx-jdbc-sql-server/src/main/java/cool/scx/jdbc/sql_server/SQLServerDialect.java new file mode 100644 index 00000000..8377e954 --- /dev/null +++ b/scx-jdbc-sql-server/src/main/java/cool/scx/jdbc/sql_server/SQLServerDialect.java @@ -0,0 +1,74 @@ +package cool.scx.jdbc.sql_server; + +import com.microsoft.sqlserver.jdbc.SQLServerDataSource; +import com.microsoft.sqlserver.jdbc.SQLServerDriver; +import cool.scx.jdbc.JDBCType; +import cool.scx.jdbc.dialect.DDLBuilder; +import cool.scx.jdbc.dialect.Dialect; + +import javax.sql.DataSource; +import java.sql.Driver; +import java.sql.SQLException; +import java.sql.Statement; + +public class SQLServerDialect extends Dialect { + + private static final SQLServerDriver DRIVER = initDRIVER(); + + private static SQLServerDriver initDRIVER() { + return new SQLServerDriver(); + } + + @Override + public boolean canHandle(String url) { + try { + return DRIVER.acceptsURL(url); + } catch (SQLException e) { + return false; + } + } + + @Override + public boolean canHandle(DataSource dataSource) { + try { + return dataSource instanceof SQLServerDataSource || dataSource.isWrapperFor(SQLServerDataSource.class); + } catch (SQLException e) { + return false; + } + } + + @Override + public boolean canHandle(Driver driver) { + return driver instanceof SQLServerDriver; + } + + @Override + public String getFinalSQL(Statement statement) { + return ""; + } + + @Override + public DDLBuilder ddlBuilder() { + return null; + } + + @Override + public DataSource createDataSource(String url, String username, String password, String[] parameters) { + var sqlServerDataSource = new SQLServerDataSource(); + sqlServerDataSource.setURL(url); + sqlServerDataSource.setUser(username); + sqlServerDataSource.setPassword(password); + return sqlServerDataSource; + } + + @Override + public JDBCType dialectDataTypeToJDBCType(String dialectDataType) { + return null; + } + + @Override + public String jdbcTypeToDialectDataType(JDBCType jdbcType) { + return ""; + } + +} diff --git a/scx-jdbc-sql-server/src/main/resources/META-INF/services/cool.scx.jdbc.dialect.Dialect b/scx-jdbc-sql-server/src/main/resources/META-INF/services/cool.scx.jdbc.dialect.Dialect new file mode 100644 index 00000000..f68c6632 --- /dev/null +++ b/scx-jdbc-sql-server/src/main/resources/META-INF/services/cool.scx.jdbc.dialect.Dialect @@ -0,0 +1 @@ +cool.scx.jdbc.sql_server.SQLServerDialect diff --git a/scx-jdbc-sql-server/src/test/java/cool/scx/jdbc/sql_server/test/Test.java b/scx-jdbc-sql-server/src/test/java/cool/scx/jdbc/sql_server/test/Test.java new file mode 100644 index 00000000..b8770aba --- /dev/null +++ b/scx-jdbc-sql-server/src/test/java/cool/scx/jdbc/sql_server/test/Test.java @@ -0,0 +1,9 @@ +package cool.scx.jdbc.sql_server.test; + +public class Test { + + public static void main(String[] args) { + + } + +} diff --git a/scx-jdbc-sql-server/src/test/resources/.gitkeep b/scx-jdbc-sql-server/src/test/resources/.gitkeep new file mode 100644 index 00000000..e69de29b