Search in sources :

Example 11 with Region

use of com.liferay.blade.samples.jndiservicebuilder.model.Region 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)

Example 12 with Region

use of com.liferay.blade.samples.jndiservicebuilder.model.Region in project liferay-blade-samples by liferay.

the class RegionPersistenceImpl method remove.

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

Example 13 with Region

use of com.liferay.blade.samples.jndiservicebuilder.model.Region in project liferay-blade-samples by liferay.

the class RegionPersistenceImpl method create.

/**
 * Creates a new region with the primary key. Does not add the region to the database.
 *
 * @param regionId the primary key for the new region
 * @return the new region
 */
@Override
public Region create(long regionId) {
    Region region = new RegionImpl();
    region.setNew(true);
    region.setPrimaryKey(regionId);
    return region;
}
Also used : Region(com.liferay.blade.samples.jndiservicebuilder.model.Region) RegionImpl(com.liferay.blade.samples.jndiservicebuilder.model.impl.RegionImpl)

Example 14 with Region

use of com.liferay.blade.samples.jndiservicebuilder.model.Region in project liferay-blade-samples by liferay.

the class RegionPersistenceTest method testFetchByPrimaryKeysWithMultiplePrimaryKeysWhereAllPrimaryKeysExist.

@Test
public void testFetchByPrimaryKeysWithMultiplePrimaryKeysWhereAllPrimaryKeysExist() throws Exception {
    Region newRegion1 = addRegion();
    Region newRegion2 = addRegion();
    Set<Serializable> primaryKeys = new HashSet<Serializable>();
    primaryKeys.add(newRegion1.getPrimaryKey());
    primaryKeys.add(newRegion2.getPrimaryKey());
    Map<Serializable, Region> regions = _persistence.fetchByPrimaryKeys(primaryKeys);
    Assert.assertEquals(2, regions.size());
    Assert.assertEquals(newRegion1, regions.get(newRegion1.getPrimaryKey()));
    Assert.assertEquals(newRegion2, regions.get(newRegion2.getPrimaryKey()));
}
Also used : Serializable(java.io.Serializable) Region(com.liferay.blade.samples.jndiservicebuilder.model.Region) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 15 with Region

use of com.liferay.blade.samples.jndiservicebuilder.model.Region in project liferay-blade-samples by liferay.

the class RegionPersistenceTest method testActionableDynamicQuery.

@Test
public void testActionableDynamicQuery() throws Exception {
    final IntegerWrapper count = new IntegerWrapper();
    ActionableDynamicQuery actionableDynamicQuery = RegionLocalServiceUtil.getActionableDynamicQuery();
    actionableDynamicQuery.setPerformActionMethod(new ActionableDynamicQuery.PerformActionMethod<Region>() {

        @Override
        public void performAction(Region region) {
            Assert.assertNotNull(region);
            count.increment();
        }
    });
    actionableDynamicQuery.performActions();
    Assert.assertEquals(count.getValue(), _persistence.countAll());
}
Also used : Region(com.liferay.blade.samples.jndiservicebuilder.model.Region) IntegerWrapper(com.liferay.portal.kernel.util.IntegerWrapper) ActionableDynamicQuery(com.liferay.portal.kernel.dao.orm.ActionableDynamicQuery) Test(org.junit.Test)

Aggregations

Region (com.liferay.blade.samples.jndiservicebuilder.model.Region)23 Test (org.junit.Test)13 Serializable (java.io.Serializable)5 NoSuchRegionException (com.liferay.blade.samples.jndiservicebuilder.exception.NoSuchRegionException)4 ActionableDynamicQuery (com.liferay.portal.kernel.dao.orm.ActionableDynamicQuery)4 Session (com.liferay.portal.kernel.dao.orm.Session)4 RegionImpl (com.liferay.blade.samples.jndiservicebuilder.model.impl.RegionImpl)3 StringBundler (com.liferay.petra.string.StringBundler)3 DynamicQuery (com.liferay.portal.kernel.dao.orm.DynamicQuery)3 HashMap (java.util.HashMap)3 HashSet (java.util.HashSet)3 Query (com.liferay.portal.kernel.dao.orm.Query)2 LinkedHashMap (java.util.LinkedHashMap)2 Map (java.util.Map)2 Function (java.util.function.Function)2 FinderPath (com.liferay.portal.kernel.dao.orm.FinderPath)1 IntegerWrapper (com.liferay.portal.kernel.util.IntegerWrapper)1 StringBundler (com.liferay.portal.kernel.util.StringBundler)1 List (java.util.List)1