${database.allClassCopyright}package ${glPackageNss};
#set ($myClassName = "${myNestSelectSetupperClassName}")

#if ($table.hasForeignKeyOrReferrerAsOne())
import org.seasar.dbflute.cbean.ConditionQuery;
#end
import ${glPackageCQ}.${myConditionQueryClassName};

/**
 * The nest select set-upper of ${table.name}.
 * @author ${database.classAuthor}
 */
public class ${myClassName} {

    // ===================================================================================
    //                                                                           Attribute
    //                                                                           =========
    protected ${myConditionQueryClassName} _query;
    public ${myClassName}(${myConditionQueryClassName} query) { _query = query; }
    public boolean hasConditionQuery() { return _query != null; }

    // ===================================================================================
    //                                                                     Nested Relation
    //                                                                     ===============
#foreach ($fk in $table.foreignKeys)
#set ($tmpPropertyName = "${fk.foreignPropertyName}")
#set ($tmpPropertyNameInitCap = "${fk.foreignPropertyNameInitCap}")
#set ($dynamicFixedConditionArgs = "")
#set ($dynamicFixedConditionVariables = "")
#if ($fk.hasDynamicFixedCondition())
#set ($dynamicFixedConditionArgs = "${fk.dynamicFixedConditionFinalArgs}")
#set ($dynamicFixedConditionVariables = "${fk.dynamicFixedConditionVariables}")
#end
    public ${fk.foreignTableNestSelectSetupperClassName} with${tmpPropertyNameInitCap}(${dynamicFixedConditionArgs}) {
        _query.doNss(new ${myConditionQueryClassName}.NssCall() { public ConditionQuery qf() { return _query.query${tmpPropertyNameInitCap}(${dynamicFixedConditionVariables}); }});
		return new ${fk.foreignTableNestSelectSetupperClassName}(_query.query${tmpPropertyNameInitCap}(${dynamicFixedConditionVariables}));
    }
#end

#foreach ($referrer in $table.referrers)
#if (${referrer.isOneToOne()})
#set ($tmpPropertyName = "${referrer.referrerPropertyNameAsOne}")
#set ($tmpPropertyNameInitCap = "${referrer.referrerPropertyNameInitCapAsOne}")
    public ${referrer.referrerTableNestSelectSetupperClassName} with${tmpPropertyNameInitCap}() {
        _query.doNss(new ${myConditionQueryClassName}.NssCall() { public ConditionQuery qf() { return _query.query${tmpPropertyNameInitCap}(); }});
		return new ${referrer.referrerTableNestSelectSetupperClassName}(_query.query${tmpPropertyNameInitCap}());
    }
#end
#end
}
