mirror of
https://github.com/ebean-orm/ebean.git
synced 2024-04-21 10:51:47 +00:00
Sqlserver support (#1053)
* made some tests sqlserver ready (No effective code change in src/main) * FIX enhance packages and let all testcases inherit from BaseTestCase, so that they can be launched directly from eclipse * ADD sqldriver in pom and datasource * FIX: DDL-generation for sqlserver - not yet all sqlserver tests passing mvn verify -Ddatasource.default=mssql => Tests run: 1980, Failures: 22, Errors: 44, Skipped: 16 * BaseDdlHandlerTest checks against correct sqlserver-ddl now
This commit is contained in:
committed by
Rob Bygrave
parent
e49c4bfe5a
commit
2001539755
@@ -1,5 +1,6 @@
|
||||
package io.ebean;
|
||||
|
||||
import io.ebean.util.StringHelper;
|
||||
import io.ebeaninternal.api.SpiEbeanServer;
|
||||
import io.ebeaninternal.server.deploy.BeanDescriptor;
|
||||
import org.tests.model.basic.Country;
|
||||
@@ -15,7 +16,7 @@ public class BaseTestCase {
|
||||
|
||||
static {
|
||||
logger.debug("... preStart");
|
||||
if (!AgentLoader.loadAgentFromClasspath("ebean-agent", "debug=1;packages=com.avaje.tests,org.avaje.test")) {
|
||||
if (!AgentLoader.loadAgentFromClasspath("ebean-agent", "debug=1;packages=org.tests,org.avaje.test,io.ebean")) {
|
||||
logger.info("avaje-ebeanorm-agent not found in classpath - not dynamically loaded");
|
||||
}
|
||||
}
|
||||
@@ -39,10 +40,10 @@ public class BaseTestCase {
|
||||
*/
|
||||
protected String trimSql(String sql, int columns) {
|
||||
for (int i = 0; i <= columns; i++) {
|
||||
sql = sql.replace(" c" + i + ",", ",");
|
||||
sql = StringHelper.replaceString(sql, " c" + i + ",", ",");
|
||||
}
|
||||
for (int i = 0; i <= columns; i++) {
|
||||
sql = sql.replace(" c" + i + " ", " ");
|
||||
sql = StringHelper.replaceString(sql, " c" + i + " ", " ");
|
||||
}
|
||||
return sql;
|
||||
}
|
||||
|
||||
@@ -8,7 +8,7 @@ import org.mockito.Mockito;
|
||||
|
||||
import javax.sql.DataSource;
|
||||
|
||||
public class EbeanServerFactory_MultiTenancy_Test {
|
||||
public class EbeanServerFactory_MultiTenancy_Test extends BaseTestCase {
|
||||
|
||||
/**
|
||||
* Tests using multi tenancy per database
|
||||
|
||||
@@ -10,7 +10,7 @@ import java.util.List;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
|
||||
public class EbeanServer_deleteAllByIdTest {
|
||||
public class EbeanServer_deleteAllByIdTest extends BaseTestCase {
|
||||
|
||||
@Test
|
||||
public void deleteAllById() {
|
||||
|
||||
@@ -9,7 +9,7 @@ import java.util.List;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
|
||||
public class EbeanServer_deleteByIdTest {
|
||||
public class EbeanServer_deleteByIdTest extends BaseTestCase {
|
||||
|
||||
@Test
|
||||
public void deleteById() {
|
||||
|
||||
@@ -9,7 +9,7 @@ import java.util.List;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
|
||||
public class EbeanServer_deleteTest {
|
||||
public class EbeanServer_deleteTest extends BaseTestCase {
|
||||
|
||||
@Test
|
||||
public void delete() {
|
||||
|
||||
@@ -20,7 +20,12 @@ public class EbeanServer_eqlTest extends BaseTestCase {
|
||||
query.setMaxRows(100);
|
||||
query.findList();
|
||||
|
||||
assertThat(query.getGeneratedSql()).contains("order by t0.id ");
|
||||
if (isSqlServer()) {
|
||||
assertThat(query.getGeneratedSql()).startsWith("select top 100 ");
|
||||
assertThat(query.getGeneratedSql()).endsWith("order by t0.id");
|
||||
} else {
|
||||
assertThat(query.getGeneratedSql()).endsWith("order by t0.id limit 100");
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -31,9 +36,81 @@ public class EbeanServer_eqlTest extends BaseTestCase {
|
||||
Query<Customer> query = Ebean.createQuery(Customer.class, "order by id limit 10");
|
||||
query.findList();
|
||||
|
||||
assertThat(query.getGeneratedSql()).contains("order by t0.id ");
|
||||
if (isSqlServer()) {
|
||||
assertThat(query.getGeneratedSql()).startsWith("select top 10 ");
|
||||
assertThat(query.getGeneratedSql()).endsWith("order by t0.id");
|
||||
} else {
|
||||
assertThat(query.getGeneratedSql()).endsWith("order by t0.id limit 10");
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void basic_limit_offset1() {
|
||||
|
||||
ResetBasicData.reset();
|
||||
|
||||
Query<Customer> query = Ebean.createQuery(Customer.class, "order by id limit 10 offset 3");
|
||||
query.findList();
|
||||
|
||||
if (isSqlServer()) {
|
||||
assertThat(query.getGeneratedSql()).endsWith("order by t0.id offset 3 rows fetch next 10 rows only");
|
||||
} else {
|
||||
assertThat(query.getGeneratedSql()).endsWith("order by t0.id limit 10 offset 3");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void basic_limit_offset2() {
|
||||
|
||||
ResetBasicData.reset();
|
||||
|
||||
Query<Customer> query = Ebean.createQuery(Customer.class, "order by name");
|
||||
query.setMaxRows(10);
|
||||
query.setFirstRow(3);
|
||||
query.findList();
|
||||
|
||||
if (isSqlServer()) {
|
||||
assertThat(query.getGeneratedSql()).endsWith("order by t0.name, t0.id offset 3 rows fetch next 10 rows only");
|
||||
} else {
|
||||
assertThat(query.getGeneratedSql()).endsWith("order by t0.name, t0.id limit 10 offset 3");
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void basic_limit_offset3() {
|
||||
|
||||
ResetBasicData.reset();
|
||||
|
||||
Query<Customer> query = Ebean.createQuery(Customer.class);
|
||||
query.setMaxRows(10);
|
||||
query.setFirstRow(3);
|
||||
query.findList();
|
||||
|
||||
if (isSqlServer()) {
|
||||
assertThat(query.getGeneratedSql()).endsWith("order by t0.id offset 3 rows fetch next 10 rows only");
|
||||
} else {
|
||||
assertThat(query.getGeneratedSql()).endsWith("order by t0.id limit 10 offset 3");
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void basic_limit_offset4() {
|
||||
|
||||
ResetBasicData.reset();
|
||||
|
||||
Query<Customer> query = Ebean.createQuery(Customer.class);
|
||||
query.setMaxRows(10);
|
||||
query.findList();
|
||||
|
||||
if (isSqlServer()) {
|
||||
assertThat(query.getGeneratedSql()).startsWith("select top 10 ");
|
||||
assertThat(query.getGeneratedSql()).endsWith("order by t0.id");
|
||||
} else {
|
||||
assertThat(query.getGeneratedSql()).endsWith("order by t0.id limit 10");
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void orderBy_override() {
|
||||
|
||||
|
||||
@@ -10,7 +10,9 @@ public class SqlRowBooleanTest extends BaseTestCase {
|
||||
public void getBoolean() {
|
||||
|
||||
SqlQuery sqlQuery;
|
||||
if (isOracle()) {
|
||||
if (isSqlServer()) {
|
||||
sqlQuery = Ebean.createSqlQuery("SELECT 1 AS ISNT_NULL");
|
||||
} else if (isOracle()) {
|
||||
sqlQuery = Ebean.createSqlQuery("SELECT 1 AS ISNT_NULL from dual");
|
||||
} else {
|
||||
sqlQuery = Ebean.createSqlQuery("SELECT 1 IS NOT NULL AS ISNT_NULL");
|
||||
|
||||
@@ -40,7 +40,7 @@ public class BaseDdlHandlerTest extends BaseTestCase {
|
||||
|
||||
write = new DdlWrite();
|
||||
sqlserverHandler().generate(write, Helper.getAddColumn());
|
||||
assertThat(write.apply().getBuffer()).isEqualTo("alter table foo add column added_to_foo varchar(20);\n\n");
|
||||
assertThat(write.apply().getBuffer()).isEqualTo("alter table foo add added_to_foo varchar(20);\n\n");
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -68,7 +68,7 @@ public class BaseDdlHandlerTest extends BaseTestCase {
|
||||
|
||||
DdlHandler sqlserverHandler = sqlserverHandler();
|
||||
sqlserverHandler.generate(write, Helper.getAlterTableAddDbArrayColumn());
|
||||
assertThat(write.apply().getBuffer()).isEqualTo("alter table foo add column dbarray_added_to_foo varchar(1000);\n\n");
|
||||
assertThat(write.apply().getBuffer()).isEqualTo("alter table foo add dbarray_added_to_foo varchar(1000);\n\n");
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -85,7 +85,7 @@ public class BaseDdlHandlerTest extends BaseTestCase {
|
||||
|
||||
write = new DdlWrite();
|
||||
sqlserverHandler().generate(write, Helper.getAlterTableAddDbArrayColumnWithLength());
|
||||
assertThat(write.apply().getBuffer()).isEqualTo("alter table foo add column dbarray_ninety varchar(90);\n\n");
|
||||
assertThat(write.apply().getBuffer()).isEqualTo("alter table foo add dbarray_ninety varchar(90);\n\n");
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -101,11 +101,11 @@ public class BaseDdlHandlerTest extends BaseTestCase {
|
||||
|
||||
write = new DdlWrite();
|
||||
sqlserverHandler().generate(write, Helper.getAlterTableAddDbArrayColumnIntegerWithLength());
|
||||
assertThat(write.apply().getBuffer()).isEqualTo("alter table foo add column dbarray_integer varchar(90);\n\n");
|
||||
assertThat(write.apply().getBuffer()).isEqualTo("alter table foo add dbarray_integer varchar(90);\n\n");
|
||||
|
||||
write = new DdlWrite();
|
||||
sqlserverHandler().generate(write, Helper.getAlterTableAddDbArrayColumnInteger());
|
||||
assertThat(write.apply().getBuffer()).isEqualTo("alter table foo add column dbarray_integer varchar(1000);\n\n");
|
||||
assertThat(write.apply().getBuffer()).isEqualTo("alter table foo add dbarray_integer varchar(1000);\n\n");
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package io.ebean.plugin;
|
||||
|
||||
import io.ebean.BaseTestCase;
|
||||
import io.ebean.Ebean;
|
||||
import io.ebean.EbeanServer;
|
||||
import org.tests.model.basic.Customer;
|
||||
@@ -10,7 +11,7 @@ import java.util.List;
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
|
||||
public class SpiServerTest {
|
||||
public class SpiServerTest extends BaseTestCase {
|
||||
|
||||
@Test
|
||||
public void test() {
|
||||
|
||||
@@ -48,8 +48,6 @@ public class TestBatchInsertSimple extends BaseTestCase {
|
||||
@Test
|
||||
public void testTransactional() {
|
||||
|
||||
if (isSqlServer()) return;
|
||||
|
||||
saveWithFullBatchMode();
|
||||
}
|
||||
|
||||
@@ -123,9 +121,6 @@ public class TestBatchInsertSimple extends BaseTestCase {
|
||||
@Test
|
||||
public void testJdbcBatchOnCollection() {
|
||||
|
||||
// MS SQL Server doesn't like batch inserts when we need getGeneratedKeys
|
||||
if (isSqlServer()) return;
|
||||
|
||||
int numOfMasters = 3;
|
||||
|
||||
List<UTMaster> masters = new ArrayList<>();
|
||||
|
||||
@@ -18,7 +18,6 @@ public class TestBatchInsertWithInitialisedCollection extends BaseTestCase {
|
||||
@Test
|
||||
public void test() {
|
||||
|
||||
if (isSqlServer()) return;
|
||||
|
||||
List<OCachedBean> list = new ArrayList();
|
||||
|
||||
|
||||
@@ -54,7 +54,11 @@ public class TestSecondaryQueries extends BaseTestCase {
|
||||
List<String> sql = LoggedSqlCollector.stop();
|
||||
|
||||
assertThat(sql).hasSize(1);
|
||||
assertThat(trimSql(sql.get(0), 2)).contains("select t0.id, t0.status, t0.kcustomer_id from o_order t0");
|
||||
if (isSqlServer()) {
|
||||
assertThat(trimSql(sql.get(0), 2)).contains("select top 10 t0.id, t0.status, t0.kcustomer_id from o_order t0 order by t0.id");
|
||||
} else {
|
||||
assertThat(trimSql(sql.get(0), 2)).contains("select t0.id, t0.status, t0.kcustomer_id from o_order t0");
|
||||
}
|
||||
|
||||
LoggedSqlCollector.start();
|
||||
|
||||
|
||||
@@ -1,8 +1,12 @@
|
||||
package org.tests.compositekeys;
|
||||
|
||||
import io.ebean.BaseTestCase;
|
||||
import io.ebean.Ebean;
|
||||
import io.ebean.Query;
|
||||
import io.ebean.Transaction;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.tests.compositekeys.db.Item;
|
||||
import org.tests.compositekeys.db.ItemKey;
|
||||
import org.tests.compositekeys.db.Region;
|
||||
@@ -11,7 +15,8 @@ import org.tests.compositekeys.db.SubType;
|
||||
import org.tests.compositekeys.db.SubTypeKey;
|
||||
import org.tests.compositekeys.db.Type;
|
||||
import org.tests.compositekeys.db.TypeKey;
|
||||
import org.tests.lib.EbeanTestCase;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@@ -22,25 +27,24 @@ import java.util.List;
|
||||
* <li>find</li>
|
||||
* </ul>
|
||||
*/
|
||||
public class TestCore extends EbeanTestCase {
|
||||
public class TestCore extends BaseTestCase {
|
||||
|
||||
@Override
|
||||
@Before
|
||||
public void setUp() throws Exception {
|
||||
if (isMsSqlServer()) return;
|
||||
|
||||
Ebean.createUpdate(Item.class, "delete from Item").execute();
|
||||
Ebean.createUpdate(Region.class, "delete from Region").execute();
|
||||
Ebean.createUpdate(Type.class, "delete from Type").execute();
|
||||
Ebean.createUpdate(SubType.class, "delete from SubType").execute();
|
||||
|
||||
Transaction tx = getServer().beginTransaction();
|
||||
Transaction tx = server().beginTransaction();
|
||||
|
||||
SubType subType = new SubType();
|
||||
SubTypeKey subTypeKey = new SubTypeKey();
|
||||
subTypeKey.setSubTypeId(1);
|
||||
subType.setKey(subTypeKey);
|
||||
subType.setDescription("ANY SUBTYPE");
|
||||
getServer().save(subType);
|
||||
server().save(subType);
|
||||
|
||||
Type type = new Type();
|
||||
TypeKey typeKey = new TypeKey();
|
||||
@@ -49,7 +53,7 @@ public class TestCore extends EbeanTestCase {
|
||||
type.setKey(typeKey);
|
||||
type.setDescription("Type Old-Item - Customer 1");
|
||||
type.setSubType(subType);
|
||||
getServer().save(type);
|
||||
server().save(type);
|
||||
|
||||
type = new Type();
|
||||
typeKey = new TypeKey();
|
||||
@@ -58,7 +62,7 @@ public class TestCore extends EbeanTestCase {
|
||||
type.setKey(typeKey);
|
||||
type.setDescription("Type Old-Item - Customer 2");
|
||||
type.setSubType(subType);
|
||||
getServer().save(type);
|
||||
server().save(type);
|
||||
|
||||
Region region = new Region();
|
||||
RegionKey regionKey = new RegionKey();
|
||||
@@ -66,7 +70,7 @@ public class TestCore extends EbeanTestCase {
|
||||
regionKey.setType(500);
|
||||
region.setKey(regionKey);
|
||||
region.setDescription("Region West - Customer 1");
|
||||
getServer().save(region);
|
||||
server().save(region);
|
||||
|
||||
region = new Region();
|
||||
regionKey = new RegionKey();
|
||||
@@ -74,7 +78,7 @@ public class TestCore extends EbeanTestCase {
|
||||
regionKey.setType(500);
|
||||
region.setKey(regionKey);
|
||||
region.setDescription("Region West - Customer 2");
|
||||
getServer().save(region);
|
||||
server().save(region);
|
||||
|
||||
Item item = new Item();
|
||||
ItemKey itemKey = new ItemKey();
|
||||
@@ -85,7 +89,7 @@ public class TestCore extends EbeanTestCase {
|
||||
item.setDescription("Fancy Car - Customer 1");
|
||||
item.setRegion(500);
|
||||
item.setType(10);
|
||||
getServer().save(item);
|
||||
server().save(item);
|
||||
|
||||
item = new Item();
|
||||
itemKey = new ItemKey();
|
||||
@@ -96,20 +100,20 @@ public class TestCore extends EbeanTestCase {
|
||||
item.setDescription("Another Fancy Car - Customer 2");
|
||||
item.setRegion(500);
|
||||
item.setType(10);
|
||||
getServer().save(item);
|
||||
server().save(item);
|
||||
|
||||
tx.commit();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testFind() {
|
||||
if (isMsSqlServer()) return;
|
||||
|
||||
List<Item> items = getServer().find(Item.class).findList();
|
||||
List<Item> items = server().find(Item.class).findList();
|
||||
|
||||
assertNotNull(items);
|
||||
assertEquals(2, items.size());
|
||||
|
||||
Query<Item> qItems = getServer().find(Item.class);
|
||||
Query<Item> qItems = server().find(Item.class);
|
||||
// qItems.where(Expr.eq("key.customer", Integer.valueOf(1)));
|
||||
|
||||
// I want to discourage the direct use of Expr
|
||||
@@ -123,15 +127,14 @@ public class TestCore extends EbeanTestCase {
|
||||
/**
|
||||
* This partially loads the item and then lazy loads the ManyToOne assoc
|
||||
*/
|
||||
@Test
|
||||
public void testDoubleLazyLoad() {
|
||||
|
||||
if (isMsSqlServer()) return;
|
||||
|
||||
ItemKey itemKey = new ItemKey();
|
||||
itemKey.setCustomer(2);
|
||||
itemKey.setItemNumber("ITEM1");
|
||||
|
||||
Item item = getServer().find(Item.class).select("description").where().idEq(itemKey).findUnique();
|
||||
Item item = server().find(Item.class).select("description").where().idEq(itemKey).findUnique();
|
||||
assertNotNull(item);
|
||||
assertNotNull(item.getUnits());
|
||||
assertEquals("P", item.getUnits());
|
||||
@@ -144,23 +147,19 @@ public class TestCore extends EbeanTestCase {
|
||||
assertNotNull(subType);
|
||||
assertNotNull(subType.getDescription());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testEmbeddedWithOrder() {
|
||||
|
||||
if (isMsSqlServer()) return;
|
||||
|
||||
List<Item> items = getServer().find(Item.class).order("auditInfo.created asc, type asc").findList();
|
||||
List<Item> items = server().find(Item.class).order("auditInfo.created asc, type asc").findList();
|
||||
|
||||
assertNotNull(items);
|
||||
assertEquals(2, items.size());
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testFindAndOrderByEType() {
|
||||
|
||||
if (isMsSqlServer()) return;
|
||||
|
||||
List<Item> items = getServer().find(Item.class).order("eType").findList();
|
||||
List<Item> items = server().find(Item.class).order("eType").findList();
|
||||
|
||||
assertNotNull(items);
|
||||
assertEquals(2, items.size());
|
||||
|
||||
-8
@@ -33,8 +33,6 @@ public class TestOnCascadeDeleteChildrenWithCompositeKeys extends BaseTestCase {
|
||||
@Before
|
||||
public void before() {
|
||||
|
||||
if (isSqlServer()) return;
|
||||
|
||||
// remove all the User records first
|
||||
Ebean.deleteAll(Ebean.find(User.class).findList());
|
||||
|
||||
@@ -49,8 +47,6 @@ public class TestOnCascadeDeleteChildrenWithCompositeKeys extends BaseTestCase {
|
||||
@Test
|
||||
public void testDeleteById() {
|
||||
|
||||
if (isSqlServer()) return;
|
||||
|
||||
assertEquals(2, Ebean.find(User.class).findList().size());
|
||||
Ebean.delete(User.class, 1L);
|
||||
Ebean.delete(User.class, 2L);
|
||||
@@ -64,8 +60,6 @@ public class TestOnCascadeDeleteChildrenWithCompositeKeys extends BaseTestCase {
|
||||
@Test
|
||||
public void testDeleteByIdList() {
|
||||
|
||||
if (isSqlServer()) return;
|
||||
|
||||
assertEquals(2, Ebean.find(User.class).findList().size());
|
||||
List<Long> ids = new ArrayList<>();
|
||||
ids.add(1L);
|
||||
@@ -78,8 +72,6 @@ public class TestOnCascadeDeleteChildrenWithCompositeKeys extends BaseTestCase {
|
||||
@Test
|
||||
public void testFindByParentIdList() {
|
||||
|
||||
if (isSqlServer()) return;
|
||||
|
||||
assertEquals(2, Ebean.find(User.class).findList().size());
|
||||
|
||||
SpiEbeanServer spiServer = (SpiEbeanServer) Ebean.getServer(null);
|
||||
|
||||
@@ -15,8 +15,6 @@ public class TestDeleteByIdWithPersistenceContext extends BaseTestCase {
|
||||
@Test
|
||||
public void test() {
|
||||
|
||||
if (isSqlServer()) return;
|
||||
|
||||
ResetBasicData.reset();
|
||||
|
||||
Ebean.delete(Product.class, 100);
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package org.tests.el;
|
||||
|
||||
import io.ebean.BaseTestCase;
|
||||
import io.ebean.Ebean;
|
||||
import io.ebean.Query;
|
||||
import org.tests.model.basic.Customer;
|
||||
@@ -7,7 +8,7 @@ import org.junit.Test;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
public class TestUnderscoreParam {
|
||||
public class TestUnderscoreParam extends BaseTestCase {
|
||||
|
||||
@Test
|
||||
public void test() {
|
||||
|
||||
@@ -1,29 +1,34 @@
|
||||
package org.tests.idkeys;
|
||||
|
||||
import org.tests.lib.EbeanTestCase;
|
||||
import org.junit.Test;
|
||||
import org.tests.model.basic.TOne;
|
||||
|
||||
import io.ebean.BaseTestCase;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
import java.sql.SQLException;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Test lazy loading
|
||||
*/
|
||||
public class TestLazyLoad extends EbeanTestCase {
|
||||
public class TestLazyLoad extends BaseTestCase {
|
||||
/**
|
||||
* This test loads just a single property of the Entity AuditLog and later on access
|
||||
* the description which should force a lazy load of this property
|
||||
*/
|
||||
@Test
|
||||
public void testPartialLoad() throws SQLException {
|
||||
TOne log = new TOne();
|
||||
log.setName("test partial");
|
||||
log.setDescription("log");
|
||||
|
||||
getServer().save(log);
|
||||
server().save(log);
|
||||
|
||||
assertNotNull(log.getId());
|
||||
|
||||
List<TOne> logs = getServer().find(TOne.class)
|
||||
List<TOne> logs = server().find(TOne.class)
|
||||
.select("id")
|
||||
.where().eq("id", log.getId())
|
||||
.findList();
|
||||
|
||||
@@ -1,9 +1,13 @@
|
||||
package org.tests.idkeys;
|
||||
|
||||
import io.ebean.BaseTestCase;
|
||||
import io.ebean.Transaction;
|
||||
import io.ebean.bean.EntityBean;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.tests.idkeys.db.AuditLog;
|
||||
import org.tests.lib.EbeanTestCase;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
import java.beans.PropertyChangeEvent;
|
||||
import java.beans.PropertyChangeListener;
|
||||
@@ -17,7 +21,7 @@ import java.util.List;
|
||||
/**
|
||||
* Test various aspects of the PropertyChangeSupport
|
||||
*/
|
||||
public class TestPropertyChangeSupport extends EbeanTestCase implements PropertyChangeListener {
|
||||
public class TestPropertyChangeSupport extends BaseTestCase implements PropertyChangeListener {
|
||||
private int nuofEvents = 0;
|
||||
private List<PropertyChangeEvent> pces = new ArrayList<>();
|
||||
private PropertyChangeEvent lastPce;
|
||||
@@ -32,6 +36,7 @@ public class TestPropertyChangeSupport extends EbeanTestCase implements Property
|
||||
/**
|
||||
* Test the core property change functionality
|
||||
*/
|
||||
@Test
|
||||
public void testPropertyChange() throws SQLException {
|
||||
resetEvent();
|
||||
|
||||
@@ -61,7 +66,7 @@ public class TestPropertyChangeSupport extends EbeanTestCase implements Property
|
||||
resetEvent();
|
||||
|
||||
// test if we get change notification if EBean assigns an id to the bean
|
||||
getServer().save(al);
|
||||
server().save(al);
|
||||
|
||||
assertNotNull(lastPce);
|
||||
assertEquals("id", lastPce.getPropertyName());
|
||||
@@ -73,7 +78,7 @@ public class TestPropertyChangeSupport extends EbeanTestCase implements Property
|
||||
resetEvent();
|
||||
|
||||
// simulate external change and test if we get change notification when we refresh the entity
|
||||
Transaction tx = getServer().beginTransaction();
|
||||
Transaction tx = server().beginTransaction();
|
||||
PreparedStatement pstm = tx.getConnection().prepareStatement("update audit_log set description = ? where id = ?");
|
||||
pstm.setString(1, "GHI");
|
||||
pstm.setLong(2, al.getId());
|
||||
@@ -87,7 +92,7 @@ public class TestPropertyChangeSupport extends EbeanTestCase implements Property
|
||||
assertNull(lastPce);
|
||||
assertEquals(0, nuofEvents);
|
||||
|
||||
getServer().refresh(al);
|
||||
server().refresh(al);
|
||||
|
||||
assertEquals("GHI", al.getDescription());
|
||||
|
||||
@@ -114,17 +119,18 @@ public class TestPropertyChangeSupport extends EbeanTestCase implements Property
|
||||
* <li>updating a lazy loaded property fires two events</li>
|
||||
* </ul>
|
||||
*/
|
||||
@Test
|
||||
public void testPartialLoad() throws SQLException {
|
||||
AuditLog log = new AuditLog();
|
||||
log.setDescription("log");
|
||||
|
||||
getServer().save(log);
|
||||
server().save(log);
|
||||
|
||||
assertNotNull(log.getId());
|
||||
|
||||
resetEvent();
|
||||
|
||||
List<AuditLog> logs = getServer().find(AuditLog.class)
|
||||
List<AuditLog> logs = server().find(AuditLog.class)
|
||||
.where().eq("id", log.getId())
|
||||
.select("id")
|
||||
.findList();
|
||||
|
||||
@@ -18,8 +18,6 @@ public class TestInsertBatchThenFlushThenUpdate extends BaseTestCase {
|
||||
@Test
|
||||
public void test() {
|
||||
|
||||
if (isSqlServer()) return;
|
||||
|
||||
LoggedSqlCollector.start();
|
||||
Transaction txn = Ebean.beginTransaction();
|
||||
try {
|
||||
|
||||
@@ -18,8 +18,6 @@ public class TestInsertBatchThenUpdate extends BaseTestCase {
|
||||
@Test
|
||||
public void test() {
|
||||
|
||||
if (isSqlServer()) return;
|
||||
|
||||
LoggedSqlCollector.start();
|
||||
Transaction txn = Ebean.beginTransaction();
|
||||
try {
|
||||
|
||||
@@ -17,8 +17,6 @@ public class TestInsertBatchWithDifferentRootTypes extends BaseTestCase {
|
||||
@Test
|
||||
public void testDifferRootTypes() {
|
||||
|
||||
if (isSqlServer()) return;
|
||||
|
||||
LoggedSqlCollector.start();
|
||||
Transaction txn = Ebean.beginTransaction();
|
||||
try {
|
||||
|
||||
@@ -1,13 +1,15 @@
|
||||
package org.tests.model.composite;
|
||||
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
import javax.persistence.Embeddable;
|
||||
|
||||
/**
|
||||
* @author rnentjes
|
||||
*/
|
||||
@Embeddable
|
||||
public class ROrderPK {
|
||||
public class ROrderPK implements Serializable {
|
||||
|
||||
private static final long serialVersionUID = 7632735517186104883L;
|
||||
|
||||
|
||||
@@ -13,15 +13,17 @@ public class TestOrderByWithFunction extends BaseTestCase {
|
||||
@Test
|
||||
public void testWithFunction() {
|
||||
|
||||
if (isSqlServer()) return;
|
||||
|
||||
ResetBasicData.reset();
|
||||
|
||||
Query<Customer> query = Ebean.find(Customer.class).order("length(name),name");
|
||||
String length = "length";
|
||||
if (isSqlServer()) {
|
||||
length = "len";
|
||||
}
|
||||
|
||||
Query<Customer> query = Ebean.find(Customer.class).order(length + "(name),name");
|
||||
|
||||
query.findList();
|
||||
String sql = query.getGeneratedSql();
|
||||
|
||||
Assert.assertTrue(sql.contains("order by length(t0.name)"));
|
||||
Assert.assertTrue(sql.contains("order by " + length + "(t0.name)"));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -31,7 +31,14 @@ public class SqlQueryTests extends BaseTestCase {
|
||||
|
||||
List<String> sql = LoggedSqlCollector.stop();
|
||||
|
||||
assertThat(sql.get(0)).contains("Select * from o_order limit 10 offset 3; --bind()");
|
||||
if (isSqlServer()) {
|
||||
// FIXME: we should order by primary key ALWAYS (not by first column) when no
|
||||
// explicit order is specified. In postgres this leads to strange scrolling
|
||||
// artifacts.
|
||||
assertThat(sql.get(0)).contains("order by 1 offset 3 rows fetch next 10 rows only");
|
||||
} else {
|
||||
assertThat(sql.get(0)).contains("Select * from o_order limit 10 offset 3; --bind()");
|
||||
}
|
||||
assertThat(list).isNotEmpty();
|
||||
}
|
||||
|
||||
@@ -65,7 +72,11 @@ public class SqlQueryTests extends BaseTestCase {
|
||||
sqlQuery.findList();
|
||||
List<String> sql = LoggedSqlCollector.stop();
|
||||
|
||||
assertThat(sql.get(0)).contains("Select * from o_order order by id limit 10");
|
||||
if (isSqlServer()) {
|
||||
assertThat(sql.get(0)).contains("Select * from o_order order by id offset 0 rows fetch next 10 rows only;");
|
||||
} else {
|
||||
assertThat(sql.get(0)).contains("Select * from o_order order by id limit 10");
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -81,7 +92,11 @@ public class SqlQueryTests extends BaseTestCase {
|
||||
sqlQuery.findList();
|
||||
List<String> sql = LoggedSqlCollector.stop();
|
||||
|
||||
assertThat(sql.get(0)).contains("select * from o_order where o_order.id > ? order by id limit 10;");
|
||||
if (isSqlServer()) {
|
||||
assertThat(sql.get(0)).contains("select * from o_order where o_order.id > ? order by id offset 0 rows fetch next 10 rows only;");
|
||||
} else {
|
||||
assertThat(sql.get(0)).contains("select * from o_order where o_order.id > ? order by id limit 10;");
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -96,7 +111,11 @@ public class SqlQueryTests extends BaseTestCase {
|
||||
sqlQuery.findEach(bean -> bean.get("id"));
|
||||
List<String> sql = LoggedSqlCollector.stop();
|
||||
|
||||
assertThat(sql.get(0)).contains("limit 10");
|
||||
if (isSqlServer()) {
|
||||
assertThat(sql.get(0)).contains("offset 0 rows fetch next 10 rows only");
|
||||
} else {
|
||||
assertThat(sql.get(0)).contains("limit 10");
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
@@ -11,8 +11,6 @@ public class TestInsertSqlLogging extends BaseTestCase {
|
||||
@Test
|
||||
public void test() {
|
||||
|
||||
if (isSqlServer()) return;
|
||||
|
||||
Ebean.delete(AuditLog.class, 10000);
|
||||
|
||||
String sql = "insert into audit_log (id, description, modified_description) values (?,?,?)";
|
||||
|
||||
@@ -35,7 +35,13 @@ public class TestRawSqlOrmQuery extends BaseTestCase {
|
||||
}
|
||||
|
||||
String sql = query.getGeneratedSql();
|
||||
assertThat(sql).contains("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");
|
||||
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");
|
||||
}
|
||||
@@ -78,8 +84,6 @@ public class TestRawSqlOrmQuery extends BaseTestCase {
|
||||
@Test
|
||||
public void testFirstRowsMaxRows() throws InterruptedException, ExecutionException {
|
||||
|
||||
if (isSqlServer()) return;
|
||||
|
||||
ResetBasicData.reset();
|
||||
|
||||
RawSql rawSql =
|
||||
@@ -158,7 +162,12 @@ public class TestRawSqlOrmQuery extends BaseTestCase {
|
||||
query.setMaxRows(100);
|
||||
query.findList();
|
||||
|
||||
assertThat(query.getGeneratedSql()).contains("order by o.ship_date desc, o.id limit 100");
|
||||
if (isSqlServer()) {
|
||||
assertThat(query.getGeneratedSql()).contains("top 100 ");
|
||||
assertThat(query.getGeneratedSql()).contains("order by o.ship_date desc, o.id");
|
||||
} else {
|
||||
assertThat(query.getGeneratedSql()).contains("order by o.ship_date desc, o.id limit 100");
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -176,10 +185,20 @@ public class TestRawSqlOrmQuery extends BaseTestCase {
|
||||
query.setRawSql(rawSql);
|
||||
|
||||
query.setMaxRows(100);
|
||||
query.order("coalesce(shipDate, now()) desc");
|
||||
query.findList();
|
||||
|
||||
if (isSqlServer()) {
|
||||
query.order("coalesce(shipDate, getdate()) desc");
|
||||
query.findList();
|
||||
|
||||
assertThat(query.getGeneratedSql()).contains("order by coalesce(o.ship_date, now()) desc, o.id limit 100");
|
||||
assertThat(sqlOf(query)).contains("order by coalesce(o.ship_date, getdate()) desc, o.id");
|
||||
assertThat(sqlOf(query)).contains("select top 100");
|
||||
|
||||
} else {
|
||||
query.order("coalesce(shipDate, now()) desc");
|
||||
query.findList();
|
||||
|
||||
assertThat(query.getGeneratedSql()).contains("order by coalesce(o.ship_date, now()) desc, o.id limit 100");
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -202,6 +221,11 @@ public class TestRawSqlOrmQuery extends BaseTestCase {
|
||||
pagedList.getList();
|
||||
pagedList.getTotalCount();
|
||||
|
||||
assertThat(query.getGeneratedSql()).contains("order by o.id desc limit 100");
|
||||
if (isSqlServer()) {
|
||||
assertThat(sqlOf(query)).contains("select top 100 ");
|
||||
assertThat(sqlOf(query)).contains("order by o.id desc");
|
||||
} else {
|
||||
assertThat(sqlOf(query)).contains("order by o.id desc limit 100");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -12,8 +12,6 @@ public class TestSaveSamePK extends BaseTestCase {
|
||||
@Test
|
||||
public void test() {
|
||||
|
||||
if (isSqlServer()) return;
|
||||
|
||||
// delete in case we are running multiple times without full db drop
|
||||
Ebean.delete(TSMaster.class, 10000);
|
||||
|
||||
|
||||
@@ -44,8 +44,10 @@ public class TestCommitAndContinue extends BaseTestCase {
|
||||
try (Transaction anotherTxn = server.createTransaction()) {
|
||||
// success prior to commitAndContinue
|
||||
assertNotNull(server.find(MnyB.class, a.getId(), anotherTxn));
|
||||
// insert failed after commitAndContinue
|
||||
assertNull(server.find(MnyB.class, b.getId(), anotherTxn));
|
||||
if (!isSqlServer()) {
|
||||
// insert failed after commitAndContinue - sqlserver dead locks here
|
||||
assertNull(server.find(MnyB.class, b.getId(), anotherTxn));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -81,7 +83,9 @@ public class TestCommitAndContinue extends BaseTestCase {
|
||||
// success prior to commitAndContinue
|
||||
assertNotNull(server.find(MnyB.class, a.getId(), anotherTxn));
|
||||
// insert failed after commitAndContinue
|
||||
assertNull(server.find(MnyB.class, b.getId(), anotherTxn));
|
||||
if (!isSqlServer()) { // sqlServer dead locks here...
|
||||
assertNull(server.find(MnyB.class, b.getId(), anotherTxn));
|
||||
}
|
||||
//anotherTxn.end();
|
||||
}
|
||||
}
|
||||
@@ -136,9 +140,10 @@ public class TestCommitAndContinue extends BaseTestCase {
|
||||
// success prior to commitAndContinue
|
||||
assertNotNull(server.find(MnyB.class, a.getId(), txnForAssert));
|
||||
|
||||
// insert failed after commitAndContinue
|
||||
assertNull(server.find(MnyB.class, b.getId(), txnForAssert));
|
||||
|
||||
if (!isSqlServer()) {
|
||||
// insert failed after commitAndContinue
|
||||
assertNull(server.find(MnyB.class, b.getId(), txnForAssert));
|
||||
}
|
||||
// successful insert using txn2
|
||||
assertNotNull(server.find(MnyB.class, c.getId(), txnForAssert));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user