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