From 5f6427b1d03233196f10899d8c2d47eaba2b367c Mon Sep 17 00:00:00 2001 From: delchev Date: Wed, 18 Dec 2019 18:22:17 +0200 Subject: [PATCH] case sensitive aware OData processing --- .../model/processors/TableAlterProcessor.java | 7 +++-- .../engine/odata2/sql/builder/SQLQuery.java | 26 ++++++++++++++----- .../builder/expression/SQLExpressionJoin.java | 14 +++++++--- 3 files changed, 33 insertions(+), 14 deletions(-) diff --git a/modules/database/database-data-models/src/main/java/org/eclipse/dirigible/database/ds/model/processors/TableAlterProcessor.java b/modules/database/database-data-models/src/main/java/org/eclipse/dirigible/database/ds/model/processors/TableAlterProcessor.java index 79ae274d95c..f87820fe6bf 100644 --- a/modules/database/database-data-models/src/main/java/org/eclipse/dirigible/database/ds/model/processors/TableAlterProcessor.java +++ b/modules/database/database-data-models/src/main/java/org/eclipse/dirigible/database/ds/model/processors/TableAlterProcessor.java @@ -69,8 +69,10 @@ public static void execute(Connection connection, DataStructureTableModel tableM // ADD iteration for (DataStructureTableColumnModel columnModel : tableModel.getColumns()) { - String name = columnModel.getName(); + if (caseSensitive) { + name = "\"" + name + "\""; + } DataType type = DataType.valueOf(columnModel.getType()); String length = columnModel.getLength(); boolean isNullable = columnModel.isNullable(); @@ -106,9 +108,6 @@ public static void execute(Connection connection, DataStructureTableModel tableM AlterTableBuilder alterTableBuilder = SqlFactory.getNative(connection).alter().table(tableName); - if (caseSensitive) { - name = "\"" + name + "\""; - } alterTableBuilder.add().column(name, type, isPrimaryKey, isNullable, isUnique, args); if (!isNullable) { diff --git a/modules/engines/engine-odata/src/main/java/org/eclipse/dirigible/engine/odata2/sql/builder/SQLQuery.java b/modules/engines/engine-odata/src/main/java/org/eclipse/dirigible/engine/odata2/sql/builder/SQLQuery.java index 123fa6b63d7..6b24c469f4f 100644 --- a/modules/engines/engine-odata/src/main/java/org/eclipse/dirigible/engine/odata2/sql/builder/SQLQuery.java +++ b/modules/engines/engine-odata/src/main/java/org/eclipse/dirigible/engine/odata2/sql/builder/SQLQuery.java @@ -53,6 +53,8 @@ import org.apache.olingo.odata2.api.uri.expression.FilterExpression; import org.apache.olingo.odata2.api.uri.expression.OrderByExpression; import org.apache.olingo.odata2.api.uri.expression.OrderExpression; +import org.eclipse.dirigible.commons.config.Configuration; +import org.eclipse.dirigible.database.ds.model.IDataStructureModel; import org.eclipse.dirigible.engine.odata2.sql.api.OData2Exception; import org.eclipse.dirigible.engine.odata2.sql.binding.EdmTableBinding; import org.eclipse.dirigible.engine.odata2.sql.binding.EdmTableBinding.ColumnInfo; @@ -188,17 +190,29 @@ public String getSQLTablePrimaryKey(final EdmStructuralType type) throws EdmExce } public String getSQLTableColumn(final EdmStructuralType targetEnitityType, final EdmProperty p) throws EdmException { - if (p.isSimple()) - return getSQLTableAlias(targetEnitityType) + "." + tableMappingProvider.getEdmTableBinding(targetEnitityType).getColumnName(p); - else + if (p.isSimple()) { + boolean caseSensitive = Boolean.parseBoolean(Configuration.get(IDataStructureModel.DIRIGIBLE_DATABASE_NAMES_CASE_SENSITIVE, "false")); + if (caseSensitive) { + return "\"" + getSQLTableAlias(targetEnitityType) + "\".\"" + tableMappingProvider.getEdmTableBinding(targetEnitityType).getColumnName(p) + "\""; + } else { + return getSQLTableAlias(targetEnitityType) + "." + tableMappingProvider.getEdmTableBinding(targetEnitityType).getColumnName(p); + } + } else { throw new IllegalArgumentException("Unable to get the table column name of complex property " + p); + } } public ColumnInfo getSQLTableColumnInfo(final EdmStructuralType targetEnitityType, final EdmProperty p) throws EdmException { if (p.isSimple()) { - ColumnInfo info = tableMappingProvider.getEdmTableBinding((targetEnitityType)).getColumnInfo(p); - return new ColumnInfo(getSQLTableAlias(targetEnitityType) + "." + info.getColumnName(), info.getSqlType()); - //return getSQLTableAlias(targetEnitityType) + "." + tableMappingProvider.getTableMapping(targetEnitityType).getColumnName(p); + ColumnInfo info = tableMappingProvider.getEdmTableBinding((targetEnitityType)).getColumnInfo(p); + boolean caseSensitive = Boolean.parseBoolean(Configuration.get(IDataStructureModel.DIRIGIBLE_DATABASE_NAMES_CASE_SENSITIVE, "false")); + if (caseSensitive) { + return new ColumnInfo("\"" + getSQLTableAlias(targetEnitityType) + "\".\"" + info.getColumnName(), info.getSqlType()); + //return getSQLTableAlias(targetEnitityType) + "." + tableMappingProvider.getTableMapping(targetEnitityType).getColumnName(p); + } else { + return new ColumnInfo(getSQLTableAlias(targetEnitityType) + "." + info.getColumnName(), info.getSqlType()); + //return getSQLTableAlias(targetEnitityType) + "." + tableMappingProvider.getTableMapping(targetEnitityType).getColumnName(p); + } } else { throw new IllegalArgumentException("Unable to get the table column name of complex property " + p); } diff --git a/modules/engines/engine-odata/src/main/java/org/eclipse/dirigible/engine/odata2/sql/builder/expression/SQLExpressionJoin.java b/modules/engines/engine-odata/src/main/java/org/eclipse/dirigible/engine/odata2/sql/builder/expression/SQLExpressionJoin.java index 95f7be5a6a7..dcf40f7e96a 100644 --- a/modules/engines/engine-odata/src/main/java/org/eclipse/dirigible/engine/odata2/sql/builder/expression/SQLExpressionJoin.java +++ b/modules/engines/engine-odata/src/main/java/org/eclipse/dirigible/engine/odata2/sql/builder/expression/SQLExpressionJoin.java @@ -19,6 +19,8 @@ import org.apache.olingo.odata2.api.edm.EdmException; import org.apache.olingo.odata2.api.edm.EdmStructuralType; import org.apache.olingo.odata2.api.uri.KeyPredicate; +import org.eclipse.dirigible.commons.config.Configuration; +import org.eclipse.dirigible.database.ds.model.IDataStructureModel; import org.eclipse.dirigible.engine.odata2.sql.api.OData2Exception; import org.eclipse.dirigible.engine.odata2.sql.builder.SQLContext; import org.eclipse.dirigible.engine.odata2.sql.builder.SQLQuery; @@ -59,21 +61,25 @@ public String evaluate(SQLContext context, ExpressionType type) throws EdmExcept if (type != ExpressionType.JOIN || isEmpty()) { return EMPTY_STRING; } - + boolean caseSensitive = Boolean.parseBoolean(Configuration.get(IDataStructureModel.DIRIGIBLE_DATABASE_NAMES_CASE_SENSITIVE, "false")); + String csl = ""; + if (caseSensitive) { + csl = "\""; + } StringBuilder join = new StringBuilder(); join.append(joinType.toString()); join.append(" JOIN "); - join.append(getTableName(start)); + join.append(csl + getTableName(start) + csl); join.append(" AS "); join.append(query.getSQLTableAlias(start)); join.append(" ON "); join.append(query.getSQLTableAlias(start)); join.append("."); - join.append(getTargetJoinKeyForEntityType(start, target)); + join.append(csl + getTargetJoinKeyForEntityType(start, target) + csl); join.append(" = "); join.append(query.getSQLTableAlias(target)); join.append("."); - join.append(query.getSQLJoinTableName(target, start)); + join.append(csl + query.getSQLJoinTableName(target, start) + csl); return join.toString(); }