initial add of EbeanORM server based on v2.8.1

This commit is contained in:
rbygrave
2012-09-14 00:40:39 +12:00
parent 2b74d0f9d9
commit 96ce4c0ddf
1188 changed files with 135034 additions and 0 deletions
@@ -0,0 +1,98 @@
package com.avaje.ebeaninternal.server.querydefn;
import java.util.Set;
import junit.framework.Assert;
import junit.framework.TestCase;
import com.avaje.ebean.Ebean;
import com.avaje.ebean.EbeanServer;
import com.avaje.ebeaninternal.server.expression.DefaultExpressionFactory;
import com.avaje.ebeaninternal.server.querydefn.DefaultOrmQuery;
import com.avaje.ebeaninternal.server.querydefn.OrmQueryDetail;
import com.avaje.ebeaninternal.server.querydefn.OrmQueryDetailParser;
import com.avaje.ebeaninternal.server.querydefn.OrmQueryProperties;
import com.avaje.tests.model.basic.Order;
public class TestQueryLanguage extends TestCase {
public void test() {
DefaultOrmQuery<Order> q = check("find order join customer (id, name)");
OrmQueryDetail detail = q.getDetail();
OrmQueryProperties chunk = detail.getChunk("customer", false);
Set<String> props = chunk.getAllIncludedProperties();
Assert.assertTrue(props.contains("id"));
Assert.assertTrue(props.contains("name"));
q = check("find order join customer(id, name)");
detail = q.getDetail();
chunk = detail.getChunk("customer", false);
props = chunk.getAllIncludedProperties();
Assert.assertTrue(props.contains("id"));
Assert.assertTrue(props.contains("name"));
Assert.assertFalse(chunk.isCache());
Assert.assertFalse(chunk.isReadOnly());
q = check("find order join customer(+cache +readonly, id, name)");
detail = q.getDetail();
chunk = detail.getChunk("customer", false);
props = chunk.getAllIncludedProperties();
Assert.assertTrue(props.contains("id"));
Assert.assertTrue(props.contains("name"));
Assert.assertTrue(chunk.isCache());
Assert.assertTrue(chunk.isReadOnly());
q = check("find order join customer(+cache +readonly,id,name)");
detail = q.getDetail();
chunk = detail.getChunk("customer", false);
props = chunk.getAllIncludedProperties();
Assert.assertTrue(props.contains("id"));
Assert.assertTrue(props.contains("name"));
Assert.assertTrue(chunk.isCache());
Assert.assertTrue(chunk.isReadOnly());
q = check("find order(id,status) join customer(+cache +readonly,id,name)");
detail = q.getDetail();
chunk = detail.getChunk("customer", false);
props = chunk.getAllIncludedProperties();
Assert.assertTrue(props.contains("id"));
Assert.assertTrue(props.contains("name"));
Assert.assertTrue(chunk.isCache());
Assert.assertTrue(chunk.isReadOnly());
chunk = detail.getChunk(null, false);
props = chunk.getAllIncludedProperties();
Assert.assertTrue(props.contains("id"));
Assert.assertTrue(props.contains("status"));
Assert.assertFalse(props.contains("orderDate"));
q = check("find order(id,status) join customer(+cache +readonly,id,name) where id > :minId order by status");
detail = q.getDetail();
chunk = detail.getChunk("customer", false);
props = chunk.getAllIncludedProperties();
Assert.assertTrue(props.contains("id"));
Assert.assertTrue(props.contains("name"));
Assert.assertTrue(chunk.isCache());
Assert.assertTrue(chunk.isReadOnly());
String orderBy = q.getOrderBy().toStringFormat();
Assert.assertEquals("status", orderBy);
}
private DefaultOrmQuery<Order> check(String q) {
EbeanServer server = Ebean.getServer(null);
OrmQueryDetailParser p = new OrmQueryDetailParser(q);
p.parse();
DefaultOrmQuery<Order> qry = new DefaultOrmQuery<Order>(Order.class, server, new DefaultExpressionFactory(), (String)null);
p.assign(qry);
return qry;
}
}