Search in sources :

Example 36 with Foo

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

the class FooModelImpl method toString.

@Override
public String toString() {
    Map<String, Function<Foo, Object>> attributeGetterFunctions = getAttributeGetterFunctions();
    StringBundler sb = new StringBundler(4 * attributeGetterFunctions.size() + 2);
    sb.append("{");
    for (Map.Entry<String, Function<Foo, Object>> entry : attributeGetterFunctions.entrySet()) {
        String attributeName = entry.getKey();
        Function<Foo, Object> attributeGetterFunction = entry.getValue();
        sb.append(attributeName);
        sb.append("=");
        sb.append(attributeGetterFunction.apply((Foo) this));
        sb.append(", ");
    }
    if (sb.index() > 1) {
        sb.setIndex(sb.index() - 1);
    }
    sb.append("}");
    return sb.toString();
}
Also used : Function(java.util.function.Function) Foo(com.liferay.blade.basic.model.Foo) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map) StringBundler(com.liferay.petra.string.StringBundler)

Example 37 with Foo

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

the class FooModelImpl method toXmlString.

@Override
public String toXmlString() {
    Map<String, Function<Foo, Object>> attributeGetterFunctions = getAttributeGetterFunctions();
    StringBundler sb = new StringBundler(5 * attributeGetterFunctions.size() + 4);
    sb.append("<model><model-name>");
    sb.append(getModelClassName());
    sb.append("</model-name>");
    for (Map.Entry<String, Function<Foo, Object>> entry : attributeGetterFunctions.entrySet()) {
        String attributeName = entry.getKey();
        Function<Foo, Object> attributeGetterFunction = entry.getValue();
        sb.append("<column><column-name>");
        sb.append(attributeName);
        sb.append("</column-name><column-value><![CDATA[");
        sb.append(attributeGetterFunction.apply((Foo) this));
        sb.append("]]></column-value></column>");
    }
    sb.append("</model>");
    return sb.toString();
}
Also used : Function(java.util.function.Function) Foo(com.liferay.blade.basic.model.Foo) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map) StringBundler(com.liferay.petra.string.StringBundler)

Example 38 with Foo

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

the class FooPersistenceImpl method findByUuid_C_PrevAndNext.

/**
 * Returns the foos before and after the current foo in the ordered set where uuid = &#63; and companyId = &#63;.
 *
 * @param fooId the primary key of the current foo
 * @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 foo
 * @throws NoSuchFooException if a foo with the primary key could not be found
 */
@Override
public Foo[] findByUuid_C_PrevAndNext(long fooId, String uuid, long companyId, OrderByComparator<Foo> orderByComparator) throws NoSuchFooException {
    uuid = Objects.toString(uuid, "");
    Foo foo = findByPrimaryKey(fooId);
    Session session = null;
    try {
        session = openSession();
        Foo[] array = new FooImpl[3];
        array[0] = getByUuid_C_PrevAndNext(session, foo, uuid, companyId, orderByComparator, true);
        array[1] = foo;
        array[2] = getByUuid_C_PrevAndNext(session, foo, uuid, companyId, orderByComparator, false);
        return array;
    } catch (Exception e) {
        throw processException(e);
    } finally {
        closeSession(session);
    }
}
Also used : 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 39 with Foo

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

the class FooPersistenceImpl method getByUuid_C_PrevAndNext.

protected Foo getByUuid_C_PrevAndNext(Session session, Foo foo, String uuid, long companyId, OrderByComparator<Foo> orderByComparator, boolean previous) {
    StringBundler query = null;
    if (orderByComparator != null) {
        query = new StringBundler(5 + (orderByComparator.getOrderByConditionFields().length * 3) + (orderByComparator.getOrderByFields().length * 3));
    } else {
        query = new StringBundler(4);
    }
    query.append(_SQL_SELECT_FOO_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);
    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);
    if (bindUuid) {
        qPos.add(uuid);
    }
    qPos.add(companyId);
    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 40 with Foo

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

the class FooPersistenceImpl method create.

/**
 * Creates a new foo with the primary key. Does not add the foo to the database.
 *
 * @param fooId the primary key for the new foo
 * @return the new foo
 */
@Override
public Foo create(long fooId) {
    Foo foo = new FooImpl();
    foo.setNew(true);
    foo.setPrimaryKey(fooId);
    String uuid = PortalUUIDUtil.generate();
    foo.setUuid(uuid);
    foo.setCompanyId(CompanyThreadLocal.getCompanyId());
    return foo;
}
Also used : Foo(com.liferay.blade.basic.model.Foo) FooImpl(com.liferay.blade.basic.model.impl.FooImpl)

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