Search in sources :

Example 6 with StringBundler

use of com.liferay.petra.string.StringBundler in project liferay-blade-samples by liferay.

the class BarPersistenceImpl method findByUuid.

/**
 * Returns an ordered range of all the bars where uuid = ?.
 *
 * <p>
 * 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 <code>QueryUtil#ALL_POS</code> 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, then the query will include the default ORDER BY logic from <code>BarModelImpl</code>.
 * </p>
 *
 * @param uuid the uuid
 * @param start the lower bound of the range of bars
 * @param end the upper bound of the range of bars (not inclusive)
 * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
 * @param useFinderCache whether to use the finder cache
 * @return the ordered range of matching bars
 */
@Override
public List<Bar> findByUuid(String uuid, int start, int end, OrderByComparator<Bar> orderByComparator, boolean useFinderCache) {
    uuid = Objects.toString(uuid, "");
    FinderPath finderPath = null;
    Object[] finderArgs = null;
    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) && (orderByComparator == null)) {
        if (useFinderCache) {
            finderPath = _finderPathWithoutPaginationFindByUuid;
            finderArgs = new Object[] { uuid };
        }
    } else if (useFinderCache) {
        finderPath = _finderPathWithPaginationFindByUuid;
        finderArgs = new Object[] { uuid, start, end, orderByComparator };
    }
    List<Bar> list = null;
    if (useFinderCache) {
        list = (List<Bar>) finderCache.getResult(finderPath, finderArgs, this);
        if ((list != null) && !list.isEmpty()) {
            for (Bar bar : list) {
                if (!uuid.equals(bar.getUuid())) {
                    list = null;
                    break;
                }
            }
        }
    }
    if (list == null) {
        StringBundler query = null;
        if (orderByComparator != null) {
            query = new StringBundler(3 + (orderByComparator.getOrderByFields().length * 2));
        } else {
            query = new StringBundler(3);
        }
        query.append(_SQL_SELECT_BAR_WHERE);
        boolean bindUuid = false;
        if (uuid.isEmpty()) {
            query.append(_FINDER_COLUMN_UUID_UUID_3);
        } else {
            bindUuid = true;
            query.append(_FINDER_COLUMN_UUID_UUID_2);
        }
        if (orderByComparator != null) {
            appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS, orderByComparator);
        } else {
            query.append(BarModelImpl.ORDER_BY_JPQL);
        }
        String sql = query.toString();
        Session session = null;
        try {
            session = openSession();
            Query q = session.createQuery(sql);
            QueryPos qPos = QueryPos.getInstance(q);
            if (bindUuid) {
                qPos.add(uuid);
            }
            list = (List<Bar>) QueryUtil.list(q, getDialect(), start, end);
            cacheResult(list);
            if (useFinderCache) {
                finderCache.putResult(finderPath, finderArgs, list);
            }
        } catch (Exception e) {
            if (useFinderCache) {
                finderCache.removeResult(finderPath, finderArgs);
            }
            throw processException(e);
        } finally {
            closeSession(session);
        }
    }
    return list;
}
Also used : Bar(com.liferay.blade.samples.servicebuilder.adq.model.Bar) Query(com.liferay.portal.kernel.dao.orm.Query) FinderPath(com.liferay.portal.kernel.dao.orm.FinderPath) QueryPos(com.liferay.portal.kernel.dao.orm.QueryPos) StringBundler(com.liferay.petra.string.StringBundler) NoSuchBarException(com.liferay.blade.samples.servicebuilder.adq.exception.NoSuchBarException) Session(com.liferay.portal.kernel.dao.orm.Session)

Example 7 with StringBundler

use of com.liferay.petra.string.StringBundler in project liferay-blade-samples by liferay.

the class BarPersistenceImpl method countByUuid_C.

/**
 * Returns the number of bars where uuid = &#63; and companyId = &#63;.
 *
 * @param uuid the uuid
 * @param companyId the company ID
 * @return the number of matching bars
 */
