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