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.SetUtil;
030    import com.liferay.portal.kernel.util.StringBundler;
031    import com.liferay.portal.kernel.util.StringPool;
032    import com.liferay.portal.kernel.util.Validator;
033    import com.liferay.portal.kernel.uuid.PortalUUIDUtil;
034    import com.liferay.portal.model.CacheModel;
035    import com.liferay.portal.service.ServiceContext;
036    import com.liferay.portal.service.ServiceContextThreadLocal;
037    import com.liferay.portal.service.persistence.impl.BasePersistenceImpl;
038    
039    import com.liferay.portlet.dynamicdatamapping.NoSuchStructureLayoutException;
040    import com.liferay.portlet.dynamicdatamapping.model.DDMStructureLayout;
041    import com.liferay.portlet.dynamicdatamapping.model.impl.DDMStructureLayoutImpl;
042    import com.liferay.portlet.dynamicdatamapping.model.impl.DDMStructureLayoutModelImpl;
043    import com.liferay.portlet.dynamicdatamapping.service.persistence.DDMStructureLayoutPersistence;
044    
045    import java.io.Serializable;
046    
047    import java.util.Collections;
048    import java.util.Date;
049    import java.util.HashMap;
050    import java.util.HashSet;
051    import java.util.Iterator;
052    import java.util.List;
053    import java.util.Map;
054    import java.util.Set;
055    
056    /**
057     * The persistence implementation for the d d m structure layout service.
058     *
059     * <p>
060     * Caching information and settings can be found in <code>portal.properties</code>
061     * </p>
062     *
063     * @author Brian Wing Shun Chan
064     * @see DDMStructureLayoutPersistence
065     * @see com.liferay.portlet.dynamicdatamapping.service.persistence.DDMStructureLayoutUtil
066     * @generated
067     */
068    @ProviderType
069    public class DDMStructureLayoutPersistenceImpl extends BasePersistenceImpl<DDMStructureLayout>
070            implements DDMStructureLayoutPersistence {
071            /*
072             * NOTE FOR DEVELOPERS:
073             *
074             * Never modify or reference this class directly. Always use {@link DDMStructureLayoutUtil} to access the d d m structure layout persistence. Modify <code>service.xml</code> and rerun ServiceBuilder to regenerate this class.
075             */
076            public static final String FINDER_CLASS_NAME_ENTITY = DDMStructureLayoutImpl.class.getName();
077            public static final String FINDER_CLASS_NAME_LIST_WITH_PAGINATION = FINDER_CLASS_NAME_ENTITY +
078                    ".List1";
079            public static final String FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION = FINDER_CLASS_NAME_ENTITY +
080                    ".List2";
081            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_ALL = new FinderPath(DDMStructureLayoutModelImpl.ENTITY_CACHE_ENABLED,
082                            DDMStructureLayoutModelImpl.FINDER_CACHE_ENABLED,
083                            DDMStructureLayoutImpl.class,
084                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findAll", new String[0]);
085            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL = new FinderPath(DDMStructureLayoutModelImpl.ENTITY_CACHE_ENABLED,
086                            DDMStructureLayoutModelImpl.FINDER_CACHE_ENABLED,
087                            DDMStructureLayoutImpl.class,
088                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findAll", new String[0]);
089            public static final FinderPath FINDER_PATH_COUNT_ALL = new FinderPath(DDMStructureLayoutModelImpl.ENTITY_CACHE_ENABLED,
090                            DDMStructureLayoutModelImpl.FINDER_CACHE_ENABLED, Long.class,
091                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countAll", new String[0]);
092            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_UUID = new FinderPath(DDMStructureLayoutModelImpl.ENTITY_CACHE_ENABLED,
093                            DDMStructureLayoutModelImpl.FINDER_CACHE_ENABLED,
094                            DDMStructureLayoutImpl.class,
095                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByUuid",
096                            new String[] {
097                                    String.class.getName(),
098                                    
099                            Integer.class.getName(), Integer.class.getName(),
100                                    OrderByComparator.class.getName()
101                            });
102            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID = new FinderPath(DDMStructureLayoutModelImpl.ENTITY_CACHE_ENABLED,
103                            DDMStructureLayoutModelImpl.FINDER_CACHE_ENABLED,
104                            DDMStructureLayoutImpl.class,
105                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByUuid",
106                            new String[] { String.class.getName() },
107                            DDMStructureLayoutModelImpl.UUID_COLUMN_BITMASK);
108            public static final FinderPath FINDER_PATH_COUNT_BY_UUID = new FinderPath(DDMStructureLayoutModelImpl.ENTITY_CACHE_ENABLED,
109                            DDMStructureLayoutModelImpl.FINDER_CACHE_ENABLED, Long.class,
110                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByUuid",
111                            new String[] { String.class.getName() });
112    
113            /**
114             * Returns all the d d m structure layouts where uuid = &#63;.
115             *
116             * @param uuid the uuid
117             * @return the matching d d m structure layouts
118             */
119            @Override
120            public List<DDMStructureLayout> findByUuid(String uuid) {
121                    return findByUuid(uuid, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
122            }
123    
124            /**
125             * Returns a range of all the d d m structure layouts where uuid = &#63;.
126             *
127             * <p>
128             * 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 DDMStructureLayoutModelImpl}. 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.
129             * </p>
130             *
131             * @param uuid the uuid
132             * @param start the lower bound of the range of d d m structure layouts
133             * @param end the upper bound of the range of d d m structure layouts (not inclusive)
134             * @return the range of matching d d m structure layouts
135             */
136            @Override
137            public List<DDMStructureLayout> findByUuid(String uuid, int start, int end) {
138                    return findByUuid(uuid, start, end, null);
139            }
140    
141            /**
142             * Returns an ordered range of all the d d m structure layouts where uuid = &#63;.
143             *
144             * <p>
145             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link 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 DDMStructureLayoutModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
146             * </p>
147             *
148             * @param uuid the uuid
149             * @param start the lower bound of the range of d d m structure layouts
150             * @param end the upper bound of the range of d d m structure layouts (not inclusive)
151             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
152             * @return the ordered range of matching d d m structure layouts
153             */
154            @Override
155            public List<DDMStructureLayout> findByUuid(String uuid, int start, int end,
156                    OrderByComparator<DDMStructureLayout> orderByComparator) {
157                    boolean pagination = true;
158                    FinderPath finderPath = null;
159                    Object[] finderArgs = null;
160    
161                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
162                                    (orderByComparator == null)) {
163                            pagination = false;
164                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID;
165                            finderArgs = new Object[] { uuid };
166                    }
167                    else {
168                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_UUID;
169                            finderArgs = new Object[] { uuid, start, end, orderByComparator };
170                    }
171    
172                    List<DDMStructureLayout> list = (List<DDMStructureLayout>)FinderCacheUtil.getResult(finderPath,
173                                    finderArgs, this);
174    
175                    if ((list != null) && !list.isEmpty()) {
176                            for (DDMStructureLayout ddmStructureLayout : list) {
177                                    if (!Validator.equals(uuid, ddmStructureLayout.getUuid())) {
178                                            list = null;
179    
180                                            break;
181                                    }
182                            }
183                    }
184    
185                    if (list == null) {
186                            StringBundler query = null;
187    
188                            if (orderByComparator != null) {
189                                    query = new StringBundler(3 +
190                                                    (orderByComparator.getOrderByFields().length * 3));
191                            }
192                            else {
193                                    query = new StringBundler(3);
194                            }
195    
196                            query.append(_SQL_SELECT_DDMSTRUCTURELAYOUT_WHERE);
197    
198                            boolean bindUuid = false;
199    
200                            if (uuid == null) {
201                                    query.append(_FINDER_COLUMN_UUID_UUID_1);
202                            }
203                            else if (uuid.equals(StringPool.BLANK)) {
204                                    query.append(_FINDER_COLUMN_UUID_UUID_3);
205                            }
206                            else {
207                                    bindUuid = true;
208    
209                                    query.append(_FINDER_COLUMN_UUID_UUID_2);
210                            }
211    
212                            if (orderByComparator != null) {
213                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
214                                            orderByComparator);
215                            }
216                            else
217                             if (pagination) {
218                                    query.append(DDMStructureLayoutModelImpl.ORDER_BY_JPQL);
219                            }
220    
221                            String sql = query.toString();
222    
223                            Session session = null;
224    
225                            try {
226                                    session = openSession();
227    
228                                    Query q = session.createQuery(sql);
229    
230                                    QueryPos qPos = QueryPos.getInstance(q);
231    
232                                    if (bindUuid) {
233                                            qPos.add(uuid);
234                                    }
235    
236                                    if (!pagination) {
237                                            list = (List<DDMStructureLayout>)QueryUtil.list(q,
238                                                            getDialect(), start, end, false);
239    
240                                            Collections.sort(list);
241    
242                                            list = Collections.unmodifiableList(list);
243                                    }
244                                    else {
245                                            list = (List<DDMStructureLayout>)QueryUtil.list(q,
246                                                            getDialect(), start, end);
247                                    }
248    
249                                    cacheResult(list);
250    
251                                    FinderCacheUtil.putResult(finderPath, finderArgs, list);
252                            }
253                            catch (Exception e) {
254                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
255    
256                                    throw processException(e);
257                            }
258                            finally {
259                                    closeSession(session);
260                            }
261                    }
262    
263                    return list;
264            }
265    
266            /**
267             * Returns the first d d m structure layout in the ordered set where uuid = &#63;.
268             *
269             * @param uuid the uuid
270             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
271             * @return the first matching d d m structure layout
272             * @throws NoSuchStructureLayoutException if a matching d d m structure layout could not be found
273             */
274            @Override
275            public DDMStructureLayout findByUuid_First(String uuid,
276                    OrderByComparator<DDMStructureLayout> orderByComparator)
277                    throws NoSuchStructureLayoutException {
278                    DDMStructureLayout ddmStructureLayout = fetchByUuid_First(uuid,
279                                    orderByComparator);
280    
281                    if (ddmStructureLayout != null) {
282                            return ddmStructureLayout;
283                    }
284    
285                    StringBundler msg = new StringBundler(4);
286    
287                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
288    
289                    msg.append("uuid=");
290                    msg.append(uuid);
291    
292                    msg.append(StringPool.CLOSE_CURLY_BRACE);
293    
294                    throw new NoSuchStructureLayoutException(msg.toString());
295            }
296    
297            /**
298             * Returns the first d d m structure layout in the ordered set where uuid = &#63;.
299             *
300             * @param uuid the uuid
301             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
302             * @return the first matching d d m structure layout, or <code>null</code> if a matching d d m structure layout could not be found
303             */
304            @Override
305            public DDMStructureLayout fetchByUuid_First(String uuid,
306                    OrderByComparator<DDMStructureLayout> orderByComparator) {
307                    List<DDMStructureLayout> list = findByUuid(uuid, 0, 1, orderByComparator);
308    
309                    if (!list.isEmpty()) {
310                            return list.get(0);
311                    }
312    
313                    return null;
314            }
315    
316            /**
317             * Returns the last d d m structure layout in the ordered set where uuid = &#63;.
318             *
319             * @param uuid the uuid
320             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
321             * @return the last matching d d m structure layout
322             * @throws NoSuchStructureLayoutException if a matching d d m structure layout could not be found
323             */
324            @Override
325            public DDMStructureLayout findByUuid_Last(String uuid,
326                    OrderByComparator<DDMStructureLayout> orderByComparator)
327                    throws NoSuchStructureLayoutException {
328                    DDMStructureLayout ddmStructureLayout = fetchByUuid_Last(uuid,
329                                    orderByComparator);
330    
331                    if (ddmStructureLayout != null) {
332                            return ddmStructureLayout;
333                    }
334    
335                    StringBundler msg = new StringBundler(4);
336    
337                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
338    
339                    msg.append("uuid=");
340                    msg.append(uuid);
341    
342                    msg.append(StringPool.CLOSE_CURLY_BRACE);
343    
344                    throw new NoSuchStructureLayoutException(msg.toString());
345            }
346    
347            /**
348             * Returns the last d d m structure layout in the ordered set where uuid = &#63;.
349             *
350             * @param uuid the uuid
351             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
352             * @return the last matching d d m structure layout, or <code>null</code> if a matching d d m structure layout could not be found
353             */
354            @Override
355            public DDMStructureLayout fetchByUuid_Last(String uuid,
356                    OrderByComparator<DDMStructureLayout> orderByComparator) {
357                    int count = countByUuid(uuid);
358    
359                    if (count == 0) {
360                            return null;
361                    }
362    
363                    List<DDMStructureLayout> list = findByUuid(uuid, count - 1, count,
364                                    orderByComparator);
365    
366                    if (!list.isEmpty()) {
367                            return list.get(0);
368                    }
369    
370                    return null;
371            }
372    
373            /**
374             * Returns the d d m structure layouts before and after the current d d m structure layout in the ordered set where uuid = &#63;.
375             *
376             * @param structureLayoutId the primary key of the current d d m structure layout
377             * @param uuid the uuid
378             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
379             * @return the previous, current, and next d d m structure layout
380             * @throws NoSuchStructureLayoutException if a d d m structure layout with the primary key could not be found
381             */
382            @Override
383            public DDMStructureLayout[] findByUuid_PrevAndNext(long structureLayoutId,
384                    String uuid, OrderByComparator<DDMStructureLayout> orderByComparator)
385                    throws NoSuchStructureLayoutException {
386                    DDMStructureLayout ddmStructureLayout = findByPrimaryKey(structureLayoutId);
387    
388                    Session session = null;
389    
390                    try {
391                            session = openSession();
392    
393                            DDMStructureLayout[] array = new DDMStructureLayoutImpl[3];
394    
395                            array[0] = getByUuid_PrevAndNext(session, ddmStructureLayout, uuid,
396                                            orderByComparator, true);
397    
398                            array[1] = ddmStructureLayout;
399    
400                            array[2] = getByUuid_PrevAndNext(session, ddmStructureLayout, uuid,
401                                            orderByComparator, false);
402    
403                            return array;
404                    }
405                    catch (Exception e) {
406                            throw processException(e);
407                    }
408                    finally {
409                            closeSession(session);
410                    }
411            }
412    
413            protected DDMStructureLayout getByUuid_PrevAndNext(Session session,
414                    DDMStructureLayout ddmStructureLayout, String uuid,
415                    OrderByComparator<DDMStructureLayout> orderByComparator,
416                    boolean previous) {
417                    StringBundler query = null;
418    
419                    if (orderByComparator != null) {
420                            query = new StringBundler(6 +
421                                            (orderByComparator.getOrderByFields().length * 6));
422                    }
423                    else {
424                            query = new StringBundler(3);
425                    }
426    
427                    query.append(_SQL_SELECT_DDMSTRUCTURELAYOUT_WHERE);
428    
429                    boolean bindUuid = false;
430    
431                    if (uuid == null) {
432                            query.append(_FINDER_COLUMN_UUID_UUID_1);
433                    }
434                    else if (uuid.equals(StringPool.BLANK)) {
435                            query.append(_FINDER_COLUMN_UUID_UUID_3);
436                    }
437                    else {
438                            bindUuid = true;
439    
440                            query.append(_FINDER_COLUMN_UUID_UUID_2);
441                    }
442    
443                    if (orderByComparator != null) {
444                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
445    
446                            if (orderByConditionFields.length > 0) {
447                                    query.append(WHERE_AND);
448                            }
449    
450                            for (int i = 0; i < orderByConditionFields.length; i++) {
451                                    query.append(_ORDER_BY_ENTITY_ALIAS);
452                                    query.append(orderByConditionFields[i]);
453    
454                                    if ((i + 1) < orderByConditionFields.length) {
455                                            if (orderByComparator.isAscending() ^ previous) {
456                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
457                                            }
458                                            else {
459                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
460                                            }
461                                    }
462                                    else {
463                                            if (orderByComparator.isAscending() ^ previous) {
464                                                    query.append(WHERE_GREATER_THAN);
465                                            }
466                                            else {
467                                                    query.append(WHERE_LESSER_THAN);
468                                            }
469                                    }
470                            }
471    
472                            query.append(ORDER_BY_CLAUSE);
473    
474                            String[] orderByFields = orderByComparator.getOrderByFields();
475    
476                            for (int i = 0; i < orderByFields.length; i++) {
477                                    query.append(_ORDER_BY_ENTITY_ALIAS);
478                                    query.append(orderByFields[i]);
479    
480                                    if ((i + 1) < orderByFields.length) {
481                                            if (orderByComparator.isAscending() ^ previous) {
482                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
483                                            }
484                                            else {
485                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
486                                            }
487                                    }
488                                    else {
489                                            if (orderByComparator.isAscending() ^ previous) {
490                                                    query.append(ORDER_BY_ASC);
491                                            }
492                                            else {
493                                                    query.append(ORDER_BY_DESC);
494                                            }
495                                    }
496                            }
497                    }
498                    else {
499                            query.append(DDMStructureLayoutModelImpl.ORDER_BY_JPQL);
500                    }
501    
502                    String sql = query.toString();
503    
504                    Query q = session.createQuery(sql);
505    
506                    q.setFirstResult(0);
507                    q.setMaxResults(2);
508    
509                    QueryPos qPos = QueryPos.getInstance(q);
510    
511                    if (bindUuid) {
512                            qPos.add(uuid);
513                    }
514    
515                    if (orderByComparator != null) {
516                            Object[] values = orderByComparator.getOrderByConditionValues(ddmStructureLayout);
517    
518                            for (Object value : values) {
519                                    qPos.add(value);
520                            }
521                    }
522    
523                    List<DDMStructureLayout> list = q.list();
524    
525                    if (list.size() == 2) {
526                            return list.get(1);
527                    }
528                    else {
529                            return null;
530                    }
531            }
532    
533            /**
534             * Removes all the d d m structure layouts where uuid = &#63; from the database.
535             *
536             * @param uuid the uuid
537             */
538            @Override
539            public void removeByUuid(String uuid) {
540                    for (DDMStructureLayout ddmStructureLayout : findByUuid(uuid,
541                                    QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
542                            remove(ddmStructureLayout);
543                    }
544            }
545    
546            /**
547             * Returns the number of d d m structure layouts where uuid = &#63;.
548             *
549             * @param uuid the uuid
550             * @return the number of matching d d m structure layouts
551             */
552            @Override
553            public int countByUuid(String uuid) {
554                    FinderPath finderPath = FINDER_PATH_COUNT_BY_UUID;
555    
556                    Object[] finderArgs = new Object[] { uuid };
557    
558                    Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
559                                    this);
560    
561                    if (count == null) {
562                            StringBundler query = new StringBundler(2);
563    
564                            query.append(_SQL_COUNT_DDMSTRUCTURELAYOUT_WHERE);
565    
566                            boolean bindUuid = false;
567    
568                            if (uuid == null) {
569                                    query.append(_FINDER_COLUMN_UUID_UUID_1);
570                            }
571                            else if (uuid.equals(StringPool.BLANK)) {
572                                    query.append(_FINDER_COLUMN_UUID_UUID_3);
573                            }
574                            else {
575                                    bindUuid = true;
576    
577                                    query.append(_FINDER_COLUMN_UUID_UUID_2);
578                            }
579    
580                            String sql = query.toString();
581    
582                            Session session = null;
583    
584                            try {
585                                    session = openSession();
586    
587                                    Query q = session.createQuery(sql);
588    
589                                    QueryPos qPos = QueryPos.getInstance(q);
590    
591                                    if (bindUuid) {
592                                            qPos.add(uuid);
593                                    }
594    
595                                    count = (Long)q.uniqueResult();
596    
597                                    FinderCacheUtil.putResult(finderPath, finderArgs, count);
598                            }
599                            catch (Exception e) {
600                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
601    
602                                    throw processException(e);
603                            }
604                            finally {
605                                    closeSession(session);
606                            }
607                    }
608    
609                    return count.intValue();
610            }
611    
612            private static final String _FINDER_COLUMN_UUID_UUID_1 = "ddmStructureLayout.uuid IS NULL";
613            private static final String _FINDER_COLUMN_UUID_UUID_2 = "ddmStructureLayout.uuid = ?";
614            private static final String _FINDER_COLUMN_UUID_UUID_3 = "(ddmStructureLayout.uuid IS NULL OR ddmStructureLayout.uuid = '')";
615            public static final FinderPath FINDER_PATH_FETCH_BY_UUID_G = new FinderPath(DDMStructureLayoutModelImpl.ENTITY_CACHE_ENABLED,
616                            DDMStructureLayoutModelImpl.FINDER_CACHE_ENABLED,
617                            DDMStructureLayoutImpl.class, FINDER_CLASS_NAME_ENTITY,
618                            "fetchByUUID_G",
619                            new String[] { String.class.getName(), Long.class.getName() },
620                            DDMStructureLayoutModelImpl.UUID_COLUMN_BITMASK |
621                            DDMStructureLayoutModelImpl.GROUPID_COLUMN_BITMASK);
622            public static final FinderPath FINDER_PATH_COUNT_BY_UUID_G = new FinderPath(DDMStructureLayoutModelImpl.ENTITY_CACHE_ENABLED,
623                            DDMStructureLayoutModelImpl.FINDER_CACHE_ENABLED, Long.class,
624                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByUUID_G",
625                            new String[] { String.class.getName(), Long.class.getName() });
626    
627            /**
628             * Returns the d d m structure layout where uuid = &#63; and groupId = &#63; or throws a {@link NoSuchStructureLayoutException} if it could not be found.
629             *
630             * @param uuid the uuid
631             * @param groupId the group ID
632             * @return the matching d d m structure layout
633             * @throws NoSuchStructureLayoutException if a matching d d m structure layout could not be found
634             */
635            @Override
636            public DDMStructureLayout findByUUID_G(String uuid, long groupId)
637                    throws NoSuchStructureLayoutException {
638                    DDMStructureLayout ddmStructureLayout = fetchByUUID_G(uuid, groupId);
639    
640                    if (ddmStructureLayout == null) {
641                            StringBundler msg = new StringBundler(6);
642    
643                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
644    
645                            msg.append("uuid=");
646                            msg.append(uuid);
647    
648                            msg.append(", groupId=");
649                            msg.append(groupId);
650    
651                            msg.append(StringPool.CLOSE_CURLY_BRACE);
652    
653                            if (_log.isWarnEnabled()) {
654                                    _log.warn(msg.toString());
655                            }
656    
657                            throw new NoSuchStructureLayoutException(msg.toString());
658                    }
659    
660                    return ddmStructureLayout;
661            }
662    
663            /**
664             * Returns the d d m structure layout where uuid = &#63; and groupId = &#63; or returns <code>null</code> if it could not be found. Uses the finder cache.
665             *
666             * @param uuid the uuid
667             * @param groupId the group ID
668             * @return the matching d d m structure layout, or <code>null</code> if a matching d d m structure layout could not be found
669             */
670            @Override
671            public DDMStructureLayout fetchByUUID_G(String uuid, long groupId) {
672                    return fetchByUUID_G(uuid, groupId, true);
673            }
674    
675            /**
676             * Returns the d d m structure layout where uuid = &#63; and groupId = &#63; or returns <code>null</code> if it could not be found, optionally using the finder cache.
677             *
678             * @param uuid the uuid
679             * @param groupId the group ID
680             * @param retrieveFromCache whether to use the finder cache
681             * @return the matching d d m structure layout, or <code>null</code> if a matching d d m structure layout could not be found
682             */
683            @Override
684            public DDMStructureLayout fetchByUUID_G(String uuid, long groupId,
685                    boolean retrieveFromCache) {
686                    Object[] finderArgs = new Object[] { uuid, groupId };
687    
688                    Object result = null;
689    
690                    if (retrieveFromCache) {
691                            result = FinderCacheUtil.getResult(FINDER_PATH_FETCH_BY_UUID_G,
692                                            finderArgs, this);
693                    }
694    
695                    if (result instanceof DDMStructureLayout) {
696                            DDMStructureLayout ddmStructureLayout = (DDMStructureLayout)result;
697    
698                            if (!Validator.equals(uuid, ddmStructureLayout.getUuid()) ||
699                                            (groupId != ddmStructureLayout.getGroupId())) {
700                                    result = null;
701                            }
702                    }
703    
704                    if (result == null) {
705                            StringBundler query = new StringBundler(4);
706    
707                            query.append(_SQL_SELECT_DDMSTRUCTURELAYOUT_WHERE);
708    
709                            boolean bindUuid = false;
710    
711                            if (uuid == null) {
712                                    query.append(_FINDER_COLUMN_UUID_G_UUID_1);
713                            }
714                            else if (uuid.equals(StringPool.BLANK)) {
715                                    query.append(_FINDER_COLUMN_UUID_G_UUID_3);
716                            }
717                            else {
718                                    bindUuid = true;
719    
720                                    query.append(_FINDER_COLUMN_UUID_G_UUID_2);
721                            }
722    
723                            query.append(_FINDER_COLUMN_UUID_G_GROUPID_2);
724    
725                            String sql = query.toString();
726    
727                            Session session = null;
728    
729                            try {
730                                    session = openSession();
731    
732                                    Query q = session.createQuery(sql);
733    
734                                    QueryPos qPos = QueryPos.getInstance(q);
735    
736                                    if (bindUuid) {
737                                            qPos.add(uuid);
738                                    }
739    
740                                    qPos.add(groupId);
741    
742                                    List<DDMStructureLayout> list = q.list();
743    
744                                    if (list.isEmpty()) {
745                                            FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_UUID_G,
746                                                    finderArgs, list);
747                                    }
748                                    else {
749                                            DDMStructureLayout ddmStructureLayout = list.get(0);
750    
751                                            result = ddmStructureLayout;
752    
753                                            cacheResult(ddmStructureLayout);
754    
755                                            if ((ddmStructureLayout.getUuid() == null) ||
756                                                            !ddmStructureLayout.getUuid().equals(uuid) ||
757                                                            (ddmStructureLayout.getGroupId() != groupId)) {
758                                                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_UUID_G,
759                                                            finderArgs, ddmStructureLayout);
760                                            }
761                                    }
762                            }
763                            catch (Exception e) {
764                                    FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_UUID_G,
765                                            finderArgs);
766    
767                                    throw processException(e);
768                            }
769                            finally {
770                                    closeSession(session);
771                            }
772                    }
773    
774                    if (result instanceof List<?>) {
775                            return null;
776                    }
777                    else {
778                            return (DDMStructureLayout)result;
779                    }
780            }
781    
782            /**
783             * Removes the d d m structure layout where uuid = &#63; and groupId = &#63; from the database.
784             *
785             * @param uuid the uuid
786             * @param groupId the group ID
787             * @return the d d m structure layout that was removed
788             */
789            @Override
790            public DDMStructureLayout removeByUUID_G(String uuid, long groupId)
791                    throws NoSuchStructureLayoutException {
792                    DDMStructureLayout ddmStructureLayout = findByUUID_G(uuid, groupId);
793    
794                    return remove(ddmStructureLayout);
795            }
796    
797            /**
798             * Returns the number of d d m structure layouts where uuid = &#63; and groupId = &#63;.
799             *
800             * @param uuid the uuid
801             * @param groupId the group ID
802             * @return the number of matching d d m structure layouts
803             */
804            @Override
805            public int countByUUID_G(String uuid, long groupId) {
806                    FinderPath finderPath = FINDER_PATH_COUNT_BY_UUID_G;
807    
808                    Object[] finderArgs = new Object[] { uuid, groupId };
809    
810                    Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
811                                    this);
812    
813                    if (count == null) {
814                            StringBundler query = new StringBundler(3);
815    
816                            query.append(_SQL_COUNT_DDMSTRUCTURELAYOUT_WHERE);
817    
818                            boolean bindUuid = false;
819    
820                            if (uuid == null) {
821                                    query.append(_FINDER_COLUMN_UUID_G_UUID_1);
822                            }
823                            else if (uuid.equals(StringPool.BLANK)) {
824                                    query.append(_FINDER_COLUMN_UUID_G_UUID_3);
825                            }
826                            else {
827                                    bindUuid = true;
828    
829                                    query.append(_FINDER_COLUMN_UUID_G_UUID_2);
830                            }
831    
832                            query.append(_FINDER_COLUMN_UUID_G_GROUPID_2);
833    
834                            String sql = query.toString();
835    
836                            Session session = null;
837    
838                            try {
839                                    session = openSession();
840    
841                                    Query q = session.createQuery(sql);
842    
843                                    QueryPos qPos = QueryPos.getInstance(q);
844    
845                                    if (bindUuid) {
846                                            qPos.add(uuid);
847                                    }
848    
849                                    qPos.add(groupId);
850    
851                                    count = (Long)q.uniqueResult();
852    
853                                    FinderCacheUtil.putResult(finderPath, finderArgs, count);
854                            }
855                            catch (Exception e) {
856                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
857    
858                                    throw processException(e);
859                            }
860                            finally {
861                                    closeSession(session);
862                            }
863                    }
864    
865                    return count.intValue();
866            }
867    
868            private static final String _FINDER_COLUMN_UUID_G_UUID_1 = "ddmStructureLayout.uuid IS NULL AND ";
869            private static final String _FINDER_COLUMN_UUID_G_UUID_2 = "ddmStructureLayout.uuid = ? AND ";
870            private static final String _FINDER_COLUMN_UUID_G_UUID_3 = "(ddmStructureLayout.uuid IS NULL OR ddmStructureLayout.uuid = '') AND ";
871            private static final String _FINDER_COLUMN_UUID_G_GROUPID_2 = "ddmStructureLayout.groupId = ?";
872            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_UUID_C = new FinderPath(DDMStructureLayoutModelImpl.ENTITY_CACHE_ENABLED,
873                            DDMStructureLayoutModelImpl.FINDER_CACHE_ENABLED,
874                            DDMStructureLayoutImpl.class,
875                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByUuid_C",
876                            new String[] {
877                                    String.class.getName(), Long.class.getName(),
878                                    
879                            Integer.class.getName(), Integer.class.getName(),
880                                    OrderByComparator.class.getName()
881                            });
882            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID_C =
883                    new FinderPath(DDMStructureLayoutModelImpl.ENTITY_CACHE_ENABLED,
884                            DDMStructureLayoutModelImpl.FINDER_CACHE_ENABLED,
885                            DDMStructureLayoutImpl.class,
886                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByUuid_C",
887                            new String[] { String.class.getName(), Long.class.getName() },
888                            DDMStructureLayoutModelImpl.UUID_COLUMN_BITMASK |
889                            DDMStructureLayoutModelImpl.COMPANYID_COLUMN_BITMASK);
890            public static final FinderPath FINDER_PATH_COUNT_BY_UUID_C = new FinderPath(DDMStructureLayoutModelImpl.ENTITY_CACHE_ENABLED,
891                            DDMStructureLayoutModelImpl.FINDER_CACHE_ENABLED, Long.class,
892                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByUuid_C",
893                            new String[] { String.class.getName(), Long.class.getName() });
894    
895            /**
896             * Returns all the d d m structure layouts where uuid = &#63; and companyId = &#63;.
897             *
898             * @param uuid the uuid
899             * @param companyId the company ID
900             * @return the matching d d m structure layouts
901             */
902            @Override
903            public List<DDMStructureLayout> findByUuid_C(String uuid, long companyId) {
904                    return findByUuid_C(uuid, companyId, QueryUtil.ALL_POS,
905                            QueryUtil.ALL_POS, null);
906            }
907    
908            /**
909             * Returns a range of all the d d m structure layouts where uuid = &#63; and companyId = &#63;.
910             *
911             * <p>
912             * 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 DDMStructureLayoutModelImpl}. 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.
913             * </p>
914             *
915             * @param uuid the uuid
916             * @param companyId the company ID
917             * @param start the lower bound of the range of d d m structure layouts
918             * @param end the upper bound of the range of d d m structure layouts (not inclusive)
919             * @return the range of matching d d m structure layouts
920             */
921            @Override
922            public List<DDMStructureLayout> findByUuid_C(String uuid, long companyId,
923                    int start, int end) {
924                    return findByUuid_C(uuid, companyId, start, end, null);
925            }
926    
927            /**
928             * Returns an ordered range of all the d d m structure layouts where uuid = &#63; and companyId = &#63;.
929             *
930             * <p>
931             * 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 DDMStructureLayoutModelImpl}. 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.
932             * </p>
933             *
934             * @param uuid the uuid
935             * @param companyId the company ID
936             * @param start the lower bound of the range of d d m structure layouts
937             * @param end the upper bound of the range of d d m structure layouts (not inclusive)
938             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
939             * @return the ordered range of matching d d m structure layouts
940             */
941            @Override
942            public List<DDMStructureLayout> findByUuid_C(String uuid, long companyId,
943                    int start, int end,
944                    OrderByComparator<DDMStructureLayout> orderByComparator) {
945                    boolean pagination = true;
946                    FinderPath finderPath = null;
947                    Object[] finderArgs = null;
948    
949                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
950                                    (orderByComparator == null)) {
951                            pagination = false;
952                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID_C;
953                            finderArgs = new Object[] { uuid, companyId };
954                    }
955                    else {
956                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_UUID_C;
957                            finderArgs = new Object[] {
958                                            uuid, companyId,
959                                            
960                                            start, end, orderByComparator
961                                    };
962                    }
963    
964                    List<DDMStructureLayout> list = (List<DDMStructureLayout>)FinderCacheUtil.getResult(finderPath,
965                                    finderArgs, this);
966    
967                    if ((list != null) && !list.isEmpty()) {
968                            for (DDMStructureLayout ddmStructureLayout : list) {
969                                    if (!Validator.equals(uuid, ddmStructureLayout.getUuid()) ||
970                                                    (companyId != ddmStructureLayout.getCompanyId())) {
971                                            list = null;
972    
973                                            break;
974                                    }
975                            }
976                    }
977    
978                    if (list == null) {
979                            StringBundler query = null;
980    
981                            if (orderByComparator != null) {
982                                    query = new StringBundler(4 +
983                                                    (orderByComparator.getOrderByFields().length * 3));
984                            }
985                            else {
986                                    query = new StringBundler(4);
987                            }
988    
989                            query.append(_SQL_SELECT_DDMSTRUCTURELAYOUT_WHERE);
990    
991                            boolean bindUuid = false;
992    
993                            if (uuid == null) {
994                                    query.append(_FINDER_COLUMN_UUID_C_UUID_1);
995                            }
996                            else if (uuid.equals(StringPool.BLANK)) {
997                                    query.append(_FINDER_COLUMN_UUID_C_UUID_3);
998                            }
999                            else {
1000                                    bindUuid = true;
1001    
1002                                    query.append(_FINDER_COLUMN_UUID_C_UUID_2);
1003                            }
1004    
1005                            query.append(_FINDER_COLUMN_UUID_C_COMPANYID_2);
1006    
1007                            if (orderByComparator != null) {
1008                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1009                                            orderByComparator);
1010                            }
1011                            else
1012                             if (pagination) {
1013                                    query.append(DDMStructureLayoutModelImpl.ORDER_BY_JPQL);
1014                            }
1015    
1016                            String sql = query.toString();
1017    
1018                            Session session = null;
1019    
1020                            try {
1021                                    session = openSession();
1022    
1023                                    Query q = session.createQuery(sql);
1024    
1025                                    QueryPos qPos = QueryPos.getInstance(q);
1026    
1027                                    if (bindUuid) {
1028                                            qPos.add(uuid);
1029                                    }
1030    
1031                                    qPos.add(companyId);
1032    
1033                                    if (!pagination) {
1034                                            list = (List<DDMStructureLayout>)QueryUtil.list(q,
1035                                                            getDialect(), start, end, false);
1036    
1037                                            Collections.sort(list);
1038    
1039                                            list = Collections.unmodifiableList(list);
1040                                    }
1041                                    else {
1042                                            list = (List<DDMStructureLayout>)QueryUtil.list(q,
1043                                                            getDialect(), start, end);
1044                                    }
1045    
1046                                    cacheResult(list);
1047    
1048                                    FinderCacheUtil.putResult(finderPath, finderArgs, list);
1049                            }
1050                            catch (Exception e) {
1051                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
1052    
1053                                    throw processException(e);
1054                            }
1055                            finally {
1056                                    closeSession(session);
1057                            }
1058                    }
1059    
1060                    return list;
1061            }
1062    
1063            /**
1064             * Returns the first d d m structure layout in the ordered set where uuid = &#63; and companyId = &#63;.
1065             *
1066             * @param uuid the uuid
1067             * @param companyId the company ID
1068             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1069             * @return the first matching d d m structure layout
1070             * @throws NoSuchStructureLayoutException if a matching d d m structure layout could not be found
1071             */
1072            @Override
1073            public DDMStructureLayout findByUuid_C_First(String uuid, long companyId,
1074                    OrderByComparator<DDMStructureLayout> orderByComparator)
1075                    throws NoSuchStructureLayoutException {
1076                    DDMStructureLayout ddmStructureLayout = fetchByUuid_C_First(uuid,
1077                                    companyId, orderByComparator);
1078    
1079                    if (ddmStructureLayout != null) {
1080                            return ddmStructureLayout;
1081                    }
1082    
1083                    StringBundler msg = new StringBundler(6);
1084    
1085                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1086    
1087                    msg.append("uuid=");
1088                    msg.append(uuid);
1089    
1090                    msg.append(", companyId=");
1091                    msg.append(companyId);
1092    
1093                    msg.append(StringPool.CLOSE_CURLY_BRACE);
1094    
1095                    throw new NoSuchStructureLayoutException(msg.toString());
1096            }
1097    
1098            /**
1099             * Returns the first d d m structure layout in the ordered set where uuid = &#63; and companyId = &#63;.
1100             *
1101             * @param uuid the uuid
1102             * @param companyId the company ID
1103             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1104             * @return the first matching d d m structure layout, or <code>null</code> if a matching d d m structure layout could not be found
1105             */
1106            @Override
1107            public DDMStructureLayout fetchByUuid_C_First(String uuid, long companyId,
1108                    OrderByComparator<DDMStructureLayout> orderByComparator) {
1109                    List<DDMStructureLayout> list = findByUuid_C(uuid, companyId, 0, 1,
1110                                    orderByComparator);
1111    
1112                    if (!list.isEmpty()) {
1113                            return list.get(0);
1114                    }
1115    
1116                    return null;
1117            }
1118    
1119            /**
1120             * Returns the last d d m structure layout in the ordered set where uuid = &#63; and companyId = &#63;.
1121             *
1122             * @param uuid the uuid
1123             * @param companyId the company ID
1124             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1125             * @return the last matching d d m structure layout
1126             * @throws NoSuchStructureLayoutException if a matching d d m structure layout could not be found
1127             */
1128            @Override
1129            public DDMStructureLayout findByUuid_C_Last(String uuid, long companyId,
1130                    OrderByComparator<DDMStructureLayout> orderByComparator)
1131                    throws NoSuchStructureLayoutException {
1132                    DDMStructureLayout ddmStructureLayout = fetchByUuid_C_Last(uuid,
1133                                    companyId, orderByComparator);
1134    
1135                    if (ddmStructureLayout != null) {
1136                            return ddmStructureLayout;
1137                    }
1138    
1139                    StringBundler msg = new StringBundler(6);
1140    
1141                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1142    
1143                    msg.append("uuid=");
1144                    msg.append(uuid);
1145    
1146                    msg.append(", companyId=");
1147                    msg.append(companyId);
1148    
1149                    msg.append(StringPool.CLOSE_CURLY_BRACE);
1150    
1151                    throw new NoSuchStructureLayoutException(msg.toString());
1152            }
1153    
1154            /**
1155             * Returns the last d d m structure layout in the ordered set where uuid = &#63; and companyId = &#63;.
1156             *
1157             * @param uuid the uuid
1158             * @param companyId the company ID
1159             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1160             * @return the last matching d d m structure layout, or <code>null</code> if a matching d d m structure layout could not be found
1161             */
1162            @Override
1163            public DDMStructureLayout fetchByUuid_C_Last(String uuid, long companyId,
1164                    OrderByComparator<DDMStructureLayout> orderByComparator) {
1165                    int count = countByUuid_C(uuid, companyId);
1166    
1167                    if (count == 0) {
1168                            return null;
1169                    }
1170    
1171                    List<DDMStructureLayout> list = findByUuid_C(uuid, companyId,
1172                                    count - 1, count, orderByComparator);
1173    
1174                    if (!list.isEmpty()) {
1175                            return list.get(0);
1176                    }
1177    
1178                    return null;
1179            }
1180    
1181            /**
1182             * Returns the d d m structure layouts before and after the current d d m structure layout in the ordered set where uuid = &#63; and companyId = &#63;.
1183             *
1184             * @param structureLayoutId the primary key of the current d d m structure layout
1185             * @param uuid the uuid
1186             * @param companyId the company ID
1187             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1188             * @return the previous, current, and next d d m structure layout
1189             * @throws NoSuchStructureLayoutException if a d d m structure layout with the primary key could not be found
1190             */
1191            @Override
1192            public DDMStructureLayout[] findByUuid_C_PrevAndNext(
1193                    long structureLayoutId, String uuid, long companyId,
1194                    OrderByComparator<DDMStructureLayout> orderByComparator)
1195                    throws NoSuchStructureLayoutException {
1196                    DDMStructureLayout ddmStructureLayout = findByPrimaryKey(structureLayoutId);
1197    
1198                    Session session = null;
1199    
1200                    try {
1201                            session = openSession();
1202    
1203                            DDMStructureLayout[] array = new DDMStructureLayoutImpl[3];
1204    
1205                            array[0] = getByUuid_C_PrevAndNext(session, ddmStructureLayout,
1206                                            uuid, companyId, orderByComparator, true);
1207    
1208                            array[1] = ddmStructureLayout;
1209    
1210                            array[2] = getByUuid_C_PrevAndNext(session, ddmStructureLayout,
1211                                            uuid, companyId, orderByComparator, false);
1212    
1213                            return array;
1214                    }
1215                    catch (Exception e) {
1216                            throw processException(e);
1217                    }
1218                    finally {
1219                            closeSession(session);
1220                    }
1221            }
1222    
1223            protected DDMStructureLayout getByUuid_C_PrevAndNext(Session session,
1224                    DDMStructureLayout ddmStructureLayout, String uuid, long companyId,
1225                    OrderByComparator<DDMStructureLayout> orderByComparator,
1226                    boolean previous) {
1227                    StringBundler query = null;
1228    
1229                    if (orderByComparator != null) {
1230                            query = new StringBundler(6 +
1231                                            (orderByComparator.getOrderByFields().length * 6));
1232                    }
1233                    else {
1234                            query = new StringBundler(3);
1235                    }
1236    
1237                    query.append(_SQL_SELECT_DDMSTRUCTURELAYOUT_WHERE);
1238    
1239                    boolean bindUuid = false;
1240    
1241                    if (uuid == null) {
1242                            query.append(_FINDER_COLUMN_UUID_C_UUID_1);
1243                    }
1244                    else if (uuid.equals(StringPool.BLANK)) {
1245                            query.append(_FINDER_COLUMN_UUID_C_UUID_3);
1246                    }
1247                    else {
1248                            bindUuid = true;
1249    
1250                            query.append(_FINDER_COLUMN_UUID_C_UUID_2);
1251                    }
1252    
1253                    query.append(_FINDER_COLUMN_UUID_C_COMPANYID_2);
1254    
1255                    if (orderByComparator != null) {
1256                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
1257    
1258                            if (orderByConditionFields.length > 0) {
1259                                    query.append(WHERE_AND);
1260                            }
1261    
1262                            for (int i = 0; i < orderByConditionFields.length; i++) {
1263                                    query.append(_ORDER_BY_ENTITY_ALIAS);
1264                                    query.append(orderByConditionFields[i]);
1265    
1266                                    if ((i + 1) < orderByConditionFields.length) {
1267                                            if (orderByComparator.isAscending() ^ previous) {
1268                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
1269                                            }
1270                                            else {
1271                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
1272                                            }
1273                                    }
1274                                    else {
1275                                            if (orderByComparator.isAscending() ^ previous) {
1276                                                    query.append(WHERE_GREATER_THAN);
1277                                            }
1278                                            else {
1279                                                    query.append(WHERE_LESSER_THAN);
1280                                            }
1281                                    }
1282                            }
1283    
1284                            query.append(ORDER_BY_CLAUSE);
1285    
1286                            String[] orderByFields = orderByComparator.getOrderByFields();
1287    
1288                            for (int i = 0; i < orderByFields.length; i++) {
1289                                    query.append(_ORDER_BY_ENTITY_ALIAS);
1290                                    query.append(orderByFields[i]);
1291    
1292                                    if ((i + 1) < orderByFields.length) {
1293                                            if (orderByComparator.isAscending() ^ previous) {
1294                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
1295                                            }
1296                                            else {
1297                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
1298                                            }
1299                                    }
1300                                    else {
1301                                            if (orderByComparator.isAscending() ^ previous) {
1302                                                    query.append(ORDER_BY_ASC);
1303                                            }
1304                                            else {
1305                                                    query.append(ORDER_BY_DESC);
1306                                            }
1307                                    }
1308                            }
1309                    }
1310                    else {
1311                            query.append(DDMStructureLayoutModelImpl.ORDER_BY_JPQL);
1312                    }
1313    
1314                    String sql = query.toString();
1315    
1316                    Query q = session.createQuery(sql);
1317    
1318                    q.setFirstResult(0);
1319                    q.setMaxResults(2);
1320    
1321                    QueryPos qPos = QueryPos.getInstance(q);
1322    
1323                    if (bindUuid) {
1324                            qPos.add(uuid);
1325                    }
1326    
1327                    qPos.add(companyId);
1328    
1329                    if (orderByComparator != null) {
1330                            Object[] values = orderByComparator.getOrderByConditionValues(ddmStructureLayout);
1331    
1332                            for (Object value : values) {
1333                                    qPos.add(value);
1334                            }
1335                    }
1336    
1337                    List<DDMStructureLayout> list = q.list();
1338    
1339                    if (list.size() == 2) {
1340                            return list.get(1);
1341                    }
1342                    else {
1343                            return null;
1344                    }
1345            }
1346    
1347            /**
1348             * Removes all the d d m structure layouts where uuid = &#63; and companyId = &#63; from the database.
1349             *
1350             * @param uuid the uuid
1351             * @param companyId the company ID
1352             */
1353            @Override
1354            public void removeByUuid_C(String uuid, long companyId) {
1355                    for (DDMStructureLayout ddmStructureLayout : findByUuid_C(uuid,
1356                                    companyId, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
1357                            remove(ddmStructureLayout);
1358                    }
1359            }
1360    
1361            /**
1362             * Returns the number of d d m structure layouts where uuid = &#63; and companyId = &#63;.
1363             *
1364             * @param uuid the uuid
1365             * @param companyId the company ID
1366             * @return the number of matching d d m structure layouts
1367             */
1368            @Override
1369            public int countByUuid_C(String uuid, long companyId) {
1370                    FinderPath finderPath = FINDER_PATH_COUNT_BY_UUID_C;
1371    
1372                    Object[] finderArgs = new Object[] { uuid, companyId };
1373    
1374                    Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
1375                                    this);
1376    
1377                    if (count == null) {
1378                            StringBundler query = new StringBundler(3);
1379    
1380                            query.append(_SQL_COUNT_DDMSTRUCTURELAYOUT_WHERE);
1381    
1382                            boolean bindUuid = false;
1383    
1384                            if (uuid == null) {
1385                                    query.append(_FINDER_COLUMN_UUID_C_UUID_1);
1386                            }
1387                            else if (uuid.equals(StringPool.BLANK)) {
1388                                    query.append(_FINDER_COLUMN_UUID_C_UUID_3);
1389                            }
1390                            else {
1391                                    bindUuid = true;
1392    
1393                                    query.append(_FINDER_COLUMN_UUID_C_UUID_2);
1394                            }
1395    
1396                            query.append(_FINDER_COLUMN_UUID_C_COMPANYID_2);
1397    
1398                            String sql = query.toString();
1399    
1400                            Session session = null;
1401    
1402                            try {
1403                                    session = openSession();
1404    
1405                                    Query q = session.createQuery(sql);
1406    
1407                                    QueryPos qPos = QueryPos.getInstance(q);
1408    
1409                                    if (bindUuid) {
1410                                            qPos.add(uuid);
1411                                    }
1412    
1413                                    qPos.add(companyId);
1414    
1415                                    count = (Long)q.uniqueResult();
1416    
1417                                    FinderCacheUtil.putResult(finderPath, finderArgs, count);
1418                            }
1419                            catch (Exception e) {
1420                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
1421    
1422                                    throw processException(e);
1423                            }
1424                            finally {
1425                                    closeSession(session);
1426                            }
1427                    }
1428    
1429                    return count.intValue();
1430            }
1431    
1432            private static final String _FINDER_COLUMN_UUID_C_UUID_1 = "ddmStructureLayout.uuid IS NULL AND ";
1433            private static final String _FINDER_COLUMN_UUID_C_UUID_2 = "ddmStructureLayout.uuid = ? AND ";
1434            private static final String _FINDER_COLUMN_UUID_C_UUID_3 = "(ddmStructureLayout.uuid IS NULL OR ddmStructureLayout.uuid = '') AND ";
1435            private static final String _FINDER_COLUMN_UUID_C_COMPANYID_2 = "ddmStructureLayout.companyId = ?";
1436            public static final FinderPath FINDER_PATH_FETCH_BY_STRUCTUREVERSIONID = new FinderPath(DDMStructureLayoutModelImpl.ENTITY_CACHE_ENABLED,
1437                            DDMStructureLayoutModelImpl.FINDER_CACHE_ENABLED,
1438                            DDMStructureLayoutImpl.class, FINDER_CLASS_NAME_ENTITY,
1439                            "fetchByStructureVersionId", new String[] { Long.class.getName() },
1440                            DDMStructureLayoutModelImpl.STRUCTUREVERSIONID_COLUMN_BITMASK);
1441            public static final FinderPath FINDER_PATH_COUNT_BY_STRUCTUREVERSIONID = new FinderPath(DDMStructureLayoutModelImpl.ENTITY_CACHE_ENABLED,
1442                            DDMStructureLayoutModelImpl.FINDER_CACHE_ENABLED, Long.class,
1443                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION,
1444                            "countByStructureVersionId", new String[] { Long.class.getName() });
1445    
1446            /**
1447             * Returns the d d m structure layout where structureVersionId = &#63; or throws a {@link NoSuchStructureLayoutException} if it could not be found.
1448             *
1449             * @param structureVersionId the structure version ID
1450             * @return the matching d d m structure layout
1451             * @throws NoSuchStructureLayoutException if a matching d d m structure layout could not be found
1452             */
1453            @Override
1454            public DDMStructureLayout findByStructureVersionId(long structureVersionId)
1455                    throws NoSuchStructureLayoutException {
1456                    DDMStructureLayout ddmStructureLayout = fetchByStructureVersionId(structureVersionId);
1457    
1458                    if (ddmStructureLayout == null) {
1459                            StringBundler msg = new StringBundler(4);
1460    
1461                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1462    
1463                            msg.append("structureVersionId=");
1464                            msg.append(structureVersionId);
1465    
1466                            msg.append(StringPool.CLOSE_CURLY_BRACE);
1467    
1468                            if (_log.isWarnEnabled()) {
1469                                    _log.warn(msg.toString());
1470                            }
1471    
1472                            throw new NoSuchStructureLayoutException(msg.toString());
1473                    }
1474    
1475                    return ddmStructureLayout;
1476            }
1477    
1478            /**
1479             * Returns the d d m structure layout where structureVersionId = &#63; or returns <code>null</code> if it could not be found. Uses the finder cache.
1480             *
1481             * @param structureVersionId the structure version ID
1482             * @return the matching d d m structure layout, or <code>null</code> if a matching d d m structure layout could not be found
1483             */
1484            @Override
1485            public DDMStructureLayout fetchByStructureVersionId(long structureVersionId) {
1486                    return fetchByStructureVersionId(structureVersionId, true);
1487            }
1488    
1489            /**
1490             * Returns the d d m structure layout where structureVersionId = &#63; or returns <code>null</code> if it could not be found, optionally using the finder cache.
1491             *
1492             * @param structureVersionId the structure version ID
1493             * @param retrieveFromCache whether to use the finder cache
1494             * @return the matching d d m structure layout, or <code>null</code> if a matching d d m structure layout could not be found
1495             */
1496            @Override
1497            public DDMStructureLayout fetchByStructureVersionId(
1498                    long structureVersionId, boolean retrieveFromCache) {
1499                    Object[] finderArgs = new Object[] { structureVersionId };
1500    
1501                    Object result = null;
1502    
1503                    if (retrieveFromCache) {
1504                            result = FinderCacheUtil.getResult(FINDER_PATH_FETCH_BY_STRUCTUREVERSIONID,
1505                                            finderArgs, this);
1506                    }
1507    
1508                    if (result instanceof DDMStructureLayout) {
1509                            DDMStructureLayout ddmStructureLayout = (DDMStructureLayout)result;
1510    
1511                            if ((structureVersionId != ddmStructureLayout.getStructureVersionId())) {
1512                                    result = null;
1513                            }
1514                    }
1515    
1516                    if (result == null) {
1517                            StringBundler query = new StringBundler(3);
1518    
1519                            query.append(_SQL_SELECT_DDMSTRUCTURELAYOUT_WHERE);
1520    
1521                            query.append(_FINDER_COLUMN_STRUCTUREVERSIONID_STRUCTUREVERSIONID_2);
1522    
1523                            String sql = query.toString();
1524    
1525                            Session session = null;
1526    
1527                            try {
1528                                    session = openSession();
1529    
1530                                    Query q = session.createQuery(sql);
1531    
1532                                    QueryPos qPos = QueryPos.getInstance(q);
1533    
1534                                    qPos.add(structureVersionId);
1535    
1536                                    List<DDMStructureLayout> list = q.list();
1537    
1538                                    if (list.isEmpty()) {
1539                                            FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_STRUCTUREVERSIONID,
1540                                                    finderArgs, list);
1541                                    }
1542                                    else {
1543                                            DDMStructureLayout ddmStructureLayout = list.get(0);
1544    
1545                                            result = ddmStructureLayout;
1546    
1547                                            cacheResult(ddmStructureLayout);
1548    
1549                                            if ((ddmStructureLayout.getStructureVersionId() != structureVersionId)) {
1550                                                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_STRUCTUREVERSIONID,
1551                                                            finderArgs, ddmStructureLayout);
1552                                            }
1553                                    }
1554                            }
1555                            catch (Exception e) {
1556                                    FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_STRUCTUREVERSIONID,
1557                                            finderArgs);
1558    
1559                                    throw processException(e);
1560                            }
1561                            finally {
1562                                    closeSession(session);
1563                            }
1564                    }
1565    
1566                    if (result instanceof List<?>) {
1567                            return null;
1568                    }
1569                    else {
1570                            return (DDMStructureLayout)result;
1571                    }
1572            }
1573    
1574            /**
1575             * Removes the d d m structure layout where structureVersionId = &#63; from the database.
1576             *
1577             * @param structureVersionId the structure version ID
1578             * @return the d d m structure layout that was removed
1579             */
1580            @Override
1581            public DDMStructureLayout removeByStructureVersionId(
1582                    long structureVersionId) throws NoSuchStructureLayoutException {
1583                    DDMStructureLayout ddmStructureLayout = findByStructureVersionId(structureVersionId);
1584    
1585                    return remove(ddmStructureLayout);
1586            }
1587    
1588            /**
1589             * Returns the number of d d m structure layouts where structureVersionId = &#63;.
1590             *
1591             * @param structureVersionId the structure version ID
1592             * @return the number of matching d d m structure layouts
1593             */
1594            @Override
1595            public int countByStructureVersionId(long structureVersionId) {
1596                    FinderPath finderPath = FINDER_PATH_COUNT_BY_STRUCTUREVERSIONID;
1597    
1598                    Object[] finderArgs = new Object[] { structureVersionId };
1599    
1600                    Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
1601                                    this);
1602    
1603                    if (count == null) {
1604                            StringBundler query = new StringBundler(2);
1605    
1606                            query.append(_SQL_COUNT_DDMSTRUCTURELAYOUT_WHERE);
1607    
1608                            query.append(_FINDER_COLUMN_STRUCTUREVERSIONID_STRUCTUREVERSIONID_2);
1609    
1610                            String sql = query.toString();
1611    
1612                            Session session = null;
1613    
1614                            try {
1615                                    session = openSession();
1616    
1617                                    Query q = session.createQuery(sql);
1618    
1619                                    QueryPos qPos = QueryPos.getInstance(q);
1620    
1621                                    qPos.add(structureVersionId);
1622    
1623                                    count = (Long)q.uniqueResult();
1624    
1625                                    FinderCacheUtil.putResult(finderPath, finderArgs, count);
1626                            }
1627                            catch (Exception e) {
1628                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
1629    
1630                                    throw processException(e);
1631                            }
1632                            finally {
1633                                    closeSession(session);
1634                            }
1635                    }
1636    
1637                    return count.intValue();
1638            }
1639    
1640            private static final String _FINDER_COLUMN_STRUCTUREVERSIONID_STRUCTUREVERSIONID_2 =
1641                    "ddmStructureLayout.structureVersionId = ?";
1642    
1643            public DDMStructureLayoutPersistenceImpl() {
1644                    setModelClass(DDMStructureLayout.class);
1645            }
1646    
1647            /**
1648             * Caches the d d m structure layout in the entity cache if it is enabled.
1649             *
1650             * @param ddmStructureLayout the d d m structure layout
1651             */
1652            @Override
1653            public void cacheResult(DDMStructureLayout ddmStructureLayout) {
1654                    EntityCacheUtil.putResult(DDMStructureLayoutModelImpl.ENTITY_CACHE_ENABLED,
1655                            DDMStructureLayoutImpl.class, ddmStructureLayout.getPrimaryKey(),
1656                            ddmStructureLayout);
1657    
1658                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_UUID_G,
1659                            new Object[] {
1660                                    ddmStructureLayout.getUuid(), ddmStructureLayout.getGroupId()
1661                            }, ddmStructureLayout);
1662    
1663                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_STRUCTUREVERSIONID,
1664                            new Object[] { ddmStructureLayout.getStructureVersionId() },
1665                            ddmStructureLayout);
1666    
1667                    ddmStructureLayout.resetOriginalValues();
1668            }
1669    
1670            /**
1671             * Caches the d d m structure layouts in the entity cache if it is enabled.
1672             *
1673             * @param ddmStructureLayouts the d d m structure layouts
1674             */
1675            @Override
1676            public void cacheResult(List<DDMStructureLayout> ddmStructureLayouts) {
1677                    for (DDMStructureLayout ddmStructureLayout : ddmStructureLayouts) {
1678                            if (EntityCacheUtil.getResult(
1679                                                    DDMStructureLayoutModelImpl.ENTITY_CACHE_ENABLED,
1680                                                    DDMStructureLayoutImpl.class,
1681                                                    ddmStructureLayout.getPrimaryKey()) == null) {
1682                                    cacheResult(ddmStructureLayout);
1683                            }
1684                            else {
1685                                    ddmStructureLayout.resetOriginalValues();
1686                            }
1687                    }
1688            }
1689    
1690            /**
1691             * Clears the cache for all d d m structure layouts.
1692             *
1693             * <p>
1694             * The {@link com.liferay.portal.kernel.dao.orm.EntityCache} and {@link com.liferay.portal.kernel.dao.orm.FinderCache} are both cleared by this method.
1695             * </p>
1696             */
1697            @Override
1698            public void clearCache() {
1699                    EntityCacheUtil.clearCache(DDMStructureLayoutImpl.class);
1700    
1701                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_ENTITY);
1702                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
1703                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
1704            }
1705    
1706            /**
1707             * Clears the cache for the d d m structure layout.
1708             *
1709             * <p>
1710             * The {@link com.liferay.portal.kernel.dao.orm.EntityCache} and {@link com.liferay.portal.kernel.dao.orm.FinderCache} are both cleared by this method.
1711             * </p>
1712             */
1713            @Override
1714            public void clearCache(DDMStructureLayout ddmStructureLayout) {
1715                    EntityCacheUtil.removeResult(DDMStructureLayoutModelImpl.ENTITY_CACHE_ENABLED,
1716                            DDMStructureLayoutImpl.class, ddmStructureLayout.getPrimaryKey());
1717    
1718                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
1719                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
1720    
1721                    clearUniqueFindersCache(ddmStructureLayout);
1722            }
1723    
1724            @Override
1725            public void clearCache(List<DDMStructureLayout> ddmStructureLayouts) {
1726                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
1727                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
1728    
1729                    for (DDMStructureLayout ddmStructureLayout : ddmStructureLayouts) {
1730                            EntityCacheUtil.removeResult(DDMStructureLayoutModelImpl.ENTITY_CACHE_ENABLED,
1731                                    DDMStructureLayoutImpl.class, ddmStructureLayout.getPrimaryKey());
1732    
1733                            clearUniqueFindersCache(ddmStructureLayout);
1734                    }
1735            }
1736    
1737            protected void cacheUniqueFindersCache(
1738                    DDMStructureLayout ddmStructureLayout) {
1739                    if (ddmStructureLayout.isNew()) {
1740                            Object[] args = new Object[] {
1741                                            ddmStructureLayout.getUuid(),
1742                                            ddmStructureLayout.getGroupId()
1743                                    };
1744    
1745                            FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_UUID_G, args,
1746                                    Long.valueOf(1));
1747                            FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_UUID_G, args,
1748                                    ddmStructureLayout);
1749    
1750                            args = new Object[] { ddmStructureLayout.getStructureVersionId() };
1751    
1752                            FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_STRUCTUREVERSIONID,
1753                                    args, Long.valueOf(1));
1754                            FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_STRUCTUREVERSIONID,
1755                                    args, ddmStructureLayout);
1756                    }
1757                    else {
1758                            DDMStructureLayoutModelImpl ddmStructureLayoutModelImpl = (DDMStructureLayoutModelImpl)ddmStructureLayout;
1759    
1760                            if ((ddmStructureLayoutModelImpl.getColumnBitmask() &
1761                                            FINDER_PATH_FETCH_BY_UUID_G.getColumnBitmask()) != 0) {
1762                                    Object[] args = new Object[] {
1763                                                    ddmStructureLayout.getUuid(),
1764                                                    ddmStructureLayout.getGroupId()
1765                                            };
1766    
1767                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_UUID_G, args,
1768                                            Long.valueOf(1));
1769                                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_UUID_G, args,
1770                                            ddmStructureLayout);
1771                            }
1772    
1773                            if ((ddmStructureLayoutModelImpl.getColumnBitmask() &
1774                                            FINDER_PATH_FETCH_BY_STRUCTUREVERSIONID.getColumnBitmask()) != 0) {
1775                                    Object[] args = new Object[] {
1776                                                    ddmStructureLayout.getStructureVersionId()
1777                                            };
1778    
1779                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_STRUCTUREVERSIONID,
1780                                            args, Long.valueOf(1));
1781                                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_STRUCTUREVERSIONID,
1782                                            args, ddmStructureLayout);
1783                            }
1784                    }
1785            }
1786    
1787            protected void clearUniqueFindersCache(
1788                    DDMStructureLayout ddmStructureLayout) {
1789                    DDMStructureLayoutModelImpl ddmStructureLayoutModelImpl = (DDMStructureLayoutModelImpl)ddmStructureLayout;
1790    
1791                    Object[] args = new Object[] {
1792                                    ddmStructureLayout.getUuid(), ddmStructureLayout.getGroupId()
1793                            };
1794    
1795                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_UUID_G, args);
1796                    FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_UUID_G, args);
1797    
1798                    if ((ddmStructureLayoutModelImpl.getColumnBitmask() &
1799                                    FINDER_PATH_FETCH_BY_UUID_G.getColumnBitmask()) != 0) {
1800                            args = new Object[] {
1801                                            ddmStructureLayoutModelImpl.getOriginalUuid(),
1802                                            ddmStructureLayoutModelImpl.getOriginalGroupId()
1803                                    };
1804    
1805                            FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_UUID_G, args);
1806                            FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_UUID_G, args);
1807                    }
1808    
1809                    args = new Object[] { ddmStructureLayout.getStructureVersionId() };
1810    
1811                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_STRUCTUREVERSIONID,
1812                            args);
1813                    FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_STRUCTUREVERSIONID,
1814                            args);
1815    
1816                    if ((ddmStructureLayoutModelImpl.getColumnBitmask() &
1817                                    FINDER_PATH_FETCH_BY_STRUCTUREVERSIONID.getColumnBitmask()) != 0) {
1818                            args = new Object[] {
1819                                            ddmStructureLayoutModelImpl.getOriginalStructureVersionId()
1820                                    };
1821    
1822                            FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_STRUCTUREVERSIONID,
1823                                    args);
1824                            FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_STRUCTUREVERSIONID,
1825                                    args);
1826                    }
1827            }
1828    
1829            /**
1830             * Creates a new d d m structure layout with the primary key. Does not add the d d m structure layout to the database.
1831             *
1832             * @param structureLayoutId the primary key for the new d d m structure layout
1833             * @return the new d d m structure layout
1834             */
1835            @Override
1836            public DDMStructureLayout create(long structureLayoutId) {
1837                    DDMStructureLayout ddmStructureLayout = new DDMStructureLayoutImpl();
1838    
1839                    ddmStructureLayout.setNew(true);
1840                    ddmStructureLayout.setPrimaryKey(structureLayoutId);
1841    
1842                    String uuid = PortalUUIDUtil.generate();
1843    
1844                    ddmStructureLayout.setUuid(uuid);
1845    
1846                    return ddmStructureLayout;
1847            }
1848    
1849            /**
1850             * Removes the d d m structure layout with the primary key from the database. Also notifies the appropriate model listeners.
1851             *
1852             * @param structureLayoutId the primary key of the d d m structure layout
1853             * @return the d d m structure layout that was removed
1854             * @throws NoSuchStructureLayoutException if a d d m structure layout with the primary key could not be found
1855             */
1856            @Override
1857            public DDMStructureLayout remove(long structureLayoutId)
1858                    throws NoSuchStructureLayoutException {
1859                    return remove((Serializable)structureLayoutId);
1860            }
1861    
1862            /**
1863             * Removes the d d m structure layout with the primary key from the database. Also notifies the appropriate model listeners.
1864             *
1865             * @param primaryKey the primary key of the d d m structure layout
1866             * @return the d d m structure layout that was removed
1867             * @throws NoSuchStructureLayoutException if a d d m structure layout with the primary key could not be found
1868             */
1869            @Override
1870            public DDMStructureLayout remove(Serializable primaryKey)
1871                    throws NoSuchStructureLayoutException {
1872                    Session session = null;
1873    
1874                    try {
1875                            session = openSession();
1876    
1877                            DDMStructureLayout ddmStructureLayout = (DDMStructureLayout)session.get(DDMStructureLayoutImpl.class,
1878                                            primaryKey);
1879    
1880                            if (ddmStructureLayout == null) {
1881                                    if (_log.isWarnEnabled()) {
1882                                            _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + primaryKey);
1883                                    }
1884    
1885                                    throw new NoSuchStructureLayoutException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
1886                                            primaryKey);
1887                            }
1888    
1889                            return remove(ddmStructureLayout);
1890                    }
1891                    catch (NoSuchStructureLayoutException nsee) {
1892                            throw nsee;
1893                    }
1894                    catch (Exception e) {
1895                            throw processException(e);
1896                    }
1897                    finally {
1898                            closeSession(session);
1899                    }
1900            }
1901    
1902            @Override
1903            protected DDMStructureLayout removeImpl(
1904                    DDMStructureLayout ddmStructureLayout) {
1905                    ddmStructureLayout = toUnwrappedModel(ddmStructureLayout);
1906    
1907                    Session session = null;
1908    
1909                    try {
1910                            session = openSession();
1911    
1912                            if (!session.contains(ddmStructureLayout)) {
1913                                    ddmStructureLayout = (DDMStructureLayout)session.get(DDMStructureLayoutImpl.class,
1914                                                    ddmStructureLayout.getPrimaryKeyObj());
1915                            }
1916    
1917                            if (ddmStructureLayout != null) {
1918                                    session.delete(ddmStructureLayout);
1919                            }
1920                    }
1921                    catch (Exception e) {
1922                            throw processException(e);
1923                    }
1924                    finally {
1925                            closeSession(session);
1926                    }
1927    
1928                    if (ddmStructureLayout != null) {
1929                            clearCache(ddmStructureLayout);
1930                    }
1931    
1932                    return ddmStructureLayout;
1933            }
1934    
1935            @Override
1936            public DDMStructureLayout updateImpl(DDMStructureLayout ddmStructureLayout) {
1937                    ddmStructureLayout = toUnwrappedModel(ddmStructureLayout);
1938    
1939                    boolean isNew = ddmStructureLayout.isNew();
1940    
1941                    DDMStructureLayoutModelImpl ddmStructureLayoutModelImpl = (DDMStructureLayoutModelImpl)ddmStructureLayout;
1942    
1943                    if (Validator.isNull(ddmStructureLayout.getUuid())) {
1944                            String uuid = PortalUUIDUtil.generate();
1945    
1946                            ddmStructureLayout.setUuid(uuid);
1947                    }
1948    
1949                    ServiceContext serviceContext = ServiceContextThreadLocal.getServiceContext();
1950    
1951                    Date now = new Date();
1952    
1953                    if (isNew && (ddmStructureLayout.getCreateDate() == null)) {
1954                            if (serviceContext == null) {
1955                                    ddmStructureLayout.setCreateDate(now);
1956                            }
1957                            else {
1958                                    ddmStructureLayout.setCreateDate(serviceContext.getCreateDate(
1959                                                    now));
1960                            }
1961                    }
1962    
1963                    if (!ddmStructureLayoutModelImpl.hasSetModifiedDate()) {
1964                            if (serviceContext == null) {
1965                                    ddmStructureLayout.setModifiedDate(now);
1966                            }
1967                            else {
1968                                    ddmStructureLayout.setModifiedDate(serviceContext.getModifiedDate(
1969                                                    now));
1970                            }
1971                    }
1972    
1973                    Session session = null;
1974    
1975                    try {
1976                            session = openSession();
1977    
1978                            if (ddmStructureLayout.isNew()) {
1979                                    session.save(ddmStructureLayout);
1980    
1981                                    ddmStructureLayout.setNew(false);
1982                            }
1983                            else {
1984                                    session.merge(ddmStructureLayout);
1985                            }
1986                    }
1987                    catch (Exception e) {
1988                            throw processException(e);
1989                    }
1990                    finally {
1991                            closeSession(session);
1992                    }
1993    
1994                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
1995    
1996                    if (isNew || !DDMStructureLayoutModelImpl.COLUMN_BITMASK_ENABLED) {
1997                            FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
1998                    }
1999    
2000                    else {
2001                            if ((ddmStructureLayoutModelImpl.getColumnBitmask() &
2002                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID.getColumnBitmask()) != 0) {
2003                                    Object[] args = new Object[] {
2004                                                    ddmStructureLayoutModelImpl.getOriginalUuid()
2005                                            };
2006    
2007                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_UUID, args);
2008                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID,
2009                                            args);
2010    
2011                                    args = new Object[] { ddmStructureLayoutModelImpl.getUuid() };
2012    
2013                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_UUID, args);
2014                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID,
2015                                            args);
2016                            }
2017    
2018                            if ((ddmStructureLayoutModelImpl.getColumnBitmask() &
2019                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID_C.getColumnBitmask()) != 0) {
2020                                    Object[] args = new Object[] {
2021                                                    ddmStructureLayoutModelImpl.getOriginalUuid(),
2022                                                    ddmStructureLayoutModelImpl.getOriginalCompanyId()
2023                                            };
2024    
2025                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_UUID_C, args);
2026                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID_C,
2027                                            args);
2028    
2029                                    args = new Object[] {
2030                                                    ddmStructureLayoutModelImpl.getUuid(),
2031                                                    ddmStructureLayoutModelImpl.getCompanyId()
2032                                            };
2033    
2034                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_UUID_C, args);
2035                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID_C,
2036                                            args);
2037                            }
2038                    }
2039    
2040                    EntityCacheUtil.putResult(DDMStructureLayoutModelImpl.ENTITY_CACHE_ENABLED,
2041                            DDMStructureLayoutImpl.class, ddmStructureLayout.getPrimaryKey(),
2042                            ddmStructureLayout, false);
2043    
2044                    clearUniqueFindersCache(ddmStructureLayout);
2045                    cacheUniqueFindersCache(ddmStructureLayout);
2046    
2047                    ddmStructureLayout.resetOriginalValues();
2048    
2049                    return ddmStructureLayout;
2050            }
2051    
2052            protected DDMStructureLayout toUnwrappedModel(
2053                    DDMStructureLayout ddmStructureLayout) {
2054                    if (ddmStructureLayout instanceof DDMStructureLayoutImpl) {
2055                            return ddmStructureLayout;
2056                    }
2057    
2058                    DDMStructureLayoutImpl ddmStructureLayoutImpl = new DDMStructureLayoutImpl();
2059    
2060                    ddmStructureLayoutImpl.setNew(ddmStructureLayout.isNew());
2061                    ddmStructureLayoutImpl.setPrimaryKey(ddmStructureLayout.getPrimaryKey());
2062    
2063                    ddmStructureLayoutImpl.setUuid(ddmStructureLayout.getUuid());
2064                    ddmStructureLayoutImpl.setStructureLayoutId(ddmStructureLayout.getStructureLayoutId());
2065                    ddmStructureLayoutImpl.setGroupId(ddmStructureLayout.getGroupId());
2066                    ddmStructureLayoutImpl.setCompanyId(ddmStructureLayout.getCompanyId());
2067                    ddmStructureLayoutImpl.setUserId(ddmStructureLayout.getUserId());
2068                    ddmStructureLayoutImpl.setUserName(ddmStructureLayout.getUserName());
2069                    ddmStructureLayoutImpl.setCreateDate(ddmStructureLayout.getCreateDate());
2070                    ddmStructureLayoutImpl.setModifiedDate(ddmStructureLayout.getModifiedDate());
2071                    ddmStructureLayoutImpl.setStructureVersionId(ddmStructureLayout.getStructureVersionId());
2072                    ddmStructureLayoutImpl.setDefinition(ddmStructureLayout.getDefinition());
2073    
2074                    return ddmStructureLayoutImpl;
2075            }
2076    
2077            /**
2078             * Returns the d d m structure layout with the primary key or throws a {@link com.liferay.portal.NoSuchModelException} if it could not be found.
2079             *
2080             * @param primaryKey the primary key of the d d m structure layout
2081             * @return the d d m structure layout
2082             * @throws NoSuchStructureLayoutException if a d d m structure layout with the primary key could not be found
2083             */
2084            @Override
2085            public DDMStructureLayout findByPrimaryKey(Serializable primaryKey)
2086                    throws NoSuchStructureLayoutException {
2087                    DDMStructureLayout ddmStructureLayout = fetchByPrimaryKey(primaryKey);
2088    
2089                    if (ddmStructureLayout == null) {
2090                            if (_log.isWarnEnabled()) {
2091                                    _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + primaryKey);
2092                            }
2093    
2094                            throw new NoSuchStructureLayoutException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
2095                                    primaryKey);
2096                    }
2097    
2098                    return ddmStructureLayout;
2099            }
2100    
2101            /**
2102             * Returns the d d m structure layout with the primary key or throws a {@link NoSuchStructureLayoutException} if it could not be found.
2103             *
2104             * @param structureLayoutId the primary key of the d d m structure layout
2105             * @return the d d m structure layout
2106             * @throws NoSuchStructureLayoutException if a d d m structure layout with the primary key could not be found
2107             */
2108            @Override
2109            public DDMStructureLayout findByPrimaryKey(long structureLayoutId)
2110                    throws NoSuchStructureLayoutException {
2111                    return findByPrimaryKey((Serializable)structureLayoutId);
2112            }
2113    
2114            /**
2115             * Returns the d d m structure layout with the primary key or returns <code>null</code> if it could not be found.
2116             *
2117             * @param primaryKey the primary key of the d d m structure layout
2118             * @return the d d m structure layout, or <code>null</code> if a d d m structure layout with the primary key could not be found
2119             */
2120            @Override
2121            public DDMStructureLayout fetchByPrimaryKey(Serializable primaryKey) {
2122                    DDMStructureLayout ddmStructureLayout = (DDMStructureLayout)EntityCacheUtil.getResult(DDMStructureLayoutModelImpl.ENTITY_CACHE_ENABLED,
2123                                    DDMStructureLayoutImpl.class, primaryKey);
2124    
2125                    if (ddmStructureLayout == _nullDDMStructureLayout) {
2126                            return null;
2127                    }
2128    
2129                    if (ddmStructureLayout == null) {
2130                            Session session = null;
2131    
2132                            try {
2133                                    session = openSession();
2134    
2135                                    ddmStructureLayout = (DDMStructureLayout)session.get(DDMStructureLayoutImpl.class,
2136                                                    primaryKey);
2137    
2138                                    if (ddmStructureLayout != null) {
2139                                            cacheResult(ddmStructureLayout);
2140                                    }
2141                                    else {
2142                                            EntityCacheUtil.putResult(DDMStructureLayoutModelImpl.ENTITY_CACHE_ENABLED,
2143                                                    DDMStructureLayoutImpl.class, primaryKey,
2144                                                    _nullDDMStructureLayout);
2145                                    }
2146                            }
2147                            catch (Exception e) {
2148                                    EntityCacheUtil.removeResult(DDMStructureLayoutModelImpl.ENTITY_CACHE_ENABLED,
2149                                            DDMStructureLayoutImpl.class, primaryKey);
2150    
2151                                    throw processException(e);
2152                            }
2153                            finally {
2154                                    closeSession(session);
2155                            }
2156                    }
2157    
2158                    return ddmStructureLayout;
2159            }
2160    
2161            /**
2162             * Returns the d d m structure layout with the primary key or returns <code>null</code> if it could not be found.
2163             *
2164             * @param structureLayoutId the primary key of the d d m structure layout
2165             * @return the d d m structure layout, or <code>null</code> if a d d m structure layout with the primary key could not be found
2166             */
2167            @Override
2168            public DDMStructureLayout fetchByPrimaryKey(long structureLayoutId) {
2169                    return fetchByPrimaryKey((Serializable)structureLayoutId);
2170            }
2171    
2172            @Override
2173            public Map<Serializable, DDMStructureLayout> fetchByPrimaryKeys(
2174                    Set<Serializable> primaryKeys) {
2175                    if (primaryKeys.isEmpty()) {
2176                            return Collections.emptyMap();
2177                    }
2178    
2179                    Map<Serializable, DDMStructureLayout> map = new HashMap<Serializable, DDMStructureLayout>();
2180    
2181                    if (primaryKeys.size() == 1) {
2182                            Iterator<Serializable> iterator = primaryKeys.iterator();
2183    
2184                            Serializable primaryKey = iterator.next();
2185    
2186                            DDMStructureLayout ddmStructureLayout = fetchByPrimaryKey(primaryKey);
2187    
2188                            if (ddmStructureLayout != null) {
2189                                    map.put(primaryKey, ddmStructureLayout);
2190                            }
2191    
2192                            return map;
2193                    }
2194    
2195                    Set<Serializable> uncachedPrimaryKeys = null;
2196    
2197                    for (Serializable primaryKey : primaryKeys) {
2198                            DDMStructureLayout ddmStructureLayout = (DDMStructureLayout)EntityCacheUtil.getResult(DDMStructureLayoutModelImpl.ENTITY_CACHE_ENABLED,
2199                                            DDMStructureLayoutImpl.class, primaryKey);
2200    
2201                            if (ddmStructureLayout == null) {
2202                                    if (uncachedPrimaryKeys == null) {
2203                                            uncachedPrimaryKeys = new HashSet<Serializable>();
2204                                    }
2205    
2206                                    uncachedPrimaryKeys.add(primaryKey);
2207                            }
2208                            else {
2209                                    map.put(primaryKey, ddmStructureLayout);
2210                            }
2211                    }
2212    
2213                    if (uncachedPrimaryKeys == null) {
2214                            return map;
2215                    }
2216    
2217                    StringBundler query = new StringBundler((uncachedPrimaryKeys.size() * 2) +
2218                                    1);
2219    
2220                    query.append(_SQL_SELECT_DDMSTRUCTURELAYOUT_WHERE_PKS_IN);
2221    
2222                    for (Serializable primaryKey : uncachedPrimaryKeys) {
2223                            query.append(String.valueOf(primaryKey));
2224    
2225                            query.append(StringPool.COMMA);
2226                    }
2227    
2228                    query.setIndex(query.index() - 1);
2229    
2230                    query.append(StringPool.CLOSE_PARENTHESIS);
2231    
2232                    String sql = query.toString();
2233    
2234                    Session session = null;
2235    
2236                    try {
2237                            session = openSession();
2238    
2239                            Query q = session.createQuery(sql);
2240    
2241                            for (DDMStructureLayout ddmStructureLayout : (List<DDMStructureLayout>)q.list()) {
2242                                    map.put(ddmStructureLayout.getPrimaryKeyObj(),
2243                                            ddmStructureLayout);
2244    
2245                                    cacheResult(ddmStructureLayout);
2246    
2247                                    uncachedPrimaryKeys.remove(ddmStructureLayout.getPrimaryKeyObj());
2248                            }
2249    
2250                            for (Serializable primaryKey : uncachedPrimaryKeys) {
2251                                    EntityCacheUtil.putResult(DDMStructureLayoutModelImpl.ENTITY_CACHE_ENABLED,
2252                                            DDMStructureLayoutImpl.class, primaryKey,
2253                                            _nullDDMStructureLayout);
2254                            }
2255                    }
2256                    catch (Exception e) {
2257                            throw processException(e);
2258                    }
2259                    finally {
2260                            closeSession(session);
2261                    }
2262    
2263                    return map;
2264            }
2265    
2266            /**
2267             * Returns all the d d m structure layouts.
2268             *
2269             * @return the d d m structure layouts
2270             */
2271            @Override
2272            public List<DDMStructureLayout> findAll() {
2273                    return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
2274            }
2275    
2276            /**
2277             * Returns a range of all the d d m structure layouts.
2278             *
2279             * <p>
2280             * 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 DDMStructureLayoutModelImpl}. 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.
2281             * </p>
2282             *
2283             * @param start the lower bound of the range of d d m structure layouts
2284             * @param end the upper bound of the range of d d m structure layouts (not inclusive)
2285             * @return the range of d d m structure layouts
2286             */
2287            @Override
2288            public List<DDMStructureLayout> findAll(int start, int end) {
2289                    return findAll(start, end, null);
2290            }
2291    
2292            /**
2293             * Returns an ordered range of all the d d m structure layouts.
2294             *
2295             * <p>
2296             * 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 DDMStructureLayoutModelImpl}. 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.
2297             * </p>
2298             *
2299             * @param start the lower bound of the range of d d m structure layouts
2300             * @param end the upper bound of the range of d d m structure layouts (not inclusive)
2301             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
2302             * @return the ordered range of d d m structure layouts
2303             */
2304            @Override
2305            public List<DDMStructureLayout> findAll(int start, int end,
2306                    OrderByComparator<DDMStructureLayout> orderByComparator) {
2307                    boolean pagination = true;
2308                    FinderPath finderPath = null;
2309                    Object[] finderArgs = null;
2310    
2311                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
2312                                    (orderByComparator == null)) {
2313                            pagination = false;
2314                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL;
2315                            finderArgs = FINDER_ARGS_EMPTY;
2316                    }
2317                    else {
2318                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_ALL;
2319                            finderArgs = new Object[] { start, end, orderByComparator };
2320                    }
2321    
2322                    List<DDMStructureLayout> list = (List<DDMStructureLayout>)FinderCacheUtil.getResult(finderPath,
2323                                    finderArgs, this);
2324    
2325                    if (list == null) {
2326                            StringBundler query = null;
2327                            String sql = null;
2328    
2329                            if (orderByComparator != null) {
2330                                    query = new StringBundler(2 +
2331                                                    (orderByComparator.getOrderByFields().length * 3));
2332    
2333                                    query.append(_SQL_SELECT_DDMSTRUCTURELAYOUT);
2334    
2335                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
2336                                            orderByComparator);
2337    
2338                                    sql = query.toString();
2339                            }
2340                            else {
2341                                    sql = _SQL_SELECT_DDMSTRUCTURELAYOUT;
2342    
2343                                    if (pagination) {
2344                                            sql = sql.concat(DDMStructureLayoutModelImpl.ORDER_BY_JPQL);
2345                                    }
2346                            }
2347    
2348                            Session session = null;
2349    
2350                            try {
2351                                    session = openSession();
2352    
2353                                    Query q = session.createQuery(sql);
2354    
2355                                    if (!pagination) {
2356                                            list = (List<DDMStructureLayout>)QueryUtil.list(q,
2357                                                            getDialect(), start, end, false);
2358    
2359                                            Collections.sort(list);
2360    
2361                                            list = Collections.unmodifiableList(list);
2362                                    }
2363                                    else {
2364                                            list = (List<DDMStructureLayout>)QueryUtil.list(q,
2365                                                            getDialect(), start, end);
2366                                    }
2367    
2368                                    cacheResult(list);
2369    
2370                                    FinderCacheUtil.putResult(finderPath, finderArgs, list);
2371                            }
2372                            catch (Exception e) {
2373                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
2374    
2375                                    throw processException(e);
2376                            }
2377                            finally {
2378                                    closeSession(session);
2379                            }
2380                    }
2381    
2382                    return list;
2383            }
2384    
2385            /**
2386             * Removes all the d d m structure layouts from the database.
2387             *
2388             */
2389            @Override
2390            public void removeAll() {
2391                    for (DDMStructureLayout ddmStructureLayout : findAll()) {
2392                            remove(ddmStructureLayout);
2393                    }
2394            }
2395    
2396            /**
2397             * Returns the number of d d m structure layouts.
2398             *
2399             * @return the number of d d m structure layouts
2400             */
2401            @Override
2402            public int countAll() {
2403                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_ALL,
2404                                    FINDER_ARGS_EMPTY, this);
2405    
2406                    if (count == null) {
2407                            Session session = null;
2408    
2409                            try {
2410                                    session = openSession();
2411    
2412                                    Query q = session.createQuery(_SQL_COUNT_DDMSTRUCTURELAYOUT);
2413    
2414                                    count = (Long)q.uniqueResult();
2415    
2416                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_ALL,
2417                                            FINDER_ARGS_EMPTY, count);
2418                            }
2419                            catch (Exception e) {
2420                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_ALL,
2421                                            FINDER_ARGS_EMPTY);
2422    
2423                                    throw processException(e);
2424                            }
2425                            finally {
2426                                    closeSession(session);
2427                            }
2428                    }
2429    
2430                    return count.intValue();
2431            }
2432    
2433            @Override
2434            protected Set<String> getBadColumnNames() {
2435                    return _badColumnNames;
2436            }
2437    
2438            /**
2439             * Initializes the d d m structure layout persistence.
2440             */
2441            public void afterPropertiesSet() {
2442            }
2443    
2444            public void destroy() {
2445                    EntityCacheUtil.removeCache(DDMStructureLayoutImpl.class.getName());
2446                    FinderCacheUtil.removeCache(FINDER_CLASS_NAME_ENTITY);
2447                    FinderCacheUtil.removeCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
2448                    FinderCacheUtil.removeCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
2449            }
2450    
2451            private static final String _SQL_SELECT_DDMSTRUCTURELAYOUT = "SELECT ddmStructureLayout FROM DDMStructureLayout ddmStructureLayout";
2452            private static final String _SQL_SELECT_DDMSTRUCTURELAYOUT_WHERE_PKS_IN = "SELECT ddmStructureLayout FROM DDMStructureLayout ddmStructureLayout WHERE structureLayoutId IN (";
2453            private static final String _SQL_SELECT_DDMSTRUCTURELAYOUT_WHERE = "SELECT ddmStructureLayout FROM DDMStructureLayout ddmStructureLayout WHERE ";
2454            private static final String _SQL_COUNT_DDMSTRUCTURELAYOUT = "SELECT COUNT(ddmStructureLayout) FROM DDMStructureLayout ddmStructureLayout";
2455            private static final String _SQL_COUNT_DDMSTRUCTURELAYOUT_WHERE = "SELECT COUNT(ddmStructureLayout) FROM DDMStructureLayout ddmStructureLayout WHERE ";
2456            private static final String _ORDER_BY_ENTITY_ALIAS = "ddmStructureLayout.";
2457            private static final String _NO_SUCH_ENTITY_WITH_PRIMARY_KEY = "No DDMStructureLayout exists with the primary key ";
2458            private static final String _NO_SUCH_ENTITY_WITH_KEY = "No DDMStructureLayout exists with the key {";
2459            private static final Log _log = LogFactoryUtil.getLog(DDMStructureLayoutPersistenceImpl.class);
2460            private static final Set<String> _badColumnNames = SetUtil.fromArray(new String[] {
2461                                    "uuid"
2462                            });
2463            private static final DDMStructureLayout _nullDDMStructureLayout = new DDMStructureLayoutImpl() {
2464                            @Override
2465                            public Object clone() {
2466                                    return this;
2467                            }
2468    
2469                            @Override
2470                            public CacheModel<DDMStructureLayout> toCacheModel() {
2471                                    return _nullDDMStructureLayoutCacheModel;
2472                            }
2473                    };
2474    
2475            private static final CacheModel<DDMStructureLayout> _nullDDMStructureLayoutCacheModel =
2476                    new CacheModel<DDMStructureLayout>() {
2477                            @Override
2478                            public DDMStructureLayout toEntityModel() {
2479                                    return _nullDDMStructureLayout;
2480                            }
2481                    };
2482    }