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