EOAdaptor adaptor = EOAdaptor.adaptorWithModel(model); EODatabase db = new EODatabase(adaptor);
EODatabaseContext dbc = EOUtilities.databaseContextForModelNamed(ec, model.name()); EOAdaptor adaptor = dbc.adaptorContext().adaptor();
    public static EOSQLExpression sqlExpressionForFetchSpecification(EOEditingContext ec, EOFetchSpecification spec, long start, long end) {        EOEntity entity = ERXEOAccessUtilities.entityNamed(ec, spec.entityName());        EOModel model = entity.model();        EOAdaptor adaptor = EOAdaptor.adaptorWithModel(model);        EODatabase db = new EODatabase(adaptor);        EOSQLExpressionFactory sqlFactory = adaptor.expressionFactory();        NSArray attributes = spec.rawRowKeyPaths();        if (attributes == null || attributes.count() == 0) attributes = entity.attributesToFetch();        EOSQLExpression sqlExpr = sqlFactory.selectStatementForAttributes(attributes, false, spec, entity);        String sql = sqlExpr.statement();        if (end >= 0) {            String url = (String) model.connectionDictionary().objectForKey("URL");            if (url != null) {                if (url.toLowerCase().indexOf("frontbase") != -1) {                    //add TOP(start, (end - start)) after the SELECT word                    int index = sql.indexOf("select");                    if (index == -1) {                        index = sql.indexOf("SELECT");                    }                    index += 6;                    //FIXME: this works for frontbase, might need to be                    // adjusted for other db servers!                    StringBuffer buf = new StringBuffer();                    buf.append(sql.substring(0, index)).append(" TOP(").append(start).append(",").append(end - start).append(") ").append(                            sql.substring(index + 1, sql.length()));                    sql = buf.toString();                } else if (url.toLowerCase().indexOf("openbase") != -1) { // Openbase support for limiting result set                    sql += " return results " + start + " to " + end;                } else if (url.toLowerCase().indexOf("mysql") != -1) {                    sql += " LIMIT " + start + ", " + (end - start);                }            }            sqlExpr.setStatement(sql);        }        return sqlExpr;    }