use of com.liferay.blade.samples.jdbcservicebuilder.model.Country in project liferay-blade-samples by liferay.
the class CountryPersistenceImpl method create.
/**
* Creates a new country with the primary key. Does not add the country to the database.
*
* @param countryId the primary key for the new country
* @return the new country
*/
@Override
public Country create(long countryId) {
Country country = new CountryImpl();
country.setNew(true);
country.setPrimaryKey(countryId);
return country;
}
use of com.liferay.blade.samples.jdbcservicebuilder.model.Country in project liferay-blade-samples by liferay.
the class CountryPersistenceImpl method fetchByPrimaryKeys.
@Override
public Map<Serializable, Country> fetchByPrimaryKeys(Set<Serializable> primaryKeys) {
if (primaryKeys.isEmpty()) {
return Collections.emptyMap();
}
Map<Serializable, Country> map = new HashMap<Serializable, Country>();
if (primaryKeys.size() == 1) {
Iterator<Serializable> iterator = primaryKeys.iterator();
Serializable primaryKey = iterator.next();
Country country = fetchByPrimaryKey(primaryKey);
if (country != null) {
map.put(primaryKey, country);
}
return map;
}
Set<Serializable> uncachedPrimaryKeys = null;
for (Serializable primaryKey : primaryKeys) {
Serializable serializable = entityCache.getResult(CountryModelImpl.ENTITY_CACHE_ENABLED, CountryImpl.class, primaryKey);
if (serializable != nullModel) {
if (serializable == null) {
if (uncachedPrimaryKeys == null) {
uncachedPrimaryKeys = new HashSet<Serializable>();
}
uncachedPrimaryKeys.add(primaryKey);
} else {
map.put(primaryKey, (Country) serializable);
}
}
}
if (uncachedPrimaryKeys == null) {
return map;
}
StringBundler query = new StringBundler((uncachedPrimaryKeys.size() * 2) + 1);
query.append(_SQL_SELECT_COUNTRY_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 (Country country : (List<Country>) q.list()) {
map.put(country.getPrimaryKeyObj(), country);
cacheResult(country);
uncachedPrimaryKeys.remove(country.getPrimaryKeyObj());
}
for (Serializable primaryKey : uncachedPrimaryKeys) {
entityCache.putResult(CountryModelImpl.ENTITY_CACHE_ENABLED, CountryImpl.class, primaryKey, nullModel);
}
} catch (Exception e) {
throw processException(e);
} finally {
closeSession(session);
}
return map;
}
use of com.liferay.blade.samples.jdbcservicebuilder.model.Country in project liferay-blade-samples by liferay.
the class CountryPersistenceTest method testDynamicQueryByPrimaryKeyExisting.
@Test
public void testDynamicQueryByPrimaryKeyExisting() throws Exception {
Country newCountry = addCountry();
DynamicQuery dynamicQuery = DynamicQueryFactoryUtil.forClass(Country.class, _dynamicQueryClassLoader);
dynamicQuery.add(RestrictionsFactoryUtil.eq("countryId", newCountry.getCountryId()));
List<Country> result = _persistence.findWithDynamicQuery(dynamicQuery);
Assert.assertEquals(1, result.size());
Country existingCountry = result.get(0);
Assert.assertEquals(existingCountry, newCountry);
}
use of com.liferay.blade.samples.jdbcservicebuilder.model.Country in project liferay-blade-samples by liferay.
the class CountryPersistenceTest method testCreate.
@Test
public void testCreate() throws Exception {
long pk = RandomTestUtil.nextLong();
Country country = _persistence.create(pk);
Assert.assertNotNull(country);
Assert.assertEquals(country.getPrimaryKey(), pk);
}
use of com.liferay.blade.samples.jdbcservicebuilder.model.Country in project liferay-blade-samples by liferay.
the class CountryPersistenceTest method testFetchByPrimaryKeyMissing.
@Test
public void testFetchByPrimaryKeyMissing() throws Exception {
long pk = RandomTestUtil.nextLong();
Country missingCountry = _persistence.fetchByPrimaryKey(pk);
Assert.assertNull(missingCountry);
}
Aggregations