Search in sources :

Example 11 with Bar

use of com.liferay.blade.samples.servicebuilder.adq.model.Bar 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 12 with Bar

use of com.liferay.blade.samples.servicebuilder.adq.model.Bar in project liferay-blade-samples by liferay.

the class BarPersistenceImpl method findByUuid_PrevAndNext.

/**
 * Returns the bars before and after the current bar in the ordered set where uuid = &#63;.
 *
 * @param barId the primary key of the current bar
 * @param uuid the uuid
 * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
 * @return the previous, current, and next bar
 * @throws NoSuchBarException if a bar with the primary key could not be found
 */
@Override
public Bar[] findByUuid_PrevAndNext(long barId, String uuid, OrderByComparator<Bar> orderByComparator) throws NoSuchBarException {
    uuid = Objects.toString(uuid, "");
    Bar bar = findByPrimaryKey(barId);
    Session session = null;
    try {
        session = openSession();
        Bar[] array = new BarImpl[3];
        array[0] = getByUuid_PrevAndNext(session, bar, uuid, orderByComparator, true);
        array[1] = bar;
        array[2] = getByUuid_PrevAndNext(session, bar, uuid, orderByComparator, false);
        return array;
    } catch (Exception e) {
        throw processException(e);
    } finally {
        closeSession(session);
    }
}
Also used : Bar(com.liferay.blade.samples.servicebuilder.adq.model.Bar) BarImpl(com.liferay.blade.samples.servicebuilder.adq.model.impl.BarImpl) NoSuchBarException(com.liferay.blade.samples.servicebuilder.adq.exception.NoSuchBarException) Session(com.liferay.portal.kernel.dao.orm.Session)

Example 13 with Bar

use of com.liferay.blade.samples.servicebuilder.adq.model.Bar in project liferay-blade-samples by liferay.

the class BarPersistenceImpl method findByUuid_C_PrevAndNext.

/**
 * Returns the bars before and after the current bar in the ordered set where uuid = &#63; and companyId = &#63;.
 *
 * @param barId the primary key of the current bar
 * @param uuid the uuid
 * @param companyId the company ID
 * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
 * @return the previous, current, and next bar
 * @throws NoSuchBarException if a bar with the primary key could not be found
 */
@Override
public Bar[] findByUuid_C_PrevAndNext(long barId, String uuid, long companyId, OrderByComparator<Bar> orderByComparator) throws NoSuchBarException {
    uuid = Objects.toString(uuid, "");
    Bar bar = findByPrimaryKey(barId);
    Session session = null;
    try {
        session = openSession();
        Bar[] array = new BarImpl[3];
        array[0] = getByUuid_C_PrevAndNext(session, bar, uuid, companyId, orderByComparator, true);
        array[1] = bar;
        array[2] = getByUuid_C_PrevAndNext(session, bar, uuid, companyId, orderByComparator, false);
        return array;
    } catch (Exception e) {
        throw processException(e);
    } finally {
        closeSession(session);
    }
}
Also used : Bar(com.liferay.blade.samples.servicebuilder.adq.model.Bar) BarImpl(com.liferay.blade.samples.servicebuilder.adq.model.impl.BarImpl) NoSuchBarException(com.liferay.blade.samples.servicebuilder.adq.exception.NoSuchBarException) Session(com.liferay.portal.kernel.dao.orm.Session)

Example 14 with Bar

use of com.liferay.blade.samples.servicebuilder.adq.model.Bar in project liferay-blade-samples by liferay.

the class BarPersistenceImpl method findByField2_PrevAndNext.

/**
 * Returns the bars before and after the current bar in the ordered set where field2 = &#63;.
 *
 * @param barId the primary key of the current bar
 * @param field2 the field2
 * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
 * @return the previous, current, and next bar
 * @throws NoSuchBarException if a bar with the primary key could not be found
 */
@Override
public Bar[] findByField2_PrevAndNext(long barId, boolean field2, OrderByComparator<Bar> orderByComparator) throws NoSuchBarException {
    Bar bar = findByPrimaryKey(barId);
    Session session = null;
    try {
        session = openSession();
        Bar[] array = new BarImpl[3];
        array[0] = getByField2_PrevAndNext(session, bar, field2, orderByComparator, true);
        array[1] = bar;
        array[2] = getByField2_PrevAndNext(session, bar, field2, orderByComparator, false);
        return array;
    } catch (Exception e) {
        throw processException(e);
    } finally {
        closeSession(session);
    }
}
Also used : Bar(com.liferay.blade.samples.servicebuilder.adq.model.Bar) BarImpl(com.liferay.blade.samples.servicebuilder.adq.model.impl.BarImpl) NoSuchBarException(com.liferay.blade.samples.servicebuilder.adq.exception.NoSuchBarException) Session(com.liferay.portal.kernel.dao.orm.Session)

Example 15 with Bar

use of com.liferay.blade.samples.servicebuilder.adq.model.Bar in project liferay-blade-samples by liferay.

the class BarPersistenceTest method testFetchByPrimaryKeysWithOnePrimaryKey.

@Test
public void testFetchByPrimaryKeysWithOnePrimaryKey() throws Exception {
    Bar newBar = addBar();
    Set<Serializable> primaryKeys = new HashSet<Serializable>();
    primaryKeys.add(newBar.getPrimaryKey());
    Map<Serializable, Bar> bars = _persistence.fetchByPrimaryKeys(primaryKeys);
    Assert.assertEquals(1, bars.size());
    Assert.assertEquals(newBar, bars.get(newBar.getPrimaryKey()));
}
Also used : Bar(com.liferay.blade.samples.servicebuilder.adq.model.Bar) Serializable(java.io.Serializable) HashSet(java.util.HashSet) Test(org.junit.Test)

Aggregations

Bar (com.liferay.blade.samples.servicebuilder.adq.model.Bar)44 StringBundler (com.liferay.petra.string.StringBundler)17 NoSuchBarException (com.liferay.blade.samples.servicebuilder.adq.exception.NoSuchBarException)16 Test (org.junit.Test)15 Session (com.liferay.portal.kernel.dao.orm.Session)9 Query (com.liferay.portal.kernel.dao.orm.Query)8 QueryPos (com.liferay.portal.kernel.dao.orm.QueryPos)7 ActionableDynamicQuery (com.liferay.portal.kernel.dao.orm.ActionableDynamicQuery)6 BarImpl (com.liferay.blade.samples.servicebuilder.adq.model.impl.BarImpl)5 DynamicQuery (com.liferay.portal.kernel.dao.orm.DynamicQuery)5 FinderPath (com.liferay.portal.kernel.dao.orm.FinderPath)4 Serializable (java.io.Serializable)3 HashSet (java.util.HashSet)3 HashMap (java.util.HashMap)2 LinkedHashMap (java.util.LinkedHashMap)2 Map (java.util.Map)2 Function (java.util.function.Function)2 ManifestSummary (com.liferay.exportimport.kernel.lar.ManifestSummary)1 StagedModelType (com.liferay.exportimport.kernel.lar.StagedModelType)1 DefaultActionableDynamicQuery (com.liferay.portal.kernel.dao.orm.DefaultActionableDynamicQuery)1