All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.liferay.portal.service.base.CountryLocalServiceBaseImpl Maven / Gradle / Ivy

/**
 * Copyright (c) 2000-present Liferay, Inc. All rights reserved.
 *
 * This library is free software; you can redistribute it and/or modify it under
 * the terms of the GNU Lesser General Public License as published by the Free
 * Software Foundation; either version 2.1 of the License, or (at your option)
 * any later version.
 *
 * This library is distributed in the hope that it will be useful, but WITHOUT
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
 * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
 * details.
 */

package com.liferay.portal.service.base;

import com.liferay.exportimport.kernel.lar.ExportImportHelperUtil;
import com.liferay.exportimport.kernel.lar.ManifestSummary;
import com.liferay.exportimport.kernel.lar.PortletDataContext;
import com.liferay.exportimport.kernel.lar.StagedModelDataHandlerUtil;
import com.liferay.exportimport.kernel.lar.StagedModelType;
import com.liferay.petra.sql.dsl.query.DSLQuery;
import com.liferay.portal.kernel.bean.BeanReference;
import com.liferay.portal.kernel.dao.db.DB;
import com.liferay.portal.kernel.dao.db.DBManagerUtil;
import com.liferay.portal.kernel.dao.jdbc.SqlUpdate;
import com.liferay.portal.kernel.dao.jdbc.SqlUpdateFactoryUtil;
import com.liferay.portal.kernel.dao.orm.ActionableDynamicQuery;
import com.liferay.portal.kernel.dao.orm.DefaultActionableDynamicQuery;
import com.liferay.portal.kernel.dao.orm.DynamicQuery;
import com.liferay.portal.kernel.dao.orm.DynamicQueryFactoryUtil;
import com.liferay.portal.kernel.dao.orm.ExportActionableDynamicQuery;
import com.liferay.portal.kernel.dao.orm.IndexableActionableDynamicQuery;
import com.liferay.portal.kernel.dao.orm.Projection;
import com.liferay.portal.kernel.exception.PortalException;
import com.liferay.portal.kernel.exception.SystemException;
import com.liferay.portal.kernel.log.Log;
import com.liferay.portal.kernel.log.LogFactoryUtil;
import com.liferay.portal.kernel.model.Country;
import com.liferay.portal.kernel.model.CountryLocalization;
import com.liferay.portal.kernel.model.PersistedModel;
import com.liferay.portal.kernel.module.framework.service.IdentifiableOSGiService;
import com.liferay.portal.kernel.search.Indexable;
import com.liferay.portal.kernel.search.IndexableType;
import com.liferay.portal.kernel.service.BaseLocalServiceImpl;
import com.liferay.portal.kernel.service.CountryLocalService;
import com.liferay.portal.kernel.service.CountryLocalServiceUtil;
import com.liferay.portal.kernel.service.PersistedModelLocalServiceRegistry;
import com.liferay.portal.kernel.service.persistence.BasePersistence;
import com.liferay.portal.kernel.service.persistence.CountryLocalizationPersistence;
import com.liferay.portal.kernel.service.persistence.CountryPersistence;
import com.liferay.portal.kernel.transaction.Transactional;
import com.liferay.portal.kernel.util.OrderByComparator;
import com.liferay.portal.kernel.util.PortalUtil;

import java.io.Serializable;

import java.lang.reflect.Field;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.sql.DataSource;

