[ 
https://issues.apache.org/jira/browse/CAY-1241?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
 ]

Laurentiu Cocanu updated CAY-1241:
----------------------------------

    Attachment: patch.txt

A possible solution to this issue (also in the attached patch):

/**
     * Creates an expression that matches the primary key of object in 
<code>ObjectId</code>'s <code>IdSnapshot</code> for the argument 
<code>object</code>.     
     */
    public static Expression matchObject(CayenneDataObject object) {            
        ObjectId obid = object.getObjectId();
                
                Map<String, Object> objectIdKeys = obid.getIdSnapshot();
                                
                Iterator<String> it = objectIdKeys.keySet().iterator();
                
                String key = it.next();
                Object value = objectIdKeys.get(key);
                Expression exp = ExpressionFactory.matchDbExp(key, value);
                
                while(it.hasNext())     {
                        key = it.next();
                        value = objectIdKeys.get(key);
                        exp = exp.andExp(ExpressionFactory.matchDbExp(key, 
value));
                }
                
                return exp;
    }
    
    /**
     * Creates an expression that matches any of the objects contained in the 
list <code>objects</code>
     */
    public static Expression matchObjects(List<CayenneDataObject> objects) {    
        
        Iterator<CayenneDataObject> it = objects.iterator();
        Expression exp = matchObject(it.next());
        while(it.hasNext())     {                       
                        exp = exp.orExp(matchObject(it.next()));
                }
                
                return exp;
    }

> Add method to ExpressionFactory to match against the primary key of an object 
> or list of objects
> ------------------------------------------------------------------------------------------------
>
>                 Key: CAY-1241
>                 URL: https://issues.apache.org/jira/browse/CAY-1241
>             Project: Cayenne
>          Issue Type: Improvement
>          Components: Cayenne Core Library
>    Affects Versions: 3.0M6
>            Reporter: Øyvind Harboe
>         Attachments: patch.txt
>
>
> It would be helpful to have a method in ExpressionFactory that build an 
> expression using matchDbExp() to match an object's primary keys.
> This can be helpful in excluding a single or list of known objects from the 
> result of a query.

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.

Reply via email to