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