/**
 * Provides the base implementation for the country local service.
 *
 * 

* This implementation exists only as a container for the default service methods generated by ServiceBuilder. All custom service methods should be put in {@link com.liferay.portal.service.impl.CountryLocalServiceImpl}. *

* * @author Brian Wing Shun Chan * @see com.liferay.portal.service.impl.CountryLocalServiceImpl * @generated */ public abstract class CountryLocalServiceBaseImpl extends BaseLocalServiceImpl implements CountryLocalService, IdentifiableOSGiService { /* * NOTE FOR DEVELOPERS: * * Never modify or reference this class directly. Use CountryLocalService via injection or a org.osgi.util.tracker.ServiceTracker or use CountryLocalServiceUtil. */ /** * Adds the country to the database. Also notifies the appropriate model listeners. * *

* Important: Inspect CountryLocalServiceImpl for overloaded versions of the method. If provided, use these entry points to the API, as the implementation logic may require the additional parameters defined there. *

* * @param country the country * @return the country that was added */ @Indexable(type = IndexableType.REINDEX) @Override public Country addCountry(Country country) { country.setNew(true); return countryPersistence.update(country); } /** * 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 @Transactional(enabled = false) public Country createCountry(long countryId) { return countryPersistence.create(countryId); } /** * Deletes the country with the primary key from the database. Also notifies the appropriate model listeners. * *

* Important: Inspect CountryLocalServiceImpl for overloaded versions of the method. If provided, use these entry points to the API, as the implementation logic may require the additional parameters defined there. *

* * @param countryId the primary key of the country * @return the country that was removed * @throws PortalException if a country with the primary key could not be found */ @Indexable(type = IndexableType.DELETE) @Override public Country deleteCountry(long countryId) throws PortalException { return countryPersistence.remove(countryId); } /** * Deletes the country from the database. Also notifies the appropriate model listeners. * *

* Important: Inspect CountryLocalServiceImpl for overloaded versions of the method. If provided, use these entry points to the API, as the implementation logic may require the additional parameters defined there. *

* * @param country the country * @return the country that was removed * @throws PortalException */ @Indexable(type = IndexableType.DELETE) @Override public Country deleteCountry(Country country) throws PortalException { return countryPersistence.remove(country); } @Override public T dslQuery(DSLQuery dslQuery) { return countryPersistence.dslQuery(dslQuery); } @Override public int dslQueryCount(DSLQuery dslQuery) { Long count = dslQuery(dslQuery); return count.intValue(); } @Override public DynamicQuery dynamicQuery() { Class clazz = getClass(); return DynamicQueryFactoryUtil.forClass( Country.class, clazz.getClassLoader()); } /** * Performs a dynamic query on the database and returns the matching rows. * * @param dynamicQuery the dynamic query * @return the matching rows */ @Override public List dynamicQuery(DynamicQuery dynamicQuery) { return countryPersistence.findWithDynamicQuery(dynamicQuery); } /** * Performs a dynamic query on the database and returns a range of the matching rows. * *

* Useful when paginating results. Returns a maximum of end - start instances. start and end are not primary keys, they are indexes in the result set. Thus, 0 refers to the first result in the set. Setting both start and end to com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS will return the full result set. If orderByComparator is specified, then the query will include the given ORDER BY logic. If orderByComparator is absent, then the query will include the default ORDER BY logic from com.liferay.portal.model.impl.CountryModelImpl. *

* * @param dynamicQuery the dynamic query * @param start the lower bound of the range of model instances * @param end the upper bound of the range of model instances (not inclusive) * @return the range of matching rows */ @Override public List dynamicQuery( DynamicQuery dynamicQuery, int start, int end) { return countryPersistence.findWithDynamicQuery( dynamicQuery, start, end); } /** * Performs a dynamic query on the database and returns an ordered range of the matching rows. * *

* Useful when paginating results. Returns a maximum of end - start instances. start and end are not primary keys, they are indexes in the result set. Thus, 0 refers to the first result in the set. Setting both start and end to com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS will return the full result set. If orderByComparator is specified, then the query will include the given ORDER BY logic. If orderByComparator is absent, then the query will include the default ORDER BY logic from com.liferay.portal.model.impl.CountryModelImpl. *

* * @param dynamicQuery the dynamic query * @param start the lower bound of the range of model instances * @param end the upper bound of the range of model instances (not inclusive) * @param orderByComparator the comparator to order the results by (optionally null) * @return the ordered range of matching rows */ @Override public List dynamicQuery( DynamicQuery dynamicQuery, int start, int end, OrderByComparator orderByComparator) { return countryPersistence.findWithDynamicQuery( dynamicQuery, start, end, orderByComparator); } /** * Returns the number of rows matching the dynamic query. * * @param dynamicQuery the dynamic query * @return the number of rows matching the dynamic query */ @Override public long dynamicQueryCount(DynamicQuery dynamicQuery) { return countryPersistence.countWithDynamicQuery(dynamicQuery); } /** * Returns the number of rows matching the dynamic query. * * @param dynamicQuery the dynamic query * @param projection the projection to apply to the query * @return the number of rows matching the dynamic query */ @Override public long dynamicQueryCount( DynamicQuery dynamicQuery, Projection projection) { return countryPersistence.countWithDynamicQuery( dynamicQuery, projection); } @Override public Country fetchCountry(long countryId) { return countryPersistence.fetchByPrimaryKey(countryId); } /** * Returns the country with the matching UUID and company. * * @param uuid the country's UUID * @param companyId the primary key of the company * @return the matching country, or null if a matching country could not be found */ @Override public Country fetchCountryByUuidAndCompanyId(String uuid, long companyId) { return countryPersistence.fetchByUuid_C_First(uuid, companyId, null); } /** * Returns the country with the primary key. * * @param countryId the primary key of the country * @return the country * @throws PortalException if a country with the primary key could not be found */ @Override public Country getCountry(long countryId) throws PortalException { return countryPersistence.findByPrimaryKey(countryId); } @Override public ActionableDynamicQuery getActionableDynamicQuery() { ActionableDynamicQuery actionableDynamicQuery = new DefaultActionableDynamicQuery(); actionableDynamicQuery.setBaseLocalService(countryLocalService); actionableDynamicQuery.setClassLoader(getClassLoader()); actionableDynamicQuery.setModelClass(Country.class); actionableDynamicQuery.setPrimaryKeyPropertyName("countryId"); return actionableDynamicQuery; } @Override public IndexableActionableDynamicQuery getIndexableActionableDynamicQuery() { IndexableActionableDynamicQuery indexableActionableDynamicQuery = new IndexableActionableDynamicQuery(); indexableActionableDynamicQuery.setBaseLocalService( countryLocalService); indexableActionableDynamicQuery.setClassLoader(getClassLoader()); indexableActionableDynamicQuery.setModelClass(Country.class); indexableActionableDynamicQuery.setPrimaryKeyPropertyName("countryId"); return indexableActionableDynamicQuery; } protected void initActionableDynamicQuery( ActionableDynamicQuery actionableDynamicQuery) { actionableDynamicQuery.setBaseLocalService(countryLocalService); actionableDynamicQuery.setClassLoader(getClassLoader()); actionableDynamicQuery.setModelClass(Country.class); actionableDynamicQuery.setPrimaryKeyPropertyName("countryId"); } @Override public ExportActionableDynamicQuery getExportActionableDynamicQuery( final PortletDataContext portletDataContext) { final ExportActionableDynamicQuery exportActionableDynamicQuery = new ExportActionableDynamicQuery() { @Override public long performCount() throws PortalException { ManifestSummary manifestSummary = portletDataContext.getManifestSummary(); StagedModelType stagedModelType = getStagedModelType(); long modelAdditionCount = super.performCount(); manifestSummary.addModelAdditionCount( stagedModelType, modelAdditionCount); long modelDeletionCount = ExportImportHelperUtil.getModelDeletionCount( portletDataContext, stagedModelType); manifestSummary.addModelDeletionCount( stagedModelType, modelDeletionCount); return modelAdditionCount; } }; initActionableDynamicQuery(exportActionableDynamicQuery); exportActionableDynamicQuery.setAddCriteriaMethod( new ActionableDynamicQuery.AddCriteriaMethod() { @Override public void addCriteria(DynamicQuery dynamicQuery) { portletDataContext.addDateRangeCriteria( dynamicQuery, "modifiedDate"); } }); exportActionableDynamicQuery.setCompanyId( portletDataContext.getCompanyId()); exportActionableDynamicQuery.setPerformActionMethod( new ActionableDynamicQuery.PerformActionMethod() { @Override public void performAction(Country country) throws PortalException { StagedModelDataHandlerUtil.exportStagedModel( portletDataContext, country); } }); exportActionableDynamicQuery.setStagedModelType( new StagedModelType( PortalUtil.getClassNameId(Country.class.getName()))); return exportActionableDynamicQuery; } /** * @throws PortalException */ @Override public PersistedModel createPersistedModel(Serializable primaryKeyObj) throws PortalException { return countryPersistence.create(((Long)primaryKeyObj).longValue()); } /** * @throws PortalException */ @Override public PersistedModel deletePersistedModel(PersistedModel persistedModel) throws PortalException { if (_log.isWarnEnabled()) { _log.warn( "Implement CountryLocalServiceImpl#deleteCountry(Country) to avoid orphaned data"); } return countryLocalService.deleteCountry((Country)persistedModel); } @Override public BasePersistence getBasePersistence() { return countryPersistence; } /** * @throws PortalException */ @Override public PersistedModel getPersistedModel(Serializable primaryKeyObj) throws PortalException { return countryPersistence.findByPrimaryKey(primaryKeyObj); } /** * Returns the country with the matching UUID and company. * * @param uuid the country's UUID * @param companyId the primary key of the company * @return the matching country * @throws PortalException if a matching country could not be found */ @Override public Country getCountryByUuidAndCompanyId(String uuid, long companyId) throws PortalException { return countryPersistence.findByUuid_C_First(uuid, companyId, null); } /** * Returns a range of all the countries. * *

* Useful when paginating results. Returns a maximum of end - start instances. start and end are not primary keys, they are indexes in the result set. Thus, 0 refers to the first result in the set. Setting both start and end to com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS will return the full result set. If orderByComparator is specified, then the query will include the given ORDER BY logic. If orderByComparator is absent, then the query will include the default ORDER BY logic from com.liferay.portal.model.impl.CountryModelImpl. *

* * @param start the lower bound of the range of countries * @param end the upper bound of the range of countries (not inclusive) * @return the range of countries */ @Override public List getCountries(int start, int end) { return countryPersistence.findAll(start, end); } /** * Returns the number of countries. * * @return the number of countries */ @Override public int getCountriesCount() { return countryPersistence.countAll(); } /** * Updates the country in the database or adds it if it does not yet exist. Also notifies the appropriate model listeners. * *

* Important: Inspect CountryLocalServiceImpl for overloaded versions of the method. If provided, use these entry points to the API, as the implementation logic may require the additional parameters defined there. *

* * @param country the country * @return the country that was updated */ @Indexable(type = IndexableType.REINDEX) @Override public Country updateCountry(Country country) { return countryPersistence.update(country); } @Override public CountryLocalization fetchCountryLocalization( long countryId, String languageId) { return countryLocalizationPersistence.fetchByCountryId_LanguageId( countryId, languageId); } @Override public CountryLocalization getCountryLocalization( long countryId, String languageId) throws PortalException { return countryLocalizationPersistence.findByCountryId_LanguageId( countryId, languageId); } @Override public List getCountryLocalizations(long countryId) { return countryLocalizationPersistence.findByCountryId(countryId); } @Override public CountryLocalization updateCountryLocalization( Country country, String languageId, String title) throws PortalException { country = countryPersistence.findByPrimaryKey(country.getPrimaryKey()); CountryLocalization countryLocalization = countryLocalizationPersistence.fetchByCountryId_LanguageId( country.getCountryId(), languageId); return _updateCountryLocalization( country, countryLocalization, languageId, title); } @Override public List updateCountryLocalizations( Country country, Map titleMap) throws PortalException { country = countryPersistence.findByPrimaryKey(country.getPrimaryKey()); Map localizedValuesMap = new HashMap(); for (Map.Entry entry : titleMap.entrySet()) { String languageId = entry.getKey(); String[] localizedValues = localizedValuesMap.get(languageId); if (localizedValues == null) { localizedValues = new String[1]; localizedValuesMap.put(languageId, localizedValues); } localizedValues[0] = entry.getValue(); } List countryLocalizations = new ArrayList(localizedValuesMap.size()); for (CountryLocalization countryLocalization : countryLocalizationPersistence.findByCountryId( country.getCountryId())) { String[] localizedValues = localizedValuesMap.remove( countryLocalization.getLanguageId()); if (localizedValues == null) { countryLocalizationPersistence.remove(countryLocalization); } else { countryLocalization.setCompanyId(country.getCompanyId()); countryLocalization.setTitle(localizedValues[0]); countryLocalizations.add( countryLocalizationPersistence.update(countryLocalization)); } } long batchCounter = counterLocalService.increment( CountryLocalization.class.getName(), localizedValuesMap.size()) - localizedValuesMap.size(); for (Map.Entry entry : localizedValuesMap.entrySet()) { String languageId = entry.getKey(); String[] localizedValues = entry.getValue(); CountryLocalization countryLocalization = countryLocalizationPersistence.create(++batchCounter); countryLocalization.setCountryId(country.getCountryId()); countryLocalization.setCompanyId(country.getCompanyId()); countryLocalization.setLanguageId(languageId); countryLocalization.setTitle(localizedValues[0]); countryLocalizations.add( countryLocalizationPersistence.update(countryLocalization)); } return countryLocalizations; } private CountryLocalization _updateCountryLocalization( Country country, CountryLocalization countryLocalization, String languageId, String title) throws PortalException { if (countryLocalization == null) { long countryLocalizationId = counterLocalService.increment( CountryLocalization.class.getName()); countryLocalization = countryLocalizationPersistence.create( countryLocalizationId); countryLocalization.setCountryId(country.getCountryId()); countryLocalization.setLanguageId(languageId); } countryLocalization.setCompanyId(country.getCompanyId()); countryLocalization.setTitle(title); return countryLocalizationPersistence.update(countryLocalization); } /** * Returns the country local service. * * @return the country local service */ public CountryLocalService getCountryLocalService() { return countryLocalService; } /** * Sets the country local service. * * @param countryLocalService the country local service */ public void setCountryLocalService( CountryLocalService countryLocalService) { this.countryLocalService = countryLocalService; } /** * Returns the country persistence. * * @return the country persistence */ public CountryPersistence getCountryPersistence() { return countryPersistence; } /** * Sets the country persistence. * * @param countryPersistence the country persistence */ public void setCountryPersistence(CountryPersistence countryPersistence) { this.countryPersistence = countryPersistence; } /** * Returns the counter local service. * * @return the counter local service */ public com.liferay.counter.kernel.service.CounterLocalService getCounterLocalService() { return counterLocalService; } /** * Sets the counter local service. * * @param counterLocalService the counter local service */ public void setCounterLocalService( com.liferay.counter.kernel.service.CounterLocalService counterLocalService) { this.counterLocalService = counterLocalService; } /** * Returns the country localization persistence. * * @return the country localization persistence */ public CountryLocalizationPersistence getCountryLocalizationPersistence() { return countryLocalizationPersistence; } /** * Sets the country localization persistence. * * @param countryLocalizationPersistence the country localization persistence */ public void setCountryLocalizationPersistence( CountryLocalizationPersistence countryLocalizationPersistence) { this.countryLocalizationPersistence = countryLocalizationPersistence; } public void afterPropertiesSet() { persistedModelLocalServiceRegistry.register( "com.liferay.portal.kernel.model.Country", countryLocalService); _setLocalServiceUtilService(countryLocalService); } public void destroy() { persistedModelLocalServiceRegistry.unregister( "com.liferay.portal.kernel.model.Country"); _setLocalServiceUtilService(null); } /** * Returns the OSGi service identifier. * * @return the OSGi service identifier */ @Override public String getOSGiServiceIdentifier() { return CountryLocalService.class.getName(); } protected Class getModelClass() { return Country.class; } protected String getModelClassName() { return Country.class.getName(); } /** * Performs a SQL query. * * @param sql the sql query */ protected void runSQL(String sql) { try { DataSource dataSource = countryPersistence.getDataSource(); DB db = DBManagerUtil.getDB(); sql = db.buildSQL(sql); sql = PortalUtil.transformSQL(sql); SqlUpdate sqlUpdate = SqlUpdateFactoryUtil.getSqlUpdate( dataSource, sql); sqlUpdate.update(); } catch (Exception exception) { throw new SystemException(exception); } } private void _setLocalServiceUtilService( CountryLocalService countryLocalService) { try { Field field = CountryLocalServiceUtil.class.getDeclaredField( "_service"); field.setAccessible(true); field.set(null, countryLocalService); } catch (ReflectiveOperationException reflectiveOperationException) { throw new RuntimeException(reflectiveOperationException); } } @BeanReference(type = CountryLocalService.class) protected CountryLocalService countryLocalService; @BeanReference(type = CountryPersistence.class) protected CountryPersistence countryPersistence; @BeanReference( type = com.liferay.counter.kernel.service.CounterLocalService.class ) protected com.liferay.counter.kernel.service.CounterLocalService counterLocalService; @BeanReference(type = CountryLocalizationPersistence.class) protected CountryLocalizationPersistence countryLocalizationPersistence; private static final Log _log = LogFactoryUtil.getLog( CountryLocalServiceBaseImpl.class); @BeanReference(type = PersistedModelLocalServiceRegistry.class) protected PersistedModelLocalServiceRegistry persistedModelLocalServiceRegistry; }




© 2015 - 2025 Weber Informatics LLC | Privacy Policy