mirror of
https://github.com/ebean-orm/ebean.git
synced 2026-10-23 21:15:52 +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
@@ -21,6 +21,13 @@
|
||||
</scm>
|
||||
|
||||
<dependencies>
|
||||
<!-- MS SQL Server dependency is now publicly available -->
|
||||
<dependency>
|
||||
<groupId>com.microsoft.sqlserver</groupId>
|
||||
<artifactId>mssql-jdbc</artifactId>
|
||||
<version>6.1.3.jre8-preview</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.jetbrains</groupId>
|
||||
|
||||
@@ -54,6 +54,8 @@ public class BaseTableDdl implements TableDdl {
|
||||
* Used when unique constraints specifically for OneToOne can't be created normally (MsSqlServer).
|
||||
*/
|
||||
protected List<Column> externalUnique = new ArrayList<>();
|
||||
|
||||
protected List<UniqueConstraint> externalCompoundUnique = new ArrayList<>();
|
||||
|
||||
// counters used when constraint names are truncated due to maximum length
|
||||
// and these counters are used to keep the constraint name unique
|
||||
@@ -85,6 +87,7 @@ public class BaseTableDdl implements TableDdl {
|
||||
protected void reset() {
|
||||
indexSet.clear();
|
||||
externalUnique.clear();
|
||||
externalCompoundUnique.clear();
|
||||
countCheck = 0;
|
||||
countUnique = 0;
|
||||
countForeignKey = 0;
|
||||
@@ -213,6 +216,18 @@ public class BaseTableDdl implements TableDdl {
|
||||
.append(platformDdl.dropIndex(uqName, tableName))
|
||||
.endOfStatement();
|
||||
}
|
||||
|
||||
for (UniqueConstraint constraint : externalCompoundUnique) {
|
||||
String uqName = constraint.getName();
|
||||
String[] columnNames = StringHelper.delimitedToArray(constraint.getColumnNames(), ",", false);
|
||||
write.apply()
|
||||
.append(platformDdl.alterTableAddUniqueConstraint(tableName, uqName, columnNames))
|
||||
.endOfStatement();
|
||||
|
||||
write.dropAllForeignKeys()
|
||||
.append(platformDdl.dropIndex(uqName, tableName))
|
||||
.endOfStatement();
|
||||
}
|
||||
}
|
||||
|
||||
protected void writeSequence(DdlWrite writer, CreateTable createTable, String pk) throws IOException {
|
||||
@@ -406,12 +421,17 @@ public class BaseTableDdl implements TableDdl {
|
||||
protected void writeCompoundUniqueConstraints(DdlBuffer apply, CreateTable createTable) throws IOException {
|
||||
|
||||
List<UniqueConstraint> uniqueConstraints = createTable.getUniqueConstraint();
|
||||
boolean inlineUniqueCompound = platformDdl.isInlineUniqueOneToOne();
|
||||
for (UniqueConstraint uniqueConstraint : uniqueConstraints) {
|
||||
String uqName = uniqueConstraint.getName();
|
||||
String[] columns = toColumnNamesSplit(uniqueConstraint.getColumnNames());
|
||||
apply.append(",").newLine();
|
||||
apply.append(" constraint ").append(uqName).append(" unique");
|
||||
appendColumns(columns, apply);
|
||||
if (inlineUniqueCompound) {
|
||||
String uqName = uniqueConstraint.getName();
|
||||
String[] columns = toColumnNamesSplit(uniqueConstraint.getColumnNames());
|
||||
apply.append(",").newLine();
|
||||
apply.append(" constraint ").append(uqName).append(" unique");
|
||||
appendColumns(columns, apply);
|
||||
} else {
|
||||
externalCompoundUnique.add(uniqueConstraint);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -832,22 +852,11 @@ public class BaseTableDdl implements TableDdl {
|
||||
}
|
||||
|
||||
protected void alterTableAddColumn(DdlBuffer buffer, String tableName, Column column, boolean onHistoryTable) throws IOException {
|
||||
|
||||
String convertedType = platformDdl.convert(column.getType(), false);
|
||||
buffer.append("alter table ").append(tableName)
|
||||
.append(" add column ").append(column.getName())
|
||||
.append(" ").append(convertedType);
|
||||
|
||||
if (!onHistoryTable) {
|
||||
if (isTrue(column.isNotnull())) {
|
||||
buffer.append(" not null");
|
||||
}
|
||||
if (hasValue(column.getCheckConstraint())) {
|
||||
buffer.append(" constraint ").append(column.getCheckConstraintName());
|
||||
buffer.append(" ").append(column.getCheckConstraint());
|
||||
}
|
||||
String ddl = platformDdl.alterTableAddColumn(tableName, column, onHistoryTable);
|
||||
if (hasValue(ddl)) {
|
||||
buffer.append(ddl);
|
||||
buffer.endOfStatement();
|
||||
}
|
||||
buffer.endOfStatement();
|
||||
}
|
||||
|
||||
protected boolean isFalse(Boolean value) {
|
||||
|
||||
@@ -17,6 +17,7 @@ import io.ebean.dbmigration.migration.Column;
|
||||
import io.ebean.dbmigration.migration.DropHistoryTable;
|
||||
import io.ebean.dbmigration.migration.IdentityType;
|
||||
import io.ebean.dbmigration.model.MTable;
|
||||
import io.ebean.util.StringHelper;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.List;
|
||||
@@ -74,6 +75,8 @@ public class PlatformDdl {
|
||||
protected String dropUniqueConstraint = "drop constraint";
|
||||
|
||||
protected String addConstraint = "add constraint";
|
||||
|
||||
protected String addColumn = "add column";
|
||||
|
||||
protected String columnSetType = "";
|
||||
|
||||
@@ -375,6 +378,27 @@ public class PlatformDdl {
|
||||
appendColumns(columns, buffer);
|
||||
return buffer.toString();
|
||||
}
|
||||
|
||||
public String alterTableAddColumn(String tableName, Column column, boolean onHistoryTable) throws IOException {
|
||||
|
||||
String convertedType = convert(column.getType(), false);
|
||||
|
||||
StringBuilder buffer = new StringBuilder(90);
|
||||
buffer.append("alter table ").append(tableName)
|
||||
.append(' ').append(addColumn).append(' ').append(column.getName())
|
||||
.append(' ').append(convertedType);
|
||||
|
||||
if (!onHistoryTable) {
|
||||
if (isTrue(column.isNotnull())) {
|
||||
buffer.append(" not null");
|
||||
}
|
||||
if (!StringHelper.isNull(column.getCheckConstraint())) {
|
||||
buffer.append(" constraint ").append(column.getCheckConstraintName());
|
||||
buffer.append(" ").append(column.getCheckConstraint());
|
||||
}
|
||||
}
|
||||
return buffer.toString();
|
||||
}
|
||||
|
||||
/**
|
||||
* Return true if unique constraints for OneToOne can be inlined as normal.
|
||||
|
||||
@@ -15,6 +15,8 @@ public class SqlServerDdl extends PlatformDdl {
|
||||
super(platform);
|
||||
this.identitySuffix = " identity(1,1)";
|
||||
this.foreignKeyRestrict = "";
|
||||
this.alterTableIfExists = "";
|
||||
this.addColumn = "add";
|
||||
this.inlineUniqueOneToOne = false;
|
||||
this.columnSetDefault = "add default";
|
||||
this.dropConstraintIfExists = "drop constraint";
|
||||
@@ -28,9 +30,23 @@ public class SqlServerDdl extends PlatformDdl {
|
||||
|
||||
@Override
|
||||
public String alterTableDropForeignKey(String tableName, String fkName) {
|
||||
return "IF OBJECT_ID('" + fkName + "', 'F') IS NOT NULL " + super.alterTableDropForeignKey(tableName, fkName);
|
||||
int pos = tableName.lastIndexOf('.');
|
||||
String objectId = fkName;
|
||||
if (pos != -1) {
|
||||
objectId = tableName.substring(0, pos + 1) + fkName;
|
||||
}
|
||||
return "IF OBJECT_ID('" + objectId + "', 'F') IS NOT NULL " + super.alterTableDropForeignKey(tableName, fkName);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String dropSequence(String sequenceName) {
|
||||
return "IF OBJECT_ID('" + sequenceName + "', 'SO') IS NOT NULL drop sequence " + sequenceName;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String dropIndex(String indexName, String tableName) {
|
||||
return "IF EXISTS (SELECT name FROM sys.indexes WHERE object_id = OBJECT_ID('" + tableName +"','U') AND name = '" + indexName + "') drop index " + indexName + " ON " + tableName;
|
||||
}
|
||||
/**
|
||||
* MsSqlServer specific null handling on unique constraints.
|
||||
*/
|
||||
@@ -48,12 +64,37 @@ public class SqlServerDdl extends PlatformDdl {
|
||||
sb.append(columns[i]);
|
||||
}
|
||||
sb.append(") where");
|
||||
String sep = " ";
|
||||
for (String column : columns) {
|
||||
sb.append(" ").append(column).append(" is not null");
|
||||
sb.append(sep).append(column).append(" is not null");
|
||||
sep = " and ";
|
||||
}
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
/**
|
||||
* Generate and return the create sequence DDL.
|
||||
*/
|
||||
@Override
|
||||
public String createSequence(String sequenceName, int initialValue, int allocationSize) {
|
||||
|
||||
StringBuilder sb = new StringBuilder("create sequence ");
|
||||
sb.append(sequenceName);
|
||||
sb.append(" as bigint ");
|
||||
if (initialValue > 1) {
|
||||
sb.append(" start with ").append(initialValue);
|
||||
} else {
|
||||
sb.append(" start with 1 ");
|
||||
}
|
||||
if (allocationSize > 0 && allocationSize != 50) {
|
||||
// at this stage ignoring allocationSize 50 as this is the 'default' and
|
||||
// not consistent with the way Ebean batch fetches sequence values
|
||||
sb.append(" increment by ").append(allocationSize);
|
||||
}
|
||||
sb.append(";");
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String alterColumnDefaultValue(String tableName, String columnName, String defaultValue) {
|
||||
|
||||
@@ -74,7 +115,7 @@ public class SqlServerDdl extends PlatformDdl {
|
||||
boolean notnull = (alter.isNotnull() != null) ? alter.isNotnull() : Boolean.TRUE.equals(alter.isCurrentNotnull());
|
||||
String notnullClause = notnull ? " not null" : "";
|
||||
|
||||
return "alter table " + tableName + " alter column " + columnName + " " + type + notnullClause;
|
||||
return "alter table " + tableName + " " + alterColumn + " " + columnName + " " + type + notnullClause;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -34,16 +34,25 @@ public class SqlServerHistoryDdl implements PlatformHistoryDdl {
|
||||
apply.append("alter table ").append(baseTable).newLine()
|
||||
.append(" add ").append(systemPeriodStart).append(" datetime2 GENERATED ALWAYS AS ROW START NOT NULL DEFAULT SYSUTCDATETIME(),").newLine()
|
||||
.append(" ").append(systemPeriodEnd).append(" datetime2 GENERATED ALWAYS AS ROW END NOT NULL,").newLine()
|
||||
.append("period for system_time (").append(systemPeriodStart).append("From, ").append(systemPeriodEnd).append("To)").endOfStatement();
|
||||
.append("period for system_time (").append(systemPeriodStart).append(", ").append(systemPeriodEnd).append(")").endOfStatement();
|
||||
|
||||
apply.append("alter table ").append(baseTable).append("set (system_versioning = on)").endOfStatement();
|
||||
String historyTable = baseTable + "_history"; // history must contain schema, otherwise you'll get
|
||||
// Setting SYSTEM_VERSIONING to ON failed because history table 'xxx_history' is not specified in two-part name format.
|
||||
if (historyTable.indexOf('.') == -1) {
|
||||
historyTable = "dbo." +historyTable; // so add the default schema, if none was specified.
|
||||
}
|
||||
apply.append("alter table ").append(baseTable).append(" set (system_versioning = on (history_table=").append(historyTable).append("))").endOfStatement();
|
||||
|
||||
DdlBuffer drop = writer.dropAll();
|
||||
drop.append("IF OBJECT_ID('").append(baseTable).append("', 'U') IS NOT NULL alter table ").append(baseTable).append(" set (system_versioning = off)").endOfStatement();
|
||||
drop.append("IF OBJECT_ID('").append(baseTable).append("_history', 'U') IS NOT NULL drop table ").append(baseTable).append("_history").endOfStatement();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void dropHistoryTable(DdlWrite writer, DropHistoryTable dropHistoryTable) throws IOException {
|
||||
String baseTable = dropHistoryTable.getBaseTable();
|
||||
DdlBuffer apply = writer.applyHistory();
|
||||
apply.append("alter table ").append(baseTable).append("set (system_versioning = off)").endOfStatement();
|
||||
apply.append("alter table ").append(baseTable).append(" set (system_versioning = off)").endOfStatement();
|
||||
apply.append("alter table ").append(baseTable).append(" drop column ").append(systemPeriodStart).endOfStatement();
|
||||
apply.append("alter table ").append(baseTable).append(" drop column ").append(systemPeriodEnd).endOfStatement();
|
||||
}
|
||||
|
||||
@@ -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));
|
||||
}
|
||||
|
||||
@@ -122,3 +122,8 @@ datasource.pg.databaseDriver=org.postgresql.Driver
|
||||
datasource.pg.capturestacktrace=true
|
||||
datasource.pg.maxStackTraceSize=50
|
||||
|
||||
#TODO we need an sqlserver for travis - maybe from azure cloud
|
||||
datasource.mssql.username=ebean
|
||||
datasource.mssql.password=ebean
|
||||
datasource.mssql.databaseUrl=jdbc:sqlserver://10.75.1.40:1433;databaseName=ebean_unittest;selectMethod=cursor
|
||||
datasource.mssql.databaseDriver=com.microsoft.sqlserver.jdbc.SQLServerDriver
|
||||
|
||||
Reference in New Issue
Block a user