public EOSQLExpression sqlExpressionForFetchSpecification(EOEditingContext ec, EOFetchSpecification spec, long start, long end, NSArray<EOAttribute> attributes) {
EOEntity entity = ERXEOAccessUtilities.entityNamed(ec, spec.entityName());
EOModel model = entity.model();
EODatabaseContext dbc = EOUtilities.databaseContextForModelNamed(ec, model.name());
EOAdaptor adaptor = dbc.adaptorContext().adaptor();
EOSQLExpressionFactory sqlFactory = adaptor.expressionFactory();
spec = (EOFetchSpecification) spec.clone();
EOQualifier qualifier = spec.qualifier();
if (qualifier != null) {
qualifier = EOQualifierSQLGeneration.Support._schemaBasedQualifierWithRootEntity(qualifier, entity);
}
if (qualifier != spec.qualifier()) {
spec.setQualifier(qualifier);
}
if (spec.fetchLimit() > 0) {
spec.setFetchLimit(0);
spec.setPromptsAfterFetchLimit(false);
}
spec = ERXEOAccessUtilities.localizeFetchSpecification(ec, spec);
if (attributes == null) {
attributes = attributesToFetchForEntity(spec, entity);
}
EOSQLExpression sqlExpr = sqlFactory.selectStatementForAttributes(attributes, false, spec, entity);
String sql = sqlExpr.statement();
if (spec.hints() != null && !spec.hints().isEmpty() && spec.hints().valueForKey(EODatabaseContext.CustomQueryExpressionHintKey) != null) {
Object hint = spec.hints().valueForKey(EODatabaseContext.CustomQueryExpressionHintKey);
sql = customQueryExpressionHintAsString(hint);
}