zoukankan      html  css  js  c++  java
  • Shiro SessionDAO的设计概念

    SessionDao

    其行为有

    AbstractSessionDAO 

    具备了生成Session的ID的工具SessionIdGenerator,该工具有多种功能(默认是UUID形式的),可以生成UUID形式的,可以是随机数形式的

    公共的方法抽取出来交给AbstractSessionDao来做,如生成Session的ID,如新增、查询、更新、删除Session过程中涉及的行为(四种基础行为抽象)

    public Serializable create(Session session) {
        Serializable sessionId = doCreate(session);
        verifySessionId(sessionId);
        return sessionId;
    }
    
    private void verifySessionId(Serializable sessionId) {
        if (sessionId == null) {
            String msg = "sessionId returned from doCreate implementation is null.  Please verify the implementation.";
            throw new IllegalStateException(msg);
        }
    }
    
    protected abstract Serializable doCreate(Session session);

    MemorySessionDAO具体实现新增行为

    protected Serializable doCreate(Session session) {
        Serializable sessionId = generateSessionId(session);
        assignSessionId(session, sessionId);
        storeSession(sessionId, session);
        return sessionId;
    }

    将Session存储到了内存中

    private ConcurrentMap<Serializable, Session> sessions;
    
    public MemorySessionDAO() {
        this.sessions = new ConcurrentHashMap<Serializable, Session>();
    }
    
    protected Session storeSession(Serializable id, Session session) {
        if (id == null) {
            throw new NullPointerException("id argument cannot be null.");
        }
        return sessions.putIfAbsent(id, session);
    }
  • 相关阅读:
    Spring配置数据源和注解开发
    spring 的配置介绍
    spring
    maven
    mybatis初始
    idea中配置xml不自动提示解决方案(eclipse配置XmlCatalog)
    JSON、AJAX
    ThreadLocal的使用
    Filter过滤器
    谷歌 kaptcha 图片验证码的使用
  • 原文地址:https://www.cnblogs.com/BINGJJFLY/p/9296258.html
Copyright © 2011-2022 走看看