/** * Parses the path properties string returning the parsed properties and options. * In general it is comma delimited with some special strings like +lazy(20). */ public static Response parse(String rawProperties) { return new OrmQueryPropertiesParser(rawProperties).parse(); }
/** * Parse the raw string properties input. */ private Response parse() { if (inputProperties == null || inputProperties.isEmpty()) { return EMPTY; } int pos = inputProperties.indexOf("+readonly"); if (pos > -1) { inputProperties = StringHelper.replaceString(inputProperties, "+readonly", ""); readOnly = true; } pos = inputProperties.indexOf("+cache"); if (pos > -1) { inputProperties = StringHelper.replaceString(inputProperties, "+cache", ""); cache = true; } pos = inputProperties.indexOf("+query"); if (pos > -1) { queryFetchBatch = parseBatchHint(pos, "+query"); } pos = inputProperties.indexOf("+lazy"); if (pos > -1) { lazyFetchBatch = parseBatchHint(pos, "+lazy"); } LinkedHashSet<String> included = parseIncluded(); String properties = (allProperties) ? "*" : outputProperties; return new Response(readOnly, cache, queryFetchBatch, lazyFetchBatch, properties, included); }
public OrmQueryProperties(String path, String rawProperties, FetchConfig fetchConfig) { OrmQueryPropertiesParser.Response response = OrmQueryPropertiesParser.parse(rawProperties); this.path = path; this.parentPath = SplitName.parent(path); this.rawProperties = rawProperties; this.trimmedProperties = response.properties; this.included = response.included; this.cache = response.cache; this.readOnly = response.readOnly; if (fetchConfig != null) { this.fetchConfig = fetchConfig; } else { this.fetchConfig = response.fetchConfig; } }
private int parseBatchHint(int pos, String option) { int startPos = pos + option.length(); int endPos = findEndPos(startPos, inputProperties); if (endPos == -1) { inputProperties = StringHelper.replaceString(inputProperties, option, ""); return 0; } else { String batchParam = inputProperties.substring(startPos + 1, endPos); if (endPos + 1 >= inputProperties.length()) { inputProperties = inputProperties.substring(0, pos); } else { inputProperties = inputProperties.substring(0, pos) + inputProperties.substring(endPos + 1); } return Integer.parseInt(batchParam); } }