Return-Path: X-Original-To: apmail-cayenne-user-archive@www.apache.org Delivered-To: apmail-cayenne-user-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 2103DD842 for ; Thu, 30 Aug 2012 04:55:31 +0000 (UTC) Received: (qmail 84067 invoked by uid 500); 30 Aug 2012 04:55:30 -0000 Delivered-To: apmail-cayenne-user-archive@cayenne.apache.org Received: (qmail 83812 invoked by uid 500); 30 Aug 2012 04:55:24 -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 83783 invoked by uid 99); 30 Aug 2012 04:55:23 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 30 Aug 2012 04:55:23 +0000 X-ASF-Spam-Status: No, hits=-0.0 required=5.0 tests=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; Thu, 30 Aug 2012 04:55:18 +0000 Received: (qmail 15075 invoked from network); 30 Aug 2012 04:55:55 -0000 Received: from unknown (HELO ?192.168.1.37?) (194.158.197.10) by vorsha.objectstyle.org with SMTP; 30 Aug 2012 04:55:55 -0000 Content-Type: text/plain; charset=iso-8859-1 Mime-Version: 1.0 (Apple Message framework v1084) Subject: Re: Vaadin Integration and MetaData of mappings From: Andrus Adamchik In-Reply-To: Date: Thu, 30 Aug 2012 07:54:54 +0300 Content-Transfer-Encoding: quoted-printable Message-Id: <6ED7A8D3-B0A8-400D-BD9E-83F55D8D03CE@objectstyle.org> References: <503A2F70.60101@gmail.com> <7F7E2F7D-7216-443D-B29D-BA81A01A70B9@objectstyle.org> To: user@cayenne.apache.org X-Mailer: Apple Mail (2.1084) X-Virus-Checked: Checked by ClamAV on apache.org 1. Serialization. There's not much to it really. Just make sure the = context you are using is session-scoped. See for instance this class = that provides a session-bound context (used by CayenneFilter) : = http://svn.apache.org/viewvc/cayenne/main/branches/STABLE-3.1/framework/ca= yenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/configuration/we= b/SessionContextRequestHandler.java?view=3Dmarkup 2. Multi-tenancy... So if you go with DB-schema per tenant, it might = look like this:=20 // do it once per tenant, and cache the returned runtime in the app = scope ServerRuntime createServerRuntime(final String tenantSchema) { // "cayenne-xyz.xml" is a mapping common to all tenants, that will be = further customized here ServerRuntime runtime =3D new ServerRuntime("cayenne-xyz.xml", new = Module() { // in a custom module override the schema of all loaded DataMaps public void configure(Binder binder) { binder.bind(DataMapLoader.class).toInstance(new = TenantMapLoader(tenantSchema)); } }); =20 =20 return runtime; } class TenantMapLoader extends XMLDataMapLoader { private String tenantSchema; TenantMapLoader(String tenantSchema) { this.tenantSchema =3D tenantSchema; } public DataMap load(Resource configurationResource) { DataMap map =3D super.load(configurationResource); map.setDefaultSchema(tenantSchema); =20 for(DbEntity e : map.getDbEntities()) { e.setSchema(tenantSchema); } =20 return map; } } Andrus On Aug 29, 2012, at 4:15 PM, Juan Jos=E9 Gil wrote: > Thanks for the reply Andrus! >=20 > Could you point me to docs/samples about ObjectContext Serialization & > multi-tenant approaches you describe? >=20 > About the"adding-metadata" part, I was thinking in adding constraints = in a > similar way to active-record in RoR or GORM in grails, but using code > generation phases of cayenne. >=20 > By now i'll use some kind of "typed" KVC delegating to cayenne the > properties access and then providing some kind a "class metadata" = which can > be extended by subclasses... but i'll prefer the "code generation" = form, so > I can use IDEs capabilities. >=20 > maybe I'll generate some "java code configuration" which then will be = used > to generate final classes... it sounds as a mess but it could give = really > nice possibilities! don't you think? >=20 > if i get to somewhere with this approach I'll tell you :) >=20 >>=20 >>=20 >>> the data objects will reside at the http session, and will be used >> directly by the vaadin widgets, does this kind of cayenne data = objects >> "use" could arrive with attaching/detaching problems? >>=20 >> Shouldn't be a problem. You can store Cayenne objects in a session. = The >> simplest way to avoid attach/detach issues is to have a = session-scoped >> ObjectContext. Then it is serialized/deserialized together with the = objects >> in case the session is saved to disk, or replicated across the = cluster. >>=20 >>> Also, is there a way to add metadata info in cayenne metamodel? I = would >> like to add constraints / validations to generated classes, so they = can be >> used to define searching criterias on indexed attributes (something = like >> active-records class filters, but only on indexed properties) and = generate >> model validations on properties so they can be used at UI fields = directly, >> facilitating the app development. >>=20 >> You can add extra info using callbacks or lifecycle listeners. Any = extra >> properties can be defined either manually in generated subclasses, or = even >> stored in the base CayenneDataObject (with 'readProperty' / = 'writeProperty' >> methods, and custom property names). >>=20 >>> Finally, I'm looking for a multitenant implementation to use, and I >> believe that the solution pointed at >> = http://blog.jerodsanto.net/2011/07/building-multi-tenant-rails-apps-with-p= ostgresql-schemas/could be also used with cayenne; is there any = constraint I should look for? >>=20 >> Cayenne is certainly friendly to various multi-tenancy approaches. In = 3.1 >> API terms, you might assign a separate instance of ServerRuntime to = each >> tenant, and use that to create ObjectContexts for its users. You may = start >> all runtimes from the same basic configuration, and "namespace" them = using >> tenant-unique DB URL. Or you may use a single DataSource, and after a >> runtime is loaded, scan through all its DbEntities and assign a = tenant >> "schema" to them. Feel free to ask about further details. >>=20 >> Andrus >>=20 >>=20 >> On Aug 26, 2012, at 5:15 PM, Juan J. Gil wrote: >>> Hello, I'm thinking to use cayenne in conjunction with vaadin ( >> http://vaadin.com). >>>=20 >>> I'm trying to use some kind of tight integration between both = frameworks >> (defining cayenne generated classes which are vaadin data models >> implementations). >>> That way I could define forms directly on data objects, querying & >> mutating its state directly from vaadin widgets. >>> As vaadin is an stateful web framework, should I have to expect for = some >> kind of problem with data objects between requests? I mean, the data >> objects will reside at the http session, and will be used directly by = the >> vaadin widgets, does this kind of cayenne data objects "use" could = arrive >> with attaching/detaching problems? >>>=20 >>> Also, is there a way to add metadata info in cayenne metamodel? I = would >> like to add constraints / validations to generated classes, so they = can be >> used to define searching criterias on indexed attributes (something = like >> active-records class filters, but only on indexed properties) and = generate >> model validations on properties so they can be used at UI fields = directly, >> facilitating the app development. >>>=20 >>> Finally, I'm looking for a multitenant implementation to use, and I >> believe that the solution pointed at >> = http://blog.jerodsanto.net/2011/07/building-multi-tenant-rails-apps-with-p= ostgresql-schemas/could be also used with cayenne; is there any = constraint I should look for? >>>=20 >>> Best regards >>> Juanjo >>>=20 >>> ps: pardon my really poor English! :P >>>=20 >>>=20 >>=20 >>=20