Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

case sensitive databases by default #4211

Merged
merged 8 commits into from
Aug 12, 2024
Merged
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
1 change: 0 additions & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,6 @@ jobs:
DIRIGIBLE_DATASOURCE_DEFAULT_URL: jdbc:postgresql://localhost:5432/${{ env.POSTGRES_DB }}
DIRIGIBLE_DATASOURCE_DEFAULT_USERNAME: ${{ env.POSTGRES_USER }}
DIRIGIBLE_DATASOURCE_DEFAULT_PASSWORD: ${{ env.POSTGRES_PASS }}
DIRIGIBLE_DATABASE_NAMES_CASE_SENSITIVE: true

- name: Generate a random artifact name
if: always()
Expand Down
1 change: 0 additions & 1 deletion .github/workflows/pull-request.yml
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,6 @@ jobs:
DIRIGIBLE_DATASOURCE_DEFAULT_URL: jdbc:postgresql://localhost:5432/${{ env.POSTGRES_DB }}
DIRIGIBLE_DATASOURCE_DEFAULT_USERNAME: ${{ env.POSTGRES_USER }}
DIRIGIBLE_DATASOURCE_DEFAULT_PASSWORD: ${{ env.POSTGRES_PASS }}
DIRIGIBLE_DATABASE_NAMES_CASE_SENSITIVE: true

- name: Generate a random artifact name
if: always()
Expand Down
3 changes: 1 addition & 2 deletions build/application/src/main/resources/dirigible.properties
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ DIRIGIBLE_DATABASE_PROVIDER=local
DIRIGIBLE_JAVASCRIPT_HANDLER_CLASS_NAME=org.eclipse.dirigible.graalium.handler.GraaliumJavascriptHandler
DIRIGIBLE_GRAALIUM_ENABLE_DEBUG=true
DIRIGIBLE_HOME_URL=services/web/ide/
DIRIGIBLE_DATABASE_NAMES_CASE_SENSITIVE=true
DIRIGIBLE_MULTI_TENANT_MODE=true
DIRIGIBLE_BRANDING_HELP_ITEMS=HELP,SUPPORT,FEATURE,NEWS,DOWNLOAD
DIRIGIBLE_BRANDING_HELP_ITEM_HELP_NAME=Help Portal
Expand All @@ -41,4 +40,4 @@ DIRIGIBLE_BRANDING_HELP_ITEM_NEWS_DIVIDER=false
DIRIGIBLE_BRANDING_HELP_ITEM_DOWNLOAD_NAME=Check for Updates
DIRIGIBLE_BRANDING_HELP_ITEM_DOWNLOAD_ORDER=5
DIRIGIBLE_BRANDING_HELP_ITEM_DOWNLOAD_URL=http://download.dirigible.io/
DIRIGIBLE_BRANDING_HELP_ITEM_DOWNLOAD_DIVIDER=true
DIRIGIBLE_BRANDING_HELP_ITEM_DOWNLOAD_DIVIDER=true
4 changes: 0 additions & 4 deletions build/helm-charts/dirigible/templates/dirigible.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -118,8 +118,6 @@ spec:
value: {{ required "Missing database password" .Values.database.password }}
- name: DIRIGIBLE_MESSAGING_USE_DEFAULT_DATABASE
value: "false"
- name: DIRIGIBLE_DATABASE_NAMES_CASE_SENSITIVE
value: "true"
- name: DIRIGIBLE_SCHEDULER_MEMORY_STORE
value: "true"
{{- end }}
Expand Down Expand Up @@ -149,8 +147,6 @@ spec:
key: password
- name: DIRIGIBLE_MESSAGING_USE_DEFAULT_DATABASE
value: "false"
- name: DIRIGIBLE_DATABASE_NAMES_CASE_SENSITIVE
value: "true"
- name: DIRIGIBLE_SCHEDULER_MEMORY_STORE
value: "true"
{{- end }}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -936,16 +936,10 @@ export function create(oDefinition, logCtxName, dataSourceName) {
globals.set(dataSourceName, productName);
}

let isCaseSensitive = configurations.get("DIRIGIBLE_DATABASE_NAMES_CASE_SENSITIVE");
if (!isCaseSensitive && productName === "PostgreSQL") {
orm["properties"].map(function (property) {
property.column = property.column.toLowerCase();
});
}
// }
return new DAO(orm, logCtxName, dataSourceName);
};

