Skip to content

Commit

Permalink
添加 SQLServer 支持 (#100)
Browse files Browse the repository at this point in the history
  • Loading branch information
scx567888 authored Oct 14, 2024
1 parent ed6ff3f commit e122cdd
Show file tree
Hide file tree
Showing 6 changed files with 145 additions and 0 deletions.
9 changes: 9 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@
<module>scx-scheduling</module>
<module>scx-net</module>
<module>scx-io</module>
<module>scx-jdbc-sql-server</module>
</modules>

<build>
Expand Down Expand Up @@ -190,6 +191,13 @@
<version>${mysql-connector-j.version}</version>
</dependency>

<!-- sql server 驱动 -->
<dependency>
<groupId>com.microsoft.sqlserver</groupId>
<artifactId>mssql-jdbc</artifactId>
<version>${mssql-jdbc.version}</version>
</dependency>

<!-- sqlite 驱动 -->
<dependency>
<groupId>org.xerial</groupId>
Expand Down Expand Up @@ -234,6 +242,7 @@
<jasypt.version>1.9.3</jasypt.version>
<cron-utils.version>9.2.1</cron-utils.version>
<mysql-connector-j.version>9.0.0</mysql-connector-j.version>
<mssql-jdbc.version>12.8.1.jre11</mssql-jdbc.version>
<sqlite-jdbc.version>3.46.1.3</sqlite-jdbc.version>
<slf4j.version>2.0.16</slf4j.version>
<log4j2.version>2.24.1</log4j2.version>
Expand Down
52 changes: 52 additions & 0 deletions scx-jdbc-sql-server/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://maven.apache.org/POM/4.0.0"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<parent>
<groupId>cool.scx</groupId>
<artifactId>scx</artifactId>
<version>3.1.7</version>
</parent>

<artifactId>scx-jdbc-sql-server</artifactId>
<packaging>jar</packaging>

<name>SCX JDBC SQL Server</name>
<url>https://github.com/scx567888/scx</url>
<description>
SCX JDBC SQL Server
</description>

<dependencies>

<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>scx-jdbc</artifactId>
<version>${project.version}</version>
</dependency>

<!-- sql server 驱动 -->
<dependency>
<groupId>com.microsoft.sqlserver</groupId>
<artifactId>mssql-jdbc</artifactId>
</dependency>

<!-- ****************** 以下为测试依赖 ****************** -->

<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>scx-logging</artifactId>
<version>${project.version}</version>
<scope>test</scope>
</dependency>

<dependency>
<groupId>org.testng</groupId>
<artifactId>testng</artifactId>
<scope>test</scope>
</dependency>

</dependencies>

</project>
Original file line number Diff line number Diff line change
@@ -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 "";
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
cool.scx.jdbc.sql_server.SQLServerDialect
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package cool.scx.jdbc.sql_server.test;

public class Test {

public static void main(String[] args) {

}

}
Empty file.

0 comments on commit e122cdd

Please sign in to comment.