Search in sources :

Example 1 with Country

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;
}
Also used : Serializable(java.io.Serializable) CountryImpl(com.liferay.blade.samples.jdbcservicebuilder.model.impl.CountryImpl) Country(com.liferay.blade.samples.jdbcservicebuilder.model.Country) NoSuchCountryException(com.liferay.blade.samples.jdbcservicebuilder.exception.NoSuchCountryException) Session(com.liferay.portal.kernel.dao.orm.Session)

Example 2 with 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);
}
Also used : DynamicQuery(com.liferay.portal.kernel.dao.orm.DynamicQuery) ActionableDynamicQuery(com.liferay.portal.kernel.dao.orm.ActionableDynamicQuery) Country(com.liferay.blade.samples.jdbcservicebuilder.model.Country) Test(org.junit.Test)

Example 3 with Country

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);
}
Also used : Country(com.liferay.blade.samples.jdbcservicebuilder.model.Country) Test(org.junit.Test)

Example 4 with Country

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()));
}
Also used : Serializable(java.io.Serializable) Country(com.liferay.blade.samples.jdbcservicebuilder.model.Country) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 5 with Country

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()));
}
Also used : Serializable(java.io.Serializable) Country(com.liferay.blade.samples.jdbcservicebuilder.model.Country) HashSet(java.util.HashSet) Test(org.junit.Test)

Aggregations

Country (com.liferay.blade.samples.jdbcservicebuilder.model.Country)23 Test (org.junit.Test)13 Serializable (java.io.Serializable)5 NoSuchCountryException (com.liferay.blade.samples.jdbcservicebuilder.exception.NoSuchCountryException)4 ActionableDynamicQuery (com.liferay.portal.kernel.dao.orm.ActionableDynamicQuery)4 Session (com.liferay.portal.kernel.dao.orm.Session)4 CountryImpl (com.liferay.blade.samples.jdbcservicebuilder.model.impl.CountryImpl)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