Skip to content

Commit

Permalink
DataSource refactoring + Snowflake fixes (#4204)
Browse files Browse the repository at this point in the history
* more cleanup

Signed-off-by: Iliyan Velichkov <[email protected]>

* rollback

Signed-off-by: Iliyan Velichkov <[email protected]>

* set connection test query

Signed-off-by: Iliyan Velichkov <[email protected]>

* remove explicit token property loading

Signed-off-by: Iliyan Velichkov <[email protected]>

* add DatabaseType to dirigible data sources

Signed-off-by: Iliyan Velichkov <[email protected]>

* rename DatabaseType to DatabaseSystem since it is already used

move to common package the type

Signed-off-by: Iliyan Velichkov <[email protected]>

* dont add props twice

Signed-off-by: Iliyan Velichkov <[email protected]>

* do not overwrite snowflake properties

Signed-off-by: Iliyan Velichkov <[email protected]>

* remove user

Signed-off-by: Iliyan Velichkov <[email protected]>

* rollback

Signed-off-by: Iliyan Velichkov <[email protected]>

* refactor SqlDialectFactory use DirigibleDataSource for optimization

Signed-off-by: Iliyan Velichkov <[email protected]>

* refactoring

Signed-off-by: Iliyan Velichkov <[email protected]>

* add some optimizations

Signed-off-by: Iliyan Velichkov <[email protected]>

* add wrapper for db connections + optimize dialect loading

Signed-off-by: Iliyan Velichkov <[email protected]>

* fix

Signed-off-by: Iliyan Velichkov <[email protected]>

* fix build

Signed-off-by: Iliyan Velichkov <[email protected]>

* schedule snowflake datasource destroy after 9 mins since created

Signed-off-by: Iliyan Velichkov <[email protected]>

* refactoring

Signed-off-by: Iliyan Velichkov <[email protected]>

* code formatting

Signed-off-by: Iliyan Velichkov <[email protected]>

* refact

Signed-off-by: Iliyan Velichkov <[email protected]>

* cleanup

Signed-off-by: Iliyan Velichkov <[email protected]>

* refactor connection enhance logic

Signed-off-by: Iliyan Velichkov <[email protected]>

* remove logger

Signed-off-by: Iliyan Velichkov <[email protected]>

* more cleanup

Signed-off-by: Iliyan Velichkov <[email protected]>

* DatabaseSystemDeterminer refactoring

Signed-off-by: Iliyan Velichkov <[email protected]>

* set dirigible loggers to debug in integration tests

Signed-off-by: Iliyan Velichkov <[email protected]>

* code formating

Signed-off-by: Iliyan Velichkov <[email protected]>

* add TS API

Signed-off-by: Iliyan Velichkov <[email protected]>

* refactoring

Signed-off-by: Iliyan Velichkov <[email protected]>

* fix

Signed-off-by: Iliyan Velichkov <[email protected]>

* reduce logging

Signed-off-by: Iliyan Velichkov <[email protected]>

* fix postgresql IT stability - provision tenant and then publish the test project

Signed-off-by: Iliyan Velichkov <[email protected]>

* increase timeout

Signed-off-by: Iliyan Velichkov <[email protected]>

* add DIRIGIBLE_SNOWFLAKE_DATA_SOURCE_LIFESPAN_SECONDS config

Signed-off-by: Iliyan Velichkov <[email protected]>

---------

Signed-off-by: Iliyan Velichkov <[email protected]>
  • Loading branch information
iliyan-velichkov authored Aug 9, 2024
1 parent 49709f3 commit 2a536a3
Show file tree
Hide file tree
Showing 55 changed files with 1,471 additions and 691 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
import org.eclipse.dirigible.components.data.management.helpers.DatabaseResultSetHelper;
import org.eclipse.dirigible.components.data.management.service.DatabaseDefinitionService;
import org.eclipse.dirigible.components.data.sources.manager.DataSourcesManager;
import org.eclipse.dirigible.components.database.DirigibleConnection;
import org.eclipse.dirigible.components.database.DirigibleDataSource;
import org.eclipse.dirigible.components.database.NamedParameterStatement;
import org.eclipse.dirigible.database.persistence.processors.identity.PersistenceNextValueIdentityProcessor;
import org.eclipse.dirigible.database.sql.SqlFactory;
Expand Down Expand Up @@ -109,7 +111,7 @@ public DatabaseDefinitionService getDatabaseDefinitionService() {
*
* @return the default data source
*/
public static final DataSource getDefaultDataSource() {
public static final DirigibleDataSource getDefaultDataSource() {
return DatabaseFacade.get()
.getDataSourcesManager()
.getDefaultDataSource();
Expand Down Expand Up @@ -146,7 +148,7 @@ public static final String getMetadata(String datasourceName) throws SQLExceptio
* @param datasourceName the datasource name
* @return the data source
*/
private static DataSource getDataSource(String datasourceName) {
private static DirigibleDataSource getDataSource(String datasourceName) {
return datasourceName == null || "".equals(datasourceName.trim()) || "DefaultDB".equals(datasourceName) ? DatabaseFacade.get()
.getDataSourcesManager()
.getDefaultDataSource()
Expand Down Expand Up @@ -521,7 +523,7 @@ public static final int updateNamed(String sql) throws Exception {
* @return the connection
* @throws SQLException the SQL exception
*/
public static final Connection getConnection() throws SQLException {
public static final DirigibleConnection getConnection() throws SQLException {
return getConnection(null);
}

Expand All @@ -532,8 +534,8 @@ public static final Connection getConnection() throws SQLException {
* @return the connection
* @throws SQLException the SQL exception
*/
public static final Connection getConnection(String datasourceName) throws SQLException {
DataSource dataSource = getDataSource(datasourceName);
public static final DirigibleConnection getConnection(String datasourceName) throws SQLException {
DirigibleDataSource dataSource = getDataSource(datasourceName);
if (dataSource == null) {
String error = format("DataSource {0} not known.", datasourceName);
throw new IllegalArgumentException(error);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,98 +84,139 @@ export function getProductName(datasourceName) {
return productName;
};

export function getConnection(datasourceName) {
const connection = new Connection();
export function getConnection(datasourceName: string | undefined) : Connection {
var native;
if (datasourceName) {
native = DatabaseFacade.getConnection(datasourceName);
} else {
native = DatabaseFacade.getConnection();
}
connection.native = native;
return connection;
return new Connection(native);
};

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

/**
* Connection object
*/
function Connection() {
export class Connection {

private readonly native;

constructor(native: any) {
this.native = native;
}

public isOfType(databaseSystem: DatabaseSystem): boolean {
const actualDatabaseSystem = this.getDatabaseSystem();
return actualDatabaseSystem == databaseSystem;
}

this.prepareStatement = function (sql) {
public getDatabaseSystem() {
const dbSystem = this.native.getDatabaseSystem().name();
switch (dbSystem) {
case "DERBY":
return DatabaseSystem.DERBY;
case "POSTGRESQL":
return DatabaseSystem.POSTGRESQL;
case "H2":
return DatabaseSystem.H2;
case "MARIADB":
return DatabaseSystem.MARIADB;
case "HANA":
return DatabaseSystem.HANA;
case "SNOWFLAKE":
return DatabaseSystem.SNOWFLAKE;
case "MYSQL":
return DatabaseSystem.MYSQL;
case "MONGODB":
return DatabaseSystem.MONGODB;
case "SYBASE":
return DatabaseSystem.SYBASE;
case "UNKNOWN":
return DatabaseSystem.UNKNOWN;
default:
throw Error("Missing mapping for database system type " + dbSystem);
}
}

public prepareStatement(sql) {
const preparedStatement = new PreparedStatement();
const native = this.native.prepareStatement(sql);
preparedStatement.native = native;
return preparedStatement;
};
}

this.prepareCall = function (sql) {
public prepareCall(sql) {
const callableStatement = new CallableStatement();
const native = this.native.prepareCall(sql);
callableStatement.native = native;
return callableStatement;
};
}

this.close = function () {
public close() {
if (!this.isClosed()) {
this.native.close();
}
};
}

this.commit = function () {
public commit() {
this.native.commit();
};
}

this.getAutoCommit = function () {
public getAutoCommit() {
return this.native.getAutoCommit();
};
}

this.getCatalog = function () {
public getCatalog() {
return this.native.getCatalog();
};
}

this.getSchema = function () {
public getSchema() {
return this.native.getSchema();
};
}

this.getTransactionIsolation = function () {
public getTransactionIsolation() {
return this.native.getTransactionIsolation();
};
}

this.isClosed = function () {
public isClosed() {
return this.native.isClosed();
};
}

this.isReadOnly = function () {
public isReadOnly() {
return this.native.isReadOnly();
};
}

this.isValid = function () {
public isValid() {
return this.native.isValid();
};
}

this.rollback = function () {
public rollback() {
return this.native.rollback();
};
}

this.setAutoCommit = function (autoCommit) {
public setAutoCommit(autoCommit) {
this.native.setAutoCommit(autoCommit);
};
}

this.setCatalog = function (catalog) {
public setCatalog(catalog) {
this.native.setCatalog(catalog);
};
}

this.setReadOnly = function (readOnly) {
public setReadOnly(readOnly) {
this.native.setReadOnly(readOnly);
};
}

this.setSchema = function (schema) {
public setSchema(schema) {
this.native.setSchema(schema);
};
}

this.setTransactionIsolation = function (transactionIsolation) {
public setTransactionIsolation(transactionIsolation) {
this.native.setTransactionIsolation(transactionIsolation);
};
}
}

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
/*
* Copyright (c) 2024 Eclipse Dirigible contributors
*
* All rights reserved. This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v2.0 which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v20.html
*
* SPDX-FileCopyrightText: Eclipse Dirigible contributors SPDX-License-Identifier: EPL-2.0
*/
package org.eclipse.dirigible.components.database;

import java.sql.Connection;
import java.sql.SQLException;

public interface ConnectionEnhancer {

boolean isApplicable(DatabaseSystem databaseSystem);

void apply(Connection connection) throws SQLException;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
/*
* Copyright (c) 2024 Eclipse Dirigible contributors
*
* All rights reserved. This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v2.0 which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v20.html
*
* SPDX-FileCopyrightText: Eclipse Dirigible contributors SPDX-License-Identifier: EPL-2.0
*/
package org.eclipse.dirigible.components.database;

import com.zaxxer.hikari.HikariConfig;

/**
* The Interface DatabaseConfigurator.
*/
public interface DatabaseConfigurator {

boolean isApplicable(DatabaseSystem databaseSystem);

void apply(HikariConfig config);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
package org.eclipse.dirigible.components.database;

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, SYBASE;

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

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

public boolean isHANA() {
return isOfType(HANA);
}

public boolean isPostgreSQL() {
return isOfType(POSTGRESQL);
}

public boolean isMariaDB() {
return isOfType(MARIADB);
}

public boolean isMySQL() {
return isOfType(MYSQL);
}

public boolean isUnknown() {
return isOfType(UNKNOWN);
}

public boolean isMongoDB() {
return isOfType(MONGODB);
}

public boolean isDerby() {
return isOfType(DERBY);
}

public boolean isOfType(DatabaseSystem databaseSystem) {
return this == databaseSystem;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package org.eclipse.dirigible.components.database;

public interface DatabaseSystemAware {

DatabaseSystem getDatabaseSystem();

boolean isOfType(DatabaseSystem databaseSystem);

}
Loading

0 comments on commit 2a536a3

Please sign in to comment.