mirror of
https://github.com/ebean-orm/ebean.git
synced 2026-11-12 22:41:35 +00:00
#2075 - Refactor external mapping (i.e. named queries from ebean.xml etc) - extract api and separate module
This commit is contained in:
1 parent
f57db28f1c
commit
49b1bd54c3
52 files changed
+817
-259
No files matched your search
+23
-18
@@ -13,16 +13,16 @@ import java.util.Optional;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
public class NamedDtoQueryTest extends BaseTestCase {
|
||||
public class DtoQuery2Test extends BaseTestCase {
|
||||
|
||||
private static final Logger log = LoggerFactory.getLogger(NamedDtoQueryTest.class);
|
||||
private static final Logger log = LoggerFactory.getLogger(DtoQuery2Test.class);
|
||||
|
||||
@Test
|
||||
public void dto_findList_constructorMatch() {
|
||||
|
||||
ResetBasicData.reset();
|
||||
|
||||
DtoQuery<DCust> dtoQuery = server().createNamedDtoQuery(DCust.class, "findList");
|
||||
DtoQuery<DCust> dtoQuery = server().findDto(DCust.class, "select id, name from o_customer");
|
||||
|
||||
List<DCust> list = dtoQuery.findList();
|
||||
|
||||
@@ -36,7 +36,7 @@ public class NamedDtoQueryTest extends BaseTestCase {
|
||||
ResetBasicData.reset();
|
||||
|
||||
LoggedSqlCollector.start();
|
||||
server().createNamedDtoQuery(DCust.class, "findGtId")
|
||||
server().findDto(DCust.class, "select id, name from o_customer where id > :id")
|
||||
.setParameter("id", 0)
|
||||
.findEach(it -> log.info("got " + it.getId() + " " + it.getName()));
|
||||
|
||||
@@ -50,7 +50,7 @@ public class NamedDtoQueryTest extends BaseTestCase {
|
||||
ResetBasicData.reset();
|
||||
|
||||
LoggedSqlCollector.start();
|
||||
server().createNamedDtoQuery(DCust.class, "findGtIdDesc")
|
||||
server().findDto(DCust.class, "select id, name from o_customer where id > :id order by id desc")
|
||||
.setParameter("id", 0)
|
||||
.findEachWhile(customer -> {
|
||||
log.info("got " + customer.getId() + " " + customer.getName());
|
||||
@@ -66,13 +66,13 @@ public class NamedDtoQueryTest extends BaseTestCase {
|
||||
|
||||
ResetBasicData.reset();
|
||||
|
||||
Optional<DCust> rob = server().createNamedDtoQuery(DCust.class, "findByName")
|
||||
Optional<DCust> rob = server().findDto(DCust.class, "select id, name from o_customer where name = :name")
|
||||
.setParameter("name", "Fiona")
|
||||
.findOneOrEmpty();
|
||||
|
||||
assertThat(rob.isPresent()).isTrue();
|
||||
|
||||
Optional<DCust> oneOrEmpty = server().createNamedDtoQuery(DCust.class, "findByName")
|
||||
Optional<DCust> oneOrEmpty = server().findDto(DCust.class, "select id, name from o_customer where name = :name")
|
||||
.setParameter("name", "DoesNotExistMyFriend")
|
||||
.findOneOrEmpty();
|
||||
|
||||
@@ -84,13 +84,13 @@ public class NamedDtoQueryTest extends BaseTestCase {
|
||||
|
||||
ResetBasicData.reset();
|
||||
|
||||
DCust fiona = server().createNamedDtoQuery(DCust.class, "findByName")
|
||||
DCust fiona = server().findDto(DCust.class, "select id, name from o_customer where name = :name")
|
||||
.setParameter("name", "Fiona")
|
||||
.findOne();
|
||||
|
||||
assertThat(fiona.getName()).isEqualTo("Fiona");
|
||||
|
||||
DCust empty = server().createNamedDtoQuery(DCust.class, "findByName")
|
||||
DCust empty = server().findDto(DCust.class, "select id, name from o_customer where name = :name")
|
||||
.setParameter("name", "DoesNotExistMyFriend")
|
||||
.findOne();
|
||||
|
||||
@@ -109,7 +109,7 @@ public class NamedDtoQueryTest extends BaseTestCase {
|
||||
|
||||
for (String name : names) {
|
||||
|
||||
List<DCust> custs = server().createNamedDtoQuery(DCust.class, "findByName_c3")
|
||||
List<DCust> custs = server().findDto(DCust.class, "select c3.id, c3.name from o_customer c3 where c3.name = :name")
|
||||
.setLabel("basic")
|
||||
.setParameter("name", name)
|
||||
.findList();
|
||||
@@ -130,7 +130,7 @@ public class NamedDtoQueryTest extends BaseTestCase {
|
||||
assertThat(queryMetric.getName()).isEqualTo("dto.DCust_basic");
|
||||
|
||||
|
||||
server().createNamedDtoQuery(DCust.class, "findByName_c4")
|
||||
server().findDto(DCust.class, "select c4.id, c4.name from o_customer c4 where lower(c4.name) = :name")
|
||||
.setLabel("basic2")
|
||||
.setParameter("name", "rob")
|
||||
.findList();
|
||||
@@ -149,7 +149,7 @@ public class NamedDtoQueryTest extends BaseTestCase {
|
||||
|
||||
ResetBasicData.reset();
|
||||
|
||||
List<DCust3> list = server().createNamedDtoQuery(DCust3.class, "findByName_relaxedMode")
|
||||
List<DCust2> list = server().findDto(DCust2.class, "select id, '42' as something_we_cannot_map, name from o_customer")
|
||||
.setRelaxedMode()
|
||||
.findList();
|
||||
|
||||
@@ -162,7 +162,7 @@ public class NamedDtoQueryTest extends BaseTestCase {
|
||||
|
||||
ResetBasicData.reset();
|
||||
|
||||
List<DCust2> list = server().createNamedDtoQuery(DCust2.class, "findByName_relaxedMode")
|
||||
List<DCust2> list = server().findDto(DCust2.class, "select id, '42' as something_we_cannot_map, name from o_customer")
|
||||
.setRelaxedMode()
|
||||
.findList();
|
||||
|
||||
@@ -175,7 +175,13 @@ public class NamedDtoQueryTest extends BaseTestCase {
|
||||
|
||||
ResetBasicData.reset();
|
||||
|
||||
List<DCust> dtos = server().createNamedDtoQuery(DCust.class, "findListByName")
|
||||
String sql = "select c.id, c.name, count(o.id) as totalOrders\n" +
|
||||
" from o_customer c\n" +
|
||||
" join o_order o on o.kcustomer_id = c.id\n" +
|
||||
" where c.name like :name\n" +
|
||||
" group by c.id, c.name";
|
||||
|
||||
List<DCust> dtos = server().findDto(DCust.class, sql)
|
||||
.setParameter("name", "Rob")
|
||||
.findList();
|
||||
|
||||
@@ -188,7 +194,7 @@ public class NamedDtoQueryTest extends BaseTestCase {
|
||||
|
||||
ResetBasicData.reset();
|
||||
|
||||
DtoQuery<DCust2> dtoQuery = server().createNamedDtoQuery(DCust2.class, "findList");
|
||||
DtoQuery<DCust2> dtoQuery = server().findDto(DCust2.class, "select id, name from o_customer");
|
||||
|
||||
List<DCust2> list = dtoQuery.findList();
|
||||
|
||||
@@ -200,7 +206,7 @@ public class NamedDtoQueryTest extends BaseTestCase {
|
||||
|
||||
ResetBasicData.reset();
|
||||
|
||||
List<DCust3> robs = server().createNamedDtoQuery(DCust3.class, "findByNameLike")
|
||||
List<DCust3> robs = server().findDto(DCust3.class, "select id, name, 42 as totalOrders from o_customer where name like ?")
|
||||
.setParameter("Rob")
|
||||
.setMaxRows(10)
|
||||
.findList();
|
||||
@@ -215,11 +221,10 @@ public class NamedDtoQueryTest extends BaseTestCase {
|
||||
|
||||
ResetBasicData.reset();
|
||||
|
||||
List<DCust3> robs = server().createNamedDtoQuery(DCust3.class, "findByName")
|
||||
List<DCust3> robs = server().findDto(DCust3.class, "select id, name from o_customer where name = :name")
|
||||
.setParameter("name", "Rob")
|
||||
.findList();
|
||||
|
||||
|
||||
log.info(robs.toString());
|
||||
assertThat(robs).isNotEmpty();
|
||||
}
|
||||
@@ -6,11 +6,10 @@ import org.tests.model.basic.Customer;
|
||||
import org.tests.model.basic.ResetBasicData;
|
||||
|
||||
import javax.persistence.PersistenceException;
|
||||
import java.util.List;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class EbeanServer_eqlTest extends BaseTestCase {
|
||||
|
||||
|
||||
@@ -90,7 +89,7 @@ public class EbeanServer_eqlTest extends BaseTestCase {
|
||||
// check also select count(*)
|
||||
LoggedSqlCollector.start();
|
||||
query.findCount();
|
||||
List<String>sql = LoggedSqlCollector.stop();
|
||||
List<String> sql = LoggedSqlCollector.stop();
|
||||
assertThat(sql.get(0)).startsWith("select count(*) from o_customer t0;");
|
||||
}
|
||||
|
||||
@@ -116,7 +115,7 @@ public class EbeanServer_eqlTest extends BaseTestCase {
|
||||
// check also select count(*)
|
||||
LoggedSqlCollector.start();
|
||||
query.findCount();
|
||||
List<String>sql = LoggedSqlCollector.stop();
|
||||
List<String> sql = LoggedSqlCollector.stop();
|
||||
assertThat(sql.get(0)).startsWith("select count(*) from o_customer t0;");
|
||||
|
||||
}
|
||||
@@ -233,33 +232,4 @@ public class EbeanServer_eqlTest extends BaseTestCase {
|
||||
assertSql(query).contains("from o_customer t0 left join contact t1 on t1.customer_id = t0.id ");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void namedQuery_fromXml() {
|
||||
|
||||
ResetBasicData.reset();
|
||||
|
||||
Query<Customer> query = server()
|
||||
.createNamedQuery(Customer.class, "withContactsById")
|
||||
.setParameter("id", 1);
|
||||
|
||||
query.setUseCache(false);
|
||||
query.findOne();
|
||||
|
||||
assertSql(query).contains("from o_customer t0 left join contact t1 on t1.customer_id = t0.id ");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void namedQuery_fromCustomXmlLocations() {
|
||||
|
||||
ResetBasicData.reset();
|
||||
|
||||
Query<Customer> query = server()
|
||||
.createNamedQuery(Customer.class, "withContactsById2")
|
||||
.setParameter("id", 1);
|
||||
|
||||
query.setUseCache(false);
|
||||
query.findOne();
|
||||
|
||||
assertSql(query).contains("from o_customer t0 left join contact t1 on t1.customer_id = t0.id ");
|
||||
}
|
||||
}
|
||||
@@ -1,21 +0,0 @@
|
||||
package io.ebeaninternal.xmlmapping.model;
|
||||
|
||||
import io.ebeaninternal.xmlmapping.XmlMappingReader;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.io.InputStream;
|
||||
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
|
||||
public class XmlMappingReaderTest {
|
||||
|
||||
@Test
|
||||
public void read() throws Exception {
|
||||
|
||||
InputStream is = XmlMappingReaderTest.class.getResourceAsStream("/test-ebean.xml");
|
||||
XmEbean testMapping = XmlMappingReader.read(is);
|
||||
|
||||
assertNotNull(testMapping);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -93,61 +93,4 @@ public class TestOrderTotalAmountReportBean extends BaseTestCase {
|
||||
assertSql(query).contains("count(*) as totalItems, sum(order_qty*unit_price) as totalAmount");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDefaultNamedRawSql() {
|
||||
|
||||
Query<OrderAggregate> query = Ebean.find(OrderAggregate.class);
|
||||
List<OrderAggregate> list = query.findList();
|
||||
|
||||
assertSql(query).contains("count(*) as total_items, sum(order_qty*unit_price) as total_amount");
|
||||
assertNotNull(list);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testNamedRawSql() {
|
||||
|
||||
ResetBasicData.reset();
|
||||
|
||||
Query<OrderAggregate> query = Ebean.getDefaultServer().createNamedQuery(OrderAggregate.class, "withMax");
|
||||
List<OrderAggregate> list = query.findList();
|
||||
|
||||
assertSql(query).contains("count(*) as total_items, sum(order_qty*unit_price) as total_amount, max(order_qty*unit_price) as maxAmount from o_order_detail");
|
||||
assertNotNull(list);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testNamedRawSql_with_extraPredicates() {
|
||||
|
||||
ResetBasicData.reset();
|
||||
|
||||
Query<OrderAggregate> query = Ebean.getDefaultServer().createNamedQuery(OrderAggregate.class, "withMax");
|
||||
List<OrderAggregate> list = query
|
||||
.where().gt("order.id", 1)
|
||||
.having().gt("totalItems", 1)
|
||||
.order().desc("totalAmount")
|
||||
.findList();
|
||||
|
||||
assertSql(query).contains("count(*) as total_items, sum(order_qty*unit_price) as total_amount, max(order_qty*unit_price) as maxAmount from o_order_detail");
|
||||
assertSql(query).contains("from o_order_detail where order_id > ? group by order_id having count(*) > ? order by sum(order_qty*unit_price) desc");
|
||||
assertNotNull(list);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testNamedRawSql_with_param() {
|
||||
|
||||
ResetBasicData.reset();
|
||||
|
||||
Query<OrderAggregate> query = Ebean.getDefaultServer().createNamedQuery(OrderAggregate.class, "withParam");
|
||||
List<OrderAggregate> list = query
|
||||
.setParameter("minId", 2)
|
||||
.where().isNotNull("order.id")
|
||||
.having().lt("totalAmount", 100)
|
||||
.order().desc("totalAmount")
|
||||
.setMaxRows(10)
|
||||
.findList();
|
||||
|
||||
assertSql(query).contains("count(*) as totalItems, sum(order_qty*unit_price) as totalAmount, max(order_qty*unit_price) as maxAmount from o_order_detail");
|
||||
assertSql(query).contains("from o_order_detail where id > ? and order_id is not null group by order_id having sum(order_qty*unit_price) < ? order by sum(order_qty*unit_price) desc");
|
||||
assertNotNull(list);
|
||||
}
|
||||
}
|
||||
@@ -24,71 +24,6 @@ import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
public class TestRawSqlOrmQuery extends BaseTestCase {
|
||||
|
||||
@IgnorePlatform(Platform.ORACLE)
|
||||
@Test
|
||||
public void testNamed() {
|
||||
|
||||
ResetBasicData.reset();
|
||||
|
||||
Query<Order> query = Ebean.createNamedQuery(Order.class, "myRawTest");
|
||||
query.setParameter("orderStatus", Order.Status.NEW);
|
||||
query.setMaxRows(10);
|
||||
List<Order> list = query.findList();
|
||||
for (Order order : list) {
|
||||
order.getCretime();
|
||||
}
|
||||
|
||||
String sql = query.getGeneratedSql();
|
||||
if (isSqlServer()) {
|
||||
assertThat(sql).contains("select top 10 o.id,");
|
||||
} else {
|
||||
assertThat(sql).contains("select o.id,");
|
||||
assertThat(sql).contains("limit 10");
|
||||
}
|
||||
assertThat(sql).contains("o.id, o.status, o.ship_date, c.id, c.name, a.id, a.line_1, a.line_2, a.city from o_order o");
|
||||
assertThat(sql).contains("join o_customer c on o.kcustomer_id = c.id ");
|
||||
assertThat(sql).contains("where o.status = ? order by c.name, c.id");
|
||||
}
|
||||
|
||||
@IgnorePlatform(Platform.ORACLE)
|
||||
@Test
|
||||
public void testNamed_fromCustomXmlLocations() {
|
||||
|
||||
ResetBasicData.reset();
|
||||
|
||||
Query<Order> query = Ebean.createNamedQuery(Order.class, "myRawTest2");
|
||||
query.setParameter("orderStatus", Order.Status.NEW);
|
||||
query.setMaxRows(10);
|
||||
List<Order> list = query.findList();
|
||||
for (Order order : list) {
|
||||
order.getCretime();
|
||||
}
|
||||
|
||||
String sql = query.getGeneratedSql();
|
||||
if (isSqlServer()) {
|
||||
assertThat(sql).contains("select top 10 o.id,");
|
||||
} else {
|
||||
assertThat(sql).contains("select o.id,");
|
||||
assertThat(sql).contains("limit 10");
|
||||
}
|
||||
assertThat(sql).contains("o.id, o.status, o.ship_date, c.id, c.name, a.id, a.line_1, a.line_2, a.city from o_order o");
|
||||
assertThat(sql).contains("join o_customer c on o.kcustomer_id = c.id ");
|
||||
assertThat(sql).contains("where o.status = ? order by c.name, c.id");
|
||||
}
|
||||
|
||||
@IgnorePlatform(Platform.ORACLE)
|
||||
@Test
|
||||
public void testNamed_fromCustomXmlLocations_withComments() {
|
||||
|
||||
ResetBasicData.reset();
|
||||
|
||||
Query<Order> query = Ebean.createNamedQuery(Order.class, "myRawTest3");
|
||||
query.setMaxRows(10);
|
||||
|
||||
List<Order> list = query.findList();
|
||||
assertThat(list).isNotEmpty();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test() {
|
||||
|
||||
|
||||
@@ -1,14 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
|
||||
<ebean xmlns="http://ebean-orm.github.io/xml/ns/ebean">
|
||||
|
||||
<entity class="org.tests.model.basic.Customer">
|
||||
<named-query name="withContactsById2">
|
||||
<query>
|
||||
select (name, version)
|
||||
fetch contacts (firstName, lastName, email)
|
||||
where id = :id
|
||||
</query>
|
||||
</named-query>
|
||||
</entity>
|
||||
|
||||
</ebean>
|
||||
@@ -1,77 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
|
||||
<ebean xmlns="http://ebean-orm.github.io/xml/ns/ebean">
|
||||
|
||||
<dto class="io.ebean.NamedDtoQueryTest$DCust">
|
||||
<raw-sql name="findList">
|
||||
<query>
|
||||
select id, name from o_customer
|
||||
</query>
|
||||
</raw-sql>
|
||||
<raw-sql name="findGtId">
|
||||
<query>
|
||||
select id, name from o_customer where id > :id
|
||||
</query>
|
||||
</raw-sql>
|
||||
<raw-sql name="findGtIdDesc">
|
||||
<query>
|
||||
select id, name from o_customer where id > :id order by id desc
|
||||
</query>
|
||||
</raw-sql>
|
||||
<raw-sql name="findByName">
|
||||
<query>
|
||||
select id, name from o_customer where name = :name
|
||||
</query>
|
||||
</raw-sql>
|
||||
<raw-sql name="findByName_c3">
|
||||
<query>
|
||||
select c3.id, c3.name from o_customer c3 where c3.name = :name
|
||||
</query>
|
||||
</raw-sql>
|
||||
<raw-sql name="findByName_c4">
|
||||
<query>
|
||||
select c4.id, c4.name from o_customer c4 where lower(c4.name) = :name
|
||||
</query>
|
||||
</raw-sql>
|
||||
<raw-sql name="findListByName">
|
||||
<query>
|
||||
select c.id, c.name, count(o.id) as totalOrders
|
||||
from o_customer c
|
||||
join o_order o on o.kcustomer_id = c.id
|
||||
where c.name like :name
|
||||
group by c.id, c.name
|
||||
</query>
|
||||
</raw-sql>
|
||||
</dto>
|
||||
|
||||
<dto class="io.ebean.NamedDtoQueryTest$DCust2">
|
||||
<raw-sql name="findByName_relaxedMode">
|
||||
<query>
|
||||
select id, '42' as something_we_cannot_map, name from o_customer
|
||||
</query>
|
||||
</raw-sql>
|
||||
<raw-sql name="findList">
|
||||
<query>
|
||||
select id, name from o_customer
|
||||
</query>
|
||||
</raw-sql>
|
||||
</dto>
|
||||
|
||||
<dto class="io.ebean.NamedDtoQueryTest$DCust3">
|
||||
<raw-sql name="findByName_relaxedMode">
|
||||
<query>
|
||||
select id, name, 42 as total, '42' as something_we_cannot_map from o_customer
|
||||
</query>
|
||||
</raw-sql>
|
||||
<raw-sql name="findByNameLike">
|
||||
<query>
|
||||
select id, name, 42 as totalOrders from o_customer where name like ?
|
||||
</query>
|
||||
</raw-sql>
|
||||
<raw-sql name="findByName">
|
||||
<query>
|
||||
select id, name from o_customer where name = :name
|
||||
</query>
|
||||
</raw-sql>
|
||||
</dto>
|
||||
|
||||
</ebean>
|
||||
@@ -1,30 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
|
||||
<ebean xmlns="http://ebean-orm.github.io/xml/ns/ebean">
|
||||
|
||||
<entity class="org.tests.model.basic.Order">
|
||||
<raw-sql name="myRawTest2">
|
||||
<alias-mapping alias="c" property="customer"/>
|
||||
<alias-mapping alias="a" property="customer.billingAddress"/>
|
||||
<query>
|
||||
select o.id, o.status, o.ship_date, c.id, c.name, a.id, a.line_1, a.line_2, a.city
|
||||
from o_order o
|
||||
join o_customer c on o.kcustomer_id = c.id
|
||||
join o_address a on c.billing_address_id = a.id
|
||||
where o.status = :orderStatus
|
||||
order by c.name, c.id
|
||||
</query>
|
||||
</raw-sql>
|
||||
|
||||
<raw-sql name="myRawTest3">
|
||||
<column-mapping column="o.id" property="id"/>
|
||||
<column-mapping column="o.status" property="status"/>
|
||||
<query>
|
||||
-- must be unparsed raw sql
|
||||
select o.id, o.status
|
||||
from o_order o
|
||||
</query>
|
||||
</raw-sql>
|
||||
|
||||
</entity>
|
||||
|
||||
</ebean>
|
||||
@@ -1,59 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
|
||||
<ebean xmlns="http://ebean-orm.github.io/xml/ns/ebean">
|
||||
|
||||
<entity class="org.tests.model.basic.OrderAggregate">
|
||||
<raw-sql name="default">
|
||||
<column-mapping column="order_id" property="order.id"/>
|
||||
<query>
|
||||
select order_id, count(*) as total_items, sum(order_qty*unit_price) as total_amount
|
||||
from o_order_detail
|
||||
group by order_id
|
||||
</query>
|
||||
</raw-sql>
|
||||
|
||||
<raw-sql name="withMax">
|
||||
<column-mapping column="order_id" property="order.id"/>
|
||||
<query>
|
||||
select order_id, count(*) as total_items, sum(order_qty*unit_price) as total_amount, max(order_qty*unit_price) as maxAmount
|
||||
from o_order_detail
|
||||
group by order_id
|
||||
</query>
|
||||
</raw-sql>
|
||||
|
||||
<raw-sql name="withParam">
|
||||
<column-mapping column="order_id" property="order.id"/>
|
||||
<query>
|
||||
select order_id, count(*) as totalItems, sum(order_qty*unit_price) as totalAmount, max(order_qty*unit_price) as maxAmount
|
||||
from o_order_detail where id > :minId
|
||||
group by order_id
|
||||
</query>
|
||||
</raw-sql>
|
||||
|
||||
</entity>
|
||||
|
||||
<entity class="org.tests.model.basic.Order">
|
||||
<raw-sql name="myRawTest">
|
||||
<alias-mapping alias="c" property="customer"/>
|
||||
<alias-mapping alias="a" property="customer.billingAddress"/>
|
||||
<query>
|
||||
select o.id, o.status, o.ship_date, c.id, c.name, a.id, a.line_1, a.line_2, a.city
|
||||
from o_order o
|
||||
join o_customer c on o.kcustomer_id = c.id
|
||||
join o_address a on c.billing_address_id = a.id
|
||||
where o.status = :orderStatus
|
||||
order by c.name, c.id
|
||||
</query>
|
||||
</raw-sql>
|
||||
</entity>
|
||||
|
||||
<entity class="org.tests.model.basic.Customer">
|
||||
<named-query name="withContactsById">
|
||||
<query>
|
||||
select (name, version)
|
||||
fetch contacts (firstName, lastName, email)
|
||||
where id = :id
|
||||
</query>
|
||||
</named-query>
|
||||
</entity>
|
||||
|
||||
</ebean>
|
||||
@@ -1,23 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
|
||||
<ebean xmlns="http://ebean-orm.github.io/xml/ns/ebean">
|
||||
|
||||
<entity class="org.tests.model.basic.OrderAggregate">
|
||||
<raw-sql name="default">
|
||||
<column-mapping column="order_id" property="order.id"/>
|
||||
<query>
|
||||
select order_id, count(*) as totalItems, sum(order_qty*unit_price) as totalAmount
|
||||
from o_order_detail
|
||||
group by order_id
|
||||
</query>
|
||||
</raw-sql>
|
||||
<raw-sql name="default">
|
||||
<column-mapping column="order_id" property="order.id"/>
|
||||
<query>
|
||||
select order_id, count(*) as totalItems, sum(order_qty*unit_price) as totalAmount
|
||||
from o_order_detail
|
||||
group by order_id
|
||||
</query>
|
||||
</raw-sql>
|
||||
</entity>
|
||||
|
||||
</ebean>
|
||||
Reference in new issue
Block a user