Search in sources :

Example 11 with OAuthToken

use of com.liferay.opensocial.model.OAuthToken in project liferay-ide by liferay.

the class OAuthTokenPersistenceImpl method create.

/**
 * Creates a new o auth token with the primary key. Does not add the o auth token to the database.
 *
 * @param oAuthTokenId the primary key for the new o auth token
 * @return the new o auth token
 */
@Override
public OAuthToken create(long oAuthTokenId) {
    OAuthToken oAuthToken = new OAuthTokenImpl();
    oAuthToken.setNew(true);
    oAuthToken.setPrimaryKey(oAuthTokenId);
    return oAuthToken;
}
Also used : OAuthToken(com.liferay.opensocial.model.OAuthToken) OAuthTokenImpl(com.liferay.opensocial.model.impl.OAuthTokenImpl)

Example 12 with OAuthToken

use of com.liferay.opensocial.model.OAuthToken in project liferay-ide by liferay.

the class OAuthTokenPersistenceImpl method fetchByPrimaryKey.

/**
 * Returns the o auth token with the primary key or returns <code>null</code> if it could not be found.
 *
 * @param primaryKey the primary key of the o auth token
 * @return the o auth token, or <code>null</code> if a o auth token with the primary key could not be found
 * @throws SystemException if a system exception occurred
 */
@Override
public OAuthToken fetchByPrimaryKey(Serializable primaryKey) throws SystemException {
    OAuthToken oAuthToken = (OAuthToken) EntityCacheUtil.getResult(OAuthTokenModelImpl.ENTITY_CACHE_ENABLED, OAuthTokenImpl.class, primaryKey);
    if (oAuthToken == _nullOAuthToken) {
        return null;
    }
    if (oAuthToken == null) {
        Session session = null;
        try {
            session = openSession();
            oAuthToken = (OAuthToken) session.get(OAuthTokenImpl.class, primaryKey);
            if (oAuthToken != null) {
                cacheResult(oAuthToken);
            } else {
                EntityCacheUtil.putResult(OAuthTokenModelImpl.ENTITY_CACHE_ENABLED, OAuthTokenImpl.class, primaryKey, _nullOAuthToken);
            }
        } catch (Exception e) {
            EntityCacheUtil.removeResult(OAuthTokenModelImpl.ENTITY_CACHE_ENABLED, OAuthTokenImpl.class, primaryKey);
            throw processException(e);
        } finally {
            closeSession(session);
        }
    }
    return oAuthToken;
}
Also used : OAuthToken(com.liferay.opensocial.model.OAuthToken) OAuthTokenImpl(com.liferay.opensocial.model.impl.OAuthTokenImpl) SystemException(com.liferay.portal.kernel.exception.SystemException) NoSuchOAuthTokenException(com.liferay.opensocial.NoSuchOAuthTokenException) Session(com.liferay.portal.kernel.dao.orm.Session)

Example 13 with OAuthToken

use of com.liferay.opensocial.model.OAuthToken in project liferay-ide by liferay.

the class OAuthTokenPersistenceImpl method remove.

/**
 * Removes the o auth token with the primary key from the database. Also notifies the appropriate model listeners.
 *
 * @param primaryKey the primary key of the o auth token
 * @return the o auth token that was removed
 * @throws com.liferay.opensocial.NoSuchOAuthTokenException if a o auth token with the primary key could not be found
 * @throws SystemException if a system exception occurred
 */
@Override
public OAuthToken remove(Serializable primaryKey) throws NoSuchOAuthTokenException, SystemException {
    Session session = null;
    try {
        session = openSession();
        OAuthToken oAuthToken = (OAuthToken) session.get(OAuthTokenImpl.class, primaryKey);
        if (oAuthToken == null) {
            if (_log.isWarnEnabled()) {
                _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + primaryKey);
            }
            throw new NoSuchOAuthTokenException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + primaryKey);
        }
        return remove(oAuthToken);
    } catch (NoSuchOAuthTokenException nsee) {
        throw nsee;
    } catch (Exception e) {
        throw processException(e);
    } finally {
        closeSession(session);
    }
}
Also used : OAuthToken(com.liferay.opensocial.model.OAuthToken) OAuthTokenImpl(com.liferay.opensocial.model.impl.OAuthTokenImpl) NoSuchOAuthTokenException(com.liferay.opensocial.NoSuchOAuthTokenException) SystemException(com.liferay.portal.kernel.exception.SystemException) NoSuchOAuthTokenException(com.liferay.opensocial.NoSuchOAuthTokenException) Session(com.liferay.portal.kernel.dao.orm.Session)

