mirror of
https://github.com/ebean-orm/ebean.git
synced 2024-04-21 10:51:47 +00:00
Merge pull request #1948 from ebean-orm/feature/queryUsingDatabase
ENH: Add query.usingDatabase(database)
This commit is contained in:
+27
@@ -103,6 +103,33 @@ public class DefaultTransactionThreadLocalTest extends BaseTestCase {
|
||||
}
|
||||
}
|
||||
|
||||
@ForPlatform(Platform.H2)
|
||||
@Test
|
||||
public void usingDatabase() {
|
||||
|
||||
// setup
|
||||
Database otherDb = createOtherDatabase();
|
||||
EBasicVer bean = new EBasicVer("TestUsingDatabase");
|
||||
otherDb.save(bean);
|
||||
|
||||
// act
|
||||
final EBasicVer foundOtherDb = DB.find(EBasicVer.class)
|
||||
.usingDatabase(otherDb)
|
||||
.where().eq("name", "TestUsingDatabase")
|
||||
.findOne();
|
||||
|
||||
assertNotNull(foundOtherDb);
|
||||
assertThat(foundOtherDb.getId()).isEqualTo(bean.getId());
|
||||
|
||||
final EBasicVer foundDefaultDb = DB.find(EBasicVer.class)
|
||||
.where().eq("name", "TestUsingDatabase")
|
||||
.findOne();
|
||||
|
||||
assertNull(foundDefaultDb);
|
||||
|
||||
otherDb.delete(bean);
|
||||
}
|
||||
|
||||
|
||||
private Database createOtherDatabase() {
|
||||
|
||||
|
||||
@@ -2,6 +2,7 @@ package org.tests.basic;
|
||||
|
||||
import io.ebean.BaseTestCase;
|
||||
import io.ebean.DB;
|
||||
import io.ebean.Database;
|
||||
import io.ebean.Transaction;
|
||||
import io.ebean.annotation.IgnorePlatform;
|
||||
import io.ebean.annotation.Platform;
|
||||
@@ -18,6 +19,21 @@ import static org.junit.Assert.assertEquals;
|
||||
|
||||
public class TestQueryUsingConnection extends BaseTestCase {
|
||||
|
||||
@Test
|
||||
public void usingDatabase() {
|
||||
|
||||
ResetBasicData.reset();
|
||||
|
||||
final Database database = DB.getDefault();
|
||||
|
||||
int count =
|
||||
DB.find(Country.class)
|
||||
.usingDatabase(database)
|
||||
.findCount();
|
||||
|
||||
assertThat(count).isGreaterThan(0);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void usingConnection() throws SQLException {
|
||||
|
||||
|
||||
Reference in New Issue
Block a user