You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@cayenne.apache.org by Andrus Adamchik <an...@objectstyle.org> on 2007/12/20 09:53:16 UTC

Re: [CONF] Apache Cayenne: XML Mapping File (page edited)

Wonder who this guy is and how is this addition relevant to the "XML  
Mapping File" page?

http://cwiki.apache.org/confluence/pages/diffpagesbyversion.action?pageId=9806&originalVersion=2&revisedVersion=3

Andrus


On Dec 20, 2007, at 4:28 AM, confluence@apache.org wrote:

> Page Edited : CAY : XML Mapping File
> XML Mapping File has been edited by Terrence Pietrondi (Dec 19, 2007).
>
> (View changes)
>
> Content:
> Introduction
> The XML mapping file is a schema of sorts for mapping your  
> Persistent objects to XML. It is fully compatible with the format  
> used by WebObjects, making migration to or from Cayenne simple.
>
> This document aims to describe the format of the XML mapping file  
> and how you may use it.
>
> FormatOverview
> All mapping documents are composed of three elements:
>
> 	• <model>
> 	• <entity>
> 	• <property>
> The elements are nested in that order as well. A property always  
> belongs to an entity. An entity always belongs to a model. This  
> implies that <model> is always the root tag of the mapping file.
>
> <entity> and <property> also have attribute values that affect the  
> mapping. Please read their dedicated sections for more details.
>
> <model>
> <model> is always the root of the mapping document. It accepts no  
> attributes and there may only be one per document.
>
> <entity>
> <entity> corresponds to a Persistent object in your Cayenne datamap.
>
> Attributes:
>
> Name
> Required
> Explanation
> name
>
> Fully qualified class name of the Persistent object to represent.
> xmlTag
>
> The XML tag that will be used to represent the Persistent object in  
> its encoded form.
> <property>
> <property> corresponds to a JavaBeans property of a Persistent  
> object in your Cayenne datamap.
>
> Name
> Required
> Explanation
> name
>
> The name of the property of the enclosing Persistent object to  
> represent. This uses standard JavaBeans notation, including dotted  
> values for arbitrarily nested properties.
> xmlTag
>
> The XML tag that will be used to represent the property in its  
> encoded form.
> ExamplesMapping Simple Attributes
> This example shows how to get the value of a specific column in a  
> CayenneDataObject as the result of a select on that object's table.  
> For example, given a table named YOUR_TABLE that has column  
> YOUR_FIELD, you want to select a specific row and get the value for  
> YOUR_FIELD using the ObjEntity of the CayenneDataObject.
>
> // Create a data context
> DataContext context = ....;
> // Create a match expression
> Expression qual =  
> ExpressionFactory.matchExp(YourTable.YOUR_FIELD_PROPERTY,match);
> // Create your select query
> SelectQuery select  = new SelectQuery(YourTable.class,qual);
> // Limit the results to one
> select.setFetchLimit(1);
> // Form your data object from the query getting the first result
> CayenneDataObject next = (YourTable)  
> context.performQuery(select).get(0);
> Now to get the value of YOUR_FIELD from the CayenneDataObject  
> object, you need to create an ObjEntity (for later) from the  
> CayenneDataObject, get the DataMap from the context, and create a  
> DbEntity:
>
> // For later
> ObjEntity entity = next.getObjEntity();
> DataMap mapping  =  
> context.getEntityResolver().getDataMap("YourDomainMap");
> DbEntity table   = mapping.getDbEntity("YOUR_TABLE");
> At compile time, we hard code the table names and columns, because  
> we know them from the database, but we do not know for instance, or  
> at least you might not want to guess what the ObjEntity property  
> names are. And so we can look in the map for our column name that we  
> know and find its property name to pull its value from the  
> CayenneDataObject as a result of our select:
>
> // Get the DbEntity attributes as a collection
> Collection collect = entity.getAttributes();
> // And its iterator
> Iterator colItr = collect.iterator();
> // Initialize a return value
> String ruleValue = null;
> // Loop the attributes
> while(colItr.hasNext()){
>    // Get the next ObjAttribute on the DbEntity
>    ObjAttribute attr = (ObjAttribute) colItr.next();
>    // Get the attribute database path, the column name
>    String dbattr = attr.getDbAttributePath();
>    // Check if the current database field name matches
>    // what you are interested in
>    if(dbattr.equals("YOUR_FIELD")){
>       // If so, read the property in your CayenneDataObject
>       // using the name of the current ObjAttribute on the DbEntity
>       ruleValue = (String) next.readProperty(attr.getName());
>       break;
>    }
> }
> // Commit your work
> context.commitChanges();
> //Return the value of YOUR_FIELD on the CayenneDataObject
> return returnValue;
> Mapping RelationshipsMapping Collections
>
>
> Powered by Atlassian Confluence (Version: 2.2.9 Build:#527 Sep 07,  
> 2006) - Bug/feature request
>
> Unsubscribe or edit your notifications preferences


