Return-Path: Delivered-To: apmail-cayenne-user-archive@www.apache.org Received: (qmail 67317 invoked from network); 10 Feb 2009 07:05:38 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.2) by minotaur.apache.org with SMTP; 10 Feb 2009 07:05:38 -0000 Received: (qmail 85772 invoked by uid 500); 10 Feb 2009 07:05:37 -0000 Delivered-To: apmail-cayenne-user-archive@cayenne.apache.org Received: (qmail 85601 invoked by uid 500); 10 Feb 2009 07:05:36 -0000 Mailing-List: contact user-help@cayenne.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: user@cayenne.apache.org Delivered-To: mailing list user@cayenne.apache.org Received: (qmail 85589 invoked by uid 99); 10 Feb 2009 07:05:36 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 09 Feb 2009 23:05:36 -0800 X-ASF-Spam-Status: No, hits=1.2 required=10.0 tests=FS_REPLICA,SPF_PASS X-Spam-Check-By: apache.org Received-SPF: pass (athena.apache.org: local policy) Received: from [208.78.103.231] (HELO vorsha.objectstyle.org) (208.78.103.231) by apache.org (qpsmtpd/0.29) with SMTP; Tue, 10 Feb 2009 07:05:27 +0000 Received: (qmail 20295 invoked from network); 10 Feb 2009 07:05:04 -0000 Received: from unknown (HELO ?IPv6:::1?) (127.0.0.1) by localhost with SMTP; 10 Feb 2009 07:05:04 -0000 Message-Id: From: Andrus Adamchik To: user@cayenne.apache.org In-Reply-To: <4990B690.1020309@nitido.com> Content-Type: text/plain; charset=US-ASCII; format=flowed; delsp=yes Content-Transfer-Encoding: 7bit Mime-Version: 1.0 (Apple Message framework v930.3) Subject: Re: Cayenne + master/slave mysql database replication Date: Tue, 10 Feb 2009 09:05:03 +0200 References: <49908F7B.6010201@tamu.edu> <4990B690.1020309@nitido.com> X-Mailer: Apple Mail (2.930.3) X-Virus-Checked: Checked by ClamAV on apache.org Interesting... I am using a similar setup with MySQL (a master and a bunch of slaves), however we split the code into read-only and read/ write webapp modules and use separate URL's for each type. In addition to proper load balancing, this adds a layer of security (apps that are read-only are guaranteed to have no write access even if there are programming errors that result in write attempts). Of course this is not as generic (for instance I'd like my read-write apps to still read from slaves). To handle it the way MySQL describes it, the simplest way is to create a custom "replicating adapter" that is a subclass of MySQLAdapter, and override 'getAction'. There's a few helper classes involved there (MySQLActionBuilder, ...), but the goal is to override MySQLSelectAction to call "connection.setReadOnly" before execution. If you are using SQLTemplates or ProcedureQueries, the approach is similar, only you'll need to analyze the contents of the query to decide whether this is a select or update. We may include this in Cayenne at some point, but as demonstrated above, it should be easy to do it as a custom extension. Andrus On Feb 10, 2009, at 1:04 AM, Michael Shea wrote: > Hi guys, > > I am currently using Cayenne 3.0M4 in a web application, using a > MySQL database. > > I have been asked to modify the application so that we can perform > reads from one of N slave database servers, but writes will occur > only on one master database server. > > Is it possible to do this with Cayenne? Anyone know how? =) > > I've looked at this briefly: > http://dev.mysql.com/doc/refman/5.0/en/connector-j-reference-replication-connection.html > > ... So it looks like I could configure a JNDI datasource that > represents the master + all the slaves pretty easily. I just don't > know how to get Cayenne to call "connection.setReadOnly(...)" as > necessary. > > > Thanks! > > > Mike Shea. >