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.SymbolConfigurationPersistenceImpl.java

License:Open Source License

/**
 * Returns the symbol configuration where scope = &#63; and eventtype = &#63; or returns <code>null</code> if it could not be found, optionally using the finder cache.
 *
 * @param scope the scope/*w w w.j a  va  2s  . c o m*/
 * @param eventtype the eventtype
 * @param retrieveFromCache whether to use the finder cache
 * @return the matching symbol configuration, or <code>null</code> if a matching symbol configuration could not be found
 * @throws SystemException if a system exception occurred
 */
@Override
public SymbolConfiguration fetchByFieldSymbol(String scope, String eventtype, boolean retrieveFromCache)
        throws SystemException {
    Object[] finderArgs = new Object[] { scope, eventtype };

    Object result = null;

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

    if (result instanceof SymbolConfiguration) {
        SymbolConfiguration symbolConfiguration = (SymbolConfiguration) result;

        if (!Validator.equals(scope, symbolConfiguration.getScope())
                || !Validator.equals(eventtype, symbolConfiguration.getEventtype())) {
            result = null;
        }
    }

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

        query.append(_SQL_SELECT_SYMBOLCONFIGURATION_WHERE);

        boolean bindScope = false;

        if (scope == null) {
            query.append(_FINDER_COLUMN_FIELDSYMBOL_SCOPE_1);
        } else if (scope.equals(StringPool.BLANK)) {
            query.append(_FINDER_COLUMN_FIELDSYMBOL_SCOPE_3);
        } else {
            bindScope = true;

            query.append(_FINDER_COLUMN_FIELDSYMBOL_SCOPE_2);
        }

        boolean bindEventtype = false;

        if (eventtype == null) {
            query.append(_FINDER_COLUMN_FIELDSYMBOL_EVENTTYPE_1);
        } else if (eventtype.equals(StringPool.BLANK)) {
            query.append(_FINDER_COLUMN_FIELDSYMBOL_EVENTTYPE_3);
        } else {
            bindEventtype = true;

            query.append(_FINDER_COLUMN_FIELDSYMBOL_EVENTTYPE_2);
        }

        String sql = query.toString();

        Session session = null;

        try {
            session = openSession();

            Query q = session.createQuery(sql);

            QueryPos qPos = QueryPos.getInstance(q);

            if (bindScope) {
                qPos.add(scope);
            }

            if (bindEventtype) {
                qPos.add(eventtype);
            }

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

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

                SymbolConfiguration symbolConfiguration = list.get(0);

                result = symbolConfiguration;

                cacheResult(symbolConfiguration);

                if ((symbolConfiguration.getScope() == null) || !symbolConfiguration.getScope().equals(scope)
                        || (symbolConfiguration.getEventtype() == null)
                        || !symbolConfiguration.getEventtype().equals(eventtype)) {
                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_FIELDSYMBOL, finderArgs,
                            symbolConfiguration);
                }
            }
        } catch (Exception e) {
            FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_FIELDSYMBOL, finderArgs);

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

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

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

License:Open Source License

/**
 * Returns the number of symbol configurations where scope = &#63; and eventtype = &#63;.
 *
 * @param scope the scope/*from ww  w . j ava 2  s.c om*/
 * @param eventtype the eventtype
 * @return the number of matching symbol configurations
 * @throws SystemException if a system exception occurred
 */
