Search in sources :

Example 1 with Quote_Person

use of org.apache.cayenne.testdo.quotemap.Quote_Person in project cayenne by apache.

the class QuotedIdentifiersIT method testPrefetchQuote.

@Test
public void testPrefetchQuote() throws Exception {
    DbEntity entity = context.getEntityResolver().getObjEntity(QuoteAdress.class).getDbEntity();
    List idAttributes = Collections.singletonList(entity.getAttribute("City"));
    List updatedAttributes = Collections.singletonList(entity.getAttribute("City"));
    UpdateBatchQuery updateQuery = new UpdateBatchQuery(entity, idAttributes, updatedAttributes, Collections.<String>emptySet(), 1);
    List objects3 = context.performQuery(updateQuery);
    assertEquals(0, objects3.size());
    SelectQuery qQuote_Person2 = new SelectQuery(Quote_Person.class);
    List objects4 = context.performQuery(qQuote_Person2);
    assertEquals(2, objects4.size());
    SelectQuery qQuote_Person3 = new SelectQuery(Quote_Person.class, ExpressionFactory.matchExp("salary", 100));
    List objects5 = context.performQuery(qQuote_Person3);
    assertEquals(1, objects5.size());
    SelectQuery qQuote_Person4 = new SelectQuery(Quote_Person.class, ExpressionFactory.matchExp("group", "107324"));
    List objects6 = context.performQuery(qQuote_Person4);
    assertEquals(1, objects6.size());
    SelectQuery quoteAdress1 = new SelectQuery(QuoteAdress.class, ExpressionFactory.matchExp("group", "324"));
    List objects7 = context.performQuery(quoteAdress1);
    assertEquals(1, objects7.size());
    ObjectIdQuery queryObjectId = new ObjectIdQuery(new ObjectId("QuoteAdress", QuoteAdress.GROUP.getName(), "324"));
    List objects8 = context.performQuery(queryObjectId);
    assertEquals(1, objects8.size());
    ObjectIdQuery queryObjectId2 = new ObjectIdQuery(new ObjectId("Quote_Person", "GROUP", "1111"));
    List objects9 = context.performQuery(queryObjectId2);
    assertEquals(1, objects9.size());
    SelectQuery person2Query = new SelectQuery(Quote_Person.class, ExpressionFactory.matchExp("name", "Name"));
    Quote_Person quote_Person2 = (Quote_Person) context.performQuery(person2Query).get(0);
    RelationshipQuery relationshipQuery = new RelationshipQuery(quote_Person2.getObjectId(), "address_Rel");
    List objects10 = context.performQuery(relationshipQuery);
    assertEquals(1, objects10.size());
}
Also used : SelectQuery(org.apache.cayenne.query.SelectQuery) DbEntity(org.apache.cayenne.map.DbEntity) ObjectId(org.apache.cayenne.ObjectId) RelationshipQuery(org.apache.cayenne.query.RelationshipQuery) UpdateBatchQuery(org.apache.cayenne.query.UpdateBatchQuery) QuoteAdress(org.apache.cayenne.testdo.quotemap.QuoteAdress) List(java.util.List) ObjectIdQuery(org.apache.cayenne.query.ObjectIdQuery) Quote_Person(org.apache.cayenne.testdo.quotemap.Quote_Person) Test(org.junit.Test)

Example 2 with Quote_Person

use of org.apache.cayenne.testdo.quotemap.Quote_Person in project cayenne by apache.

the class QuotedIdentifiersIT method testQuotedEJBQLQueryWithOrderBy.

@Test
public void testQuotedEJBQLQueryWithOrderBy() throws Exception {
    EJBQLQuery query = new EJBQLQuery("select p from Quote_Person p order by p.name");
    List<Quote_Person> resultList = (List<Quote_Person>) context.performQuery(query);
    assertEquals(2, resultList.size());
    assertEquals("Arcadi", resultList.get(0).getName());
    assertEquals("Name", resultList.get(1).getName());
}
Also used : EJBQLQuery(org.apache.cayenne.query.EJBQLQuery) List(java.util.List) Quote_Person(org.apache.cayenne.testdo.quotemap.Quote_Person) Test(org.junit.Test)

Example 3 with Quote_Person

use of org.apache.cayenne.testdo.quotemap.Quote_Person in project cayenne by apache.

the class QuotedIdentifiersIT method setUp.

@Before
public void setUp() throws Exception {
    QuoteAdress quoteAdress = context.newObject(QuoteAdress.class);
    quoteAdress.setCity("city");
    quoteAdress.setGroup("324");
    Quote_Person quote_Person = context.newObject(Quote_Person.class);
    quote_Person.setSalary(10000);
    quote_Person.setName("Arcadi");
    quote_Person.setGroup("107324");
    quote_Person.setAddress_Rel(quoteAdress);
    context.commitChanges();
    SelectQuery q = new SelectQuery(QuoteAdress.class);
    List objects = context.performQuery(q);
    assertEquals(1, objects.size());
    SelectQuery qQuote_Person = new SelectQuery(Quote_Person.class);
    List objects2 = context.performQuery(qQuote_Person);
    assertEquals(1, objects2.size());
    QuoteAdress quoteAdress2 = context.newObject(QuoteAdress.class);
    quoteAdress2.setCity("city2");
    Quote_Person quote_Person2 = context.newObject(Quote_Person.class);
    quote_Person2.setSalary(100);
    quote_Person2.setName("Name");
    quote_Person2.setGroup("1111");
    quote_Person2.setDAte(new Date());
    quote_Person2.setAddress_Rel(quoteAdress2);
    context.commitChanges();
}
Also used : SelectQuery(org.apache.cayenne.query.SelectQuery) QuoteAdress(org.apache.cayenne.testdo.quotemap.QuoteAdress) List(java.util.List) Quote_Person(org.apache.cayenne.testdo.quotemap.Quote_Person) Date(java.util.Date) Before(org.junit.Before)

Aggregations

List (java.util.List)3 Quote_Person (org.apache.cayenne.testdo.quotemap.Quote_Person)3 SelectQuery (org.apache.cayenne.query.SelectQuery)2 QuoteAdress (org.apache.cayenne.testdo.quotemap.QuoteAdress)2 Test (org.junit.Test)2 Date (java.util.Date)1 ObjectId (org.apache.cayenne.ObjectId)1 DbEntity (org.apache.cayenne.map.DbEntity)1 EJBQLQuery (org.apache.cayenne.query.EJBQLQuery)1 ObjectIdQuery (org.apache.cayenne.query.ObjectIdQuery)1 RelationshipQuery (org.apache.cayenne.query.RelationshipQuery)1 UpdateBatchQuery (org.apache.cayenne.query.UpdateBatchQuery)1 Before (org.junit.Before)1