use of com.liferay.petra.string.StringBundler 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();
}
use of com.liferay.petra.string.StringBundler 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();
}
use of com.liferay.petra.string.StringBundler in project liferay-blade-samples by liferay.
the class FooPersistenceImpl method countByUUID_G.
/**
* Returns the number of foos where uuid = ? and groupId = ?.
*
* @param uuid the uuid
* @param groupId the group ID
* @return the number of matching foos
*/
@Override
public int countByUUID_G(String uuid, long groupId) {
uuid = Objects.toString(uuid, "");
FinderPath finderPath = _finderPathCountByUUID_G;
Object[] finderArgs = new Object[] { uuid, groupId };
Long count = (Long) finderCache.getResult(finderPath, finderArgs, this);
if (count == null) {
StringBundler query = new StringBundler(3);
query.append(_SQL_COUNT_FOO_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);
count = (Long) q.uniqueResult();
finderCache.putResult(finderPath, finderArgs, count);
} catch (Exception e) {
finderCache.removeResult(finderPath, finderArgs);
throw processException(e);
} finally {
closeSession(session);
}
}
return count.intValue();
}
use of com.liferay.petra.string.StringBundler 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;
}
}
use of com.liferay.petra.string.StringBundler in project liferay-blade-samples by liferay.
the class FooPersistenceImpl method findByUuid_Last.
/**
* Returns the last foo in the ordered set where uuid = ?.
*
* @param uuid the uuid
* @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
* @return the last matching foo
* @throws NoSuchFooException if a matching foo could not be found
*/
@Override
public Foo findByUuid_Last(String uuid, OrderByComparator<Foo> orderByComparator) throws NoSuchFooException {
Foo foo = fetchByUuid_Last(uuid, orderByComparator);
if (foo != null) {
return foo;
}
StringBundler msg = new StringBundler(4);
msg.append(_NO_SUCH_ENTITY_WITH_KEY);
msg.append("uuid=");
msg.append(uuid);
msg.append("}");
throw new NoSuchFooException(msg.toString());
}
Aggregations