Example 14 with OAuthToken

use of com.liferay.opensocial.model.OAuthToken in project liferay-ide by liferay.

the class OAuthTokenPersistenceImpl method findByG_S_PrevAndNext.

/**
 * Returns the o auth tokens before and after the current o auth token in the ordered set where gadgetKey = &#63; and serviceName = &#63;.
 *
 * @param oAuthTokenId the primary key of the current o auth token
 * @param gadgetKey the gadget key
 * @param serviceName the service name
 * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
 * @return the previous, current, and next o auth token
 * @throws com.liferay.opensocial.NoSuchOAuthTokenException if a o auth token with the primary key could not be found
 * @throws SystemException if a system exception occurred
 */
@Override
public OAuthToken[] findByG_S_PrevAndNext(long oAuthTokenId, String gadgetKey, String serviceName, OrderByComparator orderByComparator) throws NoSuchOAuthTokenException, SystemException {
    OAuthToken oAuthToken = findByPrimaryKey(oAuthTokenId);
    Session session = null;
    try {
        session = openSession();
        OAuthToken[] array = new OAuthTokenImpl[3];
        array[0] = getByG_S_PrevAndNext(session, oAuthToken, gadgetKey, serviceName, orderByComparator, true);
        array[1] = oAuthToken;
        array[2] = getByG_S_PrevAndNext(session, oAuthToken, gadgetKey, serviceName, orderByComparator, false);
        return array;
    } catch (Exception e) {
        throw processException(e);
    } finally {
        closeSession(session);
    }
}
Also used : OAuthToken(com.liferay.opensocial.model.OAuthToken) OAuthTokenImpl(com.liferay.opensocial.model.impl.OAuthTokenImpl) SystemException(com.liferay.portal.kernel.exception.SystemException) NoSuchOAuthTokenException(com.liferay.opensocial.NoSuchOAuthTokenException) Session(com.liferay.portal.kernel.dao.orm.Session)

Example 15 with OAuthToken

use of com.liferay.opensocial.model.OAuthToken in project liferay-ide by liferay.

the class OAuthTokenPersistenceImpl method fetchByU_G_S_M_T.

/**
 * Returns the o auth token where userId = &#63; and gadgetKey = &#63; and serviceName = &#63; and moduleId = &#63; and tokenName = &#63; or returns <code>null</code> if it could not be found, optionally using the finder cache.
 *
 * @param userId the user ID
 * @param gadgetKey the gadget key
 * @param serviceName the service name
 * @param moduleId the module ID
 * @param tokenName the token name
 * @param retrieveFromCache whether to use the finder cache
 * @return the matching o auth token, or <code>null</code> if a matching o auth token could not be found
 * @throws SystemException if a system exception occurred
 */
