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