@Override
public int countByUuid_C(String uuid, long companyId) {
    uuid = Objects.toString(uuid, "");
    FinderPath finderPath = _finderPathCountByUuid_C;
    Object[] finderArgs = new Object[] { uuid, companyId };
    Long count = (Long) finderCache.getResult(finderPath, finderArgs, this);
    if (count == null) {
        StringBundler query = new StringBundler(3);
        query.append(_SQL_COUNT_BAR_WHERE);
        boolean bindUuid = false;
        if (uuid.isEmpty()) {
            query.append(_FINDER_COLUMN_UUID_C_UUID_3);
        } else {
            bindUuid = true;
            query.append(_FINDER_COLUMN_UUID_C_UUID_2);
        }
        query.append(_FINDER_COLUMN_UUID_C_COMPANYID_2);
        String sql = query.toString();
        Session session = null;
        try {
            session = openSession();
            Query q = session.createQuery(sql);
            QueryPos qPos = QueryPos.getInstance(q);
            if (bindUuid) {
                qPos.add(uuid);
            }
            qPos.add(companyId);
            count = (Long) q.uniqueResult();
            finderCache.putResult(finderPath, finderArgs, count);
        } catch (Exception e) {
            finderCache.removeResult(finderPath, finderArgs);
            throw processException(e);
        } finally {
            closeSession(session);
        }
    }
    return count.intValue();
}
Also used : Query(com.liferay.portal.kernel.dao.orm.Query) FinderPath(com.liferay.portal.kernel.dao.orm.FinderPath) QueryPos(com.liferay.portal.kernel.dao.orm.QueryPos) StringBundler(com.liferay.petra.string.StringBundler) NoSuchBarException(com.liferay.blade.samples.servicebuilder.adq.exception.NoSuchBarException) Session(com.liferay.portal.kernel.dao.orm.Session)

Example 8 with StringBundler

use of com.liferay.petra.string.StringBundler in project liferay-blade-samples by liferay.

the class BarPersistenceImpl method findAll.

/**
 * Returns an ordered range of all the bars.
 *
 * <p>
 * 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 <code>QueryUtil#ALL_POS</code> 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, then the query will include the default ORDER BY logic from <code>BarModelImpl</code>.
 * </p>
 *
 * @param start the lower bound of the range of bars
 * @param end the upper bound of the range of bars (not inclusive)
 * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
 * @param useFinderCache whether to use the finder cache
 * @return the ordered range of bars
 */
@Override
public List<Bar> findAll(int start, int end, OrderByComparator<Bar> orderByComparator, boolean useFinderCache) {
    FinderPath finderPath = null;
    Object[] finderArgs = null;
    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) && (orderByComparator == null)) {
        if (useFinderCache) {
            finderPath = _finderPathWithoutPaginationFindAll;
            finderArgs = FINDER_ARGS_EMPTY;
        }
    } else if (useFinderCache) {
        finderPath = _finderPathWithPaginationFindAll;
        finderArgs = new Object[] { start, end, orderByComparator };
    }
    List<Bar> list = null;
    if (useFinderCache) {
        list = (List<Bar>) finderCache.getResult(finderPath, finderArgs, this);
    }
    if (list == null) {
        StringBundler query = null;
        String sql = null;
        if (orderByComparator != null) {
            query = new StringBundler(2 + (orderByComparator.getOrderByFields().length * 2));
            query.append(_SQL_SELECT_BAR);
            appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS, orderByComparator);
            sql = query.toString();
        } else {
            sql = _SQL_SELECT_BAR;
            sql = sql.concat(BarModelImpl.ORDER_BY_JPQL);
        }
        Session session = null;
        try {
            session = openSession();
            Query q = session.createQuery(sql);
            list = (List<Bar>) QueryUtil.list(q, getDialect(), start, end);
            cacheResult(list);
            if (useFinderCache) {
                finderCache.putResult(finderPath, finderArgs, list);
            }
        } catch (Exception e) {
            if (useFinderCache) {
                finderCache.removeResult(finderPath, finderArgs);
            }
            throw processException(e);
        } finally {
            closeSession(session);
        }
    }
    return list;
}
Also used : Bar(com.liferay.blade.samples.servicebuilder.adq.model.Bar) Query(com.liferay.portal.kernel.dao.orm.Query) FinderPath(com.liferay.portal.kernel.dao.orm.FinderPath) StringBundler(com.liferay.petra.string.StringBundler) NoSuchBarException(com.liferay.blade.samples.servicebuilder.adq.exception.NoSuchBarException) Session(com.liferay.portal.kernel.dao.orm.Session)

Example 9 with StringBundler

use of com.liferay.petra.string.StringBundler in project liferay-blade-samples by liferay.

the class BarPersistenceImpl method countByUUID_G.

/**
 * Returns the number of bars where uuid = &#63; and groupId = &#63;.
 *
 * @param uuid the uuid
 * @param groupId the group ID
 * @return the number of matching bars
 */
