private void addFilterStringtoGlobalWhere(List<Filter> filters, String currentPath) { currentPath=convertToUpperCaseIfRequired(currentPath); if (filters != null && !filters.isEmpty()) { for (int i = 0; i < filters.size(); i++) { globalWherePlaceHolder.add(filters.get(i).getExpression() .replaceAll("ROOT_ENTITY_SELECT_ALIAS", rootEntitySelectAlias) .replaceAll("ROOT_ENTITY_SELECT", rootEntitySelect).replaceAll("PATH_FROM_ROOT", currentPath)); } } }
public List<Column> getColumnsFromListOfStrings(List<String> columns) { return columns.stream().map(s -> !s.contains(" AS ") ? new Column(s).setDbaliasName(convertToUpperCaseIfRequired(ALIASHLP + s)) : new Column((s.split(" AS ")[0]).replaceAll("ROOT_ENTITY_SELECT_ALIAS\\.", "").replaceAll("ROOT_ENTITY_SELECT\\.","").replaceAll("PATH_FROM_ROOT\\.", "")) .setDbaliasName(convertToUpperCaseIfRequired((s.split(" AS ")[1])).replaceAll("ROOT_ENTITY_SELECT_ALIAS\\.", "").replaceAll("ROOT_ENTITY_SELECT\\.","").replaceAll("PATH_FROM_ROOT\\.", "")) .setAliasName((s.split(" AS ")[1]).replaceAll("ROOT_ENTITY_SELECT_ALIAS\\.", "").replaceAll("ROOT_ENTITY_SELECT\\.","").replaceAll("PATH_FROM_ROOT\\.", ""))) .collect(Collectors.toList()); }
private void prepareGroupByHavingClause() { ReadEntityInfo enInfo = qHelper.getEntityInfo(); if (!enInfo.getGroupBy().isEmpty()) { groupByHavingClause.append("GROUP BY ") .append(convertToUpperCaseIfRequired(enInfo.getGroupBy().stream().collect(Collectors.joining(", ")))); if (!enInfo.getHaving().isEmpty()) { groupByHavingClause.append(" HAVING "); groupByHavingClause.append(enInfo.getHaving().stream().collect(Collectors.joining(" AND "))); } } }
private void formWhereClauseforLimitOffset() { String pathtolastNavEnt = formPathtoLastNavEnInfo(); List<Column> lastNavEInfoKeyCols = getLastEntityNavigatedKeyColumns(); for (Column keyCol : lastNavEInfoKeyCols) { StringBuffer limitsql = new StringBuffer(""); limitsql.append(convertToUpperCaseIfRequired(pathtolastNavEnt + keyCol.getName())); limitsql.append(" IN ( "); limitsql.append(formInnerQueriesforLimitOffset(keyCol)); limitsql.append(" )"); globalWherePlaceHolder.add(limitsql.toString()); } }
private String formInnerQueriesforLimitOffset(Column keyCol) { StringBuffer sql = new StringBuffer(""); // Start Formation of SELECT AND FROM (CDS SQL Notation) sql.append(convertToUpperCaseIfRequired(selectPartLimit(keyCol))); // START FORMATION OF WHERE prepareGlobalWhereClauseLimit(); if (globalWhereClauseLimit.length() > 0) { sql.append(" " + globalWhereClauseLimit); globalWhereClauseLimit.delete(0, globalWhereClauseLimit.length()); } // START FORMATION OF ORDERBY if (globalOrderByLimit.length() > 0) { sql.append(" ORDER BY ").append(convertToUpperCaseIfRequired((globalOrderByLimit.toString().substring(1)))); globalOrderByLimit.delete(0, globalOrderByLimit.length()); } // START FORMATION OF TOP AND SKIP formInnerLimitOffsetSql(); if (limitOffsetInner != null) { sql.append(limitOffsetInner); limitOffsetInner = ""; } return sql.toString(); }
private void addFilterstoWhereLimit(ReadEntityInfo eInfo,String currentPath) { currentPath=convertToUpperCaseIfRequired(currentPath); String pathToBeReplaced = "PATH_FROM_ROOT"; if (!eInfo.getFilters().isEmpty()) { for (int i = 0; i < eInfo.getFilters().size(); i++) { String filterExpression = eInfo.getFilters().get(i).getExpression().replaceAll("ROOT_ENTITY_SELECT_ALIAS\\.", "") .replaceAll("ROOT_ENTITY_SELECT\\.", ""); if(currentPath.equals("")) { /*This is done as part of fixing message 1880169598. Before the fix, there used to be a dot in the query without a namespace or an alias preceding it.*/ pathToBeReplaced = "PATH_FROM_ROOT\\."; } globalWherePlaceHolderLimit.add(filterExpression.replaceAll(pathToBeReplaced, currentPath) ); } } }
public String replacePkJoin(String filterExp, UriResource currentUri) { if (filterExp.contains("ROOT_ENTITY_SELECT_ALIAS_PKJOIN") && currentUri instanceof UriResourcePartTyped) { UriResourcePartTyped currentTypedUri = (UriResourcePartTyped) currentUri; EdmType currentType = currentTypedUri.getType(); if (currentType instanceof EdmEntityType) { EdmEntityType entityType = (EdmEntityType) currentType; List<EdmKeyPropertyRef> currentEntityKeys = entityType.getKeyPropertyRefs(); List<String> currentEntityPrimaryKeys = currentEntityKeys.stream().map(keyRef -> convertToUpperCaseIfRequired(keyRef.getName())) .collect(Collectors.toList()); String firstKey = currentEntityPrimaryKeys.remove(0); String joinString = "PATH_FROM_ROOT." + firstKey + " = " + "ROOT_ENTITY_SELECT_ALIAS" + "." + "PATH_FROM_ROOT." + firstKey; for (String key : currentEntityPrimaryKeys) { joinString += " AND "; joinString += "PATH_FROM_ROOT." + key + " = " + "ROOT_ENTITY_SELECT_ALIAS" + "." + "PATH_FROM_ROOT." + key; } filterExp = filterExp.replaceAll("ROOT_ENTITY_SELECT_ALIAS_PKJOIN", joinString); } } return filterExp; }
@Override public Object visitMember(Member member) throws ExpressionVisitException, ODataApplicationException { List<UriResource> uriPartsWithinLambda = member.getResourcePath().getUriResourceParts(); String propertyPath = uriPartsWithinLambda.get(1).getSegmentValue(); if(uriPartsWithinLambda.size() > 2){ List<UriResource> restOfUri = uriPartsWithinLambda.subList(2, uriPartsWithinLambda.size()); for(UriResource uPa : restOfUri) { propertyPath += "."; propertyPath += uPa.getSegmentValue(); }} return convertToUpperCaseIfRequired(propertyPath); }
private void getColumnsFromApplyExpandNode(ApplyExpandNode currentApplyExpandNode, List<Column> columnList, String currentPath) { String aliasPrefix = currentPath + ALIASHLP; if (currentApplyExpandNode != null) { columnList.addAll(currentApplyExpandNode.getProperties().stream().map(s -> !s.contains("AS") ? new Column(aliasPrefix + s) : new Column((s.split("AS ")[0]).replaceAll("ROOT_ENTITY_SELECT_ALIAS\\.", "").replaceAll("ROOT_ENTITY_SELECT\\.","").replaceAll("PATH_FROM_ROOT\\.", "")) .setDbaliasName(convertToUpperCaseIfRequired((s.split(" AS ")[1]).replaceAll("ROOT_ENTITY_SELECT_ALIAS\\.", "").replaceAll("ROOT_ENTITY_SELECT\\.","").replaceAll("PATH_FROM_ROOT\\.", ""))) .setAliasName((s.split(" AS ")[1]).replaceAll("ROOT_ENTITY_SELECT_ALIAS\\.", "").replaceAll("ROOT_ENTITY_SELECT\\.","").replaceAll("PATH_FROM_ROOT\\.", ""))) .collect(Collectors.toList())); for (ApplyExpandNode child : currentApplyExpandNode.getChildren()) {// NOSONAR String navigationProperty = child.getName(); String childPath = aliasPrefix + navigationProperty; getColumnsFromApplyExpandNode(child, columnList, childPath); } } }
public String generateSQl() { StringBuffer sql = new StringBuffer(""); sql.append(convertToUpperCaseIfRequired(selectPart())); sql.append(" ORDER BY ").append(convertToUpperCaseIfRequired(globalOrderBy.toString().substring(1)));
String queryEndStr = ""; if (searchableProperties != null) { searchableProperties = searchableProperties.stream().map(prop -> convertToUpperCaseIfRequired(prop)) .collect(Collectors.toList()); if (hasNavigation) { queryStartStr = "UPPER(ROOT_ENTITY_ALIAS." + convertToUpperCaseIfRequired(readEntityInfo.getEntityName()) + "."; queryEndStr = ")"; } else {
private List<ReadEntityInfo> prepExpandInfoListFromApplyExpandNode(ApplyExpandNode applyExpandNode, String currentExpandPath) { List<ReadEntityInfo> entityInfoToBeExpandedList = new ArrayList<ReadEntityInfo>(); if (applyExpandNode != null) for (ApplyExpandNode child : applyExpandNode.getChildren()) { ReadEntityInfo childEnInfo = new ReadEntityInfo(); String navigationProperty = child.getName(); String childExpandPath = currentExpandPath + ALIASHLP + navigationProperty; childEnInfo.setEntityName(navigationProperty); if (!child.getProperties().isEmpty()) { List<String> complexProperties = child.getProperties().stream() .filter(s -> ((!s.contains(" AS ") && s.contains(".")))).collect(Collectors.toList()); childEnInfo.setColumns( child.getProperties().stream().map(s -> (!s.contains(" AS ") && !s.contains(".")) ? new Column(s).setDbaliasName(convertToUpperCaseIfRequired(childExpandPath + ALIASHLP + s)) : s.contains(" AS ") ? new Column((s.split(" AS ")[0]).replaceAll("ROOT_ENTITY_SELECT_ALIAS\\.", "").replaceAll("ROOT_ENTITY_SELECT\\.","").replaceAll("PATH_FROM_ROOT\\.", "")) .setDbaliasName(convertToUpperCaseIfRequired((s.split(" AS ")[1])).replaceAll("ROOT_ENTITY_SELECT_ALIAS\\.", "").replaceAll("ROOT_ENTITY_SELECT\\.","").replaceAll("PATH_FROM_ROOT\\.", "")) .setAliasName((s.split(" AS ")[1]).replaceAll("ROOT_ENTITY_SELECT_ALIAS\\.", "").replaceAll("ROOT_ENTITY_SELECT\\.","").replaceAll("PATH_FROM_ROOT\\.", "")) : null) .filter(s -> s != null).collect(Collectors.toList())); childEnInfo.setFetchColumns(true); } childEnInfo.setEntitiesExpanded(prepExpandInfoListFromApplyExpandNode(child, childExpandPath)); entityInfoToBeExpandedList.add(childEnInfo); } return entityInfoToBeExpandedList; }
public static List<String> extractKeyPredicateFilterExpressions(UriInfo uriInfo, boolean considerActiveEntityKey) throws EdmException { List<KeyPredicate> keypredicates = extractKeyPredicateRefsFromUriInfo(uriInfo, considerActiveEntityKey); EdmEntityType entity = uriInfo.getTargetEntitySet().getEntityType(); List<String> filters=new ArrayList<>(); for (int j = 0; j < keypredicates.size(); j++) { String filter; String kpAlias = keypredicates.get(j).getProperty().getName(); EdmTyped kpRef = entity.getProperty(kpAlias); if(kpRef.getName().equals(DRAFTS_ISACTIVE_ENTITY)) { continue; } String kpNameInFilter = convertToUpperCaseIfRequired(kpRef.getName()); String keyPredType = kpRef.getType().toString(); if (keyPredType != null && (keyPredType.equals("Edm.DateTimeOffset") || keyPredType.equals("Edm.DateTime") || keyPredType.equals("Edm.Date") || keyPredType.equals("Edm.Guid") )) { filter=kpNameInFilter.replace("/", ".") + " = '"+ keypredicates.get(j).getLiteral() + "'"; } else { filter=kpNameInFilter.replace("/", ".") + " = " + keypredicates.get(j).getLiteral(); } filters.add(filter); } return filters; }
return adjustForGuid(propertyName,edmProperty) ; String pathPrefixedName = "ROOT_ENTITY_SELECT_ALIAS" + "."+"PATH_FROM_ROOT."+ convertToUpperCaseIfRequired(propertyName); return adjustForGuid(pathPrefixedName,edmProperty) ; String pathPrefixedName = convertToUpperCaseIfRequired(edmProperty.getName()); return adjustForGuid(pathPrefixedName,edmProperty) ; return "ROOT_ENTITY_SELECT_ALIAS" + "."+"PATH_FROM_ROOT."+convertToUpperCaseIfRequired(complexPropName.toString()); pathTillLambda.append(convertToUpperCaseIfRequired(uriResourceParts.get(i).getSegmentValue())); if (i != uriResourceParts.size() - 2) { pathTillLambda.append(".");
String kpAlias = keyPredicates.get(j).getName(); EdmKeyPropertyRef kpRef = entity.getKeyPropertyRef(kpAlias); String kpNameInFilter = convertToUpperCaseIfRequired(kpRef.getName()); EdmType keyPredType = kpRef.getProperty().getType(); if (keyPredType != null && (keyPredType.getFullQualifiedName()
String kpAlias = keyPredicates.get(j).getName(); EdmKeyPropertyRef kpRef = entity.getKeyPropertyRef(kpAlias); String kpNameInFilter = convertToUpperCaseIfRequired(kpRef.getName()); EdmType keyPredType = kpRef.getProperty().getType(); if (keyPredType != null && (keyPredType.getFullQualifiedName()
continue; String kpNameInFilter = convertToUpperCaseIfRequired(kpRef.getName()); EdmType keyPredType = kpRef.getProperty().getType(); if (keyPredType != null && (keyPredType.getFullQualifiedName()
public Column formNewColumnObject(EdmStructuredType targetEntityType, String propertyName, String dbalias, boolean isKey, String parentComplexName,ReadEntityInfo eInfo) { Column col =null; col = new Column(); col.setpKey(isKey); col.setName(propertyName); col.setDbaliasName(convertToUpperCaseIfRequired(dbalias + ALIASHLP + propertyName)); if (parentComplexName != null) { col.setPathName(parentComplexName + "." + propertyName); } else { col.setPathName(propertyName); } if(targetEntityType.getProperty(propertyName)==null && propertyName.equalsIgnoreCase(DraftUtilsV4.DRAFTS_FOREIGN_KEY)) { col.setType(ColumnType.Primitive); col.setColumnDataType("Edm.Guid"); } else { col.setType(ColumnType.Primitive); col.setColumnDataType(targetEntityType.getProperty(propertyName).getType().getFullQualifiedName() .getFullQualifiedNameAsString()); } return col; }
col.setpKey(isKey); col.setName(propertyName); col.setDbaliasName(convertToUpperCaseIfRequired(dbalias + ALIASHLP + propertyName)); if (parentComplexName != null) { col.setPathName(parentComplexName + "." + propertyName);
public Column formNewColumnObject(EdmStructuredType targetEntityType, String propertyName, String dbalias, boolean isKey, String parentComplexName,ReadEntityInfo eInfo) { Column col =null; col = new Column(); col.setpKey(isKey); col.setName(propertyName); col.setDbaliasName(convertToUpperCaseIfRequired(dbalias + ALIASHLP + propertyName)); if (parentComplexName != null) { col.setPathName(parentComplexName + "." + propertyName); } else { col.setPathName(propertyName); } if (targetEntityType.getProperty(propertyName).getType() instanceof EdmTypeDefinition) { col.setType(ColumnType.Scalar); col.setColumnDataType(((EdmTypeDefinition) targetEntityType.getProperty(propertyName).getType()) .getUnderlyingType().getFullQualifiedName().getFullQualifiedNameAsString()); } else { col.setType(ColumnType.Primitive); col.setColumnDataType(targetEntityType.getProperty(propertyName).getType().getFullQualifiedName() .getFullQualifiedNameAsString()); } return col; }