mirror of
https://github.com/ebean-orm/ebean.git
synced 2026-11-17 22:56:28 +00:00
#1351 - ENH: Add named DtoQuery
Merge branch 'feature/namedDtoQuery' of https://github.com/hexagonframework/ebean into hexagonframework-feature/namedDtoQuery
This commit is contained in:
1 parent
8601f51a6c
commit
74e0a16531
14 files changed
+139
-216
No files matched your search
@@ -1,9 +1,7 @@
|
||||
package io.ebeaninternal.server.dto;
|
||||
|
||||
import io.ebean.meta.MetricVisitor;
|
||||
import io.ebeaninternal.server.rawsql.SpiRawSql;
|
||||
import java.util.HashMap;
|
||||
import java.util.LinkedHashMap;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
|
||||
@@ -12,25 +10,18 @@ import java.util.concurrent.ConcurrentHashMap;
|
||||
*/
|
||||
public class DtoBeanDescriptor<T> {
|
||||
|
||||
private static final Map<String, String> EMPTY_NAMED_QUERY = new HashMap<>();
|
||||
|
||||
private static final Map<String, SpiRawSql> EMPTY_RAW_MAP = new HashMap<>();
|
||||
|
||||
private final Map<Object, DtoQueryPlan> plans = new ConcurrentHashMap<>();
|
||||
|
||||
private final Class<T> dtoType;
|
||||
|
||||
private final DtoMeta meta;
|
||||
|
||||
private Map<String, SpiRawSql> namedRawSql;
|
||||
private final Map<String, String> namedQueries;
|
||||
|
||||
private Map<String, String> namedQuery;
|
||||
|
||||
DtoBeanDescriptor(Class<T> dtoType, DtoMeta meta) {
|
||||
DtoBeanDescriptor(Class<T> dtoType, DtoMeta meta, Map<String, String> namedQueries) {
|
||||
this.dtoType = dtoType;
|
||||
this.meta = meta;
|
||||
this.namedQuery = getNamedQuery();
|
||||
this.namedRawSql = getNamedRawSql();
|
||||
this.namedQueries = namedQueries;
|
||||
}
|
||||
|
||||
public Class<T> getType() {
|
||||
@@ -55,51 +46,11 @@ public class DtoBeanDescriptor<T> {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the named ORM query.
|
||||
*/
|
||||
public String getNamedQuery(String name) {
|
||||
return namedQuery.get(name);
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the named RawSql query.
|
||||
*/
|
||||
public SpiRawSql getNamedRawSql(String named) {
|
||||
return namedRawSql.get(named);
|
||||
public String getNamedRawSql(String name) {
|
||||
return namedQueries.get(name);
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the named ORM queries.
|
||||
*/
|
||||
public Map<String, String> getNamedQuery() {
|
||||
return (namedQuery != null) ? namedQuery : EMPTY_NAMED_QUERY;
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a named query.
|
||||
*/
|
||||
public void addNamedQuery(String name, String query) {
|
||||
if (namedQuery == null) {
|
||||
namedQuery = new LinkedHashMap<>();
|
||||
}
|
||||
namedQuery.put(name, query);
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the named RawSql queries.
|
||||
*/
|
||||
public Map<String, SpiRawSql> getNamedRawSql() {
|
||||
return (namedRawSql != null) ? namedRawSql : EMPTY_RAW_MAP;
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a named RawSql from ebean.xml file.
|
||||
*/
|
||||
public void addRawSql(String name, SpiRawSql rawSql) {
|
||||
if (namedRawSql == null) {
|
||||
namedRawSql = new HashMap<>();
|
||||
}
|
||||
namedRawSql.put(name, rawSql);
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user