use of com.liferay.blade.samples.jdbcservicebuilder.model.Country in project liferay-blade-samples by liferay.
the class CountryPersistenceImpl method fetchByPrimaryKey.
/**
* Returns the country with the primary key or returns <code>null</code> if it could not be found.
*
* @param primaryKey the primary key of the country
* @return the country, or <code>null</code> if a country with the primary key could not be found
*/
@Override
public Country fetchByPrimaryKey(Serializable primaryKey) {
Serializable serializable = entityCache.getResult(CountryModelImpl.ENTITY_CACHE_ENABLED, CountryImpl.class, primaryKey);
if (serializable == nullModel) {
return null;
}
Country country = (Country) serializable;
if (country == null) {
Session session = null;
try {
session = openSession();
country = (Country) session.get(CountryImpl.class, primaryKey);
if (country != null) {
cacheResult(country);
} else {
entityCache.putResult(CountryModelImpl.ENTITY_CACHE_ENABLED, CountryImpl.class, primaryKey, nullModel);
}
} catch (Exception e) {
entityCache.removeResult(CountryModelImpl.ENTITY_CACHE_ENABLED, CountryImpl.class, primaryKey);
throw processException(e);
} finally {
closeSession(session);
}
}
return country;
}
use of com.liferay.blade.samples.jdbcservicebuilder.model.Country in project liferay-blade-samples by liferay.
the class CountryPersistenceTest method testDynamicQueryByProjectionExisting.
@Test
public void testDynamicQueryByProjectionExisting() throws Exception {
Country newCountry = addCountry();
DynamicQuery dynamicQuery = DynamicQueryFactoryUtil.forClass(Country.class, _dynamicQueryClassLoader);
dynamicQuery.setProjection(ProjectionFactoryUtil.property("countryId"));
Object newCountryId = newCountry.getCountryId();
dynamicQuery.add(RestrictionsFactoryUtil.in("countryId", new Object[] { newCountryId }));
List<Object> result = _persistence.findWithDynamicQuery(dynamicQuery);
Assert.assertEquals(1, result.size());
Object existingCountryId = result.get(0);
Assert.assertEquals(existingCountryId, newCountryId);
}
use of com.liferay.blade.samples.jdbcservicebuilder.model.Country in project liferay-blade-samples by liferay.
the class CountryPersistenceTest method testFetchByPrimaryKeyExisting.
@Test
public void testFetchByPrimaryKeyExisting() throws Exception {
Country newCountry = addCountry();
Country existingCountry = _persistence.fetchByPrimaryKey(newCountry.getPrimaryKey());
Assert.assertEquals(existingCountry, newCountry);
}
use of com.liferay.blade.samples.jdbcservicebuilder.model.Country in project liferay-blade-samples by liferay.
the class CountryPersistenceTest method testFetchByPrimaryKeysWithMultiplePrimaryKeysWhereAllPrimaryKeysExist.
@Test
public void testFetchByPrimaryKeysWithMultiplePrimaryKeysWhereAllPrimaryKeysExist() throws Exception {
Country newCountry1 = addCountry();
Country newCountry2 = addCountry();
Set<Serializable> primaryKeys = new HashSet<Serializable>();
primaryKeys.add(newCountry1.getPrimaryKey());
primaryKeys.add(newCountry2.getPrimaryKey());
Map<Serializable, Country> countries = _persistence.fetchByPrimaryKeys(primaryKeys);
Assert.assertEquals(2, countries.size());
Assert.assertEquals(newCountry1, countries.get(newCountry1.getPrimaryKey()));
Assert.assertEquals(newCountry2, countries.get(newCountry2.getPrimaryKey()));
}
use of com.liferay.blade.samples.jdbcservicebuilder.model.Country in project liferay-blade-samples by liferay.
the class CountryPersistenceTest method testFetchByPrimaryKeysWithOnePrimaryKey.
@Test
public void testFetchByPrimaryKeysWithOnePrimaryKey() throws Exception {
Country newCountry = addCountry();
Set<Serializable> primaryKeys = new HashSet<Serializable>();
primaryKeys.add(newCountry.getPrimaryKey());
Map<Serializable, Country> countries = _persistence.fetchByPrimaryKeys(primaryKeys);
Assert.assertEquals(1, countries.size());
Assert.assertEquals(newCountry, countries.get(newCountry.getPrimaryKey()));
}
Aggregations