Search in sources :

Example 66 with StringBundler

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

the class CountryModelImpl method toString.

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

Example 67 with StringBundler

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

the class CountryPersistenceImpl method findAll.

/**
 * Returns an ordered range of all the countries.
 *
 * <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, then the query will include the default ORDER BY logic from <code>CountryModelImpl</code>.
 * </p>
 *
 * @param start the lower bound of the range of countries
 * @param end the upper bound of the range of countries (not inclusive)
 * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
 * @param useFinderCache whether to use the finder cache
 * @return the ordered range of countries
 */
@Override
public List<Country> findAll(int start, int end, OrderByComparator<Country> orderByComparator, boolean useFinderCache) {
    FinderPath finderPath = null;
    Object[] finderArgs = null;
    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) && (orderByComparator == null)) {
        if (useFinderCache) {
            finderPath = _finderPathWithoutPaginationFindAll;
            finderArgs = FINDER_ARGS_EMPTY;
        }
    } else if (useFinderCache) {
        finderPath = _finderPathWithPaginationFindAll;
        finderArgs = new Object[] { start, end, orderByComparator };
    }
    List<Country> list = null;
    if (useFinderCache) {
        list = (List<Country>) finderCache.getResult(finderPath, finderArgs, this);
    }
    if (list == null) {
        StringBundler sb = null;
        String sql = null;
        if (orderByComparator != null) {
            sb = new StringBundler(2 + (orderByComparator.getOrderByFields().length * 2));
            sb.append(_SQL_SELECT_COUNTRY);
            appendOrderByComparator(sb, _ORDER_BY_ENTITY_ALIAS, orderByComparator);
            sql = sb.toString();
        } else {
            sql = _SQL_SELECT_COUNTRY;
            sql = sql.concat(CountryModelImpl.ORDER_BY_JPQL);
        }
        Session session = null;
        try {
            session = openSession();
            Query query = session.createQuery(sql);
            list = (List<Country>) QueryUtil.list(query, getDialect(), start, end);
            cacheResult(list);
            if (useFinderCache) {
                finderCache.putResult(finderPath, finderArgs, list);
            }
        } catch (Exception exception) {
            if (useFinderCache) {
                finderCache.removeResult(finderPath, finderArgs);
            }
            throw processException(exception);
        } finally {
            closeSession(session);
        }
    }
    return list;
}
Also used : Query(com.liferay.portal.kernel.dao.orm.Query) FinderPath(com.liferay.portal.kernel.dao.orm.FinderPath) Country(com.liferay.blade.samples.dspservicebuilder.model.Country) StringBundler(com.liferay.petra.string.StringBundler) NoSuchCountryException(com.liferay.blade.samples.dspservicebuilder.exception.NoSuchCountryException) Session(com.liferay.portal.kernel.dao.orm.Session)

Example 68 with StringBundler

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

the class CountryCacheModel method toString.

@Override
public String toString() {
    StringBundler sb = new StringBundler(5);
    sb.append("{countryId=");
    sb.append(countryId);
    sb.append(", countryName=");
    sb.append(countryName);
    sb.append("}");
    return sb.toString();
}
Also used : StringBundler(com.liferay.petra.string.StringBundler)

Example 69 with StringBundler

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

the class CountryPersistenceImpl method findAll.

/**
 * Returns an ordered range of all the countries.
 *
 * <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, then the query will include the default ORDER BY logic from <code>CountryModelImpl</code>.
 * </p>
 *
 * @param start the lower bound of the range of countries
 * @param end the upper bound of the range of countries (not inclusive)
 * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
 * @param useFinderCache whether to use the finder cache
 * @return the ordered range of countries
 */
@Override
public List<Country> findAll(int start, int end, OrderByComparator<Country> orderByComparator, boolean useFinderCache) {
    FinderPath finderPath = null;
    Object[] finderArgs = null;
    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) && (orderByComparator == null)) {
        if (useFinderCache) {
            finderPath = _finderPathWithoutPaginationFindAll;
            finderArgs = FINDER_ARGS_EMPTY;
        }
    } else if (useFinderCache) {
        finderPath = _finderPathWithPaginationFindAll;
        finderArgs = new Object[] { start, end, orderByComparator };
    }
    List<Country> list = null;
    if (useFinderCache) {
        list = (List<Country>) 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_COUNTRY);
            appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS, orderByComparator);
            sql = query.toString();
        } else {
            sql = _SQL_SELECT_COUNTRY;
            sql = sql.concat(CountryModelImpl.ORDER_BY_JPQL);
        }
        Session session = null;
        try {
            session = openSession();
            Query q = session.createQuery(sql);
            list = (List<Country>) QueryUtil.list(q, getDialect(), start, end);
            cacheResult(list);
            if (useFinderCache) {
                finderCache.putResult(finderPath, finderArgs, list);
            }
        } catch (Exception e) {
            if (useFinderCache) {
                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) Country(com.liferay.blade.samples.jdbcservicebuilder.model.Country) StringBundler(com.liferay.petra.string.StringBundler) NoSuchCountryException(com.liferay.blade.samples.jdbcservicebuilder.exception.NoSuchCountryException) Session(com.liferay.portal.kernel.dao.orm.Session)

Example 70 with StringBundler

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

the class RegionPersistenceImpl method findAll.

/**
 * Returns an ordered range of all the regions.
 *
 * <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, then the query will include the default ORDER BY logic from <code>RegionModelImpl</code>.
 * </p>
 *
 * @param start the lower bound of the range of regions
 * @param end the upper bound of the range of regions (not inclusive)
 * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
 * @param useFinderCache whether to use the finder cache
 * @return the ordered range of regions
 */
@Override
public List<Region> findAll(int start, int end, OrderByComparator<Region> orderByComparator, boolean useFinderCache) {
    FinderPath finderPath = null;
    Object[] finderArgs = null;
    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) && (orderByComparator == null)) {
        if (useFinderCache) {
            finderPath = _finderPathWithoutPaginationFindAll;
            finderArgs = FINDER_ARGS_EMPTY;
        }
    } else if (useFinderCache) {
        finderPath = _finderPathWithPaginationFindAll;
        finderArgs = new Object[] { start, end, orderByComparator };
    }
    List<Region> list = null;
    if (useFinderCache) {
        list = (List<Region>) 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_REGION);
            appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS, orderByComparator);
            sql = query.toString();
        } else {
            sql = _SQL_SELECT_REGION;
            sql = sql.concat(RegionModelImpl.ORDER_BY_JPQL);
        }
        Session session = null;
        try {
            session = openSession();
            Query q = session.createQuery(sql);
            list = (List<Region>) QueryUtil.list(q, getDialect(), start, end);
            cacheResult(list);
            if (useFinderCache) {
                finderCache.putResult(finderPath, finderArgs, list);
            }
        } catch (Exception e) {
            if (useFinderCache) {
                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) Region(com.liferay.blade.samples.jndiservicebuilder.model.Region) StringBundler(com.liferay.petra.string.StringBundler) NoSuchRegionException(com.liferay.blade.samples.jndiservicebuilder.exception.NoSuchRegionException) 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