Skip to content

Commit

Permalink
case sensitive aware OData processing
Browse files Browse the repository at this point in the history
  • Loading branch information
delchev committed Dec 18, 2019
1 parent acd11ac commit 5f6427b
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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();
}

Expand Down

0 comments on commit 5f6427b

Please sign in to comment.