private void parseLimitClause(Query query, String limitClause) { limitClause = limitClause.Trim(); if (!limitClause.IsEmpty()) { try { int limit = NInteger.ParseInt(limitClause); query.setMaxRows(limit); } catch (FormatException e) { throw new QueryParserException("Could not parse LIMIT value: " + limitClause); } } }
private void parseOffsetClause(Query query, String offsetClause) { offsetClause = offsetClause.Trim(); if (!offsetClause.IsEmpty()) { try { int offset = NInteger.ParseInt(offsetClause); // ofset is 0-based, but first-row is 1-based int firstRow = offset + 1; query.setFirstRow(firstRow); } catch (FormatException e) { throw new QueryParserException("Could not parse OFFSET value: " + offsetClause); } } }
} // find() private static Object find(Dictionary <object, object> map, String key, int fromIndex) { int indexOfDot = key.IndexOf('.', fromIndex); int indexOfBracket = key.IndexOf('[', fromIndex); int indexOfEndBracket = -1; int arrayIndex = -1; bool hasDot = indexOfDot != -1; bool hasBracket = indexOfBracket != -1; if (hasBracket) { // also check that there is an end-bracket indexOfEndBracket = key.IndexOf("]", indexOfBracket); hasBracket = indexOfEndBracket != -1; if (hasBracket) { String indexString = key.Substring(indexOfBracket + 1, indexOfEndBracket); try { arrayIndex = NInteger.ParseInt(indexString); } catch (FormatException e) { // not a valid array/list index hasBracket = false; } } } if (hasDot && hasBracket) { if (indexOfDot > indexOfBracket) { hasDot = false; } else { hasBracket = false; } } if (hasDot) { String prefix = key.Substring(0, indexOfDot); Object nestedObject = map[prefix]; if (nestedObject == null) { return(find(map, key, indexOfDot + 1)); } if (nestedObject is Dictionary <String, object> ) { String remainingPart = key.Substring(indexOfDot + 1); //@SuppressWarnings("unchecked") Dictionary <object, object> nestedMap = (Dictionary <object, object>)nestedObject; return(find(nestedMap, remainingPart)); } } if (hasBracket) { String prefix = key.Substring(0, indexOfBracket); Object nestedObject = map[prefix]; if (nestedObject == null) { return(find(map, key, indexOfBracket + 1)); } String remainingPart = key.Substring(indexOfEndBracket + 1); try { Object valueAtIndex; if (nestedObject is List <object> ) { valueAtIndex = ((List <object>)nestedObject)[arrayIndex]; } else if (nestedObject.GetType().IsArray) { valueAtIndex = ((Array)nestedObject).GetValue(arrayIndex); } else { // no way to extract from a non-array and non-list valueAtIndex = null; } if (valueAtIndex != null) { if (remainingPart.StartsWith(".")) { remainingPart = remainingPart.Substring(1); } if (remainingPart.IsEmpty()) { return(valueAtIndex); } if (valueAtIndex is Dictionary <object, object> ) { //@SuppressWarnings("unchecked") Dictionary <object, object> nestedMap = (Dictionary <object, object>)valueAtIndex; return(find(nestedMap, remainingPart)); } else { // not traversing any further. Should we want to add // support for double-sided arrays, we could do it here. } } } catch (NIndexOutOfBoundsException e) { return(null); } } return(null); } // find()