mirror of
https://github.com/ebean-orm/ebean.git
synced 2024-04-21 10:51:47 +00:00
Added ability to set alias for root table of sql query.
This commit is contained in:
@@ -1230,4 +1230,9 @@ public interface Query<T> extends Serializable {
|
||||
* Return true if this query has forUpdate set.
|
||||
*/
|
||||
public boolean isForUpdate();
|
||||
|
||||
/**
|
||||
* Set root table alias.
|
||||
*/
|
||||
public Query<T> alias(String alias);
|
||||
}
|
||||
|
||||
@@ -611,4 +611,9 @@ public interface SpiQuery<T> extends Query<T> {
|
||||
* Return true if this query has been cancelled.
|
||||
*/
|
||||
public boolean isCancelled();
|
||||
|
||||
/**
|
||||
* Return root table alias set by {@link #alias(String)} command.
|
||||
*/
|
||||
public String getAlias();
|
||||
}
|
||||
|
||||
@@ -104,7 +104,7 @@ public class SqlTreeBuilder {
|
||||
this.queryDetail = query.getDetail();
|
||||
|
||||
this.predicates = predicates;
|
||||
this.alias = new SqlTreeAlias(request.getBeanDescriptor().getBaseTableAlias());
|
||||
this.alias = new SqlTreeAlias(request.getQuery().getAlias()==null?request.getBeanDescriptor().getBaseTableAlias():request.getQuery().getAlias());
|
||||
this.ctx = new DefaultDbSqlContext(alias, tableAliasPlaceHolder, columnAliasPrefix, !subQuery);
|
||||
}
|
||||
|
||||
|
||||
@@ -190,6 +190,11 @@ public class DefaultOrmQuery<T> implements SpiQuery<T> {
|
||||
private boolean autoFetchTuned;
|
||||
|
||||
private boolean logSecondaryQuery;
|
||||
|
||||
/**
|
||||
* Root table alias. For {@link Query#alias(String)} command.
|
||||
*/
|
||||
private String rootTableAlias=null;
|
||||
|
||||
/**
|
||||
* The node of the bean or collection that fired lazy loading. Not null if profiling is on and
|
||||
@@ -680,6 +685,7 @@ public class DefaultOrmQuery<T> implements SpiQuery<T> {
|
||||
builder.add(id != null);
|
||||
builder.add(rawSql == null ? 0 : rawSql.queryHash());
|
||||
builder.add(includeTableJoin != null ? includeTableJoin.queryHash() : 0);
|
||||
builder.add(rootTableAlias);
|
||||
|
||||
if (detail != null) {
|
||||
detail.queryPlanHash(request, builder);
|
||||
@@ -1284,6 +1290,17 @@ public class DefaultOrmQuery<T> implements SpiQuery<T> {
|
||||
this.cancelableQuery = cancelableQuery;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Query<T> alias(String alias) {
|
||||
this.rootTableAlias=alias;
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getAlias() {
|
||||
return rootTableAlias;
|
||||
}
|
||||
|
||||
public void cancel() {
|
||||
synchronized (this) {
|
||||
|
||||
Reference in New Issue
Block a user