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());
}
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);
}
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;
}
}
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;
}
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;
}
Aggregations