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