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 3E0DE200C10 for ; Fri, 20 Jan 2017 02:34:01 +0100 (CET) Received: by cust-asf.ponee.io (Postfix) id 3CAB1160B57; Fri, 20 Jan 2017 01:34:01 +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 869BA160B54 for ; Fri, 20 Jan 2017 02:34:00 +0100 (CET) Received: (qmail 35695 invoked by uid 500); 20 Jan 2017 01:33:59 -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 35682 invoked by uid 99); 20 Jan 2017 01:33:59 -0000 Received: from pnap-us-west-generic-nat.apache.org (HELO spamd3-us-west.apache.org) (209.188.14.142) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 20 Jan 2017 01:33:59 +0000 Received: from localhost (localhost [127.0.0.1]) by spamd3-us-west.apache.org (ASF Mail Server at spamd3-us-west.apache.org) with ESMTP id 07BE9185F35 for ; Fri, 20 Jan 2017 01:33:59 +0000 (UTC) X-Virus-Scanned: Debian amavisd-new at spamd3-us-west.apache.org X-Spam-Flag: NO X-Spam-Score: 0.379 X-Spam-Level: X-Spam-Status: No, score=0.379 tagged_above=-999 required=6.31 tests=[DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H3=-0.01, RCVD_IN_MSPIKE_WL=-0.01, RCVD_IN_SORBS_SPAM=0.5, SPF_PASS=-0.001] autolearn=disabled Authentication-Results: spamd3-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 (spamd3-us-west.apache.org [10.40.0.10]) (amavisd-new, port 10024) with ESMTP id V_Zox6Uj0PGq for ; Fri, 20 Jan 2017 01:33:57 +0000 (UTC) Received: from mail-yw0-f169.google.com (mail-yw0-f169.google.com [209.85.161.169]) by mx1-lw-eu.apache.org (ASF Mail Server at mx1-lw-eu.apache.org) with ESMTPS id 243CE5F282 for ; Fri, 20 Jan 2017 01:33:57 +0000 (UTC) Received: by mail-yw0-f169.google.com with SMTP id l19so60509615ywc.2 for ; Thu, 19 Jan 2017 17:33:57 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:content-transfer-encoding:mime-version:date:subject:message-id :references:in-reply-to:to; bh=ma0Lf2iMdP58pWHe/G1pp03X7e3ZPDD1usYPHDUoRYE=; b=Npa7rFGW0PFO35GXsNaJuMUJ62KOMgguk0bfVafSXUoi39jN/OoN4BGsTVaFn6hB7o kN3bmk0bj752BCrvAdbhwkn860olao+qfPtKwQhM+NAuYY18YR1s7poJRe9XEXTQ/34i eLJuvWKXO/0wTZpW1JSTR4cFX5QREYa/CLoCmoc0y46svsFzTPUh6kyLeC0VzISEpEzW n0mNDj+V1DZOPpX/y3pZH9Pi5Cbdbowx+LU+/YscQyHH85EFFxdTBJteFo8mJwLYFVKv vczt1Rcfk6vhndN/kr6FXB6SJPLsl8+CT3bn8o6FCeMNYiJ2CyBss7/yai2E/kXgTrUj Yomw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:content-transfer-encoding:mime-version:date :subject:message-id:references:in-reply-to:to; bh=ma0Lf2iMdP58pWHe/G1pp03X7e3ZPDD1usYPHDUoRYE=; b=RJpv9fxtkZbvTZshrTzdhLmla0Fjsv80dPdyG899olChvbFzQ8yV/2cTXXl6+8mZ1E LRsZ+BR21wQZHaCsaqwrXMhzyPRG4ME6ZctZzt++Z94PRvwMOISWl1A64qQmAl3ucFMX qblUmwrSe7bA3Q/5ayL0gzTETmGWdEeJiQr6IBoEz40UVaIUxRNvkb9OSH69gSruw1Qu vqV4nYkDiE0icM/tMcrzx/a3m6+tA53Cxrk8ejz9XvbAfTJrlUt0n5ksoG7Ck3o2eSGr 8N7VE8TIXGbIXiYh0N4AWPZlCrMYL9YS+t7BqaczEkLMlK3tzvR/pdBkmFl7Sbp000qK rD2Q== X-Gm-Message-State: AIkVDXJBWQGSKw5ZfEbYAkTCAPT3hKJCWHit9PBSp70/bA4XikrJT2GHHiZzDi4F4MQT6Q== X-Received: by 10.55.25.42 with SMTP id k42mr11300102qkh.297.1484876035368; Thu, 19 Jan 2017 17:33:55 -0800 (PST) Received: from ?IPv6:2604:2000:6089:69f0:9143:8828:8c9e:3a48? ([2604:2000:6089:69f0:9143:8828:8c9e:3a48]) by smtp.gmail.com with ESMTPSA id d52sm4645452qtc.2.2017.01.19.17.33.54 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 19 Jan 2017 17:33:54 -0800 (PST) From: Eric Schneider Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: quoted-printable Mime-Version: 1.0 (1.0) Date: Thu, 19 Jan 2017 20:33:54 -0500 Subject: Re: Dynamic mapping Message-Id: <45CA900F-60BB-4308-8850-3466F9B52EB4@gmail.com> References: <7D7E4AAC-1BBB-4A5D-A034-2969CB4A8A62@objectstyle.org> In-Reply-To: <7D7E4AAC-1BBB-4A5D-A034-2969CB4A8A62@objectstyle.org> To: user@cayenne.apache.org X-Mailer: iPhone Mail (14B100) archived-at: Fri, 20 Jan 2017 01:34:01 -0000 I'm glad somebody finally noticed it. :-) > On Jan 19, 2017, at 8:29 PM, Andrus Adamchik wrot= e: >=20 > TL;DR: Map relationships dynamically in a running app if you need to conne= ct multiple reusable ORM modules. >=20 > A longer version: >=20 > I'd often mention at various presentations that Cayenne supports generic o= bjects and you can create mapping in runtime. I didn't have many real-life e= xamples to demonstrate the need until now. But recently I encountered a good= use case that was solved by dynamic mapping - reusable ORM modules.=20 >=20 > Say I have a reusable lib.jar containing a Cayenne project and some persis= tent code built around it. Now I want to use it in app.jar (or app.war if yo= u are still on JavaEE). app.jar has its own Cayenne project, with entities t= hat need to reference entities in lib.jar. You can't relate them in the Mode= ler, short of unpacking lib.jar and reassembling a new project from both pro= jects (the level of effort with such approach would kill most of the benefit= s of reuse). >=20 > Consider that in runtime EntityResolver would contain entities from both l= ib and app, so all we need is to connect them. So instead of messing with XM= L files, we'd create a DataChannelFilter in app.jar with "init" method that b= uilds all needed relationships on the fly. Now we can access these relations= hips via generic DataObject API (on the app.jar side you can optionally crea= te regular type-safe getters and setters). I wrote a utility relationship bu= ilder that makes this code transparent: >=20 > Relationships.oneToOne("libEntity") > .between(AppEntity.class, LibEntity.class) > .toDepPK() > .joined(AppEntity.ID_PK_COLUMN, LibEntity.ID_PK_COLUMN) > .createReverse("appEntity") > .exec(resolver); >=20 > Needless to say that all this happens in a running application, and is not= limited to relationships. E.g. you can create flattened attributes instead.= >=20 > The implications are pretty exciting - you can write fully self-contained l= ibraries with Cayenne that can be easily extended (without unpacking) with m= ore tables, and otherwise integrated in app DB schemas. Dynamic mapping was t= he last missing piece of a puzzle in a modular CMS design that I am working o= n right now. Ironically the feature was there in Cayenne since Day 1, waitin= g to get noticed. >=20 > Andrus >=20 > --------------- > Andrus Adamchik > @andrus_a | @ApacheCayenne >=20