⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 openiduserrpdao.java

📁 开源的OpenId的一个java实现
💻 JAVA
字号:
package org.wso2.solutions.identity.persistence.dao;

import java.util.ArrayList;
import java.util.Date;
import java.util.Iterator;
import java.util.List;

import org.hibernate.Query;
import org.hibernate.Session;
import org.hibernate.Transaction;
import org.wso2.solutions.identity.persistence.dataobject.OpenIDUserRPDO;
import org.wso2.solutions.identity.persistence.HibernateConfig;
import org.wso2.solutions.identity.report.OpenIDSummaryReportData;
import org.wso2.solutions.identity.report.SummaryReportData;

public class OpenIDUserRPDAO extends BaseDAO {

    public OpenIDUserRPDAO(HibernateConfig config) {
        super(config);
    }

    /**
     * Returns relying party user settings corresponding to a given user name.
     * @param userName Unique user name
     * @param rpUrl Relying party url
     * @return A set of OpenIDUserRPDO, corresponding to the provided user name
     *         and RP url.
     */
    public OpenIDUserRPDO[] getOpenIDUserRP(String userName, String rpUrl) {

        Session session = hbConfig.getCurrentSession();
        String stmt = "from OpenIDUserRPDO as c where c.rpUrl = '" + rpUrl
                + "' and c.userName='" + userName + "'";
        OpenIDUserRPDO[] rpdo = null;

        try {
            Query query = session.createQuery(stmt);
            List lst = query.list();
            rpdo = (OpenIDUserRPDO[]) lst
                    .toArray(new OpenIDUserRPDO[lst.size()]);
            if (rpdo == null)
                return new OpenIDUserRPDO[0];
        } catch (Throwable e) {
            String msg = messages.getMessage("errorQuerryingOpenIDUserRP");
            throw new RuntimeException(msg, e);
        } finally {
            hbConfig.closeSession();
        }

        return rpdo;
    }

    /**
     * Returns relying party user settings corresponding to a given user name.
     * @param userName Unique user name
     * @return OpenIDUserRPDO, corresponding to the provided user name and RP
     *         url.
     */
    public OpenIDUserRPDO[] getOpenIDUserRP(String userName) {

        Session session = hbConfig.getCurrentSession();
        String stmt = "from OpenIDUserRPDO as c where c.userName='" + userName
                + "'";
        OpenIDUserRPDO[] rpdo = null;

        try {
            Query query = session.createQuery(stmt);
            List lst = query.list();
            rpdo = (OpenIDUserRPDO[]) lst
                    .toArray(new OpenIDUserRPDO[lst.size()]);
            if (rpdo == null)
                return new OpenIDUserRPDO[0];
        } catch (Throwable e) {
            String msg = messages.getMessage("errorQuerryingOpenIDUserRP");
            throw new RuntimeException(msg, e);
        } finally {
            hbConfig.closeSession();
        }

        return rpdo;
    }

    /**
     * Returns the default user profile corresponding to the given user name and
     * the RP url.
     * @param userName Unique user name
     * @param rpUrl Relying party url
     * @return Default user profile
     */
    public String getOpenIDDefaultUserProfile(String userName, String rpUrl) {

        Session session = hbConfig.getCurrentSession();
        String stmt = "select c.defaultProfileName from OpenIDUserRPDO as c where c.userName='"
                + userName + "' and c.rpUrl='" + rpUrl + "'";
        String[] profileId = null;

        try {
            Query query = session.createQuery(stmt);
            List lst = query.list();
            profileId = (String[]) lst.toArray(new String[lst.size()]);
            if (profileId != null && profileId.length > 0)
                return profileId[0];
            else
                return null;
        } catch (Throwable e) {
            String msg = messages.getMessage("errorQuerryingOpenIDUserRP");
            throw new RuntimeException(msg, e);
        } finally {
            hbConfig.closeSession();
        }
    }

    /**
     * Returns user name,number of total visits, last login time and OpenID, of
     * all the users who at least used his OpenID once.
     * @return user data
     */
    public List<OpenIDSummaryReportData> getOpenIDsGroupedByUser() {

        String stmt = "select c.userName, sum(c.visitCount),max(lastVisit) from OpenIDUserRPDO c group by c.userName";
        Session session = hbConfig.getCurrentSession();

        List<OpenIDSummaryReportData> userData = new ArrayList<OpenIDSummaryReportData>();

        try {
            Query query = session.createQuery(stmt);
            List lst = query.list();
            Iterator ite = lst.iterator();
            while (ite.hasNext()) {
                Object[] tuple = (Object[]) ite.next();
                String userId = (String) tuple[0];
                Integer count = (Integer) tuple[1];
                OpenIDSummaryReportData data = new OpenIDSummaryReportData();
                data.setCardCount(count.intValue());
                data.setUserId(userId);
                data.setLastVisit((Date)tuple[2]);
                userData.add(data);
            }
        } catch (Throwable e) {
            String msg = messages.getMessage("errorQuerryingOpenIDUserRP");
            log.error(msg, e);
            throw new RuntimeException(msg, e);
        } finally {
            hbConfig.closeSession();
        }
        return userData;
    }

}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -