001    /**
002     * Copyright (c) 2000-2012 Liferay, Inc. All rights reserved.
003     *
004     * The contents of this file are subject to the terms of the Liferay Enterprise
005     * Subscription License ("License"). You may not use this file except in
006     * compliance with the License. You can obtain a copy of the License by
007     * contacting Liferay, Inc. See the License for the specific language governing
008     * permissions and limitations under the License, including but not limited to
009     * distribution rights of the Software.
010     *
011     *
012     *
013     */
014    
015    package com.liferay.portlet.mobiledevicerules.service.persistence;
016    
017    import com.liferay.portal.NoSuchModelException;
018    import com.liferay.portal.kernel.bean.BeanReference;
019    import com.liferay.portal.kernel.cache.CacheRegistryUtil;
020    import com.liferay.portal.kernel.dao.orm.EntityCacheUtil;
021    import com.liferay.portal.kernel.dao.orm.FinderCacheUtil;
022    import com.liferay.portal.kernel.dao.orm.FinderPath;
023    import com.liferay.portal.kernel.dao.orm.Query;
024    import com.liferay.portal.kernel.dao.orm.QueryPos;
025    import com.liferay.portal.kernel.dao.orm.QueryUtil;
026    import com.liferay.portal.kernel.dao.orm.Session;
027    import com.liferay.portal.kernel.exception.SystemException;
028    import com.liferay.portal.kernel.log.Log;
029    import com.liferay.portal.kernel.log.LogFactoryUtil;
030    import com.liferay.portal.kernel.util.GetterUtil;
031    import com.liferay.portal.kernel.util.InstanceFactory;
032    import com.liferay.portal.kernel.util.OrderByComparator;
033    import com.liferay.portal.kernel.util.StringBundler;
034    import com.liferay.portal.kernel.util.StringPool;
035    import com.liferay.portal.kernel.util.StringUtil;
036    import com.liferay.portal.kernel.util.Validator;
037    import com.liferay.portal.kernel.uuid.PortalUUIDUtil;
038    import com.liferay.portal.model.CacheModel;
039    import com.liferay.portal.model.ModelListener;
040    import com.liferay.portal.service.persistence.BatchSessionUtil;
041    import com.liferay.portal.service.persistence.ResourcePersistence;
042    import com.liferay.portal.service.persistence.UserPersistence;
043    import com.liferay.portal.service.persistence.impl.BasePersistenceImpl;
044    
045    import com.liferay.portlet.mobiledevicerules.NoSuchRuleException;
046    import com.liferay.portlet.mobiledevicerules.model.MDRRule;
047    import com.liferay.portlet.mobiledevicerules.model.impl.MDRRuleImpl;
048    import com.liferay.portlet.mobiledevicerules.model.impl.MDRRuleModelImpl;
049    
050    import java.io.Serializable;
051    
052    import java.util.ArrayList;
053    import java.util.Collections;
054    import java.util.List;
055    
056    /**
057     * The persistence implementation for the m d r rule service.
058     *
059     * <p>
060     * Caching information and settings can be found in <code>portal.properties</code>
061     * </p>
062     *
063     * @author Edward C. Han
064     * @see MDRRulePersistence
065     * @see MDRRuleUtil
066     * @generated
067     */
068    public class MDRRulePersistenceImpl extends BasePersistenceImpl<MDRRule>
069            implements MDRRulePersistence {
070            /*
071             * NOTE FOR DEVELOPERS:
072             *
073             * Never modify or reference this class directly. Always use {@link MDRRuleUtil} to access the m d r rule persistence. Modify <code>service.xml</code> and rerun ServiceBuilder to regenerate this class.
074             */
075            public static final String FINDER_CLASS_NAME_ENTITY = MDRRuleImpl.class.getName();
076            public static final String FINDER_CLASS_NAME_LIST_WITH_PAGINATION = FINDER_CLASS_NAME_ENTITY +
077                    ".List1";
078            public static final String FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION = FINDER_CLASS_NAME_ENTITY +
079                    ".List2";
080            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_UUID = new FinderPath(MDRRuleModelImpl.ENTITY_CACHE_ENABLED,
081                            MDRRuleModelImpl.FINDER_CACHE_ENABLED, MDRRuleImpl.class,
082                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByUuid",
083                            new String[] {
084                                    String.class.getName(),
085                                    
086                            "java.lang.Integer", "java.lang.Integer",
087                                    "com.liferay.portal.kernel.util.OrderByComparator"
088                            });
089            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID = new FinderPath(MDRRuleModelImpl.ENTITY_CACHE_ENABLED,
090                            MDRRuleModelImpl.FINDER_CACHE_ENABLED, MDRRuleImpl.class,
091                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByUuid",
092                            new String[] { String.class.getName() },
093                            MDRRuleModelImpl.UUID_COLUMN_BITMASK);
094            public static final FinderPath FINDER_PATH_COUNT_BY_UUID = new FinderPath(MDRRuleModelImpl.ENTITY_CACHE_ENABLED,
095                            MDRRuleModelImpl.FINDER_CACHE_ENABLED, Long.class,
096                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByUuid",
097                            new String[] { String.class.getName() });
098            public static final FinderPath FINDER_PATH_FETCH_BY_UUID_G = new FinderPath(MDRRuleModelImpl.ENTITY_CACHE_ENABLED,
099                            MDRRuleModelImpl.FINDER_CACHE_ENABLED, MDRRuleImpl.class,
100                            FINDER_CLASS_NAME_ENTITY, "fetchByUUID_G",
101                            new String[] { String.class.getName(), Long.class.getName() },
102                            MDRRuleModelImpl.UUID_COLUMN_BITMASK |
103                            MDRRuleModelImpl.GROUPID_COLUMN_BITMASK);
104            public static final FinderPath FINDER_PATH_COUNT_BY_UUID_G = new FinderPath(MDRRuleModelImpl.ENTITY_CACHE_ENABLED,
105                            MDRRuleModelImpl.FINDER_CACHE_ENABLED, Long.class,
106                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByUUID_G",
107                            new String[] { String.class.getName(), Long.class.getName() });
108            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_RULEGROUPID =
109                    new FinderPath(MDRRuleModelImpl.ENTITY_CACHE_ENABLED,
110                            MDRRuleModelImpl.FINDER_CACHE_ENABLED, MDRRuleImpl.class,
111                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByRuleGroupId",
112                            new String[] {
113                                    Long.class.getName(),
114                                    
115                            "java.lang.Integer", "java.lang.Integer",
116                                    "com.liferay.portal.kernel.util.OrderByComparator"
117                            });
118            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_RULEGROUPID =
119                    new FinderPath(MDRRuleModelImpl.ENTITY_CACHE_ENABLED,
120                            MDRRuleModelImpl.FINDER_CACHE_ENABLED, MDRRuleImpl.class,
121                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByRuleGroupId",
122                            new String[] { Long.class.getName() },
123                            MDRRuleModelImpl.RULEGROUPID_COLUMN_BITMASK);
124            public static final FinderPath FINDER_PATH_COUNT_BY_RULEGROUPID = new FinderPath(MDRRuleModelImpl.ENTITY_CACHE_ENABLED,
125                            MDRRuleModelImpl.FINDER_CACHE_ENABLED, Long.class,
126                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByRuleGroupId",
127                            new String[] { Long.class.getName() });
128            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_ALL = new FinderPath(MDRRuleModelImpl.ENTITY_CACHE_ENABLED,
129                            MDRRuleModelImpl.FINDER_CACHE_ENABLED, MDRRuleImpl.class,
130                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findAll", new String[0]);
131            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL = new FinderPath(MDRRuleModelImpl.ENTITY_CACHE_ENABLED,
132                            MDRRuleModelImpl.FINDER_CACHE_ENABLED, MDRRuleImpl.class,
133                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findAll", new String[0]);
134            public static final FinderPath FINDER_PATH_COUNT_ALL = new FinderPath(MDRRuleModelImpl.ENTITY_CACHE_ENABLED,
135                            MDRRuleModelImpl.FINDER_CACHE_ENABLED, Long.class,
136                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countAll", new String[0]);
137    
138            /**
139             * Caches the m d r rule in the entity cache if it is enabled.
140             *
141             * @param mdrRule the m d r rule
142             */
143            public void cacheResult(MDRRule mdrRule) {
144                    EntityCacheUtil.putResult(MDRRuleModelImpl.ENTITY_CACHE_ENABLED,
145                            MDRRuleImpl.class, mdrRule.getPrimaryKey(), mdrRule);
146    
147                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_UUID_G,
148                            new Object[] { mdrRule.getUuid(), Long.valueOf(mdrRule.getGroupId()) },
149                            mdrRule);
150    
151                    mdrRule.resetOriginalValues();
152            }
153    
154            /**
155             * Caches the m d r rules in the entity cache if it is enabled.
156             *
157             * @param mdrRules the m d r rules
158             */
159            public void cacheResult(List<MDRRule> mdrRules) {
160                    for (MDRRule mdrRule : mdrRules) {
161                            if (EntityCacheUtil.getResult(
162                                                    MDRRuleModelImpl.ENTITY_CACHE_ENABLED,
163                                                    MDRRuleImpl.class, mdrRule.getPrimaryKey()) == null) {
164                                    cacheResult(mdrRule);
165                            }
166                            else {
167                                    mdrRule.resetOriginalValues();
168                            }
169                    }
170            }
171    
172            /**
173             * Clears the cache for all m d r rules.
174             *
175             * <p>
176             * The {@link com.liferay.portal.kernel.dao.orm.EntityCache} and {@link com.liferay.portal.kernel.dao.orm.FinderCache} are both cleared by this method.
177             * </p>
178             */
179            @Override
180            public void clearCache() {
181                    if (_HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE) {
182                            CacheRegistryUtil.clear(MDRRuleImpl.class.getName());
183                    }
184    
185                    EntityCacheUtil.clearCache(MDRRuleImpl.class.getName());
186    
187                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_ENTITY);
188                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
189                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
190            }
191    
192            /**
193             * Clears the cache for the m d r rule.
194             *
195             * <p>
196             * The {@link com.liferay.portal.kernel.dao.orm.EntityCache} and {@link com.liferay.portal.kernel.dao.orm.FinderCache} are both cleared by this method.
197             * </p>
198             */
199            @Override
200            public void clearCache(MDRRule mdrRule) {
201                    EntityCacheUtil.removeResult(MDRRuleModelImpl.ENTITY_CACHE_ENABLED,
202                            MDRRuleImpl.class, mdrRule.getPrimaryKey());
203    
204                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
205                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
206    
207                    clearUniqueFindersCache(mdrRule);
208            }
209    
210            @Override
211            public void clearCache(List<MDRRule> mdrRules) {
212                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
213                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
214    
215                    for (MDRRule mdrRule : mdrRules) {
216                            EntityCacheUtil.removeResult(MDRRuleModelImpl.ENTITY_CACHE_ENABLED,
217                                    MDRRuleImpl.class, mdrRule.getPrimaryKey());
218    
219                            clearUniqueFindersCache(mdrRule);
220                    }
221            }
222    
223            protected void clearUniqueFindersCache(MDRRule mdrRule) {
224                    FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_UUID_G,
225                            new Object[] { mdrRule.getUuid(), Long.valueOf(mdrRule.getGroupId()) });
226            }
227    
228            /**
229             * Creates a new m d r rule with the primary key. Does not add the m d r rule to the database.
230             *
231             * @param ruleId the primary key for the new m d r rule
232             * @return the new m d r rule
233             */
234            public MDRRule create(long ruleId) {
235                    MDRRule mdrRule = new MDRRuleImpl();
236    
237                    mdrRule.setNew(true);
238                    mdrRule.setPrimaryKey(ruleId);
239    
240                    String uuid = PortalUUIDUtil.generate();
241    
242                    mdrRule.setUuid(uuid);
243    
244                    return mdrRule;
245            }
246    
247            /**
248             * Removes the m d r rule with the primary key from the database. Also notifies the appropriate model listeners.
249             *
250             * @param ruleId the primary key of the m d r rule
251             * @return the m d r rule that was removed
252             * @throws com.liferay.portlet.mobiledevicerules.NoSuchRuleException if a m d r rule with the primary key could not be found
253             * @throws SystemException if a system exception occurred
254             */
255            public MDRRule remove(long ruleId)
256                    throws NoSuchRuleException, SystemException {
257                    return remove(Long.valueOf(ruleId));
258            }
259    
260            /**
261             * Removes the m d r rule with the primary key from the database. Also notifies the appropriate model listeners.
262             *
263             * @param primaryKey the primary key of the m d r rule
264             * @return the m d r rule that was removed
265             * @throws com.liferay.portlet.mobiledevicerules.NoSuchRuleException if a m d r rule with the primary key could not be found
266             * @throws SystemException if a system exception occurred
267             */
268            @Override
269            public MDRRule remove(Serializable primaryKey)
270                    throws NoSuchRuleException, SystemException {
271                    Session session = null;
272    
273                    try {
274                            session = openSession();
275    
276                            MDRRule mdrRule = (MDRRule)session.get(MDRRuleImpl.class, primaryKey);
277    
278                            if (mdrRule == null) {
279                                    if (_log.isWarnEnabled()) {
280                                            _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + primaryKey);
281                                    }
282    
283                                    throw new NoSuchRuleException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
284                                            primaryKey);
285                            }
286    
287                            return remove(mdrRule);
288                    }
289                    catch (NoSuchRuleException nsee) {
290                            throw nsee;
291                    }
292                    catch (Exception e) {
293                            throw processException(e);
294                    }
295                    finally {
296                            closeSession(session);
297                    }
298            }
299    
300            @Override
301            protected MDRRule removeImpl(MDRRule mdrRule) throws SystemException {
302                    mdrRule = toUnwrappedModel(mdrRule);
303    
304                    Session session = null;
305    
306                    try {
307                            session = openSession();
308    
309                            BatchSessionUtil.delete(session, mdrRule);
310                    }
311                    catch (Exception e) {
312                            throw processException(e);
313                    }
314                    finally {
315                            closeSession(session);
316                    }
317    
318                    clearCache(mdrRule);
319    
320                    return mdrRule;
321            }
322    
323            @Override
324            public MDRRule updateImpl(
325                    com.liferay.portlet.mobiledevicerules.model.MDRRule mdrRule,
326                    boolean merge) throws SystemException {
327                    mdrRule = toUnwrappedModel(mdrRule);
328    
329                    boolean isNew = mdrRule.isNew();
330    
331                    MDRRuleModelImpl mdrRuleModelImpl = (MDRRuleModelImpl)mdrRule;
332    
333                    if (Validator.isNull(mdrRule.getUuid())) {
334                            String uuid = PortalUUIDUtil.generate();
335    
336                            mdrRule.setUuid(uuid);
337                    }
338    
339                    Session session = null;
340    
341                    try {
342                            session = openSession();
343    
344                            BatchSessionUtil.update(session, mdrRule, merge);
345    
346                            mdrRule.setNew(false);
347                    }
348                    catch (Exception e) {
349                            throw processException(e);
350                    }
351                    finally {
352                            closeSession(session);
353                    }
354    
355                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
356    
357                    if (isNew || !MDRRuleModelImpl.COLUMN_BITMASK_ENABLED) {
358                            FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
359                    }
360    
361                    else {
362                            if ((mdrRuleModelImpl.getColumnBitmask() &
363                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID.getColumnBitmask()) != 0) {
364                                    Object[] args = new Object[] { mdrRuleModelImpl.getOriginalUuid() };
365    
366                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_UUID, args);
367                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID,
368                                            args);
369    
370                                    args = new Object[] { mdrRuleModelImpl.getUuid() };
371    
372                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_UUID, args);
373                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID,
374                                            args);
375                            }
376    
377                            if ((mdrRuleModelImpl.getColumnBitmask() &
378                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_RULEGROUPID.getColumnBitmask()) != 0) {
379                                    Object[] args = new Object[] {
380                                                    Long.valueOf(mdrRuleModelImpl.getOriginalRuleGroupId())
381                                            };
382    
383                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_RULEGROUPID,
384                                            args);
385                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_RULEGROUPID,
386                                            args);
387    
388                                    args = new Object[] {
389                                                    Long.valueOf(mdrRuleModelImpl.getRuleGroupId())
390                                            };
391    
392                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_RULEGROUPID,
393                                            args);
394                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_RULEGROUPID,
395                                            args);
396                            }
397                    }
398    
399                    EntityCacheUtil.putResult(MDRRuleModelImpl.ENTITY_CACHE_ENABLED,
400                            MDRRuleImpl.class, mdrRule.getPrimaryKey(), mdrRule);
401    
402                    if (isNew) {
403                            FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_UUID_G,
404                                    new Object[] {
405                                            mdrRule.getUuid(), Long.valueOf(mdrRule.getGroupId())
406                                    }, mdrRule);
407                    }
408                    else {
409                            if ((mdrRuleModelImpl.getColumnBitmask() &
410                                            FINDER_PATH_FETCH_BY_UUID_G.getColumnBitmask()) != 0) {
411                                    Object[] args = new Object[] {
412                                                    mdrRuleModelImpl.getOriginalUuid(),
413                                                    Long.valueOf(mdrRuleModelImpl.getOriginalGroupId())
414                                            };
415    
416                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_UUID_G, args);
417    
418                                    FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_UUID_G, args);
419    
420                                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_UUID_G,
421                                            new Object[] {
422                                                    mdrRule.getUuid(), Long.valueOf(mdrRule.getGroupId())
423                                            }, mdrRule);
424                            }
425                    }
426    
427                    return mdrRule;
428            }
429    
430            protected MDRRule toUnwrappedModel(MDRRule mdrRule) {
431                    if (mdrRule instanceof MDRRuleImpl) {
432                            return mdrRule;
433                    }
434    
435                    MDRRuleImpl mdrRuleImpl = new MDRRuleImpl();
436    
437                    mdrRuleImpl.setNew(mdrRule.isNew());
438                    mdrRuleImpl.setPrimaryKey(mdrRule.getPrimaryKey());
439    
440                    mdrRuleImpl.setUuid(mdrRule.getUuid());
441                    mdrRuleImpl.setRuleId(mdrRule.getRuleId());
442                    mdrRuleImpl.setGroupId(mdrRule.getGroupId());
443                    mdrRuleImpl.setCompanyId(mdrRule.getCompanyId());
444                    mdrRuleImpl.setUserId(mdrRule.getUserId());
445                    mdrRuleImpl.setUserName(mdrRule.getUserName());
446                    mdrRuleImpl.setCreateDate(mdrRule.getCreateDate());
447                    mdrRuleImpl.setModifiedDate(mdrRule.getModifiedDate());
448                    mdrRuleImpl.setRuleGroupId(mdrRule.getRuleGroupId());
449                    mdrRuleImpl.setName(mdrRule.getName());
450                    mdrRuleImpl.setDescription(mdrRule.getDescription());
451                    mdrRuleImpl.setType(mdrRule.getType());
452                    mdrRuleImpl.setTypeSettings(mdrRule.getTypeSettings());
453    
454                    return mdrRuleImpl;
455            }
456    
457            /**
458             * Returns the m d r rule with the primary key or throws a {@link com.liferay.portal.NoSuchModelException} if it could not be found.
459             *
460             * @param primaryKey the primary key of the m d r rule
461             * @return the m d r rule
462             * @throws com.liferay.portal.NoSuchModelException if a m d r rule with the primary key could not be found
463             * @throws SystemException if a system exception occurred
464             */
465            @Override
466            public MDRRule findByPrimaryKey(Serializable primaryKey)
467                    throws NoSuchModelException, SystemException {
468                    return findByPrimaryKey(((Long)primaryKey).longValue());
469            }
470    
471            /**
472             * Returns the m d r rule with the primary key or throws a {@link com.liferay.portlet.mobiledevicerules.NoSuchRuleException} if it could not be found.
473             *
474             * @param ruleId the primary key of the m d r rule
475             * @return the m d r rule
476             * @throws com.liferay.portlet.mobiledevicerules.NoSuchRuleException if a m d r rule with the primary key could not be found
477             * @throws SystemException if a system exception occurred
478             */
479            public MDRRule findByPrimaryKey(long ruleId)
480                    throws NoSuchRuleException, SystemException {
481                    MDRRule mdrRule = fetchByPrimaryKey(ruleId);
482    
483                    if (mdrRule == null) {
484                            if (_log.isWarnEnabled()) {
485                                    _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + ruleId);
486                            }
487    
488                            throw new NoSuchRuleException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
489                                    ruleId);
490                    }
491    
492                    return mdrRule;
493            }
494    
495            /**
496             * Returns the m d r rule with the primary key or returns <code>null</code> if it could not be found.
497             *
498             * @param primaryKey the primary key of the m d r rule
499             * @return the m d r rule, or <code>null</code> if a m d r rule with the primary key could not be found
500             * @throws SystemException if a system exception occurred
501             */
502            @Override
503            public MDRRule fetchByPrimaryKey(Serializable primaryKey)
504                    throws SystemException {
505                    return fetchByPrimaryKey(((Long)primaryKey).longValue());
506            }
507    
508            /**
509             * Returns the m d r rule with the primary key or returns <code>null</code> if it could not be found.
510             *
511             * @param ruleId the primary key of the m d r rule
512             * @return the m d r rule, or <code>null</code> if a m d r rule with the primary key could not be found
513             * @throws SystemException if a system exception occurred
514             */
515            public MDRRule fetchByPrimaryKey(long ruleId) throws SystemException {
516                    MDRRule mdrRule = (MDRRule)EntityCacheUtil.getResult(MDRRuleModelImpl.ENTITY_CACHE_ENABLED,
517                                    MDRRuleImpl.class, ruleId);
518    
519                    if (mdrRule == _nullMDRRule) {
520                            return null;
521                    }
522    
523                    if (mdrRule == null) {
524                            Session session = null;
525    
526                            boolean hasException = false;
527    
528                            try {
529                                    session = openSession();
530    
531                                    mdrRule = (MDRRule)session.get(MDRRuleImpl.class,
532                                                    Long.valueOf(ruleId));
533                            }
534                            catch (Exception e) {
535                                    hasException = true;
536    
537                                    throw processException(e);
538                            }
539                            finally {
540                                    if (mdrRule != null) {
541                                            cacheResult(mdrRule);
542                                    }
543                                    else if (!hasException) {
544                                            EntityCacheUtil.putResult(MDRRuleModelImpl.ENTITY_CACHE_ENABLED,
545                                                    MDRRuleImpl.class, ruleId, _nullMDRRule);
546                                    }
547    
548                                    closeSession(session);
549                            }
550                    }
551    
552                    return mdrRule;
553            }
554    
555            /**
556             * Returns all the m d r rules where uuid = &#63;.
557             *
558             * @param uuid the uuid
559             * @return the matching m d r rules
560             * @throws SystemException if a system exception occurred
561             */
562            public List<MDRRule> findByUuid(String uuid) throws SystemException {
563                    return findByUuid(uuid, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
564            }
565    
566            /**
567             * Returns a range of all the m d r rules where uuid = &#63;.
568             *
569             * <p>
570             * 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.
571             * </p>
572             *
573             * @param uuid the uuid
574             * @param start the lower bound of the range of m d r rules
575             * @param end the upper bound of the range of m d r rules (not inclusive)
576             * @return the range of matching m d r rules
577             * @throws SystemException if a system exception occurred
578             */
579            public List<MDRRule> findByUuid(String uuid, int start, int end)
580                    throws SystemException {
581                    return findByUuid(uuid, start, end, null);
582            }
583    
584            /**
585             * Returns an ordered range of all the m d r rules where uuid = &#63;.
586             *
587             * <p>
588             * 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.
589             * </p>
590             *
591             * @param uuid the uuid
592             * @param start the lower bound of the range of m d r rules
593             * @param end the upper bound of the range of m d r rules (not inclusive)
594             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
595             * @return the ordered range of matching m d r rules
596             * @throws SystemException if a system exception occurred
597             */
598            public List<MDRRule> findByUuid(String uuid, int start, int end,
599                    OrderByComparator orderByComparator) throws SystemException {
600                    FinderPath finderPath = null;
601                    Object[] finderArgs = null;
602    
603                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
604                                    (orderByComparator == null)) {
605                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID;
606                            finderArgs = new Object[] { uuid };
607                    }
608                    else {
609                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_UUID;
610                            finderArgs = new Object[] { uuid, start, end, orderByComparator };
611                    }
612    
613                    List<MDRRule> list = (List<MDRRule>)FinderCacheUtil.getResult(finderPath,
614                                    finderArgs, this);
615    
616                    if ((list != null) && !list.isEmpty()) {
617                            for (MDRRule mdrRule : list) {
618                                    if (!Validator.equals(uuid, mdrRule.getUuid())) {
619                                            list = null;
620    
621                                            break;
622                                    }
623                            }
624                    }
625    
626                    if (list == null) {
627                            StringBundler query = null;
628    
629                            if (orderByComparator != null) {
630                                    query = new StringBundler(3 +
631                                                    (orderByComparator.getOrderByFields().length * 3));
632                            }
633                            else {
634                                    query = new StringBundler(2);
635                            }
636    
637                            query.append(_SQL_SELECT_MDRRULE_WHERE);
638    
639                            if (uuid == null) {
640                                    query.append(_FINDER_COLUMN_UUID_UUID_1);
641                            }
642                            else {
643                                    if (uuid.equals(StringPool.BLANK)) {
644                                            query.append(_FINDER_COLUMN_UUID_UUID_3);
645                                    }
646                                    else {
647                                            query.append(_FINDER_COLUMN_UUID_UUID_2);
648                                    }
649                            }
650    
651                            if (orderByComparator != null) {
652                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
653                                            orderByComparator);
654                            }
655    
656                            String sql = query.toString();
657    
658                            Session session = null;
659    
660                            try {
661                                    session = openSession();
662    
663                                    Query q = session.createQuery(sql);
664    
665                                    QueryPos qPos = QueryPos.getInstance(q);
666    
667                                    if (uuid != null) {
668                                            qPos.add(uuid);
669                                    }
670    
671                                    list = (List<MDRRule>)QueryUtil.list(q, getDialect(), start, end);
672                            }
673                            catch (Exception e) {
674                                    throw processException(e);
675                            }
676                            finally {
677                                    if (list == null) {
678                                            FinderCacheUtil.removeResult(finderPath, finderArgs);
679                                    }
680                                    else {
681                                            cacheResult(list);
682    
683                                            FinderCacheUtil.putResult(finderPath, finderArgs, list);
684                                    }
685    
686                                    closeSession(session);
687                            }
688                    }
689    
690                    return list;
691            }
692    
693            /**
694             * Returns the first m d r rule in the ordered set where uuid = &#63;.
695             *
696             * @param uuid the uuid
697             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
698             * @return the first matching m d r rule
699             * @throws com.liferay.portlet.mobiledevicerules.NoSuchRuleException if a matching m d r rule could not be found
700             * @throws SystemException if a system exception occurred
701             */
702            public MDRRule findByUuid_First(String uuid,
703                    OrderByComparator orderByComparator)
704                    throws NoSuchRuleException, SystemException {
705                    MDRRule mdrRule = fetchByUuid_First(uuid, orderByComparator);
706    
707                    if (mdrRule != null) {
708                            return mdrRule;
709                    }
710    
711                    StringBundler msg = new StringBundler(4);
712    
713                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
714    
715                    msg.append("uuid=");
716                    msg.append(uuid);
717    
718                    msg.append(StringPool.CLOSE_CURLY_BRACE);
719    
720                    throw new NoSuchRuleException(msg.toString());
721            }
722    
723            /**
724             * Returns the first m d r rule in the ordered set where uuid = &#63;.
725             *
726             * @param uuid the uuid
727             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
728             * @return the first matching m d r rule, or <code>null</code> if a matching m d r rule could not be found
729             * @throws SystemException if a system exception occurred
730             */
731            public MDRRule fetchByUuid_First(String uuid,
732                    OrderByComparator orderByComparator) throws SystemException {
733                    List<MDRRule> list = findByUuid(uuid, 0, 1, orderByComparator);
734    
735                    if (!list.isEmpty()) {
736                            return list.get(0);
737                    }
738    
739                    return null;
740            }
741    
742            /**
743             * Returns the last m d r rule in the ordered set where uuid = &#63;.
744             *
745             * @param uuid the uuid
746             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
747             * @return the last matching m d r rule
748             * @throws com.liferay.portlet.mobiledevicerules.NoSuchRuleException if a matching m d r rule could not be found
749             * @throws SystemException if a system exception occurred
750             */
751            public MDRRule findByUuid_Last(String uuid,
752                    OrderByComparator orderByComparator)
753                    throws NoSuchRuleException, SystemException {
754                    MDRRule mdrRule = fetchByUuid_Last(uuid, orderByComparator);
755    
756                    if (mdrRule != null) {
757                            return mdrRule;
758                    }
759    
760                    StringBundler msg = new StringBundler(4);
761    
762                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
763    
764                    msg.append("uuid=");
765                    msg.append(uuid);
766    
767                    msg.append(StringPool.CLOSE_CURLY_BRACE);
768    
769                    throw new NoSuchRuleException(msg.toString());
770            }
771    
772            /**
773             * Returns the last m d r rule in the ordered set where uuid = &#63;.
774             *
775             * @param uuid the uuid
776             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
777             * @return the last matching m d r rule, or <code>null</code> if a matching m d r rule could not be found
778             * @throws SystemException if a system exception occurred
779             */
780            public MDRRule fetchByUuid_Last(String uuid,
781                    OrderByComparator orderByComparator) throws SystemException {
782                    int count = countByUuid(uuid);
783    
784                    List<MDRRule> list = findByUuid(uuid, count - 1, count,
785                                    orderByComparator);
786    
787                    if (!list.isEmpty()) {
788                            return list.get(0);
789                    }
790    
791                    return null;
792            }
793    
794            /**
795             * Returns the m d r rules before and after the current m d r rule in the ordered set where uuid = &#63;.
796             *
797             * @param ruleId the primary key of the current m d r rule
798             * @param uuid the uuid
799             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
800             * @return the previous, current, and next m d r rule
801             * @throws com.liferay.portlet.mobiledevicerules.NoSuchRuleException if a m d r rule with the primary key could not be found
802             * @throws SystemException if a system exception occurred
803             */
804            public MDRRule[] findByUuid_PrevAndNext(long ruleId, String uuid,
805                    OrderByComparator orderByComparator)
806                    throws NoSuchRuleException, SystemException {
807                    MDRRule mdrRule = findByPrimaryKey(ruleId);
808    
809                    Session session = null;
810    
811                    try {
812                            session = openSession();
813    
814                            MDRRule[] array = new MDRRuleImpl[3];
815    
816                            array[0] = getByUuid_PrevAndNext(session, mdrRule, uuid,
817                                            orderByComparator, true);
818    
819                            array[1] = mdrRule;
820    
821                            array[2] = getByUuid_PrevAndNext(session, mdrRule, uuid,
822                                            orderByComparator, false);
823    
824                            return array;
825                    }
826                    catch (Exception e) {
827                            throw processException(e);
828                    }
829                    finally {
830                            closeSession(session);
831                    }
832            }
833    
834            protected MDRRule getByUuid_PrevAndNext(Session session, MDRRule mdrRule,
835                    String uuid, OrderByComparator orderByComparator, boolean previous) {
836                    StringBundler query = null;
837    
838                    if (orderByComparator != null) {
839                            query = new StringBundler(6 +
840                                            (orderByComparator.getOrderByFields().length * 6));
841                    }
842                    else {
843                            query = new StringBundler(3);
844                    }
845    
846                    query.append(_SQL_SELECT_MDRRULE_WHERE);
847    
848                    if (uuid == null) {
849                            query.append(_FINDER_COLUMN_UUID_UUID_1);
850                    }
851                    else {
852                            if (uuid.equals(StringPool.BLANK)) {
853                                    query.append(_FINDER_COLUMN_UUID_UUID_3);
854                            }
855                            else {
856                                    query.append(_FINDER_COLUMN_UUID_UUID_2);
857                            }
858                    }
859    
860                    if (orderByComparator != null) {
861                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
862    
863                            if (orderByConditionFields.length > 0) {
864                                    query.append(WHERE_AND);
865                            }
866    
867                            for (int i = 0; i < orderByConditionFields.length; i++) {
868                                    query.append(_ORDER_BY_ENTITY_ALIAS);
869                                    query.append(orderByConditionFields[i]);
870    
871                                    if ((i + 1) < orderByConditionFields.length) {
872                                            if (orderByComparator.isAscending() ^ previous) {
873                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
874                                            }
875                                            else {
876                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
877                                            }
878                                    }
879                                    else {
880                                            if (orderByComparator.isAscending() ^ previous) {
881                                                    query.append(WHERE_GREATER_THAN);
882                                            }
883                                            else {
884                                                    query.append(WHERE_LESSER_THAN);
885                                            }
886                                    }
887                            }
888    
889                            query.append(ORDER_BY_CLAUSE);
890    
891                            String[] orderByFields = orderByComparator.getOrderByFields();
892    
893                            for (int i = 0; i < orderByFields.length; i++) {
894                                    query.append(_ORDER_BY_ENTITY_ALIAS);
895                                    query.append(orderByFields[i]);
896    
897                                    if ((i + 1) < orderByFields.length) {
898                                            if (orderByComparator.isAscending() ^ previous) {
899                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
900                                            }
901                                            else {
902                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
903                                            }
904                                    }
905                                    else {
906                                            if (orderByComparator.isAscending() ^ previous) {
907                                                    query.append(ORDER_BY_ASC);
908                                            }
909                                            else {
910                                                    query.append(ORDER_BY_DESC);
911                                            }
912                                    }
913                            }
914                    }
915    
916                    String sql = query.toString();
917    
918                    Query q = session.createQuery(sql);
919    
920                    q.setFirstResult(0);
921                    q.setMaxResults(2);
922    
923                    QueryPos qPos = QueryPos.getInstance(q);
924    
925                    if (uuid != null) {
926                            qPos.add(uuid);
927                    }
928    
929                    if (orderByComparator != null) {
930                            Object[] values = orderByComparator.getOrderByConditionValues(mdrRule);
931    
932                            for (Object value : values) {
933                                    qPos.add(value);
934                            }
935                    }
936    
937                    List<MDRRule> list = q.list();
938    
939                    if (list.size() == 2) {
940                            return list.get(1);
941                    }
942                    else {
943                            return null;
944                    }
945            }
946    
947            /**
948             * Returns the m d r rule where uuid = &#63; and groupId = &#63; or throws a {@link com.liferay.portlet.mobiledevicerules.NoSuchRuleException} if it could not be found.
949             *
950             * @param uuid the uuid
951             * @param groupId the group ID
952             * @return the matching m d r rule
953             * @throws com.liferay.portlet.mobiledevicerules.NoSuchRuleException if a matching m d r rule could not be found
954             * @throws SystemException if a system exception occurred
955             */
956            public MDRRule findByUUID_G(String uuid, long groupId)
957                    throws NoSuchRuleException, SystemException {
958                    MDRRule mdrRule = fetchByUUID_G(uuid, groupId);
959    
960                    if (mdrRule == null) {
961                            StringBundler msg = new StringBundler(6);
962    
963                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
964    
965                            msg.append("uuid=");
966                            msg.append(uuid);
967    
968                            msg.append(", groupId=");
969                            msg.append(groupId);
970    
971                            msg.append(StringPool.CLOSE_CURLY_BRACE);
972    
973                            if (_log.isWarnEnabled()) {
974                                    _log.warn(msg.toString());
975                            }
976    
977                            throw new NoSuchRuleException(msg.toString());
978                    }
979    
980                    return mdrRule;
981            }
982    
983            /**
984             * Returns the m d r rule where uuid = &#63; and groupId = &#63; or returns <code>null</code> if it could not be found. Uses the finder cache.
985             *
986             * @param uuid the uuid
987             * @param groupId the group ID
988             * @return the matching m d r rule, or <code>null</code> if a matching m d r rule could not be found
989             * @throws SystemException if a system exception occurred
990             */
991            public MDRRule fetchByUUID_G(String uuid, long groupId)
992                    throws SystemException {
993                    return fetchByUUID_G(uuid, groupId, true);
994            }
995    
996            /**
997             * Returns the m d r rule where uuid = &#63; and groupId = &#63; or returns <code>null</code> if it could not be found, optionally using the finder cache.
998             *
999             * @param uuid the uuid
1000             * @param groupId the group ID
1001             * @param retrieveFromCache whether to use the finder cache
1002             * @return the matching m d r rule, or <code>null</code> if a matching m d r rule could not be found
1003             * @throws SystemException if a system exception occurred
1004             */
1005            public MDRRule fetchByUUID_G(String uuid, long groupId,
1006                    boolean retrieveFromCache) throws SystemException {
1007                    Object[] finderArgs = new Object[] { uuid, groupId };
1008    
1009                    Object result = null;
1010    
1011                    if (retrieveFromCache) {
1012                            result = FinderCacheUtil.getResult(FINDER_PATH_FETCH_BY_UUID_G,
1013                                            finderArgs, this);
1014                    }
1015    
1016                    if (result instanceof MDRRule) {
1017                            MDRRule mdrRule = (MDRRule)result;
1018    
1019                            if (!Validator.equals(uuid, mdrRule.getUuid()) ||
1020                                            (groupId != mdrRule.getGroupId())) {
1021                                    result = null;
1022                            }
1023                    }
1024    
1025                    if (result == null) {
1026                            StringBundler query = new StringBundler(3);
1027    
1028                            query.append(_SQL_SELECT_MDRRULE_WHERE);
1029    
1030                            if (uuid == null) {
1031                                    query.append(_FINDER_COLUMN_UUID_G_UUID_1);
1032                            }
1033                            else {
1034                                    if (uuid.equals(StringPool.BLANK)) {
1035                                            query.append(_FINDER_COLUMN_UUID_G_UUID_3);
1036                                    }
1037                                    else {
1038                                            query.append(_FINDER_COLUMN_UUID_G_UUID_2);
1039                                    }
1040                            }
1041    
1042                            query.append(_FINDER_COLUMN_UUID_G_GROUPID_2);
1043    
1044                            String sql = query.toString();
1045    
1046                            Session session = null;
1047    
1048                            try {
1049                                    session = openSession();
1050    
1051                                    Query q = session.createQuery(sql);
1052    
1053                                    QueryPos qPos = QueryPos.getInstance(q);
1054    
1055                                    if (uuid != null) {
1056                                            qPos.add(uuid);
1057                                    }
1058    
1059                                    qPos.add(groupId);
1060    
1061                                    List<MDRRule> list = q.list();
1062    
1063                                    result = list;
1064    
1065                                    MDRRule mdrRule = null;
1066    
1067                                    if (list.isEmpty()) {
1068                                            FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_UUID_G,
1069                                                    finderArgs, list);
1070                                    }
1071                                    else {
1072                                            mdrRule = list.get(0);
1073    
1074                                            cacheResult(mdrRule);
1075    
1076                                            if ((mdrRule.getUuid() == null) ||
1077                                                            !mdrRule.getUuid().equals(uuid) ||
1078                                                            (mdrRule.getGroupId() != groupId)) {
1079                                                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_UUID_G,
1080                                                            finderArgs, mdrRule);
1081                                            }
1082                                    }
1083    
1084                                    return mdrRule;
1085                            }
1086                            catch (Exception e) {
1087                                    throw processException(e);
1088                            }
1089                            finally {
1090                                    if (result == null) {
1091                                            FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_UUID_G,
1092                                                    finderArgs);
1093                                    }
1094    
1095                                    closeSession(session);
1096                            }
1097                    }
1098                    else {
1099                            if (result instanceof List<?>) {
1100                                    return null;
1101                            }
1102                            else {
1103                                    return (MDRRule)result;
1104                            }
1105                    }
1106            }
1107    
1108            /**
1109             * Returns all the m d r rules where ruleGroupId = &#63;.
1110             *
1111             * @param ruleGroupId the rule group ID
1112             * @return the matching m d r rules
1113             * @throws SystemException if a system exception occurred
1114             */
1115            public List<MDRRule> findByRuleGroupId(long ruleGroupId)
1116                    throws SystemException {
1117                    return findByRuleGroupId(ruleGroupId, QueryUtil.ALL_POS,
1118                            QueryUtil.ALL_POS, null);
1119            }
1120    
1121            /**
1122             * Returns a range of all the m d r rules where ruleGroupId = &#63;.
1123             *
1124             * <p>
1125             * 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.
1126             * </p>
1127             *
1128             * @param ruleGroupId the rule group ID
1129             * @param start the lower bound of the range of m d r rules
1130             * @param end the upper bound of the range of m d r rules (not inclusive)
1131             * @return the range of matching m d r rules
1132             * @throws SystemException if a system exception occurred
1133             */
1134            public List<MDRRule> findByRuleGroupId(long ruleGroupId, int start, int end)
1135                    throws SystemException {
1136                    return findByRuleGroupId(ruleGroupId, start, end, null);
1137            }
1138    
1139            /**
1140             * Returns an ordered range of all the m d r rules where ruleGroupId = &#63;.
1141             *
1142             * <p>
1143             * 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.
1144             * </p>
1145             *
1146             * @param ruleGroupId the rule group ID
1147             * @param start the lower bound of the range of m d r rules
1148             * @param end the upper bound of the range of m d r rules (not inclusive)
1149             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
1150             * @return the ordered range of matching m d r rules
1151             * @throws SystemException if a system exception occurred
1152             */
1153            public List<MDRRule> findByRuleGroupId(long ruleGroupId, int start,
1154                    int end, OrderByComparator orderByComparator) throws SystemException {
1155                    FinderPath finderPath = null;
1156                    Object[] finderArgs = null;
1157    
1158                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
1159                                    (orderByComparator == null)) {
1160                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_RULEGROUPID;
1161                            finderArgs = new Object[] { ruleGroupId };
1162                    }
1163                    else {
1164                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_RULEGROUPID;
1165                            finderArgs = new Object[] { ruleGroupId, start, end, orderByComparator };
1166                    }
1167    
1168                    List<MDRRule> list = (List<MDRRule>)FinderCacheUtil.getResult(finderPath,
1169                                    finderArgs, this);
1170    
1171                    if ((list != null) && !list.isEmpty()) {
1172                            for (MDRRule mdrRule : list) {
1173                                    if ((ruleGroupId != mdrRule.getRuleGroupId())) {
1174                                            list = null;
1175    
1176                                            break;
1177                                    }
1178                            }
1179                    }
1180    
1181                    if (list == null) {
1182                            StringBundler query = null;
1183    
1184                            if (orderByComparator != null) {
1185                                    query = new StringBundler(3 +
1186                                                    (orderByComparator.getOrderByFields().length * 3));
1187                            }
1188                            else {
1189                                    query = new StringBundler(2);
1190                            }
1191    
1192                            query.append(_SQL_SELECT_MDRRULE_WHERE);
1193    
1194                            query.append(_FINDER_COLUMN_RULEGROUPID_RULEGROUPID_2);
1195    
1196                            if (orderByComparator != null) {
1197                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1198                                            orderByComparator);
1199                            }
1200    
1201                            String sql = query.toString();
1202    
1203                            Session session = null;
1204    
1205                            try {
1206                                    session = openSession();
1207    
1208                                    Query q = session.createQuery(sql);
1209    
1210                                    QueryPos qPos = QueryPos.getInstance(q);
1211    
1212                                    qPos.add(ruleGroupId);
1213    
1214                                    list = (List<MDRRule>)QueryUtil.list(q, getDialect(), start, end);
1215                            }
1216                            catch (Exception e) {
1217                                    throw processException(e);
1218                            }
1219                            finally {
1220                                    if (list == null) {
1221                                            FinderCacheUtil.removeResult(finderPath, finderArgs);
1222                                    }
1223                                    else {
1224                                            cacheResult(list);
1225    
1226                                            FinderCacheUtil.putResult(finderPath, finderArgs, list);
1227                                    }
1228    
1229                                    closeSession(session);
1230                            }
1231                    }
1232    
1233                    return list;
1234            }
1235    
1236            /**
1237             * Returns the first m d r rule in the ordered set where ruleGroupId = &#63;.
1238             *
1239             * @param ruleGroupId the rule group ID
1240             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1241             * @return the first matching m d r rule
1242             * @throws com.liferay.portlet.mobiledevicerules.NoSuchRuleException if a matching m d r rule could not be found
1243             * @throws SystemException if a system exception occurred
1244             */
1245            public MDRRule findByRuleGroupId_First(long ruleGroupId,
1246                    OrderByComparator orderByComparator)
1247                    throws NoSuchRuleException, SystemException {
1248                    MDRRule mdrRule = fetchByRuleGroupId_First(ruleGroupId,
1249                                    orderByComparator);
1250    
1251                    if (mdrRule != null) {
1252                            return mdrRule;
1253                    }
1254    
1255                    StringBundler msg = new StringBundler(4);
1256    
1257                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1258    
1259                    msg.append("ruleGroupId=");
1260                    msg.append(ruleGroupId);
1261    
1262                    msg.append(StringPool.CLOSE_CURLY_BRACE);
1263    
1264                    throw new NoSuchRuleException(msg.toString());
1265            }
1266    
1267            /**
1268             * Returns the first m d r rule in the ordered set where ruleGroupId = &#63;.
1269             *
1270             * @param ruleGroupId the rule group ID
1271             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1272             * @return the first matching m d r rule, or <code>null</code> if a matching m d r rule could not be found
1273             * @throws SystemException if a system exception occurred
1274             */
1275            public MDRRule fetchByRuleGroupId_First(long ruleGroupId,
1276                    OrderByComparator orderByComparator) throws SystemException {
1277                    List<MDRRule> list = findByRuleGroupId(ruleGroupId, 0, 1,
1278                                    orderByComparator);
1279    
1280                    if (!list.isEmpty()) {
1281                            return list.get(0);
1282                    }
1283    
1284                    return null;
1285            }
1286    
1287            /**
1288             * Returns the last m d r rule in the ordered set where ruleGroupId = &#63;.
1289             *
1290             * @param ruleGroupId the rule group ID
1291             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1292             * @return the last matching m d r rule
1293             * @throws com.liferay.portlet.mobiledevicerules.NoSuchRuleException if a matching m d r rule could not be found
1294             * @throws SystemException if a system exception occurred
1295             */
1296            public MDRRule findByRuleGroupId_Last(long ruleGroupId,
1297                    OrderByComparator orderByComparator)
1298                    throws NoSuchRuleException, SystemException {
1299                    MDRRule mdrRule = fetchByRuleGroupId_Last(ruleGroupId, orderByComparator);
1300    
1301                    if (mdrRule != null) {
1302                            return mdrRule;
1303                    }
1304    
1305                    StringBundler msg = new StringBundler(4);
1306    
1307                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1308    
1309                    msg.append("ruleGroupId=");
1310                    msg.append(ruleGroupId);
1311    
1312                    msg.append(StringPool.CLOSE_CURLY_BRACE);
1313    
1314                    throw new NoSuchRuleException(msg.toString());
1315            }
1316    
1317            /**
1318             * Returns the last m d r rule in the ordered set where ruleGroupId = &#63;.
1319             *
1320             * @param ruleGroupId the rule group ID
1321             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1322             * @return the last matching m d r rule, or <code>null</code> if a matching m d r rule could not be found
1323             * @throws SystemException if a system exception occurred
1324             */
1325            public MDRRule fetchByRuleGroupId_Last(long ruleGroupId,
1326                    OrderByComparator orderByComparator) throws SystemException {
1327                    int count = countByRuleGroupId(ruleGroupId);
1328    
1329                    List<MDRRule> list = findByRuleGroupId(ruleGroupId, count - 1, count,
1330                                    orderByComparator);
1331    
1332                    if (!list.isEmpty()) {
1333                            return list.get(0);
1334                    }
1335    
1336                    return null;
1337            }
1338    
1339            /**
1340             * Returns the m d r rules before and after the current m d r rule in the ordered set where ruleGroupId = &#63;.
1341             *
1342             * @param ruleId the primary key of the current m d r rule
1343             * @param ruleGroupId the rule group ID
1344             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1345             * @return the previous, current, and next m d r rule
1346             * @throws com.liferay.portlet.mobiledevicerules.NoSuchRuleException if a m d r rule with the primary key could not be found
1347             * @throws SystemException if a system exception occurred
1348             */
1349            public MDRRule[] findByRuleGroupId_PrevAndNext(long ruleId,
1350                    long ruleGroupId, OrderByComparator orderByComparator)
1351                    throws NoSuchRuleException, SystemException {
1352                    MDRRule mdrRule = findByPrimaryKey(ruleId);
1353    
1354                    Session session = null;
1355    
1356                    try {
1357                            session = openSession();
1358    
1359                            MDRRule[] array = new MDRRuleImpl[3];
1360    
1361                            array[0] = getByRuleGroupId_PrevAndNext(session, mdrRule,
1362                                            ruleGroupId, orderByComparator, true);
1363    
1364                            array[1] = mdrRule;
1365    
1366                            array[2] = getByRuleGroupId_PrevAndNext(session, mdrRule,
1367                                            ruleGroupId, orderByComparator, false);
1368    
1369                            return array;
1370                    }
1371                    catch (Exception e) {
1372                            throw processException(e);
1373                    }
1374                    finally {
1375                            closeSession(session);
1376                    }
1377            }
1378    
1379            protected MDRRule getByRuleGroupId_PrevAndNext(Session session,
1380                    MDRRule mdrRule, long ruleGroupId, OrderByComparator orderByComparator,
1381                    boolean previous) {
1382                    StringBundler query = null;
1383    
1384                    if (orderByComparator != null) {
1385                            query = new StringBundler(6 +
1386                                            (orderByComparator.getOrderByFields().length * 6));
1387                    }
1388                    else {
1389                            query = new StringBundler(3);
1390                    }
1391    
1392                    query.append(_SQL_SELECT_MDRRULE_WHERE);
1393    
1394                    query.append(_FINDER_COLUMN_RULEGROUPID_RULEGROUPID_2);
1395    
1396                    if (orderByComparator != null) {
1397                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
1398    
1399                            if (orderByConditionFields.length > 0) {
1400                                    query.append(WHERE_AND);
1401                            }
1402    
1403                            for (int i = 0; i < orderByConditionFields.length; i++) {
1404                                    query.append(_ORDER_BY_ENTITY_ALIAS);
1405                                    query.append(orderByConditionFields[i]);
1406    
1407                                    if ((i + 1) < orderByConditionFields.length) {
1408                                            if (orderByComparator.isAscending() ^ previous) {
1409                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
1410                                            }
1411                                            else {
1412                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
1413                                            }
1414                                    }
1415                                    else {
1416                                            if (orderByComparator.isAscending() ^ previous) {
1417                                                    query.append(WHERE_GREATER_THAN);
1418                                            }
1419                                            else {
1420                                                    query.append(WHERE_LESSER_THAN);
1421                                            }
1422                                    }
1423                            }
1424    
1425                            query.append(ORDER_BY_CLAUSE);
1426    
1427                            String[] orderByFields = orderByComparator.getOrderByFields();
1428    
1429                            for (int i = 0; i < orderByFields.length; i++) {
1430                                    query.append(_ORDER_BY_ENTITY_ALIAS);
1431                                    query.append(orderByFields[i]);
1432    
1433                                    if ((i + 1) < orderByFields.length) {
1434                                            if (orderByComparator.isAscending() ^ previous) {
1435                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
1436                                            }
1437                                            else {
1438                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
1439                                            }
1440                                    }
1441                                    else {
1442                                            if (orderByComparator.isAscending() ^ previous) {
1443                                                    query.append(ORDER_BY_ASC);
1444                                            }
1445                                            else {
1446                                                    query.append(ORDER_BY_DESC);
1447                                            }
1448                                    }
1449                            }
1450                    }
1451    
1452                    String sql = query.toString();
1453    
1454                    Query q = session.createQuery(sql);
1455    
1456                    q.setFirstResult(0);
1457                    q.setMaxResults(2);
1458    
1459                    QueryPos qPos = QueryPos.getInstance(q);
1460    
1461                    qPos.add(ruleGroupId);
1462    
1463                    if (orderByComparator != null) {
1464                            Object[] values = orderByComparator.getOrderByConditionValues(mdrRule);
1465    
1466                            for (Object value : values) {
1467                                    qPos.add(value);
1468                            }
1469                    }
1470    
1471                    List<MDRRule> list = q.list();
1472    
1473                    if (list.size() == 2) {
1474                            return list.get(1);
1475                    }
1476                    else {
1477                            return null;
1478                    }
1479            }
1480    
1481            /**
1482             * Returns all the m d r rules.
1483             *
1484             * @return the m d r rules
1485             * @throws SystemException if a system exception occurred
1486             */
1487            public List<MDRRule> findAll() throws SystemException {
1488                    return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
1489            }
1490    
1491            /**
1492             * Returns a range of all the m d r rules.
1493             *
1494             * <p>
1495             * 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.
1496             * </p>
1497             *
1498             * @param start the lower bound of the range of m d r rules
1499             * @param end the upper bound of the range of m d r rules (not inclusive)
1500             * @return the range of m d r rules
1501             * @throws SystemException if a system exception occurred
1502             */
1503            public List<MDRRule> findAll(int start, int end) throws SystemException {
1504                    return findAll(start, end, null);
1505            }
1506    
1507            /**
1508             * Returns an ordered range of all the m d r rules.
1509             *
1510             * <p>
1511             * 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.
1512             * </p>
1513             *
1514             * @param start the lower bound of the range of m d r rules
1515             * @param end the upper bound of the range of m d r rules (not inclusive)
1516             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
1517             * @return the ordered range of m d r rules
1518             * @throws SystemException if a system exception occurred
1519             */
1520            public List<MDRRule> findAll(int start, int end,
1521                    OrderByComparator orderByComparator) throws SystemException {
1522                    FinderPath finderPath = null;
1523                    Object[] finderArgs = new Object[] { start, end, orderByComparator };
1524    
1525                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
1526                                    (orderByComparator == null)) {
1527                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL;
1528                            finderArgs = FINDER_ARGS_EMPTY;
1529                    }
1530                    else {
1531                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_ALL;
1532                            finderArgs = new Object[] { start, end, orderByComparator };
1533                    }
1534    
1535                    List<MDRRule> list = (List<MDRRule>)FinderCacheUtil.getResult(finderPath,
1536                                    finderArgs, this);
1537    
1538                    if (list == null) {
1539                            StringBundler query = null;
1540                            String sql = null;
1541    
1542                            if (orderByComparator != null) {
1543                                    query = new StringBundler(2 +
1544                                                    (orderByComparator.getOrderByFields().length * 3));
1545    
1546                                    query.append(_SQL_SELECT_MDRRULE);
1547    
1548                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1549                                            orderByComparator);
1550    
1551                                    sql = query.toString();
1552                            }
1553                            else {
1554                                    sql = _SQL_SELECT_MDRRULE;
1555                            }
1556    
1557                            Session session = null;
1558    
1559                            try {
1560                                    session = openSession();
1561    
1562                                    Query q = session.createQuery(sql);
1563    
1564                                    if (orderByComparator == null) {
1565                                            list = (List<MDRRule>)QueryUtil.list(q, getDialect(),
1566                                                            start, end, false);
1567    
1568                                            Collections.sort(list);
1569                                    }
1570                                    else {
1571                                            list = (List<MDRRule>)QueryUtil.list(q, getDialect(),
1572                                                            start, end);
1573                                    }
1574                            }
1575                            catch (Exception e) {
1576                                    throw processException(e);
1577                            }
1578                            finally {
1579                                    if (list == null) {
1580                                            FinderCacheUtil.removeResult(finderPath, finderArgs);
1581                                    }
1582                                    else {
1583                                            cacheResult(list);
1584    
1585                                            FinderCacheUtil.putResult(finderPath, finderArgs, list);
1586                                    }
1587    
1588                                    closeSession(session);
1589                            }
1590                    }
1591    
1592                    return list;
1593            }
1594    
1595            /**
1596             * Removes all the m d r rules where uuid = &#63; from the database.
1597             *
1598             * @param uuid the uuid
1599             * @throws SystemException if a system exception occurred
1600             */
1601            public void removeByUuid(String uuid) throws SystemException {
1602                    for (MDRRule mdrRule : findByUuid(uuid)) {
1603                            remove(mdrRule);
1604                    }
1605            }
1606    
1607            /**
1608             * Removes the m d r rule where uuid = &#63; and groupId = &#63; from the database.
1609             *
1610             * @param uuid the uuid
1611             * @param groupId the group ID
1612             * @return the m d r rule that was removed
1613             * @throws SystemException if a system exception occurred
1614             */
1615            public MDRRule removeByUUID_G(String uuid, long groupId)
1616                    throws NoSuchRuleException, SystemException {
1617                    MDRRule mdrRule = findByUUID_G(uuid, groupId);
1618    
1619                    return remove(mdrRule);
1620            }
1621    
1622            /**
1623             * Removes all the m d r rules where ruleGroupId = &#63; from the database.
1624             *
1625             * @param ruleGroupId the rule group ID
1626             * @throws SystemException if a system exception occurred
1627             */
1628            public void removeByRuleGroupId(long ruleGroupId) throws SystemException {
1629                    for (MDRRule mdrRule : findByRuleGroupId(ruleGroupId)) {
1630                            remove(mdrRule);
1631                    }
1632            }
1633    
1634            /**
1635             * Removes all the m d r rules from the database.
1636             *
1637             * @throws SystemException if a system exception occurred
1638             */
1639            public void removeAll() throws SystemException {
1640                    for (MDRRule mdrRule : findAll()) {
1641                            remove(mdrRule);
1642                    }
1643            }
1644    
1645            /**
1646             * Returns the number of m d r rules where uuid = &#63;.
1647             *
1648             * @param uuid the uuid
1649             * @return the number of matching m d r rules
1650             * @throws SystemException if a system exception occurred
1651             */
1652            public int countByUuid(String uuid) throws SystemException {
1653                    Object[] finderArgs = new Object[] { uuid };
1654    
1655                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_UUID,
1656                                    finderArgs, this);
1657    
1658                    if (count == null) {
1659                            StringBundler query = new StringBundler(2);
1660    
1661                            query.append(_SQL_COUNT_MDRRULE_WHERE);
1662    
1663                            if (uuid == null) {
1664                                    query.append(_FINDER_COLUMN_UUID_UUID_1);
1665                            }
1666                            else {
1667                                    if (uuid.equals(StringPool.BLANK)) {
1668                                            query.append(_FINDER_COLUMN_UUID_UUID_3);
1669                                    }
1670                                    else {
1671                                            query.append(_FINDER_COLUMN_UUID_UUID_2);
1672                                    }
1673                            }
1674    
1675                            String sql = query.toString();
1676    
1677                            Session session = null;
1678    
1679                            try {
1680                                    session = openSession();
1681    
1682                                    Query q = session.createQuery(sql);
1683    
1684                                    QueryPos qPos = QueryPos.getInstance(q);
1685    
1686                                    if (uuid != null) {
1687                                            qPos.add(uuid);
1688                                    }
1689    
1690                                    count = (Long)q.uniqueResult();
1691                            }
1692                            catch (Exception e) {
1693                                    throw processException(e);
1694                            }
1695                            finally {
1696                                    if (count == null) {
1697                                            count = Long.valueOf(0);
1698                                    }
1699    
1700                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_UUID,
1701                                            finderArgs, count);
1702    
1703                                    closeSession(session);
1704                            }
1705                    }
1706    
1707                    return count.intValue();
1708            }
1709    
1710            /**
1711             * Returns the number of m d r rules where uuid = &#63; and groupId = &#63;.
1712             *
1713             * @param uuid the uuid
1714             * @param groupId the group ID
1715             * @return the number of matching m d r rules
1716             * @throws SystemException if a system exception occurred
1717             */
1718            public int countByUUID_G(String uuid, long groupId)
1719                    throws SystemException {
1720                    Object[] finderArgs = new Object[] { uuid, groupId };
1721    
1722                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_UUID_G,
1723                                    finderArgs, this);
1724    
1725                    if (count == null) {
1726                            StringBundler query = new StringBundler(3);
1727    
1728                            query.append(_SQL_COUNT_MDRRULE_WHERE);
1729    
1730                            if (uuid == null) {
1731                                    query.append(_FINDER_COLUMN_UUID_G_UUID_1);
1732                            }
1733                            else {
1734                                    if (uuid.equals(StringPool.BLANK)) {
1735                                            query.append(_FINDER_COLUMN_UUID_G_UUID_3);
1736                                    }
1737                                    else {
1738                                            query.append(_FINDER_COLUMN_UUID_G_UUID_2);
1739                                    }
1740                            }
1741    
1742                            query.append(_FINDER_COLUMN_UUID_G_GROUPID_2);
1743    
1744                            String sql = query.toString();
1745    
1746                            Session session = null;
1747    
1748                            try {
1749                                    session = openSession();
1750    
1751                                    Query q = session.createQuery(sql);
1752    
1753                                    QueryPos qPos = QueryPos.getInstance(q);
1754    
1755                                    if (uuid != null) {
1756                                            qPos.add(uuid);
1757                                    }
1758    
1759                                    qPos.add(groupId);
1760    
1761                                    count = (Long)q.uniqueResult();
1762                            }
1763                            catch (Exception e) {
1764                                    throw processException(e);
1765                            }
1766                            finally {
1767                                    if (count == null) {
1768                                            count = Long.valueOf(0);
1769                                    }
1770    
1771                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_UUID_G,
1772                                            finderArgs, count);
1773    
1774                                    closeSession(session);
1775                            }
1776                    }
1777    
1778                    return count.intValue();
1779            }
1780    
1781            /**
1782             * Returns the number of m d r rules where ruleGroupId = &#63;.
1783             *
1784             * @param ruleGroupId the rule group ID
1785             * @return the number of matching m d r rules
1786             * @throws SystemException if a system exception occurred
1787             */
1788            public int countByRuleGroupId(long ruleGroupId) throws SystemException {
1789                    Object[] finderArgs = new Object[] { ruleGroupId };
1790    
1791                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_RULEGROUPID,
1792                                    finderArgs, this);
1793    
1794                    if (count == null) {
1795                            StringBundler query = new StringBundler(2);
1796    
1797                            query.append(_SQL_COUNT_MDRRULE_WHERE);
1798    
1799                            query.append(_FINDER_COLUMN_RULEGROUPID_RULEGROUPID_2);
1800    
1801                            String sql = query.toString();
1802    
1803                            Session session = null;
1804    
1805                            try {
1806                                    session = openSession();
1807    
1808                                    Query q = session.createQuery(sql);
1809    
1810                                    QueryPos qPos = QueryPos.getInstance(q);
1811    
1812                                    qPos.add(ruleGroupId);
1813    
1814                                    count = (Long)q.uniqueResult();
1815                            }
1816                            catch (Exception e) {
1817                                    throw processException(e);
1818                            }
1819                            finally {
1820                                    if (count == null) {
1821                                            count = Long.valueOf(0);
1822                                    }
1823    
1824                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_RULEGROUPID,
1825                                            finderArgs, count);
1826    
1827                                    closeSession(session);
1828                            }
1829                    }
1830    
1831                    return count.intValue();
1832            }
1833    
1834            /**
1835             * Returns the number of m d r rules.
1836             *
1837             * @return the number of m d r rules
1838             * @throws SystemException if a system exception occurred
1839             */
1840            public int countAll() throws SystemException {
1841                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_ALL,
1842                                    FINDER_ARGS_EMPTY, this);
1843    
1844                    if (count == null) {
1845                            Session session = null;
1846    
1847                            try {
1848                                    session = openSession();
1849    
1850                                    Query q = session.createQuery(_SQL_COUNT_MDRRULE);
1851    
1852                                    count = (Long)q.uniqueResult();
1853                            }
1854                            catch (Exception e) {
1855                                    throw processException(e);
1856                            }
1857                            finally {
1858                                    if (count == null) {
1859                                            count = Long.valueOf(0);
1860                                    }
1861    
1862                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_ALL,
1863                                            FINDER_ARGS_EMPTY, count);
1864    
1865                                    closeSession(session);
1866                            }
1867                    }
1868    
1869                    return count.intValue();
1870            }
1871    
1872            /**
1873             * Initializes the m d r rule persistence.
1874             */
1875            public void afterPropertiesSet() {
1876                    String[] listenerClassNames = StringUtil.split(GetterUtil.getString(
1877                                            com.liferay.portal.util.PropsUtil.get(
1878                                                    "value.object.listener.com.liferay.portlet.mobiledevicerules.model.MDRRule")));
1879    
1880                    if (listenerClassNames.length > 0) {
1881                            try {
1882                                    List<ModelListener<MDRRule>> listenersList = new ArrayList<ModelListener<MDRRule>>();
1883    
1884                                    for (String listenerClassName : listenerClassNames) {
1885                                            listenersList.add((ModelListener<MDRRule>)InstanceFactory.newInstance(
1886                                                            listenerClassName));
1887                                    }
1888    
1889                                    listeners = listenersList.toArray(new ModelListener[listenersList.size()]);
1890                            }
1891                            catch (Exception e) {
1892                                    _log.error(e);
1893                            }
1894                    }
1895            }
1896    
1897            public void destroy() {
1898                    EntityCacheUtil.removeCache(MDRRuleImpl.class.getName());
1899                    FinderCacheUtil.removeCache(FINDER_CLASS_NAME_ENTITY);
1900                    FinderCacheUtil.removeCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
1901            }
1902    
1903            @BeanReference(type = MDRActionPersistence.class)
1904            protected MDRActionPersistence mdrActionPersistence;
1905            @BeanReference(type = MDRRulePersistence.class)
1906            protected MDRRulePersistence mdrRulePersistence;
1907            @BeanReference(type = MDRRuleGroupPersistence.class)
1908            protected MDRRuleGroupPersistence mdrRuleGroupPersistence;
1909            @BeanReference(type = MDRRuleGroupInstancePersistence.class)
1910            protected MDRRuleGroupInstancePersistence mdrRuleGroupInstancePersistence;
1911            @BeanReference(type = ResourcePersistence.class)
1912            protected ResourcePersistence resourcePersistence;
1913            @BeanReference(type = UserPersistence.class)
1914            protected UserPersistence userPersistence;
1915            private static final String _SQL_SELECT_MDRRULE = "SELECT mdrRule FROM MDRRule mdrRule";
1916            private static final String _SQL_SELECT_MDRRULE_WHERE = "SELECT mdrRule FROM MDRRule mdrRule WHERE ";
1917            private static final String _SQL_COUNT_MDRRULE = "SELECT COUNT(mdrRule) FROM MDRRule mdrRule";
1918            private static final String _SQL_COUNT_MDRRULE_WHERE = "SELECT COUNT(mdrRule) FROM MDRRule mdrRule WHERE ";
1919            private static final String _FINDER_COLUMN_UUID_UUID_1 = "mdrRule.uuid IS NULL";
1920            private static final String _FINDER_COLUMN_UUID_UUID_2 = "mdrRule.uuid = ?";
1921            private static final String _FINDER_COLUMN_UUID_UUID_3 = "(mdrRule.uuid IS NULL OR mdrRule.uuid = ?)";
1922            private static final String _FINDER_COLUMN_UUID_G_UUID_1 = "mdrRule.uuid IS NULL AND ";
1923            private static final String _FINDER_COLUMN_UUID_G_UUID_2 = "mdrRule.uuid = ? AND ";
1924            private static final String _FINDER_COLUMN_UUID_G_UUID_3 = "(mdrRule.uuid IS NULL OR mdrRule.uuid = ?) AND ";
1925            private static final String _FINDER_COLUMN_UUID_G_GROUPID_2 = "mdrRule.groupId = ?";
1926            private static final String _FINDER_COLUMN_RULEGROUPID_RULEGROUPID_2 = "mdrRule.ruleGroupId = ?";
1927            private static final String _ORDER_BY_ENTITY_ALIAS = "mdrRule.";
1928            private static final String _NO_SUCH_ENTITY_WITH_PRIMARY_KEY = "No MDRRule exists with the primary key ";
1929            private static final String _NO_SUCH_ENTITY_WITH_KEY = "No MDRRule exists with the key {";
1930            private static final boolean _HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE = com.liferay.portal.util.PropsValues.HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE;
1931            private static Log _log = LogFactoryUtil.getLog(MDRRulePersistenceImpl.class);
1932            private static MDRRule _nullMDRRule = new MDRRuleImpl() {
1933                            @Override
1934                            public Object clone() {
1935                                    return this;
1936                            }
1937    
1938                            @Override
1939                            public CacheModel<MDRRule> toCacheModel() {
1940                                    return _nullMDRRuleCacheModel;
1941                            }
1942                    };
1943    
1944            private static CacheModel<MDRRule> _nullMDRRuleCacheModel = new CacheModel<MDRRule>() {
1945                            public MDRRule toEntityModel() {
1946                                    return _nullMDRRule;
1947                            }
1948                    };
1949    }