isami100のSwingin' Seasar日記

2000-01-10 s2study.app.login.dao

DummyUserDao.java

package s2study.app.login.dao;

import java.util.HashMap;
import java.util.Map;

import s2study.app.entity.User;

public class DummyUserDao implements UserDao {

    private Map users = new HashMap();

    public DummyUserDao() {
        setUpDummyData();
    }
    private void setUpDummyData() {
        users.put("00001", new User("00001", "00001".getBytes(), "Okita"));
        users.put("00002", new User("00002", "00002".getBytes(), "Nagakura"));
        users.put("00003", new User("00003", "00003".getBytes(), "Saito"));
        users.put("00004", new User("00004", "00004".getBytes(), "Matsubara"));
        users.put("00005", new User("00005", "00005".getBytes(), "Takeda"));
        users.put("00006", new User("00006", "00006".getBytes(), "Inoue"));
        users.put("00007", new User("00007", "00007".getBytes(), "Tani"));
        users.put("00008", new User("00008", "00008".getBytes(), "Todo"));
        users.put("00009", new User("00009", "00009".getBytes(), "Suzuki"));
        users.put("00010", new User("00010", "00010".getBytes(), "Harada"));
    }

    public User getUser(String userId) {
        try {
            Thread.sleep(1000L);
        }
        finally {
            return (User) users.get(userId);
        }
    }

}

JdbcUserDao.java

package s2study.app.login.dao;

import org.seasar.extension.jdbc.SelectHandler;

import s2study.app.entity.User;

public class JdbcUserDao implements UserDao {

    private SelectHandler _selectHandlar;

    public JdbcUserDao(SelectHandler selectHandler) {
        setSelectHandler(selectHandler);
    }

    public User getUser(String userId) {
        return (User) _selectHandlar.execute(new Object[] { userId });
    }

    public void setSelectHandler(final SelectHandler selectHandlar) {
        _selectHandlar = selectHandlar;
    }

}

UserDao.java

package s2study.app.login.dao;

import s2study.app.entity.User;

public interface UserDao {
    public Class BEAN = User.class;
    public String getUser_ARGS = "userId";
    User getUser(String userId);
}

LoginDao.dicon



"http://www.seasar.org/dtd/components.dtd">
<components namespace="LoginDao">
    <!-- Handler -->
    <component name="userSelectHandler" class="org.seasar.extension.jdbc.impl.BasicSelectHandler">
        <property name="sql">
            "SELECT USERID, PASSWD, USERNAME FROM USER WHERE USERID = ?"
        </property>
        <property name="resultSetHandler">
            <component class="org.seasar.extension.jdbc.impl.BeanResultSetHandler">
                <arg>@s2study.app.entity.User@class</arg>
            </component>
        </property>
    </component>
    

    <!-- Dao -->
    <!-- Dummy    -->
        <component name="userDao" class="s2study.app.login.dao.DummyUserDao"/>


    <!-- S2JDBC 
    <component name="userDao" class="s2study.app.login.dao.JdbcUserDao">
        <arg>userSelectHandler</arg>
    </component>
    -->
    <!-- S2DAO
    <component name="userDao" class="s2study.app.login.dao.UserDao">
        <aspect>
            <component class="org.seasar.dao.interceptors.S2DaoInterceptor"/>
        </aspect>
    </component>
     -->
</components>

UserDao_getUser.sql

SELECT USER.* FROM USER 
WHERE USERID = /*userId*/'00001'