logger.debug("Deserializing string [" + (String)o + "]");
try {
queryJSON = new JSONObject( (String)o );
} catch(Throwable t) {
logger.debug("Object to be deserialized must be string encoding a JSON object");
throw new SerializationException("An error occurred while deserializing query: " + (String)o, t);
}
} else if(o instanceof JSONObject) {
queryJSON = (JSONObject)o;
} else {
Assert.assertUnreachable("Object to be deserialized must be of type string or of type JSONObject, not of type [" + o.getClass().getName() + "]");
}
query = new Query();
try {
query.setId(queryJSON.getString(QuerySerializationConstants.ID));
query.setName(queryJSON.optString(QuerySerializationConstants.NAME));
query.setDescription(queryJSON.optString(QuerySerializationConstants.DESCRIPTION));
query.setDistinctClauseEnabled(queryJSON.optBoolean( QuerySerializationConstants.DISTINCT ));
// TODO: move this in AnalysisStateLoader class
try {
query.setNestedExpression(queryJSON.getBoolean( QuerySerializationConstants.IS_NESTED_EXPRESSION ));
} catch(Exception e) {
query.setNestedExpression(false);
}
fieldsJSON = queryJSON.getJSONArray( QuerySerializationConstants.FIELDS );
filtersJSON = queryJSON.getJSONArray( QuerySerializationConstants.FILTERS );
expressionJSON = queryJSON.getJSONObject( QuerySerializationConstants.EXPRESSION );
havingsJSON = queryJSON.getJSONArray( QuerySerializationConstants.HAVINGS );
subqueriesJSON = queryJSON.getJSONArray( QuerySerializationConstants.SUBQUERIES );
} catch (JSONException e) {
throw new SerializationException("An error occurred while deserializing query: " + queryJSON.toString(), e);
}
deserializeFields(fieldsJSON, dataSource, query);
deserializeFilters(filtersJSON, dataSource, query);
deserializeExpression(expressionJSON, dataSource, query);
deserializeHavings(havingsJSON, dataSource, query);
for(int i = 0; i < subqueriesJSON.length(); i++) {
try {
subquery = deserializeQuery(subqueriesJSON.get(i), dataSource);
} catch (JSONException e) {
throw new SerializationException("An error occurred while deserializing subquery number [" + (i+1) + "]: " + subqueriesJSON.toString(), e);
}
query.addSubquery(subquery);
}
} finally {