package io.ebeaninternal.server.query;
import io.ebean.bean.EntityBean;
import io.ebeaninternal.api.SpiQuery;
import io.ebeaninternal.server.deploy.DbReadContext;
import io.ebeaninternal.server.deploy.DbSqlContext;
import java.sql.SQLException;
import java.util.List;
final class SqlTreeNodeManyRoot extends SqlTreeNodeBean {
private final STreePropertyAssocMany manyProp;
SqlTreeNodeManyRoot(String prefix, STreePropertyAssocMany prop, SqlTreeProperties props, List<SqlTreeNode> myList,
SpiQuery.TemporalMode temporalMode, boolean disableLazyLoad) {
super(prefix, prop, props, myList, true, temporalMode, disableLazyLoad);
this.manyProp = prop;
}
@Override
public void appendDistinctOn(DbSqlContext ctx, boolean subQuery) {
ctx.pushTableAlias(prefix);
appendSelectId(ctx, idBinder.getBeanProperty());
ctx.popTableAlias();
}
@Override
public EntityBean load(DbReadContext cquery, EntityBean parentBean, EntityBean contextParent) throws SQLException {
EntityBean detailBean = super.load(cquery, null, null);
if (contextParent != null) {
manyProp.addBeanToCollectionWithCreate(contextParent, detailBean, false);
}
return detailBean;
}
@Override
protected SqlJoinType appendFromAsJoin(DbSqlContext ctx, SqlJoinType joinType) {
SqlJoinType join = super.appendFromAsJoin(ctx, joinType);
super.appendExtraWhere(ctx);
return join;
}
@Override
protected void (DbSqlContext ctx) {
}
@Override
public void appendFrom(DbSqlContext ctx, SqlJoinType joinType) {
super.appendFrom(ctx, joinType.autoToOuter());
}
@Override
public boolean hasMany() {
return true;
}
}