#2351 - Rename Database.getReference() to reference() with deprecation

This commit is contained in:
rbygrave committed 2021-09-03 10:50:29 +12:00
1 parent 57c0bceb63
commit 7c2a77081b
6 files changed
+19 -15

No files matched your search

+10 -4
View File
@@ -658,24 +658,30 @@ public final class DB {
* @param beanType the type of entity bean * @param beanType the type of entity bean
* @param id the id value * @param id the id value
*/ */
public static <T> T getReference(Class<T> beanType, Object id) { public static <T> T reference(Class<T> beanType, Object id) {
return getDefault().reference(beanType, id); return getDefault().reference(beanType, id);
} }
/**
* Deprecated migrate to beanId().
*/
@Deprecated
public static <T> T getReference(Class<T> beanType, Object id) {
return reference(beanType, id);
}
/** /**
* Sort the list using the sortByClause which can contain a comma delimited * Sort the list using the sortByClause which can contain a comma delimited
* list of property names and keywords asc, desc, nullsHigh and nullsLow. * list of property names and keywords asc, desc, nullsHigh and nullsLow.
* <ul> * <ul>
* <li>asc - ascending order (which is the default)</li> * <li>asc - ascending order (which is the default)</li>
* <li>desc - Descending order</li> * <li>desc - Descending order</li>
* <li>nullsHigh - Treat null values as high/large values (which is the * <li>nullsHigh - Treat null values as high/large values (which is the default)</li>
* default)</li>
* <li>nullsLow- Treat null values as low/very small values</li> * <li>nullsLow- Treat null values as low/very small values</li>
* </ul> * </ul>
* <p> * <p>
* If you leave off any keywords the defaults are ascending order and treating * If you leave off any keywords the defaults are ascending order and treating
* nulls as high values. * nulls as high values.
* </p>
* <p> * <p>
* Note that the sorting uses a Comparator and Collections.sort(); and does * Note that the sorting uses a Comparator and Collections.sort(); and does
* not invoke a DB query. * not invoke a DB query.
@@ -71,7 +71,7 @@ public class TestQueryForUpdatePostgresLock extends BaseTestCase {
log.info("insert start"); log.info("insert start");
timePreInsert = System.currentTimeMillis(); timePreInsert = System.currentTimeMillis();
Section section = new Section(); Section section = new Section();
section.setArticle(DB.getReference(Article.class, id)); section.setArticle(DB.reference(Article.class, id));
DB.save(section); DB.save(section);
timePostInsert = System.currentTimeMillis(); timePostInsert = System.currentTimeMillis();
log.info("inserted"); log.info("inserted");
@@ -5,8 +5,6 @@ import static org.assertj.core.api.Assertions.assertThat;
import java.util.List; import java.util.List;
import org.junit.Test; import org.junit.Test;
import org.tests.model.m2m.MnyEdge;
import org.tests.model.m2m.MnyNode;
import io.ebean.BaseTestCase; import io.ebean.BaseTestCase;
import io.ebean.DB; import io.ebean.DB;
@@ -108,8 +106,8 @@ public class TestM2MWithWhere extends BaseTestCase {
sb.append("from = ").append(from).append(" |"); sb.append("from = ").append(from).append(" |");
for (int to = 1; to <= 5; to++) { for (int to = 1; to <= 5; to++) {
MnyEdge edge = new MnyEdge(); MnyEdge edge = new MnyEdge();
edge.setFrom(DB.getReference(MnyNode.class, from)); edge.setFrom(DB.reference(MnyNode.class, from));
edge.setTo(DB.getReference(MnyNode.class, to)); edge.setTo(DB.reference(MnyNode.class, to));
int flags = 0; int flags = 0;
if (from < to) { if (from < to) {
flags |= 1; flags |= 1;
@@ -125,7 +123,7 @@ public class TestM2MWithWhere extends BaseTestCase {
} }
// System.out.println(sb); dump the table // System.out.println(sb); dump the table
} }
@Test @Test
public void testWithDbTableName() { public void testWithDbTableName() {
@@ -33,7 +33,7 @@ public class TestOneToManyOnlyBean extends BaseTestCase {
@Test @Test
public void isReference_when_getReference_expectTrue() { public void isReference_when_getReference_expectTrue() {
OMVertex myBean = DB.getReference(OMVertex.class, UUID.randomUUID()); OMVertex myBean = DB.reference(OMVertex.class, UUID.randomUUID());
assertTrue(isReference(myBean)); assertTrue(isReference(myBean));
} }
@@ -85,7 +85,7 @@ public class TestOneToManyJoinTable extends BaseTestCase {
// make m2 dirty ... cascades to an update on Uim // make m2 dirty ... cascades to an update on Uim
m2.setFoodPreference("Apple"); m2.setFoodPreference("Apple");
trainer.getMonkeys().add(m2); trainer.getMonkeys().add(m2);
trainer.getMonkeys().add(DB.getReference(JtMonkey.class, m1.getMid())); trainer.getMonkeys().add(DB.reference(JtMonkey.class, m1.getMid()));
trainer.getMonkeys().add(new JtMonkey("FAlp")); trainer.getMonkeys().add(new JtMonkey("FAlp"));
trainer.getMonkeys().add(new JtMonkey("FBet")); trainer.getMonkeys().add(new JtMonkey("FBet"));
trainer.getMonkeys().add(new JtMonkey("FThe")); trainer.getMonkeys().add(new JtMonkey("FThe"));
@@ -27,7 +27,7 @@ public class TestExecuteComplete extends BaseTestCase {
try { try {
DB.execute(TxScope.required().setBatch(PersistBatch.ALL), () -> { DB.execute(TxScope.required().setBatch(PersistBatch.ALL), () -> {
Customer customer = DB.getReference(Customer.class, 42424242L); Customer customer = DB.reference(Customer.class, 42424242L);
Order order = new Order(); Order order = new Order();
order.setCustomer(customer); order.setCustomer(customer);
@@ -48,7 +48,7 @@ public class TestExecuteComplete extends BaseTestCase {
DB.execute(TxScope.required().setBatch(PersistBatch.ALL), () -> DB.execute(TxScope.required().setBatch(PersistBatch.ALL), () ->
DB.execute(() -> { DB.execute(() -> {
Customer customer = DB.getReference(Customer.class, 42424242L); Customer customer = DB.reference(Customer.class, 42424242L);
Order order = new Order(); Order order = new Order();
order.setCustomer(customer); order.setCustomer(customer);
@@ -75,7 +75,7 @@ public class TestExecuteComplete extends BaseTestCase {
@Transactional(batchSize = 10) @Transactional(batchSize = 10)
private void errorOnCommit() { private void errorOnCommit() {
Customer customer = DB.getReference(Customer.class, 42424242L); Customer customer = DB.reference(Customer.class, 42424242L);
Order order = new Order(); Order order = new Order();
order.setCustomer(customer); order.setCustomer(customer);