Merge remote-tracking branch 'ebean/master'

This commit is contained in:
Roland Praml
2016-08-16 11:06:47 +02:00
173 changed files with 2492 additions and 1739 deletions
@@ -147,7 +147,7 @@ public class MainDbBoolean {
.setAutoTune(false)
.order("id");
int rc = query.findRowCount();
int rc = query.findCount();
Assert.assertTrue(rc > 0);
@@ -1,17 +1,17 @@
package com.avaje.tests.basic;
import java.util.List;
import java.util.concurrent.ExecutionException;
import org.junit.Assert;
import org.junit.Test;
import com.avaje.ebean.BaseTestCase;
import com.avaje.ebean.Ebean;
import com.avaje.ebean.FutureIds;
import com.avaje.ebean.Query;
import com.avaje.tests.model.basic.Order;
import com.avaje.tests.model.basic.ResetBasicData;
import org.junit.Test;
import java.util.List;
import java.util.concurrent.ExecutionException;
import static org.assertj.core.api.Assertions.assertThat;
public class TestFetchId extends BaseTestCase {
@@ -28,19 +28,12 @@ public class TestFetchId extends BaseTestCase {
.query();
List<Object> ids = Ebean.getServer(null).findIds(query, null);
assertThat(ids).isNotEmpty();
FutureIds<Order> futureIds = Ebean.getServer(null).findFutureIds(query,null);
// this list is likely empty at this point and
// will get populated in the background
List<Object> partial = futureIds.getPartialIds();
// this is likely 0 or a small number
// wait for all the id's to be fetched
List<Object> idList = futureIds.get();
Assert.assertTrue("same instance", partial == idList);
Assert.assertTrue("sz > 0", !ids.isEmpty());
assertThat(idList).isNotEmpty();
}
}
@@ -14,8 +14,7 @@ public class TestIUDVanilla extends BaseTestCase {
@Test
public void test() {
EBasicVer e0 = new EBasicVer();
e0.setName("vanilla");
EBasicVer e0 = new EBasicVer("vanilla");
Ebean.save(e0);
@@ -39,9 +38,8 @@ public class TestIUDVanilla extends BaseTestCase {
e2.setName("forcedUpdate");
Ebean.update(e2);
EBasicVer e3 = new EBasicVer();
EBasicVer e3 = new EBasicVer("ModNoOCC");
e3.setId(e0.getId());
e3.setName("ModNoOCC");
Ebean.update(e3);
@@ -22,7 +22,7 @@ public class TestLazyLoadInCache extends BaseTestCase {
ResetBasicData.reset();
Map<?, Customer> map = Ebean.find(Customer.class)
Map<Integer, Customer> map = Ebean.find(Customer.class)
.select("id, name")
.setLoadBeanCache(true)
.setReadOnly(true)
@@ -17,7 +17,7 @@ public class TestLoadBeanCache extends BaseTestCase {
ResetBasicData.reset();
Map<?, Country> map = Ebean.find(Country.class)
Map<String, Country> map = Ebean.find(Country.class)
.setLoadBeanCache(true)
.setUseQueryCache(true)
.setReadOnly(true)
@@ -25,9 +25,8 @@ public class TestLogTransLogOnError extends BaseTestCase {
Ebean.find(Customer.class).findList();
Ebean.find(Order.class).where().gt("id", 1).findList();
EBasicVer newBean = new EBasicVer();
EBasicVer newBean = new EBasicVer("aName");
newBean.setDescription("something");
newBean.setName("aName");
// Ebean.save(newBean);
@@ -55,13 +54,12 @@ public class TestLogTransLogOnError extends BaseTestCase {
try {
Ebean.find(Customer.class).findList();
EBasicVer newBean = new EBasicVer();
EBasicVer newBean = new EBasicVer("aName");
newBean
.setDescription("something sdfjksdjflsjdflsjdflksjdfkjd fsjdfkjsdkfjsdkfjskdjfskjdf"
+ " sjdf sdjflksjdfkjsdlfkjsdkfjs ksjdfksjdlfjsldf something sdfjksdjflsjdflsjdflksjdfkjd"
+ "fsjdfkjsdkfjsdkfjskdjfskjdf sjdf sdjflksjdfkjsdlfkjsdkfjs ksjdfksjdlfjsldf something s"
+ "dfjksdjflsjdflsjdflksjdfkjd fsjdfkjsdkfjsdkfjskdjfskjdf sjdf sdjflksjdfkjsdlfkjsdkfjs ");
newBean.setName("aName");
// t.log("--- next insert should error");
Ebean.save(newBean);
@@ -1,43 +0,0 @@
package com.avaje.tests.basic.event;
import com.avaje.ebean.Transaction;
import com.avaje.ebean.event.TransactionEventListener;
public class MyTestTransactionEventListener implements TransactionEventListener {
private volatile static boolean doTest = false;
private static Transaction lastCommitted;
private static Transaction lastRollbacked;
public void postTransactionCommit(Transaction tx) {
if (!doTest) {
return;
}
lastCommitted = tx;
}
public void postTransactionRollback(Transaction tx, Throwable cause) {
if (!doTest) {
return;
}
lastRollbacked = tx;
}
public static void setDoTest(boolean doTest) {
MyTestTransactionEventListener.doTest = doTest;
// reset what we've recorded so far
lastCommitted = null;
lastRollbacked = null;
}
public static Transaction getLastCommitted() {
return lastCommitted;
}
public static Transaction getLastRollbacked() {
return lastRollbacked;
}
}
@@ -1,62 +0,0 @@
package com.avaje.tests.basic.event;
import junit.framework.TestCase;
import com.avaje.ebean.Ebean;
import com.avaje.ebean.Transaction;
import com.avaje.tests.model.basic.TWithPreInsert;
public class TestTransactionEvent extends TestCase {
@Override
protected void tearDown() throws Exception {
MyTestTransactionEventListener.setDoTest(false);
}
@Override
protected void setUp() throws Exception {
MyTestTransactionEventListener.setDoTest(true);
}
public void test() {
assertNull(MyTestTransactionEventListener.getLastCommitted());
assertNull(MyTestTransactionEventListener.getLastRollbacked());
final Object myUserObject = new Object();
Transaction tx = Ebean.beginTransaction();
tx.putUserObject("myUserObject", myUserObject);
TWithPreInsert e = new TWithPreInsert();
e.setTitle("Mister Transaction1");
Ebean.save(e);
tx.commit();
assertNotNull(MyTestTransactionEventListener.getLastCommitted());
assertNotNull(MyTestTransactionEventListener.getLastCommitted().getUserObject("myUserObject"));
assertSame(MyTestTransactionEventListener.getLastCommitted().getUserObject("myUserObject"), myUserObject);
assertNull(MyTestTransactionEventListener.getLastRollbacked());
Transaction tx2 = Ebean.beginTransaction();
tx2.putUserObject("myUserObject2", myUserObject);
TWithPreInsert e2 = new TWithPreInsert();
e2.setTitle("Mister Transaction2");
Ebean.save(e2);
tx2.rollback();
assertNotNull(MyTestTransactionEventListener.getLastCommitted());
assertNotNull(MyTestTransactionEventListener.getLastRollbacked());
assertNotSame(MyTestTransactionEventListener.getLastCommitted(), MyTestTransactionEventListener.getLastRollbacked());
assertNotNull(MyTestTransactionEventListener.getLastCommitted().getUserObject("myUserObject"));
assertSame(MyTestTransactionEventListener.getLastCommitted().getUserObject("myUserObject"), myUserObject);
assertNotNull(MyTestTransactionEventListener.getLastRollbacked().getUserObject("myUserObject2"));
assertSame(MyTestTransactionEventListener.getLastRollbacked().getUserObject("myUserObject2"), myUserObject);
}
}