Return-Path: X-Original-To: archive-asf-public-internal@cust-asf2.ponee.io Delivered-To: archive-asf-public-internal@cust-asf2.ponee.io Received: from cust-asf.ponee.io (cust-asf.ponee.io [163.172.22.183]) by cust-asf2.ponee.io (Postfix) with ESMTP id 76CC7200C6C for ; Fri, 5 May 2017 15:19:27 +0200 (CEST) Received: by cust-asf.ponee.io (Postfix) id 754DD160BAF; Fri, 5 May 2017 13:19:27 +0000 (UTC) Delivered-To: archive-asf-public@cust-asf.ponee.io Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by cust-asf.ponee.io (Postfix) with SMTP id B96C4160B97 for ; Fri, 5 May 2017 15:19:26 +0200 (CEST) Received: (qmail 65926 invoked by uid 500); 5 May 2017 13:19:25 -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 65914 invoked by uid 99); 5 May 2017 13:19:25 -0000 Received: from pnap-us-west-generic-nat.apache.org (HELO spamd4-us-west.apache.org) (209.188.14.142) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 05 May 2017 13:19:25 +0000 Received: from localhost (localhost [127.0.0.1]) by spamd4-us-west.apache.org (ASF Mail Server at spamd4-us-west.apache.org) with ESMTP id 3A7E9C0587 for ; Fri, 5 May 2017 13:19:25 +0000 (UTC) X-Virus-Scanned: Debian amavisd-new at spamd4-us-west.apache.org X-Spam-Flag: NO X-Spam-Score: 2.174 X-Spam-Level: ** X-Spam-Status: No, score=2.174 tagged_above=-999 required=6.31 tests=[DKIM_ADSP_CUSTOM_MED=0.001, FROM_MISSPACED=0.001, NML_ADSP_CUSTOM_MED=1.2, SPF_SOFTFAIL=0.972] autolearn=disabled Received: from mx1-lw-us.apache.org ([10.40.0.8]) by localhost (spamd4-us-west.apache.org [10.40.0.11]) (amavisd-new, port 10024) with ESMTP id fHRNNqn6N7F4 for ; Fri, 5 May 2017 13:19:23 +0000 (UTC) Received: from mailrelay1-us-west.apache.org (mailrelay1-us-west.apache.org [209.188.14.139]) by mx1-lw-us.apache.org (ASF Mail Server at mx1-lw-us.apache.org) with ESMTP id 120645F1BA for ; Fri, 5 May 2017 13:19:23 +0000 (UTC) Received: from localhost (cust-asf.ponee.io [163.172.22.183]) by mailrelay1-us-west.apache.org (ASF Mail Server at mailrelay1-us-west.apache.org) with ESMTP id 3B5CFE0045 for ; Fri, 5 May 2017 13:19:22 +0000 (UTC) MIME-Version: 1.0 Message-ID: Subject: Re: Read-only contexts? References: From: "Alexander" In-Reply-To: Content-Type: text/plain; charset="iso-8859-1" x-ponymail-sender: 5fc56de2e301e0040eebdead2758ab1b532b4e5a Date: Fri, 05 May 2017 13:19:21 -0000 x-ponymail-agent: PonyMail Composer/0.2 To: X-Mailer: LuaSocket 3.0-rc1 archived-at: Fri, 05 May 2017 13:19:27 -0000 Hi, thank you and Maik for answering so fast. You saved me a lot of time searching around for nothing. Your suggestion seems to be the right approach. I’d consider making the read-only flag in the ObjectContext final, as to prevent unintended changes. Therefore it has to be set in the ObjectContext’s constructor. A fail fast behavior should be considered for nested ObjectContexts, i.e. commitChangesToParent() should check the parent’s read-only flag, unless the nested context’s read-only flag is copied from the parent on instantiation (in this case ObjectContextFactory class has to be changed too).. Let’s hope this feature will be added before 4.0 final. For now subclassing is a good option. Thanks again Alexander On 2017-05-05 13:08 (+0200), Michael Gentry wrote: > #2 should've read: > > 2. Alter CayenneDataObject to check the entity's read-only status AND the > context's read-only status. (Change writeProperty(), etc.) If either is > read-only and you are trying to sneak a change in, throw an exception. > > mrg > > > On Fri, May 5, 2017 at 7:04 AM, Michael Gentry wrote: > > > Hi Alexander, > > > > I don't believe what you are asking for is currently doable, even in the > > latest 4.0 milestone release. > > > > An ObjectContext doesn't know anything about read-only. You can make a > > Cayenne object read-only in Cayenne Modeler, however this just omits > > setter-type methods. CayenneDataObject, which all Cayenne database objects > > inherit from, doesn't actually restrict setting values if you flag it as > > read-only in the modeler. You can directly call writeProperty(), > > writePropertyDirectly(), removeToManyTarget(), etc on the objects. > > > > I think this feature would be fairly easy to add (the information is > > already in the model's XML files [1]), so perhaps it could be added before > > 4.0 final. > > > > I'd suggest: > > > > 1. Add a read-only flag to DataContext and friends. If you call > > commitChanges() on a read-only context, throw an exception. > > 2. Alter each CayenneDataObject which modifies data (writeProperty(), etc) > > to check the entity's read-only status AND the context's read-only status. > > If either is read-only and you are trying to sneak a change in, throw an > > exception. > > > > Does this sound like the right approach (to you and other Cayenne users)? > > > > As to your localObject() question, I think it should adhere to the 1/2 > > semantics I just mentioned. > > Thanks, > > > > mrg > > > > [1] > dbEntityName="..." superClassName="..."> > > > > > > > > On Fri, May 5, 2017 at 6:29 AM, Alexander wrote: > > > >> Hi, > >> > >> I searched for a while, but wasn’t able to find a solution to make an > >> ObjectContext “read-only”. > >> Maybe I'm missing something. > >> > >> The point is: > >> As suggested many times, there are situations where it makes sense to > >> have a shared read-only ObjectContext and other ObjectContexts to commit > >> changes. > >> I can certainly handle two and more ObjectContexts, but I need to lock > >> out other users / applications which can somehow gain access to persistent > >> objects instantiated through the assumed read-only shared context, since > >> any application that has access to such objects (maybe obtained from a > >> service class that is expected to return read-only objects) could simply > >> call object.getObjectContext().commitChanges(). By the way, this would > >> also commit unwanted temporary changes that happen elsewhere in the main > >> application or in the service class. > >> > >> Is there a method like CONTEXT.makeReadOnly() to make sure that any > >> objects that resides in this specific ObjectContext cannot be changed? > >> Even better, is there a way to let persistent objects, that are bound to > >> a read-only context, throw an exception? > >> > >> Should this be possible, there is only one question left: would it still > >> be possible to transfer objects retrieved through a read-only > >> ObjectContext to a read-write ObjectContext, by calling > >> localObject(readWriteContext)? > >> > >> Any help would be greatly appreciated. > >> Alexander > >> > >> > > >