(4)S2Factory for FDS2を使ってみる(javaソースの作成)

日付が前後しまくって書いてます。3月23日の分を25日に書いてるのね。

外山恒一に気を取られてなかなか理解が追いつかないのであります。

でもだんだん分かってきました。S2Factory for FDS2。

こんな遠回りなことせずとも、AKABANA - downloadsここでサンプルを落とせますので、そっちを見たほうが近道かもです。
遠回りなのは私めの勉強のためであります。

で、作成したクラスです。

■AddressService

package sample;
import java.util.Collection;
import sample.vo.Address;
public interface AddressService {
    public int insert(Address dto);
    public int update(Address dto);
    public int remove(Address dto);
    public Collection<Address> select();
}

■AddressServiceImpl

package sample.impl;
import java.util.Collection;
import java.util.HashMap;
import java.util.Map;
import org.seasar.flex2.rpc.remoting.service.annotation.RemotingService;
import sample.AddressService;
import sample.vo.Address;
@RemotingService
public class AddressServiceImpl implements AddressService {
    private static Map<String,Address> map = new HashMap<String,Address>();
    private static int count = 0;
    /**
     * 追加
     */
    public int insert(Address dto){
        dto.setAddressid(Integer.toString(++count));
        map.put(dto.getAddressid(),dto);
        return 1;
    }
    /**
     * 修正
     */
    public int update(Address dto){
        map.remove( dto.getAddressid() );
        map.put(dto.getAddressid(),dto);
        return 1;
    }
    /**
     * 削除
     */
    public int remove(Address dto){
        map.remove(dto.getAddressid());
        return 1;
    }
    /**
     * 全件検索
     */
    public Collection<Address> select(){
        return map.values();
    }
}

VOクラスは省略です。
また、as側のクラスは、Cairngormのときのサンプルをそのまま使います。
変更が必要な場合は、また改めて記述します。

ようやく下準備が完成しました。

次回は、設定ファイルを記述して動かすところまで持っていきます。