Example usage for com.liferay.portal.kernel.util StringPool BLANK

List of usage examples for com.liferay.portal.kernel.util StringPool BLANK

Introduction

In this page you can find the example usage for com.liferay.portal.kernel.util StringPool BLANK.

Prototype

String BLANK

To view the source code for com.liferay.portal.kernel.util StringPool BLANK.

Click Source Link

Usage

From source file:at.graz.meduni.liferay.portlet.bibbox.service.persistence.IconConfigurationPersistenceImpl.java

License:Open Source License

/**
 * Returns the icon configuration where symbolconfigurationId = &#63; and key = &#63; and position = &#63; or returns <code>null</code> if it could not be found, optionally using the finder cache.
 *
 * @param symbolconfigurationId the symbolconfiguration ID
 * @param key the key/*www.  j  a  v  a  2  s . co m*/
 * @param position the position
 * @param retrieveFromCache whether to use the finder cache
 * @return the matching icon configuration, or <code>null</code> if a matching icon configuration could not be found
 * @throws SystemException if a system exception occurred
 */
@Override
public IconConfiguration fetchByIconsKeyPosition(long symbolconfigurationId, String key, String position,
        boolean retrieveFromCache) throws SystemException {
    Object[] finderArgs = new Object[] { symbolconfigurationId, key, position };

    Object result = null;

    if (retrieveFromCache) {
        result = FinderCacheUtil.getResult(FINDER_PATH_FETCH_BY_ICONSKEYPOSITION, finderArgs, this);
    }

    if (result instanceof IconConfiguration) {
        IconConfiguration iconConfiguration = (IconConfiguration) result;

        if ((symbolconfigurationId != iconConfiguration.getSymbolconfigurationId())
                || !Validator.equals(key, iconConfiguration.getKey())
                || !Validator.equals(position, iconConfiguration.getPosition())) {
            result = null;
        }
    }

    if (result == null) {
        StringBundler query = new StringBundler(5);

        query.append(_SQL_SELECT_ICONCONFIGURATION_WHERE);

        query.append(_FINDER_COLUMN_ICONSKEYPOSITION_SYMBOLCONFIGURATIONID_2);

        boolean bindKey = false;

        if (key == null) {
            query.append(_FINDER_COLUMN_ICONSKEYPOSITION_KEY_1);
        } else if (key.equals(StringPool.BLANK)) {
            query.append(_FINDER_COLUMN_ICONSKEYPOSITION_KEY_3);
        } else {
            bindKey = true;

            query.append(_FINDER_COLUMN_ICONSKEYPOSITION_KEY_2);
        }

        boolean bindPosition = false;

        if (position == null) {
            query.append(_FINDER_COLUMN_ICONSKEYPOSITION_POSITION_1);
        } else if (position.equals(StringPool.BLANK)) {
            query.append(_FINDER_COLUMN_ICONSKEYPOSITION_POSITION_3);
        } else {
            bindPosition = true;

            query.append(_FINDER_COLUMN_ICONSKEYPOSITION_POSITION_2);
        }

        String sql = query.toString();

        Session session = null;

        try {
            session = openSession();

            Query q = session.createQuery(sql);

            QueryPos qPos = QueryPos.getInstance(q);

            qPos.add(symbolconfigurationId);

            if (bindKey) {
                qPos.add(key);
            }

            if (bindPosition) {
                qPos.add(position);
            }

            List<IconConfiguration> list = q.list();

            if (list.isEmpty()) {
                FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_ICONSKEYPOSITION, finderArgs, list);
            } else {
                if ((list.size() > 1) && _log.isWarnEnabled()) {
                    _log.warn(
                            "IconConfigurationPersistenceImpl.fetchByIconsKeyPosition(long, String, 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.");
                }

                IconConfiguration iconConfiguration = list.get(0);

                result = iconConfiguration;

                cacheResult(iconConfiguration);

                if ((iconConfiguration.getSymbolconfigurationId() != symbolconfigurationId)
                        || (iconConfiguration.getKey() == null) || !iconConfiguration.getKey().equals(key)
                        || (iconConfiguration.getPosition() == null)
                        || !iconConfiguration.getPosition().equals(position)) {
                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_ICONSKEYPOSITION, finderArgs,
                            iconConfiguration);
                }
            }
        } catch (Exception e) {
            FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_ICONSKEYPOSITION, finderArgs);

            throw processException(e);
        } finally {
            closeSession(session);
        }
    }

    if (result instanceof List<?>) {
        return null;
    } else {
        return (IconConfiguration) result;
    }
}

