mirror of
https://github.com/ebean-orm/ebean.git
synced 2026-10-24 03:57:45 +00:00
#803 - Fix generics on findMap() to ... <K> Map<K, T> findMap();
This commit is contained in:
@@ -986,7 +986,7 @@ public interface EbeanServer {
|
||||
* @return the map of fetched beans.
|
||||
* @see Query#findMap()
|
||||
*/
|
||||
<T> Map<?, T> findMap(Query<T> query, Transaction transaction);
|
||||
<K, T> Map<K, T> findMap(Query<T> query, Transaction transaction);
|
||||
|
||||
/**
|
||||
* Execute the query returning a list of values for a single property.
|
||||
|
||||
@@ -203,7 +203,7 @@ public interface ExpressionList<T> {
|
||||
*
|
||||
* @see Query#findMap()
|
||||
*/
|
||||
Map<?, T> findMap();
|
||||
<K> Map<K, T> findMap();
|
||||
|
||||
/**
|
||||
* Return a typed map specifying the key property and type.
|
||||
|
||||
@@ -660,7 +660,7 @@ public abstract class Model {
|
||||
* <p>
|
||||
* Equivalent to {@link Query#findMap()}
|
||||
*/
|
||||
public Map<?, T> findMap() {
|
||||
public <K> Map<K, T> findMap() {
|
||||
return query().findMap();
|
||||
}
|
||||
|
||||
|
||||
@@ -661,7 +661,7 @@ public interface Query<T> {
|
||||
* </p>
|
||||
* <pre>{@code
|
||||
*
|
||||
* Map<?, Product> map =
|
||||
* Map<String, Product> map =
|
||||
* ebeanServer.find(Product.class)
|
||||
* .setMapKey("sku")
|
||||
* .findMap();
|
||||
@@ -670,7 +670,7 @@ public interface Query<T> {
|
||||
*
|
||||
* @see EbeanServer#findMap(Query, Transaction)
|
||||
*/
|
||||
Map<?, T> findMap();
|
||||
<K> Map<K, T> findMap();
|
||||
|
||||
/**
|
||||
* Return a typed map specifying the key property and type.
|
||||
|
||||
@@ -1134,18 +1134,18 @@ public final class DefaultServer implements SpiServer, SpiEbeanServer {
|
||||
}
|
||||
|
||||
@SuppressWarnings({ "unchecked", "rawtypes" })
|
||||
public <T> Map<?, T> findMap(Query<T> query, Transaction t) {
|
||||
public <K, T> Map<K, T> findMap(Query<T> query, Transaction t) {
|
||||
|
||||
SpiOrmQueryRequest request = createQueryRequest(Type.MAP, query, t);
|
||||
|
||||
Object result = request.getFromQueryCache();
|
||||
if (result != null) {
|
||||
return (Map<?, T>) result;
|
||||
return (Map<K, T>) result;
|
||||
}
|
||||
|
||||
try {
|
||||
request.initTransIfRequired();
|
||||
return (Map<?, T>) request.findMap();
|
||||
return (Map<K, T>) request.findMap();
|
||||
|
||||
} finally {
|
||||
request.endTransIfRequired();
|
||||
@@ -1153,6 +1153,7 @@ public final class DefaultServer implements SpiServer, SpiEbeanServer {
|
||||
}
|
||||
|
||||
@Override
|
||||
@SuppressWarnings("unchecked")
|
||||
public <A> List<A> findSingleAttributeList(Query<?> query, Transaction t) {
|
||||
|
||||
SpiOrmQueryRequest request = createQueryRequest(Type.ATTRIBUTE, query, t);
|
||||
|
||||
@@ -379,7 +379,7 @@ public class DefaultExpressionList<T> implements SpiExpressionList<T> {
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<?, T> findMap() {
|
||||
public <K> Map<K, T> findMap() {
|
||||
return query.findMap();
|
||||
}
|
||||
|
||||
|
||||
@@ -64,7 +64,7 @@ public class FilterExpressionList<T> extends DefaultExpressionList<T> {
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<?, T> findMap() {
|
||||
public <K> Map<K, T> findMap() {
|
||||
return rootQuery.findMap();
|
||||
}
|
||||
|
||||
|
||||
@@ -391,7 +391,7 @@ class JunctionExpression<T> implements SpiJunction<T>, SpiExpression, Expression
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<?, T> findMap() {
|
||||
public <K> Map<K, T> findMap() {
|
||||
return exprList.findMap();
|
||||
}
|
||||
|
||||
|
||||
@@ -1142,7 +1142,7 @@ public class DefaultOrmQuery<T> implements SpiQuery<T> {
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<?, T> findMap() {
|
||||
public <K> Map<K, T> findMap() {
|
||||
return server.findMap(this, null);
|
||||
}
|
||||
|
||||
|
||||
@@ -516,7 +516,7 @@ public class TDSpiEbeanServer implements SpiEbeanServer {
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T> Map<?, T> findMap(Query<T> query, Transaction transaction) {
|
||||
public <K, T> Map<K, T> findMap(Query<T> query, Transaction transaction) {
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -1,14 +1,16 @@
|
||||
package com.avaje.tests.query;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
||||
import com.avaje.ebean.BaseTestCase;
|
||||
import com.avaje.ebean.Ebean;
|
||||
import com.avaje.tests.model.basic.Customer;
|
||||
import com.avaje.tests.model.basic.Product;
|
||||
import com.avaje.tests.model.basic.ResetBasicData;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
|
||||
public class TestQueryFindMapTypedKey extends BaseTestCase {
|
||||
|
||||
@@ -17,9 +19,21 @@ public class TestQueryFindMapTypedKey extends BaseTestCase {
|
||||
|
||||
ResetBasicData.reset();
|
||||
|
||||
Map<String, Customer> map = Ebean.find(Customer.class).select("id, name")
|
||||
.findMap("name", String.class);
|
||||
Map<String, Product> productsBySku = Ebean.find(Product.class)
|
||||
.setMapKey("sku")
|
||||
.findMap();
|
||||
|
||||
assertThat(productsBySku).isNotEmpty();
|
||||
|
||||
Product desk = productsBySku.get("DSK1");
|
||||
assertNotNull(desk);
|
||||
|
||||
Map<String, Customer> map = Ebean.find(Customer.class)
|
||||
.select("id, name")
|
||||
.setMapKey("name")
|
||||
.findMap();
|
||||
|
||||
assertNotNull(map);
|
||||
|
||||
Assert.assertNotNull(map);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -257,7 +257,7 @@ public class TestReadAudit extends BaseTestCase {
|
||||
|
||||
resetCounters();
|
||||
|
||||
Map<?,EBasicChangeLog> list = server.find(EBasicChangeLog.class)
|
||||
Map<Long,EBasicChangeLog> list = server.find(EBasicChangeLog.class)
|
||||
.where().startsWith("shortDescription", "readAudit")
|
||||
.findMap();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user