${database.allClassCopyright}package ${glPackageBaseBhv}; #set ($myClassName = "${myBaseBhvClassName}") import java.util.List; import org.seasar.dbflute.*; import org.seasar.dbflute.bhv.*; #if ($table.isAvailableNonPrimaryKeyWritable()) import org.seasar.dbflute.bhv.core.command.InsertEntityCommand; #end import org.seasar.dbflute.cbean.ConditionBean; import org.seasar.dbflute.cbean.EntityRowHandler; import org.seasar.dbflute.cbean.ListResultBean; import org.seasar.dbflute.cbean.PagingResultBean; import org.seasar.dbflute.dbmeta.DBMeta; #if ($database.isMakeFlatExpansion()) import org.seasar.dbflute.dbmeta.hierarchy.HierarchyArranger; import org.seasar.dbflute.dbmeta.hierarchy.HierarchyBasicRequest; import org.seasar.dbflute.dbmeta.hierarchy.HierarchyRequest; #end #if ($table.isBuriTarget()) import ${glPackagePluginBuri}.${glBuriDef}; #end #if ($table.hasPrimaryKeyForcedClassificationSetting()) import ${glPackageBaseCommon}.${glCDef}; #end #if (${table.hasPrimaryKey()} && $table.hasReferrerAsMany()) import ${glPackageExtendedBhv}.*; #end import ${glPackageExtendedEntity}.*; import ${myDBMetaPackageName}.*; import ${glPackageCB}.*; #set ($myExtendClassName = "") #if ($table.isWritable()) #set ($myExtendClassName = "AbstractBehaviorWritable") #else #set ($myExtendClassName = "AbstractBehaviorReadable") #end /** * The behavior of ${table.basicInfoDispString}.
#if ($table.isBuriInternal()) * {Buri Internal} #end *
 * [primary-key]
 *     ${table.primaryKeyNameCommaString}
 * 
 * [column]
 *     ${table.columnNameCommaString}
 * 
 * [sequence]
 *     ${table.definedSequenceName}
 * 
 * [identity]
 *     ${table.identityColumnName}
 * 
 * [version-no]
 *     ${table.versionNoColumnName}
 * 
 * [foreign-table]
 *     ${table.foreignTableNameCommaString}
 * 
 * [referrer-table]
 *     ${table.referrerTableNameCommaString}
 * 
 * [foreign-property]
 *     ${table.foreignPropertyNameCommaString}
 * 
 * [referrer-property]
 *     ${table.referrerPropertyNameCommaString}
 * 
