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.dao.db.DB; 021 import com.liferay.portal.kernel.dao.db.DBFactoryUtil; 022 import com.liferay.portal.kernel.dao.jdbc.SqlUpdate; 023 import com.liferay.portal.kernel.dao.jdbc.SqlUpdateFactoryUtil; 024 import com.liferay.portal.kernel.dao.orm.ActionableDynamicQuery; 025 import com.liferay.portal.kernel.dao.orm.DefaultActionableDynamicQuery; 026 import com.liferay.portal.kernel.dao.orm.DynamicQuery; 027 import com.liferay.portal.kernel.dao.orm.DynamicQueryFactoryUtil; 028 import com.liferay.portal.kernel.dao.orm.Projection; 029 import com.liferay.portal.kernel.exception.PortalException; 030 import com.liferay.portal.kernel.exception.SystemException; 031 import com.liferay.portal.kernel.module.framework.service.IdentifiableOSGiService; 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.ClassName; 036 import com.liferay.portal.model.PersistedModel; 037 import com.liferay.portal.service.BaseLocalServiceImpl; 038 import com.liferay.portal.service.ClassNameLocalService; 039 import com.liferay.portal.service.PersistedModelLocalServiceRegistry; 040 import com.liferay.portal.service.persistence.ClassNamePersistence; 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 class name 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.ClassNameLocalServiceImpl}. 054 * </p> 055 * 056 * @author Brian Wing Shun Chan 057 * @see com.liferay.portal.service.impl.ClassNameLocalServiceImpl 058 * @see com.liferay.portal.service.ClassNameLocalServiceUtil 059 * @generated 060 */ 061 @ProviderType 062 public abstract class ClassNameLocalServiceBaseImpl extends BaseLocalServiceImpl 063 implements ClassNameLocalService, IdentifiableOSGiService { 064 /* 065 * NOTE FOR DEVELOPERS: 066 * 067 * Never modify or reference this class directly. Always use {@link com.liferay.portal.service.ClassNameLocalServiceUtil} to access the class name local service. 068 */ 069 070 /** 071 * Adds the class name to the database. Also notifies the appropriate model listeners. 072 * 073 * @param className the class name 074 * @return the class name that was added 075 */ 076 @Indexable(type = IndexableType.REINDEX) 077 @Override 078 public ClassName addClassName(ClassName className) { 079 className.setNew(true); 080 081 return classNamePersistence.update(className); 082 } 083 084 /** 085 * Creates a new class name with the primary key. Does not add the class name to the database. 086 * 087 * @param classNameId the primary key for the new class name 088 * @return the new class name 089 */ 090 @Override 091 public ClassName createClassName(long classNameId) { 092 return classNamePersistence.create(classNameId); 093 } 094 095 /** 096 * Deletes the class name with the primary key from the database. Also notifies the appropriate model listeners. 097 * 098 * @param classNameId the primary key of the class name 099 * @return the class name that was removed 100 * @throws PortalException if a class name with the primary key could not be found 101 */ 102 @Indexable(type = IndexableType.DELETE) 103 @Override 104 public ClassName deleteClassName(long classNameId) 105 throws PortalException { 106 return classNamePersistence.remove(classNameId); 107 } 108 109 /** 110 * Deletes the class name from the database. Also notifies the appropriate model listeners. 111 * 112 * @param className the class name 113 * @return the class name that was removed 114 */ 115 @Indexable(type = IndexableType.DELETE) 116 @Override 117 public ClassName deleteClassName(ClassName className) { 118 return classNamePersistence.remove(className); 119 } 120 121 @Override 122 public DynamicQuery dynamicQuery() { 123 Class<?> clazz = getClass(); 124 125 return DynamicQueryFactoryUtil.forClass(ClassName.class, 126 clazz.getClassLoader()); 127 } 128 129 /** 130 * Performs a dynamic query on the database and returns the matching rows. 131 * 132 * @param dynamicQuery the dynamic query 133 * @return the matching rows 134 */ 135 @Override 136 public <T> List<T> dynamicQuery(DynamicQuery dynamicQuery) { 137 return classNamePersistence.findWithDynamicQuery(dynamicQuery); 138 } 139 140 /** 141 * Performs a dynamic query on the database and returns a range of the matching rows. 142 * 143 * <p> 144 * 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.ClassNameModelImpl}. 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. 145 * </p> 146 * 147 * @param dynamicQuery the dynamic query 148 * @param start the lower bound of the range of model instances 149 * @param end the upper bound of the range of model instances (not inclusive) 150 * @return the range of matching rows 151 */ 152 @Override 153 public <T> List<T> dynamicQuery(DynamicQuery dynamicQuery, int start, 154 int end) { 155 return classNamePersistence.findWithDynamicQuery(dynamicQuery, start, 156 end); 157 } 158 159 /** 160 * Performs a dynamic query on the database and returns an ordered range of the matching rows. 161 * 162 * <p> 163 * 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.ClassNameModelImpl}. 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. 164 * </p> 165 * 166 * @param dynamicQuery the dynamic query 167 * @param start the lower bound of the range of model instances 168 * @param end the upper bound of the range of model instances (not inclusive) 169 * @param orderByComparator the comparator to order the results by (optionally <code>null</code>) 170 * @return the ordered range of matching rows 171 */ 172 @Override 173 public <T> List<T> dynamicQuery(DynamicQuery dynamicQuery, int start, 174 int end, OrderByComparator<T> orderByComparator) { 175 return classNamePersistence.findWithDynamicQuery(dynamicQuery, start, 176 end, orderByComparator); 177 } 178 179 /** 180 * Returns the number of rows matching the dynamic query. 181 * 182 * @param dynamicQuery the dynamic query 183 * @return the number of rows matching the dynamic query 184 */ 185 @Override 186 public long dynamicQueryCount(DynamicQuery dynamicQuery) { 187 return classNamePersistence.countWithDynamicQuery(dynamicQuery); 188 } 189 190 /** 191 * Returns the number of rows matching the dynamic query. 192 * 193 * @param dynamicQuery the dynamic query 194 * @param projection the projection to apply to the query 195 * @return the number of rows matching the dynamic query 196 */ 197 @Override 198 public long dynamicQueryCount(DynamicQuery dynamicQuery, 199 Projection projection) { 200 return classNamePersistence.countWithDynamicQuery(dynamicQuery, 201 projection); 202 } 203 204 @Override 205 public ClassName fetchClassName(long classNameId) { 206 return classNamePersistence.fetchByPrimaryKey(classNameId); 207 } 208 209 /** 210 * Returns the class name with the primary key. 211 * 212 * @param classNameId the primary key of the class name 213 * @return the class name 214 * @throws PortalException if a class name with the primary key could not be found 215 */ 216 @Override 217 public ClassName getClassName(long classNameId) throws PortalException { 218 return classNamePersistence.findByPrimaryKey(classNameId); 219 } 220 221 @Override 222 public ActionableDynamicQuery getActionableDynamicQuery() { 223 ActionableDynamicQuery actionableDynamicQuery = new DefaultActionableDynamicQuery(); 224 225 actionableDynamicQuery.setBaseLocalService(com.liferay.portal.service.ClassNameLocalServiceUtil.getService()); 226 actionableDynamicQuery.setClass(ClassName.class); 227 actionableDynamicQuery.setClassLoader(getClassLoader()); 228 229 actionableDynamicQuery.setPrimaryKeyPropertyName("classNameId"); 230 231 return actionableDynamicQuery; 232 } 233 234 protected void initActionableDynamicQuery( 235 ActionableDynamicQuery actionableDynamicQuery) { 236 actionableDynamicQuery.setBaseLocalService(com.liferay.portal.service.ClassNameLocalServiceUtil.getService()); 237 actionableDynamicQuery.setClass(ClassName.class); 238 actionableDynamicQuery.setClassLoader(getClassLoader()); 239 240 actionableDynamicQuery.setPrimaryKeyPropertyName("classNameId"); 241 } 242 243 /** 244 * @throws PortalException 245 */ 246 @Override 247 public PersistedModel deletePersistedModel(PersistedModel persistedModel) 248 throws PortalException { 249 return classNameLocalService.deleteClassName((ClassName)persistedModel); 250 } 251 252 @Override 253 public PersistedModel getPersistedModel(Serializable primaryKeyObj) 254 throws PortalException { 255 return classNamePersistence.findByPrimaryKey(primaryKeyObj); 256 } 257 258 /** 259 * Returns a range of all the class names. 260 * 261 * <p> 262 * 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.ClassNameModelImpl}. 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. 263 * </p> 264 * 265 * @param start the lower bound of the range of class names 266 * @param end the upper bound of the range of class names (not inclusive) 267 * @return the range of class names 268 */ 269 @Override 270 public List<ClassName> getClassNames(int start, int end) { 271 return classNamePersistence.findAll(start, end); 272 } 273 274 /** 275 * Returns the number of class names. 276 * 277 * @return the number of class names 278 */ 279 @Override 280 public int getClassNamesCount() { 281 return classNamePersistence.countAll(); 282 } 283 284 /** 285 * Updates the class name in the database or adds it if it does not yet exist. Also notifies the appropriate model listeners. 286 * 287 * @param className the class name 288 * @return the class name that was updated 289 */ 290 @Indexable(type = IndexableType.REINDEX) 291 @Override 292 public ClassName updateClassName(ClassName className) { 293 return classNamePersistence.update(className); 294 } 295 296 /** 297 * Returns the class name local service. 298 * 299 * @return the class name local service 300 */ 301 public ClassNameLocalService getClassNameLocalService() { 302 return classNameLocalService; 303 } 304 305 /** 306 * Sets the class name local service. 307 * 308 * @param classNameLocalService the class name local service 309 */ 310 public void setClassNameLocalService( 311 ClassNameLocalService classNameLocalService) { 312 this.classNameLocalService = classNameLocalService; 313 } 314 315 /** 316 * Returns the class name remote service. 317 * 318 * @return the class name remote service 319 */ 320 public com.liferay.portal.service.ClassNameService getClassNameService() { 321 return classNameService; 322 } 323 324 /** 325 * Sets the class name remote service. 326 * 327 * @param classNameService the class name remote service 328 */ 329 public void setClassNameService( 330 com.liferay.portal.service.ClassNameService classNameService) { 331 this.classNameService = classNameService; 332 } 333 334 /** 335 * Returns the class name persistence. 336 * 337 * @return the class name persistence 338 */ 339 public ClassNamePersistence getClassNamePersistence() { 340 return classNamePersistence; 341 } 342 343 /** 344 * Sets the class name persistence. 345 * 346 * @param classNamePersistence the class name persistence 347 */ 348 public void setClassNamePersistence( 349 ClassNamePersistence classNamePersistence) { 350 this.classNamePersistence = classNamePersistence; 351 } 352 353 /** 354 * Returns the counter local service. 355 * 356 * @return the counter local service 357 */ 358 public com.liferay.counter.service.CounterLocalService getCounterLocalService() { 359 return counterLocalService; 360 } 361 362 /** 363 * Sets the counter local service. 364 * 365 * @param counterLocalService the counter local service 366 */ 367 public void setCounterLocalService( 368 com.liferay.counter.service.CounterLocalService counterLocalService) { 369 this.counterLocalService = counterLocalService; 370 } 371 372 public void afterPropertiesSet() { 373 persistedModelLocalServiceRegistry.register("com.liferay.portal.model.ClassName", 374 classNameLocalService); 375 } 376 377 public void destroy() { 378 persistedModelLocalServiceRegistry.unregister( 379 "com.liferay.portal.model.ClassName"); 380 } 381 382 /** 383 * Returns the OSGi service identifier. 384 * 385 * @return the OSGi service identifier 386 */ 387 @Override 388 public String getOSGiServiceIdentifier() { 389 return ClassNameLocalService.class.getName(); 390 } 391 392 protected Class<?> getModelClass() { 393 return ClassName.class; 394 } 395 396 protected String getModelClassName() { 397 return ClassName.class.getName(); 398 } 399 400 /** 401 * Performs a SQL query. 402 * 403 * @param sql the sql query 404 */ 405 protected void runSQL(String sql) { 406 try { 407 DataSource dataSource = classNamePersistence.getDataSource(); 408 409 DB db = DBFactoryUtil.getDB(); 410 411 sql = db.buildSQL(sql); 412 sql = PortalUtil.transformSQL(sql); 413 414 SqlUpdate sqlUpdate = SqlUpdateFactoryUtil.getSqlUpdate(dataSource, 415 sql, new int[0]); 416 417 sqlUpdate.update(); 418 } 419 catch (Exception e) { 420 throw new SystemException(e); 421 } 422 } 423 424 @BeanReference(type = com.liferay.portal.service.ClassNameLocalService.class) 425 protected ClassNameLocalService classNameLocalService; 426 @BeanReference(type = com.liferay.portal.service.ClassNameService.class) 427 protected com.liferay.portal.service.ClassNameService classNameService; 428 @BeanReference(type = ClassNamePersistence.class) 429 protected ClassNamePersistence classNamePersistence; 430 @BeanReference(type = com.liferay.counter.service.CounterLocalService.class) 431 protected com.liferay.counter.service.CounterLocalService counterLocalService; 432 @BeanReference(type = PersistedModelLocalServiceRegistry.class) 433 protected PersistedModelLocalServiceRegistry persistedModelLocalServiceRegistry; 434 }