001 /** 002 * Copyright (c) 2000-present Liferay, Inc. All rights reserved. 003 * 004 * This library is free software; you can redistribute it and/or modify it under 005 * the terms of the GNU Lesser General Public License as published by the Free 006 * Software Foundation; either version 2.1 of the License, or (at your option) 007 * any later version. 008 * 009 * This library is distributed in the hope that it will be useful, but WITHOUT 010 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS 011 * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more 012 * details. 013 */ 014 015 package com.liferay.counter.service.base; 016 017 import aQute.bnd.annotation.ProviderType; 018 019 import com.liferay.counter.model.Counter; 020 import com.liferay.counter.service.CounterLocalService; 021 import com.liferay.counter.service.persistence.CounterFinder; 022 import com.liferay.counter.service.persistence.CounterPersistence; 023 024 import com.liferay.portal.kernel.bean.BeanReference; 025 import com.liferay.portal.kernel.dao.db.DB; 026 import com.liferay.portal.kernel.dao.db.DBManagerUtil; 027 import com.liferay.portal.kernel.dao.jdbc.SqlUpdate; 028 import com.liferay.portal.kernel.dao.jdbc.SqlUpdateFactoryUtil; 029 import com.liferay.portal.kernel.dao.orm.DynamicQuery; 030 import com.liferay.portal.kernel.dao.orm.DynamicQueryFactoryUtil; 031 import com.liferay.portal.kernel.dao.orm.Projection; 032 import com.liferay.portal.kernel.exception.PortalException; 033 import com.liferay.portal.kernel.exception.SystemException; 034 import com.liferay.portal.kernel.module.framework.service.IdentifiableOSGiService; 035 import com.liferay.portal.kernel.search.Indexable; 036 import com.liferay.portal.kernel.search.IndexableType; 037 import com.liferay.portal.kernel.util.OrderByComparator; 038 import com.liferay.portal.model.PersistedModel; 039 import com.liferay.portal.service.BaseLocalServiceImpl; 040 import com.liferay.portal.service.PersistedModelLocalServiceRegistry; 041 import com.liferay.portal.util.PortalUtil; 042 043 import java.io.Serializable; 044 045 import java.util.List; 046 047 import javax.sql.DataSource; 048 049 /** 050 * Provides the base implementation for the counter local service. 051 * 052 * <p> 053 * 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.counter.service.impl.CounterLocalServiceImpl}. 054 * </p> 055 * 056 * @author Brian Wing Shun Chan 057 * @see com.liferay.counter.service.impl.CounterLocalServiceImpl 058 * @see com.liferay.counter.service.CounterLocalServiceUtil 059 * @generated 060 */ 061 @ProviderType 062 public abstract class CounterLocalServiceBaseImpl extends BaseLocalServiceImpl 063 implements CounterLocalService, IdentifiableOSGiService { 064 /* 065 * NOTE FOR DEVELOPERS: 066 * 067 * Never modify or reference this class directly. Always use {@link com.liferay.counter.service.CounterLocalServiceUtil} to access the counter local service. 068 */ 069 070 /** 071 * Adds the counter to the database. Also notifies the appropriate model listeners. 072 * 073 * @param counter the counter 074 * @return the counter that was added 075 */ 076 @Indexable(type = IndexableType.REINDEX) 077 @Override 078 public Counter addCounter(Counter counter) { 079 counter.setNew(true); 080 081 return counterPersistence.update(counter); 082 } 083 084 /** 085 * Creates a new counter with the primary key. Does not add the counter to the database. 086 * 087 * @param name the primary key for the new counter 088 * @return the new counter 089 */ 090 @Override 091 public Counter createCounter(String name) { 092 return counterPersistence.create(name); 093 } 094 095 /** 096 * Deletes the counter with the primary key from the database. Also notifies the appropriate model listeners. 097 * 098 * @param name the primary key of the counter 099 * @return the counter that was removed 100 * @throws PortalException if a counter with the primary key could not be found 101 */ 102 @Indexable(type = IndexableType.DELETE) 103 @Override 104 public Counter deleteCounter(String name) throws PortalException { 105 return counterPersistence.remove(name); 106 } 107 108 /** 109 * Deletes the counter from the database. Also notifies the appropriate model listeners. 110 * 111 * @param counter the counter 112 * @return the counter that was removed 113 */ 114 @Indexable(type = IndexableType.DELETE) 115 @Override 116 public Counter deleteCounter(Counter counter) { 117 return counterPersistence.remove(counter); 118 } 119 120 @Override 121 public DynamicQuery dynamicQuery() { 122 Class<?> clazz = getClass(); 123 124 return DynamicQueryFactoryUtil.forClass(Counter.class, 125 clazz.getClassLoader()); 126 } 127 128 /** 129 * Performs a dynamic query on the database and returns the matching rows. 130 * 131 * @param dynamicQuery the dynamic query 132 * @return the matching rows 133 */ 134 @Override 135 public <T> List<T> dynamicQuery(DynamicQuery dynamicQuery) { 136 return counterPersistence.findWithDynamicQuery(dynamicQuery); 137 } 138 139 /** 140 * Performs a dynamic query on the database and returns a range of the matching rows. 141 * 142 * <p> 143 * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.counter.model.impl.CounterModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order. 144 * </p> 145 * 146 * @param dynamicQuery the dynamic query 147 * @param start the lower bound of the range of model instances 148 * @param end the upper bound of the range of model instances (not inclusive) 149 * @return the range of matching rows 150 */ 151 @Override 152 public <T> List<T> dynamicQuery(DynamicQuery dynamicQuery, int start, 153 int end) { 154 return counterPersistence.findWithDynamicQuery(dynamicQuery, start, end); 155 } 156 157 /** 158 * Performs a dynamic query on the database and returns an ordered range of the matching rows. 159 * 160 * <p> 161 * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.counter.model.impl.CounterModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order. 162 * </p> 163 * 164 * @param dynamicQuery the dynamic query 165 * @param start the lower bound of the range of model instances 166 * @param end the upper bound of the range of model instances (not inclusive) 167 * @param orderByComparator the comparator to order the results by (optionally <code>null</code>) 168 * @return the ordered range of matching rows 169 */ 170 @Override 171 public <T> List<T> dynamicQuery(DynamicQuery dynamicQuery, int start, 172 int end, OrderByComparator<T> orderByComparator) { 173 return counterPersistence.findWithDynamicQuery(dynamicQuery, start, 174 end, orderByComparator); 175 } 176 177 /** 178 * Returns the number of rows matching the dynamic query. 179 * 180 * @param dynamicQuery the dynamic query 181 * @return the number of rows matching the dynamic query 182 */ 183 @Override 184 public long dynamicQueryCount(DynamicQuery dynamicQuery) { 185 return counterPersistence.countWithDynamicQuery(dynamicQuery); 186 } 187 188 /** 189 * Returns the number of rows matching the dynamic query. 190 * 191 * @param dynamicQuery the dynamic query 192 * @param projection the projection to apply to the query 193 * @return the number of rows matching the dynamic query 194 */ 195 @Override 196 public long dynamicQueryCount(DynamicQuery dynamicQuery, 197 Projection projection) { 198 return counterPersistence.countWithDynamicQuery(dynamicQuery, projection); 199 } 200 201 @Override 202 public Counter fetchCounter(String name) { 203 return counterPersistence.fetchByPrimaryKey(name); 204 } 205 206 /** 207 * Returns the counter with the primary key. 208 * 209 * @param name the primary key of the counter 210 * @return the counter 211 * @throws PortalException if a counter with the primary key could not be found 212 */ 213 @Override 214 public Counter getCounter(String name) throws PortalException { 215 return counterPersistence.findByPrimaryKey(name); 216 } 217 218 /** 219 * @throws PortalException 220 */ 221 @Override 222 public PersistedModel deletePersistedModel(PersistedModel persistedModel) 223 throws PortalException { 224 return counterLocalService.deleteCounter((Counter)persistedModel); 225 } 226 227 @Override 228 public PersistedModel getPersistedModel(Serializable primaryKeyObj) 229 throws PortalException { 230 return counterPersistence.findByPrimaryKey(primaryKeyObj); 231 } 232 233 /** 234 * Returns a range of all the counters. 235 * 236 * <p> 237 * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.counter.model.impl.CounterModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order. 238 * </p> 239 * 240 * @param start the lower bound of the range of counters 241 * @param end the upper bound of the range of counters (not inclusive) 242 * @return the range of counters 243 */ 244 @Override 245 public List<Counter> getCounters(int start, int end) { 246 return counterPersistence.findAll(start, end); 247 } 248 249 /** 250 * Returns the number of counters. 251 * 252 * @return the number of counters 253 */ 254 @Override 255 public int getCountersCount() { 256 return counterPersistence.countAll(); 257 } 258 259 /** 260 * Updates the counter in the database or adds it if it does not yet exist. Also notifies the appropriate model listeners. 261 * 262 * @param counter the counter 263 * @return the counter that was updated 264 */ 265 @Indexable(type = IndexableType.REINDEX) 266 @Override 267 public Counter updateCounter(Counter counter) { 268 return counterPersistence.update(counter); 269 } 270 271 /** 272 * Returns the counter local service. 273 * 274 * @return the counter local service 275 */ 276 public CounterLocalService getCounterLocalService() { 277 return counterLocalService; 278 } 279 280 /** 281 * Sets the counter local service. 282 * 283 * @param counterLocalService the counter local service 284 */ 285 public void setCounterLocalService(CounterLocalService counterLocalService) { 286 this.counterLocalService = counterLocalService; 287 } 288 289 /** 290 * Returns the counter persistence. 291 * 292 * @return the counter persistence 293 */ 294 public CounterPersistence getCounterPersistence() { 295 return counterPersistence; 296 } 297 298 /** 299 * Sets the counter persistence. 300 * 301 * @param counterPersistence the counter persistence 302 */ 303 public void setCounterPersistence(CounterPersistence counterPersistence) { 304 this.counterPersistence = counterPersistence; 305 } 306 307 /** 308 * Returns the counter finder. 309 * 310 * @return the counter finder 311 */ 312 public CounterFinder getCounterFinder() { 313 return counterFinder; 314 } 315 316 /** 317 * Sets the counter finder. 318 * 319 * @param counterFinder the counter finder 320 */ 321 public void setCounterFinder(CounterFinder counterFinder) { 322 this.counterFinder = counterFinder; 323 } 324 325 public void afterPropertiesSet() { 326 persistedModelLocalServiceRegistry.register("com.liferay.counter.model.Counter", 327 counterLocalService); 328 } 329 330 public void destroy() { 331 persistedModelLocalServiceRegistry.unregister( 332 "com.liferay.counter.model.Counter"); 333 } 334 335 /** 336 * Returns the OSGi service identifier. 337 * 338 * @return the OSGi service identifier 339 */ 340 @Override 341 public String getOSGiServiceIdentifier() { 342 return CounterLocalService.class.getName(); 343 } 344 345 protected Class<?> getModelClass() { 346 return Counter.class; 347 } 348 349 protected String getModelClassName() { 350 return Counter.class.getName(); 351 } 352 353 /** 354 * Performs a SQL query. 355 * 356 * @param sql the sql query 357 */ 358 protected void runSQL(String sql) { 359 try { 360 DataSource dataSource = counterPersistence.getDataSource(); 361 362 DB db = DBManagerUtil.getDB(); 363 364 sql = db.buildSQL(sql); 365 sql = PortalUtil.transformSQL(sql); 366 367 SqlUpdate sqlUpdate = SqlUpdateFactoryUtil.getSqlUpdate(dataSource, 368 sql, new int[0]); 369 370 sqlUpdate.update(); 371 } 372 catch (Exception e) { 373 throw new SystemException(e); 374 } 375 } 376 377 @BeanReference(type = com.liferay.counter.service.CounterLocalService.class) 378 protected CounterLocalService counterLocalService; 379 @BeanReference(type = CounterPersistence.class) 380 protected CounterPersistence counterPersistence; 381 @BeanReference(type = CounterFinder.class) 382 protected CounterFinder counterFinder; 383 @BeanReference(type = PersistedModelLocalServiceRegistry.class) 384 protected PersistedModelLocalServiceRegistry persistedModelLocalServiceRegistry; 385 }