@Override
public int countByUUID_G(String uuid, long groupId) {
    uuid = Objects.toString(uuid, "");
    FinderPath finderPath = _finderPathCountByUUID_G;
    Object[] finderArgs = new Object[] { uuid, groupId };
    Long count = (Long) finderCache.getResult(finderPath, finderArgs, this);
    if (count == null) {
        StringBundler query = new StringBundler(3);
        query.append(_SQL_COUNT_BAR_WHERE);
        boolean bindUuid = false;
        if (uuid.isEmpty()) {
            query.append(_FINDER_COLUMN_UUID_G_UUID_3);
        } else {
            bindUuid = true;
            query.append(_FINDER_COLUMN_UUID_G_UUID_2);
        }
        query.append(_FINDER_COLUMN_UUID_G_GROUPID_2);
        String sql = query.toString();
        Session session = null;
        try {
            session = openSession();
            Query q = session.createQuery(sql);
            QueryPos qPos = QueryPos.getInstance(q);
            if (bindUuid) {
                qPos.add(uuid);
            }
            qPos.add(groupId);
            count = (Long) q.uniqueResult();
            finderCache.putResult(finderPath, finderArgs, count);
        } catch (Exception e) {
            finderCache.removeResult(finderPath, finderArgs);
            throw processException(e);
        } finally {
            closeSession(session);
        }
    }
    return count.intValue();
}
Also used : Query(com.liferay.portal.kernel.dao.orm.Query) FinderPath(com.liferay.portal.kernel.dao.orm.FinderPath) QueryPos(com.liferay.portal.kernel.dao.orm.QueryPos) StringBundler(com.liferay.petra.string.StringBundler) NoSuchBarException(com.liferay.blade.samples.servicebuilder.adq.exception.NoSuchBarException) Session(com.liferay.portal.kernel.dao.orm.Session)

Example 10 with StringBundler

use of com.liferay.petra.string.StringBundler in project liferay-blade-samples by liferay.

the class BarPersistenceImpl method countByField2.

/**
 * Returns the number of bars where field2 = &#63;.
 *
 * @param field2 the field2
 * @return the number of matching bars
 */
@Override
public int countByField2(boolean field2) {
    FinderPath finderPath = _finderPathCountByField2;
    Object[] finderArgs = new Object[] { field2 };
    Long count = (Long) finderCache.getResult(finderPath, finderArgs, this);
    if (count == null) {
        StringBundler query = new StringBundler(2);
        query.append(_SQL_COUNT_BAR_WHERE);
        query.append(_FINDER_COLUMN_FIELD2_FIELD2_2);
        String sql = query.toString();
        Session session = null;
        try {
            session = openSession();
            Query q = session.createQuery(sql);
            QueryPos qPos = QueryPos.getInstance(q);
            qPos.add(field2);
            count = (Long) q.uniqueResult();
            finderCache.putResult(finderPath, finderArgs, count);
        } catch (Exception e) {
            finderCache.removeResult(finderPath, finderArgs);
            throw processException(e);
        } finally {
            closeSession(session);
        }
    }
    return count.intValue();
}
Also used : Query(com.liferay.portal.kernel.dao.orm.Query) FinderPath(com.liferay.portal.kernel.dao.orm.FinderPath) QueryPos(com.liferay.portal.kernel.dao.orm.QueryPos) StringBundler(com.liferay.petra.string.StringBundler) NoSuchBarException(com.liferay.blade.samples.servicebuilder.adq.exception.NoSuchBarException) Session(com.liferay.portal.kernel.dao.orm.Session)

Aggregations

StringBundler (com.liferay.petra.string.StringBundler)90 Query (com.liferay.portal.kernel.dao.orm.Query)45 QueryPos (com.liferay.portal.kernel.dao.orm.QueryPos)38 Session (com.liferay.portal.kernel.dao.orm.Session)35 FinderPath (com.liferay.portal.kernel.dao.orm.FinderPath)31 Foo (com.liferay.blade.basic.model.Foo)17 Bar (com.liferay.blade.samples.servicebuilder.adq.model.Bar)17 NoSuchFooException (com.liferay.blade.basic.exception.NoSuchFooException)16 NoSuchBarException (com.liferay.blade.samples.servicebuilder.adq.exception.NoSuchBarException)16 HashMap (java.util.HashMap)14 LinkedHashMap (java.util.LinkedHashMap)14 Map (java.util.Map)14 Function (java.util.function.Function)14 Qux (com.liferay.blade.workflow.asset.model.Qux)13 Baz (com.liferay.blade.workflow.basic.model.Baz)13 NoSuchQuxException (com.liferay.blade.workflow.asset.exception.NoSuchQuxException)12 NoSuchBazException (com.liferay.blade.workflow.basic.exception.NoSuchBazException)12 List (java.util.List)4 Country (com.liferay.blade.samples.dspservicebuilder.model.Country)3 Country (com.liferay.blade.samples.jdbcservicebuilder.model.Country)3