package org.docksidestage.hangar.dbflute.nogen;

import java.time.Duration;
import java.util.concurrent.Executor;

import org.dbflute.Entity;
import org.dbflute.bhv.AbstractBehaviorWritable;
import org.dbflute.bhv.readable.CBCall;
import org.dbflute.bhv.readable.EntityRowHandler;
import org.dbflute.cbean.ConditionBean;
import org.docksidestage.hangar.dbflute.nogen.akka.AkkaSourceHelper;

import akka.NotUsed;
import akka.stream.javadsl.Source;

/**
 * @param <ENTITY> The type of entity handled by this behavior.
 * @param <CB> The type of condition-bean handled by this behavior.
 * @author jflute (2019/12/30 Monday at sheraton)
 */
public abstract class ExtendedAbstractBehaviorWritable<ENTITY extends Entity, CB extends ConditionBean>
        extends AbstractBehaviorWritable<ENTITY, CB> implements ExtendedBehaviorWritable<ENTITY, CB> {

    // ===================================================================================
    //                                                                             Gateway
    //                                                                             =======
    // gateway to generated methods in behavior implementation
    protected abstract void selectCursor(CBCall<CB> cbLambda, EntityRowHandler<ENTITY> entityLambda);

    // ===================================================================================
    //                                                                               Akka
    //                                                                              ======
    @Override
    public Source<ENTITY, NotUsed> source(CBCall<CB> cbLambda, Executor executor) {
        return AkkaSourceHelper.<ENTITY> generator(Duration.ofSeconds(5)).mapMaterializedValue(generator -> generator.runAsync(() -> {
            selectCursor(cbLambda, generator::pushNext);
        }, executor));
    }
}

@@ -1755,16 +1755,37 @@
 rator -%3E
+ %7B%0A            return
  generat
@@ -1800,24 +1800,28 @@
 ync(() -%3E %7B%0A
+    
             
@@ -1873,16 +1873,20 @@
         
+    
 %7D, execu
@@ -1889,16 +1889,27 @@
 xecutor)
+;%0A        %7D
 );%0A    %7D

change lambda format