mirror of
https://github.com/ebean-orm/ebean.git
synced 2026-11-17 22:56:28 +00:00
#1566 - ENH: Support query.setBaseTable() ... to query against dynamic table (ala manual table partitioning)
This commit is contained in:
1 parent
3207ae1f08
commit
cd8c12a9a8
6 files changed
+97
-7
No files matched your search
@@ -312,7 +312,12 @@ public final class SqlTreeBuilder {
|
||||
// Optional many property for lazy loading query
|
||||
STreePropertyAssocMany lazyLoadMany = (query == null) ? null : query.getLazyLoadMany();
|
||||
boolean withId = !rawNoId && !subQuery && (query == null || query.isWithId());
|
||||
return new SqlTreeNodeRoot(desc, props, myList, withId, includeJoin, lazyLoadMany, temporalMode, disableLazyLoad, sqlDistinct);
|
||||
|
||||
String baseTable = (query == null) ? null : query.getBaseTable();
|
||||
if (baseTable == null) {
|
||||
baseTable = desc.getBaseTable(temporalMode);
|
||||
}
|
||||
return new SqlTreeNodeRoot(desc, props, myList, withId, includeJoin, lazyLoadMany, temporalMode, disableLazyLoad, sqlDistinct, baseTable);
|
||||
|
||||
} else if (prop instanceof STreePropertyAssocMany) {
|
||||
return new SqlTreeNodeManyRoot(prefix, (STreePropertyAssocMany) prop, props, myList, temporalMode, disableLazyLoad);
|
||||
@@ -497,9 +502,9 @@ public final class SqlTreeBuilder {
|
||||
for (STreePropertyAssocOne propertyAssocOne : desc.propsOne()) {
|
||||
//noinspection StatementWithEmptyBody
|
||||
if (queryProps != null
|
||||
&& queryProps.isIncludedBeanJoin(propertyAssocOne.getName())
|
||||
&& propertyAssocOne.hasForeignKey()
|
||||
&& !propertyAssocOne.isFormula()) {
|
||||
&& queryProps.isIncludedBeanJoin(propertyAssocOne.getName())
|
||||
&& propertyAssocOne.hasForeignKey()
|
||||
&& !propertyAssocOne.isFormula()) {
|
||||
// if it is a joined bean with FK constraint... then don't add the property
|
||||
// as it will have its own entire Node in the SqlTree
|
||||
} else {
|
||||
|
||||
@@ -16,15 +16,18 @@ final class SqlTreeNodeRoot extends SqlTreeNodeBean {
|
||||
|
||||
private final boolean sqlDistinct;
|
||||
|
||||
private final String baseTable;
|
||||
|
||||
/**
|
||||
* Specify for SqlSelect to include an Id property or not.
|
||||
*/
|
||||
SqlTreeNodeRoot(STreeType desc, SqlTreeProperties props, List<SqlTreeNode> myList, boolean withId,
|
||||
TableJoin includeJoin, STreePropertyAssocMany many, SpiQuery.TemporalMode temporalMode, boolean disableLazyLoad, boolean sqlDistinct) {
|
||||
SqlTreeNodeRoot(STreeType desc, SqlTreeProperties props, List<SqlTreeNode> myList, boolean withId, TableJoin includeJoin,
|
||||
STreePropertyAssocMany many, SpiQuery.TemporalMode temporalMode, boolean disableLazyLoad, boolean sqlDistinct, String baseTable) {
|
||||
|
||||
super(desc, props, myList, withId, many, temporalMode, disableLazyLoad);
|
||||
this.includeJoin = includeJoin;
|
||||
this.sqlDistinct = sqlDistinct;
|
||||
this.baseTable = baseTable;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -73,7 +76,7 @@ final class SqlTreeNodeRoot extends SqlTreeNodeBean {
|
||||
@Override
|
||||
public SqlJoinType appendFromBaseTable(DbSqlContext ctx, SqlJoinType joinType) {
|
||||
|
||||
ctx.append(desc.getBaseTable(temporalMode));
|
||||
ctx.append(baseTable);
|
||||
ctx.append(" ").append(baseTableAlias);
|
||||
ctx.appendFromForUpdate();
|
||||
|
||||
|
||||
@@ -235,6 +235,8 @@ public class DefaultOrmQuery<T> implements SpiQuery<T> {
|
||||
*/
|
||||
private String rootTableAlias;
|
||||
|
||||
private String baseTable;
|
||||
|
||||
/**
|
||||
* The node of the bean or collection that fired lazy loading. Not null if profiling is on and
|
||||
* this query is for lazy loading. Used to hook back a lazy loading query to the "original" query
|
||||
@@ -764,6 +766,7 @@ public class DefaultOrmQuery<T> implements SpiQuery<T> {
|
||||
copy.profilingListener = profilingListener;
|
||||
copy.profileLocation = profileLocation;
|
||||
|
||||
copy.baseTable = baseTable;
|
||||
copy.rootTableAlias = rootTableAlias;
|
||||
copy.distinct = distinct;
|
||||
copy.timeout = timeout;
|
||||
@@ -1082,6 +1085,9 @@ public class DefaultOrmQuery<T> implements SpiQuery<T> {
|
||||
if (disableLazyLoading) {
|
||||
sb.append(",disLazy:");
|
||||
}
|
||||
if (baseTable != null) {
|
||||
sb.append(",baseTable:").append(baseTable);
|
||||
}
|
||||
if (rootTableAlias != null) {
|
||||
sb.append(",root:").append(rootTableAlias);
|
||||
}
|
||||
@@ -1858,6 +1864,17 @@ public class DefaultOrmQuery<T> implements SpiQuery<T> {
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Query<T> setBaseTable(String baseTable) {
|
||||
this.baseTable = baseTable;
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getBaseTable() {
|
||||
return baseTable;
|
||||
}
|
||||
|
||||
@Override
|
||||
public DefaultOrmQuery<T> alias(String alias) {
|
||||
this.rootTableAlias = alias;
|
||||
|
||||
Reference in new issue
Block a user