Search in sources :

Example 1 with StringBundler

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

the class BarCacheModel method toString.

@Override
public String toString() {
    StringBundler sb = new StringBundler(27);
    sb.append("{uuid=");
    sb.append(uuid);
    sb.append(", barId=");
    sb.append(barId);
    sb.append(", groupId=");
    sb.append(groupId);
    sb.append(", companyId=");
    sb.append(companyId);
    sb.append(", userId=");
    sb.append(userId);
    sb.append(", userName=");
    sb.append(userName);
    sb.append(", createDate=");
    sb.append(createDate);
    sb.append(", modifiedDate=");
    sb.append(modifiedDate);
    sb.append(", field1=");
    sb.append(field1);
    sb.append(", field2=");
    sb.append(field2);
    sb.append(", field3=");
    sb.append(field3);
    sb.append(", field4=");
    sb.append(field4);
    sb.append(", field5=");
    sb.append(field5);
    sb.append("}");
    return sb.toString();
}
Also used : StringBundler(com.liferay.petra.string.StringBundler)

Example 2 with StringBundler

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

the class BarModelImpl method toXmlString.

@Override
public String toXmlString() {
    Map<String, Function<Bar, 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<Bar, Object>> entry : attributeGetterFunctions.entrySet()) {
        String attributeName = entry.getKey();
        Function<Bar, Object> attributeGetterFunction = entry.getValue();
        sb.append("<column><column-name>");
        sb.append(attributeName);
        sb.append("</column-name><column-value><![CDATA[");
        sb.append(attributeGetterFunction.apply((Bar) this));
        sb.append("]]></column-value></column>");
    }
    sb.append("</model>");
    return sb.toString();
}
Also used : Function(java.util.function.Function) Bar(com.liferay.blade.samples.servicebuilder.adq.model.Bar) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map) StringBundler(com.liferay.petra.string.StringBundler)

Example 3 with StringBundler

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

the class BarModelImpl method toString.

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

Example 4 with StringBundler

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

the class BarPersistenceImpl method findByUuid_Last.

/**
 * Returns the last bar in the ordered set where uuid = &#63;.
 *
 * @param uuid the uuid
 * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
 * @return the last matching bar
 * @throws NoSuchBarException if a matching bar could not be found
 */
@Override
public Bar findByUuid_Last(String uuid, OrderByComparator<Bar> orderByComparator) throws NoSuchBarException {
    Bar bar = fetchByUuid_Last(uuid, orderByComparator);
    if (bar != null) {
        return bar;
    }
    StringBundler msg = new StringBundler(4);
    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
    msg.append("uuid=");
    msg.append(uuid);
    msg.append("}");
    throw new NoSuchBarException(msg.toString());
}
Also used : Bar(com.liferay.blade.samples.servicebuilder.adq.model.Bar) NoSuchBarException(com.liferay.blade.samples.servicebuilder.adq.exception.NoSuchBarException) StringBundler(com.liferay.petra.string.StringBundler)

Example 5 with StringBundler

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

the class BarPersistenceImpl method fetchByUUID_G.

/**
 * Returns the bar 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 useFinderCache whether to use the finder cache
 * @return the matching bar, or <code>null</code> if a matching bar could not be found
 */
@Override
public Bar fetchByUUID_G(String uuid, long groupId, boolean useFinderCache) {
    uuid = Objects.toString(uuid, "");
    Object[] finderArgs = null;
    if (useFinderCache) {
        finderArgs = new Object[] { uuid, groupId };
    }
    Object result = null;
    if (useFinderCache) {
        result = finderCache.getResult(_finderPathFetchByUUID_G, finderArgs, this);
    }
    if (result instanceof Bar) {
        Bar bar = (Bar) result;
        if (!Objects.equals(uuid, bar.getUuid()) || (groupId != bar.getGroupId())) {
            result = null;
        }
    }
    if (result == null) {
        StringBundler query = new StringBundler(4);
        query.append(_SQL_SELECT_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);
            List<Bar> list = q.list();
            if (list.isEmpty()) {
                if (useFinderCache) {
                    finderCache.putResult(_finderPathFetchByUUID_G, finderArgs, list);
                }
            } else {
                Bar bar = list.get(0);
                result = bar;
                cacheResult(bar);
            }
        } catch (Exception e) {
            if (useFinderCache) {
                finderCache.removeResult(_finderPathFetchByUUID_G, finderArgs);
            }
            throw processException(e);
        } finally {
            closeSession(session);
        }
    }
    if (result instanceof List<?>) {
        return null;
    } else {
        return (Bar) result;
    }
}
Also used : Bar(com.liferay.blade.samples.servicebuilder.adq.model.Bar) Query(com.liferay.portal.kernel.dao.orm.Query) List(java.util.List) 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