Re: [CONF] Apache Cayenne: XML Mapping File (page edited)

Posted by Andrus Adamchik <an...@objectstyle.org>.
On Dec 20, 2007, at 11:50 AM, Aristedes Maniatis wrote:

> And the other one:
>
> http://cwiki.apache.org/confluence/pages/diffpages.action?pageId=9806&originalId=72976
>
> which I don't believe is good advice to give in a multi-threaded  
> environment,

yeah..

> and is changing the objectID even sensible in Cayenne?

I'd have to test it to say for sure, but I think it actually should  
work, as Cayenne checks for changed ID's at the end of the commit  
cycle and re-registers objects. Still the right way would have been  
ObjectId.getReplacementIdMap().put(...).

I'll clean up the wiki.

Andrus

Re: [CONF] Apache Cayenne: XML Mapping File (page edited)

Posted by Tore Halset <ha...@pvv.ntnu.no>.
Hello.

On Dec 20, 2007, at 10:50 , Aristedes Maniatis wrote:

>  is changing the objectID even sensible in Cayenne?

It is at least changed for temp to generated pk and if you change a  
meaningful primary key.

  - Tore.

Re: [CONF] Apache Cayenne: XML Mapping File (page edited)

Posted by Aristedes Maniatis <ar...@ish.com.au>.
On 20/12/2007, at 7:54 PM, Andrus Adamchik wrote:

> Sorry, here is the correct link to the diff:
>
> http://cwiki.apache.org/confluence/pages/diffpages.action?pageId=69339&originalId=72978
>

And the other one:

http://cwiki.apache.org/confluence/pages/diffpages.action?pageId=9806&originalId=72976

which I don't believe is good advice to give in a multi-threaded  
environment, and is changing the objectID even sensible in Cayenne?


Andrus, I think only you have revert rights to the confluence space...

Ari



-------------------------->
ish
http://www.ish.com.au
Level 1, 30 Wilson Street Newtown 2042 Australia
phone +61 2 9550 5001   fax +61 2 9550 4001
GPG fingerprint CBFB 84B4 738D 4E87 5E5C  5EFA EF6A 7D2E 3E49 102A



Re: [CONF] Apache Cayenne: XML Mapping File (page edited)

Posted by Andrus Adamchik <an...@objectstyle.org>.
Sorry, here is the correct link to the diff:

http://cwiki.apache.org/confluence/pages/diffpages.action?pageId=69339&originalId=72978



On Dec 20, 2007, at 10:53 AM, Andrus Adamchik wrote:

> Wonder who this guy is and how is this addition relevant to the "XML  
> Mapping File" page?
>
> http://cwiki.apache.org/confluence/pages/diffpagesbyversion.action?pageId=9806&originalVersion=2&revisedVersion=3
>
> Andrus
>
>
> On Dec 20, 2007, at 4:28 AM, confluence@apache.org wrote:
>
>> Page Edited : CAY : XML Mapping File
>> XML Mapping File has been edited by Terrence Pietrondi (Dec 19,  
>> 2007).
>>
>> (View changes)
>>
>> Content:
>> Introduction
>> The XML mapping file is a schema of sorts for mapping your  
>> Persistent objects to XML. It is fully compatible with the format  
>> used by WebObjects, making migration to or from Cayenne simple.
>>
>> This document aims to describe the format of the XML mapping file  
>> and how you may use it.
>>
>> FormatOverview
>> All mapping documents are composed of three elements:
>>
>> 	• <model>
>> 	• <entity>
>> 	• <property>
>> The elements are nested in that order as well. A property always  
>> belongs to an entity. An entity always belongs to a model. This  
>> implies that <model> is always the root tag of the mapping file.
>>
>> <entity> and <property> also have attribute values that affect the  
>> mapping. Please read their dedicated sections for more details.
>>
>> <model>
>> <model> is always the root of the mapping document. It accepts no  
>> attributes and there may only be one per document.
>>
>> <entity>
>> <entity> corresponds to a Persistent object in your Cayenne datamap.
>>
>> Attributes:
>>
>> Name
>> Required
>> Explanation
>> name
>>
>> Fully qualified class name of the Persistent object to represent.
>> xmlTag
>>
>> The XML tag that will be used to represent the Persistent object in  
>> its encoded form.
>> <property>
>> <property> corresponds to a JavaBeans property of a Persistent  
>> object in your Cayenne datamap.
>>
>> Name
>> Required
>> Explanation
>> name
>>
>> The name of the property of the enclosing Persistent object to  
>> represent. This uses standard JavaBeans notation, including dotted  
>> values for arbitrarily nested properties.
>> xmlTag
>>
>> The XML tag that will be used to represent the property in its  
>> encoded form.
>> ExamplesMapping Simple Attributes
>> This example shows how to get the value of a specific column in a  
>> CayenneDataObject as the result of a select on that object's table.  
>> For example, given a table named YOUR_TABLE that has column  
>> YOUR_FIELD, you want to select a specific row and get the value for  
>> YOUR_FIELD using the ObjEntity of the CayenneDataObject.
>>
>> // Create a data context
>> DataContext context = ....;
>> // Create a match expression
>> Expression qual =  
>> ExpressionFactory.matchExp(YourTable.YOUR_FIELD_PROPERTY,match);
>> // Create your select query
>> SelectQuery select  = new SelectQuery(YourTable.class,qual);
>> // Limit the results to one
>> select.setFetchLimit(1);
>> // Form your data object from the query getting the first result
>> CayenneDataObject next = (YourTable)  
>> context.performQuery(select).get(0);
>> Now to get the value of YOUR_FIELD from the CayenneDataObject  
>> object, you need to create an ObjEntity (for later) from the  
>> CayenneDataObject, get the DataMap from the context, and create a  
>> DbEntity:
>>
>> // For later
>> ObjEntity entity = next.getObjEntity();
>> DataMap mapping  =  
>> context.getEntityResolver().getDataMap("YourDomainMap");
>> DbEntity table   = mapping.getDbEntity("YOUR_TABLE");
>> At compile time, we hard code the table names and columns, because  
>> we know them from the database, but we do not know for instance, or  
>> at least you might not want to guess what the ObjEntity property  
>> names are. And so we can look in the map for our column name that  
>> we know and find its property name to pull its value from the  
>> CayenneDataObject as a result of our select:
>>
>> // Get the DbEntity attributes as a collection
>> Collection collect = entity.getAttributes();
>> // And its iterator
>> Iterator colItr = collect.iterator();
>> // Initialize a return value
>> String ruleValue = null;
>> // Loop the attributes
>> while(colItr.hasNext()){
>>   // Get the next ObjAttribute on the DbEntity
>>   ObjAttribute attr = (ObjAttribute) colItr.next();
>>   // Get the attribute database path, the column name
>>   String dbattr = attr.getDbAttributePath();
>>   // Check if the current database field name matches
>>   // what you are interested in
>>   if(dbattr.equals("YOUR_FIELD")){
>>      // If so, read the property in your CayenneDataObject
>>      // using the name of the current ObjAttribute on the DbEntity
>>      ruleValue = (String) next.readProperty(attr.getName());
>>      break;
>>   }
>> }
>> // Commit your work
>> context.commitChanges();
>> //Return the value of YOUR_FIELD on the CayenneDataObject
>> return returnValue;
>> Mapping RelationshipsMapping Collections
>>
>>
>> Powered by Atlassian Confluence (Version: 2.2.9 Build:#527 Sep 07,  
>> 2006) - Bug/feature request
>>
>> Unsubscribe or edit your notifications preferences
>
>