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 6B381200C6C for ; Fri, 5 May 2017 13:05:25 +0200 (CEST) Received: by cust-asf.ponee.io (Postfix) id 69E16160BAF; Fri, 5 May 2017 11:05:25 +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 AF1CB160B97 for ; Fri, 5 May 2017 13:05:24 +0200 (CEST) Received: (qmail 39099 invoked by uid 500); 5 May 2017 11:05:23 -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 39071 invoked by uid 99); 5 May 2017 11:05:23 -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 11:05:23 +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 288EAC0587 for ; Fri, 5 May 2017 11:05:23 +0000 (UTC) X-Virus-Scanned: Debian amavisd-new at spamd4-us-west.apache.org X-Spam-Flag: NO X-Spam-Score: 1.879 X-Spam-Level: * X-Spam-Status: No, score=1.879 tagged_above=-999 required=6.31 tests=[DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, HTML_MESSAGE=2, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H3=-0.01, RCVD_IN_MSPIKE_WL=-0.01, SPF_PASS=-0.001] autolearn=disabled Authentication-Results: spamd4-us-west.apache.org (amavisd-new); dkim=pass (2048-bit key) header.d=gmail.com Received: from mx1-lw-eu.apache.org ([10.40.0.8]) by localhost (spamd4-us-west.apache.org [10.40.0.11]) (amavisd-new, port 10024) with ESMTP id G4as2-7Lpq65 for ; Fri, 5 May 2017 11:05:20 +0000 (UTC) Received: from mail-ua0-f181.google.com (mail-ua0-f181.google.com [209.85.217.181]) by mx1-lw-eu.apache.org (ASF Mail Server at mx1-lw-eu.apache.org) with ESMTPS id 675B45F56A for ; Fri, 5 May 2017 11:05:20 +0000 (UTC) Received: by mail-ua0-f181.google.com with SMTP id z47so1448820uaz.0 for ; Fri, 05 May 2017 04:05:20 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:in-reply-to:references:from:date:message-id:subject:to; bh=cnl4qFAsbP/3+FfdM25I6saxiNt/ZaAILCUxK7A7Wh4=; b=YkeV6fr7SvcYyUsP/y0P9Z0T+xez34F+KG6it3b4ak9z2jfeO/llZ4oF46ODIokHtY lGg7yre8GhPtQ2ThazG56edgUb0KRTlrXGPD5tJnz0pDcas2DO79/4s2tOkZw8xXBPyk 1b1u7pJZV7fMshTumxlKXZNPWW2vrm63Ew6R/QMctPAacsAPiJ8a4OgcKX53TMrrOKS6 lSJC0zvJPUxVinczwoYxcoPL2//djqnwYPy6cTASrldBsrdSO4Igk7rFwYgYN6+n3Tkn 5hKsA2I/LObDMdep5o0qm6H4RMkakaokUOY20vRPta3mIvQY54Zl0eeyvcpWsEqmAxmh 0o6g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:in-reply-to:references:from:date :message-id:subject:to; bh=cnl4qFAsbP/3+FfdM25I6saxiNt/ZaAILCUxK7A7Wh4=; b=bG6umew8c4GjssKEpgCZvJnBqTYp7wzOdGLAAyU0pbL1et5JpcFY5rMcEYoMIecK4C Kueb2QyDzIHztTt3vhBgqVOOqUk+a7QoxOSc3VaS1c4ry41Rnq3z/8nZviOX3nr7Jf7i JhyEO1SgqmVEWCGn9s2VO0bfCcC4GAbNRf5RohOu3MLpoBuOVsz8T6Pdn10pdBcoI5w6 jjgE7PbQQMXe79cyXRTO5C5wfwTMNx6aExptUF4su/pYRNrBFTBCcFPxNuWsxdZWfiRw R42hwUsy47k6lYTk0hZLL/+Wh+zwvlZ2NcA+D4g+WF/0N7nH0wwPUT2VEUQNypxWdw5a N1Kw== X-Gm-Message-State: AN3rC/6g+Uwa76WyQsnwEldFcCPq3CP4uGE1OFja2TwiHLwD0Jxzs49e malmYwOiGrNSoI0/J8vet1oyFk8yIAqt X-Received: by 10.176.74.211 with SMTP id t19mr24846336uae.89.1493982313359; Fri, 05 May 2017 04:05:13 -0700 (PDT) MIME-Version: 1.0 Received: by 10.103.122.130 with HTTP; Fri, 5 May 2017 04:04:42 -0700 (PDT) In-Reply-To: References: From: Michael Gentry Date: Fri, 5 May 2017 07:04:42 -0400 Message-ID: Subject: Re: Read-only contexts? To: Cayenne Users Content-Type: multipart/alternative; boundary=f403045f8af216b18b054ec4dd5c archived-at: Fri, 05 May 2017 11:05:25 -0000 --f403045f8af216b18b054ec4dd5c Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable 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] On Fri, May 5, 2017 at 6:29 AM, Alexander wrote: > Hi, > > I searched for a while, but wasn=E2=80=99t able to find a solution to mak= e an > ObjectContext =E2=80=9Cread-only=E2=80=9D. > Maybe I'm missing something. > > The point is: > As suggested many times, there are situations where it makes sense to hav= e > a shared read-only ObjectContext and other ObjectContexts to commit chang= es. > I can certainly handle two and more ObjectContexts, but I need to lock ou= t > 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 > > --f403045f8af216b18b054ec4dd5c--