Merge branch 'master' of github.com:ebean-orm/ebean

This commit is contained in:
rob bygrave
2017-10-09 21:13:32 +13:00
39 changed files with 406 additions and 56 deletions
@@ -27,7 +27,7 @@ public class TestExprNestedDisjunction extends BaseTestCase {
q.findList();
String s = q.getGeneratedSql();
assertThat(s).contains("(t0.name like ? ");
assertThat(s).contains("(t0.name like ");
assertThat(s).contains(" and t0.anniversary = ? ) or (t0.status = ? and t0.id > ? )");
}
@@ -51,7 +51,7 @@ public class TestExprNestedDisjunction extends BaseTestCase {
q.findList();
String s = q.getGeneratedSql();
assertThat(s).contains("(t0.name like ? ");
assertThat(s).contains("(t0.name like ");
assertThat(s).contains(" and t0.anniversary = ? ) or (t0.status = ? and t0.id > ? )");
}
@@ -154,7 +154,7 @@ public class TestQueryFetchManyTwoDeep extends BaseTestCase {
Assert.assertTrue(generatedSql.contains("from contact t0 "));
Assert.assertTrue(generatedSql.contains("join o_customer t1 on t1.id = t0.customer_id"));
Assert.assertTrue(generatedSql.contains("where lower(t1.name) like ?"));
Assert.assertTrue(generatedSql.contains("where lower(t1.name) like "));
}
@@ -9,16 +9,17 @@ import org.tests.model.basic.Customer;
import org.tests.model.basic.Order;
import org.tests.model.basic.OrderShipment;
import org.tests.model.basic.ResetBasicData;
import org.avaje.datasource.DataSourcePool;
import org.ebeantest.LoggedSqlCollector;
import org.junit.Test;
import javax.persistence.PersistenceException;
import java.util.List;
import java.util.NoSuchElementException;
import java.util.concurrent.atomic.AtomicInteger;
import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.*;
public class TestQueryFindIterate extends BaseTestCase {
@@ -224,4 +225,39 @@ public class TestQueryFindIterate extends BaseTestCase {
}
});
}
@Test
public void testCloseConnection() throws Exception {
ResetBasicData.reset();
DataSourcePool dsPool = (DataSourcePool) server().getPluginApi().getDataSource();
int startConns = dsPool.getStatus(false).getBusy();
QueryIterator<Customer> queryIterator = server().find(Customer.class)
.where()
.isNotNull("name")
.setMaxRows(3)
.order().asc("id")
.findIterate();
assertThat(dsPool.getStatus(false).getBusy()).isEqualTo(startConns + 1);
assertTrue(queryIterator.hasNext());
assertThat(queryIterator.next()).isNotNull();
assertThat(dsPool.getStatus(false).getBusy()).isEqualTo(startConns + 1);
assertTrue(queryIterator.hasNext());
assertThat(queryIterator.next()).isNotNull();
assertThat(dsPool.getStatus(false).getBusy()).isEqualTo(startConns + 1);
assertTrue(queryIterator.hasNext());
assertThat(queryIterator.next()).isNotNull();
assertThat(dsPool.getStatus(false).getBusy()).isEqualTo(startConns + 1);
assertFalse(queryIterator.hasNext());
assertThat(dsPool.getStatus(false).getBusy()).isEqualTo(startConns);
try {
queryIterator.next();
fail("noSuchElementException expected");
} catch (NoSuchElementException e) {}
}
}
@@ -82,7 +82,7 @@ public class TestAggregationCount extends BaseTestCase {
String sql = sqlOf(query2, 5);
assertThat(sql).contains("select t0.id, t0.name, count(u1.id), sum(u1.units), sum(u1.units * u1.amount) from tevent_one t0");
assertThat(sql).contains("from tevent_one t0 join tevent_many u1 on u1.event_id = t0.id ");
assertThat(sql).contains("where u1.description like ? ");
assertThat(sql).contains("where u1.description like ");
assertThat(sql).contains(" group by t0.id, t0.name having count(u1.id) >= ? order by t0.name");
// invoke lazy loading
@@ -26,7 +26,7 @@ public class TestQueryManyToOneWhereClauseJoin extends BaseTestCase {
query.findList();
//select t0.id c0, t0.status c1, t0.order_date c2, t0.ship_date c3, t1.name c4, t0.cretime c5, t0.updtime c6, t0.kcustomer_id c7
String expectedSql = "from o_order t0 join o_customer t1 on t1.id = t0.kcustomer_id where lower(t1.name) like ? ";
String expectedSql = "from o_order t0 join o_customer t1 on t1.id = t0.kcustomer_id where lower(t1.name) like ";
Assert.assertTrue(query.getGeneratedSql().contains(expectedSql));
// select t0.id c0, t0.status c1, t0.order_date c2, t0.ship_date c3, t1.name c4, t0.cretime c5, t0.updtime c6, t0.kcustomer_id c7
@@ -50,7 +50,7 @@ public class TestQueryManyToOneWhereClauseJoin extends BaseTestCase {
query.findList();
//select t0.id c0, t0.status c1, t0.order_date c2, t0.ship_date c3, t1.name c4, t0.cretime c5, t0.updtime c6, t0.kcustomer_id c7
String expectedSql = "from o_order t0 join o_customer t1 on t1.id = t0.kcustomer_id where (lower(t1.name) like ? ";
String expectedSql = "from o_order t0 join o_customer t1 on t1.id = t0.kcustomer_id where (lower(t1.name) like ";
Assert.assertTrue(query.getGeneratedSql().contains(expectedSql));
// select t0.id c0, t0.status c1, t0.order_date c2, t0.ship_date c3, t1.name c4, t0.cretime c5, t0.updtime c6, t0.kcustomer_id c7
@@ -80,7 +80,7 @@ public class TestQueryManyToOneWhereClauseJoin extends BaseTestCase {
String generatedSql = query.getGeneratedSql();
Assert.assertTrue(generatedSql.contains("from o_order t0 join o_customer t1 on t1.id = t0.kcustomer_id"));
Assert.assertTrue(generatedSql.contains("left join contact t2 on t2.customer_id = t1.id"));
Assert.assertTrue(generatedSql.contains("where lower(t1.name) like ?"));
Assert.assertTrue(generatedSql.contains("where lower(t1.name) like "));
// select t0.id c0, t0.status c1, t0.order_date c2, t0.ship_date c3, t1.name c4, t0.cretime c5, t0.updtime c6,
// t1.id c7, t1.status c8, t1.name c9, t1.smallnote c10, t1.anniversary c11, t1.cretime c12, t1.updtime c13, t1.billing_address_id c14, t1.shipping_address_id c15,
@@ -46,7 +46,7 @@ public class TestOrderByWithDistinctTake2 extends BaseTestCase {
}
assertThat(generatedSql).contains("order by t0.name desc");
assertThat(generatedSql).contains("from o_customer t0 join contact u1 on u1.customer_id = t0.id");
assertThat(generatedSql).contains("where lower(u1.first_name) like ?");
assertThat(generatedSql).contains("where lower(u1.first_name) like ");
}
@Test
@@ -68,7 +68,7 @@ public class TestOrderByWithDistinctTake2 extends BaseTestCase {
}
assertThat(generatedSql).contains("order by t0.name, t0.id desc");
assertThat(generatedSql).contains("from o_customer t0 join contact u1 on u1.customer_id = t0.id");
assertThat(generatedSql).contains("where lower(u1.first_name) like ?");
assertThat(generatedSql).contains("where lower(u1.first_name) like ");
}
}
@@ -22,11 +22,19 @@ public class TestLikeEscaping extends BaseTestCase {
Ebean.save(ResetBasicData.createCustomer("Paul %% Doublepercentage", "|Pipeway", "[other]", 1, null));
Ebean.save(ResetBasicData.createCustomer("_Udo Underscore", "|Pipeway", "[other]", 1, null));
Ebean.save(ResetBasicData.createCustomer("Bodo \\ backslash", "\\BS", "[other]", 1, null));
assertThat(Ebean.find(Customer.class)
.where().contains("name", "Paul %%").findCount()
).isEqualTo(1);
assertThat(Ebean.find(Customer.class)
.where().contains("name", "o \\ b").findCount()
).isEqualTo(1);
assertThat(Ebean.find(Customer.class)
.where().contains("name", "o \\\\ b").findCount()
).isEqualTo(0);
assertThat(Ebean.find(Customer.class)
.where().startsWith("name", "_").findCount()
@@ -48,10 +56,13 @@ public class TestLikeEscaping extends BaseTestCase {
.where().startsWith("shippingAddress.line1", "|P").findCount()
).isEqualTo(2);
assertThat(Ebean.find(Customer.class)
.where().startsWith("shippingAddress.line1", "\\B").findCount()
).isEqualTo(1);
assertThat(Ebean.find(Customer.class)
.where().endsWith("billingAddress.line1", "]").findCount()
).isEqualTo(4);
).isEqualTo(5);
assertThat(Ebean.find(Customer.class)
.where().endsWith("billingAddress.line1", "[none]").findCount()
@@ -112,7 +112,7 @@ public class TestQuerySingleAttribute extends BaseTestCase {
List<String> names = query.findSingleAttributeList();
assertThat(sqlOf(query)).contains("select distinct t0.name from o_customer t0 left join o_address t1 on t1.id = t0.billing_address_id where t0.status = ? and lower(t1.city) like ?");
assertThat(sqlOf(query)).contains("select distinct t0.name from o_customer t0 left join o_address t1 on t1.id = t0.billing_address_id where t0.status = ? and lower(t1.city) like ");
assertThat(names).isNotNull();
}