Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
76 changes: 73 additions & 3 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ jobs:
run: mvn -T 1C formatter:validate

build-deploy:
needs: [ tests, integration-tests-h2, integration-tests-postgresql ]
needs: [ tests, integration-tests-h2, integration-tests-postgresql, integration-tests-mssql ]
runs-on: ${{ matrix.runner }}
strategy:
matrix:
Expand Down Expand Up @@ -207,7 +207,7 @@ jobs:
uses: actions/upload-artifact@v4
if: always()
with:
retention-days: 1
retention-days: 3
name: ${{ env.ARTIFACT_NAME }}
path: tests/tests-integrations/build/reports/tests

Expand Down Expand Up @@ -285,7 +285,77 @@ jobs:
uses: actions/upload-artifact@v4
if: always()
with:
retention-days: 1
retention-days: 3
name: ${{ env.ARTIFACT_NAME }}
path: tests/tests-integrations/build/reports/tests

integration-tests-mssql:
runs-on: ubuntu-latest
env:
MSSQL_PASS: 'mYPass1234!'
services:
mssql:
image: mcr.microsoft.com/mssql/server:2022-CU22-ubuntu-22.04
ports:
- 1433:1433
env:
ACCEPT_EULA: Y
MSSQL_SA_PASSWORD: ${{ env.MSSQL_PASS }}
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0

- name: Cache local Maven repository
uses: actions/cache@v4
with:
path: ~/.m2/repository
key: ${{ runner.os }}-maven-${{ hashFiles('**/pom.xml') }}
restore-keys: ${{ runner.os }}-maven-

- name: Set up JDK Corretto 21
uses: actions/setup-java@v4
with:
distribution: 'corretto'
java-version: '21'
architecture: x64

- name: Install NodeJS
uses: actions/setup-node@v4
with:
node-version: 22.x

- name: Install TypeScript and esbuild
run: npm install -g typescript esbuild

- name: Install ttyd (prebuilt)
run: |
sudo apt update
sudo apt install -y ttyd

- name: Verify ttyd installation
run: ttyd --version

- name: Integration tests
run: mvn clean install -P integration-tests
env:
DIRIGIBLE_DATASOURCE_DEFAULT_DRIVER: 'com.microsoft.sqlserver.jdbc.SQLServerDriver'
DIRIGIBLE_DATASOURCE_DEFAULT_URL: 'jdbc:sqlserver://localhost:1433;databaseName=master;encrypt=true;trustServerCertificate=true'
DIRIGIBLE_DATASOURCE_DEFAULT_USERNAME: 'sa'
DIRIGIBLE_DATASOURCE_DEFAULT_PASSWORD: ${{ env.MSSQL_PASS }}

- name: Generate a random artifact name
if: always()
id: generate_name
run: |
TIMESTAMP=$(date +"%Y%m%d_%H%M%S")
echo "ARTIFACT_NAME=selenide-screenshots-${TIMESTAMP}.zip" >> $GITHUB_ENV

- name: Upload selenide screenshots
uses: actions/upload-artifact@v4
if: always()
with:
retention-days: 3
name: ${{ env.ARTIFACT_NAME }}
path: tests/tests-integrations/build/reports/tests

Expand Down
75 changes: 73 additions & 2 deletions .github/workflows/pull-request.yml
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ jobs:
uses: actions/upload-artifact@v4
if: always()
with:
retention-days: 1
retention-days: 3
name: ${{ env.ARTIFACT_NAME }}
path: tests/tests-integrations/build/reports/tests

Expand Down Expand Up @@ -230,6 +230,77 @@ jobs:
uses: actions/upload-artifact@v4
if: always()
with:
retention-days: 1
retention-days: 3
name: ${{ env.ARTIFACT_NAME }}
path: tests/tests-integrations/build/reports/tests