From source file:at.graz.meduni.liferay.portlet.bibbox.service.persistence.IconConfigurationPersistenceImpl.java

License:Open Source License

/**
 * Returns the number of icon configurations where symbolconfigurationId = &#63; and key = &#63; and position = &#63;.
 *
 * @param symbolconfigurationId the symbolconfiguration ID
 * @param key the key//from  ww  w . ja  v  a 2 s . c  om
 * @param position the position
 * @return the number of matching icon configurations
 * @throws SystemException if a system exception occurred
 */
@Override
public int countByIconsKeyPosition(long symbolconfigurationId, String key, String position)
        throws SystemException {
    FinderPath finderPath = FINDER_PATH_COUNT_BY_ICONSKEYPOSITION;

    Object[] finderArgs = new Object[] { symbolconfigurationId, key, position };

    Long count = (Long) FinderCacheUtil.getResult(finderPath, finderArgs, this);

    if (count == null) {
        StringBundler query = new StringBundler(4);

        query.append(_SQL_COUNT_ICONCONFIGURATION_WHERE);

        query.append(_FINDER_COLUMN_ICONSKEYPOSITION_SYMBOLCONFIGURATIONID_2);

        boolean bindKey = false;

        if (key == null) {
            query.append(_FINDER_COLUMN_ICONSKEYPOSITION_KEY_1);
        } else if (key.equals(StringPool.BLANK)) {
            query.append(_FINDER_COLUMN_ICONSKEYPOSITION_KEY_3);
        } else {
            bindKey = true;

            query.append(_FINDER_COLUMN_ICONSKEYPOSITION_KEY_2);
        }

        boolean bindPosition = false;

        if (position == null) {
            query.append(_FINDER_COLUMN_ICONSKEYPOSITION_POSITION_1);
        } else if (position.equals(StringPool.BLANK)) {
            query.append(_FINDER_COLUMN_ICONSKEYPOSITION_POSITION_3);
        } else {
            bindPosition = true;

            query.append(_FINDER_COLUMN_ICONSKEYPOSITION_POSITION_2);
        }

        String sql = query.toString();

        Session session = null;

        try {
            session = openSession();

            Query q = session.createQuery(sql);

            QueryPos qPos = QueryPos.getInstance(q);

            qPos.add(symbolconfigurationId);

            if (bindKey) {
                qPos.add(key);
            }

            if (bindPosition) {
                qPos.add(position);
            }

            count = (Long) q.uniqueResult();

            FinderCacheUtil.putResult(finderPath, finderArgs, count);
        } catch (Exception e) {
            FinderCacheUtil.removeResult(finderPath, finderArgs);

            throw processException(e);
        } finally {
            closeSession(session);
        }
    }

    return count.intValue();
}

From source file:at.graz.meduni.liferay.portlet.bibbox.service.persistence.OrganizationSearchIndexPersistenceImpl.java

License:Open Source License

/**
 * Returns an ordered range of all the organization search indexs where searchvalue = &#63;.
 *
 * <p>//from  w  w w. j  a v a  2  s  . c  o  m
 * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link at.graz.meduni.liferay.portlet.bibbox.model.impl.OrganizationSearchIndexModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
 * </p>
 *
 * @param searchvalue the searchvalue
 * @param start the lower bound of the range of organization search indexs
 * @param end the upper bound of the range of organization search indexs (not inclusive)
 * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
 * @return the ordered range of matching organization search indexs
 * @throws SystemException if a system exception occurred
 */
