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.portal.service.base; 016 017 import aQute.bnd.annotation.ProviderType; 018 019 import com.liferay.portal.kernel.bean.BeanReference; 020 import com.liferay.portal.kernel.bean.IdentifiableBean; 021 import com.liferay.portal.kernel.dao.db.DB; 022 import com.liferay.portal.kernel.dao.db.DBFactoryUtil; 023 import com.liferay.portal.kernel.dao.jdbc.SqlUpdate; 024 import com.liferay.portal.kernel.dao.jdbc.SqlUpdateFactoryUtil; 025 import com.liferay.portal.kernel.dao.orm.ActionableDynamicQuery; 026 import com.liferay.portal.kernel.dao.orm.DefaultActionableDynamicQuery; 027 import com.liferay.portal.kernel.dao.orm.DynamicQuery; 028 import com.liferay.portal.kernel.dao.orm.DynamicQueryFactoryUtil; 029 import com.liferay.portal.kernel.dao.orm.Projection; 030 import com.liferay.portal.kernel.exception.PortalException; 031 import com.liferay.portal.kernel.exception.SystemException; 032 import com.liferay.portal.kernel.search.Indexable; 033 import com.liferay.portal.kernel.search.IndexableType; 034 import com.liferay.portal.kernel.util.OrderByComparator; 035 import com.liferay.portal.model.Account; 036 import com.liferay.portal.model.PersistedModel; 037 import com.liferay.portal.service.AccountLocalService; 038 import com.liferay.portal.service.BaseLocalServiceImpl; 039 import com.liferay.portal.service.PersistedModelLocalServiceRegistry; 040 import com.liferay.portal.service.persistence.AccountPersistence; 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 account 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.portal.service.impl.AccountLocalServiceImpl}. 054 * </p> 055 * 056 * @author Brian Wing Shun Chan 057 * @see com.liferay.portal.service.impl.AccountLocalServiceImpl 058 * @see com.liferay.portal.service.AccountLocalServiceUtil 059 * @generated 060 */ 061 @ProviderType 062 public abstract class AccountLocalServiceBaseImpl extends BaseLocalServiceImpl 063 implements AccountLocalService, IdentifiableBean { 064 /* 065 * NOTE FOR DEVELOPERS: 066 * 067 * Never modify or reference this class directly. Always use {@link com.liferay.portal.service.AccountLocalServiceUtil} to access the account local service. 068 */ 069 070 /** 071 * Adds the account to the database. Also notifies the appropriate model listeners. 072 * 073 * @param account the account 074 * @return the account that was added 075 */ 076 @Indexable(type = IndexableType.REINDEX) 077 @Override 078 public Account addAccount(Account account) { 079 account.setNew(true); 080 081 return accountPersistence.update(account); 082 } 083 084 /** 085 * Creates a new account with the primary key. Does not add the account to the database. 086 * 087 * @param accountId the primary key for the new account 088 * @return the new account 089 */ 090 @Override 091 public Account createAccount(long accountId) { 092 return accountPersistence.create(accountId); 093 } 094 095 /** 096 * Deletes the account with the primary key from the database. Also notifies the appropriate model listeners. 097 * 098 * @param accountId the primary key of the account 099 * @return the account that was removed 100 * @throws PortalException if a account with the primary key could not be found 101 */ 102 @Indexable(type = IndexableType.DELETE) 103 @Override 104 public Account deleteAccount(long accountId) throws PortalException { 105 return accountPersistence.remove(accountId); 106 } 107 108 /** 109 * Deletes the account from the database. Also notifies the appropriate model listeners. 110 * 111 * @param account the account 112 * @return the account that was removed 113 */ 114 @Indexable(type = IndexableType.DELETE) 115 @Override 116 public Account deleteAccount(Account account) { 117 return accountPersistence.remove(account); 118 } 119 120 @Override 121 public DynamicQuery dynamicQuery() { 122 Class<?> clazz = getClass(); 123 124 return DynamicQueryFactoryUtil.forClass(Account.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 accountPersistence.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.portal.model.impl.AccountModelImpl}. 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 accountPersistence.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.portal.model.impl.AccountModelImpl}. 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 accountPersistence.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 accountPersistence.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 accountPersistence.countWithDynamicQuery(dynamicQuery, projection); 199 } 200 201 @Override 202 public Account fetchAccount(long accountId) { 203 return accountPersistence.fetchByPrimaryKey(accountId); 204 } 205 206 /** 207 * Returns the account with the primary key. 208 * 209 * @param accountId the primary key of the account 210 * @return the account 211 * @throws PortalException if a account with the primary key could not be found 212 */ 213 @Override 214 public Account getAccount(long accountId) throws PortalException { 215 return accountPersistence.findByPrimaryKey(accountId); 216 } 217 218 @Override 219 public ActionableDynamicQuery getActionableDynamicQuery() { 220 ActionableDynamicQuery actionableDynamicQuery = new DefaultActionableDynamicQuery(); 221 222 actionableDynamicQuery.setBaseLocalService(com.liferay.portal.service.AccountLocalServiceUtil.getService()); 223 actionableDynamicQuery.setClass(Account.class); 224 actionableDynamicQuery.setClassLoader(getClassLoader()); 225 226 actionableDynamicQuery.setPrimaryKeyPropertyName("accountId"); 227 228 return actionableDynamicQuery; 229 } 230 231 protected void initActionableDynamicQuery( 232 ActionableDynamicQuery actionableDynamicQuery) { 233 actionableDynamicQuery.setBaseLocalService(com.liferay.portal.service.AccountLocalServiceUtil.getService()); 234 actionableDynamicQuery.setClass(Account.class); 235 actionableDynamicQuery.setClassLoader(getClassLoader()); 236 237 actionableDynamicQuery.setPrimaryKeyPropertyName("accountId"); 238 } 239 240 /** 241 * @throws PortalException 242 */ 243 @Override 244 public PersistedModel deletePersistedModel(PersistedModel persistedModel) 245 throws PortalException { 246 return accountLocalService.deleteAccount((Account)persistedModel); 247 } 248 249 @Override 250 public PersistedModel getPersistedModel(Serializable primaryKeyObj) 251 throws PortalException { 252 return accountPersistence.findByPrimaryKey(primaryKeyObj); 253 } 254 255 /** 256 * Returns a range of all the accounts. 257 * 258 * <p> 259 * 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.portal.model.impl.AccountModelImpl}. 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. 260 * </p> 261 * 262 * @param start the lower bound of the range of accounts 263 * @param end the upper bound of the range of accounts (not inclusive) 264 * @return the range of accounts 265 */ 266 @Override 267 public List<Account> getAccounts(int start, int end) { 268 return accountPersistence.findAll(start, end); 269 } 270 271 /** 272 * Returns the number of accounts. 273 * 274 * @return the number of accounts 275 */ 276 @Override 277 public int getAccountsCount() { 278 return accountPersistence.countAll(); 279 } 280 281 /** 282 * Updates the account in the database or adds it if it does not yet exist. Also notifies the appropriate model listeners. 283 * 284 * @param account the account 285 * @return the account that was updated 286 */ 287 @Indexable(type = IndexableType.REINDEX) 288 @Override 289 public Account updateAccount(Account account) { 290 return accountPersistence.update(account); 291 } 292 293 /** 294 * Returns the account local service. 295 * 296 * @return the account local service 297 */ 298 public AccountLocalService getAccountLocalService() { 299 return accountLocalService; 300 } 301 302 /** 303 * Sets the account local service. 304 * 305 * @param accountLocalService the account local service 306 */ 307 public void setAccountLocalService(AccountLocalService accountLocalService) { 308 this.accountLocalService = accountLocalService; 309 } 310 311 /** 312 * Returns the account remote service. 313 * 314 * @return the account remote service 315 */ 316 public com.liferay.portal.service.AccountService getAccountService() { 317 return accountService; 318 } 319 320 /** 321 * Sets the account remote service. 322 * 323 * @param accountService the account remote service 324 */ 325 public void setAccountService( 326 com.liferay.portal.service.AccountService accountService) { 327 this.accountService = accountService; 328 } 329 330 /** 331 * Returns the account persistence. 332 * 333 * @return the account persistence 334 */ 335 public AccountPersistence getAccountPersistence() { 336 return accountPersistence; 337 } 338 339 /** 340 * Sets the account persistence. 341 * 342 * @param accountPersistence the account persistence 343 */ 344 public void setAccountPersistence(AccountPersistence accountPersistence) { 345 this.accountPersistence = accountPersistence; 346 } 347 348 /** 349 * Returns the counter local service. 350 * 351 * @return the counter local service 352 */ 353 public com.liferay.counter.service.CounterLocalService getCounterLocalService() { 354 return counterLocalService; 355 } 356 357 /** 358 * Sets the counter local service. 359 * 360 * @param counterLocalService the counter local service 361 */ 362 public void setCounterLocalService( 363 com.liferay.counter.service.CounterLocalService counterLocalService) { 364 this.counterLocalService = counterLocalService; 365 } 366 367 public void afterPropertiesSet() { 368 persistedModelLocalServiceRegistry.register("com.liferay.portal.model.Account", 369 accountLocalService); 370 } 371 372 public void destroy() { 373 persistedModelLocalServiceRegistry.unregister( 374 "com.liferay.portal.model.Account"); 375 } 376 377 /** 378 * Returns the Spring bean ID for this bean. 379 * 380 * @return the Spring bean ID for this bean 381 */ 382 @Override 383 public String getBeanIdentifier() { 384 return _beanIdentifier; 385 } 386 387 /** 388 * Sets the Spring bean ID for this bean. 389 * 390 * @param beanIdentifier the Spring bean ID for this bean 391 */ 392 @Override 393 public void setBeanIdentifier(String beanIdentifier) { 394 _beanIdentifier = beanIdentifier; 395 } 396 397 protected Class<?> getModelClass() { 398 return Account.class; 399 } 400 401 protected String getModelClassName() { 402 return Account.class.getName(); 403 } 404 405 /** 406 * Performs a SQL query. 407 * 408 * @param sql the sql query 409 */ 410 protected void runSQL(String sql) { 411 try { 412 DataSource dataSource = accountPersistence.getDataSource(); 413 414 DB db = DBFactoryUtil.getDB(); 415 416 sql = db.buildSQL(sql); 417 sql = PortalUtil.transformSQL(sql); 418 419 SqlUpdate sqlUpdate = SqlUpdateFactoryUtil.getSqlUpdate(dataSource, 420 sql, new int[0]); 421 422 sqlUpdate.update(); 423 } 424 catch (Exception e) { 425 throw new SystemException(e); 426 } 427 } 428 429 @BeanReference(type = com.liferay.portal.service.AccountLocalService.class) 430 protected AccountLocalService accountLocalService; 431 @BeanReference(type = com.liferay.portal.service.AccountService.class) 432 protected com.liferay.portal.service.AccountService accountService; 433 @BeanReference(type = AccountPersistence.class) 434 protected AccountPersistence accountPersistence; 435 @BeanReference(type = com.liferay.counter.service.CounterLocalService.class) 436 protected com.liferay.counter.service.CounterLocalService counterLocalService; 437 @BeanReference(type = PersistedModelLocalServiceRegistry.class) 438 protected PersistedModelLocalServiceRegistry persistedModelLocalServiceRegistry; 439 private String _beanIdentifier; 440 }