You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@openjpa.apache.org by pp...@apache.org on 2009/03/08 19:11:56 UTC

svn commit: r751487 - in /openjpa/trunk: openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/JDBCStoreManager.java openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/MySQLDictionary.java openjpa-project/src/doc/manual/ref_guide_dbsetup.xml

Author: ppoddar
Date: Sun Mar  8 18:11:55 2009
New Revision: 751487

URL: http://svn.apache.org/viewvc?rev=751487&view=rev
Log:
OPENJPA-966: Support MySQL Replication Driver

Modified:
    openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/JDBCStoreManager.java
    openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/MySQLDictionary.java
    openjpa/trunk/openjpa-project/src/doc/manual/ref_guide_dbsetup.xml

Modified: openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/JDBCStoreManager.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/JDBCStoreManager.java?rev=751487&r1=751486&r2=751487&view=diff
==============================================================================
--- openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/JDBCStoreManager.java (original)
+++ openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/JDBCStoreManager.java Sun Mar  8 18:11:55 2009
@@ -641,6 +641,11 @@
     }
 
     public Collection flush(Collection sms) {
+        try {
+            if (_conn != null && _conn.getInnermostDelegate().isReadOnly())
+                _conn.setReadOnly(false);
+        } catch (SQLException e) {
+        }
         return _conf.getUpdateManagerInstance().flush(sms, this);
     }
 

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=751487&r1=751486&r2=751487&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 Mar  8 18:11:55 2009
@@ -146,6 +146,13 @@
         }
     }
 
+    public Connection decorate(Connection conn)  throws SQLException {
+        String driver = conf.getConnectionDriverName();
+        if ("com.mysql.jdbc.ReplicationDriver".equals(driver))
+            conn.setReadOnly(true);
+        return conn;
+    }
+    
     private static int[] getMajorMinorVersions(String versionStr)
         throws IllegalArgumentException {
         int beginIndex = 0;

Modified: openjpa/trunk/openjpa-project/src/doc/manual/ref_guide_dbsetup.xml
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-project/src/doc/manual/ref_guide_dbsetup.xml?rev=751487&r1=751486&r2=751487&view=diff
==============================================================================
--- openjpa/trunk/openjpa-project/src/doc/manual/ref_guide_dbsetup.xml (original)
+++ openjpa/trunk/openjpa-project/src/doc/manual/ref_guide_dbsetup.xml Sun Mar  8 18:11:55 2009
@@ -3215,9 +3215,40 @@
 more info about <literal>deleteTableContents</literal>.) Defaults to
 <literal>false</literal>, since the statement may fail if using InnoDB
 tables and delete constraints.
-                    </para>
+                    </para>
+                    
                 </listitem>
-            </itemizedlist>
+            </itemizedlist>
+            
+                    <para>
+Starting with Connector/J 3.1.7, MySQL supports a variant of the driver 
+<literal>com.mysql.jdbc.ReplicationDriver</literal> that automatically sends 
+queries to a read/write master, or a failover or round-robin load balanced set 
+of slaves based on the state of read-only status of the connection. 
+See  <ulink url="http://dev.mysql.com/doc/refman/5.1/en/connector-j-reference-replication-connection.html">
+MySQL Reference</ulink> for more details. 
+                    </para>
+                    <para>
+This replication feature can be used transparently with OpenJPA application by
+following configuration:
+                    </para>
+        <itemizedlist>
+           <listitem>
+             <para>
+<literal>openjpa.ConnectionDriverName: com.mysql.jdbc.ReplicationDriver</literal>
+             </para>
+           </listitem>
+           <listitem>
+             <para>
+<literal>openjpa.ConnectionFactoryProperties: autoReconnect=true,roundRobinLoadBalance=true</literal>
+             </para>
+             <para>
+OpenJPA will use a read-only connection with replicated database configuration
+and will automatically switch the connection to a non-readonly mode if the
+transaction is writing to the database.             
+             </para>
+           </listitem>
+         </itemizedlist>
         </section>
         <section id="ref_guide_dbsetup_dbsupport_oracle">
             <title>