Search in sources :

Example 6 with Baz

use of com.liferay.blade.workflow.basic.model.Baz in project liferay-blade-samples by liferay.

the class BazPersistenceTest method testDynamicQueryByPrimaryKeyExisting.

@Test
public void testDynamicQueryByPrimaryKeyExisting() throws Exception {
    Baz newBaz = addBaz();
    DynamicQuery dynamicQuery = DynamicQueryFactoryUtil.forClass(Baz.class, _dynamicQueryClassLoader);
    dynamicQuery.add(RestrictionsFactoryUtil.eq("bazId", newBaz.getBazId()));
    List<Baz> result = _persistence.findWithDynamicQuery(dynamicQuery);
    Assert.assertEquals(1, result.size());
    Baz existingBaz = result.get(0);
    Assert.assertEquals(existingBaz, newBaz);
}
Also used : DynamicQuery(com.liferay.portal.kernel.dao.orm.DynamicQuery) ActionableDynamicQuery(com.liferay.portal.kernel.dao.orm.ActionableDynamicQuery) Baz(com.liferay.blade.workflow.basic.model.Baz) Test(org.junit.Test)

Example 7 with Baz

use of com.liferay.blade.workflow.basic.model.Baz in project liferay-blade-samples by liferay.

the class BazPersistenceImpl method fetchByUUID_G.

/**
 * Returns the baz where uuid = &#63; and groupId = &#63; or returns <code>null</code> if it could not be found, optionally using the finder cache.
 *
 * @param uuid the uuid
 * @param groupId the group ID
 * @param retrieveFromCache whether to retrieve from the finder cache
 * @return the matching baz, or <code>null</code> if a matching baz could not be found
 */
@Override
public Baz fetchByUUID_G(String uuid, long groupId, boolean retrieveFromCache) {
    uuid = Objects.toString(uuid, "");
    Object[] finderArgs = new Object[] { uuid, groupId };
    Object result = null;
    if (retrieveFromCache) {
        result = finderCache.getResult(_finderPathFetchByUUID_G, finderArgs, this);
    }
    if (result instanceof Baz) {
        Baz baz = (Baz) result;
        if (!Objects.equals(uuid, baz.getUuid()) || (groupId != baz.getGroupId())) {
            result = null;
        }
    }
    if (result == null) {
        StringBundler query = new StringBundler(4);
        query.append(_SQL_SELECT_BAZ_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);
            List<Baz> list = q.list();
            if (list.isEmpty()) {
                finderCache.putResult(_finderPathFetchByUUID_G, finderArgs, list);
            } else {
                Baz baz = list.get(0);
                result = baz;
                cacheResult(baz);
            }
        } catch (Exception e) {
            finderCache.removeResult(_finderPathFetchByUUID_G, finderArgs);
            throw processException(e);
        } finally {
            closeSession(session);
        }
    }
    if (result instanceof List<?>) {
        return null;
    } else {
        return (Baz) result;
    }
}
Also used : Query(com.liferay.portal.kernel.dao.orm.Query) Baz(com.liferay.blade.workflow.basic.model.Baz) List(java.util.List) QueryPos(com.liferay.portal.kernel.dao.orm.QueryPos) StringBundler(com.liferay.petra.string.StringBundler) NoSuchBazException(com.liferay.blade.workflow.basic.exception.NoSuchBazException) Session(com.liferay.portal.kernel.dao.orm.Session)

Example 8 with Baz

use of com.liferay.blade.workflow.basic.model.Baz in project liferay-blade-samples by liferay.

the class BazPersistenceImpl method findAll.

/**
 * Returns an ordered range of all the bazs.
 *
 * <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 and pagination is required (<code>start</code> and <code>end</code> are not <code>QueryUtil#ALL_POS</code>), then the query will include the default ORDER BY logic from <code>BazModelImpl</code>. 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 start the lower bound of the range of bazs
 * @param end the upper bound of the range of bazs (not inclusive)
 * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
 * @param retrieveFromCache whether to retrieve from the finder cache
 * @return the ordered range of bazs
 */
