Author: mtylenda
Date: Sun Jun 7 11:02:12 2009
New Revision: 782364
URL: http://svn.apache.org/viewvc?rev=782364&view=rev
Log:
OPENJPA-1123: MySQL query hints support
Modified:
openjpa/branches/1.3.x/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/MySQLDictionary.java
openjpa/branches/1.3.x/openjpa-project/src/doc/manual/jpa_overview_query.xml
openjpa/branches/1.3.x/openjpa-project/src/doc/manual/supported_databases.xml
Modified:
openjpa/branches/1.3.x/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/MySQLDictionary.java
URL:
http://svn.apache.org/viewvc/openjpa/branches/1.3.x/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/MySQLDictionary.java?rev=782364&r1=782363&r2=782364&view=diff
==============================================================================
---
openjpa/branches/1.3.x/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/MySQLDictionary.java
(original)
+++
openjpa/branches/1.3.x/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/MySQLDictionary.java
Sun Jun 7 11:02:12 2009
@@ -26,6 +26,7 @@
import java.util.Arrays;
import org.apache.commons.lang.StringUtils;
+import org.apache.openjpa.jdbc.kernel.JDBCFetchConfiguration;
import org.apache.openjpa.jdbc.kernel.JDBCStore;
import org.apache.openjpa.jdbc.kernel.exps.FilterValue;
import org.apache.openjpa.jdbc.schema.Column;
@@ -40,6 +41,8 @@
public class MySQLDictionary
extends DBDictionary {
+ public static final String SELECT_HINT = "openjpa.hint.MySQLSelectHint";
+
/**
* The MySQL table type to use when creating tables; defaults to innodb.
*/
@@ -313,5 +316,18 @@
public int getBatchFetchSize(int batchFetchSize) {
return Integer.MIN_VALUE;
}
-
+
+ /**
+ * Check to see if we have set the {...@link #SELECT_HINT} in the
+ * fetch configuration, and if so, append the MySQL hint after the
+ * "SELECT" part of the query.
+ */
+ @Override
+ public String getSelectOperation(JDBCFetchConfiguration fetch) {
+ Object hint = fetch == null ? null : fetch.getHint(SELECT_HINT);
+ String select = "SELECT";
+ if (hint != null)
+ select += " " + hint;
+ return select;
+ }
}
Modified:
openjpa/branches/1.3.x/openjpa-project/src/doc/manual/jpa_overview_query.xml
URL:
http://svn.apache.org/viewvc/openjpa/branches/1.3.x/openjpa-project/src/doc/manual/jpa_overview_query.xml?rev=782364&r1=782363&r2=782364&view=diff
==============================================================================
---
openjpa/branches/1.3.x/openjpa-project/src/doc/manual/jpa_overview_query.xml
(original)
+++
openjpa/branches/1.3.x/openjpa-project/src/doc/manual/jpa_overview_query.xml
Sun Jun 7 11:02:12 2009
@@ -765,10 +765,14 @@
</section>
<section>
<title>
- Oracle Query Hints
+ Database-Specific Hints
</title>
<para>
-The hint name "openjpa.hint.OracleSelectHint" can be used to specify
a string value of an Oracle query hint that will inserted into sql for an
Oracle database.See <xref linkend="dbsupport_oracle_query_hints"/> for an
example.
+The hint names "openjpa.hint.MySQLSelectHint" and
+"openjpa.hint.OracleSelectHint" can be used to specify a string value
+of a query hint that will be inserted into sql for MySQL and Oracle databases.
+See <xref linkend="dbsupport_mysql_query_hints"/> and
+<xref linkend="dbsupport_oracle_query_hints"/> for examples.
</para>
</section>
<section id="jpa_hints_named">
Modified:
openjpa/branches/1.3.x/openjpa-project/src/doc/manual/supported_databases.xml
URL:
http://svn.apache.org/viewvc/openjpa/branches/1.3.x/openjpa-project/src/doc/manual/supported_databases.xml?rev=782364&r1=782363&r2=782364&view=diff
==============================================================================
---
openjpa/branches/1.3.x/openjpa-project/src/doc/manual/supported_databases.xml
(original)
+++
openjpa/branches/1.3.x/openjpa-project/src/doc/manual/supported_databases.xml
Sun Jun 7 11:02:12 2009
@@ -771,6 +771,29 @@
openjpa.ConnectionURL: jdbc:mysql://SERVER_NAME/DB_NAME
</programlisting>
</example>
+ <section id="dbsupport_mysql_query_hints">
+ <title>
+ Using Query Hints with MySQL
+ </title>
+ <para>
+MySQL has support for "query hints", which are keywords embedded in
+SQL that provide some hint for how the query should be executed. These hints
are
+usually designed to provide suggestions to the MySQL query optimizer for how to
+efficiently perform a certain query, and aren't typically needed for any but
+the most intensive queries.
+OpenJPA supports hints to be placed between SELECT keyword and column list.
+ </para>
+ <example id="dbsupport_mysql_query_hints_ex">
+ <title>
+ Using MySQL Hints
+ </title>
+<programlisting>
+Query query = em.createQuery(...);
+query.setHint("openjpa.hint.MySQLSelectHint", "SQL_NO_CACHE");
+List results = query.getResultList();
+</programlisting>
+ </example>
+ </section>
<section id="dbsupport_mysql_issues">
<title>
Known issues with MySQL