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