@Override
public List<OrganizationSearchIndex> findByExactSearch(String searchvalue, int start, int end,
        OrderByComparator orderByComparator) throws SystemException {
    boolean pagination = true;
    FinderPath finderPath = null;
    Object[] finderArgs = null;

    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) && (orderByComparator == null)) {
        pagination = false;
        finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_EXACTSEARCH;
        finderArgs = new Object[] { searchvalue };
    } else {
        finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_EXACTSEARCH;
        finderArgs = new Object[] { searchvalue, start, end, orderByComparator };
    }

    List<OrganizationSearchIndex> list = (List<OrganizationSearchIndex>) FinderCacheUtil.getResult(finderPath,
            finderArgs, this);

    if ((list != null) && !list.isEmpty()) {
        for (OrganizationSearchIndex organizationSearchIndex : list) {
            if (!Validator.equals(searchvalue, organizationSearchIndex.getSearchvalue())) {
                list = null;

                break;
            }
        }
    }

    if (list == null) {
        StringBundler query = null;

        if (orderByComparator != null) {
            query = new StringBundler(3 + (orderByComparator.getOrderByFields().length * 3));
        } else {
            query = new StringBundler(3);
        }

        query.append(_SQL_SELECT_ORGANIZATIONSEARCHINDEX_WHERE);

        boolean bindSearchvalue = false;

        if (searchvalue == null) {
            query.append(_FINDER_COLUMN_EXACTSEARCH_SEARCHVALUE_1);
        } else if (searchvalue.equals(StringPool.BLANK)) {
            query.append(_FINDER_COLUMN_EXACTSEARCH_SEARCHVALUE_3);
        } else {
            bindSearchvalue = true;

            query.append(_FINDER_COLUMN_EXACTSEARCH_SEARCHVALUE_2);
        }

        if (orderByComparator != null) {
            appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS, orderByComparator);
        } else if (pagination) {
            query.append(OrganizationSearchIndexModelImpl.ORDER_BY_JPQL);
        }

        String sql = query.toString();

        Session session = null;

        try {
            session = openSession();

            Query q = session.createQuery(sql);

            QueryPos qPos = QueryPos.getInstance(q);

            if (bindSearchvalue) {
                qPos.add(searchvalue);
            }

            if (!pagination) {
                list = (List<OrganizationSearchIndex>) QueryUtil.list(q, getDialect(), start, end, false);

                Collections.sort(list);

                list = new UnmodifiableList<OrganizationSearchIndex>(list);
            } else {
                list = (List<OrganizationSearchIndex>) QueryUtil.list(q, getDialect(), start, end);
            }

            cacheResult(list);

            FinderCacheUtil.putResult(finderPath, finderArgs, list);
        } catch (Exception e) {
            FinderCacheUtil.removeResult(finderPath, finderArgs);

            throw processException(e);
        } finally {
            closeSession(session);
        }
    }

    return list;
}

From source file:at.graz.meduni.liferay.portlet.bibbox.service.persistence.OrganizationSearchIndexPersistenceImpl.java

License:Open Source License

