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