Search in sources :

Example 16 with Foo

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

the class FooPersistenceImpl method getByField2_PrevAndNext.

protected Foo getByField2_PrevAndNext(Session session, Foo foo, boolean field2, OrderByComparator<Foo> orderByComparator, boolean previous) {
    StringBundler query = null;
    if (orderByComparator != null) {
        query = new StringBundler(4 + (orderByComparator.getOrderByConditionFields().length * 3) + (orderByComparator.getOrderByFields().length * 3));
    } else {
        query = new StringBundler(3);
    }
    query.append(_SQL_SELECT_FOO_WHERE);
    query.append(_FINDER_COLUMN_FIELD2_FIELD2_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(FooModelImpl.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(field2);
    if (orderByComparator != null) {
        for (Object orderByConditionValue : orderByComparator.getOrderByConditionValues(foo)) {
            qPos.add(orderByConditionValue);
        }
    }
    List<Foo> list = q.list();
    if (list.size() == 2) {
        return list.get(1);
    } else {
        return null;
    }
}
Also used : Query(com.liferay.portal.kernel.dao.orm.Query) Foo(com.liferay.blade.basic.model.Foo) QueryPos(com.liferay.portal.kernel.dao.orm.QueryPos) StringBundler(com.liferay.petra.string.StringBundler)

Example 17 with Foo

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

the class FooPersistenceImpl method findByUuid_C_First.

/**
 * Returns the first foo in the ordered set where uuid = &#63; and companyId = &#63;.
 *
 * @param uuid the uuid
 * @param companyId the company ID
 * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
 * @return the first matching foo
 * @throws NoSuchFooException if a matching foo could not be found
 */
@Override
public Foo findByUuid_C_First(String uuid, long companyId, OrderByComparator<Foo> orderByComparator) throws NoSuchFooException {
    Foo foo = fetchByUuid_C_First(uuid, companyId, orderByComparator);
    if (foo != null) {
        return foo;
    }
    StringBundler msg = new StringBundler(6);
    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
    msg.append("uuid=");
    msg.append(uuid);
    msg.append(", companyId=");
    msg.append(companyId);
    msg.append("}");
    throw new NoSuchFooException(msg.toString());
}
Also used : NoSuchFooException(com.liferay.blade.basic.exception.NoSuchFooException) Foo(com.liferay.blade.basic.model.Foo) StringBundler(com.liferay.petra.string.StringBundler)

Example 18 with Foo

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

the class FooPersistenceImpl method findByUUID_G.

/**
 * Returns the foo where uuid = &#63; and groupId = &#63; or throws a <code>NoSuchFooException</code> if it could not be found.
 *
 * @param uuid the uuid
 * @param groupId the group ID
 * @return the matching foo
 * @throws NoSuchFooException if a matching foo could not be found
 */
@Override
public Foo findByUUID_G(String uuid, long groupId) throws NoSuchFooException {
    Foo foo = fetchByUUID_G(uuid, groupId);
    if (foo == null) {
        StringBundler msg = new StringBundler(6);
        msg.append(_NO_SUCH_ENTITY_WITH_KEY);
        msg.append("uuid=");
        msg.append(uuid);
        msg.append(", groupId=");
        msg.append(groupId);
        msg.append("}");
        if (_log.isDebugEnabled()) {
            _log.debug(msg.toString());
        }
        throw new NoSuchFooException(msg.toString());
    }
    return foo;
}
Also used : NoSuchFooException(com.liferay.blade.basic.exception.NoSuchFooException) Foo(com.liferay.blade.basic.model.Foo) StringBundler(com.liferay.petra.string.StringBundler)

Example 19 with Foo

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

the class FooPersistenceImpl method remove.

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

Example 20 with Foo

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

the class FooPersistenceImpl method clearCache.

@Override
public void clearCache(List<Foo> foos) {
    finderCache.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
    finderCache.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
    for (Foo foo : foos) {
        entityCache.removeResult(entityCacheEnabled, FooImpl.class, foo.getPrimaryKey());
        clearUniqueFindersCache((FooModelImpl) foo, true);
    }
}
Also used : Foo(com.liferay.blade.basic.model.Foo)

Aggregations

Foo (com.liferay.blade.basic.model.Foo)44 StringBundler (com.liferay.petra.string.StringBundler)17 NoSuchFooException (com.liferay.blade.basic.exception.NoSuchFooException)16 Test (org.junit.Test)14 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 FooImpl (com.liferay.blade.basic.model.impl.FooImpl)5 ActionableDynamicQuery (com.liferay.portal.kernel.dao.orm.ActionableDynamicQuery)5 DynamicQuery (com.liferay.portal.kernel.dao.orm.DynamicQuery)4 FinderPath (com.liferay.portal.kernel.dao.orm.FinderPath)4 Serializable (java.io.Serializable)3 Date (java.util.Date)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