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