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