@Override
public int countByFieldSymbol(String scope, String eventtype) throws SystemException {
    FinderPath finderPath = FINDER_PATH_COUNT_BY_FIELDSYMBOL;

    Object[] finderArgs = new Object[] { scope, eventtype };

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

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

        query.append(_SQL_COUNT_SYMBOLCONFIGURATION_WHERE);

        boolean bindScope = false;

        if (scope == null) {
            query.append(_FINDER_COLUMN_FIELDSYMBOL_SCOPE_1);
        } else if (scope.equals(StringPool.BLANK)) {
            query.append(_FINDER_COLUMN_FIELDSYMBOL_SCOPE_3);
        } else {
            bindScope = true;

            query.append(_FINDER_COLUMN_FIELDSYMBOL_SCOPE_2);
        }

        boolean bindEventtype = false;

        if (eventtype == null) {
            query.append(_FINDER_COLUMN_FIELDSYMBOL_EVENTTYPE_1);
        } else if (eventtype.equals(StringPool.BLANK)) {
            query.append(_FINDER_COLUMN_FIELDSYMBOL_EVENTTYPE_3);
        } else {
            bindEventtype = true;

            query.append(_FINDER_COLUMN_FIELDSYMBOL_EVENTTYPE_2);
        }

        String sql = query.toString();

        Session session = null;

        try {
            session = openSession();

            Query q = session.createQuery(sql);

            QueryPos qPos = QueryPos.getInstance(q);

            if (bindScope) {
                qPos.add(scope);
            }

            if (bindEventtype) {
                qPos.add(eventtype);
            }

            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.SymbolTypeConfigurationPersistenceImpl.java

License:Open Source License

/**
 * Returns the symbol type configuration where symboltype = &#63; or returns <code>null</code> if it could not be found, optionally using the finder cache.
 *
 * @param symboltype the symboltype//from  w w w.j  a v a2 s  . c om
 * @param retrieveFromCache whether to use the finder cache
 * @return the matching symbol type configuration, or <code>null</code> if a matching symbol type configuration could not be found
 * @throws SystemException if a system exception occurred
 */
@Override
public SymbolTypeConfiguration fetchByFieldSymbolType(String symboltype, boolean retrieveFromCache)
        throws SystemException {
    Object[] finderArgs = new Object[] { symboltype };

    Object result = null;

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

    if (result instanceof SymbolTypeConfiguration) {
        SymbolTypeConfiguration symbolTypeConfiguration = (SymbolTypeConfiguration) result;

        if (!Validator.equals(symboltype, symbolTypeConfiguration.getSymboltype())) {
            result = null;
        }
    }

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

        query.append(_SQL_SELECT_SYMBOLTYPECONFIGURATION_WHERE);

        boolean bindSymboltype = false;

        if (symboltype == null) {
            query.append(_FINDER_COLUMN_FIELDSYMBOLTYPE_SYMBOLTYPE_1);
        } else if (symboltype.equals(StringPool.BLANK)) {
            query.append(_FINDER_COLUMN_FIELDSYMBOLTYPE_SYMBOLTYPE_3);
        } else {
            bindSymboltype = true;

            query.append(_FINDER_COLUMN_FIELDSYMBOLTYPE_SYMBOLTYPE_2);
        }

        String sql = query.toString();

        Session session = null;

        try {
            session = openSession();

            Query q = session.createQuery(sql);

            QueryPos qPos = QueryPos.getInstance(q);

            if (bindSymboltype) {
                qPos.add(symboltype);
            }

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

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

                SymbolTypeConfiguration symbolTypeConfiguration = list.get(0);

                result = symbolTypeConfiguration;

                cacheResult(symbolTypeConfiguration);

                if ((symbolTypeConfiguration.getSymboltype() == null)
                        || !symbolTypeConfiguration.getSymboltype().equals(symboltype)) {
                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_FIELDSYMBOLTYPE, finderArgs,
                            symbolTypeConfiguration);
                }
            }
        } catch (Exception e) {
            FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_FIELDSYMBOLTYPE, finderArgs);

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

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

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

License:Open Source License

/**
 * Returns the number of symbol type configurations where symboltype = &#63;.
 *
 * @param symboltype the symboltype/*from w ww. j  a va2  s.c  o  m*/
 * @return the number of matching symbol type configurations
 * @throws SystemException if a system exception occurred
 */
@Override
public int countByFieldSymbolType(String symboltype) throws SystemException {
    FinderPath finderPath = FINDER_PATH_COUNT_BY_FIELDSYMBOLTYPE;

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

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

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

        query.append(_SQL_COUNT_SYMBOLTYPECONFIGURATION_WHERE);

        boolean bindSymboltype = false;

        if (symboltype == null) {
            query.append(_FINDER_COLUMN_FIELDSYMBOLTYPE_SYMBOLTYPE_1);
        } else if (symboltype.equals(StringPool.BLANK)) {
            query.append(_FINDER_COLUMN_FIELDSYMBOLTYPE_SYMBOLTYPE_3);
        } else {
            bindSymboltype = true;

            query.append(_FINDER_COLUMN_FIELDSYMBOLTYPE_SYMBOLTYPE_2);
        }

        String sql = query.toString();

        Session session = null;

        try {
            session = openSession();

            Query q = session.createQuery(sql);

            QueryPos qPos = QueryPos.getInstance(q);

            if (bindSymboltype) {
                qPos.add(symboltype);
            }

            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.service.persistence.DiseaseMatrixPersistenceImpl.java

License:Open Source License

/**
 * Returns an ordered range of all the disease matrixs where organizationId = &#63; and orphanumber = &#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.service.model.impl.DiseaseMatrixModelImpl}. 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 organizationId the organization ID
 * @param orphanumber the orphanumber
 * @param start the lower bound of the range of disease matrixs
 * @param end the upper bound of the range of disease matrixs (not inclusive)
 * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
 * @return the ordered range of matching disease matrixs
 * @throws SystemException if a system exception occurred
 */
@Override
public List<DiseaseMatrix> findByOrganizationAndOrphanumber(long organizationId, String orphanumber, 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_ORGANIZATIONANDORPHANUMBER;
        finderArgs = new Object[] { organizationId, orphanumber };
    } else {
        finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_ORGANIZATIONANDORPHANUMBER;
        finderArgs = new Object[] { organizationId, orphanumber,

                start, end, orderByComparator };
    }

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

    if ((list != null) && !list.isEmpty()) {
        for (DiseaseMatrix diseaseMatrix : list) {
            if ((organizationId != diseaseMatrix.getOrganizationId())
                    || !Validator.equals(orphanumber, diseaseMatrix.getOrphanumber())) {
                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_DISEASEMATRIX_WHERE);

        query.append(_FINDER_COLUMN_ORGANIZATIONANDORPHANUMBER_ORGANIZATIONID_2);

        boolean bindOrphanumber = false;

        if (orphanumber == null) {
            query.append(_FINDER_COLUMN_ORGANIZATIONANDORPHANUMBER_ORPHANUMBER_1);
        } else if (orphanumber.equals(StringPool.BLANK)) {
            query.append(_FINDER_COLUMN_ORGANIZATIONANDORPHANUMBER_ORPHANUMBER_3);
        } else {
            bindOrphanumber = true;

            query.append(_FINDER_COLUMN_ORGANIZATIONANDORPHANUMBER_ORPHANUMBER_2);
        }

        if (orderByComparator != null) {
            appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS, orderByComparator);
        } else if (pagination) {
            query.append(DiseaseMatrixModelImpl.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(organizationId);

            if (bindOrphanumber) {
                qPos.add(orphanumber);
            }

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

                Collections.sort(list);

                list = new UnmodifiableList<DiseaseMatrix>(list);
            } else {
                list = (List<DiseaseMatrix>) 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.service.persistence.DiseaseMatrixPersistenceImpl.java

License:Open Source License

protected DiseaseMatrix getByOrganizationAndOrphanumber_PrevAndNext(Session session,
        DiseaseMatrix diseaseMatrix, long organizationId, String orphanumber,
        OrderByComparator orderByComparator, boolean previous) {
    StringBundler query = null;/*  w  w  w  .  j  a  va 2 s  .  c o  m*/

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

    query.append(_SQL_SELECT_DISEASEMATRIX_WHERE);

    query.append(_FINDER_COLUMN_ORGANIZATIONANDORPHANUMBER_ORGANIZATIONID_2);

    boolean bindOrphanumber = false;

    if (orphanumber == null) {
        query.append(_FINDER_COLUMN_ORGANIZATIONANDORPHANUMBER_ORPHANUMBER_1);
    } else if (orphanumber.equals(StringPool.BLANK)) {
        query.append(_FINDER_COLUMN_ORGANIZATIONANDORPHANUMBER_ORPHANUMBER_3);
    } else {
        bindOrphanumber = true;

        query.append(_FINDER_COLUMN_ORGANIZATIONANDORPHANUMBER_ORPHANUMBER_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(DiseaseMatrixModelImpl.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(organizationId);

    if (bindOrphanumber) {
        qPos.add(orphanumber);
    }

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

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

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

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

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

License:Open Source License

/**
 * Returns the number of disease matrixs where organizationId = &#63; and orphanumber = &#63;.
 *
 * @param organizationId the organization ID
 * @param orphanumber the orphanumber// ww w  .j  a v a2  s . com
 * @return the number of matching disease matrixs
 * @throws SystemException if a system exception occurred
 */
@Override
public int countByOrganizationAndOrphanumber(long organizationId, String orphanumber) throws SystemException {
    FinderPath finderPath = FINDER_PATH_COUNT_BY_ORGANIZATIONANDORPHANUMBER;

    Object[] finderArgs = new Object[] { organizationId, orphanumber };

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

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

        query.append(_SQL_COUNT_DISEASEMATRIX_WHERE);

        query.append(_FINDER_COLUMN_ORGANIZATIONANDORPHANUMBER_ORGANIZATIONID_2);

        boolean bindOrphanumber = false;

        if (orphanumber == null) {
            query.append(_FINDER_COLUMN_ORGANIZATIONANDORPHANUMBER_ORPHANUMBER_1);
        } else if (orphanumber.equals(StringPool.BLANK)) {
            query.append(_FINDER_COLUMN_ORGANIZATIONANDORPHANUMBER_ORPHANUMBER_3);
        } else {
            bindOrphanumber = true;

            query.append(_FINDER_COLUMN_ORGANIZATIONANDORPHANUMBER_ORPHANUMBER_2);
        }

        String sql = query.toString();

        Session session = null;

        try {
            session = openSession();

            Query q = session.createQuery(sql);

            QueryPos qPos = QueryPos.getInstance(q);

            qPos.add(organizationId);

            if (bindOrphanumber) {
                qPos.add(orphanumber);
            }

            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.service.persistence.ImporterConfigPersistenceImpl.java

License:Open Source License

/**
 * Returns the importer config where scope = &#63; and elementId = &#63; or returns <code>null</code> if it could not be found, optionally using the finder cache.
 *
 * @param scope the scope// w  ww. j av a  2s . co m
 * @param elementId the element ID
 * @param retrieveFromCache whether to use the finder cache
 * @return the matching importer config, or <code>null</code> if a matching importer config could not be found
 * @throws SystemException if a system exception occurred
 */
@Override
public ImporterConfig fetchByImporterConfig(String scope, String elementId, boolean retrieveFromCache)
        throws SystemException {
    Object[] finderArgs = new Object[] { scope, elementId };

    Object result = null;

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

    if (result instanceof ImporterConfig) {
        ImporterConfig importerConfig = (ImporterConfig) result;

        if (!Validator.equals(scope, importerConfig.getScope())
                || !Validator.equals(elementId, importerConfig.getElementId())) {
            result = null;
        }
    }

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

        query.append(_SQL_SELECT_IMPORTERCONFIG_WHERE);

        boolean bindScope = false;

        if (scope == null) {
            query.append(_FINDER_COLUMN_IMPORTERCONFIG_SCOPE_1);
        } else if (scope.equals(StringPool.BLANK)) {
            query.append(_FINDER_COLUMN_IMPORTERCONFIG_SCOPE_3);
        } else {
            bindScope = true;

            query.append(_FINDER_COLUMN_IMPORTERCONFIG_SCOPE_2);
        }

        boolean bindElementId = false;

        if (elementId == null) {
            query.append(_FINDER_COLUMN_IMPORTERCONFIG_ELEMENTID_1);
        } else if (elementId.equals(StringPool.BLANK)) {
            query.append(_FINDER_COLUMN_IMPORTERCONFIG_ELEMENTID_3);
        } else {
            bindElementId = true;

            query.append(_FINDER_COLUMN_IMPORTERCONFIG_ELEMENTID_2);
        }

        String sql = query.toString();

        Session session = null;

        try {
            session = openSession();

            Query q = session.createQuery(sql);

            QueryPos qPos = QueryPos.getInstance(q);

            if (bindScope) {
                qPos.add(scope);
            }

            if (bindElementId) {
                qPos.add(elementId);
            }

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

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

                ImporterConfig importerConfig = list.get(0);

                result = importerConfig;

                cacheResult(importerConfig);

                if ((importerConfig.getScope() == null) || !importerConfig.getScope().equals(scope)
                        || (importerConfig.getElementId() == null)
                        || !importerConfig.getElementId().equals(elementId)) {
                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_IMPORTERCONFIG, finderArgs, importerConfig);
                }
            }
        } catch (Exception e) {
            FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_IMPORTERCONFIG, finderArgs);

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

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

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

License:Open Source License

/**
 * Returns the number of importer configs where scope = &#63; and elementId = &#63;.
 *
 * @param scope the scope// w  w w. j a v a 2  s  .  c  o  m
 * @param elementId the element ID
 * @return the number of matching importer configs
 * @throws SystemException if a system exception occurred
 */
@Override
public int countByImporterConfig(String scope, String elementId) throws SystemException {
    FinderPath finderPath = FINDER_PATH_COUNT_BY_IMPORTERCONFIG;

    Object[] finderArgs = new Object[] { scope, elementId };

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

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

        query.append(_SQL_COUNT_IMPORTERCONFIG_WHERE);

        boolean bindScope = false;

        if (scope == null) {
            query.append(_FINDER_COLUMN_IMPORTERCONFIG_SCOPE_1);
        } else if (scope.equals(StringPool.BLANK)) {
            query.append(_FINDER_COLUMN_IMPORTERCONFIG_SCOPE_3);
        } else {
            bindScope = true;

            query.append(_FINDER_COLUMN_IMPORTERCONFIG_SCOPE_2);
        }

        boolean bindElementId = false;

        if (elementId == null) {
            query.append(_FINDER_COLUMN_IMPORTERCONFIG_ELEMENTID_1);
        } else if (elementId.equals(StringPool.BLANK)) {
            query.append(_FINDER_COLUMN_IMPORTERCONFIG_ELEMENTID_3);
        } else {
            bindElementId = true;

            query.append(_FINDER_COLUMN_IMPORTERCONFIG_ELEMENTID_2);
        }

        String sql = query.toString();

        Session session = null;

        try {
            session = openSession();

            Query q = session.createQuery(sql);

            QueryPos qPos = QueryPos.getInstance(q);

            if (bindScope) {
                qPos.add(scope);
            }

            if (bindElementId) {
                qPos.add(elementId);
            }

            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.service.persistence.InvitationPersistenceImpl.java

License:Open Source License

/**
 * Returns an ordered range of all the invitations where filter = &#63;.
 *
 * <p>/*w  ww  . j  a v a2s. co 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.service.model.impl.InvitationModelImpl}. 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 filter the filter
 * @param start the lower bound of the range of invitations
 * @param end the upper bound of the range of invitations (not inclusive)
 * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
 * @return the ordered range of matching invitations
 * @throws SystemException if a system exception occurred
 */
@Override
public List<Invitation> findByFilter(String filter, 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_FILTER;
        finderArgs = new Object[] { filter };
    } else {
        finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_FILTER;
        finderArgs = new Object[] { filter, start, end, orderByComparator };
    }

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

    if ((list != null) && !list.isEmpty()) {
        for (Invitation invitation : list) {
            if (!Validator.equals(filter, invitation.getFilter())) {
                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_INVITATION_WHERE);

        boolean bindFilter = false;

        if (filter == null) {
            query.append(_FINDER_COLUMN_FILTER_FILTER_1);
        } else if (filter.equals(StringPool.BLANK)) {
            query.append(_FINDER_COLUMN_FILTER_FILTER_3);
        } else {
            bindFilter = true;

            query.append(_FINDER_COLUMN_FILTER_FILTER_2);
        }

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

        String sql = query.toString();

        Session session = null;

        try {
            session = openSession();

            Query q = session.createQuery(sql);

            QueryPos qPos = QueryPos.getInstance(q);

            if (bindFilter) {
                qPos.add(filter);
            }

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

                Collections.sort(list);

                list = new UnmodifiableList<Invitation>(list);
            } else {
                list = (List<Invitation>) 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;
}