ENH: Add mappingsLocation config to search xml mapping files.

ENH: Add mappingsLocation config to search xml mapping files.

ENH: Add mappingsLocation config to search xml mapping files.

ENH: Add mappingsLocation config to search xml mapping files.

ENH: Add mappingsLocation config to search xml mapping files.

ENH: Add mappingsLocation config to search xml mapping files.

remove unused import.

ENH: Add mappingsLocation config and search xml mapping files feature.
This commit is contained in:
yuanxuegui committed 2018-03-17 17:27:51 +08:00
1 parent 9895e48485
commit 9d336cb20b
7 files changed
+159 -21

No files matched your search

@@ -250,4 +250,19 @@ public class EbeanServer_eqlTest extends BaseTestCase {
assertThat(query.getGeneratedSql()).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();
assertThat(query.getGeneratedSql()).contains("from o_customer t0 left join contact t1 on t1.customer_id = t0.id ");
}
}
@@ -51,6 +51,32 @@ public class TestRawSqlOrmQuery extends BaseTestCase {
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");
}
@Test
public void test() {
@@ -0,0 +1,14 @@
<?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>
@@ -0,0 +1,19 @@
<?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>
</entity>
</ebean>
+2
View File
@@ -168,3 +168,5 @@ ebean.migrationtest.ddl.header=-- Migrationscripts for ebean unittest
ebean.migrationtest.migration.appName=migrationtest
ebean.migrationtest.migration.migrationPath=dbmigration/migrationtest
ebean.migrationtest.migration.strict=true
ebean.mappingsLocations=classpath:/ebean-xml-mappings