protected OrganizationSearchIndex getByExactSearch_PrevAndNext(Session session,
        OrganizationSearchIndex organizationSearchIndex, String searchvalue,
        OrderByComparator orderByComparator, boolean previous) {
    StringBundler query = null;/*w w w  . j  ava2 s. com*/

    if (orderByComparator != null) {
        query = new StringBundler(6 + (orderByComparator.getOrderByFields().length * 6));
    } else {
        query = new StringBundler(3);
    }

    query.append(_SQL_SELECT_ORGANIZATIONSEARCHINDEX_WHERE);

    boolean bindSearchvalue = false;

    if (searchvalue == null) {
        query.append(_FINDER_COLUMN_EXACTSEARCH_SEARCHVALUE_1);
    } else if (searchvalue.equals(StringPool.BLANK)) {
        query.append(_FINDER_COLUMN_EXACTSEARCH_SEARCHVALUE_3);
    } else {
        bindSearchvalue = true;

        query.append(_FINDER_COLUMN_EXACTSEARCH_SEARCHVALUE_2);
    }

    if (orderByComparator != null) {
        String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();

        if (orderByConditionFields.length > 0) {
            query.append(WHERE_AND);
        }

        for (int i = 0; i < orderByConditionFields.length; i++) {
            query.append(_ORDER_BY_ENTITY_ALIAS);
            query.append(orderByConditionFields[i]);

            if ((i + 1) < orderByConditionFields.length) {
                if (orderByComparator.isAscending() ^ previous) {
                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
                } else {
                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
                }
            } else {
                if (orderByComparator.isAscending() ^ previous) {
                    query.append(WHERE_GREATER_THAN);
                } else {
                    query.append(WHERE_LESSER_THAN);
                }
            }
        }

        query.append(ORDER_BY_CLAUSE);

        String[] orderByFields = orderByComparator.getOrderByFields();

        for (int i = 0; i < orderByFields.length; i++) {
            query.append(_ORDER_BY_ENTITY_ALIAS);
            query.append(orderByFields[i]);

            if ((i + 1) < orderByFields.length) {
                if (orderByComparator.isAscending() ^ previous) {
                    query.append(ORDER_BY_ASC_HAS_NEXT);
                } else {
                    query.append(ORDER_BY_DESC_HAS_NEXT);
                }
            } else {
                if (orderByComparator.isAscending() ^ previous) {
                    query.append(ORDER_BY_ASC);
                } else {
                    query.append(ORDER_BY_DESC);
                }
            }
        }
    } else {
        query.append(OrganizationSearchIndexModelImpl.ORDER_BY_JPQL);
    }

    String sql = query.toString();

    Query q = session.createQuery(sql);

    q.setFirstResult(0);
    q.setMaxResults(2);

    QueryPos qPos = QueryPos.getInstance(q);

    if (bindSearchvalue) {
        qPos.add(searchvalue);
    }

    if (orderByComparator != null) {
        Object[] values = orderByComparator.getOrderByConditionValues(organizationSearchIndex);

        for (Object value : values) {
            qPos.add(value);
        }
    }

    List<OrganizationSearchIndex> list = q.list();

    if (list.size() == 2) {
        return list.get(1);
    } else {
        return null;
    }
}

From source file:at.graz.meduni.liferay.portlet.bibbox.service.persistence.OrganizationSearchIndexPersistenceImpl.java

License:Open Source License

/**
 * Returns the number of organization search indexs where searchvalue = &#63;.
 *
 * @param searchvalue the searchvalue//from   w  w w  . ja v  a2  s .  c  om
 * @return the number of matching organization search indexs
 * @throws SystemException if a system exception occurred
 */
@Override
public int countByExactSearch(String searchvalue) throws SystemException {
    FinderPath finderPath = FINDER_PATH_COUNT_BY_EXACTSEARCH;

    Object[] finderArgs = new Object[] { searchvalue };

    Long count = (Long) FinderCacheUtil.getResult(finderPath, finderArgs, this);

    if (count == null) {
        StringBundler query = new StringBundler(2);

        query.append(_SQL_COUNT_ORGANIZATIONSEARCHINDEX_WHERE);

        boolean bindSearchvalue = false;

        if (searchvalue == null) {
            query.append(_FINDER_COLUMN_EXACTSEARCH_SEARCHVALUE_1);
        } else if (searchvalue.equals(StringPool.BLANK)) {
            query.append(_FINDER_COLUMN_EXACTSEARCH_SEARCHVALUE_3);
        } else {
            bindSearchvalue = true;

            query.append(_FINDER_COLUMN_EXACTSEARCH_SEARCHVALUE_2);
        }

        String sql = query.toString();

        Session session = null;

        try {
            session = openSession();

            Query q = session.createQuery(sql);

            QueryPos qPos = QueryPos.getInstance(q);

            if (bindSearchvalue) {
                qPos.add(searchvalue);
            }

            count = (Long) q.uniqueResult();

            FinderCacheUtil.putResult(finderPath, finderArgs, count);
        } catch (Exception e) {
            FinderCacheUtil.removeResult(finderPath, finderArgs);

            throw processException(e);
        } finally {
            closeSession(session);
        }
    }

    return count.intValue();
}

