mirror of
https://github.com/ebean-orm/ebean.git
synced 2026-11-13 06:42:57 +00:00
#1460 - ENH: Add FetchGroup ... as a mechanism to specify select() + fetch() separately from Query
Change to add generics for FetchGroup
This commit is contained in:
1 parent
ec7e4e4935
commit
6d0556a120
11 files changed
+81
-63
No files matched your search
@@ -6,7 +6,7 @@ import io.ebeaninternal.server.querydefn.SpiFetchGroup;
|
||||
/**
|
||||
* Default FetchGroup implementation.
|
||||
*/
|
||||
class DFetchGroup implements SpiFetchGroup {
|
||||
class DFetchGroup<T> implements SpiFetchGroup<T> {
|
||||
|
||||
private final OrmQueryDetail detail;
|
||||
|
||||
|
||||
@@ -9,39 +9,46 @@ import io.ebeaninternal.server.querydefn.SpiFetchGroup;
|
||||
/**
|
||||
* Default implementation of the FetchGroupBuilder.
|
||||
*/
|
||||
class DFetchGroupBuilder implements FetchGroupBuilder {
|
||||
class DFetchGroupBuilder<T> implements FetchGroupBuilder<T> {
|
||||
|
||||
private static final FetchConfig FETCH_QUERY = new FetchConfig().query();
|
||||
|
||||
private static final FetchConfig FETCH_LAZY = new FetchConfig().lazy();
|
||||
|
||||
private OrmQueryDetail detail;
|
||||
private final OrmQueryDetail detail;
|
||||
|
||||
DFetchGroupBuilder(OrmQueryDetail detail) {
|
||||
this.detail = detail;
|
||||
DFetchGroupBuilder() {
|
||||
this.detail = new OrmQueryDetail();
|
||||
}
|
||||
|
||||
@Override
|
||||
public FetchGroupBuilder fetch(String path) {
|
||||
public FetchGroupBuilder<T> select(String select) {
|
||||
detail.select(select);
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public FetchGroupBuilder<T> fetch(String path) {
|
||||
detail.fetch(path, null, null);
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public FetchGroupBuilder fetch(String path, FetchGroup nestedGroup) {
|
||||
public FetchGroupBuilder<T> fetch(String path, FetchGroup nestedGroup) {
|
||||
return fetchNested(path, nestedGroup, null);
|
||||
}
|
||||
|
||||
@Override
|
||||
public FetchGroupBuilder fetchQuery(String path, FetchGroup nestedGroup) {
|
||||
public FetchGroupBuilder<T> fetchQuery(String path, FetchGroup nestedGroup) {
|
||||
return fetchNested(path, nestedGroup, FETCH_QUERY);
|
||||
}
|
||||
|
||||
@Override
|
||||
public FetchGroupBuilder fetchLazy(String path, FetchGroup nestedGroup) {
|
||||
public FetchGroupBuilder<T> fetchLazy(String path, FetchGroup nestedGroup) {
|
||||
return fetchNested(path, nestedGroup, FETCH_LAZY);
|
||||
}
|
||||
|
||||
private FetchGroupBuilder fetchNested(String path, FetchGroup nestedGroup, FetchConfig fetchConfig) {
|
||||
private FetchGroupBuilder<T> fetchNested(String path, FetchGroup nestedGroup, FetchConfig fetchConfig) {
|
||||
|
||||
OrmQueryDetail nestedDetail = ((SpiFetchGroup) nestedGroup).underlying();
|
||||
detail.addNested(path, nestedDetail, fetchConfig);
|
||||
@@ -49,37 +56,37 @@ class DFetchGroupBuilder implements FetchGroupBuilder {
|
||||
}
|
||||
|
||||
@Override
|
||||
public FetchGroupBuilder fetchQuery(String path) {
|
||||
public FetchGroupBuilder<T> fetchQuery(String path) {
|
||||
detail.fetch(path, null, FETCH_QUERY);
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public FetchGroupBuilder fetchLazy(String path) {
|
||||
public FetchGroupBuilder<T> fetchLazy(String path) {
|
||||
detail.fetch(path, null, FETCH_LAZY);
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public FetchGroupBuilder fetch(String path, String properties) {
|
||||
public FetchGroupBuilder<T> fetch(String path, String properties) {
|
||||
detail.fetch(path, properties, null);
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public FetchGroupBuilder fetchQuery(String path, String properties) {
|
||||
public FetchGroupBuilder<T> fetchQuery(String path, String properties) {
|
||||
detail.fetch(path, properties, FETCH_QUERY);
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public FetchGroupBuilder fetchLazy(String path, String properties) {
|
||||
public FetchGroupBuilder<T> fetchLazy(String path, String properties) {
|
||||
detail.fetch(path, properties, FETCH_LAZY);
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public FetchGroup build() {
|
||||
return new DFetchGroup(detail);
|
||||
public FetchGroup<T> build() {
|
||||
return new DFetchGroup<>(detail);
|
||||
}
|
||||
}
|
||||
@@ -11,13 +11,13 @@ import io.ebeaninternal.server.querydefn.OrmQueryDetail;
|
||||
public final class DFetchGroupService implements SpiFetchGroupService {
|
||||
|
||||
@Override
|
||||
public FetchGroup of(String select) {
|
||||
return new DFetchGroup(detail(select));
|
||||
public <T> FetchGroup<T> of(Class<T> cls, String select) {
|
||||
return new DFetchGroup<>(detail(select));
|
||||
}
|
||||
|
||||
@Override
|
||||
public FetchGroupBuilder select(String select) {
|
||||
return new DFetchGroupBuilder(detail(select));
|
||||
public <T> FetchGroupBuilder<T> of(Class<T> cls) {
|
||||
return new DFetchGroupBuilder<>();
|
||||
}
|
||||
|
||||
private OrmQueryDetail detail(String select) {
|
||||
|
||||
@@ -5,7 +5,7 @@ import io.ebean.FetchGroup;
|
||||
/**
|
||||
* Service API of FetchGroup.
|
||||
*/
|
||||
public interface SpiFetchGroup extends FetchGroup {
|
||||
public interface SpiFetchGroup<T> extends FetchGroup<T> {
|
||||
|
||||
/**
|
||||
* Return the detail to use for query execution.
|
||||
|
||||
Reference in new issue
Block a user