OSDN Git Service

DBFlute-0.9.3に更新
[ea2ddl/ea2ddl.git] / ea2ddl-gen / dbflute-0.9.3 / templates / om / java / cbean / BsConditionQuery.vm
@@ -3,16 +3,17 @@ ${database.allClassCopyright}package ${glPackageBaseCQ};
 \r
 import java.util.Map;\r
 \r
-import ${glPackageBaseCommonCBean}.*;\r
-import ${glPackageBaseCommonCValue}.${glConditionValueName};\r
-import ${glPackageBaseCommonSqlClause}.${glSqlClauseName};\r
+import org.seasar.dbflute.cbean.*;\r
+import org.seasar.dbflute.cbean.cvalue.ConditionValue;\r
+import org.seasar.dbflute.cbean.sqlclause.SqlClause;\r
 import ${glPackageCIQ}.*;\r
+import ${glPackageCB}.*;\r
 import ${glPackageCQ}.*;\r
 \r
 /**\r
  * The base condition-query of ${table.name}.\r
  * @author ${database.ClassAuthor}\r
- */${database.outputSuppressWarningsAfterLineSeparator()}\r
+ */\r
 public class ${myClassName} extends ${myAbstractBaseConditionQueryClassName} {\r
 \r
     // ===================================================================================\r
@@ -23,7 +24,7 @@ public class ${myClassName} extends ${myAbstractBaseConditionQueryClassName} {
     // ===================================================================================\r
     //                                                                         Constructor\r
     //                                                                         ===========\r
-    public ${myClassName}(${glConditionQueryInterfaceName} childQuery, ${glSqlClauseName} sqlClause, String aliasName, int nestLevel) {\r
+    public ${myClassName}(ConditionQuery childQuery, SqlClause sqlClause, String aliasName, int nestLevel) {\r
         super(childQuery, sqlClause, aliasName, nestLevel);\r
     }\r
 \r
@@ -48,7 +49,7 @@ public class ${myClassName} extends ${myAbstractBaseConditionQueryClassName} {
      * @return On-clause query. (NotNull)\r
      */\r
     public ${myConditionInlineQueryClassName} on() {\r
-        if (isBaseQuery(this)) { throw new UnsupportedOperationException("Unsupported onClause of Base Table!"); }\r
+        if (isBaseQuery(this)) { throw new UnsupportedOperationException("Unsupported on-clause for local table!"); }\r
         ${myConditionInlineQueryClassName} inlineQuery = inline(); inlineQuery.xsetOnClauseInline(true); return inlineQuery;\r
     }\r
 \r
@@ -59,14 +60,14 @@ public class ${myClassName} extends ${myAbstractBaseConditionQueryClassName} {
 #set ($tmpJavaName = "${col.JavaName}")\r
 #set ($tmpUncapitalisedJavaName = "${col.UncapitalisedJavaName}")\r
 \r
-    protected ${glConditionValueName} _${tmpUncapitalisedJavaName};\r
-    public ${glConditionValueName} get${tmpJavaName}() {\r
-        if (_${tmpUncapitalisedJavaName} == null) { _${tmpUncapitalisedJavaName} = new ${glConditionValueName}(); }\r
+    protected ConditionValue _${tmpUncapitalisedJavaName};\r
+    public ConditionValue get${tmpJavaName}() {\r
+        if (_${tmpUncapitalisedJavaName} == null) { _${tmpUncapitalisedJavaName} = new ConditionValue(); }\r
         return _${tmpUncapitalisedJavaName};\r
     }\r
-    protected ${glConditionValueName} getCValue${tmpJavaName}() { return get${tmpJavaName}(); }\r
+    protected ConditionValue getCValue${tmpJavaName}() { return get${tmpJavaName}(); }\r
 #if (${col.isJavaNativeStringObject()})\r
-#if (${col.isSingleKeyForeignKey()})\r
+#if (${col.isSingleKeyForeignKey()} && !${col.foreignKey.hasFixedCondition()})\r
 #set ($relatedCQClassName = "${col.foreignKey.foreignTableExtendedConditionQueryClassName}")\r
 #set ($subQueryPropertyNameInitCap = "${tmpJavaName}_InScopeSubQuery_${col.foreignKey.foreignPropertyNameInitCap}")\r
 #set ($subQueryPropertyName = "${tmpUncapitalisedJavaName}_InScopeSubQuery_${col.foreignKey.foreignPropertyNameInitCap}")\r
@@ -169,8 +170,8 @@ public class ${myClassName} extends ${myAbstractBaseConditionQueryClassName} {
 #if (!${referrer.isOneToOne()})\r
 #set ($relatedCBClassName = "${referrer.referrerTableExtendedConditionBeanClassName}")\r
 #set ($relatedCQClassName = "${referrer.referrerTableExtendedConditionQueryClassName}")\r
-#set ($subQueryPropertyNameInitCap = "${tmpJavaName}_DeriveSubQuery_${referrer.referrerPropertyNameInitCap}")\r
-#set ($subQueryPropertyName = "${tmpUncapitalisedJavaName}_DeriveSubQuery_${referrer.referrerPropertyNameInitCap}")\r
+#set ($subQueryPropertyNameInitCap = "${tmpJavaName}_SpecifyDerivedReferrer_${referrer.referrerPropertyNameInitCap}")\r
+#set ($subQueryPropertyName = "${tmpUncapitalisedJavaName}_SpecifyDerivedReferrer_${referrer.referrerPropertyNameInitCap}")\r
 #set ($subQueryKeepMapGeneric = "String, ${relatedCQClassName}")\r
 \r
     protected Map<${subQueryKeepMapGeneric}> _${subQueryPropertyName}Map;\r
@@ -183,13 +184,39 @@ public class ${myClassName} extends ${myAbstractBaseConditionQueryClassName} {
 #end\r
 #end\r
 #end\r
+#if (${col.hasSingleKeyReferrer()})\r
+#foreach ($referrer in $col.singleKeyReferrers)\r
+#if (!${referrer.isOneToOne()})\r
+#set ($relatedCBClassName = "${referrer.referrerTableExtendedConditionBeanClassName}")\r
+#set ($relatedCQClassName = "${referrer.referrerTableExtendedConditionQueryClassName}")\r
+#set ($subQueryPropertyNameInitCap = "${tmpJavaName}_QueryDerivedReferrer_${referrer.referrerPropertyNameInitCap}")\r
+#set ($subQueryPropertyName = "${tmpUncapitalisedJavaName}_QueryDerivedReferrer_${referrer.referrerPropertyNameInitCap}")\r
+#set ($subQueryKeepMapGeneric = "String, ${relatedCQClassName}")\r
+\r
+    protected Map<${subQueryKeepMapGeneric}> _${subQueryPropertyName}Map;\r
+    public Map<${subQueryKeepMapGeneric}> get${subQueryPropertyNameInitCap}() { return _${subQueryPropertyName}Map; }\r
+    public String keep${subQueryPropertyNameInitCap}(${relatedCQClassName} subQuery) {\r
+        if (_${subQueryPropertyName}Map == null) { _${subQueryPropertyName}Map = newLinkedHashMap(); }\r
+        String key = "subQueryMapKey" + (_${subQueryPropertyName}Map.size() + 1);\r
+        _${subQueryPropertyName}Map.put(key, subQuery); return "${subQueryPropertyName}." + key;\r
+    }\r
+    protected Map<String, Object> _${subQueryPropertyName}ParameterMap;\r
+    public Map<String, Object> get${subQueryPropertyNameInitCap}Parameter() { return _${subQueryPropertyName}ParameterMap; }\r
+    public String keep${subQueryPropertyNameInitCap}Parameter(Object parameterValue) {\r
+        if (_${subQueryPropertyName}ParameterMap == null) { _${subQueryPropertyName}ParameterMap = newLinkedHashMap(); }\r
+        String key = "subQueryParameterKey" + (_${subQueryPropertyName}ParameterMap.size() + 1);\r
+        _${subQueryPropertyName}ParameterMap.put(key, parameterValue); return "${subQueryPropertyName}Parameter." + key;\r
+    }\r
 #end\r
-    #if (${col.isJavaNativeNumberObject()})\r
-      #if (${col.isSingleKeyForeignKey()})\r
-        #set ($relatedCQClassName = "${col.foreignKey.foreignTableExtendedConditionQueryClassName}")\r
-        #set ($subQueryPropertyNameInitCap = "${tmpJavaName}_InScopeSubQuery_${col.foreignKey.foreignPropertyNameInitCap}")\r
-        #set ($subQueryPropertyName = "${tmpUncapitalisedJavaName}_InScopeSubQuery_${col.foreignKey.foreignPropertyNameInitCap}")\r
-        #set ($subQueryKeepMapGeneric = "String, ${relatedCQClassName}")\r
+#end\r
+#end\r
+#end\r
+#if (${col.isJavaNativeNumberObject()})\r
+#if (${col.isSingleKeyForeignKey()} && !${col.foreignKey.hasFixedCondition()})\r
+#set ($relatedCQClassName = "${col.foreignKey.foreignTableExtendedConditionQueryClassName}")\r
+#set ($subQueryPropertyNameInitCap = "${tmpJavaName}_InScopeSubQuery_${col.foreignKey.foreignPropertyNameInitCap}")\r
+#set ($subQueryPropertyName = "${tmpUncapitalisedJavaName}_InScopeSubQuery_${col.foreignKey.foreignPropertyNameInitCap}")\r
+#set ($subQueryKeepMapGeneric = "String, ${relatedCQClassName}")\r
 \r
     protected Map<${subQueryKeepMapGeneric}> _${subQueryPropertyName}Map;\r
     public Map<${subQueryKeepMapGeneric}> get${subQueryPropertyNameInitCap}() { return _${subQueryPropertyName}Map; }\r
@@ -288,8 +315,27 @@ public class ${myClassName} extends ${myAbstractBaseConditionQueryClassName} {
 #if (!${referrer.isOneToOne()})\r
 #set ($relatedCBClassName = "${referrer.referrerTableExtendedConditionBeanClassName}")\r
 #set ($relatedCQClassName = "${referrer.referrerTableExtendedConditionQueryClassName}")\r
-#set ($subQueryPropertyNameInitCap = "${tmpJavaName}_DeriveSubQuery_${referrer.referrerPropertyNameInitCap}")\r
-#set ($subQueryPropertyName = "${tmpUncapitalisedJavaName}_DeriveSubQuery_${referrer.referrerPropertyNameInitCap}")\r
+#set ($subQueryPropertyNameInitCap = "${tmpJavaName}_SpecifyDerivedReferrer_${referrer.referrerPropertyNameInitCap}")\r
+#set ($subQueryPropertyName = "${tmpUncapitalisedJavaName}_SpecifyDerivedReferrer_${referrer.referrerPropertyNameInitCap}")\r
+#set ($subQueryKeepMapGeneric = "String, ${relatedCQClassName}")\r
+\r
+    protected Map<${subQueryKeepMapGeneric}> _${subQueryPropertyName}Map;\r
+    public Map<${subQueryKeepMapGeneric}> get${subQueryPropertyNameInitCap}() { return _${subQueryPropertyName}Map; }\r
+    public String keep${subQueryPropertyNameInitCap}(${relatedCQClassName} subQuery) {\r
+        if (_${subQueryPropertyName}Map == null) { _${subQueryPropertyName}Map = newLinkedHashMap(); }\r
+        String key = "subQueryMapKey" + (_${subQueryPropertyName}Map.size() + 1);\r
+        _${subQueryPropertyName}Map.put(key, subQuery); return "${subQueryPropertyName}." + key;\r
+    }\r
+#end\r
+#end\r
+#end\r
+#if (${col.hasSingleKeyReferrer()})\r
+#foreach ($referrer in $col.singleKeyReferrers)\r
+#if (!${referrer.isOneToOne()})\r
+#set ($relatedCBClassName = "${referrer.referrerTableExtendedConditionBeanClassName}")\r
+#set ($relatedCQClassName = "${referrer.referrerTableExtendedConditionQueryClassName}")\r
+#set ($subQueryPropertyNameInitCap = "${tmpJavaName}_QueryDerivedReferrer_${referrer.referrerPropertyNameInitCap}")\r
+#set ($subQueryPropertyName = "${tmpUncapitalisedJavaName}_QueryDerivedReferrer_${referrer.referrerPropertyNameInitCap}")\r
 #set ($subQueryKeepMapGeneric = "String, ${relatedCQClassName}")\r
 \r
     protected Map<${subQueryKeepMapGeneric}> _${subQueryPropertyName}Map;\r
@@ -299,6 +345,13 @@ public class ${myClassName} extends ${myAbstractBaseConditionQueryClassName} {
         String key = "subQueryMapKey" + (_${subQueryPropertyName}Map.size() + 1);\r
         _${subQueryPropertyName}Map.put(key, subQuery); return "${subQueryPropertyName}." + key;\r
     }\r
+    protected Map<String, Object> _${subQueryPropertyName}ParameterMap;\r
+    public Map<String, Object> get${subQueryPropertyNameInitCap}Parameter() { return _${subQueryPropertyName}ParameterMap; }\r
+    public String keep${subQueryPropertyNameInitCap}Parameter(Object parameterValue) {\r
+        if (_${subQueryPropertyName}ParameterMap == null) { _${subQueryPropertyName}ParameterMap = newLinkedHashMap(); }\r
+        String key = "subQueryParameterKey" + (_${subQueryPropertyName}ParameterMap.size() + 1);\r
+        _${subQueryPropertyName}ParameterMap.put(key, parameterValue); return "${subQueryPropertyName}Parameter." + key;\r
+    }\r
 #end\r
 #end\r
 #end\r
@@ -317,20 +370,25 @@ public class ${myClassName} extends ${myAbstractBaseConditionQueryClassName} {
     // ===================================================================================\r
     //                                                                         Union Query\r
     //                                                                         ===========\r
-    protected void reflectRelationOnUnionQuery(${glConditionQueryInterfaceName} baseQueryAsSuper, ${glConditionQueryInterfaceName} unionQueryAsSuper) {\r
+    protected void reflectRelationOnUnionQuery(ConditionQuery baseQueryAsSuper, ConditionQuery unionQueryAsSuper) {\r
 #if ($table.hasForeignKeyOrRefererAsOne())\r
         ${myConditionQueryClassName} baseQuery = (${myConditionQueryClassName})baseQueryAsSuper;\r
         ${myConditionQueryClassName} unionQuery = (${myConditionQueryClassName})unionQueryAsSuper;\r
 #end\r
-#foreach ($foreignKeys in $table.foreignKeys)\r
-        if (baseQuery.hasConditionQuery${foreignKeys.foreignPropertyNameInitCap}()) {\r
-            unionQuery.query${foreignKeys.foreignPropertyNameInitCap}().reflectRelationOnUnionQuery(baseQuery.query${foreignKeys.foreignPropertyNameInitCap}(), unionQuery.query${foreignKeys.foreignPropertyNameInitCap}());\r
+#foreach ($fk in $table.foreignKeys)\r
+        if (baseQuery.hasConditionQuery${fk.foreignPropertyNameInitCap}()) {\r
+#if ($fk.hasDynamicFixedCondition())\r
+            unionQuery.xsetParameterMap${fk.foreignPropertyNameInitCap}(baseQuery.getParameterMap${fk.foreignPropertyNameInitCap}());\r
+            unionQuery.getConditionQuery${fk.foreignPropertyNameInitCap}().reflectRelationOnUnionQuery(baseQuery.getConditionQuery${fk.foreignPropertyNameInitCap}(), unionQuery.getConditionQuery${fk.foreignPropertyNameInitCap}());\r
+#else\r
+            unionQuery.query${fk.foreignPropertyNameInitCap}().reflectRelationOnUnionQuery(baseQuery.query${fk.foreignPropertyNameInitCap}(), unionQuery.query${fk.foreignPropertyNameInitCap}());\r
+#end\r
         }\r
 #end\r
-#foreach ($refferer in $table.referrers)\r
-#if (${refferer.isOneToOne()})\r
-        if (baseQuery.hasConditionQuery${refferer.reffererPropertyNameInitCapAsOne}()) {\r
-            unionQuery.query${refferer.reffererPropertyNameInitCapAsOne}().reflectRelationOnUnionQuery(baseQuery.query${refferer.reffererPropertyNameInitCapAsOne}(), unionQuery.query${refferer.reffererPropertyNameInitCapAsOne}());\r
+#foreach ($referrer in $table.referrers)\r
+#if (${referrer.isOneToOne()})\r
+        if (baseQuery.hasConditionQuery${referrer.referrerPropertyNameInitCapAsOne}()) {\r
+            unionQuery.query${referrer.referrerPropertyNameInitCapAsOne}().reflectRelationOnUnionQuery(baseQuery.query${referrer.referrerPropertyNameInitCapAsOne}(), unionQuery.query${referrer.referrerPropertyNameInitCapAsOne}());\r
         }\r
 #end\r
 #end\r
@@ -339,82 +397,131 @@ public class ${myClassName} extends ${myAbstractBaseConditionQueryClassName} {
     // ===================================================================================\r
     //                                                                       Foreign Query\r
     //                                                                       =============\r
-#foreach ($foreignKeys in $table.foreignKeys)\r
-#set ($foreignCQClassName = "${foreignKeys.foreignTableExtendedConditionQueryClassName}")\r
-    \r
-    public ${foreignCQClassName} query${foreignKeys.ForeignPropertyNameInitCap}() {\r
-        return getConditionQuery${foreignKeys.ForeignPropertyNameInitCap}();\r
-    }\r
-    protected ${foreignCQClassName} _conditionQuery${foreignKeys.ForeignPropertyNameInitCap};\r
-    public ${foreignCQClassName} getConditionQuery${foreignKeys.ForeignPropertyNameInitCap}() {\r
-        if (_conditionQuery${foreignKeys.foreignPropertyNameInitCap} == null) {\r
-            _conditionQuery${foreignKeys.foreignPropertyNameInitCap} = createQuery${foreignKeys.foreignPropertyNameInitCap}();\r
-            setupOuterJoin_${foreignKeys.foreignPropertyNameInitCap}();\r
+#foreach ($fk in $table.foreignKeys)\r
+#set ($foreignCQClassName = "${fk.foreignTableExtendedConditionQueryClassName}")\r
+#set ($dynamicFixedConditionArgs = "")\r
+#if ($fk.hasDynamicFixedCondition())\r
+#set ($dynamicFixedConditionArgs = "${fk.dynamicFixedConditionArgs}")\r
+#end\r
+    public ${foreignCQClassName} query${fk.foreignPropertyNameInitCap}(${dynamicFixedConditionArgs}) {\r
+#if ($fk.hasDynamicFixedCondition())\r
+        Map<String, Object> parameterMap = getParameterMap${fk.foreignPropertyNameInitCap}();\r
+        ${fk.dynamicFixedConditionParameterMapSetup}\r
+#end\r
+        return getConditionQuery${fk.foreignPropertyNameInitCap}();\r
+    }\r
+    protected ${foreignCQClassName} _conditionQuery${fk.foreignPropertyNameInitCap};\r
+    public ${foreignCQClassName} getConditionQuery${fk.ForeignPropertyNameInitCap}() {\r
+        if (_conditionQuery${fk.foreignPropertyNameInitCap} == null) {\r
+            _conditionQuery${fk.foreignPropertyNameInitCap} = xcreateQuery${fk.foreignPropertyNameInitCap}();\r
+            xsetupOuterJoin${fk.foreignPropertyNameInitCap}();\r
         }\r
-        return _conditionQuery${foreignKeys.foreignPropertyNameInitCap};\r
+        return _conditionQuery${fk.foreignPropertyNameInitCap};\r
+    }\r
+#if ($fk.hasDynamicFixedCondition())\r
+    protected Map<String, Object> _parameterMap${fk.foreignPropertyNameInitCap};\r
+    public Map<String, Object> getParameterMap${fk.foreignPropertyNameInitCap}() {\r
+        if (_parameterMap${fk.foreignPropertyNameInitCap} == null) {\r
+            _parameterMap${fk.foreignPropertyNameInitCap} = newLinkedHashMap();\r
+        }\r
+        return _parameterMap${fk.foreignPropertyNameInitCap};\r
+    }\r
+    public void xsetParameterMap${fk.foreignPropertyNameInitCap}(Map<String, Object> parameterMap) {\r
+        _parameterMap${fk.foreignPropertyNameInitCap} = parameterMap; // for UnionQuery\r
     }\r
-    protected void setupOuterJoin_${foreignKeys.foreignPropertyNameInitCap}() {\r
+#end\r
+    protected ${foreignCQClassName} xcreateQuery${fk.foreignPropertyNameInitCap}() {\r
+        String nrp = resolveNextRelationPath("${table.name}", "${fk.foreignPropertyName}");\r
+        String jan = resolveJoinAliasName(nrp, getNextNestLevel());\r
+        ${foreignCQClassName} cq = new ${foreignCQClassName}(this, getSqlClause(), jan, getNextNestLevel());\r
+        cq.xsetForeignPropertyName("${fk.foreignPropertyName}"); cq.xsetRelationPath(nrp); return cq;\r
+    }\r
+    protected void xsetupOuterJoin${fk.foreignPropertyNameInitCap}() {\r
+        ${foreignCQClassName} cq = getConditionQuery${fk.foreignPropertyNameInitCap}();\r
         Map<String, String> joinOnMap = newLinkedHashMap();\r
-#foreach ($columnName in $foreignKeys.LocalColumns)\r
+#foreach ($columnName in $fk.LocalColumns)\r
 #set ($localColumn = $table.getColumn($columnName))\r
-#set ($foreignColumnName = $foreignKeys.getLocalForeignMapping().get($columnName))\r
-        joinOnMap.put(getRealColumnName("${localColumn.name}"), getConditionQuery${foreignKeys.foreignPropertyNameInitCap}().getRealColumnName("${foreignColumnName}"));\r
+#set ($foreignColumnName = $fk.getLocalForeignMapping().get($columnName))\r
+        joinOnMap.put(getRealColumnName("${localColumn.name}"), cq.getRealColumnName("${foreignColumnName}"));\r
 #end\r
-#if ($foreignKeys.hasFixedCondition())\r
-        joinOnMap.put("$$fixedCondition$$", prepareFixedCondition("${foreignKeys.fixedCondition}", getRealAliasName(), getConditionQuery${foreignKeys.foreignPropertyNameInitCap}().getRealAliasName()));\r
+#if ($fk.hasFixedCondition())\r
+        joinOnMap.put("$$fixedCondition$$", ppFxCd("${fk.fixedCondition}", getRealAliasName(), cq.getRealAliasName()));\r
 #end\r
-        registerOuterJoin(getConditionQuery${foreignKeys.foreignPropertyNameInitCap}(), joinOnMap);\r
-    }\r
-    protected ${foreignCQClassName} createQuery${foreignKeys.foreignPropertyNameInitCap}() {\r
-        String nrp = resolveNextRelationPath("${table.name}", "${foreignKeys.foreignPropertyName}");\r
-        String jan = resolveJoinAliasName(nrp, getNextNestLevel());\r
-        ${foreignCQClassName} cq = new ${foreignCQClassName}(this, getSqlClause(), jan, getNextNestLevel());\r
-        cq.xsetForeignPropertyName("${foreignKeys.foreignPropertyName}"); cq.xsetRelationPath(nrp); return cq;\r
+        registerOuterJoin(cq, joinOnMap);\r
     }\r
-    public boolean hasConditionQuery${foreignKeys.ForeignPropertyNameInitCap}() {\r
-        return _conditionQuery${foreignKeys.ForeignPropertyNameInitCap} != null;\r
+    public boolean hasConditionQuery${fk.ForeignPropertyNameInitCap}() {\r
+        return _conditionQuery${fk.ForeignPropertyNameInitCap} != null;\r
     }\r
-#end\r
 \r
+#end\r
 #foreach ($referrer in $table.referrers)\r
 #set ($relatedCQClassName = "${referrer.referrerTableExtendedConditionQueryClassName}")\r
 #if (${referrer.isOneToOne()})\r
-\r
     public ${relatedCQClassName} query${referrer.referrerPropertyNameInitCapAsOne}() {\r
         return getConditionQuery${referrer.referrerPropertyNameInitCapAsOne}();\r
     }\r
     protected ${relatedCQClassName} _conditionQuery${referrer.referrerPropertyNameInitCapAsOne};\r
     public ${relatedCQClassName} getConditionQuery${referrer.referrerPropertyNameInitCapAsOne}() {\r
         if (_conditionQuery${referrer.referrerPropertyNameInitCapAsOne} == null) {\r
-            _conditionQuery${referrer.referrerPropertyNameInitCapAsOne} = createQuery${referrer.referrerPropertyNameInitCapAsOne}();\r
-            setupOuterJoin_${referrer.referrerPropertyNameInitCapAsOne}();\r
+            _conditionQuery${referrer.referrerPropertyNameInitCapAsOne} = xcreateQuery${referrer.referrerPropertyNameInitCapAsOne}();\r
+            xsetupOuterJoin${referrer.referrerPropertyNameInitCapAsOne}();\r
         }\r
         return _conditionQuery${referrer.referrerPropertyNameInitCapAsOne};\r
     }\r
-    protected void setupOuterJoin_${referrer.referrerPropertyNameInitCapAsOne}() {\r
+    protected ${relatedCQClassName} xcreateQuery${referrer.referrerPropertyNameInitCapAsOne}() {\r
+        String nrp = resolveNextRelationPath("${table.name}", "${referrer.referrerPropertyNameAsOne}");\r
+        String jan = resolveJoinAliasName(nrp, getNextNestLevel());\r
+        ${relatedCQClassName} cq = new ${relatedCQClassName}(this, getSqlClause(), jan, getNextNestLevel());\r
+        cq.xsetForeignPropertyName("${referrer.referrerPropertyNameAsOne}"); cq.xsetRelationPath(nrp); return cq;\r
+    }\r
+    protected void xsetupOuterJoin${referrer.referrerPropertyNameInitCapAsOne}() {\r
+        ${relatedCQClassName} cq = getConditionQuery${referrer.referrerPropertyNameInitCapAsOne}();\r
         Map<String, String> joinOnMap = newLinkedHashMap();\r
 #foreach ($columnName in $referrer.foreignColumns)\r
 #set ($foreignColumn = $table.getColumn($columnName))\r
 #set ($referrerColumnName = $referrer.getForeignLocalMapping().get($columnName))\r
-        joinOnMap.put(getRealColumnName("${foreignColumn.name}"), getConditionQuery${referrer.referrerPropertyNameInitCapAsOne}().getRealColumnName("${referrerColumnName}"));\r
+        joinOnMap.put(getRealColumnName("${foreignColumn.name}"), cq.getRealColumnName("${referrerColumnName}"));\r
 #end\r
 #if ($referrer.hasFixedCondition())\r
-        joinOnMap.put("$$fixedCondition$$", prepareFixedCondition("${referrer.fixedCondition}", getRealAliasName(), getConditionQuery${referrer.referrerPropertyNameInitCapAsOne}().getRealAliasName()));\r
+        joinOnMap.put("$$fixedCondition$$", ppFxCd("${referrer.fixedCondition}", getRealAliasName(), cq.getRealAliasName()));\r
 #end\r
-        registerOuterJoin(getConditionQuery${referrer.referrerPropertyNameInitCapAsOne}(), joinOnMap);\r
-    }\r
-    protected ${relatedCQClassName} createQuery${referrer.referrerPropertyNameInitCapAsOne}() {\r
-        String nrp = resolveNextRelationPath("${table.name}", "${referrer.referrerPropertyNameAsOne}");\r
-        String jan = resolveJoinAliasName(nrp, getNextNestLevel());\r
-        ${relatedCQClassName} cq = new ${relatedCQClassName}(this, getSqlClause(), jan, getNextNestLevel());\r
-        cq.xsetForeignPropertyName("${referrer.referrerPropertyNameAsOne}"); cq.xsetRelationPath(nrp); return cq;\r
+        registerOuterJoin(cq, joinOnMap);\r
     }\r
     public boolean hasConditionQuery${referrer.referrerPropertyNameInitCapAsOne}() {\r
         return _conditionQuery${referrer.referrerPropertyNameInitCapAsOne} != null;\r
     }\r
+\r
 #end\r
 #end\r
+#if ($table.hasOnlyOnePrimaryKey())\r
+    // ===================================================================================\r
+    //                                                                     Scalar SubQuery\r
+    //                                                                     ===============\r
+    protected Map<String, ${myConditionQueryClassName}> _scalarSubQueryMap;\r
+    public Map<String, ${myConditionQueryClassName}> getScalarSubQuery() { return _scalarSubQueryMap; }\r
+    public String keepScalarSubQuery(${myConditionQueryClassName} subQuery) {\r
+        if (_scalarSubQueryMap == null) { _scalarSubQueryMap = newLinkedHashMap(); }\r
+        String key = "subQueryMapKey" + (_scalarSubQueryMap.size() + 1);\r
+        _scalarSubQueryMap.put(key, subQuery); return "scalarSubQuery." + key;\r
+    }\r
 \r
-    protected String getConditionQueryClassNameInternally() { return ${myConditionQueryClassName}.class.getName(); }\r
-    protected String getMapClassNameInternally() { return Map.class.getName(); }\r
+    // ===================================================================================\r
+    //                                                             MySelf InScope SubQuery\r
+    //                                                             =======================\r
+    protected Map<String, ${myConditionQueryClassName}> _myselfInScopeSubQueryMap;\r
+    public Map<String, ${myConditionQueryClassName}> getMyselfInScopeSubQuery() { return _myselfInScopeSubQueryMap; }\r
+    public String keepMyselfInScopeSubQuery(${myConditionQueryClassName} subQuery) {\r
+        if (_myselfInScopeSubQueryMap == null) { _myselfInScopeSubQueryMap = newLinkedHashMap(); }\r
+        String key = "subQueryMapKey" + (_myselfInScopeSubQueryMap.size() + 1);\r
+        _myselfInScopeSubQueryMap.put(key, subQuery); return "myselfInScopeSubQuery." + key;\r
+    }\r
+\r
+#end\r
+    // ===================================================================================\r
+    //                                                                       Very Internal\r
+    //                                                                       =============\r
+    // Very Internal (for Suppressing Warn about 'Not Use Import')\r
+    String xCB() { return ${myConditionBeanClassName}.class.getName(); }\r
+    String xCQ() { return ${myConditionQueryClassName}.class.getName(); }\r
+    String xMap() { return Map.class.getName(); }\r
 }\r