From source file:at.graz.meduni.liferay.portlet.bibbox.service.persistence.OrganizationSearchIndexPersistenceImpl.java

License:Open Source License

/**
 * Returns the organization search index where organisationid = &#63; and key = &#63; or returns <code>null</code> if it could not be found, optionally using the finder cache.
 *
 * @param organisationid the organisationid
 * @param key the key/*  w  w w .j a  v  a 2  s  .c  o  m*/
 * @param retrieveFromCache whether to use the finder cache
 * @return the matching organization search index, or <code>null</code> if a matching organization search index could not be found
 * @throws SystemException if a system exception occurred
 */
@Override
public OrganizationSearchIndex fetchByKeyAndOrganization(long organisationid, String key,
        boolean retrieveFromCache) throws SystemException {
    Object[] finderArgs = new Object[] { organisationid, key };

    Object result = null;

    if (retrieveFromCache) {
        result = FinderCacheUtil.getResult(FINDER_PATH_FETCH_BY_KEYANDORGANIZATION, finderArgs, this);
    }

    if (result instanceof OrganizationSearchIndex) {
        OrganizationSearchIndex organizationSearchIndex = (OrganizationSearchIndex) result;

        if ((organisationid != organizationSearchIndex.getOrganisationid())
                || !Validator.equals(key, organizationSearchIndex.getKey())) {
            result = null;
        }
    }

    if (result == null) {
        StringBundler query = new StringBundler(4);

        query.append(_SQL_SELECT_ORGANIZATIONSEARCHINDEX_WHERE);

        query.append(_FINDER_COLUMN_KEYANDORGANIZATION_ORGANISATIONID_2);

        boolean bindKey = false;

        if (key == null) {
            query.append(_FINDER_COLUMN_KEYANDORGANIZATION_KEY_1);
        } else if (key.equals(StringPool.BLANK)) {
            query.append(_FINDER_COLUMN_KEYANDORGANIZATION_KEY_3);
        } else {
            bindKey = true;

            query.append(_FINDER_COLUMN_KEYANDORGANIZATION_KEY_2);
        }

        String sql = query.toString();

        Session session = null;

        try {
            session = openSession();

            Query q = session.createQuery(sql);

            QueryPos qPos = QueryPos.getInstance(q);

            qPos.add(organisationid);

            if (bindKey) {
                qPos.add(key);
            }

            List<OrganizationSearchIndex> list = q.list();

            if (list.isEmpty()) {
                FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_KEYANDORGANIZATION, finderArgs, list);
            } else {
                if ((list.size() > 1) && _log.isWarnEnabled()) {
                    _log.warn(
                            "OrganizationSearchIndexPersistenceImpl.fetchByKeyAndOrganization(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.");
                }

                OrganizationSearchIndex organizationSearchIndex = list.get(0);

                result = organizationSearchIndex;

                cacheResult(organizationSearchIndex);

                if ((organizationSearchIndex.getOrganisationid() != organisationid)
                        || (organizationSearchIndex.getKey() == null)
                        || !organizationSearchIndex.getKey().equals(key)) {
                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_KEYANDORGANIZATION, finderArgs,
                            organizationSearchIndex);
                }
            }
        } catch (Exception e) {
            FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_KEYANDORGANIZATION, finderArgs);

            throw processException(e);
        } finally {
            closeSession(session);
        }
    }

    if (result instanceof List<?>) {
        return null;
    } else {
        return (OrganizationSearchIndex) result;
    }
}