integration-tests-mssql:
runs-on: ubuntu-latest
env:
MSSQL_PASS: 'mYPass1234!'
services:
mssql:
image: mcr.microsoft.com/mssql/server:2022-CU22-ubuntu-22.04
ports:
- 1433:1433
env:
MSSQL_SA_PASSWORD: ${{ env.MSSQL_PASS }}
ACCEPT_EULA: Y
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0

- name: Cache local Maven repository
uses: actions/cache@v4
with:
path: ~/.m2/repository
key: ${{ runner.os }}-maven-${{ hashFiles('**/pom.xml') }}
restore-keys: ${{ runner.os }}-maven-

- name: Set up JDK Corretto 21
uses: actions/setup-java@v4
with:
distribution: 'corretto'
java-version: '21'
architecture: x64

- name: Install NodeJS
uses: actions/setup-node@v4
with:
node-version: 22.x

- name: Install TypeScript and esbuild
run: npm install -g typescript esbuild

- name: Install ttyd (prebuilt)
run: |
sudo apt update
sudo apt install -y ttyd

- name: Verify ttyd installation
run: ttyd --version

- name: Integration tests
run: mvn clean install -P integration-tests
env:
DIRIGIBLE_DATASOURCE_DEFAULT_DRIVER: 'com.microsoft.sqlserver.jdbc.SQLServerDriver'
DIRIGIBLE_DATASOURCE_DEFAULT_URL: 'jdbc:sqlserver://localhost:1433;databaseName=master;encrypt=true;trustServerCertificate=true'
DIRIGIBLE_DATASOURCE_DEFAULT_USERNAME: 'sa'
DIRIGIBLE_DATASOURCE_DEFAULT_PASSWORD: ${{ env.MSSQL_PASS }}

- name: Generate a random artifact name
if: always()
id: generate_name
run: |
TIMESTAMP=$(date +"%Y%m%d_%H%M%S")
echo "ARTIFACT_NAME=selenide-screenshots-${TIMESTAMP}.zip" >> $GITHUB_ENV

