Return-Path: Delivered-To: apmail-incubator-cayenne-user-archive@locus.apache.org Received: (qmail 80365 invoked from network); 7 Apr 2006 12:41:00 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (209.237.227.199) by minotaur.apache.org with SMTP; 7 Apr 2006 12:41:00 -0000 Received: (qmail 26090 invoked by uid 500); 7 Apr 2006 12:41:00 -0000 Delivered-To: apmail-incubator-cayenne-user-archive@incubator.apache.org Received: (qmail 25853 invoked by uid 500); 7 Apr 2006 12:40:58 -0000 Mailing-List: contact cayenne-user-help@incubator.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: cayenne-user@incubator.apache.org Delivered-To: mailing list cayenne-user@incubator.apache.org Received: (qmail 25844 invoked by uid 99); 7 Apr 2006 12:40:58 -0000 Received: from asf.osuosl.org (HELO asf.osuosl.org) (140.211.166.49) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 07 Apr 2006 05:40:58 -0700 X-ASF-Spam-Status: No, hits=-0.0 required=10.0 tests=SPF_PASS X-Spam-Check-By: apache.org Received-SPF: pass (asf.osuosl.org: domain of Tobias.Schoessler@unvienna.org designates 193.138.94.41 as permitted sender) Received: from [193.138.94.41] (HELO mx4.unvienna.org) (193.138.94.41) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 07 Apr 2006 05:40:56 -0700 Received: from unvsmtp2.unvienna.org (unvsmtp2.unvienna.org [172.17.252.136]) by mx4.unvienna.org (8.12.11/8.12.11) with ESMTP id k37CeYT1006479 for ; Fri, 7 Apr 2006 14:40:34 +0200 In-Reply-To: <90DCEE72-FEA0-4A68-91B8-21B2296E53A4@objectstyle.org> Subject: Re: Path Expression => Attribute To: cayenne-user@incubator.apache.org X-Mailer: Lotus Notes Release 6.5.3 September 14, 2004 Message-ID: From: Tobias SCHOESSLER Date: Fri, 7 Apr 2006 14:40:32 +0200 X-MIMETrack: Serialize by Router on unvsmtp2/VIENNA/UNO(Release 6.5.4FP3|January 09, 2006) at 07/04/2006 14:40:34 MIME-Version: 1.0 Content-type: text/plain; charset=US-ASCII X-Virus-Checked: Checked by ClamAV on apache.org X-Spam-Rating: minotaur.apache.org 1.6.2 0/1000/N Andrus, this worked fine, thank you. I use this method to lookup the ObjAttribute for a given path now. public ObjAttribute pathToObjAttribute(Class baseClass, String path) { ObjEntity rootEntity = ctxt.getEntityResolver().lookupObjEntity(baseClass); ObjAttribute attribute = (ObjAttribute)Expression.fromString(path).evaluate(rootEntity); return attribute; } In the simplest case I feed this the name of an attribute in the baseClass and it returns me the ObjAttribute. e.G. 'countryCode' However it turned out that I rather need to use Db Paths to also be able to specify PK values. I changed the method to public DbAttribute pathToDbAttribute(Class baseClass, String path) { DbEntity rootEntity = ctxt.getEntityResolver().lookupDbEntity(baseClass); DbAttribute attribute = (DbAttribute)Expression.fromString(path).evaluate(rootEntity); return attribute; } I expect to be able to feed it the corresponding database attribute name now e.G. COUNTRY_CODE but this fails with the exception Caused by: org.objectstyle.cayenne.exp.ExpressionException: [v.1.1.3 September 28 2005] Invalid expression type: 'ObjPath', DB_PATH is expected. at org.objectstyle.cayenne.map.DbEntity.resolvePathComponents(DbEntity.java:249) at org.objectstyle.cayenne.exp.parser.ASTPath.evaluateEntityNode(ASTPath.java:108) at org.objectstyle.cayenne.exp.parser.ASTObjPath.evaluateNode(ASTObjPath.java:85) at org.objectstyle.cayenne.exp.parser.SimpleNode.evaluate(SimpleNode.java:243) ... 43 more Andrus Adamchik To cayenne-user@incubator.apache.org Monday, 3 April cc 2006 16:44 Subject Re: Path Expression => Attribute Please respond to cayenne-user@incu bator.apache.org You can evaluate an expression with root ObjEntity: String path = "toArtist.exhibitArray.closingDate"; ObjEntity rootEntity = context.getEntityResolver().lookupObjEntity (Painting.class); ObjAttribute attribute = Expression.fromString(path).evaluate (rootEntity); Andrus On Apr 3, 2006, at 6:36 PM, Tobias SCHOESSLER wrote: > hi, > > How do I get from a path expression to the resulting attribute > object. > > E.g. Is there anything that I can use to parse a path like > > toArtist.exhibitArray.closingDate > > and get the corresponding ObjAttribute for closingDate. > > As a precondition i would assume that the path evaluates to an > attribute. > > thanks > > regards > > Tobias > >