From source file:at.graz.meduni.liferay.portlet.bibbox.service.persistence.OrganizationSearchIndexPersistenceImpl.java

License:Open Source License

/**
 * Returns the number of organization search indexs where organisationid = &#63; and key = &#63;.
 *
 * @param organisationid the organisationid
 * @param key the key//  w  ww.  j av  a 2 s .com
 * @return the number of matching organization search indexs
 * @throws SystemException if a system exception occurred
 */
@Override
public int countByKeyAndOrganization(long organisationid, String key) throws SystemException {
    FinderPath finderPath = FINDER_PATH_COUNT_BY_KEYANDORGANIZATION;

    Object[] finderArgs = new Object[] { organisationid, key };

    Long count = (Long) FinderCacheUtil.getResult(finderPath, finderArgs, this);

    if (count == null) {
        StringBundler query = new StringBundler(3);

        query.append(_SQL_COUNT_ORGANIZATIONSEARCHINDEX_WHERE);

        query.append(_FINDER_COLUMN_KEYANDORGANIZATION_ORGANISATIONID_2);

        boolean bindKey = false;

        if (key == null) {
            query.append(_FINDER_COLUMN_KEYANDORGANIZATION_KEY_1);
        } else if (key.equals(StringPool.BLANK)) {
            query.append(_FINDER_COLUMN_KEYANDORGANIZATION_KEY_3);
        } else {
            bindKey = true;

            query.append(_FINDER_COLUMN_KEYANDORGANIZATION_KEY_2);
        }

        String sql = query.toString();

        Session session = null;

        try {
            session = openSession();

            Query q = session.createQuery(sql);

            QueryPos qPos = QueryPos.getInstance(q);

            qPos.add(organisationid);

            if (bindKey) {
                qPos.add(key);
            }

            count = (Long) q.uniqueResult();

            FinderCacheUtil.putResult(finderPath, finderArgs, count);
        } catch (Exception e) {
            FinderCacheUtil.removeResult(finderPath, finderArgs);

            throw processException(e);
        } finally {
            closeSession(session);
        }
    }

    return count.intValue();
}

From source file:at.graz.meduni.liferay.portlet.bibbox.service.persistence.OrphanetReferencePersistenceImpl.java

License:Open Source License

/**
 * Returns an ordered range of all the orphanet references where orphanetdisorderId = &#63; and source = &#63;.
 *
 * <p>//from w  ww. j  a va2  s .  c o  m
 * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link at.graz.meduni.liferay.portlet.bibbox.model.impl.OrphanetReferenceModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
 * </p>
 *
 * @param orphanetdisorderId the orphanetdisorder ID
 * @param source the source
 * @param start the lower bound of the range of orphanet references
 * @param end the upper bound of the range of orphanet references (not inclusive)
 * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
 * @return the ordered range of matching orphanet references
 * @throws SystemException if a system exception occurred
 */
