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