@Override
public List<Baz> findAll(int start, int end, OrderByComparator<Baz> orderByComparator, boolean retrieveFromCache) {
    boolean pagination = true;
    FinderPath finderPath = null;
    Object[] finderArgs = null;
    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) && (orderByComparator == null)) {
        pagination = false;
        finderPath = _finderPathWithoutPaginationFindAll;
        finderArgs = FINDER_ARGS_EMPTY;
    } else {
        finderPath = _finderPathWithPaginationFindAll;
        finderArgs = new Object[] { start, end, orderByComparator };
    }
    List<Baz> list = null;
    if (retrieveFromCache) {
        list = (List<Baz>) 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_BAZ);
            appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS, orderByComparator);
            sql = query.toString();
        } else {
            sql = _SQL_SELECT_BAZ;
            if (pagination) {
                sql = sql.concat(BazModelImpl.ORDER_BY_JPQL);
            }
        }
        Session session = null;
        try {
            session = openSession();
            Query q = session.createQuery(sql);
            if (!pagination) {
                list = (List<Baz>) QueryUtil.list(q, getDialect(), start, end, false);
                Collections.sort(list);
                list = Collections.unmodifiableList(list);
            } else {
                list = (List<Baz>) QueryUtil.list(q, getDialect(), start, end);
            }
            cacheResult(list);
            finderCache.putResult(finderPath, finderArgs, list);
        } catch (Exception e) {
            finderCache.removeResult(finderPath, finderArgs);
            throw processException(e);
        } finally {
            closeSession(session);
        }
    }
    return list;
}
Also used : Query(com.liferay.portal.kernel.dao.orm.Query) FinderPath(com.liferay.portal.kernel.dao.orm.FinderPath) Baz(com.liferay.blade.workflow.basic.model.Baz) StringBundler(com.liferay.petra.string.StringBundler) NoSuchBazException(com.liferay.blade.workflow.basic.exception.NoSuchBazException) Session(com.liferay.portal.kernel.dao.orm.Session)

Example 9 with Baz

use of com.liferay.blade.workflow.basic.model.Baz in project liferay-blade-samples by liferay.

the class BazPersistenceImpl method remove.

/**
 * Removes the baz with the primary key from the database. Also notifies the appropriate model listeners.
 *
 * @param primaryKey the primary key of the baz
 * @return the baz that was removed
 * @throws NoSuchBazException if a baz with the primary key could not be found
 */
@Override
public Baz remove(Serializable primaryKey) throws NoSuchBazException {
    Session session = null;
    try {
        session = openSession();
        Baz baz = (Baz) session.get(BazImpl.class, primaryKey);
        if (baz == null) {
            if (_log.isDebugEnabled()) {
                _log.debug(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + primaryKey);
            }
            throw new NoSuchBazException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + primaryKey);
        }
        return remove(baz);
    } catch (NoSuchBazException nsee) {
        throw nsee;
    } catch (Exception e) {
        throw processException(e);
    } finally {
        closeSession(session);
    }
}
Also used : BazImpl(com.liferay.blade.workflow.basic.model.impl.BazImpl) Baz(com.liferay.blade.workflow.basic.model.Baz) NoSuchBazException(com.liferay.blade.workflow.basic.exception.NoSuchBazException) NoSuchBazException(com.liferay.blade.workflow.basic.exception.NoSuchBazException) Session(com.liferay.portal.kernel.dao.orm.Session)

Example 10 with Baz

use of com.liferay.blade.workflow.basic.model.Baz in project liferay-blade-samples by liferay.

the class BazPersistenceImpl method findByUuid_PrevAndNext.

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

Aggregations

Baz (com.liferay.blade.workflow.basic.model.Baz)39 Test (org.junit.Test)14 StringBundler (com.liferay.petra.string.StringBundler)13 NoSuchBazException (com.liferay.blade.workflow.basic.exception.NoSuchBazException)12 Session (com.liferay.portal.kernel.dao.orm.Session)7 Query (com.liferay.portal.kernel.dao.orm.Query)6 ActionableDynamicQuery (com.liferay.portal.kernel.dao.orm.ActionableDynamicQuery)5 QueryPos (com.liferay.portal.kernel.dao.orm.QueryPos)5 BazImpl (com.liferay.blade.workflow.basic.model.impl.BazImpl)4 DynamicQuery (com.liferay.portal.kernel.dao.orm.DynamicQuery)4 FinderPath (com.liferay.portal.kernel.dao.orm.FinderPath)3 Serializable (java.io.Serializable)3 HashSet (java.util.HashSet)3 User (com.liferay.portal.kernel.model.User)2 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 StagedModelDataHandler (com.liferay.exportimport.kernel.lar.StagedModelDataHandler)1