@Override
public List<OrphanetReference> findByOrphanetDisorderIdAndSource(long orphanetdisorderId, String source,
        int start, int end, OrderByComparator orderByComparator) throws SystemException {
    boolean pagination = true;
    FinderPath finderPath = null;
    Object[] finderArgs = null;

    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) && (orderByComparator == null)) {
        pagination = false;
        finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_ORPHANETDISORDERIDANDSOURCE;
        finderArgs = new Object[] { orphanetdisorderId, source };
    } else {
        finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_ORPHANETDISORDERIDANDSOURCE;
        finderArgs = new Object[] { orphanetdisorderId, source,

                start, end, orderByComparator };
    }

    List<OrphanetReference> list = (List<OrphanetReference>) FinderCacheUtil.getResult(finderPath, finderArgs,
            this);

    if ((list != null) && !list.isEmpty()) {
        for (OrphanetReference orphanetReference : list) {
            if ((orphanetdisorderId != orphanetReference.getOrphanetdisorderId())
                    || !Validator.equals(source, orphanetReference.getSource())) {
                list = null;

                break;
            }
        }
    }

    if (list == null) {
        StringBundler query = null;

        if (orderByComparator != null) {
            query = new StringBundler(4 + (orderByComparator.getOrderByFields().length * 3));
        } else {
            query = new StringBundler(4);
        }

        query.append(_SQL_SELECT_ORPHANETREFERENCE_WHERE);

        query.append(_FINDER_COLUMN_ORPHANETDISORDERIDANDSOURCE_ORPHANETDISORDERID_2);

        boolean bindSource = false;

        if (source == null) {
            query.append(_FINDER_COLUMN_ORPHANETDISORDERIDANDSOURCE_SOURCE_1);
        } else if (source.equals(StringPool.BLANK)) {
            query.append(_FINDER_COLUMN_ORPHANETDISORDERIDANDSOURCE_SOURCE_3);
        } else {
            bindSource = true;

            query.append(_FINDER_COLUMN_ORPHANETDISORDERIDANDSOURCE_SOURCE_2);
        }

        if (orderByComparator != null) {
            appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS, orderByComparator);
        } else if (pagination) {
            query.append(OrphanetReferenceModelImpl.ORDER_BY_JPQL);
        }

        String sql = query.toString();

        Session session = null;

        try {
            session = openSession();

            Query q = session.createQuery(sql);

            QueryPos qPos = QueryPos.getInstance(q);

            qPos.add(orphanetdisorderId);

            if (bindSource) {
                qPos.add(source);
            }

            if (!pagination) {
                list = (List<OrphanetReference>) QueryUtil.list(q, getDialect(), start, end, false);

                Collections.sort(list);

                list = new UnmodifiableList<OrphanetReference>(list);
            } else {
                list = (List<OrphanetReference>) QueryUtil.list(q, getDialect(), start, end);
            }

            cacheResult(list);

            FinderCacheUtil.putResult(finderPath, finderArgs, list);
        } catch (Exception e) {
            FinderCacheUtil.removeResult(finderPath, finderArgs);

            throw processException(e);
        } finally {
            closeSession(session);
        }
    }

    return list;
}

From source file:at.graz.meduni.liferay.portlet.bibbox.service.persistence.OrphanetReferencePersistenceImpl.java

License:Open Source License

protected OrphanetReference getByOrphanetDisorderIdAndSource_PrevAndNext(Session session,
        OrphanetReference orphanetReference, long orphanetdisorderId, String source,
        OrderByComparator orderByComparator, boolean previous) {
    StringBundler query = null;/*from  w w w. jav a2s.  com*/

    if (orderByComparator != null) {
        query = new StringBundler(6 + (orderByComparator.getOrderByFields().length * 6));
    } else {
        query = new StringBundler(3);
    }

    query.append(_SQL_SELECT_ORPHANETREFERENCE_WHERE);

    query.append(_FINDER_COLUMN_ORPHANETDISORDERIDANDSOURCE_ORPHANETDISORDERID_2);

    boolean bindSource = false;

    if (source == null) {
        query.append(_FINDER_COLUMN_ORPHANETDISORDERIDANDSOURCE_SOURCE_1);
    } else if (source.equals(StringPool.BLANK)) {
        query.append(_FINDER_COLUMN_ORPHANETDISORDERIDANDSOURCE_SOURCE_3);
    } else {
        bindSource = true;

        query.append(_FINDER_COLUMN_ORPHANETDISORDERIDANDSOURCE_SOURCE_2);
    }

    if (orderByComparator != null) {
        String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();

        if (orderByConditionFields.length > 0) {
            query.append(WHERE_AND);
        }

        for (int i = 0; i < orderByConditionFields.length; i++) {
            query.append(_ORDER_BY_ENTITY_ALIAS);
            query.append(orderByConditionFields[i]);

            if ((i + 1) < orderByConditionFields.length) {
                if (orderByComparator.isAscending() ^ previous) {
                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
                } else {
                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
                }
            } else {
                if (orderByComparator.isAscending() ^ previous) {
                    query.append(WHERE_GREATER_THAN);
                } else {
                    query.append(WHERE_LESSER_THAN);
                }
            }
        }

        query.append(ORDER_BY_CLAUSE);

        String[] orderByFields = orderByComparator.getOrderByFields();

        for (int i = 0; i < orderByFields.length; i++) {
            query.append(_ORDER_BY_ENTITY_ALIAS);
            query.append(orderByFields[i]);

            if ((i + 1) < orderByFields.length) {
                if (orderByComparator.isAscending() ^ previous) {
                    query.append(ORDER_BY_ASC_HAS_NEXT);
                } else {
                    query.append(ORDER_BY_DESC_HAS_NEXT);
                }
            } else {
                if (orderByComparator.isAscending() ^ previous) {
                    query.append(ORDER_BY_ASC);
                } else {
                    query.append(ORDER_BY_DESC);
                }
            }
        }
    } else {
        query.append(OrphanetReferenceModelImpl.ORDER_BY_JPQL);
    }

    String sql = query.toString();

    Query q = session.createQuery(sql);

    q.setFirstResult(0);
    q.setMaxResults(2);

    QueryPos qPos = QueryPos.getInstance(q);

    qPos.add(orphanetdisorderId);

    if (bindSource) {
        qPos.add(source);
    }

    if (orderByComparator != null) {
        Object[] values = orderByComparator.getOrderByConditionValues(orphanetReference);

        for (Object value : values) {
            qPos.add(value);
        }
    }

    List<OrphanetReference> list = q.list();

    if (list.size() == 2) {
        return list.get(1);
    } else {
        return null;
    }
}

