openjpa-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mtyle...@apache.org
Subject svn commit: r782362 - in /openjpa/trunk: openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/conf/ openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/ openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/conf/ openjpa-project/src/doc/manual/
Date Sun, 07 Jun 2009 10:55:00 GMT
Author: mtylenda
Date: Sun Jun  7 10:54:59 2009
New Revision: 782362

URL: http://svn.apache.org/viewvc?rev=782362&view=rev
Log:
OPENJPA-1123: MySQL query hints support

Modified:
    openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/conf/JDBCProductDerivation.java
    openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/MySQLDictionary.java
    openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/conf/TestQueryHints.java
    openjpa/trunk/openjpa-project/src/doc/manual/jpa_overview_query.xml
    openjpa/trunk/openjpa-project/src/doc/manual/supported_databases.xml

Modified: openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/conf/JDBCProductDerivation.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/conf/JDBCProductDerivation.java?rev=782362&r1=782361&r2=782362&view=diff
==============================================================================
--- openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/conf/JDBCProductDerivation.java
(original)
+++ openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/conf/JDBCProductDerivation.java
Sun Jun  7 10:54:59 2009
@@ -19,12 +19,14 @@
 package org.apache.openjpa.jdbc.conf;
 
 import java.util.Collections;
+import java.util.HashSet;
 import java.util.Map;
 import java.util.Set;
 
 import org.apache.openjpa.conf.BrokerFactoryValue;
 import org.apache.openjpa.conf.OpenJPAProductDerivation;
 import org.apache.openjpa.jdbc.kernel.JDBCBrokerFactory;
+import org.apache.openjpa.jdbc.sql.MySQLDictionary;
 import org.apache.openjpa.jdbc.sql.OracleDictionary;
 import org.apache.openjpa.lib.conf.AbstractProductDerivation;
 import org.apache.openjpa.lib.conf.ConfigurationProvider;
@@ -35,6 +37,14 @@
 public class JDBCProductDerivation extends AbstractProductDerivation
     implements OpenJPAProductDerivation {
 
+    private static Set<String> supportedQueryHints = new HashSet<String>(2);
+
+    static {
+        supportedQueryHints.add(MySQLDictionary.SELECT_HINT);
+        supportedQueryHints.add(OracleDictionary.SELECT_HINT);
+        supportedQueryHints = Collections.unmodifiableSet(supportedQueryHints);
+    }
+
     public void putBrokerFactoryAliases(Map m) {
         m.put("jdbc", JDBCBrokerFactory.class.getName());
     }
@@ -54,6 +64,6 @@
     
     @Override
     public Set<String> getSupportedQueryHints() {
-        return Collections.singleton(OracleDictionary.SELECT_HINT);
+        return supportedQueryHints;
     }
 }

Modified: openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/MySQLDictionary.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/MySQLDictionary.java?rev=782362&r1=782361&r2=782362&view=diff
==============================================================================
--- openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/MySQLDictionary.java
(original)
+++ openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/MySQLDictionary.java
Sun Jun  7 10:54:59 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;
@@ -39,6 +40,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.
      */
@@ -314,5 +317,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/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/conf/TestQueryHints.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/conf/TestQueryHints.java?rev=782362&r1=782361&r2=782362&view=diff
==============================================================================
--- openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/conf/TestQueryHints.java
(original)
+++ openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/conf/TestQueryHints.java
Sun Jun  7 10:54:59 2009
@@ -21,6 +21,7 @@
 import javax.persistence.EntityManager;
 import javax.persistence.Query;
 
+import org.apache.openjpa.jdbc.sql.MySQLDictionary;
 import org.apache.openjpa.jdbc.sql.OracleDictionary;
 import org.apache.openjpa.kernel.QueryHints;
 import org.apache.openjpa.persistence.HintHandler;
@@ -48,6 +49,7 @@
     
     public void testSupportedHintsContainProductDerivationHints() {
         assertSupportedHint(OracleDictionary.SELECT_HINT, true);
+        assertSupportedHint(MySQLDictionary.SELECT_HINT, true);
     }
     
     public void testSupportedHintsContainFetchPlanHints() {
@@ -182,10 +184,10 @@
     
     void assertSupportedHint(String hint, boolean contains) {
         if (contains)
-            assertTrue("Expeceted suppoerted hint [" + hint + "]",
+            assertTrue("Expected supported hint [" + hint + "]",
                 query.getSupportedHints().contains(hint));
         else
-            assertFalse("Unexpeceted suppoerted hint [" + hint + "]",
+            assertFalse("Unexpected supported hint [" + hint + "]",
                 query.getSupportedHints().contains(hint));
     }
     

Modified: openjpa/trunk/openjpa-project/src/doc/manual/jpa_overview_query.xml
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-project/src/doc/manual/jpa_overview_query.xml?rev=782362&r1=782361&r2=782362&view=diff
==============================================================================
--- openjpa/trunk/openjpa-project/src/doc/manual/jpa_overview_query.xml (original)
+++ openjpa/trunk/openjpa-project/src/doc/manual/jpa_overview_query.xml Sun Jun  7 10:54:59
2009
@@ -787,10 +787,14 @@
             </section>
             <section>
                 <title>
-                    Oracle Query Hints
+                    Database-Specific Hints
                 </title>
                 <para>
-The hint name &quot;openjpa.hint.OracleSelectHint&quot; 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 &quot;openjpa.hint.MySQLSelectHint&quot; and
+&quot;openjpa.hint.OracleSelectHint&quot; 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/trunk/openjpa-project/src/doc/manual/supported_databases.xml
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-project/src/doc/manual/supported_databases.xml?rev=782362&r1=782361&r2=782362&view=diff
==============================================================================
--- openjpa/trunk/openjpa-project/src/doc/manual/supported_databases.xml (original)
+++ openjpa/trunk/openjpa-project/src/doc/manual/supported_databases.xml Sun Jun  7 10:54:59
2009
@@ -773,6 +773,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



Mime
View raw message