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            /**
1329             * Caches the d d m storage link in the entity cache if it is enabled.
1330             *
1331             * @param ddmStorageLink the d d m storage link
1332             */
1333            @Override
1334            public void cacheResult(DDMStorageLink ddmStorageLink) {
1335                    EntityCacheUtil.putResult(DDMStorageLinkModelImpl.ENTITY_CACHE_ENABLED,
1336                            DDMStorageLinkImpl.class, ddmStorageLink.getPrimaryKey(),
1337                            ddmStorageLink);
1338    
1339                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_CLASSPK,
1340                            new Object[] { ddmStorageLink.getClassPK() }, ddmStorageLink);
1341    
1342                    ddmStorageLink.resetOriginalValues();
1343            }
1344    
1345            /**
1346             * Caches the d d m storage links in the entity cache if it is enabled.
1347             *
1348             * @param ddmStorageLinks the d d m storage links
1349             */
1350            @Override
1351            public void cacheResult(List<DDMStorageLink> ddmStorageLinks) {
1352                    for (DDMStorageLink ddmStorageLink : ddmStorageLinks) {
1353                            if (EntityCacheUtil.getResult(
1354                                                    DDMStorageLinkModelImpl.ENTITY_CACHE_ENABLED,
1355                                                    DDMStorageLinkImpl.class, ddmStorageLink.getPrimaryKey()) == null) {
1356                                    cacheResult(ddmStorageLink);
1357                            }
1358                            else {
1359                                    ddmStorageLink.resetOriginalValues();
1360                            }
1361                    }
1362            }
1363    
1364            /**
1365             * Clears the cache for all d d m storage links.
1366             *
1367             * <p>
1368             * The {@link com.liferay.portal.kernel.dao.orm.EntityCache} and {@link com.liferay.portal.kernel.dao.orm.FinderCache} are both cleared by this method.
1369             * </p>
1370             */
1371            @Override
1372            public void clearCache() {
1373                    if (_HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE) {
1374                            CacheRegistryUtil.clear(DDMStorageLinkImpl.class.getName());
1375                    }
1376    
1377                    EntityCacheUtil.clearCache(DDMStorageLinkImpl.class.getName());
1378    
1379                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_ENTITY);
1380                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
1381                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
1382            }
1383    
1384            /**
1385             * Clears the cache for the d d m storage link.
1386             *
1387             * <p>
1388             * The {@link com.liferay.portal.kernel.dao.orm.EntityCache} and {@link com.liferay.portal.kernel.dao.orm.FinderCache} are both cleared by this method.
1389             * </p>
1390             */
1391            @Override
1392            public void clearCache(DDMStorageLink ddmStorageLink) {
1393                    EntityCacheUtil.removeResult(DDMStorageLinkModelImpl.ENTITY_CACHE_ENABLED,
1394                            DDMStorageLinkImpl.class, ddmStorageLink.getPrimaryKey());
1395    
1396                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
1397                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
1398    
1399                    clearUniqueFindersCache(ddmStorageLink);
1400            }
1401    
1402            @Override
1403            public void clearCache(List<DDMStorageLink> ddmStorageLinks) {
1404                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
1405                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
1406    
1407                    for (DDMStorageLink ddmStorageLink : ddmStorageLinks) {
1408                            EntityCacheUtil.removeResult(DDMStorageLinkModelImpl.ENTITY_CACHE_ENABLED,
1409                                    DDMStorageLinkImpl.class, ddmStorageLink.getPrimaryKey());
1410    
1411                            clearUniqueFindersCache(ddmStorageLink);
1412                    }
1413            }
1414    
1415            protected void cacheUniqueFindersCache(DDMStorageLink ddmStorageLink) {
1416                    if (ddmStorageLink.isNew()) {
1417                            Object[] args = new Object[] { ddmStorageLink.getClassPK() };
1418    
1419                            FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_CLASSPK, args,
1420                                    Long.valueOf(1));
1421                            FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_CLASSPK, args,
1422                                    ddmStorageLink);
1423                    }
1424                    else {
1425                            DDMStorageLinkModelImpl ddmStorageLinkModelImpl = (DDMStorageLinkModelImpl)ddmStorageLink;
1426    
1427                            if ((ddmStorageLinkModelImpl.getColumnBitmask() &
1428                                            FINDER_PATH_FETCH_BY_CLASSPK.getColumnBitmask()) != 0) {
1429                                    Object[] args = new Object[] { ddmStorageLink.getClassPK() };
1430    
1431                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_CLASSPK, args,
1432                                            Long.valueOf(1));
1433                                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_CLASSPK, args,
1434                                            ddmStorageLink);
1435                            }
1436                    }
1437            }
1438    
1439            protected void clearUniqueFindersCache(DDMStorageLink ddmStorageLink) {
1440                    DDMStorageLinkModelImpl ddmStorageLinkModelImpl = (DDMStorageLinkModelImpl)ddmStorageLink;
1441    
1442                    Object[] args = new Object[] { ddmStorageLink.getClassPK() };
1443    
1444                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_CLASSPK, args);
1445                    FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_CLASSPK, args);
1446    
1447                    if ((ddmStorageLinkModelImpl.getColumnBitmask() &
1448                                    FINDER_PATH_FETCH_BY_CLASSPK.getColumnBitmask()) != 0) {
1449                            args = new Object[] { ddmStorageLinkModelImpl.getOriginalClassPK() };
1450    
1451                            FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_CLASSPK, args);
1452                            FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_CLASSPK, args);
1453                    }
1454            }
1455    
1456            /**
1457             * Creates a new d d m storage link with the primary key. Does not add the d d m storage link to the database.
1458             *
1459             * @param storageLinkId the primary key for the new d d m storage link
1460             * @return the new d d m storage link
1461             */
1462            @Override
1463            public DDMStorageLink create(long storageLinkId) {
1464                    DDMStorageLink ddmStorageLink = new DDMStorageLinkImpl();
1465    
1466                    ddmStorageLink.setNew(true);
1467                    ddmStorageLink.setPrimaryKey(storageLinkId);
1468    
1469                    String uuid = PortalUUIDUtil.generate();
1470    
1471                    ddmStorageLink.setUuid(uuid);
1472    
1473                    return ddmStorageLink;
1474            }
1475    
1476            /**
1477             * Removes the d d m storage link with the primary key from the database. Also notifies the appropriate model listeners.
1478             *
1479             * @param storageLinkId the primary key of the d d m storage link
1480             * @return the d d m storage link that was removed
1481             * @throws com.liferay.portlet.dynamicdatamapping.NoSuchStorageLinkException if a d d m storage link with the primary key could not be found
1482             * @throws SystemException if a system exception occurred
1483             */
1484            @Override
1485            public DDMStorageLink remove(long storageLinkId)
1486                    throws NoSuchStorageLinkException, SystemException {
1487                    return remove((Serializable)storageLinkId);
1488            }
1489    
1490            /**
1491             * Removes the d d m storage link with the primary key from the database. Also notifies the appropriate model listeners.
1492             *
1493             * @param primaryKey the primary key of the d d m storage link
1494             * @return the d d m storage link that was removed
1495             * @throws com.liferay.portlet.dynamicdatamapping.NoSuchStorageLinkException if a d d m storage link with the primary key could not be found
1496             * @throws SystemException if a system exception occurred
1497             */
1498            @Override
1499            public DDMStorageLink remove(Serializable primaryKey)
1500                    throws NoSuchStorageLinkException, SystemException {
1501                    Session session = null;
1502    
1503                    try {
1504                            session = openSession();
1505    
1506                            DDMStorageLink ddmStorageLink = (DDMStorageLink)session.get(DDMStorageLinkImpl.class,
1507                                            primaryKey);
1508    
1509                            if (ddmStorageLink == null) {
1510                                    if (_log.isWarnEnabled()) {
1511                                            _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + primaryKey);
1512                                    }
1513    
1514                                    throw new NoSuchStorageLinkException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
1515                                            primaryKey);
1516                            }
1517    
1518                            return remove(ddmStorageLink);
1519                    }
1520                    catch (NoSuchStorageLinkException nsee) {
1521                            throw nsee;
1522                    }
1523                    catch (Exception e) {
1524                            throw processException(e);
1525                    }
1526                    finally {
1527                            closeSession(session);
1528                    }
1529            }
1530    
1531            @Override
1532            protected DDMStorageLink removeImpl(DDMStorageLink ddmStorageLink)
1533                    throws SystemException {
1534                    ddmStorageLink = toUnwrappedModel(ddmStorageLink);
1535    
1536                    Session session = null;
1537    
1538                    try {
1539                            session = openSession();
1540    
1541                            if (!session.contains(ddmStorageLink)) {
1542                                    ddmStorageLink = (DDMStorageLink)session.get(DDMStorageLinkImpl.class,
1543                                                    ddmStorageLink.getPrimaryKeyObj());
1544                            }
1545    
1546                            if (ddmStorageLink != null) {
1547                                    session.delete(ddmStorageLink);
1548                            }
1549                    }
1550                    catch (Exception e) {
1551                            throw processException(e);
1552                    }
1553                    finally {
1554                            closeSession(session);
1555                    }
1556    
1557                    if (ddmStorageLink != null) {
1558                            clearCache(ddmStorageLink);
1559                    }
1560    
1561                    return ddmStorageLink;
1562            }
1563    
1564            @Override
1565            public DDMStorageLink updateImpl(
1566                    com.liferay.portlet.dynamicdatamapping.model.DDMStorageLink ddmStorageLink)
1567                    throws SystemException {
1568                    ddmStorageLink = toUnwrappedModel(ddmStorageLink);
1569    
1570                    boolean isNew = ddmStorageLink.isNew();
1571    
1572                    DDMStorageLinkModelImpl ddmStorageLinkModelImpl = (DDMStorageLinkModelImpl)ddmStorageLink;
1573    
1574                    if (Validator.isNull(ddmStorageLink.getUuid())) {
1575                            String uuid = PortalUUIDUtil.generate();
1576    
1577                            ddmStorageLink.setUuid(uuid);
1578                    }
1579    
1580                    Session session = null;
1581    
1582                    try {
1583                            session = openSession();
1584    
1585                            if (ddmStorageLink.isNew()) {
1586                                    session.save(ddmStorageLink);
1587    
1588                                    ddmStorageLink.setNew(false);
1589                            }
1590                            else {
1591                                    session.merge(ddmStorageLink);
1592                            }
1593                    }
1594                    catch (Exception e) {
1595                            throw processException(e);
1596                    }
1597                    finally {
1598                            closeSession(session);
1599                    }
1600    
1601                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
1602    
1603                    if (isNew || !DDMStorageLinkModelImpl.COLUMN_BITMASK_ENABLED) {
1604                            FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
1605                    }
1606    
1607                    else {
1608                            if ((ddmStorageLinkModelImpl.getColumnBitmask() &
1609                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID.getColumnBitmask()) != 0) {
1610                                    Object[] args = new Object[] {
1611                                                    ddmStorageLinkModelImpl.getOriginalUuid()
1612                                            };
1613    
1614                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_UUID, args);
1615                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID,
1616                                            args);
1617    
1618                                    args = new Object[] { ddmStorageLinkModelImpl.getUuid() };
1619    
1620                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_UUID, args);
1621                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID,
1622                                            args);
1623                            }
1624    
1625                            if ((ddmStorageLinkModelImpl.getColumnBitmask() &
1626                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_STRUCTUREID.getColumnBitmask()) != 0) {
1627                                    Object[] args = new Object[] {
1628                                                    ddmStorageLinkModelImpl.getOriginalStructureId()
1629                                            };
1630    
1631                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_STRUCTUREID,
1632                                            args);
1633                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_STRUCTUREID,
1634                                            args);
1635    
1636                                    args = new Object[] { ddmStorageLinkModelImpl.getStructureId() };
1637    
1638                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_STRUCTUREID,
1639                                            args);
1640                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_STRUCTUREID,
1641                                            args);
1642                            }
1643                    }
1644    
1645                    EntityCacheUtil.putResult(DDMStorageLinkModelImpl.ENTITY_CACHE_ENABLED,
1646                            DDMStorageLinkImpl.class, ddmStorageLink.getPrimaryKey(),
1647                            ddmStorageLink);
1648    
1649                    clearUniqueFindersCache(ddmStorageLink);
1650                    cacheUniqueFindersCache(ddmStorageLink);
1651    
1652                    return ddmStorageLink;
1653            }
1654    
1655            protected DDMStorageLink toUnwrappedModel(DDMStorageLink ddmStorageLink) {
1656                    if (ddmStorageLink instanceof DDMStorageLinkImpl) {
1657                            return ddmStorageLink;
1658                    }
1659    
1660                    DDMStorageLinkImpl ddmStorageLinkImpl = new DDMStorageLinkImpl();
1661    
1662                    ddmStorageLinkImpl.setNew(ddmStorageLink.isNew());
1663                    ddmStorageLinkImpl.setPrimaryKey(ddmStorageLink.getPrimaryKey());
1664    
1665                    ddmStorageLinkImpl.setUuid(ddmStorageLink.getUuid());
1666                    ddmStorageLinkImpl.setStorageLinkId(ddmStorageLink.getStorageLinkId());
1667                    ddmStorageLinkImpl.setClassNameId(ddmStorageLink.getClassNameId());
1668                    ddmStorageLinkImpl.setClassPK(ddmStorageLink.getClassPK());
1669                    ddmStorageLinkImpl.setStructureId(ddmStorageLink.getStructureId());
1670    
1671                    return ddmStorageLinkImpl;
1672            }
1673    
1674            /**
1675             * 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.
1676             *
1677             * @param primaryKey the primary key of the d d m storage link
1678             * @return the d d m storage link
1679             * @throws com.liferay.portlet.dynamicdatamapping.NoSuchStorageLinkException if a d d m storage link with the primary key could not be found
1680             * @throws SystemException if a system exception occurred
1681             */
1682            @Override
1683            public DDMStorageLink findByPrimaryKey(Serializable primaryKey)
1684                    throws NoSuchStorageLinkException, SystemException {
1685                    DDMStorageLink ddmStorageLink = fetchByPrimaryKey(primaryKey);
1686    
1687                    if (ddmStorageLink == null) {
1688                            if (_log.isWarnEnabled()) {
1689                                    _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + primaryKey);
1690                            }
1691    
1692                            throw new NoSuchStorageLinkException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
1693                                    primaryKey);
1694                    }
1695    
1696                    return ddmStorageLink;
1697            }
1698    
1699            /**
1700             * 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.
1701             *
1702             * @param storageLinkId the primary key of the d d m storage link
1703             * @return the d d m storage link
1704             * @throws com.liferay.portlet.dynamicdatamapping.NoSuchStorageLinkException if a d d m storage link with the primary key could not be found
1705             * @throws SystemException if a system exception occurred
1706             */
1707            @Override
1708            public DDMStorageLink findByPrimaryKey(long storageLinkId)
1709                    throws NoSuchStorageLinkException, SystemException {
1710                    return findByPrimaryKey((Serializable)storageLinkId);
1711            }
1712    
1713            /**
1714             * Returns the d d m storage link with the primary key or returns <code>null</code> if it could not be found.
1715             *
1716             * @param primaryKey the primary key of the d d m storage link
1717             * @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
1718             * @throws SystemException if a system exception occurred
1719             */
1720            @Override
1721            public DDMStorageLink fetchByPrimaryKey(Serializable primaryKey)
1722                    throws SystemException {
1723                    DDMStorageLink ddmStorageLink = (DDMStorageLink)EntityCacheUtil.getResult(DDMStorageLinkModelImpl.ENTITY_CACHE_ENABLED,
1724                                    DDMStorageLinkImpl.class, primaryKey);
1725    
1726                    if (ddmStorageLink == _nullDDMStorageLink) {
1727                            return null;
1728                    }
1729    
1730                    if (ddmStorageLink == null) {
1731                            Session session = null;
1732    
1733                            try {
1734                                    session = openSession();
1735    
1736                                    ddmStorageLink = (DDMStorageLink)session.get(DDMStorageLinkImpl.class,
1737                                                    primaryKey);
1738    
1739                                    if (ddmStorageLink != null) {
1740                                            cacheResult(ddmStorageLink);
1741                                    }
1742                                    else {
1743                                            EntityCacheUtil.putResult(DDMStorageLinkModelImpl.ENTITY_CACHE_ENABLED,
1744                                                    DDMStorageLinkImpl.class, primaryKey,
1745                                                    _nullDDMStorageLink);
1746                                    }
1747                            }
1748                            catch (Exception e) {
1749                                    EntityCacheUtil.removeResult(DDMStorageLinkModelImpl.ENTITY_CACHE_ENABLED,
1750                                            DDMStorageLinkImpl.class, primaryKey);
1751    
1752                                    throw processException(e);
1753                            }
1754                            finally {
1755                                    closeSession(session);
1756                            }
1757                    }
1758    
1759                    return ddmStorageLink;
1760            }
1761    
1762            /**
1763             * Returns the d d m storage link with the primary key or returns <code>null</code> if it could not be found.
1764             *
1765             * @param storageLinkId the primary key of the d d m storage link
1766             * @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
1767             * @throws SystemException if a system exception occurred
1768             */
1769            @Override
1770            public DDMStorageLink fetchByPrimaryKey(long storageLinkId)
1771                    throws SystemException {
1772                    return fetchByPrimaryKey((Serializable)storageLinkId);
1773            }
1774    
1775            /**
1776             * Returns all the d d m storage links.
1777             *
1778             * @return the d d m storage links
1779             * @throws SystemException if a system exception occurred
1780             */
1781            @Override
1782            public List<DDMStorageLink> findAll() throws SystemException {
1783                    return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
1784            }
1785    
1786            /**
1787             * Returns a range of all the d d m storage links.
1788             *
1789             * <p>
1790             * 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.
1791             * </p>
1792             *
1793             * @param start the lower bound of the range of d d m storage links
1794             * @param end the upper bound of the range of d d m storage links (not inclusive)
1795             * @return the range of d d m storage links
1796             * @throws SystemException if a system exception occurred
1797             */
1798            @Override
1799            public List<DDMStorageLink> findAll(int start, int end)
1800                    throws SystemException {
1801                    return findAll(start, end, null);
1802            }
1803    
1804            /**
1805             * Returns an ordered range of all the d d m storage links.
1806             *
1807             * <p>
1808             * 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.
1809             * </p>
1810             *
1811             * @param start the lower bound of the range of d d m storage links
1812             * @param end the upper bound of the range of d d m storage links (not inclusive)
1813             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
1814             * @return the ordered range of d d m storage links
1815             * @throws SystemException if a system exception occurred
1816             */
1817            @Override
1818            public List<DDMStorageLink> findAll(int start, int end,
1819                    OrderByComparator orderByComparator) throws SystemException {
1820                    boolean pagination = true;
1821                    FinderPath finderPath = null;
1822                    Object[] finderArgs = null;
1823    
1824                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
1825                                    (orderByComparator == null)) {
1826                            pagination = false;
1827                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL;
1828                            finderArgs = FINDER_ARGS_EMPTY;
1829                    }
1830                    else {
1831                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_ALL;
1832                            finderArgs = new Object[] { start, end, orderByComparator };
1833                    }
1834    
1835                    List<DDMStorageLink> list = (List<DDMStorageLink>)FinderCacheUtil.getResult(finderPath,
1836                                    finderArgs, this);
1837    
1838                    if (list == null) {
1839                            StringBundler query = null;
1840                            String sql = null;
1841    
1842                            if (orderByComparator != null) {
1843                                    query = new StringBundler(2 +
1844                                                    (orderByComparator.getOrderByFields().length * 3));
1845    
1846                                    query.append(_SQL_SELECT_DDMSTORAGELINK);
1847    
1848                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1849                                            orderByComparator);
1850    
1851                                    sql = query.toString();
1852                            }
1853                            else {
1854                                    sql = _SQL_SELECT_DDMSTORAGELINK;
1855    
1856                                    if (pagination) {
1857                                            sql = sql.concat(DDMStorageLinkModelImpl.ORDER_BY_JPQL);
1858                                    }
1859                            }
1860    
1861                            Session session = null;
1862    
1863                            try {
1864                                    session = openSession();
1865    
1866                                    Query q = session.createQuery(sql);
1867    
1868                                    if (!pagination) {
1869                                            list = (List<DDMStorageLink>)QueryUtil.list(q,
1870                                                            getDialect(), start, end, false);
1871    
1872                                            Collections.sort(list);
1873    
1874                                            list = new UnmodifiableList<DDMStorageLink>(list);
1875                                    }
1876                                    else {
1877                                            list = (List<DDMStorageLink>)QueryUtil.list(q,
1878                                                            getDialect(), start, end);
1879                                    }
1880    
1881                                    cacheResult(list);
1882    
1883                                    FinderCacheUtil.putResult(finderPath, finderArgs, list);
1884                            }
1885                            catch (Exception e) {
1886                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
1887    
1888                                    throw processException(e);
1889                            }
1890                            finally {
1891                                    closeSession(session);
1892                            }
1893                    }
1894    
1895                    return list;
1896            }
1897    
1898            /**
1899             * Removes all the d d m storage links from the database.
1900             *
1901             * @throws SystemException if a system exception occurred
1902             */
1903            @Override
1904            public void removeAll() throws SystemException {
1905                    for (DDMStorageLink ddmStorageLink : findAll()) {
1906                            remove(ddmStorageLink);
1907                    }
1908            }
1909    
1910            /**
1911             * Returns the number of d d m storage links.
1912             *
1913             * @return the number of d d m storage links
1914             * @throws SystemException if a system exception occurred
1915             */
1916            @Override
1917            public int countAll() throws SystemException {
1918                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_ALL,
1919                                    FINDER_ARGS_EMPTY, this);
1920    
1921                    if (count == null) {
1922                            Session session = null;
1923    
1924                            try {
1925                                    session = openSession();
1926    
1927                                    Query q = session.createQuery(_SQL_COUNT_DDMSTORAGELINK);
1928    
1929                                    count = (Long)q.uniqueResult();
1930    
1931                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_ALL,
1932                                            FINDER_ARGS_EMPTY, count);
1933                            }
1934                            catch (Exception e) {
1935                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_ALL,
1936                                            FINDER_ARGS_EMPTY);
1937    
1938                                    throw processException(e);
1939                            }
1940                            finally {
1941                                    closeSession(session);
1942                            }
1943                    }
1944    
1945                    return count.intValue();
1946            }
1947    
1948            @Override
1949            protected Set<String> getBadColumnNames() {
1950                    return _badColumnNames;
1951            }
1952    
1953            /**
1954             * Initializes the d d m storage link persistence.
1955             */
1956            public void afterPropertiesSet() {
1957                    String[] listenerClassNames = StringUtil.split(GetterUtil.getString(
1958                                            com.liferay.portal.util.PropsUtil.get(
1959                                                    "value.object.listener.com.liferay.portlet.dynamicdatamapping.model.DDMStorageLink")));
1960    
1961                    if (listenerClassNames.length > 0) {
1962                            try {
1963                                    List<ModelListener<DDMStorageLink>> listenersList = new ArrayList<ModelListener<DDMStorageLink>>();
1964    
1965                                    for (String listenerClassName : listenerClassNames) {
1966                                            listenersList.add((ModelListener<DDMStorageLink>)InstanceFactory.newInstance(
1967                                                            getClassLoader(), listenerClassName));
1968                                    }
1969    
1970                                    listeners = listenersList.toArray(new ModelListener[listenersList.size()]);
1971                            }
1972                            catch (Exception e) {
1973                                    _log.error(e);
1974                            }
1975                    }
1976            }
1977    
1978            public void destroy() {
1979                    EntityCacheUtil.removeCache(DDMStorageLinkImpl.class.getName());
1980                    FinderCacheUtil.removeCache(FINDER_CLASS_NAME_ENTITY);
1981                    FinderCacheUtil.removeCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
1982                    FinderCacheUtil.removeCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
1983            }
1984    
1985            private static final String _SQL_SELECT_DDMSTORAGELINK = "SELECT ddmStorageLink FROM DDMStorageLink ddmStorageLink";
1986            private static final String _SQL_SELECT_DDMSTORAGELINK_WHERE = "SELECT ddmStorageLink FROM DDMStorageLink ddmStorageLink WHERE ";
1987            private static final String _SQL_COUNT_DDMSTORAGELINK = "SELECT COUNT(ddmStorageLink) FROM DDMStorageLink ddmStorageLink";
1988            private static final String _SQL_COUNT_DDMSTORAGELINK_WHERE = "SELECT COUNT(ddmStorageLink) FROM DDMStorageLink ddmStorageLink WHERE ";
1989            private static final String _ORDER_BY_ENTITY_ALIAS = "ddmStorageLink.";
1990            private static final String _NO_SUCH_ENTITY_WITH_PRIMARY_KEY = "No DDMStorageLink exists with the primary key ";
1991            private static final String _NO_SUCH_ENTITY_WITH_KEY = "No DDMStorageLink exists with the key {";
1992            private static final boolean _HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE = com.liferay.portal.util.PropsValues.HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE;
1993            private static Log _log = LogFactoryUtil.getLog(DDMStorageLinkPersistenceImpl.class);
1994            private static Set<String> _badColumnNames = SetUtil.fromArray(new String[] {
1995                                    "uuid"
1996                            });
1997            private static DDMStorageLink _nullDDMStorageLink = new DDMStorageLinkImpl() {
1998                            @Override
1999                            public Object clone() {
2000                                    return this;
2001                            }
2002    
2003                            @Override
2004                            public CacheModel<DDMStorageLink> toCacheModel() {
2005                                    return _nullDDMStorageLinkCacheModel;
2006                            }
2007                    };
2008    
2009            private static CacheModel<DDMStorageLink> _nullDDMStorageLinkCacheModel = new CacheModel<DDMStorageLink>() {
2010                            @Override
2011                            public DDMStorageLink toEntityModel() {
2012                                    return _nullDDMStorageLink;
2013                            }
2014                    };
2015    }