OPENJPA-966: Support MySQL Replication Driver

git-svn-id: https://svn.apache.org/repos/asf/openjpa/trunk@751487 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Pinaki Poddar 2009-03-08 18:11:55 +00:00
parent f1d4abda25
commit 23b0b87674
3 changed files with 45 additions and 2 deletions

View File

@ -641,6 +641,11 @@ public class JDBCStoreManager
}
public Collection flush(Collection sms) {
try {
if (_conn != null && _conn.getInnermostDelegate().isReadOnly())
_conn.setReadOnly(false);
} catch (SQLException e) {
}
return _conf.getUpdateManagerInstance().flush(sms, this);
}

View File

@ -146,6 +146,13 @@ public class MySQLDictionary
}
}
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;

View File

@ -3216,6 +3216,37 @@ more info about <literal>deleteTableContents</literal>.) Defaults to
<literal>false</literal>, since the statement may fail if using InnoDB
tables and delete constraints.
</para>
</listitem>
</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>