export function dao(oDefinition, logCtxName, dataSourceName) {
return create(oDefinition, logCtxName, dataSourceName)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@
*
*/
import { configurations } from "sdk/core";
const isCaseSensitive = configurations.get("DIRIGIBLE_DATABASE_NAMES_CASE_SENSITIVE");

export function ORM(orm) {
this.orm = orm;
Expand Down Expand Up @@ -223,7 +222,7 @@ ORM.prototype.toColumn = function (ormProperty) {
let column;
if (ormProperty) {
column = {
name: isCaseSensitive ? "\"" + ormProperty.column + "\"" : ormProperty.column,
name: "\"" + ormProperty.column + "\"",
type: ormProperty.type,
length: String(ormProperty.length),
primaryKey: String(ormProperty.id === undefined ? false : ormProperty.id),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,6 @@
*/
public interface DatabaseParameters {

/** Whether or not to use case sensitive syntax for table or view names and column names. */
String DIRIGIBLE_DATABASE_NAMES_CASE_SENSITIVE = "DIRIGIBLE_DATABASE_NAMES_CASE_SENSITIVE";

/** The Constant DIRIGIBLE_DATABASE_DEFAULT_QUERY_LIMIT. */
String DIRIGIBLE_DATABASE_DEFAULT_QUERY_LIMIT = "DIRIGIBLE_DATABASE_DEFAULT_QUERY_LIMIT";

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ 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;
UNKNOWN, DERBY, POSTGRESQL, H2, MARIADB, HANA, SNOWFLAKE, MYSQL, MONGODB;

public boolean isH2() {
return isOfType(H2);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ public class DatabaseSystemDeterminer {
DatabaseSystem.MARIADB, "jdbc:mariadb", //
DatabaseSystem.MYSQL, "jdbc:mysql", //
DatabaseSystem.MONGODB, "jdbc:mongodb", //
DatabaseSystem.SYBASE, "jdbc:sybase", //
DatabaseSystem.DERBY, "jdbc:derby"//
);

Expand All @@ -36,7 +35,6 @@ 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.SYBASE, List.of("com.sybase.jdbc4.jdbc.SybDriver"), //
DatabaseSystem.DERBY, List.of("org.apache.derby.jdbc.ClientDriver", "org.apache.derby.jdbc.EmbeddedDriver")//
);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,16 +98,6 @@ void testDetermineMongoDB_withDriver() {
testDetermine_withDriver("com.mongodb.jdbc.MongoDriver", DatabaseSystem.MONGODB);
}

@Test
void testDetermineSybase_withUrl() {
testDetermine_withUrl("jdbc:sybase:Tds:localhost:3306/database", DatabaseSystem.SYBASE);
}

@Test
void testDetermineSybase_withDriver() {
testDetermine_withDriver("com.sybase.jdbc4.jdbc.SybDriver", DatabaseSystem.SYBASE);
}

@Test
void testDetermineUnknown_withUrl() {
testDetermine_withUrl("jdbc:unknown://localhost:1234/testdb", DatabaseSystem.UNKNOWN);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
package org.eclipse.dirigible.components.data.management.load;

import com.google.common.base.CaseFormat;
import org.eclipse.dirigible.commons.config.Configuration;
import org.eclipse.dirigible.components.data.sources.manager.DataSourcesManager;
import org.eclipse.dirigible.components.data.structures.domain.*;
import org.eclipse.dirigible.components.database.DatabaseParameters;
Expand Down Expand Up @@ -38,10 +37,6 @@ public class DataSourceMetadataLoader implements DatabaseParameters {
/** The Constant logger. */
private static final Logger logger = LoggerFactory.getLogger(DataSourceMetadataLoader.class);

/** The Constant IS_CASE_SENSETIVE. */
private static final boolean IS_CASE_SENSETIVE =
Boolean.parseBoolean(Configuration.get(DatabaseParameters.DIRIGIBLE_DATABASE_NAMES_CASE_SENSITIVE));

/** The data source service. */
private final DataSourcesManager datasourceManager;

Expand Down Expand Up @@ -129,16 +124,6 @@ public static void addColumns(DatabaseMetaData databaseMetadata, Connection conn
databaseMetadata.getColumns(connection.getCatalog(), schemaPattern, normalizeTableName(tableMetadata.getName()), null);
if (columns.next()) {
iterateColumns(tableMetadata, columns);
} else if (!IS_CASE_SENSETIVE) {
// Fallback for PostgreSQL
columns = databaseMetadata.getColumns(connection.getCatalog(), schemaPattern, normalizeTableName(tableMetadata.getName()
.toLowerCase()),
null);
if (!columns.next()) {
throw new SQLException("Error in getting the information about the columns.");
} else {
iterateColumns(tableMetadata, columns);
}
}
}

Expand Down Expand Up @@ -172,14 +157,6 @@ public static void addPrimaryKeys(DatabaseMetaData databaseMetadata, Connection
databaseMetadata.getPrimaryKeys(connection.getCatalog(), schema, normalizeTableName(tableMetadata.getName()));
if (primaryKeys.next()) {
iteratePrimaryKeys(tableMetadata, primaryKeys);
} else if (!IS_CASE_SENSETIVE) {
// Fallback for PostgreSQL
primaryKeys = databaseMetadata.getPrimaryKeys(connection.getCatalog(), schema, normalizeTableName(tableMetadata.getName()
.toLowerCase()));
if (!primaryKeys.next()) {
} else {
iteratePrimaryKeys(tableMetadata, primaryKeys);
}
}
}

Expand Down Expand Up @@ -227,14 +204,6 @@ public static void addForeignKeys(DatabaseMetaData databaseMetadata, Connection
databaseMetadata.getImportedKeys(connection.getCatalog(), schema, normalizeTableName(tableMetadata.getName()));
if (foreignKeys.next()) {
iterateForeignKeys(tableMetadata, foreignKeys);
} else if (!IS_CASE_SENSETIVE) {
// Fallback for PostgreSQL
foreignKeys = databaseMetadata.getImportedKeys(connection.getCatalog(), schema, normalizeTableName(tableMetadata.getName()
.toLowerCase()));
if (!foreignKeys.next()) {
} else {
iterateForeignKeys(tableMetadata, foreignKeys);
}
}
}

Expand Down Expand Up @@ -339,16 +308,6 @@ public static void addTableType(DatabaseMetaData databaseMetadata, Connection co
databaseMetadata.getTables(connection.getCatalog(), schemaPattern, normalizeTableName(tableMetadata.getName()), null);
if (tables.next()) {
iterateTables(tableMetadata, tables);
} else if (!IS_CASE_SENSETIVE) {
// Fallback for PostgreSQL
tables = databaseMetadata.getTables(connection.getCatalog(), schemaPattern, normalizeTableName(tableMetadata.getName()
.toLowerCase()),
null);
if (!tables.next()) {
throw new SQLException("Error in getting the information about the tables.");
} else {
iterateTables(tableMetadata, tables);
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,29 +9,20 @@
*/
package org.eclipse.dirigible.components.data.structures.synchronizer.table;

import java.sql.Connection;
import java.sql.DatabaseMetaData;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.eclipse.dirigible.commons.config.Configuration;
import org.eclipse.dirigible.components.data.structures.domain.Table;
import org.eclipse.dirigible.components.data.structures.domain.TableColumn;
import org.eclipse.dirigible.components.database.DatabaseNameNormalizer;
import org.eclipse.dirigible.components.database.DatabaseParameters;
import org.eclipse.dirigible.database.sql.DataType;
import org.eclipse.dirigible.database.sql.DataTypeUtils;
import org.eclipse.dirigible.database.sql.ISqlKeywords;
import org.eclipse.dirigible.database.sql.SqlException;
import org.eclipse.dirigible.database.sql.SqlFactory;
import org.eclipse.dirigible.database.sql.*;
import org.eclipse.dirigible.database.sql.builders.table.AlterTableBuilder;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.sql.*;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
* The Table Alter Processor.
*/
Expand All @@ -41,7 +32,8 @@ public class TableAlterProcessor {
private static final Logger logger = LoggerFactory.getLogger(TableAlterProcessor.class);

/** The Constant INCOMPATIBLE_CHANGE_OF_TABLE. */
private static final String INCOMPATIBLE_CHANGE_OF_TABLE = "Incompatible change of table [%s] by adding a column [%s] which is [%s]"; //$NON-NLS-1$
private static final String INCOMPATIBLE_CHANGE_OF_TABLE = "Incompatible change of table [%s] by adding a column [%s] which is [%s]";
// $NON-NLS-1$

/**
* Execute the corresponding statement.
Expand All @@ -51,12 +43,8 @@ public class TableAlterProcessor {
* @throws SQLException the SQL exception
*/
public static void execute(Connection connection, Table tableModel) throws SQLException {
boolean caseSensitive =
Boolean.parseBoolean(Configuration.get(DatabaseParameters.DIRIGIBLE_DATABASE_NAMES_CASE_SENSITIVE, "false"));
String tableName = tableModel.getName();
if (caseSensitive) {
tableName = "\"" + tableName + "\"";
}
String tableName = "\"" + tableModel.getName() + "\"";

logger.info("Processing Alter Table: " + tableName);

Map<String, String> columnDefinitions = new HashMap<>();
Expand All @@ -80,11 +68,9 @@ public static void execute(Connection connection, Table tableModel) throws SQLEx

// ADD iteration
for (TableColumn columnModel : tableModel.getColumns()) {
String name = columnModel.getName();
String name = "\"" + columnModel.getName() + "\"";
String nameOriginal = name;
if (caseSensitive) {
name = "\"" + name + "\"";
}

DataType type = DataType.valueOfByName(columnModel.getType());
String length = columnModel.getLength();
boolean isNullable = columnModel.isNullable();
Expand Down Expand Up @@ -150,9 +136,7 @@ public static void execute(Connection connection, Table tableModel) throws SQLEx

// DROP iteration
for (String columnName : columnDefinitions.keySet()) {
if (caseSensitive) {
columnName = "\"" + columnName + "\"";
}
columnName = "\"" + columnName + "\"";
if (!modelColumnNames.contains(columnName.toUpperCase())) {
AlterTableBuilder alterTableBuilder = SqlFactory.getNative(connection)
.alter()
Expand Down
Loading
Loading