You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cayenne.apache.org by "Øyvind Harboe (JIRA)" <ji...@apache.org> on 2009/06/15 12:11:07 UTC

[jira] Created: (CAY-1241) Add method to ExpressionFactory to match against the primary key of an object or list of objects

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


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.


[jira] Commented: (CAY-1241) Add method to ExpressionFactory to match against the primary key of an object or list of objects

Posted by "Laurentiu Cocanu (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/CAY-1241?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12721741#action_12721741 ] 

Laurentiu Cocanu commented on CAY-1241:
---------------------------------------

What about this new version?

 /**
     * 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(Persistent object) {    	
    	ObjectId obid = object.getObjectId(); 		
 		Map<String, ?> map = obid.getIdSnapshot();
 		
 		List<Expression> pairs = new ArrayList<Expression>(map.size());

 	    for (Map.Entry<String, ?> entry : map.entrySet()) {

 	            Expression exp = expressionOfType(Expression.AND);
 	            exp.setOperand(0, new ASTObjPath(entry.getKey()));
 	            exp.setOperand(1, wrapPathOperand(entry.getValue()));
 	            pairs.add(exp);
 	        }
 	    
 	   return joinExp(Expression.AND, pairs);
    }
    
    /**
     * Creates an expression that matches any of the objects contained in the list <code>objects</code>
     */   
    public static Expression matchObjects(List<Persistent> objects) {    	
    	
 		List<Expression> pairs = new ArrayList<Expression>(objects.size());

 	    for (Persistent object : objects) {
 	            
 	            pairs.add(matchObject(object));
 	        }
 	    
 	   return joinExp(Expression.OR, pairs);
    }


Soon I'll come with some unit tests too.

> 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.


[jira] Commented: (CAY-1241) Add method to ExpressionFactory to match against the primary key of an object or list of objects

Posted by "Andrus Adamchik (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/CAY-1241?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12719532#action_12719532 ] 

Andrus Adamchik commented on CAY-1241:
--------------------------------------

The idea is great. A few suggestions on the API to make it look similar to the existing methods, etc.:

* s/CayenneDataObject/Persistent/
* s/matchObject/matchExp/
* s/matchObjects/matchAllExp|matchAnyExp/

Note to myself or whoever is going to apply this - please write  unit tests.

> 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.


[jira] Closed: (CAY-1241) Add method to ExpressionFactory to match against the primary key of an object or list of objects

Posted by "Andrey Razumovsky (JIRA)" <ji...@apache.org>.
     [ https://issues.apache.org/jira/browse/CAY-1241?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Andrey Razumovsky closed CAY-1241.
----------------------------------

       Resolution: Fixed
    Fix Version/s: 3.0 beta 1
         Assignee: Andrey Razumovsky

> 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
>            Assignee: Andrey Razumovsky
>             Fix For: 3.0 beta 1
>
>         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.


[jira] Updated: (CAY-1241) Add method to ExpressionFactory to match against the primary key of an object or list of objects

Posted by "Laurentiu Cocanu (JIRA)" <ji...@apache.org>.
     [ 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.


[jira] Commented: (CAY-1241) Add method to ExpressionFactory to match against the primary key of an object or list of objects

Posted by "Andrey Razumovsky (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/CAY-1241?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12724105#action_12724105 ] 

Andrey Razumovsky commented on CAY-1241:
----------------------------------------

e.g. here
http://svn.apache.org/repos/asf/cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/exp/ExpressionFactoryTest.java

> 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.


[jira] Commented: (CAY-1241) Add method to ExpressionFactory to match against the primary key of an object or list of objects

Posted by "Øyvind Harboe (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/CAY-1241?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12724095#action_12724095 ] 

Øyvind Harboe commented on CAY-1241:
------------------------------------

Could someone provide a pointer to where the ExpressionFactory junit tests are so we can add a test for these new methods?

> 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.