- name: Upload selenide screenshots
uses: actions/upload-artifact@v4
if: always()
with:
retention-days: 3
name: ${{ env.ARTIFACT_NAME }}
path: tests/tests-integrations/build/reports/tests

Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,10 @@ public class DatabaseFacade implements InitializingBean {
private static final Logger logger = LoggerFactory.getLogger(DatabaseFacade.class);

private static final Set<String> DATA_SOURCES_NOT_SUPPORTING_RETURN_GENERATED_KEYS_FEATURE = new HashSet<>();
private static final Set<DatabaseSystem> DATABASES_NOT_SUPPORTING_RETURN_GENERATED_KEYS_FEATURE = Set.of(//
// executeBatch() + getGeneratedKeys() is unsupported in MSSQL,
// possible refactoring with INSERT … OUTPUT INSERTED
DatabaseSystem.MSSQL);

/** The database facade. */
private static DatabaseFacade INSTANCE;
Expand Down Expand Up @@ -390,7 +394,8 @@ public static List<Map<String, Object>> insert(String sql, String parametersJson

return LoggingExecutor.executeWithException(dataSource, () -> {

if (DATA_SOURCES_NOT_SUPPORTING_RETURN_GENERATED_KEYS_FEATURE.contains(dataSource.getName())) {
if (DATA_SOURCES_NOT_SUPPORTING_RETURN_GENERATED_KEYS_FEATURE.contains(dataSource.getName())
|| DATABASES_NOT_SUPPORTING_RETURN_GENERATED_KEYS_FEATURE.contains(dataSource.getDatabaseSystem())) {
logger.debug("RETURN_GENERATED_KEYS not supported for data source [{}]. Will execute insert without this option.",
dataSource);
try (Connection connection = dataSource.getConnection()) {
Expand Down Expand Up @@ -465,7 +470,8 @@ static List<Map<String, Object>> insertMany(String sql, Optional<JsonElement> pa
throws Throwable {
return LoggingExecutor.executeWithException(dataSource, () -> {

if (DATA_SOURCES_NOT_SUPPORTING_RETURN_GENERATED_KEYS_FEATURE.contains(dataSource.getName())) {
if (DATA_SOURCES_NOT_SUPPORTING_RETURN_GENERATED_KEYS_FEATURE.contains(dataSource.getName())
|| DATABASES_NOT_SUPPORTING_RETURN_GENERATED_KEYS_FEATURE.contains(dataSource.getDatabaseSystem())) {
logger.debug("RETURN_GENERATED_KEYS not supported for data source [{}]. Will execute insert without this option.",
dataSource);
insertManyWithoutResult(sql, parameters, dataSource);
Expand Down Expand Up @@ -527,6 +533,9 @@ private static void insertManyWithoutResult(String sql, Optional<JsonElement> pa
} else {
ParametersSetter.setManyIndexedParameters(parameters.get(), new ParameterizedStatement(preparedStatement));
}
} else {
// required for DBs like MSSQL, DBs like H2 and Postgresql doesn't need it
preparedStatement.addBatch();
}
preparedStatement.executeBatch();
connection.commit();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ export const SQLTypes = Object.freeze({
});

export enum DatabaseSystem {
UNKNOWN, DERBY, POSTGRESQL, H2, MARIADB, HANA, SNOWFLAKE, MYSQL, MONGODB, SYBASE
UNKNOWN, DERBY, POSTGRESQL, H2, MARIADB, HANA, SNOWFLAKE, MYSQL, MONGODB, SYBASE, MSSQL
}

// --- Metadata Interfaces ---
Expand Down Expand Up @@ -1201,6 +1201,8 @@ export class Connection {
return DatabaseSystem.HANA;
case "SNOWFLAKE":
return DatabaseSystem.SNOWFLAKE;
case "MSSQL":
return DatabaseSystem.MSSQL;
case "MYSQL":
return DatabaseSystem.MYSQL;
case "MONGODB":
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,24 @@ public enum DatabaseSystem {
// when adding or changing enum values do NOT forget to
// update the JavaScript API in the connection class located at:
// dirigible/modules/src/db/database.ts
UNKNOWN, DERBY, POSTGRESQL, H2, MARIADB, HANA, SNOWFLAKE, MYSQL, MONGODB;
UNKNOWN, DERBY, POSTGRESQL, H2, MARIADB, HANA, SNOWFLAKE, MYSQL, MONGODB, MSSQL;

public boolean isH2() {
return isOfType(H2);
}

public boolean isOfType(DatabaseSystem databaseSystem) {
return this == databaseSystem;
}

public boolean isSnowflake() {
return isOfType(SNOWFLAKE);
}

public boolean isMSSQL() {
return isOfType(MSSQL);
}

public boolean isHANA() {
return isOfType(HANA);
}
Expand Down Expand Up @@ -50,8 +58,4 @@ public boolean isMongoDB() {
public boolean isDerby() {
return isOfType(DERBY);
}

public boolean isOfType(DatabaseSystem databaseSystem) {
return this == databaseSystem;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@ public class DatabaseSystemDeterminer {
DatabaseSystem.MARIADB, "jdbc:mariadb", //
DatabaseSystem.MYSQL, "jdbc:mysql", //
DatabaseSystem.MONGODB, "jdbc:mongodb", //
DatabaseSystem.DERBY, "jdbc:derby"//
DatabaseSystem.DERBY, "jdbc:derby", //
DatabaseSystem.MSSQL, "jdbc:sqlserver"//
);

private static final Map<DatabaseSystem, List<String>> DB_DRIVERS = Map.of(//
Expand All @@ -44,6 +45,7 @@ public class DatabaseSystemDeterminer {
DatabaseSystem.MARIADB, List.of("org.mariadb.jdbc.Driver"), //
DatabaseSystem.MYSQL, List.of("com.mysql.cj.jdbc.Driver"), //
DatabaseSystem.MONGODB, List.of("com.mongodb.jdbc.MongoDriver"), //
DatabaseSystem.MSSQL, List.of("com.microsoft.sqlserver.jdbc.SQLServerDriver"), //
DatabaseSystem.DERBY, List.of("org.apache.derby.jdbc.ClientDriver", "org.apache.derby.jdbc.EmbeddedDriver")//
);

Expand Down Expand Up @@ -89,15 +91,6 @@ private static Optional<DatabaseSystem> determineSystemByJdbcUrl(String jdbcUrl)
.map(Map.Entry::getKey);
}

private static DatabaseSystem determineSystemByDriverClass(String driverClass) {
return DB_DRIVERS.entrySet()
.stream()
.filter(entry -> usedOneOfDrivers(driverClass, entry.getValue()))
.findFirst()
.map(Map.Entry::getKey)
.orElse(DatabaseSystem.UNKNOWN);
}

private static boolean isJdbcUrlStartWithString(String jdbcUrl, String prefix) {
if (StringUtils.isBlank(jdbcUrl)) {
LOGGER.warn("Received blank JDBC URL [{}]", jdbcUrl, jdbcUrl);
Expand All @@ -108,6 +101,15 @@ private static boolean isJdbcUrlStartWithString(String jdbcUrl, String prefix) {
.startsWith(prefix);
}

private static DatabaseSystem determineSystemByDriverClass(String driverClass) {
return DB_DRIVERS.entrySet()
.stream()
.filter(entry -> usedOneOfDrivers(driverClass, entry.getValue()))
.findFirst()
.map(Map.Entry::getKey)
.orElse(DatabaseSystem.UNKNOWN);
}

private static boolean usedOneOfDrivers(String driverClass, List<String> drivers) {
String trimmedDriverClassName = safelyTrim(driverClass);
return drivers.stream()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,28 @@ class DatabaseSystemDeterminerTest {
@InjectMocks
private DatabaseSystemDeterminer databaseSystemDeterminer;

@Test
void testDetermineMSSQL_withUrl() {
testDetermine_withUrl("jdbc:sqlserver://localhost:1433;databaseName=master", DatabaseSystem.MSSQL);
}

private void testDetermine_withUrl(String jdbcUrl, DatabaseSystem expectedType) {
DatabaseSystem result = DatabaseSystemDeterminer.determine(jdbcUrl, null);

assertEquals(expectedType, result);
}

@Test
void testDetermineMSSQL_withDriverUrl() {
testDetermine_withDriver("com.microsoft.sqlserver.jdbc.SQLServerDriver", DatabaseSystem.MSSQL);
}

private void testDetermine_withDriver(String driverClass, DatabaseSystem expectedType) {
DatabaseSystem result = DatabaseSystemDeterminer.determine(null, driverClass);

assertEquals(expectedType, result);
}

@Test
void testDetermineDerby_withUrl() {
testDetermine_withUrl("jdbc:derby://localhost:1527/databaseName;create=true", DatabaseSystem.DERBY);
Expand Down Expand Up @@ -117,16 +139,4 @@ void testDetermineUnknown_withDriver() {
testDetermine_withDriver("com.unknown.Driver", DatabaseSystem.UNKNOWN);
}

private void testDetermine_withUrl(String jdbcUrl, DatabaseSystem expectedType) {
DatabaseSystem result = DatabaseSystemDeterminer.determine(jdbcUrl, null);

assertEquals(expectedType, result);
}

private void testDetermine_withDriver(String driverClass, DatabaseSystem expectedType) {
DatabaseSystem result = DatabaseSystemDeterminer.determine(null, driverClass);

assertEquals(expectedType, result);
}

}
6 changes: 5 additions & 1 deletion components/data/data-core/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,11 @@
<groupId>org.eclipse.dirigible</groupId>
<artifactId>dirigible-database-sql-postgres</artifactId>
</dependency>

<dependency>
<groupId>org.eclipse.dirigible</groupId>
<artifactId>dirigible-database-sql-mssql</artifactId>
</dependency>

<!-- External -->
<dependency>
<groupId>com.github.jsqlparser</groupId>
Expand Down
Loading
Loading