* @author ${database.classAuthor} */ public abstract class ${myClassName} extends ${myExtendClassName} { // =================================================================================== // Definition // ========== ${database.behaviorQueryPathBeginMark} ${database.behaviorQueryPathEndMark} // =================================================================================== // Table name // ========== /** @return The name on database of table. (NotNull) */ public String getTableDbName() { return "${table.name}"; } // =================================================================================== // DBMeta // ====== /** @return The instance of DBMeta. (NotNull) */ public DBMeta getDBMeta() { return ${myDBMetaClassName}.getInstance(); } /** @return The instance of DBMeta as my table type. (NotNull) */ public ${myDBMetaClassName} getMyDBMeta() { return ${myDBMetaClassName}.getInstance(); } // =================================================================================== // New Instance // ============ /** {@inheritDoc} */ public Entity newEntity() { return newMyEntity(); } /** {@inheritDoc} */ public ConditionBean newConditionBean() { return newMyConditionBean(); } /** @return The instance of new entity as my table type. (NotNull) */ public ${myExtendedObjectClassName} newMyEntity() { return new ${myExtendedObjectClassName}(); } /** @return The instance of new condition-bean as my table type. (NotNull) */ public ${myConditionBeanClassName} newMyConditionBean() { return new ${myConditionBeanClassName}(); } // =================================================================================== // Count Select // ============ /** * Select the count by the condition-bean. {IgnorePagingCondition} *
     * ${myConditionBeanClassName} cb = new ${myConditionBeanClassName}();
     * cb.query().setFoo...(value);
     * int count = ${myEntityVariableName}Bhv.selectCount(cb);
     * 
* @param cb The condition-bean of ${myExtendedObjectClassName}. (NotNull) * @return The selected count. */ public int selectCount(${myConditionBeanClassName} cb) { return doSelectCount(cb); } protected int doSelectCount(${myConditionBeanClassName} cb) { assertCBNotNull(cb); return delegateSelectCount(cb); } @Override protected int doReadCount(ConditionBean cb) { return selectCount(downcast(cb)); } // =================================================================================== // Cursor Select // ============= /** * Select the cursor by the condition-bean. *
     * ${myConditionBeanClassName} cb = new ${myConditionBeanClassName}();
     * cb.query().setFoo...(value);
     * ${myEntityVariableName}Bhv.selectCursor(cb, new EntityRowHandler<${myExtendedObjectClassName}>() {
     *     public void handle(${myExtendedObjectClassName} entity) {
     *         ... = entity.getFoo...();
     *     }
     * });
     * 
* @param cb The condition-bean of ${myExtendedObjectClassName}. (NotNull) * @param entityRowHandler The handler of entity row of ${myExtendedObjectClassName}. (NotNull) */ public void selectCursor(${myConditionBeanClassName} cb, EntityRowHandler<${myExtendedObjectClassName}> entityRowHandler) { doSelectCursor(cb, entityRowHandler, ${myExtendedObjectClassName}.class); } protected void doSelectCursor(${myConditionBeanClassName} cb, EntityRowHandler entityRowHandler, Class entityType) { assertCBNotNull(cb); assertObjectNotNull("entityRowHandler<${myExtendedObjectClassName}>", entityRowHandler); assertObjectNotNull("entityType", entityType); assertSpecifyDerivedReferrerEntityProperty(cb, entityType); delegateSelectCursor(cb, entityRowHandler, entityType); } // =================================================================================== // Entity Select // ============= /** * Select the entity by the condition-bean. *
     * ${myConditionBeanClassName} cb = new ${myConditionBeanClassName}();
     * cb.query().setFoo...(value);
     * ${myExtendedObjectClassName} ${myEntityVariableName} = ${myEntityVariableName}Bhv.selectEntity(cb);
     * if (${myEntityVariableName} != null) {
     *     ... = ${myEntityVariableName}.get...();
     * } else {
     *     ...
     * }
     * 
* @param cb The condition-bean of ${myExtendedObjectClassName}. (NotNull) * @return The selected entity. (Nullable: If the condition has no data, it returns null) * @exception org.seasar.dbflute.exception.EntityDuplicatedException When the entity has been duplicated. * @exception org.seasar.dbflute.exception.SelectEntityConditionNotFoundException When the condition for selecting an entity is not found. */ public ${myExtendedObjectClassName} selectEntity(${myConditionBeanClassName} cb) { return doSelectEntity(cb, ${myExtendedObjectClassName}.class); } protected ENTITY doSelectEntity(final ${myConditionBeanClassName} cb, final Class entityType) { return helpSelectEntityInternally(cb, new InternalSelectEntityCallback() { public List callbackSelectList(${myConditionBeanClassName} cb) { return doSelectList(cb, entityType); } }); } @Override protected Entity doReadEntity(ConditionBean cb) { return selectEntity(downcast(cb)); } /** * Select the entity by the condition-bean with deleted check. *
     * ${myConditionBeanClassName} cb = new ${myConditionBeanClassName}();
     * cb.query().setFoo...(value);
     * ${myExtendedObjectClassName} ${myEntityVariableName} = ${myEntityVariableName}Bhv.selectEntityWithDeletedCheck(cb);
     * ... = ${myEntityVariableName}.get...(); // the entity always be not null
     * 
* @param cb The condition-bean of ${myExtendedObjectClassName}. (NotNull) * @return The selected entity. (NotNull) * @exception org.seasar.dbflute.exception.EntityAlreadyDeletedException When the entity has already been deleted. * @exception org.seasar.dbflute.exception.EntityDuplicatedException When the entity has been duplicated. * @exception org.seasar.dbflute.exception.SelectEntityConditionNotFoundException When the condition for selecting an entity is not found. */ public ${myExtendedObjectClassName} selectEntityWithDeletedCheck(${myConditionBeanClassName} cb) { return doSelectEntityWithDeletedCheck(cb, ${myExtendedObjectClassName}.class); } protected ENTITY doSelectEntityWithDeletedCheck(final ${myConditionBeanClassName} cb, final Class entityType) { return helpSelectEntityWithDeletedCheckInternally(cb, new InternalSelectEntityWithDeletedCheckCallback() { public List callbackSelectList(${myConditionBeanClassName} cb) { return doSelectList(cb, entityType); } }); } @Override protected Entity doReadEntityWithDeletedCheck(ConditionBean cb) { return selectEntityWithDeletedCheck(downcast(cb)); } #if ($table.hasPrimaryKey()) /** * Select the entity by the primary-key value. * ${table.primaryKeyArgsJavaDocString} * @return The selected entity. (Nullable: If the primary-key value has no data, it returns null) * @exception org.seasar.dbflute.exception.EntityDuplicatedException When the entity has been duplicated. * @exception org.seasar.dbflute.exception.SelectEntityConditionNotFoundException When the condition for selecting an entity is not found. */ public ${myExtendedObjectClassName} selectByPKValue(${table.primaryKeyArgsString}) { return doSelectByPKValue(${table.primaryKeyArgsCallingString}, ${myExtendedObjectClassName}.class); } protected ENTITY doSelectByPKValue(${table.primaryKeyArgsString}, Class entityType) { return doSelectEntity(buildPKCB(${table.primaryKeyArgsCallingString}), entityType); } /** * Select the entity by the primary-key value with deleted check. * ${table.primaryKeyArgsJavaDocString} * @return The selected entity. (NotNull) * @exception org.seasar.dbflute.exception.EntityAlreadyDeletedException When the entity has already been deleted. * @exception org.seasar.dbflute.exception.EntityDuplicatedException When the entity has been duplicated. * @exception org.seasar.dbflute.exception.SelectEntityConditionNotFoundException When the condition for selecting an entity is not found. */ public ${myExtendedObjectClassName} selectByPKValueWithDeletedCheck(${table.primaryKeyArgsString}) { return doSelectByPKValueWithDeletedCheck(${table.primaryKeyArgsCallingString}, ${myExtendedObjectClassName}.class); } protected ENTITY doSelectByPKValueWithDeletedCheck(${table.primaryKeyArgsString}, Class entityType) { return doSelectEntityWithDeletedCheck(buildPKCB(${table.primaryKeyArgsCallingString}), entityType); } private ${myConditionBeanClassName} buildPKCB(${table.primaryKeyArgsString}) { ${table.primaryKeyArgsAssertString} ${myConditionBeanClassName} cb = newMyConditionBean(); ${table.primaryKeyArgsConditionSetupString} return cb; } #end // =================================================================================== // List Select // =========== /** * Select the list as result bean. *
     * ${myConditionBeanClassName} cb = new ${myConditionBeanClassName}();
     * cb.query().setFoo...(value);
     * cb.query().addOrderBy_Bar...();
     * ListResultBean<${myExtendedObjectClassName}> ${myEntityListVariableName} = ${myEntityVariableName}Bhv.selectList(cb);
     * for (${myExtendedObjectClassName} ${myEntityVariableName} : ${myEntityListVariableName}) {
     *     ... = ${myEntityVariableName}.get...();
     * }
     * 
* @param cb The condition-bean of ${myExtendedObjectClassName}. (NotNull) * @return The result bean of selected list. (NotNull) * @exception org.seasar.dbflute.exception.DangerousResultSizeException When the result size is over the specified safety size. */ public ListResultBean<${myExtendedObjectClassName}> selectList(${myConditionBeanClassName} cb) { return doSelectList(cb, ${myExtendedObjectClassName}.class); } protected ListResultBean doSelectList(${myConditionBeanClassName} cb, Class entityType) { assertCBNotNull(cb); assertObjectNotNull("entityType", entityType); assertSpecifyDerivedReferrerEntityProperty(cb, entityType); return helpSelectListInternally(cb, entityType, new InternalSelectListCallback() { public List callbackSelectList(${myConditionBeanClassName} cb, Class entityType) { return delegateSelectList(cb, entityType); } }); } @Override protected ListResultBean doReadList(ConditionBean cb) { return selectList(downcast(cb)); } // =================================================================================== // Page Select // =========== /** * Select the page as result bean.
* (both count-select and paging-select are executed) *
     * ${myConditionBeanClassName} cb = new ${myConditionBeanClassName}();
     * cb.query().setFoo...(value);
     * cb.query().addOrderBy_Bar...();
     * cb.paging(20, 3); // 20 records per a page and current page number is 3
     * PagingResultBean<${myExtendedObjectClassName}> page = ${myEntityVariableName}Bhv.selectPage(cb);
     * int allRecordCount = page.getAllRecordCount();
     * int allPageCount = page.getAllPageCount();
     * boolean isExistPrePage = page.isExistPrePage();
     * boolean isExistNextPage = page.isExistNextPage();
     * ...
     * for (${myExtendedObjectClassName} ${myEntityVariableName} : page) {
     *     ... = ${myEntityVariableName}.get...();
     * }
     * 
* @param cb The condition-bean of ${myExtendedObjectClassName}. (NotNull) * @return The result bean of selected page. (NotNull) * @exception org.seasar.dbflute.exception.DangerousResultSizeException When the result size is over the specified safety size. */ public PagingResultBean<${myExtendedObjectClassName}> selectPage(${myConditionBeanClassName} cb) { return doSelectPage(cb, ${myExtendedObjectClassName}.class); } protected PagingResultBean doSelectPage(${myConditionBeanClassName} cb, Class entityType) { assertCBNotNull(cb); assertObjectNotNull("entityType", entityType); return helpSelectPageInternally(cb, entityType, new InternalSelectPageCallback() { public int callbackSelectCount(${myConditionBeanClassName} cb) { return doSelectCount(cb); } public List callbackSelectList(${myConditionBeanClassName} cb, Class entityType) { return doSelectList(cb, entityType); } }); } @Override protected PagingResultBean doReadPage(ConditionBean cb) { return selectPage(downcast(cb)); } // =================================================================================== // Scalar Select // ============= /** * Select the scalar value derived by a function.
* You should call a function method after this method called like as follows: *
     * ${myEntityVariableName}Bhv.scalarSelect(Date.class).max(new ScalarQuery() {
     *     public void query(${myConditionBeanClassName} cb) {
     *         cb.specify().columnFooDatetime(); // required for a function
     *         cb.query().setBarName_PrefixSearch("S");
     *     }
     * });
     * 
* @param The type of result. * @param resultType The type of result. (NotNull) * @return The scalar value derived by a function. (Nullable) */ public SLFunction<${myConditionBeanClassName}, RESULT> scalarSelect(Class resultType) { return doScalarSelect(resultType, newMyConditionBean()); } protected SLFunction doScalarSelect(Class resultType, CB cb) { assertObjectNotNull("resultType", resultType); assertCBNotNull(cb); cb.xsetupForScalarSelect(); cb.getSqlClause().disableSelectIndex(); // for when you use union return new SLFunction(cb, resultType); } // =================================================================================== // Sequence // ======== #if ($table.isUseSequence()) /** * Select the next value as sequence.
* This method is called when insert() and set to primary-key automatically. * So you don't need to call this as long as you need to get next value before insert(). * @return The next value. (NotNull) */ public ${table.sequenceReturnType} selectNextVal() { return doSelectNextVal(${table.sequenceReturnType}.class); } protected RESULT doSelectNextVal(Class resultType) { return delegateSelectNextVal(resultType); } #end @Override protected Number doReadNextVal() { #if ($table.isUseSequence()) return selectNextVal(); #else String msg = "This table is NOT related to sequence: " + getTableDbName(); throw new UnsupportedOperationException(msg); #end } #if (${table.hasPrimaryKey()} && $table.hasReferrerAsMany()) // =================================================================================== // Load Referrer // ============= #foreach ($referrer in $table.referrerList) #set ($referrerEntityClassName = "${referrer.referrerTableExtendedEntityClassName}") #set ($referrerBhvClassName = "${referrer.referrerTableExtendedBehaviorClassName}") #set ($referrerCBClassName = "${referrer.referrerTableExtendedConditionBeanClassName}") #set ($referrerEntityLongClassName = "${glPackageExtendedEntity}.${referrerEntityClassName}") #set ($genericPKMyEntityMap = "${table.getPrimaryKeyJavaNativeAsOne()}, ${myExtendedObjectClassName}") #set ($genericPKChildListMap = "${table.getPrimaryKeyJavaNativeAsOne()}, List<${referrerEntityClassName}>") #if (!$referrer.isOneToOne()) /** * {Refer to overload method that has an argument of the list of entity.} * @param ${myEntityVariableName} The entity of ${table.javaBeansRulePropertyName}. (NotNull) * @param conditionBeanSetupper The instance of referrer condition-bean set-upper for registering referrer condition. (NotNull) */ public void load${referrer.referrerJavaBeansRulePropertyNameInitCap}(${myExtendedObjectClassName} ${myEntityVariableName}, ConditionBeanSetupper<${referrerCBClassName}> conditionBeanSetupper) { xassLRArg(${myEntityVariableName}, conditionBeanSetupper); load${referrer.referrerJavaBeansRulePropertyNameInitCap}(xnewLRLs(${myEntityVariableName}), conditionBeanSetupper); } /** * Load referrer of ${referrer.referrerJavaBeansRulePropertyName} with the set-upper for condition-bean of referrer. *
     * ${myEntityVariableName}Bhv.load${referrer.referrerJavaBeansRulePropertyNameInitCap}(${myEntityListVariableName}, new ConditionBeanSetupper<${referrerCBClassName}>() {
     *     public void setup(${referrerCBClassName} cb) {
     *         cb.setupSelect...();
     *         cb.query().setFoo...(value);
     *         cb.query().addOrderBy_Bar...(); // basically you should order referrer list
     *     }
     * });
     * for (${myExtendedObjectClassName} ${myEntityVariableName} : ${myEntityListVariableName}) {
     *     ... = ${myEntityVariableName}.get${referrer.referrerJavaBeansRulePropertyNameInitCap}();
     * }
     * 
* About internal policy, the value of primary key(and others too) is treated as case-insensitive.
* The condition-bean that the set-upper provides have settings before you touch it. It is as follows: *
#if ($referrer.isSimpleKeyFK())
     * cb.query().set${referrer.getLocalColumnJavaNameAsOne()}_InScope(pkList);
     * cb.query().addOrderBy_${referrer.getLocalColumnJavaNameAsOne()}_Asc();
#else
     * cb.query().set[ForeignKey]_InScope(pkList);
     * cb.query().addOrderBy_[ForeignKey]_Asc();
#end
     * 
* @param ${myEntityListVariableName} The entity list of ${table.javaBeansRulePropertyName}. (NotNull) * @param conditionBeanSetupper The instance of referrer condition-bean set-upper for registering referrer condition. (NotNull) */ public void load${referrer.referrerJavaBeansRulePropertyNameInitCap}(List<${myExtendedObjectClassName}> ${myEntityListVariableName}, ConditionBeanSetupper<${referrerCBClassName}> conditionBeanSetupper) { xassLRArg(${myEntityListVariableName}, conditionBeanSetupper); load${referrer.referrerJavaBeansRulePropertyNameInitCap}(${myEntityListVariableName}, new LoadReferrerOption<${referrerCBClassName}, ${referrerEntityClassName}>().xinit(conditionBeanSetupper)); } /** * {Refer to overload method that has an argument of the list of entity.} * @param ${myEntityVariableName} The entity of ${table.javaBeansRulePropertyName}. (NotNull) * @param loadReferrerOption The option of load-referrer. (NotNull) */ public void load${referrer.referrerJavaBeansRulePropertyNameInitCap}(${myExtendedObjectClassName} ${myEntityVariableName}, LoadReferrerOption<${referrerCBClassName}, ${referrerEntityClassName}> loadReferrerOption) { xassLRArg(${myEntityVariableName}, loadReferrerOption); load${referrer.referrerJavaBeansRulePropertyNameInitCap}(xnewLRLs(${myEntityVariableName}), loadReferrerOption); } #if ($referrer.isSimpleKeyFK()) #set ($referrerColumn = ${referrer.localColumnAsOne}) #set ($localColumn = ${referrer.foreignColumnAsOne}) #set ($keyJavaNative = "${referrerColumn.javaNative}") /** * {Refer to overload method that has an argument of condition-bean setupper.} * @param ${myEntityListVariableName} The entity list of ${table.javaBeansRulePropertyName}. (NotNull) * @param loadReferrerOption The option of load-referrer. (NotNull) */ public void load${referrer.referrerJavaBeansRulePropertyNameInitCap}(List<${myExtendedObjectClassName}> ${myEntityListVariableName}, LoadReferrerOption<${referrerCBClassName}, ${referrerEntityClassName}> loadReferrerOption) { xassLRArg(${myEntityListVariableName}, loadReferrerOption); if (${myEntityListVariableName}.isEmpty()) { return; } final ${referrerBhvClassName} referrerBhv = xgetBSFLR().select(${referrerBhvClassName}.class); helpLoadReferrerInternally(${myEntityListVariableName}, loadReferrerOption, new InternalLoadReferrerCallback<${myExtendedObjectClassName}, ${keyJavaNative}, ${referrerCBClassName}, ${referrerEntityClassName}>() { public ${keyJavaNative} getPKVal(${myExtendedObjectClassName} e) { return e.get${localColumn.javaName}(); } public void setRfLs(${myExtendedObjectClassName} e, List<${referrerEntityClassName}> ls) { e.set${referrer.referrerPropertyNameInitCap}(ls); } public ${referrerCBClassName} newMyCB() { return referrerBhv.newMyConditionBean(); } public void qyFKIn(${referrerCBClassName} cb, List<${keyJavaNative}> ls) { cb.query().set${referrerColumn.javaName}_InScope(ls); } public void qyOdFKAsc(${referrerCBClassName} cb) { cb.query().addOrderBy_${referrerColumn.javaName}_Asc(); } public void spFKCol(${referrerCBClassName} cb) { cb.specify().column${referrerColumn.javaName}(); } public List<${referrerEntityClassName}> selRfLs(${referrerCBClassName} cb) { return referrerBhv.selectList(cb); } public ${keyJavaNative} getFKVal(${referrerEntityClassName} e) { return e.get${referrerColumn.javaName}(); } public void setlcEt(${referrerEntityClassName} re, ${myExtendedObjectClassName} le) { re.set${referrer.foreignPropertyNameInitCap}(le); } }); } #else #set ($keyJavaNative = "java.util.Map") /** * {Refer to overload method that has an argument of condition-bean setupper.} * @param ${myEntityListVariableName} The entity list of ${table.javaBeansRulePropertyName}. (NotNull) * @param loadReferrerOption The option of load-referrer. (NotNull) */ public void load${referrer.referrerJavaBeansRulePropertyNameInitCap}(List<${myExtendedObjectClassName}> ${myEntityListVariableName}, LoadReferrerOption<${referrerCBClassName}, ${referrerEntityClassName}> loadReferrerOption) { xassLRArg(${myEntityListVariableName}, loadReferrerOption); if (${myEntityListVariableName}.isEmpty()) { return; } final ${referrerBhvClassName} referrerBhv = xgetBSFLR().select(${referrerBhvClassName}.class); helpLoadReferrerInternally(${myEntityListVariableName}, loadReferrerOption, new InternalLoadReferrerCallback<${myExtendedObjectClassName}, ${keyJavaNative}, ${referrerCBClassName}, ${referrerEntityClassName}>() { public ${keyJavaNative} getPKVal(${myExtendedObjectClassName} e) { ${keyJavaNative} primaryKeyMap = new java.util.LinkedHashMap(); #foreach ($col in $referrer.foreignColumnList) primaryKeyMap.put("${col.javaName}", e.get${col.javaName}()); #end return primaryKeyMap; } public void setRfLs(${myExtendedObjectClassName} e, List<${referrerEntityClassName}> ls) { e.set${referrer.referrerPropertyNameInitCap}(ls); } public ${referrerCBClassName} newMyCB() { return referrerBhv.newMyConditionBean(); } public void qyFKIn(${referrerCBClassName} cb, List<${keyJavaNative}> ls) { final String aliasName = cb.getSqlClause().getBasePointAliasName(); String identity = null; StringBuilder sb = new StringBuilder(); int index = 0; for (${keyJavaNative} primaryKeyMap : ls) { if (sb.length() > 0) { sb.append(")").append(ln()).append(" or ("); } #set ($referrerColumnIndex = 0) #foreach ($localColumn in $referrer.foreignColumnList) #set ($referrerColumn = $referrer.getLocalColumnByForeignColumn($localColumn)) #if ($referrerColumnIndex > 0) sb.append(" and "); #end sb.append(aliasName).append(".${referrerColumn.name} = "); identity = "${referrer.referrerJavaBeansRulePropertyName}${localColumn.javaName}" + index; sb.append("/*pmb.freeParameterMap.").append(identity).append("*/null"); cb.xregisterFreeParameter(identity, primaryKeyMap.get("${localColumn.javaName}")); #set ($referrerColumnIndex = $referrerColumnIndex + 1) #end ++index; } sb.insert(0, "((").append("))"); cb.getSqlClause().registerWhereClause(sb.toString()); } public void qyOdFKAsc(${referrerCBClassName} cb) { #foreach ($col in $referrer.localColumnList) cb.query().addOrderBy_${col.javaName}_Asc(); #end } public void spFKCol(${referrerCBClassName} cb) { #foreach ($col in $referrer.localColumnList) cb.specify().column${col.javaName}(); #end } public List<${referrerEntityClassName}> selRfLs(${referrerCBClassName} cb) { return referrerBhv.selectList(cb); } public ${keyJavaNative} getFKVal(${referrerEntityClassName} e) { ${keyJavaNative} foreignKeyMap = new java.util.LinkedHashMap(); #foreach ($col in $referrer.localColumnList) #set ($foreignColumn = $referrer.getForeignColumnByLocalColumn($col)) foreignKeyMap.put("${foreignColumn.javaName}", e.get${col.javaName}()); #end return foreignKeyMap; } public void setlcEt(${referrerEntityClassName} re, ${myExtendedObjectClassName} le) { re.set${referrer.foreignPropertyNameInitCap}(le); } }); } #end #end #end #end #if ($table.isBuriTarget() && $database.hasBuriAllRoundStateHistory()) #foreach ($processName in $table.tableProcessForMethodNameList) #set ($referrerEntityClassName = "${glProjectPrefix}BuriAllRoundStateHistory") #set ($referrerBhvClassName = "${glPackageExtendedBhv}.${glProjectPrefix}BuriAllRoundStateHistoryBhv") #set ($referrerCBClassName = "${glProjectPrefix}BuriAllRoundStateHistoryCB") #set ($referrerEntityLongClassName = "${glPackageExtendedEntity}.${referrerEntityClassName}") #set ($genericPKMyEntityMap = "${table.getPrimaryKeyJavaNativeAsOne()}, ${myExtendedObjectClassName}") #set ($genericPKChildListMap = "${table.getPrimaryKeyJavaNativeAsOne()}, List<${referrerEntityClassName}>") public void loadBuriAllRoundStateHistory_${processName}List(${myExtendedObjectClassName} ${myEntityVariableName}, org.seasar.dbflute.bhv.ConditionBeanSetupper<${referrerCBClassName}> conditionBeanSetupper) { xassLRArg(${myEntityVariableName}, conditionBeanSetupper); loadBuriAllRoundStateHistory_${processName}List(xnewLRLs(${myEntityVariableName}), conditionBeanSetupper); } public void loadBuriAllRoundStateHistory_${processName}List(List<${myExtendedObjectClassName}> ${myEntityListVariableName}, org.seasar.dbflute.bhv.ConditionBeanSetupper<${referrerCBClassName}> conditionBeanSetupper) { xassLRArg(${myEntityListVariableName}, conditionBeanSetupper); loadBuriAllRoundStateHistory_${processName}List(${myEntityListVariableName}, new org.seasar.dbflute.bhv.LoadReferrerOption<${referrerCBClassName}, ${referrerEntityClassName}>().xinit(conditionBeanSetupper)); } public void loadBuriAllRoundStateHistory_${processName}List(${myExtendedObjectClassName} ${myEntityVariableName}, org.seasar.dbflute.bhv.LoadReferrerOption<${referrerCBClassName}, ${referrerEntityClassName}> loadReferrerOption) { xassLRArg(${myEntityVariableName}, loadReferrerOption); loadBuriAllRoundStateHistory_${processName}List(xnewLRLs(${myEntityVariableName}), loadReferrerOption); } public void loadBuriAllRoundStateHistory_${processName}List(List<${myExtendedObjectClassName}> ${myEntityListVariableName}, org.seasar.dbflute.bhv.LoadReferrerOption<${referrerCBClassName}, ${referrerEntityClassName}> loadReferrerOption) { xassLRArg(${myEntityListVariableName}, loadReferrerOption); if (${myEntityListVariableName}.isEmpty()) { return; } final ${referrerBhvClassName} referrerBhv = xgetBSFLR().select(${referrerBhvClassName}.class); helpLoadReferrerInternally(${myEntityListVariableName}, loadReferrerOption, new InternalLoadReferrerCallback<${myExtendedObjectClassName}, ${table.getPrimaryKeyJavaNativeAsOne()}, ${referrerCBClassName}, ${referrerEntityClassName}>() { public ${table.getPrimaryKeyJavaNativeAsOne()} getPKVal(${myExtendedObjectClassName} entity) { return entity.get${table.getPrimaryKeyJavaNameAsOne()}(); } public void setRfLs(${myExtendedObjectClassName} entity, List<${referrerEntityClassName}> referrerList) { entity.setBuriAllRoundStateHistory_${processName}List(referrerList); } public ${referrerCBClassName} newMyCB() { return referrerBhv.newMyConditionBean(); } public void qyFKIn(${referrerCBClassName} cb, List<${table.getPrimaryKeyJavaNativeAsOne()}> pkList) { java.util.List internalPkValueList = new java.util.ArrayList(); for (${table.getPrimaryKeyJavaNativeAsOne()} pk : pkList) { internalPkValueList.add(Long.valueOf(pk.toString())); } cb.query().setInternalPkValue_InScope(internalPkValueList); cb.query().setInternalDataType_Equal("${glPackageExtendedEntity}.${myExtendedObjectClassName}"); // is a fixed condition! } public void qyOdFKAsc(${referrerCBClassName} cb) { cb.query().addOrderBy_InternalPkValue_Asc(); } public void spFKCol(${referrerCBClassName} cb) { cb.specify().columnInternalPkValue(); } public List<${referrerEntityClassName}> selRfLs(${referrerCBClassName} cb) { return referrerBhv.selectList(cb); } public ${table.getPrimaryKeyJavaNativeAsOne()} getFKVal(${referrerEntityClassName} entity) { return ${table.getPrimaryKeyJavaNativeAsOne()}.valueOf(entity.getInternalPkValue().toString()); } public void setlcEt(${referrerEntityClassName} referrerEntity, ${myExtendedObjectClassName} localEntity) { referrerEntity.set${table.javaName}_${processName}(localEntity); } }); } #end #end // =================================================================================== // Pull out Foreign // ================ #foreach ($foreignKey in $table.foreignKeys) #set ($foreignEntityClassName = "${foreignKey.foreignTableExtendedEntityClassName}") /** * Pull out the list of foreign table '${foreignEntityClassName}'. * @param ${myEntityListVariableName} The list of ${table.uncapitalisedJavaName}. (NotNull) * @return The list of foreign table. (NotNull) */ public List<${foreignEntityClassName}> pullout${foreignKey.foreignPropertyNameInitCap}(List<${myExtendedObjectClassName}> ${myEntityListVariableName}) { return helpPulloutInternally(${myEntityListVariableName}, new InternalPulloutCallback<${myExtendedObjectClassName}, ${foreignEntityClassName}>() { public ${foreignEntityClassName} getFr(${myExtendedObjectClassName} e) { return e.get${foreignKey.foreignPropertyNameInitCap}(); } public boolean hasRf() { return ${foreignKey.canBeReferrer()}; } #if ($foreignKey.canBeReferrer()) #if ($foreignKey.isOneToOne()) public void setRfLs(${foreignEntityClassName} e, List<${myExtendedObjectClassName}> ls) { if (!ls.isEmpty()) { e.set${foreignKey.referrerPropertyNameInitCapAsOne}(ls.get(0)); } } #else public void setRfLs(${foreignEntityClassName} e, List<${myExtendedObjectClassName}> ls) { e.set${foreignKey.referrerPropertyNameInitCap}(ls); } #end #else public void setRfLs(${foreignEntityClassName} e, List<${myExtendedObjectClassName}> ls) { throw new UnsupportedOperationException(); } #end }); } #end #foreach ($referrer in $table.referrerAsOneList) #set ($referrerTable = $referrer.table) #set ($referrerEntityClassName = "${glProjectPrefix}${referrerTable.javaName}") /** * Pull out the list of referrer-as-one table '${referrerEntityClassName}'. * @param ${myEntityListVariableName} The list of ${table.uncapitalisedJavaName}. (NotNull) * @return The list of referrer-as-one table. (NotNull) */ public List<${referrerEntityClassName}> pullout${referrer.referrerPropertyNameInitCapAsOne}(List<${myExtendedObjectClassName}> ${myEntityListVariableName}) { return helpPulloutInternally(${myEntityListVariableName}, new InternalPulloutCallback<${myExtendedObjectClassName}, ${referrerEntityClassName}>() { public ${referrerEntityClassName} getFr(${myExtendedObjectClassName} e) { return e.get${referrer.referrerPropertyNameInitCapAsOne}(); } public boolean hasRf() { return ${referrer.canBeReferrer()}; } public void setRfLs(${referrerEntityClassName} e, List<${myExtendedObjectClassName}> ls) { if (!ls.isEmpty()) { e.set${referrer.foreignPropertyNameInitCap}(ls.get(0)); } } }); } #end #if ($table.isWritable()) // =================================================================================== // Entity Update // ============= /** * Insert the entity. *
     * ${myExtendedObjectClassName} ${myEntityVariableName} = new ${myExtendedObjectClassName}();
     * // if auto-increment, you don't need to set the PK value
     * ${myEntityVariableName}.setFoo...(value);
     * ${myEntityVariableName}.setBar...(value);
     * ${myEntityVariableName}Bhv.insert(${myEntityVariableName});
     * ... = ${myEntityVariableName}.getPK...(); // if auto-increment, you can get the value after
     * 
* @param ${myEntityVariableName} The entity of insert target. (NotNull) * @exception org.seasar.dbflute.exception.EntityAlreadyExistsException When the entity already exists. (Unique Constraint Violation) */ public void insert(${myExtendedObjectClassName} ${myEntityVariableName}) { assertEntityNotNull(${myEntityVariableName}); delegateInsert(${myEntityVariableName}); } @Override protected void doCreate(Entity entity) { insert(downcast(entity)); } /** * Update the entity modified-only. {UpdateCountZeroException, ExclusiveControl} *
     * ${myExtendedObjectClassName} ${myEntityVariableName} = new ${myExtendedObjectClassName}();
     * ${myEntityVariableName}.setPK...(value); // required
     * ${myEntityVariableName}.setFoo...(value); // you should set only modified columns
     * // if exclusive control, the value of exclusive control column is required
     * ${myEntityVariableName}.setVersionNo(value);
     * try {
     *     ${myEntityVariableName}Bhv.update(${myEntityVariableName});
     * } catch (EntityAlreadyUpdatedException e) { // if concurrent update
     *     ...
     * } 
     * 
* @param ${myEntityVariableName} The entity of update target. (NotNull) {PrimaryKeyRequired, ConcurrencyColumnRequired} #if ($table.hasOptimisticLock()) * @exception org.seasar.dbflute.exception.EntityAlreadyUpdatedException When the entity has already been updated. #else * @exception org.seasar.dbflute.exception.EntityAlreadyDeletedException When the entity has already been deleted. #end * @exception org.seasar.dbflute.exception.EntityDuplicatedException When the entity has been duplicated. * @exception org.seasar.dbflute.exception.EntityAlreadyExistsException When the entity already exists. (Unique Constraint Violation) */ public void update(final ${myExtendedObjectClassName} ${myEntityVariableName}) { helpUpdateInternally(${myEntityVariableName}, new InternalUpdateCallback<${myExtendedObjectClassName}>() { public int callbackDelegateUpdate(${myExtendedObjectClassName} entity) { return delegateUpdate(entity); } }); } @Override protected void doModify(Entity entity) { update(downcast(entity)); } #if ($table.hasOptimisticLock()) /** * Update the entity non-strictly modified-only. {UpdateCountZeroException, NonExclusiveControl} *
     * ${myExtendedObjectClassName} ${myEntityVariableName} = new ${myExtendedObjectClassName}();
     * ${myEntityVariableName}.setPK...(value); // required
     * ${myEntityVariableName}.setFoo...(value); // you should set only modified columns
     * // you don't need to set the value of exclusive control column
     * // (auto-increment for version number is valid though non-exclusive control)
     * //${myEntityVariableName}.setVersionNo(value);
     * ${myEntityVariableName}Bhv.updateNonstrict(${myEntityVariableName});
     * 
* @param ${myEntityVariableName} The entity of update target. (NotNull) {PrimaryKeyRequired} * @exception org.seasar.dbflute.exception.EntityAlreadyDeletedException When the entity has already been deleted. * @exception org.seasar.dbflute.exception.EntityDuplicatedException When the entity has been duplicated. * @exception org.seasar.dbflute.exception.EntityAlreadyExistsException When the entity already exists. (Unique Constraint Violation) */ public void updateNonstrict(final ${myExtendedObjectClassName} ${myEntityVariableName}) { helpUpdateNonstrictInternally(${myEntityVariableName}, new InternalUpdateNonstrictCallback<${myExtendedObjectClassName}>() { public int callbackDelegateUpdateNonstrict(${myExtendedObjectClassName} entity) { return delegateUpdateNonstrict(entity); } }); } #end @Override protected void doModifyNonstrict(Entity entity) { #if ($table.hasOptimisticLock()) updateNonstrict(downcast(entity)); #else update(downcast(entity)); #end } /** * Insert or update the entity modified-only. {ExclusiveControl(when update)} * @param ${myEntityVariableName} The entity of insert or update target. (NotNull) #if ($table.hasOptimisticLock()) * @exception org.seasar.dbflute.exception.EntityAlreadyUpdatedException When the entity has already been updated. #else * @exception org.seasar.dbflute.exception.EntityAlreadyDeletedException When the entity has already been deleted. #end * @exception org.seasar.dbflute.exception.EntityDuplicatedException When the entity has been duplicated. * @exception org.seasar.dbflute.exception.EntityAlreadyExistsException When the entity already exists. (Unique Constraint Violation) */ public void insertOrUpdate(final ${myExtendedObjectClassName} ${myEntityVariableName}) { helpInsertOrUpdateInternally(${myEntityVariableName}, new InternalInsertOrUpdateCallback<${myExtendedObjectClassName}, ${myConditionBeanClassName}>() { public void callbackInsert(${myExtendedObjectClassName} entity) { insert(entity); } public void callbackUpdate(${myExtendedObjectClassName} entity) { update(entity); } public ${myConditionBeanClassName} callbackNewMyConditionBean() { return newMyConditionBean(); } public int callbackSelectCount(${myConditionBeanClassName} cb) { return selectCount(cb); } }); } @Override protected void doCreateOrUpdate(Entity entity) { insertOrUpdate(downcast(entity)); } #if ($table.hasOptimisticLock()) /** * Insert or update the entity non-strictly modified-only. {NonExclusiveControl(when update)} * @param ${myEntityVariableName} The entity of insert or update target. (NotNull) * @exception org.seasar.dbflute.exception.EntityAlreadyDeletedException When the entity has already been deleted. * @exception org.seasar.dbflute.exception.EntityDuplicatedException When the entity has been duplicated. * @exception org.seasar.dbflute.exception.EntityAlreadyExistsException When the entity already exists. (Unique Constraint Violation) */ public void insertOrUpdateNonstrict(${myExtendedObjectClassName} ${myEntityVariableName}) { helpInsertOrUpdateInternally(${myEntityVariableName}, new InternalInsertOrUpdateNonstrictCallback<${myExtendedObjectClassName}>() { public void callbackInsert(${myExtendedObjectClassName} entity) { insert(entity); } public void callbackUpdateNonstrict(${myExtendedObjectClassName} entity) { updateNonstrict(entity); } }); } #end @Override protected void doCreateOrUpdateNonstrict(Entity entity) { #if ($table.isUseUpdateDate() || $table.isUseVersionNo()) insertOrUpdateNonstrict(downcast(entity)); #else insertOrUpdate(downcast(entity)); #end } /** * Delete the entity. {UpdateCountZeroException, ExclusiveControl} *
     * ${myExtendedObjectClassName} ${myEntityVariableName} = new ${myExtendedObjectClassName}();
     * ${myEntityVariableName}.setPK...(value); // required
     * // if exclusive control, the value of exclusive control column is required
     * ${myEntityVariableName}.setVersionNo(value);
     * try {
     *     ${myEntityVariableName}Bhv.delete(${myEntityVariableName});
     * } catch (EntityAlreadyUpdatedException e) { // if concurrent update
     *     ...
     * } 
     * 
* @param ${myEntityVariableName} The entity of delete target. (NotNull) {PrimaryKeyRequired, ConcurrencyColumnRequired} #if ($table.hasOptimisticLock()) * @exception org.seasar.dbflute.exception.EntityAlreadyUpdatedException When the entity has already been updated. #else * @exception org.seasar.dbflute.exception.EntityAlreadyDeletedException When the entity has already been deleted. #end * @exception org.seasar.dbflute.exception.EntityDuplicatedException When the entity has been duplicated. */ public void delete(${myExtendedObjectClassName} ${myEntityVariableName}) { helpDeleteInternally(${myEntityVariableName}, new InternalDeleteCallback<${myExtendedObjectClassName}>() { public int callbackDelegateDelete(${myExtendedObjectClassName} entity) { return delegateDelete(entity); } }); } @Override protected void doRemove(Entity entity) { delete(downcast(entity)); } #if ($table.hasOptimisticLock()) /** * Delete the entity non-strictly. {UpdateCountZeroException, NonExclusiveControl} *
     * ${myExtendedObjectClassName} ${myEntityVariableName} = new ${myExtendedObjectClassName}();
     * ${myEntityVariableName}.setPK...(value); // required
     * // you don't need to set the value of exclusive control column
     * // (auto-increment for version number is valid though non-exclusive control)
     * //${myEntityVariableName}.setVersionNo(value);
     * ${myEntityVariableName}Bhv.deleteNonstrict(${myEntityVariableName});
     * 
* @param ${myEntityVariableName} Entity. (NotNull) {PrimaryKeyRequired} * @exception org.seasar.dbflute.exception.EntityAlreadyDeletedException When the entity has already been deleted. * @exception org.seasar.dbflute.exception.EntityDuplicatedException When the entity has been duplicated. */ public void deleteNonstrict(${myExtendedObjectClassName} ${myEntityVariableName}) { helpDeleteNonstrictInternally(${myEntityVariableName}, new InternalDeleteNonstrictCallback<${myExtendedObjectClassName}>() { public int callbackDelegateDeleteNonstrict(${myExtendedObjectClassName} entity) { return delegateDeleteNonstrict(entity); } }); } /** * Delete the entity non-strictly ignoring deleted. {UpdateCountZeroException, NonExclusiveControl} *
     * ${myExtendedObjectClassName} ${myEntityVariableName} = new ${myExtendedObjectClassName}();
     * ${myEntityVariableName}.setPK...(value); // required
     * // you don't need to set the value of exclusive control column
     * // (auto-increment for version number is valid though non-exclusive control)
     * //${myEntityVariableName}.setVersionNo(value);
     * ${myEntityVariableName}Bhv.deleteNonstrictIgnoreDeleted(${myEntityVariableName});
     * // if the target entity doesn't exist, no exception
     * 
* @param ${myEntityVariableName} Entity. (NotNull) {PrimaryKeyRequired} * @exception org.seasar.dbflute.exception.EntityDuplicatedException When the entity has been duplicated. */ public void deleteNonstrictIgnoreDeleted(${myExtendedObjectClassName} ${myEntityVariableName}) { helpDeleteNonstrictIgnoreDeletedInternally(${myEntityVariableName}, new InternalDeleteNonstrictIgnoreDeletedCallback<${myExtendedObjectClassName}>() { public int callbackDelegateDeleteNonstrict(${myExtendedObjectClassName} entity) { return delegateDeleteNonstrict(entity); } }); } #end // =================================================================================== // Batch Update // ============ /** * Batch-insert the list. This method uses 'Batch Update' of java.sql.PreparedStatement. * @param ${myEntityListVariableName} The list of the entity. (NotNull) * @return The array of inserted count. */ public int[] batchInsert(List<${myExtendedObjectClassName}> ${myEntityListVariableName}) { assertObjectNotNull("${myEntityListVariableName}", ${myEntityListVariableName}); return delegateInsertList(${myEntityListVariableName}); } /** * Batch-update the list.
* All columns are update target. {NOT modified only}
* This method uses 'Batch Update' of java.sql.PreparedStatement. * @param ${myEntityListVariableName} The list of the entity. (NotNull) * @return The array of updated count. #if ($table.hasOptimisticLock()) * @exception org.seasar.dbflute.exception.BatchEntityAlreadyUpdatedException When the entity has already been updated. This exception extends EntityAlreadyUpdatedException. #else * @exception org.seasar.dbflute.exception.EntityAlreadyDeletedException When the entity has already been deleted. #end */ public int[] batchUpdate(List<${myExtendedObjectClassName}> ${myEntityListVariableName}) { assertObjectNotNull("${myEntityListVariableName}", ${myEntityListVariableName}); return delegateUpdateList(${myEntityListVariableName}); } #if ($table.hasOptimisticLock()) /** * Batch-update the list non-strictly.
* All columns are update target. {NOT modified only}
* This method uses 'Batch Update' of java.sql.PreparedStatement. * @param ${myEntityListVariableName} The list of the entity. (NotNull) * @return The array of updated count. * @exception org.seasar.dbflute.exception.EntityAlreadyDeletedException When the entity has already been deleted. */ public int[] batchUpdateNonstrict(List<${myExtendedObjectClassName}> ${myEntityListVariableName}) { assertObjectNotNull("${myEntityListVariableName}", ${myEntityListVariableName}); return delegateUpdateListNonstrict(${myEntityListVariableName}); } #end /** * Batch-delete the list.
* This method uses 'Batch Update' of java.sql.PreparedStatement. * @param ${myEntityListVariableName} The list of the entity. (NotNull) * @return The array of deleted count. #if ($table.hasOptimisticLock()) * @exception org.seasar.dbflute.exception.BatchEntityAlreadyUpdatedException When the entity has already been updated. This exception extends EntityAlreadyUpdatedException. #else * @exception org.seasar.dbflute.exception.EntityAlreadyDeletedException When the entity has already been deleted. #end */ public int[] batchDelete(List<${myExtendedObjectClassName}> ${myEntityListVariableName}) { assertObjectNotNull("${myEntityListVariableName}", ${myEntityListVariableName}); return delegateDeleteList(${myEntityListVariableName}); } #if ($table.hasOptimisticLock()) /** * Batch-delete the list non-strictly.
* This method uses 'Batch Update' of java.sql.PreparedStatement. * @param ${myEntityListVariableName} The list of the entity. (NotNull) * @return The array of deleted count. * @exception org.seasar.dbflute.exception.EntityAlreadyDeletedException When the entity has already been deleted. */ public int[] batchDeleteNonstrict(List<${myExtendedObjectClassName}> ${myEntityListVariableName}) { assertObjectNotNull("${myEntityListVariableName}", ${myEntityListVariableName}); return delegateDeleteListNonstrict(${myEntityListVariableName}); } #end // =================================================================================== // Query Update // ============ /** * Query-update the several entities non-strictly modified-only. {NonExclusiveControl} *
     * ${myExtendedObjectClassName} ${myEntityVariableName} = new ${myExtendedObjectClassName}();
     * // you don't need to set PK value
     * //${myEntityVariableName}.setPK...(value);
     * ${myEntityVariableName}.setFoo...(value); // you should set only modified columns
     * // you don't need to set the value of exclusive control column
     * // (auto-increment for version number is valid though non-exclusive control)
     * //${myEntityVariableName}.setVersionNo(value);
     * ${myConditionBeanClassName} cb = new ${myConditionBeanClassName}();
     * cb.query().setFoo...(value);
     * ${myEntityVariableName}Bhv.queryUpdate(${myEntityVariableName}, cb);
     * 
* @param ${myEntityVariableName} The entity that contains update values. (NotNull) {PrimaryKeyNotRequired} * @param cb The condition-bean of ${myExtendedObjectClassName}. (NotNull) * @return The updated count. */ public int queryUpdate(${myExtendedObjectClassName} ${myEntityVariableName}, ${myConditionBeanClassName} cb) { return delegateQueryUpdate(${myEntityVariableName}, cb); } /** * Query-delete the several entities. {NonExclusiveControl} *
     * ${myConditionBeanClassName} cb = new ${myConditionBeanClassName}();
     * cb.query().setFoo...(value);
     * ${myEntityVariableName}Bhv.queryDelete(${myEntityVariableName}, cb);
     * 
* @param cb The condition-bean of ${myExtendedObjectClassName}. (NotNull) * @return The deleted count. */ public int queryDelete(${myConditionBeanClassName} cb) { return delegateQueryDelete(cb); } /** * Varying-update the entity modified-only. {UpdateCountZeroException, ExclusiveControl} *
     * ${myExtendedObjectClassName} ${myEntityVariableName} = new ${myExtendedObjectClassName}();
     * ${myEntityVariableName}.setPK...(value); // required
     * ${myEntityVariableName}.setOther...(value); // you should set only modified columns
     * // if exclusive control, the value of exclusive control column is required
     * ${myEntityVariableName}.setVersionNo(value);
     * try {
     *     UpdateOption<${myConditionBeanClassName}> option = new UpdateOption<${myConditionBeanClassName}>();
     *     option.self(new SpecifyQuery<${myConditionBeanClassName}>() {
     *         public void specify(${myConditionBeanClassName} cb) {
     *             cb.specify().columnXxxCount();
     *         }
     *     }).plus(1); // XXX_COUNT = XXX_COUNT + 1
     *     ${myEntityVariableName}Bhv.varyingUpdate(${myEntityVariableName}, option);
     * } catch (EntityAlreadyUpdatedException e) { // if concurrent update
     *     ...
     * }
     * 
* @param ${myEntityVariableName} The entity of update target. (NotNull) {PrimaryKeyRequired, ConcurrencyColumnRequired} * @param option The option of update for varying values. (NotNull) #if ($table.hasOptimisticLock()) * @exception org.seasar.dbflute.exception.EntityAlreadyUpdatedException When the entity has already been updated. #else * @exception org.seasar.dbflute.exception.EntityAlreadyDeletedException When the entity has already been deleted. #end * @exception org.seasar.dbflute.exception.EntityDuplicatedException When the entity has been duplicated. * @exception org.seasar.dbflute.exception.EntityAlreadyExistsException When the entity already exists. (Unique Constraint Violation) */ public void varyingUpdate(${myExtendedObjectClassName} ${myEntityVariableName}, final UpdateOption<${myConditionBeanClassName}> option) { processVaryingUpdate(option); helpUpdateInternally(${myEntityVariableName}, new InternalUpdateCallback<${myExtendedObjectClassName}>() { public int callbackDelegateUpdate(${myExtendedObjectClassName} entity) { return delegateVaryingUpdate(entity, option); } }); } #if ($table.hasOptimisticLock()) /** * Varying-update the entity non-strictly modified-only. {UpdateCountZeroException, NonExclusiveControl} *
     * ${myExtendedObjectClassName} ${myEntityVariableName} = new ${myExtendedObjectClassName}();
     * ${myEntityVariableName}.setPK...(value); // required
     * ${myEntityVariableName}.setOther...(value); // you should set only modified columns
     * // you don't need to set the value of exclusive control column
     * // (auto-increment for version number is valid though non-exclusive control)
     * //${myEntityVariableName}.setVersionNo(value);
     * UpdateOption<${myConditionBeanClassName}> option = new UpdateOption<${myConditionBeanClassName}>();
     * option.self(new SpecifyQuery<${myConditionBeanClassName}>() {
     *     public void specify(${myConditionBeanClassName} cb) {
     *         cb.specify().columnFooCount();
     *     }
     * }).plus(1); // FOO_COUNT = FOO_COUNT + 1
     * ${myEntityVariableName}Bhv.varyingUpdateNonstrict(${myEntityVariableName}, option);
     * 
* @param ${myEntityVariableName} The entity of update target. (NotNull) {PrimaryKeyRequired} * @param option The option of update for varying values. (NotNull) * @exception org.seasar.dbflute.exception.EntityAlreadyDeletedException When the entity has already been deleted. * @exception org.seasar.dbflute.exception.EntityDuplicatedException When the entity has been duplicated. * @exception org.seasar.dbflute.exception.EntityAlreadyExistsException When the entity already exists. (Unique Constraint Violation) */ public void varyingUpdateNonstrict(${myExtendedObjectClassName} ${myEntityVariableName}, final UpdateOption<${myConditionBeanClassName}> option) { processVaryingUpdate(option); helpUpdateNonstrictInternally(${myEntityVariableName}, new InternalUpdateNonstrictCallback<${myExtendedObjectClassName}>() { public int callbackDelegateUpdateNonstrict(${myExtendedObjectClassName} entity) { return delegateVaryingUpdateNonstrict(entity, option); } }); } #end /** * Varying-query-update the several entities non-strictly modified-only. {NonExclusiveControl} *
     * ${myExtendedObjectClassName} ${myEntityVariableName} = new ${myExtendedObjectClassName}();
     * // you don't need to set PK value
     * //${myEntityVariableName}.setPK...(value);
     * ${myEntityVariableName}.setOther...(value); // you should set only modified columns
     * // you don't need to set the value of exclusive control column
     * // (auto-increment for version number is valid though non-exclusive control)
     * //${myEntityVariableName}.setVersionNo(value);
     * ${myConditionBeanClassName} cb = new ${myConditionBeanClassName}();
     * cb.query().setFoo...(value);
     * UpdateOption<${myConditionBeanClassName}> option = new UpdateOption<${myConditionBeanClassName}>();
     * option.self(new SpecifyQuery<${myConditionBeanClassName}>() {
     *     public void specify(${myConditionBeanClassName} cb) {
     *         cb.specify().columnFooCount();
     *     }
     * }).plus(1); // FOO_COUNT = FOO_COUNT + 1
     * ${myEntityVariableName}Bhv.varyingQueryUpdate(${myEntityVariableName}, cb, option);
     * 
* @param ${myEntityVariableName} The entity that contains update values. (NotNull) {PrimaryKeyNotRequired} * @param cb The condition-bean of ${myExtendedObjectClassName}. (NotNull) * @param option The option of update for varying values. (NotNull) * @return The updated count. */ public int varyingQueryUpdate(${myExtendedObjectClassName} ${myEntityVariableName}, ${myConditionBeanClassName} cb, final UpdateOption<${myConditionBeanClassName}> option) { processVaryingUpdate(option); return delegateVaryingQueryUpdate(${myEntityVariableName}, cb, option); } protected void processVaryingUpdate(UpdateOption<${myConditionBeanClassName}> option) { assertUpdateOptionNotNull(option); ${myConditionBeanClassName} cb = newMyConditionBean(); cb.xsetupForVaryingUpdate(); option.resolveSpecification(cb); } #else #if ($table.isAvailableNonPrimaryKeyWritable()) // =================================================================================== // Entity Update // ============= /** * Insert the entity. *
     * ${myExtendedObjectClassName} ${myEntityVariableName} = new ${myExtendedObjectClassName}();
     * ${myEntityVariableName}.setPK...(value);
     * ${myEntityVariableName}.setFoo...(value);
     * ${myEntityVariableName}.setBar...(value);
     * ${myEntityVariableName}Bhv.insert(${myEntityVariableName});
     * 
* @param ${myEntityVariableName} The entity for insert. (NotNull) */ public void insert(${myExtendedObjectClassName} ${myEntityVariableName}) { assertEntityNotNull(${myEntityVariableName}); delegateInsert(${myEntityVariableName}); } #end #end #if ($table.isBuriTarget()) // =================================================================================== // Buri Interface // ============== public ${myExtendedObjectClassName} xgetEntityForBuri(${table.primaryKeyArgsString}) { // For Buri ${myExtendedObjectClassName} entity = new ${myExtendedObjectClassName}(); ${table.getPrimaryKeyArgsSetupString('entity')} ${myConditionBeanClassName} cb = newMyConditionBean(); cb.acceptPrimaryKeyMap(getDBMeta().extractPrimaryKeyMap(entity)); return selectEntity(cb); } public List<${myExtendedObjectClassName}> xgetEntitiesForBuri(List<${table.primaryKeyJavaNativeAsOne}> ids) { // For Buri ${myConditionBeanClassName} cb = newMyConditionBean(); cb.query().set${table.primaryKeyAsOne.javaName}_InScope(ids); return selectList(cb); } protected org.escafe.buri.engine.processor.BuriAutoSelectProcessor _buriAutoSelectProcessor; public void setBuriAutoSelectProcessor(org.escafe.buri.engine.processor.BuriAutoSelectProcessor buriAutoSelectProcessor) { _buriAutoSelectProcessor = buriAutoSelectProcessor; } protected void toNextStatusAction(String processPath, Object entity, Object userData, String action) { try { _buriAutoSelectProcessor.toNextStatusAction(processPath, entity, userData, action); } catch (org.seasar.coffee.script.exception.ScriptExecuteException e) { if (e.getCause() instanceof ognl.MethodFailedException) { ognl.MethodFailedException fail = (ognl.MethodFailedException) e.getCause(); Throwable reason = fail.getReason(); if (reason instanceof org.seasar.dbflute.exception.EntityAlreadyExistsException) { throw (org.seasar.dbflute.exception.EntityAlreadyExistsException)reason; } else if (reason instanceof org.seasar.dbflute.exception.EntityAlreadyDeletedException) { throw (org.seasar.dbflute.exception.EntityAlreadyDeletedException)reason; } else if (reason instanceof org.seasar.dbflute.exception.EntityAlreadyUpdatedException) { throw (org.seasar.dbflute.exception.EntityAlreadyUpdatedException)reason; } } throw e; } } protected ${glBuriDef}.BuriUserDataProvider _buriUserDataProvider; public void setBuriUserDataProvider(${glBuriDef}.BuriUserDataProvider buriUserDataProvider) { _buriUserDataProvider = buriUserDataProvider; } #foreach ($processName in $table.tableProcessForMethodNameList) public void toNextStatus_${processName}(${myExtendedObjectClassName} ${myEntityVariableName}, ${glBuriDef}.${processName}_Action action) { assertEntityNotNull(${myEntityVariableName}); String processPath = ${glBuriDef}.BuriProcess.${processName}.path(); Object userData = getUserData_${processName}(${myEntityVariableName}, action); toNextStatusAction(processPath, ${myEntityVariableName}, userData, action.code()); } protected Object getUserData_${processName}(${myExtendedObjectClassName} ${myEntityVariableName}, ${glBuriDef}.${processName}_Action action) { if (_buriUserDataProvider == null) { return null; } return _buriUserDataProvider.provide(${glBuriDef}.BuriProcess.${processName}, ${myEntityVariableName}, action); } public ${glBuriDef}.${processName}_Status getStatus_${processName}(${myExtendedObjectClassName} ${myEntityVariableName}) { assertEntityNotNullAndHasPrimaryKeyValue(${myEntityVariableName}); java.util.List buriAllRoundStateList = xgetCurrentStateList(${myEntityVariableName}, ${glBuriDef}.BuriProcess.${processName}); java.util.List<${glBuriDef}.${processName}_Status> statusList = new java.util.ArrayList<${glBuriDef}.${processName}_Status>(); if (buriAllRoundStateList.isEmpty()) { return null; } for (BuriAllRoundState buriAllRoundState : buriAllRoundStateList) { ${glBuriDef}.${processName}_Status status = ${glBuriDef}.${processName}_Status.codeOf(buriAllRoundState.getStatusPathName()); if (status != null) { statusList.add(status); } } if (statusList.size() > 1) { String msg = "This method does not support duplicate status: " + statusList; throw new IllegalStateException(msg); } return !statusList.isEmpty() ? statusList.get(0) : null; } public java.util.List<${myExtendedObjectClassName}> getEntities(org.seasar.dbflute.bhv.ConditionBeanSetupper<${myConditionBeanClassName}> conditionBeanSetupper , ${glBuriDef}.${processName}_Status... statuses) { assertObjectNotNull("statuses", statuses); ${myConditionBeanClassName} cb = newMyConditionBean(); cb.setupSelect_BuriAllRoundState_${processName}(); conditionBeanSetupper.setup(cb); java.util.List pathNameList = new java.util.ArrayList(); for (${glBuriDef}.${processName}_Status status : statuses) { pathNameList.add(status.path()); } cb.query().queryBuriAllRoundState_${processName}().setStatusPathName_InScope(pathNameList); return selectList(cb); } #end private List xgetCurrentStateList(${myExtendedObjectClassName} ${myEntityVariableName}, ${glBuriDef}.BuriProcess process) { ${glPackageExtendedBhv}.BuriAllRoundStateBhv bhv = xgetBuriAllRoundStateBhv(); BuriAllRoundStateCB cb = bhv.newMyConditionBean(); cb.specify().columnStatusPathName(); cb.query().setStatusPathName_LikeSearch(process.path() + ".", new org.seasar.dbflute.cbean.coption.LikeSearchOption().likePrefix()); cb.query().setInternalPkValue_Equal(new Long(${myEntityVariableName}.${table.primaryKeyGetterCommaString})); cb.query().setInternalDataType_Equal(${myExtendedObjectClassName}.class.getName()); return bhv.selectList(cb); } private ${glPackageExtendedBhv}.BuriAllRoundStateBhv xgetBuriAllRoundStateBhv() { return getBehaviorSelector().select(${glPackageExtendedBhv}.BuriAllRoundStateBhv.class); } #end // =================================================================================== // Delegate Method // =============== // [Behavior Command] // ----------------------------------------------------- // Select // ------ protected int delegateSelectCount(${myConditionBeanClassName} cb) { return invoke(createSelectCountCBCommand(cb)); } protected void delegateSelectCursor(${myConditionBeanClassName} cb, EntityRowHandler entityRowHandler, Class entityType) { invoke(createSelectCursorCBCommand(cb, entityRowHandler, entityType)); } protected List delegateSelectList(${myConditionBeanClassName} cb, Class entityType) { return invoke(createSelectListCBCommand(cb, entityType)); } #if ($table.isUseSequence()) protected RESULT delegateSelectNextVal(Class resultType) { return invoke(createSelectNextValCommand(resultType)); } #end #if ($table.isWritable()) // ----------------------------------------------------- // Update // ------ protected int delegateInsert(${myExtendedObjectClassName} e) { if (!processBeforeInsert(e)) { return 1; } return invoke(createInsertEntityCommand(e)); } protected int delegateUpdate(${myExtendedObjectClassName} e) #if ($table.hasOptimisticLock()) { if (!processBeforeUpdate(e)) { return 1; } return invoke(createUpdateEntityCommand(e)); } #else { if (!processBeforeUpdate(e)) { return 1; } return invoke(createUpdateNonstrictEntityCommand(e)); } #end #if ($table.hasOptimisticLock()) protected int delegateUpdateNonstrict(${myExtendedObjectClassName} e) { if (!processBeforeUpdate(e)) { return 1; } return invoke(createUpdateNonstrictEntityCommand(e)); } #end protected int delegateDelete(${myExtendedObjectClassName} e) #if ($table.hasOptimisticLock()) { if (!processBeforeDelete(e)) { return 1; } return invoke(createDeleteEntityCommand(e)); } #else { if (!processBeforeDelete(e)) { return 1; } return invoke(createDeleteNonstrictEntityCommand(e)); } #end #if ($table.hasOptimisticLock()) protected int delegateDeleteNonstrict(${myExtendedObjectClassName} e) { if (!processBeforeDelete(e)) { return 1; } return invoke(createDeleteNonstrictEntityCommand(e)); } #end protected int[] delegateInsertList(List<${myExtendedObjectClassName}> ls) { if (ls.isEmpty()) { return new int[]{}; } return invoke(createBatchInsertEntityCommand(helpFilterBeforeInsertInternally(ls))); } @SuppressWarnings("unchecked") protected int[] doCreateList(List ls) { return delegateInsertList((List)ls); } protected int[] delegateUpdateList(List<${myExtendedObjectClassName}> ls) #if ($table.hasOptimisticLock()) { if (ls.isEmpty()) { return new int[]{}; } return invoke(createBatchUpdateEntityCommand(helpFilterBeforeUpdateInternally(ls))); } #else { if (ls.isEmpty()) { return new int[]{}; } return invoke(createBatchUpdateNonstrictEntityCommand(helpFilterBeforeUpdateInternally(ls))); } #end @SuppressWarnings("unchecked") protected int[] doModifyList(List ls) { return delegateUpdateList((List)ls); } #if ($table.hasOptimisticLock()) protected int[] delegateUpdateListNonstrict(List<${myExtendedObjectClassName}> ls) { if (ls.isEmpty()) { return new int[]{}; } return invoke(createBatchUpdateNonstrictEntityCommand(helpFilterBeforeUpdateInternally(ls))); } #end protected int[] delegateDeleteList(List<${myExtendedObjectClassName}> ls) #if ($table.hasOptimisticLock()) { if (ls.isEmpty()) { return new int[]{}; } return invoke(createBatchDeleteEntityCommand(helpFilterBeforeDeleteInternally(ls))); } #else { if (ls.isEmpty()) { return new int[]{}; } return invoke(createBatchDeleteNonstrictEntityCommand(helpFilterBeforeDeleteInternally(ls))); } #end @SuppressWarnings("unchecked") protected int[] doRemoveList(List ls) { return delegateDeleteList((List)ls); } #if ($table.hasOptimisticLock()) protected int[] delegateDeleteListNonstrict(List<${myExtendedObjectClassName}> ls) { if (ls.isEmpty()) { return new int[]{}; } return invoke(createBatchDeleteNonstrictEntityCommand(helpFilterBeforeDeleteInternally(ls))); } #end protected int delegateQueryUpdate(${myExtendedObjectClassName} e, ${myConditionBeanClassName} cb) { if (!processBeforeQueryUpdate(e, cb)) { return 0; } return invoke(createQueryUpdateEntityCBCommand(e, cb)); } protected int delegateQueryDelete(${myConditionBeanClassName} cb) { if (!processBeforeQueryDelete(cb)) { return 0; } return invoke(createQueryDeleteCBCommand(cb)); } protected int delegateVaryingUpdate(${myExtendedObjectClassName} e, UpdateOption<${myConditionBeanClassName}> op) #if ($table.hasOptimisticLock()) { if (!processBeforeUpdate(e)) { return 1; } return invoke(createVaryingUpdateEntityCommand(e, op)); } #else { if (!processBeforeUpdate(e)) { return 1; } return invoke(createVaryingUpdateNonstrictEntityCommand(e, op)); } #end #if ($table.hasOptimisticLock()) protected int delegateVaryingUpdateNonstrict(${myExtendedObjectClassName} e, UpdateOption<${myConditionBeanClassName}> op) { if (!processBeforeUpdate(e)) { return 1; } return invoke(createVaryingUpdateNonstrictEntityCommand(e, op)); } #end protected int delegateVaryingQueryUpdate(${myExtendedObjectClassName} e, ${myConditionBeanClassName} cb, UpdateOption<${myConditionBeanClassName}> op) { if (!processBeforeQueryUpdate(e, cb)) { return 0; } return invoke(createVaryingQueryUpdateEntityCBCommand(e, cb, op)); } #else #if ($table.isAvailableNonPrimaryKeyWritable()) protected int delegateInsert(${myExtendedObjectClassName} e) { assertEntityNotNull(e); // If this table use identity, the entity does not have primary-key. filterEntityOfInsert(e); return invoke(createInsertEntityCommand(e)); } protected InsertEntityCommand createInsertEntityCommand(Entity entity) { assertBehaviorCommandInvoker("createInsertEntityCommand"); final InsertEntityCommand cmd = new InsertEntityCommand(); cmd.setTableDbName(getTableDbName()); _behaviorCommandInvoker.injectComponentProperty(cmd); cmd.setEntityType(entity.getClass()); cmd.setEntity(entity); return cmd; } #end #end #if ($table.hasBehaviorFilterBeforeColumn()) // =================================================================================== // Filter Override // =============== #if ($table.hasBehaviorFilterBeforeInsertColumn()) @Override protected void filterEntityOfInsert(Entity targetEntity) { super.filterEntityOfInsert(targetEntity); ${myExtendedObjectClassName} entity = downcast(targetEntity); #foreach ($column in $table.behaviorFilterBeforeInsertColumnList) entity.set${column.javaName}(${column.behaviorFilterBeforeInsertColumnExpression}); #end } #end #if ($table.isWritable()) #if ($table.hasBehaviorFilterBeforeUpdateColumn()) @Override protected void filterEntityOfUpdate(Entity targetEntity) { super.filterEntityOfUpdate(targetEntity); ${myExtendedObjectClassName} entity = downcast(targetEntity); #foreach ($column in $table.behaviorFilterBeforeUpdateColumnList) entity.set${column.javaName}(${column.behaviorFilterBeforeUpdateColumnExpression}); #end } #end #end #end #if ($database.isMakeFlatExpansion()) // =================================================================================== // Hierarchy // ========= /** * Create the basic request of hierarchy of ${myExtendedObjectClassName}.. * @param sourceList The list of source. (NotNull) * @param The type of source. * @return Hierarchy request of ${myExtendedObjectClassName}. (NotNull) */ public ${glHierarchyBasicRequest}<${myExtendedObjectClassName}, ${myDBMetaClassName}.${table.relationTraceClassName}RelationTrace> createHierarchyBasicRequest(List sourceList) { final ${glHierarchyBasicRequest}<${myExtendedObjectClassName}, ${myDBMetaClassName}.${table.relationTraceClassName}RelationTrace> request = new ${glHierarchyBasicRequest}<${myExtendedObjectClassName}, ${myDBMetaClassName}.${table.relationTraceClassName}RelationTrace>(${myExtendedObjectClassName}.class); request.registerSourceList(sourceList); return request; } /** * Arrange hierarchy. * @param request Hierarchy request of ${myExtendedObjectClassName}. (NotNull) * @return The list of ${myExtendedObjectClassName}. (NotNull) */ public List<${myExtendedObjectClassName}> arrangeHierarchy(${glHierarchyRequest}<${myExtendedObjectClassName}> request) { return new ${glHierarchyArranger}<${myExtendedObjectClassName}>().arrangeHierarchy(request); } #end // =================================================================================== // Optimistic Lock Info // ==================== /** * {@inheritDoc} */ @Override protected boolean hasVersionNoValue(Entity entity) { #if ($table.isUseVersionNo()) return !(downcast(entity).get${table.versionNoJavaName}() + "").equals("null");// For primitive type #else return false; #end } /** * {@inheritDoc} */ @Override protected boolean hasUpdateDateValue(Entity entity) { #if ($table.isUseUpdateDate()) return downcast(entity).get${table.updateDateJavaName}() != null; #else return false; #end } // =================================================================================== // Downcast Helper // =============== protected ${myExtendedObjectClassName} downcast(Entity entity) { return helpEntityDowncastInternally(entity, ${myExtendedObjectClassName}.class); } protected ${myConditionBeanClassName} downcast(ConditionBean cb) { return helpConditionBeanDowncastInternally(cb, ${myConditionBeanClassName}.class); } }