Search in sources :

Example 6 with Region

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

the class RegionPersistenceTest method testUpdateExisting.

@Test
public void testUpdateExisting() throws Exception {
    long pk = RandomTestUtil.nextLong();
    Region newRegion = _persistence.create(pk);
    newRegion.setRegionName(RandomTestUtil.randomString());
    _regions.add(_persistence.update(newRegion));
    Region existingRegion = _persistence.findByPrimaryKey(newRegion.getPrimaryKey());
    Assert.assertEquals(existingRegion.getRegionId(), newRegion.getRegionId());
    Assert.assertEquals(existingRegion.getRegionName(), newRegion.getRegionName());
}
Also used : Region(com.liferay.blade.samples.jndiservicebuilder.model.Region) Test(org.junit.Test)

Example 7 with Region

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

the class RegionPersistenceTest method testDynamicQueryByPrimaryKeyExisting.

@Test
public void testDynamicQueryByPrimaryKeyExisting() throws Exception {
    Region newRegion = addRegion();
    DynamicQuery dynamicQuery = DynamicQueryFactoryUtil.forClass(Region.class, _dynamicQueryClassLoader);
    dynamicQuery.add(RestrictionsFactoryUtil.eq("regionId", newRegion.getRegionId()));
    List<Region> result = _persistence.findWithDynamicQuery(dynamicQuery);
    Assert.assertEquals(1, result.size());
    Region existingRegion = result.get(0);
    Assert.assertEquals(existingRegion, newRegion);
}
Also used : DynamicQuery(com.liferay.portal.kernel.dao.orm.DynamicQuery) ActionableDynamicQuery(com.liferay.portal.kernel.dao.orm.ActionableDynamicQuery) Region(com.liferay.blade.samples.jndiservicebuilder.model.Region) Test(org.junit.Test)

Example 8 with Region

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

the class RegionModelImpl method equals.

@Override
public boolean equals(Object obj) {
    if (this == obj) {
        return true;
    }
    if (!(obj instanceof Region)) {
        return false;
    }
    Region region = (Region) obj;
    long primaryKey = region.getPrimaryKey();
    if (getPrimaryKey() == primaryKey) {
        return true;
    } else {
        return false;
    }
}
Also used : Region(com.liferay.blade.samples.jndiservicebuilder.model.Region)

Example 9 with Region

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

the class RegionPersistenceImpl method fetchByPrimaryKey.

/**
 * Returns the region with the primary key or returns <code>null</code> if it could not be found.
 *
 * @param primaryKey the primary key of the region
 * @return the region, or <code>null</code> if a region with the primary key could not be found
 */
@Override
public Region fetchByPrimaryKey(Serializable primaryKey) {
    Serializable serializable = entityCache.getResult(RegionModelImpl.ENTITY_CACHE_ENABLED, RegionImpl.class, primaryKey);
    if (serializable == nullModel) {
        return null;
    }
    Region region = (Region) serializable;
    if (region == null) {
        Session session = null;
        try {
            session = openSession();
            region = (Region) session.get(RegionImpl.class, primaryKey);
            if (region != null) {
                cacheResult(region);
            } else {
                entityCache.putResult(RegionModelImpl.ENTITY_CACHE_ENABLED, RegionImpl.class, primaryKey, nullModel);
            }
        } catch (Exception e) {
            entityCache.removeResult(RegionModelImpl.ENTITY_CACHE_ENABLED, RegionImpl.class, primaryKey);
            throw processException(e);
        } finally {
            closeSession(session);
        }
    }
    return region;
}
Also used : Serializable(java.io.Serializable) Region(com.liferay.blade.samples.jndiservicebuilder.model.Region) 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 10 with Region

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

the class RegionPersistenceImpl method fetchByPrimaryKeys.

@Override
public Map<Serializable, Region> fetchByPrimaryKeys(Set<Serializable> primaryKeys) {
    if (primaryKeys.isEmpty()) {
        return Collections.emptyMap();
    }
    Map<Serializable, Region> map = new HashMap<Serializable, Region>();
    if (primaryKeys.size() == 1) {
        Iterator<Serializable> iterator = primaryKeys.iterator();
        Serializable primaryKey = iterator.next();
        Region region = fetchByPrimaryKey(primaryKey);
        if (region != null) {
            map.put(primaryKey, region);
        }
        return map;
    }
    Set<Serializable> uncachedPrimaryKeys = null;
    for (Serializable primaryKey : primaryKeys) {
        Serializable serializable = entityCache.getResult(RegionModelImpl.ENTITY_CACHE_ENABLED, RegionImpl.class, primaryKey);
        if (serializable != nullModel) {
            if (serializable == null) {
                if (uncachedPrimaryKeys == null) {
                    uncachedPrimaryKeys = new HashSet<Serializable>();
                }
                uncachedPrimaryKeys.add(primaryKey);
            } else {
                map.put(primaryKey, (Region) serializable);
            }
        }
    }
    if (uncachedPrimaryKeys == null) {
        return map;
    }
    StringBundler query = new StringBundler((uncachedPrimaryKeys.size() * 2) + 1);
    query.append(_SQL_SELECT_REGION_WHERE_PKS_IN);
    for (Serializable primaryKey : uncachedPrimaryKeys) {
        query.append((long) primaryKey);
        query.append(StringPool.COMMA);
    }
    query.setIndex(query.index() - 1);
    query.append(StringPool.CLOSE_PARENTHESIS);
    String sql = query.toString();
    Session session = null;
    try {
        session = openSession();
        Query q = session.createQuery(sql);
        for (Region region : (List<Region>) q.list()) {
            map.put(region.getPrimaryKeyObj(), region);
            cacheResult(region);
            uncachedPrimaryKeys.remove(region.getPrimaryKeyObj());
        }
        for (Serializable primaryKey : uncachedPrimaryKeys) {
            entityCache.putResult(RegionModelImpl.ENTITY_CACHE_ENABLED, RegionImpl.class, primaryKey, nullModel);
        }
    } catch (Exception e) {
        throw processException(e);
    } finally {
        closeSession(session);
    }
    return map;
}
Also used : Serializable(java.io.Serializable) Query(com.liferay.portal.kernel.dao.orm.Query) HashMap(java.util.HashMap) StringBundler(com.liferay.portal.kernel.util.StringBundler) NoSuchRegionException(com.liferay.blade.samples.jndiservicebuilder.exception.NoSuchRegionException) Region(com.liferay.blade.samples.jndiservicebuilder.model.Region) List(java.util.List) Session(com.liferay.portal.kernel.dao.orm.Session)

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