From source file:at.graz.meduni.liferay.portlet.bibbox.service.persistence.OrphanetReferencePersistenceImpl.java

License:Open Source License

/**
 * Returns the number of orphanet references where orphanetdisorderId = &#63; and source = &#63;.
 *
 * @param orphanetdisorderId the orphanetdisorder ID
 * @param source the source// w w  w.j a  va2  s  .  com
 * @return the number of matching orphanet references
 * @throws SystemException if a system exception occurred
 */
@Override
public int countByOrphanetDisorderIdAndSource(long orphanetdisorderId, String source) throws SystemException {
    FinderPath finderPath = FINDER_PATH_COUNT_BY_ORPHANETDISORDERIDANDSOURCE;

    Object[] finderArgs = new Object[] { orphanetdisorderId, source };

    Long count = (Long) FinderCacheUtil.getResult(finderPath, finderArgs, this);

    if (count == null) {
        StringBundler query = new StringBundler(3);

        query.append(_SQL_COUNT_ORPHANETREFERENCE_WHERE);

        query.append(_FINDER_COLUMN_ORPHANETDISORDERIDANDSOURCE_ORPHANETDISORDERID_2);

        boolean bindSource = false;

        if (source == null) {
            query.append(_FINDER_COLUMN_ORPHANETDISORDERIDANDSOURCE_SOURCE_1);
        } else if (source.equals(StringPool.BLANK)) {
            query.append(_FINDER_COLUMN_ORPHANETDISORDERIDANDSOURCE_SOURCE_3);
        } else {
            bindSource = true;

            query.append(_FINDER_COLUMN_ORPHANETDISORDERIDANDSOURCE_SOURCE_2);
        }

        String sql = query.toString();

        Session session = null;

        try {
            session = openSession();

            Query q = session.createQuery(sql);

            QueryPos qPos = QueryPos.getInstance(q);

            qPos.add(orphanetdisorderId);

            if (bindSource) {
                qPos.add(source);
            }

            count = (Long) q.uniqueResult();

            FinderCacheUtil.putResult(finderPath, finderArgs, count);
        } catch (Exception e) {
            FinderCacheUtil.removeResult(finderPath, finderArgs);

            throw processException(e);
        } finally {
            closeSession(session);
        }
    }

    return count.intValue();
}