@Override
public OAuthToken fetchByU_G_S_M_T(long userId, String gadgetKey, String serviceName, long moduleId, String tokenName, boolean retrieveFromCache) throws SystemException {
    Object[] finderArgs = new Object[] { userId, gadgetKey, serviceName, moduleId, tokenName };
    Object result = null;
    if (retrieveFromCache) {
        result = FinderCacheUtil.getResult(FINDER_PATH_FETCH_BY_U_G_S_M_T, finderArgs, this);
    }
    if (result instanceof OAuthToken) {
        OAuthToken oAuthToken = (OAuthToken) result;
        if ((userId != oAuthToken.getUserId()) || !Validator.equals(gadgetKey, oAuthToken.getGadgetKey()) || !Validator.equals(serviceName, oAuthToken.getServiceName()) || (moduleId != oAuthToken.getModuleId()) || !Validator.equals(tokenName, oAuthToken.getTokenName())) {
            result = null;
        }
    }
    if (result == null) {
        StringBundler query = new StringBundler(7);
        query.append(_SQL_SELECT_OAUTHTOKEN_WHERE);
        query.append(_FINDER_COLUMN_U_G_S_M_T_USERID_2);
        boolean bindGadgetKey = false;
        if (gadgetKey == null) {
            query.append(_FINDER_COLUMN_U_G_S_M_T_GADGETKEY_1);
        } else if (gadgetKey.equals(StringPool.BLANK)) {
            query.append(_FINDER_COLUMN_U_G_S_M_T_GADGETKEY_3);
        } else {
            bindGadgetKey = true;
            query.append(_FINDER_COLUMN_U_G_S_M_T_GADGETKEY_2);
        }
        boolean bindServiceName = false;
        if (serviceName == null) {
            query.append(_FINDER_COLUMN_U_G_S_M_T_SERVICENAME_1);
        } else if (serviceName.equals(StringPool.BLANK)) {
            query.append(_FINDER_COLUMN_U_G_S_M_T_SERVICENAME_3);
        } else {
            bindServiceName = true;
            query.append(_FINDER_COLUMN_U_G_S_M_T_SERVICENAME_2);
        }
        query.append(_FINDER_COLUMN_U_G_S_M_T_MODULEID_2);
        boolean bindTokenName = false;
        if (tokenName == null) {
            query.append(_FINDER_COLUMN_U_G_S_M_T_TOKENNAME_1);
        } else if (tokenName.equals(StringPool.BLANK)) {
            query.append(_FINDER_COLUMN_U_G_S_M_T_TOKENNAME_3);
        } else {
            bindTokenName = true;
            query.append(_FINDER_COLUMN_U_G_S_M_T_TOKENNAME_2);
        }
        String sql = query.toString();
        Session session = null;
        try {
            session = openSession();
            Query q = session.createQuery(sql);
            QueryPos qPos = QueryPos.getInstance(q);
            qPos.add(userId);
            if (bindGadgetKey) {
                qPos.add(gadgetKey);
            }
            if (bindServiceName) {
                qPos.add(serviceName);
            }
            qPos.add(moduleId);
            if (bindTokenName) {
                qPos.add(tokenName);
            }
            List<OAuthToken> list = q.list();
            if (list.isEmpty()) {
                FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_U_G_S_M_T, finderArgs, list);
            } else {
                if ((list.size() > 1) && _log.isWarnEnabled()) {
                    _log.warn("OAuthTokenPersistenceImpl.fetchByU_G_S_M_T(long, String, String, long, String, boolean) with parameters (" + StringUtil.merge(finderArgs) + ") yields a result set with more than 1 result. This violates the logical unique restriction. There is no order guarantee on which result is returned by this finder.");
                }
                OAuthToken oAuthToken = list.get(0);
                result = oAuthToken;
                cacheResult(oAuthToken);
                if ((oAuthToken.getUserId() != userId) || (oAuthToken.getGadgetKey() == null) || !oAuthToken.getGadgetKey().equals(gadgetKey) || (oAuthToken.getServiceName() == null) || !oAuthToken.getServiceName().equals(serviceName) || (oAuthToken.getModuleId() != moduleId) || (oAuthToken.getTokenName() == null) || !oAuthToken.getTokenName().equals(tokenName)) {
                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_U_G_S_M_T, finderArgs, oAuthToken);
                }
            }
        } catch (Exception e) {
            FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_U_G_S_M_T, finderArgs);
            throw processException(e);
        } finally {
            closeSession(session);
        }
    }
    if (result instanceof List<?>) {
        return null;
    } else {
        return (OAuthToken) result;
    }
}
Also used : OAuthToken(com.liferay.opensocial.model.OAuthToken) Query(com.liferay.portal.kernel.dao.orm.Query) ArrayList(java.util.ArrayList) UnmodifiableList(com.liferay.portal.kernel.util.UnmodifiableList) List(java.util.List) QueryPos(com.liferay.portal.kernel.dao.orm.QueryPos) StringBundler(com.liferay.portal.kernel.util.StringBundler) SystemException(com.liferay.portal.kernel.exception.SystemException) NoSuchOAuthTokenException(com.liferay.opensocial.NoSuchOAuthTokenException) Session(com.liferay.portal.kernel.dao.orm.Session)

Aggregations

OAuthToken (com.liferay.opensocial.model.OAuthToken)16 NoSuchOAuthTokenException (com.liferay.opensocial.NoSuchOAuthTokenException)9 SystemException (com.liferay.portal.kernel.exception.SystemException)7 StringBundler (com.liferay.portal.kernel.util.StringBundler)7 Session (com.liferay.portal.kernel.dao.orm.Session)6 OAuthTokenImpl (com.liferay.opensocial.model.impl.OAuthTokenImpl)4 Query (com.liferay.portal.kernel.dao.orm.Query)4 QueryPos (com.liferay.portal.kernel.dao.orm.QueryPos)3 UnmodifiableList (com.liferay.portal.kernel.util.UnmodifiableList)3 ArrayList (java.util.ArrayList)3 List (java.util.List)3 FinderPath (com.liferay.portal.kernel.dao.orm.FinderPath)2 User (com.liferay.portal.model.User)1 Date (java.util.Date)1 GadgetException (org.apache.shindig.gadgets.GadgetException)1