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