From: <ms...@us...> - 2008-10-31 00:05:18
|
Revision: 8514 http://wonder.svn.sourceforge.net/wonder/?rev=8514&view=rev Author: mschrag Date: 2008-10-31 00:03:08 +0000 (Fri, 31 Oct 2008) Log Message: ----------- support for String or EOSQLExpression custom query hints + switch to use the constant instead of the String Modified Paths: -------------- trunk/Wonder/Frameworks/Core/ERExtensions/Sources/er/extensions/batching/ERXBatchingDisplayGroup.java trunk/Wonder/Frameworks/Core/ERExtensions/Sources/er/extensions/eof/ERXEOControlUtilities.java trunk/Wonder/Frameworks/Core/ERExtensions/Sources/er/extensions/jdbc/ERXSQLHelper.java Modified: trunk/Wonder/Frameworks/Core/ERExtensions/Sources/er/extensions/batching/ERXBatchingDisplayGroup.java =================================================================== --- trunk/Wonder/Frameworks/Core/ERExtensions/Sources/er/extensions/batching/ERXBatchingDisplayGroup.java 2008-10-30 19:48:12 UTC (rev 8513) +++ trunk/Wonder/Frameworks/Core/ERExtensions/Sources/er/extensions/batching/ERXBatchingDisplayGroup.java 2008-10-31 00:03:08 UTC (rev 8514) @@ -8,6 +8,7 @@ import com.webobjects.eoaccess.EOEntity; import com.webobjects.eoaccess.EOModel; import com.webobjects.eoaccess.EOModelGroup; +import com.webobjects.eoaccess.EOSQLExpression; import com.webobjects.eoaccess.EOUtilities; import com.webobjects.eocontrol.EOAndQualifier; import com.webobjects.eocontrol.EODataSource; @@ -335,7 +336,8 @@ EOModel model = EOModelGroup.defaultGroup().entityNamed(spec.entityName()).model(); ERXSQLHelper sqlHelper = ERXSQLHelper.newSQLHelper(ec, model.name()); - String sql = (String) spec.hints().valueForKey("EOCustomQueryExpressionHintKey"); + Object hint = spec.hints().valueForKey(EODatabaseContext.CustomQueryExpressionHintKey); + String sql = sqlHelper.customQueryExpressionHintAsString(sqlHelper); sql = sqlHelper.limitExpressionForSQL(null, spec, sql, start, end); result = EOUtilities.rawRowsForSQL(ec, model.name(), sql, null); } Modified: trunk/Wonder/Frameworks/Core/ERExtensions/Sources/er/extensions/eof/ERXEOControlUtilities.java =================================================================== --- trunk/Wonder/Frameworks/Core/ERExtensions/Sources/er/extensions/eof/ERXEOControlUtilities.java 2008-10-30 19:48:12 UTC (rev 8513) +++ trunk/Wonder/Frameworks/Core/ERExtensions/Sources/er/extensions/eof/ERXEOControlUtilities.java 2008-10-31 00:03:08 UTC (rev 8514) @@ -550,7 +550,7 @@ */ public static NSArray objectsInRange(EOEditingContext ec, EOFetchSpecification spec, int start, int end) { EOSQLExpression sql = ERXEOAccessUtilities.sqlExpressionForFetchSpecification(ec, spec, start, end); - NSDictionary<String, EOSQLExpression> hints = new NSDictionary<String, EOSQLExpression>(sql, "EOCustomQueryExpressionHintKey"); + NSDictionary<String, EOSQLExpression> hints = new NSDictionary<String, EOSQLExpression>(sql, EODatabaseContext.CustomQueryExpressionHintKey); spec.setHints(hints); return ec.objectsWithFetchSpecification(spec); @@ -574,7 +574,7 @@ spec.setFetchesRawRows(true); spec.setRawRowKeyPaths(pkNames); EOSQLExpression sql = ERXEOAccessUtilities.sqlExpressionForFetchSpecification(ec, spec, start, end); - NSDictionary<String, EOSQLExpression> hints = new NSDictionary<String, EOSQLExpression>(sql, "EOCustomQueryExpressionHintKey"); + NSDictionary<String, EOSQLExpression> hints = new NSDictionary<String, EOSQLExpression>(sql, EODatabaseContext.CustomQueryExpressionHintKey); spec.setHints(hints); return ec.objectsWithFetchSpecification(spec); } Modified: trunk/Wonder/Frameworks/Core/ERExtensions/Sources/er/extensions/jdbc/ERXSQLHelper.java =================================================================== --- trunk/Wonder/Frameworks/Core/ERExtensions/Sources/er/extensions/jdbc/ERXSQLHelper.java 2008-10-30 19:48:12 UTC (rev 8513) +++ trunk/Wonder/Frameworks/Core/ERExtensions/Sources/er/extensions/jdbc/ERXSQLHelper.java 2008-10-31 00:03:08 UTC (rev 8514) @@ -567,6 +567,29 @@ } /** + * Returns the custom query expression hint as a String. At the moment, if it's an EOSQLExpression, it just returns .statement(). + * + * @param hint the hint to convert to a String + * @return the hint as a String + */ + public String customQueryExpressionHintAsString(Object hint) { + String sql; + if (hint instanceof String) { + sql = (String) hint; + } + else if (hint instanceof EOSQLExpression) { + sql = ((EOSQLExpression)hint).statement(); + if (sql == null) { + throw new IllegalArgumentException("This EOSQLExpression's statement was null (" + hint + ")."); + } + } + else { + sql = null; + } + return sql; + } + + /** * Creates the SQL which is used by the provided EOFetchSpecification, * limited by the given range. * @@ -609,7 +632,8 @@ 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)) { - sql = (String)spec.hints().valueForKey(EODatabaseContext.CustomQueryExpressionHintKey); + Object hint = spec.hints().valueForKey(EODatabaseContext.CustomQueryExpressionHintKey); + sql = customQueryExpressionHintAsString(hint); } if (end >= 0) { sql = limitExpressionForSQL(sqlExpr, spec, sql, start, end); @@ -1095,7 +1119,9 @@ } else { // we have hints - sql = (String) spec.hints().valueForKey("EOCustomQueryExpressionHintKey"); + Object hint = spec.hints().valueForKey(EODatabaseContext.CustomQueryExpressionHintKey); + sql = ERXSQLHelper.newSQLHelper(model).customQueryExpressionHintAsString(hint); + // MS: This looks super sketchy ... if (sql.endsWith(";")) { sql = sql.substring(0, sql.length() - 1); } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |