cayenne-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From gilbertoca <gilbert...@gmail.com>
Subject Re: select over PKs
Date Mon, 02 Apr 2012 20:25:46 GMT

Sheldon wrote
> 
> If I specify a pageSize than I get any PK of objects.
> I want, that I know a list of PKs and get their Objects.
> 
> Sheldon
> 

You can add a NamedQuery[1] in the modeler, for example:
<pre>
	<query name="Vehicle.findInLicensePlate"
factory="org.apache.cayenne.map.SelectQueryBuilder" root="obj-entity"
root-name="Vehicle">
		<qualifier></qualifier>
	</query>        
	<query name="Vehicle.findByLicensePlate"
factory="org.apache.cayenne.map.SelectQueryBuilder" root="obj-entity"
root-name="Vehicle">
		<qualifier></qualifier>
	</query>
</pre>

Then [2]:
<pre>
    /**
     * Test of Vehicle.findInLicensePlate named query.
     */
    @Test
    public void findInLicensePlate() {
        System.out.println("\nGetting an Vehicle IN
Vehicle.findInLicensePlate.\n");
        //JPA-->Query query =
em.createNamedQuery("Vehicle.findInLicensePlate");
        //JPA-->query.setParameter("licensePlate", new
String[]{"LC101","LC102"});
        //JPA-->int size = query.getResultList().size();
        ObjectContext context = runtime.getContext();
        NamedQuery query = new NamedQuery("Vehicle.findInLicensePlate",
Collections.singletonMap("licensePlate", new String[]{"LC101","LC102"}));
        List entities = context.performQuery(query);
        assertEquals("Should have 2 Vehicle", 2, entities.size());
    }

</pre>

Hth,

Gilberto

[1]
http://cayenne.apache.org/doc/api/org/apache/cayenne/query/NamedQuery.html
[2]
http://code.google.com/p/construtor/source/browse/trunk/park-samples/park-cayenne/src/test/java/park/model/VehicleTest.java

--
View this message in context: http://cayenne.195.n3.nabble.com/select-over-PKs-tp3870305p3878913.html
Sent from the Cayenne - User mailing list archive at Nabble.com.

Mime
View raw message