001    /**
002     * Copyright (c) 2000-2013 Liferay, Inc. All rights reserved.
003     *
004     * This library is free software; you can redistribute it and/or modify it under
005     * the terms of the GNU Lesser General Public License as published by the Free
006     * Software Foundation; either version 2.1 of the License, or (at your option)
007     * any later version.
008     *
009     * This library is distributed in the hope that it will be useful, but WITHOUT
010     * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
011     * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
012     * details.
013     */
014    
015    package com.liferay.portlet.dynamicdatamapping.service.persistence;
016    
017    import com.liferay.portal.kernel.bean.BeanReference;
018    import com.liferay.portal.kernel.cache.CacheRegistryUtil;
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.SQLQuery;
026    import com.liferay.portal.kernel.dao.orm.Session;
027    import com.liferay.portal.kernel.exception.SystemException;
028    import com.liferay.portal.kernel.log.Log;
029    import com.liferay.portal.kernel.log.LogFactoryUtil;
030    import com.liferay.portal.kernel.util.ArrayUtil;
031    import com.liferay.portal.kernel.util.GetterUtil;
032    import com.liferay.portal.kernel.util.InstanceFactory;
033    import com.liferay.portal.kernel.util.OrderByComparator;
034    import com.liferay.portal.kernel.util.SetUtil;
035    import com.liferay.portal.kernel.util.StringBundler;
036    import com.liferay.portal.kernel.util.StringPool;
037    import com.liferay.portal.kernel.util.StringUtil;
038    import com.liferay.portal.kernel.util.UnmodifiableList;
039    import com.liferay.portal.kernel.util.Validator;
040    import com.liferay.portal.kernel.uuid.PortalUUIDUtil;
041    import com.liferay.portal.model.CacheModel;
042    import com.liferay.portal.model.ModelListener;
043    import com.liferay.portal.security.permission.InlineSQLHelperUtil;
044    import com.liferay.portal.service.persistence.impl.BasePersistenceImpl;
045    import com.liferay.portal.service.persistence.impl.TableMapper;
046    import com.liferay.portal.service.persistence.impl.TableMapperFactory;
047    
048    import com.liferay.portlet.documentlibrary.service.persistence.DLFileEntryTypePersistence;
049    import com.liferay.portlet.dynamicdatamapping.NoSuchStructureException;
050    import com.liferay.portlet.dynamicdatamapping.model.DDMStructure;
051    import com.liferay.portlet.dynamicdatamapping.model.impl.DDMStructureImpl;
052    import com.liferay.portlet.dynamicdatamapping.model.impl.DDMStructureModelImpl;
053    
054    import java.io.Serializable;
055    
056    import java.util.ArrayList;
057    import java.util.Collections;
058    import java.util.HashSet;
059    import java.util.List;
060    import java.util.Set;
061    
062    /**
063     * The persistence implementation for the d d m structure service.
064     *
065     * <p>
066     * Caching information and settings can be found in <code>portal.properties</code>
067     * </p>
068     *
069     * @author Brian Wing Shun Chan
070     * @see DDMStructurePersistence
071     * @see DDMStructureUtil
072     * @generated
073     */
074    public class DDMStructurePersistenceImpl extends BasePersistenceImpl<DDMStructure>
075            implements DDMStructurePersistence {
076            /*
077             * NOTE FOR DEVELOPERS:
078             *
079             * Never modify or reference this class directly. Always use {@link DDMStructureUtil} to access the d d m structure persistence. Modify <code>service.xml</code> and rerun ServiceBuilder to regenerate this class.
080             */
081            public static final String FINDER_CLASS_NAME_ENTITY = DDMStructureImpl.class.getName();
082            public static final String FINDER_CLASS_NAME_LIST_WITH_PAGINATION = FINDER_CLASS_NAME_ENTITY +
083                    ".List1";
084            public static final String FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION = FINDER_CLASS_NAME_ENTITY +
085                    ".List2";
086            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_ALL = new FinderPath(DDMStructureModelImpl.ENTITY_CACHE_ENABLED,
087                            DDMStructureModelImpl.FINDER_CACHE_ENABLED, DDMStructureImpl.class,
088                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findAll", new String[0]);
089            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL = new FinderPath(DDMStructureModelImpl.ENTITY_CACHE_ENABLED,
090                            DDMStructureModelImpl.FINDER_CACHE_ENABLED, DDMStructureImpl.class,
091                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findAll", new String[0]);
092            public static final FinderPath FINDER_PATH_COUNT_ALL = new FinderPath(DDMStructureModelImpl.ENTITY_CACHE_ENABLED,
093                            DDMStructureModelImpl.FINDER_CACHE_ENABLED, Long.class,
094                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countAll", new String[0]);
095            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_UUID = new FinderPath(DDMStructureModelImpl.ENTITY_CACHE_ENABLED,
096                            DDMStructureModelImpl.FINDER_CACHE_ENABLED, DDMStructureImpl.class,
097                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByUuid",
098                            new String[] {
099                                    String.class.getName(),
100                                    
101                            Integer.class.getName(), Integer.class.getName(),
102                                    OrderByComparator.class.getName()
103                            });
104            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID = new FinderPath(DDMStructureModelImpl.ENTITY_CACHE_ENABLED,
105                            DDMStructureModelImpl.FINDER_CACHE_ENABLED, DDMStructureImpl.class,
106                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByUuid",
107                            new String[] { String.class.getName() },
108                            DDMStructureModelImpl.UUID_COLUMN_BITMASK);
109            public static final FinderPath FINDER_PATH_COUNT_BY_UUID = new FinderPath(DDMStructureModelImpl.ENTITY_CACHE_ENABLED,
110                            DDMStructureModelImpl.FINDER_CACHE_ENABLED, Long.class,
111                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByUuid",
112                            new String[] { String.class.getName() });
113    
114            /**
115             * Returns all the d d m structures where uuid = &#63;.
116             *
117             * @param uuid the uuid
118             * @return the matching d d m structures
119             * @throws SystemException if a system exception occurred
120             */
121            @Override
122            public List<DDMStructure> findByUuid(String uuid) throws SystemException {
123                    return findByUuid(uuid, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
124            }
125    
126            /**
127             * Returns a range of all the d d m structures where uuid = &#63;.
128             *
129             * <p>
130             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portlet.dynamicdatamapping.model.impl.DDMStructureModelImpl}. 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.
131             * </p>
132             *
133             * @param uuid the uuid
134             * @param start the lower bound of the range of d d m structures
135             * @param end the upper bound of the range of d d m structures (not inclusive)
136             * @return the range of matching d d m structures
137             * @throws SystemException if a system exception occurred
138             */
139            @Override
140            public List<DDMStructure> findByUuid(String uuid, int start, int end)
141                    throws SystemException {
142                    return findByUuid(uuid, start, end, null);
143            }
144    
145            /**
146             * Returns an ordered range of all the d d m structures where uuid = &#63;.
147             *
148             * <p>
149             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portlet.dynamicdatamapping.model.impl.DDMStructureModelImpl}. 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.
150             * </p>
151             *
152             * @param uuid the uuid
153             * @param start the lower bound of the range of d d m structures
154             * @param end the upper bound of the range of d d m structures (not inclusive)
155             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
156             * @return the ordered range of matching d d m structures
157             * @throws SystemException if a system exception occurred
158             */
159            @Override
160            public List<DDMStructure> findByUuid(String uuid, int start, int end,
161                    OrderByComparator orderByComparator) throws SystemException {
162                    boolean pagination = true;
163                    FinderPath finderPath = null;
164                    Object[] finderArgs = null;
165    
166                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
167                                    (orderByComparator == null)) {
168                            pagination = false;
169                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID;
170                            finderArgs = new Object[] { uuid };
171                    }
172                    else {
173                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_UUID;
174                            finderArgs = new Object[] { uuid, start, end, orderByComparator };
175                    }
176    
177                    List<DDMStructure> list = (List<DDMStructure>)FinderCacheUtil.getResult(finderPath,
178                                    finderArgs, this);
179    
180                    if ((list != null) && !list.isEmpty()) {
181                            for (DDMStructure ddmStructure : list) {
182                                    if (!Validator.equals(uuid, ddmStructure.getUuid())) {
183                                            list = null;
184    
185                                            break;
186                                    }
187                            }
188                    }
189    
190                    if (list == null) {
191                            StringBundler query = null;
192    
193                            if (orderByComparator != null) {
194                                    query = new StringBundler(3 +
195                                                    (orderByComparator.getOrderByFields().length * 3));
196                            }
197                            else {
198                                    query = new StringBundler(3);
199                            }
200    
201                            query.append(_SQL_SELECT_DDMSTRUCTURE_WHERE);
202    
203                            boolean bindUuid = false;
204    
205                            if (uuid == null) {
206                                    query.append(_FINDER_COLUMN_UUID_UUID_1);
207                            }
208                            else if (uuid.equals(StringPool.BLANK)) {
209                                    query.append(_FINDER_COLUMN_UUID_UUID_3);
210                            }
211                            else {
212                                    bindUuid = true;
213    
214                                    query.append(_FINDER_COLUMN_UUID_UUID_2);
215                            }
216    
217                            if (orderByComparator != null) {
218                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
219                                            orderByComparator);
220                            }
221                            else
222                             if (pagination) {
223                                    query.append(DDMStructureModelImpl.ORDER_BY_JPQL);
224                            }
225    
226                            String sql = query.toString();
227    
228                            Session session = null;
229    
230                            try {
231                                    session = openSession();
232    
233                                    Query q = session.createQuery(sql);
234    
235                                    QueryPos qPos = QueryPos.getInstance(q);
236    
237                                    if (bindUuid) {
238                                            qPos.add(uuid);
239                                    }
240    
241                                    if (!pagination) {
242                                            list = (List<DDMStructure>)QueryUtil.list(q, getDialect(),
243                                                            start, end, false);
244    
245                                            Collections.sort(list);
246    
247                                            list = new UnmodifiableList<DDMStructure>(list);
248                                    }
249                                    else {
250                                            list = (List<DDMStructure>)QueryUtil.list(q, getDialect(),
251                                                            start, end);
252                                    }
253    
254                                    cacheResult(list);
255    
256                                    FinderCacheUtil.putResult(finderPath, finderArgs, list);
257                            }
258                            catch (Exception e) {
259                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
260    
261                                    throw processException(e);
262                            }
263                            finally {
264                                    closeSession(session);
265                            }
266                    }
267    
268                    return list;
269            }
270    
271            /**
272             * Returns the first d d m structure in the ordered set where uuid = &#63;.
273             *
274             * @param uuid the uuid
275             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
276             * @return the first matching d d m structure
277             * @throws com.liferay.portlet.dynamicdatamapping.NoSuchStructureException if a matching d d m structure could not be found
278             * @throws SystemException if a system exception occurred
279             */
280            @Override
281            public DDMStructure findByUuid_First(String uuid,
282                    OrderByComparator orderByComparator)
283                    throws NoSuchStructureException, SystemException {
284                    DDMStructure ddmStructure = fetchByUuid_First(uuid, orderByComparator);
285    
286                    if (ddmStructure != null) {
287                            return ddmStructure;
288                    }
289    
290                    StringBundler msg = new StringBundler(4);
291    
292                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
293    
294                    msg.append("uuid=");
295                    msg.append(uuid);
296    
297                    msg.append(StringPool.CLOSE_CURLY_BRACE);
298    
299                    throw new NoSuchStructureException(msg.toString());
300            }
301    
302            /**
303             * Returns the first d d m structure in the ordered set where uuid = &#63;.
304             *
305             * @param uuid the uuid
306             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
307             * @return the first matching d d m structure, or <code>null</code> if a matching d d m structure could not be found
308             * @throws SystemException if a system exception occurred
309             */
310            @Override
311            public DDMStructure fetchByUuid_First(String uuid,
312                    OrderByComparator orderByComparator) throws SystemException {
313                    List<DDMStructure> list = findByUuid(uuid, 0, 1, orderByComparator);
314    
315                    if (!list.isEmpty()) {
316                            return list.get(0);
317                    }
318    
319                    return null;
320            }
321    
322            /**
323             * Returns the last d d m structure in the ordered set where uuid = &#63;.
324             *
325             * @param uuid the uuid
326             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
327             * @return the last matching d d m structure
328             * @throws com.liferay.portlet.dynamicdatamapping.NoSuchStructureException if a matching d d m structure could not be found
329             * @throws SystemException if a system exception occurred
330             */
331            @Override
332            public DDMStructure findByUuid_Last(String uuid,
333                    OrderByComparator orderByComparator)
334                    throws NoSuchStructureException, SystemException {
335                    DDMStructure ddmStructure = fetchByUuid_Last(uuid, orderByComparator);
336    
337                    if (ddmStructure != null) {
338                            return ddmStructure;
339                    }
340    
341                    StringBundler msg = new StringBundler(4);
342    
343                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
344    
345                    msg.append("uuid=");
346                    msg.append(uuid);
347    
348                    msg.append(StringPool.CLOSE_CURLY_BRACE);
349    
350                    throw new NoSuchStructureException(msg.toString());
351            }
352    
353            /**
354             * Returns the last d d m structure in the ordered set where uuid = &#63;.
355             *
356             * @param uuid the uuid
357             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
358             * @return the last matching d d m structure, or <code>null</code> if a matching d d m structure could not be found
359             * @throws SystemException if a system exception occurred
360             */
361            @Override
362            public DDMStructure fetchByUuid_Last(String uuid,
363                    OrderByComparator orderByComparator) throws SystemException {
364                    int count = countByUuid(uuid);
365    
366                    if (count == 0) {
367                            return null;
368                    }
369    
370                    List<DDMStructure> list = findByUuid(uuid, count - 1, count,
371                                    orderByComparator);
372    
373                    if (!list.isEmpty()) {
374                            return list.get(0);
375                    }
376    
377                    return null;
378            }
379    
380            /**
381             * Returns the d d m structures before and after the current d d m structure in the ordered set where uuid = &#63;.
382             *
383             * @param structureId the primary key of the current d d m structure
384             * @param uuid the uuid
385             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
386             * @return the previous, current, and next d d m structure
387             * @throws com.liferay.portlet.dynamicdatamapping.NoSuchStructureException if a d d m structure with the primary key could not be found
388             * @throws SystemException if a system exception occurred
389             */
390            @Override
391            public DDMStructure[] findByUuid_PrevAndNext(long structureId, String uuid,
392                    OrderByComparator orderByComparator)
393                    throws NoSuchStructureException, SystemException {
394                    DDMStructure ddmStructure = findByPrimaryKey(structureId);
395    
396                    Session session = null;
397    
398                    try {
399                            session = openSession();
400    
401                            DDMStructure[] array = new DDMStructureImpl[3];
402    
403                            array[0] = getByUuid_PrevAndNext(session, ddmStructure, uuid,
404                                            orderByComparator, true);
405    
406                            array[1] = ddmStructure;
407    
408                            array[2] = getByUuid_PrevAndNext(session, ddmStructure, uuid,
409                                            orderByComparator, false);
410    
411                            return array;
412                    }
413                    catch (Exception e) {
414                            throw processException(e);
415                    }
416                    finally {
417                            closeSession(session);
418                    }
419            }
420    
421            protected DDMStructure getByUuid_PrevAndNext(Session session,
422                    DDMStructure ddmStructure, String uuid,
423                    OrderByComparator orderByComparator, boolean previous) {
424                    StringBundler query = null;
425    
426                    if (orderByComparator != null) {
427                            query = new StringBundler(6 +
428                                            (orderByComparator.getOrderByFields().length * 6));
429                    }
430                    else {
431                            query = new StringBundler(3);
432                    }
433    
434                    query.append(_SQL_SELECT_DDMSTRUCTURE_WHERE);
435    
436                    boolean bindUuid = false;
437    
438                    if (uuid == null) {
439                            query.append(_FINDER_COLUMN_UUID_UUID_1);
440                    }
441                    else if (uuid.equals(StringPool.BLANK)) {
442                            query.append(_FINDER_COLUMN_UUID_UUID_3);
443                    }
444                    else {
445                            bindUuid = true;
446    
447                            query.append(_FINDER_COLUMN_UUID_UUID_2);
448                    }
449    
450                    if (orderByComparator != null) {
451                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
452    
453                            if (orderByConditionFields.length > 0) {
454                                    query.append(WHERE_AND);
455                            }
456    
457                            for (int i = 0; i < orderByConditionFields.length; i++) {
458                                    query.append(_ORDER_BY_ENTITY_ALIAS);
459                                    query.append(orderByConditionFields[i]);
460    
461                                    if ((i + 1) < orderByConditionFields.length) {
462                                            if (orderByComparator.isAscending() ^ previous) {
463                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
464                                            }
465                                            else {
466                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
467                                            }
468                                    }
469                                    else {
470                                            if (orderByComparator.isAscending() ^ previous) {
471                                                    query.append(WHERE_GREATER_THAN);
472                                            }
473                                            else {
474                                                    query.append(WHERE_LESSER_THAN);
475                                            }
476                                    }
477                            }
478    
479                            query.append(ORDER_BY_CLAUSE);
480    
481                            String[] orderByFields = orderByComparator.getOrderByFields();
482    
483                            for (int i = 0; i < orderByFields.length; i++) {
484                                    query.append(_ORDER_BY_ENTITY_ALIAS);
485                                    query.append(orderByFields[i]);
486    
487                                    if ((i + 1) < orderByFields.length) {
488                                            if (orderByComparator.isAscending() ^ previous) {
489                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
490                                            }
491                                            else {
492                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
493                                            }
494                                    }
495                                    else {
496                                            if (orderByComparator.isAscending() ^ previous) {
497                                                    query.append(ORDER_BY_ASC);
498                                            }
499                                            else {
500                                                    query.append(ORDER_BY_DESC);
501                                            }
502                                    }
503                            }
504                    }
505                    else {
506                            query.append(DDMStructureModelImpl.ORDER_BY_JPQL);
507                    }
508    
509                    String sql = query.toString();
510    
511                    Query q = session.createQuery(sql);
512    
513                    q.setFirstResult(0);
514                    q.setMaxResults(2);
515    
516                    QueryPos qPos = QueryPos.getInstance(q);
517    
518                    if (bindUuid) {
519                            qPos.add(uuid);
520                    }
521    
522                    if (orderByComparator != null) {
523                            Object[] values = orderByComparator.getOrderByConditionValues(ddmStructure);
524    
525                            for (Object value : values) {
526                                    qPos.add(value);
527                            }
528                    }
529    
530                    List<DDMStructure> list = q.list();
531    
532                    if (list.size() == 2) {
533                            return list.get(1);
534                    }
535                    else {
536                            return null;
537                    }
538            }
539    
540            /**
541             * Removes all the d d m structures where uuid = &#63; from the database.
542             *
543             * @param uuid the uuid
544             * @throws SystemException if a system exception occurred
545             */
546            @Override
547            public void removeByUuid(String uuid) throws SystemException {
548                    for (DDMStructure ddmStructure : findByUuid(uuid, QueryUtil.ALL_POS,
549                                    QueryUtil.ALL_POS, null)) {
550                            remove(ddmStructure);
551                    }
552            }
553    
554            /**
555             * Returns the number of d d m structures where uuid = &#63;.
556             *
557             * @param uuid the uuid
558             * @return the number of matching d d m structures
559             * @throws SystemException if a system exception occurred
560             */
561            @Override
562            public int countByUuid(String uuid) throws SystemException {
563                    FinderPath finderPath = FINDER_PATH_COUNT_BY_UUID;
564    
565                    Object[] finderArgs = new Object[] { uuid };
566    
567                    Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
568                                    this);
569    
570                    if (count == null) {
571                            StringBundler query = new StringBundler(2);
572    
573                            query.append(_SQL_COUNT_DDMSTRUCTURE_WHERE);
574    
575                            boolean bindUuid = false;
576    
577                            if (uuid == null) {
578                                    query.append(_FINDER_COLUMN_UUID_UUID_1);
579                            }
580                            else if (uuid.equals(StringPool.BLANK)) {
581                                    query.append(_FINDER_COLUMN_UUID_UUID_3);
582                            }
583                            else {
584                                    bindUuid = true;
585    
586                                    query.append(_FINDER_COLUMN_UUID_UUID_2);
587                            }
588    
589                            String sql = query.toString();
590    
591                            Session session = null;
592    
593                            try {
594                                    session = openSession();
595    
596                                    Query q = session.createQuery(sql);
597    
598                                    QueryPos qPos = QueryPos.getInstance(q);
599    
600                                    if (bindUuid) {
601                                            qPos.add(uuid);
602                                    }
603    
604                                    count = (Long)q.uniqueResult();
605    
606                                    FinderCacheUtil.putResult(finderPath, finderArgs, count);
607                            }
608                            catch (Exception e) {
609                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
610    
611                                    throw processException(e);
612                            }
613                            finally {
614                                    closeSession(session);
615                            }
616                    }
617    
618                    return count.intValue();
619            }
620    
621            private static final String _FINDER_COLUMN_UUID_UUID_1 = "ddmStructure.uuid IS NULL";
622            private static final String _FINDER_COLUMN_UUID_UUID_2 = "ddmStructure.uuid = ?";
623            private static final String _FINDER_COLUMN_UUID_UUID_3 = "(ddmStructure.uuid IS NULL OR ddmStructure.uuid = '')";
624            public static final FinderPath FINDER_PATH_FETCH_BY_UUID_G = new FinderPath(DDMStructureModelImpl.ENTITY_CACHE_ENABLED,
625                            DDMStructureModelImpl.FINDER_CACHE_ENABLED, DDMStructureImpl.class,
626                            FINDER_CLASS_NAME_ENTITY, "fetchByUUID_G",
627                            new String[] { String.class.getName(), Long.class.getName() },
628                            DDMStructureModelImpl.UUID_COLUMN_BITMASK |
629                            DDMStructureModelImpl.GROUPID_COLUMN_BITMASK);
630            public static final FinderPath FINDER_PATH_COUNT_BY_UUID_G = new FinderPath(DDMStructureModelImpl.ENTITY_CACHE_ENABLED,
631                            DDMStructureModelImpl.FINDER_CACHE_ENABLED, Long.class,
632                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByUUID_G",
633                            new String[] { String.class.getName(), Long.class.getName() });
634    
635            /**
636             * Returns the d d m structure where uuid = &#63; and groupId = &#63; or throws a {@link com.liferay.portlet.dynamicdatamapping.NoSuchStructureException} if it could not be found.
637             *
638             * @param uuid the uuid
639             * @param groupId the group ID
640             * @return the matching d d m structure
641             * @throws com.liferay.portlet.dynamicdatamapping.NoSuchStructureException if a matching d d m structure could not be found
642             * @throws SystemException if a system exception occurred
643             */
644            @Override
645            public DDMStructure findByUUID_G(String uuid, long groupId)
646                    throws NoSuchStructureException, SystemException {
647                    DDMStructure ddmStructure = fetchByUUID_G(uuid, groupId);
648    
649                    if (ddmStructure == null) {
650                            StringBundler msg = new StringBundler(6);
651    
652                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
653    
654                            msg.append("uuid=");
655                            msg.append(uuid);
656    
657                            msg.append(", groupId=");
658                            msg.append(groupId);
659    
660                            msg.append(StringPool.CLOSE_CURLY_BRACE);
661    
662                            if (_log.isWarnEnabled()) {
663                                    _log.warn(msg.toString());
664                            }
665    
666                            throw new NoSuchStructureException(msg.toString());
667                    }
668    
669                    return ddmStructure;
670            }
671    
672            /**
673             * Returns the d d m structure where uuid = &#63; and groupId = &#63; or returns <code>null</code> if it could not be found. Uses the finder cache.
674             *
675             * @param uuid the uuid
676             * @param groupId the group ID
677             * @return the matching d d m structure, or <code>null</code> if a matching d d m structure could not be found
678             * @throws SystemException if a system exception occurred
679             */
680            @Override
681            public DDMStructure fetchByUUID_G(String uuid, long groupId)
682                    throws SystemException {
683                    return fetchByUUID_G(uuid, groupId, true);
684            }
685    
686            /**
687             * Returns the d d m structure where uuid = &#63; and groupId = &#63; or returns <code>null</code> if it could not be found, optionally using the finder cache.
688             *
689             * @param uuid the uuid
690             * @param groupId the group ID
691             * @param retrieveFromCache whether to use the finder cache
692             * @return the matching d d m structure, or <code>null</code> if a matching d d m structure could not be found
693             * @throws SystemException if a system exception occurred
694             */
695            @Override
696            public DDMStructure fetchByUUID_G(String uuid, long groupId,
697                    boolean retrieveFromCache) throws SystemException {
698                    Object[] finderArgs = new Object[] { uuid, groupId };
699    
700                    Object result = null;
701    
702                    if (retrieveFromCache) {
703                            result = FinderCacheUtil.getResult(FINDER_PATH_FETCH_BY_UUID_G,
704                                            finderArgs, this);
705                    }
706    
707                    if (result instanceof DDMStructure) {
708                            DDMStructure ddmStructure = (DDMStructure)result;
709    
710                            if (!Validator.equals(uuid, ddmStructure.getUuid()) ||
711                                            (groupId != ddmStructure.getGroupId())) {
712                                    result = null;
713                            }
714                    }
715    
716                    if (result == null) {
717                            StringBundler query = new StringBundler(4);
718    
719                            query.append(_SQL_SELECT_DDMSTRUCTURE_WHERE);
720    
721                            boolean bindUuid = false;
722    
723                            if (uuid == null) {
724                                    query.append(_FINDER_COLUMN_UUID_G_UUID_1);
725                            }
726                            else if (uuid.equals(StringPool.BLANK)) {
727                                    query.append(_FINDER_COLUMN_UUID_G_UUID_3);
728                            }
729                            else {
730                                    bindUuid = true;
731    
732                                    query.append(_FINDER_COLUMN_UUID_G_UUID_2);
733                            }
734    
735                            query.append(_FINDER_COLUMN_UUID_G_GROUPID_2);
736    
737                            String sql = query.toString();
738    
739                            Session session = null;
740    
741                            try {
742                                    session = openSession();
743    
744                                    Query q = session.createQuery(sql);
745    
746                                    QueryPos qPos = QueryPos.getInstance(q);
747    
748                                    if (bindUuid) {
749                                            qPos.add(uuid);
750                                    }
751    
752                                    qPos.add(groupId);
753    
754                                    List<DDMStructure> list = q.list();
755    
756                                    if (list.isEmpty()) {
757                                            FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_UUID_G,
758                                                    finderArgs, list);
759                                    }
760                                    else {
761                                            DDMStructure ddmStructure = list.get(0);
762    
763                                            result = ddmStructure;
764    
765                                            cacheResult(ddmStructure);
766    
767                                            if ((ddmStructure.getUuid() == null) ||
768                                                            !ddmStructure.getUuid().equals(uuid) ||
769                                                            (ddmStructure.getGroupId() != groupId)) {
770                                                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_UUID_G,
771                                                            finderArgs, ddmStructure);
772                                            }
773                                    }
774                            }
775                            catch (Exception e) {
776                                    FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_UUID_G,
777                                            finderArgs);
778    
779                                    throw processException(e);
780                            }
781                            finally {
782                                    closeSession(session);
783                            }
784                    }
785    
786                    if (result instanceof List<?>) {
787                            return null;
788                    }
789                    else {
790                            return (DDMStructure)result;
791                    }
792            }
793    
794            /**
795             * Removes the d d m structure where uuid = &#63; and groupId = &#63; from the database.
796             *
797             * @param uuid the uuid
798             * @param groupId the group ID
799             * @return the d d m structure that was removed
800             * @throws SystemException if a system exception occurred
801             */
802            @Override
803            public DDMStructure removeByUUID_G(String uuid, long groupId)
804                    throws NoSuchStructureException, SystemException {
805                    DDMStructure ddmStructure = findByUUID_G(uuid, groupId);
806    
807                    return remove(ddmStructure);
808            }
809    
810            /**
811             * Returns the number of d d m structures where uuid = &#63; and groupId = &#63;.
812             *
813             * @param uuid the uuid
814             * @param groupId the group ID
815             * @return the number of matching d d m structures
816             * @throws SystemException if a system exception occurred
817             */
818            @Override
819            public int countByUUID_G(String uuid, long groupId)
820                    throws SystemException {
821                    FinderPath finderPath = FINDER_PATH_COUNT_BY_UUID_G;
822    
823                    Object[] finderArgs = new Object[] { uuid, groupId };
824    
825                    Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
826                                    this);
827    
828                    if (count == null) {
829                            StringBundler query = new StringBundler(3);
830    
831                            query.append(_SQL_COUNT_DDMSTRUCTURE_WHERE);
832    
833                            boolean bindUuid = false;
834    
835                            if (uuid == null) {
836                                    query.append(_FINDER_COLUMN_UUID_G_UUID_1);
837                            }
838                            else if (uuid.equals(StringPool.BLANK)) {
839                                    query.append(_FINDER_COLUMN_UUID_G_UUID_3);
840                            }
841                            else {
842                                    bindUuid = true;
843    
844                                    query.append(_FINDER_COLUMN_UUID_G_UUID_2);
845                            }
846    
847                            query.append(_FINDER_COLUMN_UUID_G_GROUPID_2);
848    
849                            String sql = query.toString();
850    
851                            Session session = null;
852    
853                            try {
854                                    session = openSession();
855    
856                                    Query q = session.createQuery(sql);
857    
858                                    QueryPos qPos = QueryPos.getInstance(q);
859    
860                                    if (bindUuid) {
861                                            qPos.add(uuid);
862                                    }
863    
864                                    qPos.add(groupId);
865    
866                                    count = (Long)q.uniqueResult();
867    
868                                    FinderCacheUtil.putResult(finderPath, finderArgs, count);
869                            }
870                            catch (Exception e) {
871                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
872    
873                                    throw processException(e);
874                            }
875                            finally {
876                                    closeSession(session);
877                            }
878                    }
879    
880                    return count.intValue();
881            }
882    
883            private static final String _FINDER_COLUMN_UUID_G_UUID_1 = "ddmStructure.uuid IS NULL AND ";
884            private static final String _FINDER_COLUMN_UUID_G_UUID_2 = "ddmStructure.uuid = ? AND ";
885            private static final String _FINDER_COLUMN_UUID_G_UUID_3 = "(ddmStructure.uuid IS NULL OR ddmStructure.uuid = '') AND ";
886            private static final String _FINDER_COLUMN_UUID_G_GROUPID_2 = "ddmStructure.groupId = ?";
887            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_UUID_C = new FinderPath(DDMStructureModelImpl.ENTITY_CACHE_ENABLED,
888                            DDMStructureModelImpl.FINDER_CACHE_ENABLED, DDMStructureImpl.class,
889                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByUuid_C",
890                            new String[] {
891                                    String.class.getName(), Long.class.getName(),
892                                    
893                            Integer.class.getName(), Integer.class.getName(),
894                                    OrderByComparator.class.getName()
895                            });
896            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID_C =
897                    new FinderPath(DDMStructureModelImpl.ENTITY_CACHE_ENABLED,
898                            DDMStructureModelImpl.FINDER_CACHE_ENABLED, DDMStructureImpl.class,
899                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByUuid_C",
900                            new String[] { String.class.getName(), Long.class.getName() },
901                            DDMStructureModelImpl.UUID_COLUMN_BITMASK |
902                            DDMStructureModelImpl.COMPANYID_COLUMN_BITMASK);
903            public static final FinderPath FINDER_PATH_COUNT_BY_UUID_C = new FinderPath(DDMStructureModelImpl.ENTITY_CACHE_ENABLED,
904                            DDMStructureModelImpl.FINDER_CACHE_ENABLED, Long.class,
905                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByUuid_C",
906                            new String[] { String.class.getName(), Long.class.getName() });
907    
908            /**
909             * Returns all the d d m structures where uuid = &#63; and companyId = &#63;.
910             *
911             * @param uuid the uuid
912             * @param companyId the company ID
913             * @return the matching d d m structures
914             * @throws SystemException if a system exception occurred
915             */
916            @Override
917            public List<DDMStructure> findByUuid_C(String uuid, long companyId)
918                    throws SystemException {
919                    return findByUuid_C(uuid, companyId, QueryUtil.ALL_POS,
920                            QueryUtil.ALL_POS, null);
921            }
922    
923            /**
924             * Returns a range of all the d d m structures where uuid = &#63; and companyId = &#63;.
925             *
926             * <p>
927             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portlet.dynamicdatamapping.model.impl.DDMStructureModelImpl}. 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.
928             * </p>
929             *
930             * @param uuid the uuid
931             * @param companyId the company ID
932             * @param start the lower bound of the range of d d m structures
933             * @param end the upper bound of the range of d d m structures (not inclusive)
934             * @return the range of matching d d m structures
935             * @throws SystemException if a system exception occurred
936             */
937            @Override
938            public List<DDMStructure> findByUuid_C(String uuid, long companyId,
939                    int start, int end) throws SystemException {
940                    return findByUuid_C(uuid, companyId, start, end, null);
941            }
942    
943            /**
944             * Returns an ordered range of all the d d m structures where uuid = &#63; and companyId = &#63;.
945             *
946             * <p>
947             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portlet.dynamicdatamapping.model.impl.DDMStructureModelImpl}. 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.
948             * </p>
949             *
950             * @param uuid the uuid
951             * @param companyId the company ID
952             * @param start the lower bound of the range of d d m structures
953             * @param end the upper bound of the range of d d m structures (not inclusive)
954             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
955             * @return the ordered range of matching d d m structures
956             * @throws SystemException if a system exception occurred
957             */
958            @Override
959            public List<DDMStructure> findByUuid_C(String uuid, long companyId,
960                    int start, int end, OrderByComparator orderByComparator)
961                    throws SystemException {
962                    boolean pagination = true;
963                    FinderPath finderPath = null;
964                    Object[] finderArgs = null;
965    
966                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
967                                    (orderByComparator == null)) {
968                            pagination = false;
969                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID_C;
970                            finderArgs = new Object[] { uuid, companyId };
971                    }
972                    else {
973                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_UUID_C;
974                            finderArgs = new Object[] {
975                                            uuid, companyId,
976                                            
977                                            start, end, orderByComparator
978                                    };
979                    }
980    
981                    List<DDMStructure> list = (List<DDMStructure>)FinderCacheUtil.getResult(finderPath,
982                                    finderArgs, this);
983    
984                    if ((list != null) && !list.isEmpty()) {
985                            for (DDMStructure ddmStructure : list) {
986                                    if (!Validator.equals(uuid, ddmStructure.getUuid()) ||
987                                                    (companyId != ddmStructure.getCompanyId())) {
988                                            list = null;
989    
990                                            break;
991                                    }
992                            }
993                    }
994    
995                    if (list == null) {
996                            StringBundler query = null;
997    
998                            if (orderByComparator != null) {
999                                    query = new StringBundler(4 +
1000                                                    (orderByComparator.getOrderByFields().length * 3));
1001                            }
1002                            else {
1003                                    query = new StringBundler(4);
1004                            }
1005    
1006                            query.append(_SQL_SELECT_DDMSTRUCTURE_WHERE);
1007    
1008                            boolean bindUuid = false;
1009    
1010                            if (uuid == null) {
1011                                    query.append(_FINDER_COLUMN_UUID_C_UUID_1);
1012                            }
1013                            else if (uuid.equals(StringPool.BLANK)) {
1014                                    query.append(_FINDER_COLUMN_UUID_C_UUID_3);
1015                            }
1016                            else {
1017                                    bindUuid = true;
1018    
1019                                    query.append(_FINDER_COLUMN_UUID_C_UUID_2);
1020                            }
1021    
1022                            query.append(_FINDER_COLUMN_UUID_C_COMPANYID_2);
1023    
1024                            if (orderByComparator != null) {
1025                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1026                                            orderByComparator);
1027                            }
1028                            else
1029                             if (pagination) {
1030                                    query.append(DDMStructureModelImpl.ORDER_BY_JPQL);
1031                            }
1032    
1033                            String sql = query.toString();
1034    
1035                            Session session = null;
1036    
1037                            try {
1038                                    session = openSession();
1039    
1040                                    Query q = session.createQuery(sql);
1041    
1042                                    QueryPos qPos = QueryPos.getInstance(q);
1043    
1044                                    if (bindUuid) {
1045                                            qPos.add(uuid);
1046                                    }
1047    
1048                                    qPos.add(companyId);
1049    
1050                                    if (!pagination) {
1051                                            list = (List<DDMStructure>)QueryUtil.list(q, getDialect(),
1052                                                            start, end, false);
1053    
1054                                            Collections.sort(list);
1055    
1056                                            list = new UnmodifiableList<DDMStructure>(list);
1057                                    }
1058                                    else {
1059                                            list = (List<DDMStructure>)QueryUtil.list(q, getDialect(),
1060                                                            start, end);
1061                                    }
1062    
1063                                    cacheResult(list);
1064    
1065                                    FinderCacheUtil.putResult(finderPath, finderArgs, list);
1066                            }
1067                            catch (Exception e) {
1068                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
1069    
1070                                    throw processException(e);
1071                            }
1072                            finally {
1073                                    closeSession(session);
1074                            }
1075                    }
1076    
1077                    return list;
1078            }
1079    
1080            /**
1081             * Returns the first d d m structure in the ordered set where uuid = &#63; and companyId = &#63;.
1082             *
1083             * @param uuid the uuid
1084             * @param companyId the company ID
1085             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1086             * @return the first matching d d m structure
1087             * @throws com.liferay.portlet.dynamicdatamapping.NoSuchStructureException if a matching d d m structure could not be found
1088             * @throws SystemException if a system exception occurred
1089             */
1090            @Override
1091            public DDMStructure findByUuid_C_First(String uuid, long companyId,
1092                    OrderByComparator orderByComparator)
1093                    throws NoSuchStructureException, SystemException {
1094                    DDMStructure ddmStructure = fetchByUuid_C_First(uuid, companyId,
1095                                    orderByComparator);
1096    
1097                    if (ddmStructure != null) {
1098                            return ddmStructure;
1099                    }
1100    
1101                    StringBundler msg = new StringBundler(6);
1102    
1103                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1104    
1105                    msg.append("uuid=");
1106                    msg.append(uuid);
1107    
1108                    msg.append(", companyId=");
1109                    msg.append(companyId);
1110    
1111                    msg.append(StringPool.CLOSE_CURLY_BRACE);
1112    
1113                    throw new NoSuchStructureException(msg.toString());
1114            }
1115    
1116            /**
1117             * Returns the first d d m structure in the ordered set where uuid = &#63; and companyId = &#63;.
1118             *
1119             * @param uuid the uuid
1120             * @param companyId the company ID
1121             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1122             * @return the first matching d d m structure, or <code>null</code> if a matching d d m structure could not be found
1123             * @throws SystemException if a system exception occurred
1124             */
1125            @Override
1126            public DDMStructure fetchByUuid_C_First(String uuid, long companyId,
1127                    OrderByComparator orderByComparator) throws SystemException {
1128                    List<DDMStructure> list = findByUuid_C(uuid, companyId, 0, 1,
1129                                    orderByComparator);
1130    
1131                    if (!list.isEmpty()) {
1132                            return list.get(0);
1133                    }
1134    
1135                    return null;
1136            }
1137    
1138            /**
1139             * Returns the last d d m structure in the ordered set where uuid = &#63; and companyId = &#63;.
1140             *
1141             * @param uuid the uuid
1142             * @param companyId the company ID
1143             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1144             * @return the last matching d d m structure
1145             * @throws com.liferay.portlet.dynamicdatamapping.NoSuchStructureException if a matching d d m structure could not be found
1146             * @throws SystemException if a system exception occurred
1147             */
1148            @Override
1149            public DDMStructure findByUuid_C_Last(String uuid, long companyId,
1150                    OrderByComparator orderByComparator)
1151                    throws NoSuchStructureException, SystemException {
1152                    DDMStructure ddmStructure = fetchByUuid_C_Last(uuid, companyId,
1153                                    orderByComparator);
1154    
1155                    if (ddmStructure != null) {
1156                            return ddmStructure;
1157                    }
1158    
1159                    StringBundler msg = new StringBundler(6);
1160    
1161                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1162    
1163                    msg.append("uuid=");
1164                    msg.append(uuid);
1165    
1166                    msg.append(", companyId=");
1167                    msg.append(companyId);
1168    
1169                    msg.append(StringPool.CLOSE_CURLY_BRACE);
1170    
1171                    throw new NoSuchStructureException(msg.toString());
1172            }
1173    
1174            /**
1175             * Returns the last d d m structure in the ordered set where uuid = &#63; and companyId = &#63;.
1176             *
1177             * @param uuid the uuid
1178             * @param companyId the company ID
1179             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1180             * @return the last matching d d m structure, or <code>null</code> if a matching d d m structure could not be found
1181             * @throws SystemException if a system exception occurred
1182             */
1183            @Override
1184            public DDMStructure fetchByUuid_C_Last(String uuid, long companyId,
1185                    OrderByComparator orderByComparator) throws SystemException {
1186                    int count = countByUuid_C(uuid, companyId);
1187    
1188                    if (count == 0) {
1189                            return null;
1190                    }
1191    
1192                    List<DDMStructure> list = findByUuid_C(uuid, companyId, count - 1,
1193                                    count, orderByComparator);
1194    
1195                    if (!list.isEmpty()) {
1196                            return list.get(0);
1197                    }
1198    
1199                    return null;
1200            }
1201    
1202            /**
1203             * Returns the d d m structures before and after the current d d m structure in the ordered set where uuid = &#63; and companyId = &#63;.
1204             *
1205             * @param structureId the primary key of the current d d m structure
1206             * @param uuid the uuid
1207             * @param companyId the company ID
1208             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1209             * @return the previous, current, and next d d m structure
1210             * @throws com.liferay.portlet.dynamicdatamapping.NoSuchStructureException if a d d m structure with the primary key could not be found
1211             * @throws SystemException if a system exception occurred
1212             */
1213            @Override
1214            public DDMStructure[] findByUuid_C_PrevAndNext(long structureId,
1215                    String uuid, long companyId, OrderByComparator orderByComparator)
1216                    throws NoSuchStructureException, SystemException {
1217                    DDMStructure ddmStructure = findByPrimaryKey(structureId);
1218    
1219                    Session session = null;
1220    
1221                    try {
1222                            session = openSession();
1223    
1224                            DDMStructure[] array = new DDMStructureImpl[3];
1225    
1226                            array[0] = getByUuid_C_PrevAndNext(session, ddmStructure, uuid,
1227                                            companyId, orderByComparator, true);
1228    
1229                            array[1] = ddmStructure;
1230    
1231                            array[2] = getByUuid_C_PrevAndNext(session, ddmStructure, uuid,
1232                                            companyId, orderByComparator, false);
1233    
1234                            return array;
1235                    }
1236                    catch (Exception e) {
1237                            throw processException(e);
1238                    }
1239                    finally {
1240                            closeSession(session);
1241                    }
1242            }
1243    
1244            protected DDMStructure getByUuid_C_PrevAndNext(Session session,
1245                    DDMStructure ddmStructure, String uuid, long companyId,
1246                    OrderByComparator orderByComparator, boolean previous) {
1247                    StringBundler query = null;
1248    
1249                    if (orderByComparator != null) {
1250                            query = new StringBundler(6 +
1251                                            (orderByComparator.getOrderByFields().length * 6));
1252                    }
1253                    else {
1254                            query = new StringBundler(3);
1255                    }
1256    
1257                    query.append(_SQL_SELECT_DDMSTRUCTURE_WHERE);
1258    
1259                    boolean bindUuid = false;
1260    
1261                    if (uuid == null) {
1262                            query.append(_FINDER_COLUMN_UUID_C_UUID_1);
1263                    }
1264                    else if (uuid.equals(StringPool.BLANK)) {
1265                            query.append(_FINDER_COLUMN_UUID_C_UUID_3);
1266                    }
1267                    else {
1268                            bindUuid = true;
1269    
1270                            query.append(_FINDER_COLUMN_UUID_C_UUID_2);
1271                    }
1272    
1273                    query.append(_FINDER_COLUMN_UUID_C_COMPANYID_2);
1274    
1275                    if (orderByComparator != null) {
1276                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
1277    
1278                            if (orderByConditionFields.length > 0) {
1279                                    query.append(WHERE_AND);
1280                            }
1281    
1282                            for (int i = 0; i < orderByConditionFields.length; i++) {
1283                                    query.append(_ORDER_BY_ENTITY_ALIAS);
1284                                    query.append(orderByConditionFields[i]);
1285    
1286                                    if ((i + 1) < orderByConditionFields.length) {
1287                                            if (orderByComparator.isAscending() ^ previous) {
1288                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
1289                                            }
1290                                            else {
1291                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
1292                                            }
1293                                    }
1294                                    else {
1295                                            if (orderByComparator.isAscending() ^ previous) {
1296                                                    query.append(WHERE_GREATER_THAN);
1297                                            }
1298                                            else {
1299                                                    query.append(WHERE_LESSER_THAN);
1300                                            }
1301                                    }
1302                            }
1303    
1304                            query.append(ORDER_BY_CLAUSE);
1305    
1306                            String[] orderByFields = orderByComparator.getOrderByFields();
1307    
1308                            for (int i = 0; i < orderByFields.length; i++) {
1309                                    query.append(_ORDER_BY_ENTITY_ALIAS);
1310                                    query.append(orderByFields[i]);
1311    
1312                                    if ((i + 1) < orderByFields.length) {
1313                                            if (orderByComparator.isAscending() ^ previous) {
1314                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
1315                                            }
1316                                            else {
1317                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
1318                                            }
1319                                    }
1320                                    else {
1321                                            if (orderByComparator.isAscending() ^ previous) {
1322                                                    query.append(ORDER_BY_ASC);
1323                                            }
1324                                            else {
1325                                                    query.append(ORDER_BY_DESC);
1326                                            }
1327                                    }
1328                            }
1329                    }
1330                    else {
1331                            query.append(DDMStructureModelImpl.ORDER_BY_JPQL);
1332                    }
1333    
1334                    String sql = query.toString();
1335    
1336                    Query q = session.createQuery(sql);
1337    
1338                    q.setFirstResult(0);
1339                    q.setMaxResults(2);
1340    
1341                    QueryPos qPos = QueryPos.getInstance(q);
1342    
1343                    if (bindUuid) {
1344                            qPos.add(uuid);
1345                    }
1346    
1347                    qPos.add(companyId);
1348    
1349                    if (orderByComparator != null) {
1350                            Object[] values = orderByComparator.getOrderByConditionValues(ddmStructure);
1351    
1352                            for (Object value : values) {
1353                                    qPos.add(value);
1354                            }
1355                    }
1356    
1357                    List<DDMStructure> list = q.list();
1358    
1359                    if (list.size() == 2) {
1360                            return list.get(1);
1361                    }
1362                    else {
1363                            return null;
1364                    }
1365            }
1366    
1367            /**
1368             * Removes all the d d m structures where uuid = &#63; and companyId = &#63; from the database.
1369             *
1370             * @param uuid the uuid
1371             * @param companyId the company ID
1372             * @throws SystemException if a system exception occurred
1373             */
1374            @Override
1375            public void removeByUuid_C(String uuid, long companyId)
1376                    throws SystemException {
1377                    for (DDMStructure ddmStructure : findByUuid_C(uuid, companyId,
1378                                    QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
1379                            remove(ddmStructure);
1380                    }
1381            }
1382    
1383            /**
1384             * Returns the number of d d m structures where uuid = &#63; and companyId = &#63;.
1385             *
1386             * @param uuid the uuid
1387             * @param companyId the company ID
1388             * @return the number of matching d d m structures
1389             * @throws SystemException if a system exception occurred
1390             */
1391            @Override
1392            public int countByUuid_C(String uuid, long companyId)
1393                    throws SystemException {
1394                    FinderPath finderPath = FINDER_PATH_COUNT_BY_UUID_C;
1395    
1396                    Object[] finderArgs = new Object[] { uuid, companyId };
1397    
1398                    Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
1399                                    this);
1400    
1401                    if (count == null) {
1402                            StringBundler query = new StringBundler(3);
1403    
1404                            query.append(_SQL_COUNT_DDMSTRUCTURE_WHERE);
1405    
1406                            boolean bindUuid = false;
1407    
1408                            if (uuid == null) {
1409                                    query.append(_FINDER_COLUMN_UUID_C_UUID_1);
1410                            }
1411                            else if (uuid.equals(StringPool.BLANK)) {
1412                                    query.append(_FINDER_COLUMN_UUID_C_UUID_3);
1413                            }
1414                            else {
1415                                    bindUuid = true;
1416    
1417                                    query.append(_FINDER_COLUMN_UUID_C_UUID_2);
1418                            }
1419    
1420                            query.append(_FINDER_COLUMN_UUID_C_COMPANYID_2);
1421    
1422                            String sql = query.toString();
1423    
1424                            Session session = null;
1425    
1426                            try {
1427                                    session = openSession();
1428    
1429                                    Query q = session.createQuery(sql);
1430    
1431                                    QueryPos qPos = QueryPos.getInstance(q);
1432    
1433                                    if (bindUuid) {
1434                                            qPos.add(uuid);
1435                                    }
1436    
1437                                    qPos.add(companyId);
1438    
1439                                    count = (Long)q.uniqueResult();
1440    
1441                                    FinderCacheUtil.putResult(finderPath, finderArgs, count);
1442                            }
1443                            catch (Exception e) {
1444                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
1445    
1446                                    throw processException(e);
1447                            }
1448                            finally {
1449                                    closeSession(session);
1450                            }
1451                    }
1452    
1453                    return count.intValue();
1454            }
1455    
1456            private static final String _FINDER_COLUMN_UUID_C_UUID_1 = "ddmStructure.uuid IS NULL AND ";
1457            private static final String _FINDER_COLUMN_UUID_C_UUID_2 = "ddmStructure.uuid = ? AND ";
1458            private static final String _FINDER_COLUMN_UUID_C_UUID_3 = "(ddmStructure.uuid IS NULL OR ddmStructure.uuid = '') AND ";
1459            private static final String _FINDER_COLUMN_UUID_C_COMPANYID_2 = "ddmStructure.companyId = ?";
1460            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_GROUPID = new FinderPath(DDMStructureModelImpl.ENTITY_CACHE_ENABLED,
1461                            DDMStructureModelImpl.FINDER_CACHE_ENABLED, DDMStructureImpl.class,
1462                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByGroupId",
1463                            new String[] {
1464                                    Long.class.getName(),
1465                                    
1466                            Integer.class.getName(), Integer.class.getName(),
1467                                    OrderByComparator.class.getName()
1468                            });
1469            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_GROUPID =
1470                    new FinderPath(DDMStructureModelImpl.ENTITY_CACHE_ENABLED,
1471                            DDMStructureModelImpl.FINDER_CACHE_ENABLED, DDMStructureImpl.class,
1472                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByGroupId",
1473                            new String[] { Long.class.getName() },
1474                            DDMStructureModelImpl.GROUPID_COLUMN_BITMASK);
1475            public static final FinderPath FINDER_PATH_COUNT_BY_GROUPID = new FinderPath(DDMStructureModelImpl.ENTITY_CACHE_ENABLED,
1476                            DDMStructureModelImpl.FINDER_CACHE_ENABLED, Long.class,
1477                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByGroupId",
1478                            new String[] { Long.class.getName() });
1479            public static final FinderPath FINDER_PATH_WITH_PAGINATION_COUNT_BY_GROUPID = new FinderPath(DDMStructureModelImpl.ENTITY_CACHE_ENABLED,
1480                            DDMStructureModelImpl.FINDER_CACHE_ENABLED, Long.class,
1481                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "countByGroupId",
1482                            new String[] { Long.class.getName() });
1483    
1484            /**
1485             * Returns all the d d m structures where groupId = &#63;.
1486             *
1487             * @param groupId the group ID
1488             * @return the matching d d m structures
1489             * @throws SystemException if a system exception occurred
1490             */
1491            @Override
1492            public List<DDMStructure> findByGroupId(long groupId)
1493                    throws SystemException {
1494                    return findByGroupId(groupId, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
1495            }
1496    
1497            /**
1498             * Returns a range of all the d d m structures where groupId = &#63;.
1499             *
1500             * <p>
1501             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portlet.dynamicdatamapping.model.impl.DDMStructureModelImpl}. 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.
1502             * </p>
1503             *
1504             * @param groupId the group ID
1505             * @param start the lower bound of the range of d d m structures
1506             * @param end the upper bound of the range of d d m structures (not inclusive)
1507             * @return the range of matching d d m structures
1508             * @throws SystemException if a system exception occurred
1509             */
1510            @Override
1511            public List<DDMStructure> findByGroupId(long groupId, int start, int end)
1512                    throws SystemException {
1513                    return findByGroupId(groupId, start, end, null);
1514            }
1515    
1516            /**
1517             * Returns an ordered range of all the d d m structures where groupId = &#63;.
1518             *
1519             * <p>
1520             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portlet.dynamicdatamapping.model.impl.DDMStructureModelImpl}. 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.
1521             * </p>
1522             *
1523             * @param groupId the group ID
1524             * @param start the lower bound of the range of d d m structures
1525             * @param end the upper bound of the range of d d m structures (not inclusive)
1526             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
1527             * @return the ordered range of matching d d m structures
1528             * @throws SystemException if a system exception occurred
1529             */
1530            @Override
1531            public List<DDMStructure> findByGroupId(long groupId, int start, int end,
1532                    OrderByComparator orderByComparator) throws SystemException {
1533                    boolean pagination = true;
1534                    FinderPath finderPath = null;
1535                    Object[] finderArgs = null;
1536    
1537                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
1538                                    (orderByComparator == null)) {
1539                            pagination = false;
1540                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_GROUPID;
1541                            finderArgs = new Object[] { groupId };
1542                    }
1543                    else {
1544                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_GROUPID;
1545                            finderArgs = new Object[] { groupId, start, end, orderByComparator };
1546                    }
1547    
1548                    List<DDMStructure> list = (List<DDMStructure>)FinderCacheUtil.getResult(finderPath,
1549                                    finderArgs, this);
1550    
1551                    if ((list != null) && !list.isEmpty()) {
1552                            for (DDMStructure ddmStructure : list) {
1553                                    if ((groupId != ddmStructure.getGroupId())) {
1554                                            list = null;
1555    
1556                                            break;
1557                                    }
1558                            }
1559                    }
1560    
1561                    if (list == null) {
1562                            StringBundler query = null;
1563    
1564                            if (orderByComparator != null) {
1565                                    query = new StringBundler(3 +
1566                                                    (orderByComparator.getOrderByFields().length * 3));
1567                            }
1568                            else {
1569                                    query = new StringBundler(3);
1570                            }
1571    
1572                            query.append(_SQL_SELECT_DDMSTRUCTURE_WHERE);
1573    
1574                            query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
1575    
1576                            if (orderByComparator != null) {
1577                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1578                                            orderByComparator);
1579                            }
1580                            else
1581                             if (pagination) {
1582                                    query.append(DDMStructureModelImpl.ORDER_BY_JPQL);
1583                            }
1584    
1585                            String sql = query.toString();
1586    
1587                            Session session = null;
1588    
1589                            try {
1590                                    session = openSession();
1591    
1592                                    Query q = session.createQuery(sql);
1593    
1594                                    QueryPos qPos = QueryPos.getInstance(q);
1595    
1596                                    qPos.add(groupId);
1597    
1598                                    if (!pagination) {
1599                                            list = (List<DDMStructure>)QueryUtil.list(q, getDialect(),
1600                                                            start, end, false);
1601    
1602                                            Collections.sort(list);
1603    
1604                                            list = new UnmodifiableList<DDMStructure>(list);
1605                                    }
1606                                    else {
1607                                            list = (List<DDMStructure>)QueryUtil.list(q, getDialect(),
1608                                                            start, end);
1609                                    }
1610    
1611                                    cacheResult(list);
1612    
1613                                    FinderCacheUtil.putResult(finderPath, finderArgs, list);
1614                            }
1615                            catch (Exception e) {
1616                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
1617    
1618                                    throw processException(e);
1619                            }
1620                            finally {
1621                                    closeSession(session);
1622                            }
1623                    }
1624    
1625                    return list;
1626            }
1627    
1628            /**
1629             * Returns the first d d m structure in the ordered set where groupId = &#63;.
1630             *
1631             * @param groupId the group ID
1632             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1633             * @return the first matching d d m structure
1634             * @throws com.liferay.portlet.dynamicdatamapping.NoSuchStructureException if a matching d d m structure could not be found
1635             * @throws SystemException if a system exception occurred
1636             */
1637            @Override
1638            public DDMStructure findByGroupId_First(long groupId,
1639                    OrderByComparator orderByComparator)
1640                    throws NoSuchStructureException, SystemException {
1641                    DDMStructure ddmStructure = fetchByGroupId_First(groupId,
1642                                    orderByComparator);
1643    
1644                    if (ddmStructure != null) {
1645                            return ddmStructure;
1646                    }
1647    
1648                    StringBundler msg = new StringBundler(4);
1649    
1650                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1651    
1652                    msg.append("groupId=");
1653                    msg.append(groupId);
1654    
1655                    msg.append(StringPool.CLOSE_CURLY_BRACE);
1656    
1657                    throw new NoSuchStructureException(msg.toString());
1658            }
1659    
1660            /**
1661             * Returns the first d d m structure in the ordered set where groupId = &#63;.
1662             *
1663             * @param groupId the group ID
1664             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1665             * @return the first matching d d m structure, or <code>null</code> if a matching d d m structure could not be found
1666             * @throws SystemException if a system exception occurred
1667             */
1668            @Override
1669            public DDMStructure fetchByGroupId_First(long groupId,
1670                    OrderByComparator orderByComparator) throws SystemException {
1671                    List<DDMStructure> list = findByGroupId(groupId, 0, 1, orderByComparator);
1672    
1673                    if (!list.isEmpty()) {
1674                            return list.get(0);
1675                    }
1676    
1677                    return null;
1678            }
1679    
1680            /**
1681             * Returns the last d d m structure in the ordered set where groupId = &#63;.
1682             *
1683             * @param groupId the group ID
1684             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1685             * @return the last matching d d m structure
1686             * @throws com.liferay.portlet.dynamicdatamapping.NoSuchStructureException if a matching d d m structure could not be found
1687             * @throws SystemException if a system exception occurred
1688             */
1689            @Override
1690            public DDMStructure findByGroupId_Last(long groupId,
1691                    OrderByComparator orderByComparator)
1692                    throws NoSuchStructureException, SystemException {
1693                    DDMStructure ddmStructure = fetchByGroupId_Last(groupId,
1694                                    orderByComparator);
1695    
1696                    if (ddmStructure != null) {
1697                            return ddmStructure;
1698                    }
1699    
1700                    StringBundler msg = new StringBundler(4);
1701    
1702                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1703    
1704                    msg.append("groupId=");
1705                    msg.append(groupId);
1706    
1707                    msg.append(StringPool.CLOSE_CURLY_BRACE);
1708    
1709                    throw new NoSuchStructureException(msg.toString());
1710            }
1711    
1712            /**
1713             * Returns the last d d m structure in the ordered set where groupId = &#63;.
1714             *
1715             * @param groupId the group ID
1716             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1717             * @return the last matching d d m structure, or <code>null</code> if a matching d d m structure could not be found
1718             * @throws SystemException if a system exception occurred
1719             */
1720            @Override
1721            public DDMStructure fetchByGroupId_Last(long groupId,
1722                    OrderByComparator orderByComparator) throws SystemException {
1723                    int count = countByGroupId(groupId);
1724    
1725                    if (count == 0) {
1726                            return null;
1727                    }
1728    
1729                    List<DDMStructure> list = findByGroupId(groupId, count - 1, count,
1730                                    orderByComparator);
1731    
1732                    if (!list.isEmpty()) {
1733                            return list.get(0);
1734                    }
1735    
1736                    return null;
1737            }
1738    
1739            /**
1740             * Returns the d d m structures before and after the current d d m structure in the ordered set where groupId = &#63;.
1741             *
1742             * @param structureId the primary key of the current d d m structure
1743             * @param groupId the group ID
1744             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1745             * @return the previous, current, and next d d m structure
1746             * @throws com.liferay.portlet.dynamicdatamapping.NoSuchStructureException if a d d m structure with the primary key could not be found
1747             * @throws SystemException if a system exception occurred
1748             */
1749            @Override
1750            public DDMStructure[] findByGroupId_PrevAndNext(long structureId,
1751                    long groupId, OrderByComparator orderByComparator)
1752                    throws NoSuchStructureException, SystemException {
1753                    DDMStructure ddmStructure = findByPrimaryKey(structureId);
1754    
1755                    Session session = null;
1756    
1757                    try {
1758                            session = openSession();
1759    
1760                            DDMStructure[] array = new DDMStructureImpl[3];
1761    
1762                            array[0] = getByGroupId_PrevAndNext(session, ddmStructure, groupId,
1763                                            orderByComparator, true);
1764    
1765                            array[1] = ddmStructure;
1766    
1767                            array[2] = getByGroupId_PrevAndNext(session, ddmStructure, groupId,
1768                                            orderByComparator, false);
1769    
1770                            return array;
1771                    }
1772                    catch (Exception e) {
1773                            throw processException(e);
1774                    }
1775                    finally {
1776                            closeSession(session);
1777                    }
1778            }
1779    
1780            protected DDMStructure getByGroupId_PrevAndNext(Session session,
1781                    DDMStructure ddmStructure, long groupId,
1782                    OrderByComparator orderByComparator, boolean previous) {
1783                    StringBundler query = null;
1784    
1785                    if (orderByComparator != null) {
1786                            query = new StringBundler(6 +
1787                                            (orderByComparator.getOrderByFields().length * 6));
1788                    }
1789                    else {
1790                            query = new StringBundler(3);
1791                    }
1792    
1793                    query.append(_SQL_SELECT_DDMSTRUCTURE_WHERE);
1794    
1795                    query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
1796    
1797                    if (orderByComparator != null) {
1798                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
1799    
1800                            if (orderByConditionFields.length > 0) {
1801                                    query.append(WHERE_AND);
1802                            }
1803    
1804                            for (int i = 0; i < orderByConditionFields.length; i++) {
1805                                    query.append(_ORDER_BY_ENTITY_ALIAS);
1806                                    query.append(orderByConditionFields[i]);
1807    
1808                                    if ((i + 1) < orderByConditionFields.length) {
1809                                            if (orderByComparator.isAscending() ^ previous) {
1810                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
1811                                            }
1812                                            else {
1813                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
1814                                            }
1815                                    }
1816                                    else {
1817                                            if (orderByComparator.isAscending() ^ previous) {
1818                                                    query.append(WHERE_GREATER_THAN);
1819                                            }
1820                                            else {
1821                                                    query.append(WHERE_LESSER_THAN);
1822                                            }
1823                                    }
1824                            }
1825    
1826                            query.append(ORDER_BY_CLAUSE);
1827    
1828                            String[] orderByFields = orderByComparator.getOrderByFields();
1829    
1830                            for (int i = 0; i < orderByFields.length; i++) {
1831                                    query.append(_ORDER_BY_ENTITY_ALIAS);
1832                                    query.append(orderByFields[i]);
1833    
1834                                    if ((i + 1) < orderByFields.length) {
1835                                            if (orderByComparator.isAscending() ^ previous) {
1836                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
1837                                            }
1838                                            else {
1839                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
1840                                            }
1841                                    }
1842                                    else {
1843                                            if (orderByComparator.isAscending() ^ previous) {
1844                                                    query.append(ORDER_BY_ASC);
1845                                            }
1846                                            else {
1847                                                    query.append(ORDER_BY_DESC);
1848                                            }
1849                                    }
1850                            }
1851                    }
1852                    else {
1853                            query.append(DDMStructureModelImpl.ORDER_BY_JPQL);
1854                    }
1855    
1856                    String sql = query.toString();
1857    
1858                    Query q = session.createQuery(sql);
1859    
1860                    q.setFirstResult(0);
1861                    q.setMaxResults(2);
1862    
1863                    QueryPos qPos = QueryPos.getInstance(q);
1864    
1865                    qPos.add(groupId);
1866    
1867                    if (orderByComparator != null) {
1868                            Object[] values = orderByComparator.getOrderByConditionValues(ddmStructure);
1869    
1870                            for (Object value : values) {
1871                                    qPos.add(value);
1872                            }
1873                    }
1874    
1875                    List<DDMStructure> list = q.list();
1876    
1877                    if (list.size() == 2) {
1878                            return list.get(1);
1879                    }
1880                    else {
1881                            return null;
1882                    }
1883            }
1884    
1885            /**
1886             * Returns all the d d m structures that the user has permission to view where groupId = &#63;.
1887             *
1888             * @param groupId the group ID
1889             * @return the matching d d m structures that the user has permission to view
1890             * @throws SystemException if a system exception occurred
1891             */
1892            @Override
1893            public List<DDMStructure> filterFindByGroupId(long groupId)
1894                    throws SystemException {
1895                    return filterFindByGroupId(groupId, QueryUtil.ALL_POS,
1896                            QueryUtil.ALL_POS, null);
1897            }
1898    
1899            /**
1900             * Returns a range of all the d d m structures that the user has permission to view where groupId = &#63;.
1901             *
1902             * <p>
1903             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portlet.dynamicdatamapping.model.impl.DDMStructureModelImpl}. 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.
1904             * </p>
1905             *
1906             * @param groupId the group ID
1907             * @param start the lower bound of the range of d d m structures
1908             * @param end the upper bound of the range of d d m structures (not inclusive)
1909             * @return the range of matching d d m structures that the user has permission to view
1910             * @throws SystemException if a system exception occurred
1911             */
1912            @Override
1913            public List<DDMStructure> filterFindByGroupId(long groupId, int start,
1914                    int end) throws SystemException {
1915                    return filterFindByGroupId(groupId, start, end, null);
1916            }
1917    
1918            /**
1919             * Returns an ordered range of all the d d m structures that the user has permissions to view where groupId = &#63;.
1920             *
1921             * <p>
1922             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portlet.dynamicdatamapping.model.impl.DDMStructureModelImpl}. 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.
1923             * </p>
1924             *
1925             * @param groupId the group ID
1926             * @param start the lower bound of the range of d d m structures
1927             * @param end the upper bound of the range of d d m structures (not inclusive)
1928             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
1929             * @return the ordered range of matching d d m structures that the user has permission to view
1930             * @throws SystemException if a system exception occurred
1931             */
1932            @Override
1933            public List<DDMStructure> filterFindByGroupId(long groupId, int start,
1934                    int end, OrderByComparator orderByComparator) throws SystemException {
1935                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
1936                            return findByGroupId(groupId, start, end, orderByComparator);
1937                    }
1938    
1939                    StringBundler query = null;
1940    
1941                    if (orderByComparator != null) {
1942                            query = new StringBundler(3 +
1943                                            (orderByComparator.getOrderByFields().length * 3));
1944                    }
1945                    else {
1946                            query = new StringBundler(3);
1947                    }
1948    
1949                    if (getDB().isSupportsInlineDistinct()) {
1950                            query.append(_FILTER_SQL_SELECT_DDMSTRUCTURE_WHERE);
1951                    }
1952                    else {
1953                            query.append(_FILTER_SQL_SELECT_DDMSTRUCTURE_NO_INLINE_DISTINCT_WHERE_1);
1954                    }
1955    
1956                    query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
1957    
1958                    if (!getDB().isSupportsInlineDistinct()) {
1959                            query.append(_FILTER_SQL_SELECT_DDMSTRUCTURE_NO_INLINE_DISTINCT_WHERE_2);
1960                    }
1961    
1962                    if (orderByComparator != null) {
1963                            if (getDB().isSupportsInlineDistinct()) {
1964                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1965                                            orderByComparator, true);
1966                            }
1967                            else {
1968                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_TABLE,
1969                                            orderByComparator, true);
1970                            }
1971                    }
1972                    else {
1973                            if (getDB().isSupportsInlineDistinct()) {
1974                                    query.append(DDMStructureModelImpl.ORDER_BY_JPQL);
1975                            }
1976                            else {
1977                                    query.append(DDMStructureModelImpl.ORDER_BY_SQL);
1978                            }
1979                    }
1980    
1981                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
1982                                    DDMStructure.class.getName(),
1983                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
1984    
1985                    Session session = null;
1986    
1987                    try {
1988                            session = openSession();
1989    
1990                            SQLQuery q = session.createSQLQuery(sql);
1991    
1992                            if (getDB().isSupportsInlineDistinct()) {
1993                                    q.addEntity(_FILTER_ENTITY_ALIAS, DDMStructureImpl.class);
1994                            }
1995                            else {
1996                                    q.addEntity(_FILTER_ENTITY_TABLE, DDMStructureImpl.class);
1997                            }
1998    
1999                            QueryPos qPos = QueryPos.getInstance(q);
2000    
2001                            qPos.add(groupId);
2002    
2003                            return (List<DDMStructure>)QueryUtil.list(q, getDialect(), start,
2004                                    end);
2005                    }
2006                    catch (Exception e) {
2007                            throw processException(e);
2008                    }
2009                    finally {
2010                            closeSession(session);
2011                    }
2012            }
2013    
2014            /**
2015             * Returns the d d m structures before and after the current d d m structure in the ordered set of d d m structures that the user has permission to view where groupId = &#63;.
2016             *
2017             * @param structureId the primary key of the current d d m structure
2018             * @param groupId the group ID
2019             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
2020             * @return the previous, current, and next d d m structure
2021             * @throws com.liferay.portlet.dynamicdatamapping.NoSuchStructureException if a d d m structure with the primary key could not be found
2022             * @throws SystemException if a system exception occurred
2023             */
2024            @Override
2025            public DDMStructure[] filterFindByGroupId_PrevAndNext(long structureId,
2026                    long groupId, OrderByComparator orderByComparator)
2027                    throws NoSuchStructureException, SystemException {
2028                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
2029                            return findByGroupId_PrevAndNext(structureId, groupId,
2030                                    orderByComparator);
2031                    }
2032    
2033                    DDMStructure ddmStructure = findByPrimaryKey(structureId);
2034    
2035                    Session session = null;
2036    
2037                    try {
2038                            session = openSession();
2039    
2040                            DDMStructure[] array = new DDMStructureImpl[3];
2041    
2042                            array[0] = filterGetByGroupId_PrevAndNext(session, ddmStructure,
2043                                            groupId, orderByComparator, true);
2044    
2045                            array[1] = ddmStructure;
2046    
2047                            array[2] = filterGetByGroupId_PrevAndNext(session, ddmStructure,
2048                                            groupId, orderByComparator, false);
2049    
2050                            return array;
2051                    }
2052                    catch (Exception e) {
2053                            throw processException(e);
2054                    }
2055                    finally {
2056                            closeSession(session);
2057                    }
2058            }
2059    
2060            protected DDMStructure filterGetByGroupId_PrevAndNext(Session session,
2061                    DDMStructure ddmStructure, long groupId,
2062                    OrderByComparator orderByComparator, boolean previous) {
2063                    StringBundler query = null;
2064    
2065                    if (orderByComparator != null) {
2066                            query = new StringBundler(6 +
2067                                            (orderByComparator.getOrderByFields().length * 6));
2068                    }
2069                    else {
2070                            query = new StringBundler(3);
2071                    }
2072    
2073                    if (getDB().isSupportsInlineDistinct()) {
2074                            query.append(_FILTER_SQL_SELECT_DDMSTRUCTURE_WHERE);
2075                    }
2076                    else {
2077                            query.append(_FILTER_SQL_SELECT_DDMSTRUCTURE_NO_INLINE_DISTINCT_WHERE_1);
2078                    }
2079    
2080                    query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
2081    
2082                    if (!getDB().isSupportsInlineDistinct()) {
2083                            query.append(_FILTER_SQL_SELECT_DDMSTRUCTURE_NO_INLINE_DISTINCT_WHERE_2);
2084                    }
2085    
2086                    if (orderByComparator != null) {
2087                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
2088    
2089                            if (orderByConditionFields.length > 0) {
2090                                    query.append(WHERE_AND);
2091                            }
2092    
2093                            for (int i = 0; i < orderByConditionFields.length; i++) {
2094                                    if (getDB().isSupportsInlineDistinct()) {
2095                                            query.append(_ORDER_BY_ENTITY_ALIAS);
2096                                    }
2097                                    else {
2098                                            query.append(_ORDER_BY_ENTITY_TABLE);
2099                                    }
2100    
2101                                    query.append(orderByConditionFields[i]);
2102    
2103                                    if ((i + 1) < orderByConditionFields.length) {
2104                                            if (orderByComparator.isAscending() ^ previous) {
2105                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
2106                                            }
2107                                            else {
2108                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
2109                                            }
2110                                    }
2111                                    else {
2112                                            if (orderByComparator.isAscending() ^ previous) {
2113                                                    query.append(WHERE_GREATER_THAN);
2114                                            }
2115                                            else {
2116                                                    query.append(WHERE_LESSER_THAN);
2117                                            }
2118                                    }
2119                            }
2120    
2121                            query.append(ORDER_BY_CLAUSE);
2122    
2123                            String[] orderByFields = orderByComparator.getOrderByFields();
2124    
2125                            for (int i = 0; i < orderByFields.length; i++) {
2126                                    if (getDB().isSupportsInlineDistinct()) {
2127                                            query.append(_ORDER_BY_ENTITY_ALIAS);
2128                                    }
2129                                    else {
2130                                            query.append(_ORDER_BY_ENTITY_TABLE);
2131                                    }
2132    
2133                                    query.append(orderByFields[i]);
2134    
2135                                    if ((i + 1) < orderByFields.length) {
2136                                            if (orderByComparator.isAscending() ^ previous) {
2137                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
2138                                            }
2139                                            else {
2140                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
2141                                            }
2142                                    }
2143                                    else {
2144                                            if (orderByComparator.isAscending() ^ previous) {
2145                                                    query.append(ORDER_BY_ASC);
2146                                            }
2147                                            else {
2148                                                    query.append(ORDER_BY_DESC);
2149                                            }
2150                                    }
2151                            }
2152                    }
2153                    else {
2154                            if (getDB().isSupportsInlineDistinct()) {
2155                                    query.append(DDMStructureModelImpl.ORDER_BY_JPQL);
2156                            }
2157                            else {
2158                                    query.append(DDMStructureModelImpl.ORDER_BY_SQL);
2159                            }
2160                    }
2161    
2162                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
2163                                    DDMStructure.class.getName(),
2164                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
2165    
2166                    SQLQuery q = session.createSQLQuery(sql);
2167    
2168                    q.setFirstResult(0);
2169                    q.setMaxResults(2);
2170    
2171                    if (getDB().isSupportsInlineDistinct()) {
2172                            q.addEntity(_FILTER_ENTITY_ALIAS, DDMStructureImpl.class);
2173                    }
2174                    else {
2175                            q.addEntity(_FILTER_ENTITY_TABLE, DDMStructureImpl.class);
2176                    }
2177    
2178                    QueryPos qPos = QueryPos.getInstance(q);
2179    
2180                    qPos.add(groupId);
2181    
2182                    if (orderByComparator != null) {
2183                            Object[] values = orderByComparator.getOrderByConditionValues(ddmStructure);
2184    
2185                            for (Object value : values) {
2186                                    qPos.add(value);
2187                            }
2188                    }
2189    
2190                    List<DDMStructure> list = q.list();
2191    
2192                    if (list.size() == 2) {
2193                            return list.get(1);
2194                    }
2195                    else {
2196                            return null;
2197                    }
2198            }
2199    
2200            /**
2201             * Returns all the d d m structures that the user has permission to view where groupId = any &#63;.
2202             *
2203             * @param groupIds the group IDs
2204             * @return the matching d d m structures that the user has permission to view
2205             * @throws SystemException if a system exception occurred
2206             */
2207            @Override
2208            public List<DDMStructure> filterFindByGroupId(long[] groupIds)
2209                    throws SystemException {
2210                    return filterFindByGroupId(groupIds, QueryUtil.ALL_POS,
2211                            QueryUtil.ALL_POS, null);
2212            }
2213    
2214            /**
2215             * Returns a range of all the d d m structures that the user has permission to view where groupId = any &#63;.
2216             *
2217             * <p>
2218             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portlet.dynamicdatamapping.model.impl.DDMStructureModelImpl}. 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.
2219             * </p>
2220             *
2221             * @param groupIds the group IDs
2222             * @param start the lower bound of the range of d d m structures
2223             * @param end the upper bound of the range of d d m structures (not inclusive)
2224             * @return the range of matching d d m structures that the user has permission to view
2225             * @throws SystemException if a system exception occurred
2226             */
2227            @Override
2228            public List<DDMStructure> filterFindByGroupId(long[] groupIds, int start,
2229                    int end) throws SystemException {
2230                    return filterFindByGroupId(groupIds, start, end, null);
2231            }
2232    
2233            /**
2234             * Returns an ordered range of all the d d m structures that the user has permission to view where groupId = any &#63;.
2235             *
2236             * <p>
2237             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portlet.dynamicdatamapping.model.impl.DDMStructureModelImpl}. 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.
2238             * </p>
2239             *
2240             * @param groupIds the group IDs
2241             * @param start the lower bound of the range of d d m structures
2242             * @param end the upper bound of the range of d d m structures (not inclusive)
2243             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
2244             * @return the ordered range of matching d d m structures that the user has permission to view
2245             * @throws SystemException if a system exception occurred
2246             */
2247            @Override
2248            public List<DDMStructure> filterFindByGroupId(long[] groupIds, int start,
2249                    int end, OrderByComparator orderByComparator) throws SystemException {
2250                    if (!InlineSQLHelperUtil.isEnabled(groupIds)) {
2251                            return findByGroupId(groupIds, start, end, orderByComparator);
2252                    }
2253    
2254                    StringBundler query = new StringBundler();
2255    
2256                    if (getDB().isSupportsInlineDistinct()) {
2257                            query.append(_FILTER_SQL_SELECT_DDMSTRUCTURE_WHERE);
2258                    }
2259                    else {
2260                            query.append(_FILTER_SQL_SELECT_DDMSTRUCTURE_NO_INLINE_DISTINCT_WHERE_1);
2261                    }
2262    
2263                    boolean conjunctionable = false;
2264    
2265                    if ((groupIds == null) || (groupIds.length > 0)) {
2266                            if (conjunctionable) {
2267                                    query.append(WHERE_AND);
2268                            }
2269    
2270                            query.append(StringPool.OPEN_PARENTHESIS);
2271    
2272                            for (int i = 0; i < groupIds.length; i++) {
2273                                    query.append(_FINDER_COLUMN_GROUPID_GROUPID_5);
2274    
2275                                    if ((i + 1) < groupIds.length) {
2276                                            query.append(WHERE_OR);
2277                                    }
2278                            }
2279    
2280                            query.append(StringPool.CLOSE_PARENTHESIS);
2281    
2282                            conjunctionable = true;
2283                    }
2284    
2285                    if (!getDB().isSupportsInlineDistinct()) {
2286                            query.append(_FILTER_SQL_SELECT_DDMSTRUCTURE_NO_INLINE_DISTINCT_WHERE_2);
2287                    }
2288    
2289                    if (orderByComparator != null) {
2290                            if (getDB().isSupportsInlineDistinct()) {
2291                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
2292                                            orderByComparator, true);
2293                            }
2294                            else {
2295                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_TABLE,
2296                                            orderByComparator, true);
2297                            }
2298                    }
2299                    else {
2300                            if (getDB().isSupportsInlineDistinct()) {
2301                                    query.append(DDMStructureModelImpl.ORDER_BY_JPQL);
2302                            }
2303                            else {
2304                                    query.append(DDMStructureModelImpl.ORDER_BY_SQL);
2305                            }
2306                    }
2307    
2308                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
2309                                    DDMStructure.class.getName(),
2310                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupIds);
2311    
2312                    Session session = null;
2313    
2314                    try {
2315                            session = openSession();
2316    
2317                            SQLQuery q = session.createSQLQuery(sql);
2318    
2319                            if (getDB().isSupportsInlineDistinct()) {
2320                                    q.addEntity(_FILTER_ENTITY_ALIAS, DDMStructureImpl.class);
2321                            }
2322                            else {
2323                                    q.addEntity(_FILTER_ENTITY_TABLE, DDMStructureImpl.class);
2324                            }
2325    
2326                            QueryPos qPos = QueryPos.getInstance(q);
2327    
2328                            if (groupIds != null) {
2329                                    qPos.add(groupIds);
2330                            }
2331    
2332                            return (List<DDMStructure>)QueryUtil.list(q, getDialect(), start,
2333                                    end);
2334                    }
2335                    catch (Exception e) {
2336                            throw processException(e);
2337                    }
2338                    finally {
2339                            closeSession(session);
2340                    }
2341            }
2342    
2343            /**
2344             * Returns all the d d m structures where groupId = any &#63;.
2345             *
2346             * <p>
2347             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portlet.dynamicdatamapping.model.impl.DDMStructureModelImpl}. 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.
2348             * </p>
2349             *
2350             * @param groupIds the group IDs
2351             * @return the matching d d m structures
2352             * @throws SystemException if a system exception occurred
2353             */
2354            @Override
2355            public List<DDMStructure> findByGroupId(long[] groupIds)
2356                    throws SystemException {
2357                    return findByGroupId(groupIds, QueryUtil.ALL_POS, QueryUtil.ALL_POS,
2358                            null);
2359            }
2360    
2361            /**
2362             * Returns a range of all the d d m structures where groupId = any &#63;.
2363             *
2364             * <p>
2365             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portlet.dynamicdatamapping.model.impl.DDMStructureModelImpl}. 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.
2366             * </p>
2367             *
2368             * @param groupIds the group IDs
2369             * @param start the lower bound of the range of d d m structures
2370             * @param end the upper bound of the range of d d m structures (not inclusive)
2371             * @return the range of matching d d m structures
2372             * @throws SystemException if a system exception occurred
2373             */
2374            @Override
2375            public List<DDMStructure> findByGroupId(long[] groupIds, int start, int end)
2376                    throws SystemException {
2377                    return findByGroupId(groupIds, start, end, null);
2378            }
2379    
2380            /**
2381             * Returns an ordered range of all the d d m structures where groupId = any &#63;.
2382             *
2383             * <p>
2384             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portlet.dynamicdatamapping.model.impl.DDMStructureModelImpl}. 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.
2385             * </p>
2386             *
2387             * @param groupIds the group IDs
2388             * @param start the lower bound of the range of d d m structures
2389             * @param end the upper bound of the range of d d m structures (not inclusive)
2390             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
2391             * @return the ordered range of matching d d m structures
2392             * @throws SystemException if a system exception occurred
2393             */
2394            @Override
2395            public List<DDMStructure> findByGroupId(long[] groupIds, int start,
2396                    int end, OrderByComparator orderByComparator) throws SystemException {
2397                    if ((groupIds != null) && (groupIds.length == 1)) {
2398                            return findByGroupId(groupIds[0], start, end, orderByComparator);
2399                    }
2400    
2401                    boolean pagination = true;
2402                    Object[] finderArgs = null;
2403    
2404                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
2405                                    (orderByComparator == null)) {
2406                            pagination = false;
2407                            finderArgs = new Object[] { StringUtil.merge(groupIds) };
2408                    }
2409                    else {
2410                            finderArgs = new Object[] {
2411                                            StringUtil.merge(groupIds),
2412                                            
2413                                            start, end, orderByComparator
2414                                    };
2415                    }
2416    
2417                    List<DDMStructure> list = (List<DDMStructure>)FinderCacheUtil.getResult(FINDER_PATH_WITH_PAGINATION_FIND_BY_GROUPID,
2418                                    finderArgs, this);
2419    
2420                    if ((list != null) && !list.isEmpty()) {
2421                            for (DDMStructure ddmStructure : list) {
2422                                    if (!ArrayUtil.contains(groupIds, ddmStructure.getGroupId())) {
2423                                            list = null;
2424    
2425                                            break;
2426                                    }
2427                            }
2428                    }
2429    
2430                    if (list == null) {
2431                            StringBundler query = new StringBundler();
2432    
2433                            query.append(_SQL_SELECT_DDMSTRUCTURE_WHERE);
2434    
2435                            boolean conjunctionable = false;
2436    
2437                            if ((groupIds == null) || (groupIds.length > 0)) {
2438                                    if (conjunctionable) {
2439                                            query.append(WHERE_AND);
2440                                    }
2441    
2442                                    query.append(StringPool.OPEN_PARENTHESIS);
2443    
2444                                    for (int i = 0; i < groupIds.length; i++) {
2445                                            query.append(_FINDER_COLUMN_GROUPID_GROUPID_5);
2446    
2447                                            if ((i + 1) < groupIds.length) {
2448                                                    query.append(WHERE_OR);
2449                                            }
2450                                    }
2451    
2452                                    query.append(StringPool.CLOSE_PARENTHESIS);
2453    
2454                                    conjunctionable = true;
2455                            }
2456    
2457                            if (orderByComparator != null) {
2458                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
2459                                            orderByComparator);
2460                            }
2461                            else
2462                             if (pagination) {
2463                                    query.append(DDMStructureModelImpl.ORDER_BY_JPQL);
2464                            }
2465    
2466                            String sql = query.toString();
2467    
2468                            Session session = null;
2469    
2470                            try {
2471                                    session = openSession();
2472    
2473                                    Query q = session.createQuery(sql);
2474    
2475                                    QueryPos qPos = QueryPos.getInstance(q);
2476    
2477                                    if (groupIds != null) {
2478                                            qPos.add(groupIds);
2479                                    }
2480    
2481                                    if (!pagination) {
2482                                            list = (List<DDMStructure>)QueryUtil.list(q, getDialect(),
2483                                                            start, end, false);
2484    
2485                                            Collections.sort(list);
2486    
2487                                            list = new UnmodifiableList<DDMStructure>(list);
2488                                    }
2489                                    else {
2490                                            list = (List<DDMStructure>)QueryUtil.list(q, getDialect(),
2491                                                            start, end);
2492                                    }
2493    
2494                                    cacheResult(list);
2495    
2496                                    FinderCacheUtil.putResult(FINDER_PATH_WITH_PAGINATION_FIND_BY_GROUPID,
2497                                            finderArgs, list);
2498                            }
2499                            catch (Exception e) {
2500                                    FinderCacheUtil.removeResult(FINDER_PATH_WITH_PAGINATION_FIND_BY_GROUPID,
2501                                            finderArgs);
2502    
2503                                    throw processException(e);
2504                            }
2505                            finally {
2506                                    closeSession(session);
2507                            }
2508                    }
2509    
2510                    return list;
2511            }
2512    
2513            /**
2514             * Removes all the d d m structures where groupId = &#63; from the database.
2515             *
2516             * @param groupId the group ID
2517             * @throws SystemException if a system exception occurred
2518             */
2519            @Override
2520            public void removeByGroupId(long groupId) throws SystemException {
2521                    for (DDMStructure ddmStructure : findByGroupId(groupId,
2522                                    QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
2523                            remove(ddmStructure);
2524                    }
2525            }
2526    
2527            /**
2528             * Returns the number of d d m structures where groupId = &#63;.
2529             *
2530             * @param groupId the group ID
2531             * @return the number of matching d d m structures
2532             * @throws SystemException if a system exception occurred
2533             */
2534            @Override
2535            public int countByGroupId(long groupId) throws SystemException {
2536                    FinderPath finderPath = FINDER_PATH_COUNT_BY_GROUPID;
2537    
2538                    Object[] finderArgs = new Object[] { groupId };
2539    
2540                    Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
2541                                    this);
2542    
2543                    if (count == null) {
2544                            StringBundler query = new StringBundler(2);
2545    
2546                            query.append(_SQL_COUNT_DDMSTRUCTURE_WHERE);
2547    
2548                            query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
2549    
2550                            String sql = query.toString();
2551    
2552                            Session session = null;
2553    
2554                            try {
2555                                    session = openSession();
2556    
2557                                    Query q = session.createQuery(sql);
2558    
2559                                    QueryPos qPos = QueryPos.getInstance(q);
2560    
2561                                    qPos.add(groupId);
2562    
2563                                    count = (Long)q.uniqueResult();
2564    
2565                                    FinderCacheUtil.putResult(finderPath, finderArgs, count);
2566                            }
2567                            catch (Exception e) {
2568                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
2569    
2570                                    throw processException(e);
2571                            }
2572                            finally {
2573                                    closeSession(session);
2574                            }
2575                    }
2576    
2577                    return count.intValue();
2578            }
2579    
2580            /**
2581             * Returns the number of d d m structures where groupId = any &#63;.
2582             *
2583             * @param groupIds the group IDs
2584             * @return the number of matching d d m structures
2585             * @throws SystemException if a system exception occurred
2586             */
2587            @Override
2588            public int countByGroupId(long[] groupIds) throws SystemException {
2589                    Object[] finderArgs = new Object[] { StringUtil.merge(groupIds) };
2590    
2591                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_WITH_PAGINATION_COUNT_BY_GROUPID,
2592                                    finderArgs, this);
2593    
2594                    if (count == null) {
2595                            StringBundler query = new StringBundler();
2596    
2597                            query.append(_SQL_COUNT_DDMSTRUCTURE_WHERE);
2598    
2599                            boolean conjunctionable = false;
2600    
2601                            if ((groupIds == null) || (groupIds.length > 0)) {
2602                                    if (conjunctionable) {
2603                                            query.append(WHERE_AND);
2604                                    }
2605    
2606                                    query.append(StringPool.OPEN_PARENTHESIS);
2607    
2608                                    for (int i = 0; i < groupIds.length; i++) {
2609                                            query.append(_FINDER_COLUMN_GROUPID_GROUPID_5);
2610    
2611                                            if ((i + 1) < groupIds.length) {
2612                                                    query.append(WHERE_OR);
2613                                            }
2614                                    }
2615    
2616                                    query.append(StringPool.CLOSE_PARENTHESIS);
2617    
2618                                    conjunctionable = true;
2619                            }
2620    
2621                            String sql = query.toString();
2622    
2623                            Session session = null;
2624    
2625                            try {
2626                                    session = openSession();
2627    
2628                                    Query q = session.createQuery(sql);
2629    
2630                                    QueryPos qPos = QueryPos.getInstance(q);
2631    
2632                                    if (groupIds != null) {
2633                                            qPos.add(groupIds);
2634                                    }
2635    
2636                                    count = (Long)q.uniqueResult();
2637    
2638                                    FinderCacheUtil.putResult(FINDER_PATH_WITH_PAGINATION_COUNT_BY_GROUPID,
2639                                            finderArgs, count);
2640                            }
2641                            catch (Exception e) {
2642                                    FinderCacheUtil.removeResult(FINDER_PATH_WITH_PAGINATION_COUNT_BY_GROUPID,
2643                                            finderArgs);
2644    
2645                                    throw processException(e);
2646                            }
2647                            finally {
2648                                    closeSession(session);
2649                            }
2650                    }
2651    
2652                    return count.intValue();
2653            }
2654    
2655            /**
2656             * Returns the number of d d m structures that the user has permission to view where groupId = &#63;.
2657             *
2658             * @param groupId the group ID
2659             * @return the number of matching d d m structures that the user has permission to view
2660             * @throws SystemException if a system exception occurred
2661             */
2662            @Override
2663            public int filterCountByGroupId(long groupId) throws SystemException {
2664                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
2665                            return countByGroupId(groupId);
2666                    }
2667    
2668                    StringBundler query = new StringBundler(2);
2669    
2670                    query.append(_FILTER_SQL_COUNT_DDMSTRUCTURE_WHERE);
2671    
2672                    query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
2673    
2674                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
2675                                    DDMStructure.class.getName(),
2676                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
2677    
2678                    Session session = null;
2679    
2680                    try {
2681                            session = openSession();
2682    
2683                            SQLQuery q = session.createSQLQuery(sql);
2684    
2685                            q.addScalar(COUNT_COLUMN_NAME,
2686                                    com.liferay.portal.kernel.dao.orm.Type.LONG);
2687    
2688                            QueryPos qPos = QueryPos.getInstance(q);
2689    
2690                            qPos.add(groupId);
2691    
2692                            Long count = (Long)q.uniqueResult();
2693    
2694                            return count.intValue();
2695                    }
2696                    catch (Exception e) {
2697                            throw processException(e);
2698                    }
2699                    finally {
2700                            closeSession(session);
2701                    }
2702            }
2703    
2704            /**
2705             * Returns the number of d d m structures that the user has permission to view where groupId = any &#63;.
2706             *
2707             * @param groupIds the group IDs
2708             * @return the number of matching d d m structures that the user has permission to view
2709             * @throws SystemException if a system exception occurred
2710             */
2711            @Override
2712            public int filterCountByGroupId(long[] groupIds) throws SystemException {
2713                    if (!InlineSQLHelperUtil.isEnabled(groupIds)) {
2714                            return countByGroupId(groupIds);
2715                    }
2716    
2717                    StringBundler query = new StringBundler();
2718    
2719                    query.append(_FILTER_SQL_COUNT_DDMSTRUCTURE_WHERE);
2720    
2721                    boolean conjunctionable = false;
2722    
2723                    if ((groupIds == null) || (groupIds.length > 0)) {
2724                            if (conjunctionable) {
2725                                    query.append(WHERE_AND);
2726                            }
2727    
2728                            query.append(StringPool.OPEN_PARENTHESIS);
2729    
2730                            for (int i = 0; i < groupIds.length; i++) {
2731                                    query.append(_FINDER_COLUMN_GROUPID_GROUPID_5);
2732    
2733                                    if ((i + 1) < groupIds.length) {
2734                                            query.append(WHERE_OR);
2735                                    }
2736                            }
2737    
2738                            query.append(StringPool.CLOSE_PARENTHESIS);
2739    
2740                            conjunctionable = true;
2741                    }
2742    
2743                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
2744                                    DDMStructure.class.getName(),
2745                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupIds);
2746    
2747                    Session session = null;
2748    
2749                    try {
2750                            session = openSession();
2751    
2752                            SQLQuery q = session.createSQLQuery(sql);
2753    
2754                            q.addScalar(COUNT_COLUMN_NAME,
2755                                    com.liferay.portal.kernel.dao.orm.Type.LONG);
2756    
2757                            QueryPos qPos = QueryPos.getInstance(q);
2758    
2759                            if (groupIds != null) {
2760                                    qPos.add(groupIds);
2761                            }
2762    
2763                            Long count = (Long)q.uniqueResult();
2764    
2765                            return count.intValue();
2766                    }
2767                    catch (Exception e) {
2768                            throw processException(e);
2769                    }
2770                    finally {
2771                            closeSession(session);
2772                    }
2773            }
2774    
2775            private static final String _FINDER_COLUMN_GROUPID_GROUPID_2 = "ddmStructure.groupId = ?";
2776            private static final String _FINDER_COLUMN_GROUPID_GROUPID_5 = "(" +
2777                    removeConjunction(_FINDER_COLUMN_GROUPID_GROUPID_2) + ")";
2778            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_PARENTSTRUCTUREID =
2779                    new FinderPath(DDMStructureModelImpl.ENTITY_CACHE_ENABLED,
2780                            DDMStructureModelImpl.FINDER_CACHE_ENABLED, DDMStructureImpl.class,
2781                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByParentStructureId",
2782                            new String[] {
2783                                    Long.class.getName(),
2784                                    
2785                            Integer.class.getName(), Integer.class.getName(),
2786                                    OrderByComparator.class.getName()
2787                            });
2788            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_PARENTSTRUCTUREID =
2789                    new FinderPath(DDMStructureModelImpl.ENTITY_CACHE_ENABLED,
2790                            DDMStructureModelImpl.FINDER_CACHE_ENABLED, DDMStructureImpl.class,
2791                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION,
2792                            "findByParentStructureId", new String[] { Long.class.getName() },
2793                            DDMStructureModelImpl.PARENTSTRUCTUREID_COLUMN_BITMASK);
2794            public static final FinderPath FINDER_PATH_COUNT_BY_PARENTSTRUCTUREID = new FinderPath(DDMStructureModelImpl.ENTITY_CACHE_ENABLED,
2795                            DDMStructureModelImpl.FINDER_CACHE_ENABLED, Long.class,
2796                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION,
2797                            "countByParentStructureId", new String[] { Long.class.getName() });
2798    
2799            /**
2800             * Returns all the d d m structures where parentStructureId = &#63;.
2801             *
2802             * @param parentStructureId the parent structure ID
2803             * @return the matching d d m structures
2804             * @throws SystemException if a system exception occurred
2805             */
2806            @Override
2807            public List<DDMStructure> findByParentStructureId(long parentStructureId)
2808                    throws SystemException {
2809                    return findByParentStructureId(parentStructureId, QueryUtil.ALL_POS,
2810                            QueryUtil.ALL_POS, null);
2811            }
2812    
2813            /**
2814             * Returns a range of all the d d m structures where parentStructureId = &#63;.
2815             *
2816             * <p>
2817             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portlet.dynamicdatamapping.model.impl.DDMStructureModelImpl}. 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.
2818             * </p>
2819             *
2820             * @param parentStructureId the parent structure ID
2821             * @param start the lower bound of the range of d d m structures
2822             * @param end the upper bound of the range of d d m structures (not inclusive)
2823             * @return the range of matching d d m structures
2824             * @throws SystemException if a system exception occurred
2825             */
2826            @Override
2827            public List<DDMStructure> findByParentStructureId(long parentStructureId,
2828                    int start, int end) throws SystemException {
2829                    return findByParentStructureId(parentStructureId, start, end, null);
2830            }
2831    
2832            /**
2833             * Returns an ordered range of all the d d m structures where parentStructureId = &#63;.
2834             *
2835             * <p>
2836             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portlet.dynamicdatamapping.model.impl.DDMStructureModelImpl}. 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.
2837             * </p>
2838             *
2839             * @param parentStructureId the parent structure ID
2840             * @param start the lower bound of the range of d d m structures
2841             * @param end the upper bound of the range of d d m structures (not inclusive)
2842             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
2843             * @return the ordered range of matching d d m structures
2844             * @throws SystemException if a system exception occurred
2845             */
2846            @Override
2847            public List<DDMStructure> findByParentStructureId(long parentStructureId,
2848                    int start, int end, OrderByComparator orderByComparator)
2849                    throws SystemException {
2850                    boolean pagination = true;
2851                    FinderPath finderPath = null;
2852                    Object[] finderArgs = null;
2853    
2854                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
2855                                    (orderByComparator == null)) {
2856                            pagination = false;
2857                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_PARENTSTRUCTUREID;
2858                            finderArgs = new Object[] { parentStructureId };
2859                    }
2860                    else {
2861                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_PARENTSTRUCTUREID;
2862                            finderArgs = new Object[] {
2863                                            parentStructureId,
2864                                            
2865                                            start, end, orderByComparator
2866                                    };
2867                    }
2868    
2869                    List<DDMStructure> list = (List<DDMStructure>)FinderCacheUtil.getResult(finderPath,
2870                                    finderArgs, this);
2871    
2872                    if ((list != null) && !list.isEmpty()) {
2873                            for (DDMStructure ddmStructure : list) {
2874                                    if ((parentStructureId != ddmStructure.getParentStructureId())) {
2875                                            list = null;
2876    
2877                                            break;
2878                                    }
2879                            }
2880                    }
2881    
2882                    if (list == null) {
2883                            StringBundler query = null;
2884    
2885                            if (orderByComparator != null) {
2886                                    query = new StringBundler(3 +
2887                                                    (orderByComparator.getOrderByFields().length * 3));
2888                            }
2889                            else {
2890                                    query = new StringBundler(3);
2891                            }
2892    
2893                            query.append(_SQL_SELECT_DDMSTRUCTURE_WHERE);
2894    
2895                            query.append(_FINDER_COLUMN_PARENTSTRUCTUREID_PARENTSTRUCTUREID_2);
2896    
2897                            if (orderByComparator != null) {
2898                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
2899                                            orderByComparator);
2900                            }
2901                            else
2902                             if (pagination) {
2903                                    query.append(DDMStructureModelImpl.ORDER_BY_JPQL);
2904                            }
2905    
2906                            String sql = query.toString();
2907    
2908                            Session session = null;
2909    
2910                            try {
2911                                    session = openSession();
2912    
2913                                    Query q = session.createQuery(sql);
2914    
2915                                    QueryPos qPos = QueryPos.getInstance(q);
2916    
2917                                    qPos.add(parentStructureId);
2918    
2919                                    if (!pagination) {
2920                                            list = (List<DDMStructure>)QueryUtil.list(q, getDialect(),
2921                                                            start, end, false);
2922    
2923                                            Collections.sort(list);
2924    
2925                                            list = new UnmodifiableList<DDMStructure>(list);
2926                                    }
2927                                    else {
2928                                            list = (List<DDMStructure>)QueryUtil.list(q, getDialect(),
2929                                                            start, end);
2930                                    }
2931    
2932                                    cacheResult(list);
2933    
2934                                    FinderCacheUtil.putResult(finderPath, finderArgs, list);
2935                            }
2936                            catch (Exception e) {
2937                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
2938    
2939                                    throw processException(e);
2940                            }
2941                            finally {
2942                                    closeSession(session);
2943                            }
2944                    }
2945    
2946                    return list;
2947            }
2948    
2949            /**
2950             * Returns the first d d m structure in the ordered set where parentStructureId = &#63;.
2951             *
2952             * @param parentStructureId the parent structure ID
2953             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
2954             * @return the first matching d d m structure
2955             * @throws com.liferay.portlet.dynamicdatamapping.NoSuchStructureException if a matching d d m structure could not be found
2956             * @throws SystemException if a system exception occurred
2957             */
2958            @Override
2959            public DDMStructure findByParentStructureId_First(long parentStructureId,
2960                    OrderByComparator orderByComparator)
2961                    throws NoSuchStructureException, SystemException {
2962                    DDMStructure ddmStructure = fetchByParentStructureId_First(parentStructureId,
2963                                    orderByComparator);
2964    
2965                    if (ddmStructure != null) {
2966                            return ddmStructure;
2967                    }
2968    
2969                    StringBundler msg = new StringBundler(4);
2970    
2971                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
2972    
2973                    msg.append("parentStructureId=");
2974                    msg.append(parentStructureId);
2975    
2976                    msg.append(StringPool.CLOSE_CURLY_BRACE);
2977    
2978                    throw new NoSuchStructureException(msg.toString());
2979            }
2980    
2981            /**
2982             * Returns the first d d m structure in the ordered set where parentStructureId = &#63;.
2983             *
2984             * @param parentStructureId the parent structure ID
2985             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
2986             * @return the first matching d d m structure, or <code>null</code> if a matching d d m structure could not be found
2987             * @throws SystemException if a system exception occurred
2988             */
2989            @Override
2990            public DDMStructure fetchByParentStructureId_First(long parentStructureId,
2991                    OrderByComparator orderByComparator) throws SystemException {
2992                    List<DDMStructure> list = findByParentStructureId(parentStructureId, 0,
2993                                    1, orderByComparator);
2994    
2995                    if (!list.isEmpty()) {
2996                            return list.get(0);
2997                    }
2998    
2999                    return null;
3000            }
3001    
3002            /**
3003             * Returns the last d d m structure in the ordered set where parentStructureId = &#63;.
3004             *
3005             * @param parentStructureId the parent structure ID
3006             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
3007             * @return the last matching d d m structure
3008             * @throws com.liferay.portlet.dynamicdatamapping.NoSuchStructureException if a matching d d m structure could not be found
3009             * @throws SystemException if a system exception occurred
3010             */
3011            @Override
3012            public DDMStructure findByParentStructureId_Last(long parentStructureId,
3013                    OrderByComparator orderByComparator)
3014                    throws NoSuchStructureException, SystemException {
3015                    DDMStructure ddmStructure = fetchByParentStructureId_Last(parentStructureId,
3016                                    orderByComparator);
3017    
3018                    if (ddmStructure != null) {
3019                            return ddmStructure;
3020                    }
3021    
3022                    StringBundler msg = new StringBundler(4);
3023    
3024                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
3025    
3026                    msg.append("parentStructureId=");
3027                    msg.append(parentStructureId);
3028    
3029                    msg.append(StringPool.CLOSE_CURLY_BRACE);
3030    
3031                    throw new NoSuchStructureException(msg.toString());
3032            }
3033    
3034            /**
3035             * Returns the last d d m structure in the ordered set where parentStructureId = &#63;.
3036             *
3037             * @param parentStructureId the parent structure ID
3038             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
3039             * @return the last matching d d m structure, or <code>null</code> if a matching d d m structure could not be found
3040             * @throws SystemException if a system exception occurred
3041             */
3042            @Override
3043            public DDMStructure fetchByParentStructureId_Last(long parentStructureId,
3044                    OrderByComparator orderByComparator) throws SystemException {
3045                    int count = countByParentStructureId(parentStructureId);
3046    
3047                    if (count == 0) {
3048                            return null;
3049                    }
3050    
3051                    List<DDMStructure> list = findByParentStructureId(parentStructureId,
3052                                    count - 1, count, orderByComparator);
3053    
3054                    if (!list.isEmpty()) {
3055                            return list.get(0);
3056                    }
3057    
3058                    return null;
3059            }
3060    
3061            /**
3062             * Returns the d d m structures before and after the current d d m structure in the ordered set where parentStructureId = &#63;.
3063             *
3064             * @param structureId the primary key of the current d d m structure
3065             * @param parentStructureId the parent structure ID
3066             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
3067             * @return the previous, current, and next d d m structure
3068             * @throws com.liferay.portlet.dynamicdatamapping.NoSuchStructureException if a d d m structure with the primary key could not be found
3069             * @throws SystemException if a system exception occurred
3070             */
3071            @Override
3072            public DDMStructure[] findByParentStructureId_PrevAndNext(
3073                    long structureId, long parentStructureId,
3074                    OrderByComparator orderByComparator)
3075                    throws NoSuchStructureException, SystemException {
3076                    DDMStructure ddmStructure = findByPrimaryKey(structureId);
3077    
3078                    Session session = null;
3079    
3080                    try {
3081                            session = openSession();
3082    
3083                            DDMStructure[] array = new DDMStructureImpl[3];
3084    
3085                            array[0] = getByParentStructureId_PrevAndNext(session,
3086                                            ddmStructure, parentStructureId, orderByComparator, true);
3087    
3088                            array[1] = ddmStructure;
3089    
3090                            array[2] = getByParentStructureId_PrevAndNext(session,
3091                                            ddmStructure, parentStructureId, orderByComparator, false);
3092    
3093                            return array;
3094                    }
3095                    catch (Exception e) {
3096                            throw processException(e);
3097                    }
3098                    finally {
3099                            closeSession(session);
3100                    }
3101            }
3102    
3103            protected DDMStructure getByParentStructureId_PrevAndNext(Session session,
3104                    DDMStructure ddmStructure, long parentStructureId,
3105                    OrderByComparator orderByComparator, boolean previous) {
3106                    StringBundler query = null;
3107    
3108                    if (orderByComparator != null) {
3109                            query = new StringBundler(6 +
3110                                            (orderByComparator.getOrderByFields().length * 6));
3111                    }
3112                    else {
3113                            query = new StringBundler(3);
3114                    }
3115    
3116                    query.append(_SQL_SELECT_DDMSTRUCTURE_WHERE);
3117    
3118                    query.append(_FINDER_COLUMN_PARENTSTRUCTUREID_PARENTSTRUCTUREID_2);
3119    
3120                    if (orderByComparator != null) {
3121                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
3122    
3123                            if (orderByConditionFields.length > 0) {
3124                                    query.append(WHERE_AND);
3125                            }
3126    
3127                            for (int i = 0; i < orderByConditionFields.length; i++) {
3128                                    query.append(_ORDER_BY_ENTITY_ALIAS);
3129                                    query.append(orderByConditionFields[i]);
3130    
3131                                    if ((i + 1) < orderByConditionFields.length) {
3132                                            if (orderByComparator.isAscending() ^ previous) {
3133                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
3134                                            }
3135                                            else {
3136                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
3137                                            }
3138                                    }
3139                                    else {
3140                                            if (orderByComparator.isAscending() ^ previous) {
3141                                                    query.append(WHERE_GREATER_THAN);
3142                                            }
3143                                            else {
3144                                                    query.append(WHERE_LESSER_THAN);
3145                                            }
3146                                    }
3147                            }
3148    
3149                            query.append(ORDER_BY_CLAUSE);
3150    
3151                            String[] orderByFields = orderByComparator.getOrderByFields();
3152    
3153                            for (int i = 0; i < orderByFields.length; i++) {
3154                                    query.append(_ORDER_BY_ENTITY_ALIAS);
3155                                    query.append(orderByFields[i]);
3156    
3157                                    if ((i + 1) < orderByFields.length) {
3158                                            if (orderByComparator.isAscending() ^ previous) {
3159                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
3160                                            }
3161                                            else {
3162                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
3163                                            }
3164                                    }
3165                                    else {
3166                                            if (orderByComparator.isAscending() ^ previous) {
3167                                                    query.append(ORDER_BY_ASC);
3168                                            }
3169                                            else {
3170                                                    query.append(ORDER_BY_DESC);
3171                                            }
3172                                    }
3173                            }
3174                    }
3175                    else {
3176                            query.append(DDMStructureModelImpl.ORDER_BY_JPQL);
3177                    }
3178    
3179                    String sql = query.toString();
3180    
3181                    Query q = session.createQuery(sql);
3182    
3183                    q.setFirstResult(0);
3184                    q.setMaxResults(2);
3185    
3186                    QueryPos qPos = QueryPos.getInstance(q);
3187    
3188                    qPos.add(parentStructureId);
3189    
3190                    if (orderByComparator != null) {
3191                            Object[] values = orderByComparator.getOrderByConditionValues(ddmStructure);
3192    
3193                            for (Object value : values) {
3194                                    qPos.add(value);
3195                            }
3196                    }
3197    
3198                    List<DDMStructure> list = q.list();
3199    
3200                    if (list.size() == 2) {
3201                            return list.get(1);
3202                    }
3203                    else {
3204                            return null;
3205                    }
3206            }
3207    
3208            /**
3209             * Removes all the d d m structures where parentStructureId = &#63; from the database.
3210             *
3211             * @param parentStructureId the parent structure ID
3212             * @throws SystemException if a system exception occurred
3213             */
3214            @Override
3215            public void removeByParentStructureId(long parentStructureId)
3216                    throws SystemException {
3217                    for (DDMStructure ddmStructure : findByParentStructureId(
3218                                    parentStructureId, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
3219                            remove(ddmStructure);
3220                    }
3221            }
3222    
3223            /**
3224             * Returns the number of d d m structures where parentStructureId = &#63;.
3225             *
3226             * @param parentStructureId the parent structure ID
3227             * @return the number of matching d d m structures
3228             * @throws SystemException if a system exception occurred
3229             */
3230            @Override
3231            public int countByParentStructureId(long parentStructureId)
3232                    throws SystemException {
3233                    FinderPath finderPath = FINDER_PATH_COUNT_BY_PARENTSTRUCTUREID;
3234    
3235                    Object[] finderArgs = new Object[] { parentStructureId };
3236    
3237                    Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
3238                                    this);
3239    
3240                    if (count == null) {
3241                            StringBundler query = new StringBundler(2);
3242    
3243                            query.append(_SQL_COUNT_DDMSTRUCTURE_WHERE);
3244    
3245                            query.append(_FINDER_COLUMN_PARENTSTRUCTUREID_PARENTSTRUCTUREID_2);
3246    
3247                            String sql = query.toString();
3248    
3249                            Session session = null;
3250    
3251                            try {
3252                                    session = openSession();
3253    
3254                                    Query q = session.createQuery(sql);
3255    
3256                                    QueryPos qPos = QueryPos.getInstance(q);
3257    
3258                                    qPos.add(parentStructureId);
3259    
3260                                    count = (Long)q.uniqueResult();
3261    
3262                                    FinderCacheUtil.putResult(finderPath, finderArgs, count);
3263                            }
3264                            catch (Exception e) {
3265                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
3266    
3267                                    throw processException(e);
3268                            }
3269                            finally {
3270                                    closeSession(session);
3271                            }
3272                    }
3273    
3274                    return count.intValue();
3275            }
3276    
3277            private static final String _FINDER_COLUMN_PARENTSTRUCTUREID_PARENTSTRUCTUREID_2 =
3278                    "ddmStructure.parentStructureId = ?";
3279            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_CLASSNAMEID =
3280                    new FinderPath(DDMStructureModelImpl.ENTITY_CACHE_ENABLED,
3281                            DDMStructureModelImpl.FINDER_CACHE_ENABLED, DDMStructureImpl.class,
3282                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByClassNameId",
3283                            new String[] {
3284                                    Long.class.getName(),
3285                                    
3286                            Integer.class.getName(), Integer.class.getName(),
3287                                    OrderByComparator.class.getName()
3288                            });
3289            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_CLASSNAMEID =
3290                    new FinderPath(DDMStructureModelImpl.ENTITY_CACHE_ENABLED,
3291                            DDMStructureModelImpl.FINDER_CACHE_ENABLED, DDMStructureImpl.class,
3292                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByClassNameId",
3293                            new String[] { Long.class.getName() },
3294                            DDMStructureModelImpl.CLASSNAMEID_COLUMN_BITMASK);
3295            public static final FinderPath FINDER_PATH_COUNT_BY_CLASSNAMEID = new FinderPath(DDMStructureModelImpl.ENTITY_CACHE_ENABLED,
3296                            DDMStructureModelImpl.FINDER_CACHE_ENABLED, Long.class,
3297                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByClassNameId",
3298                            new String[] { Long.class.getName() });
3299    
3300            /**
3301             * Returns all the d d m structures where classNameId = &#63;.
3302             *
3303             * @param classNameId the class name ID
3304             * @return the matching d d m structures
3305             * @throws SystemException if a system exception occurred
3306             */
3307            @Override
3308            public List<DDMStructure> findByClassNameId(long classNameId)
3309                    throws SystemException {
3310                    return findByClassNameId(classNameId, QueryUtil.ALL_POS,
3311                            QueryUtil.ALL_POS, null);
3312            }
3313    
3314            /**
3315             * Returns a range of all the d d m structures where classNameId = &#63;.
3316             *
3317             * <p>
3318             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portlet.dynamicdatamapping.model.impl.DDMStructureModelImpl}. 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.
3319             * </p>
3320             *
3321             * @param classNameId the class name ID
3322             * @param start the lower bound of the range of d d m structures
3323             * @param end the upper bound of the range of d d m structures (not inclusive)
3324             * @return the range of matching d d m structures
3325             * @throws SystemException if a system exception occurred
3326             */
3327            @Override
3328            public List<DDMStructure> findByClassNameId(long classNameId, int start,
3329                    int end) throws SystemException {
3330                    return findByClassNameId(classNameId, start, end, null);
3331            }
3332    
3333            /**
3334             * Returns an ordered range of all the d d m structures where classNameId = &#63;.
3335             *
3336             * <p>
3337             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portlet.dynamicdatamapping.model.impl.DDMStructureModelImpl}. 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.
3338             * </p>
3339             *
3340             * @param classNameId the class name ID
3341             * @param start the lower bound of the range of d d m structures
3342             * @param end the upper bound of the range of d d m structures (not inclusive)
3343             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
3344             * @return the ordered range of matching d d m structures
3345             * @throws SystemException if a system exception occurred
3346             */
3347            @Override
3348            public List<DDMStructure> findByClassNameId(long classNameId, int start,
3349                    int end, OrderByComparator orderByComparator) throws SystemException {
3350                    boolean pagination = true;
3351                    FinderPath finderPath = null;
3352                    Object[] finderArgs = null;
3353    
3354                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
3355                                    (orderByComparator == null)) {
3356                            pagination = false;
3357                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_CLASSNAMEID;
3358                            finderArgs = new Object[] { classNameId };
3359                    }
3360                    else {
3361                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_CLASSNAMEID;
3362                            finderArgs = new Object[] { classNameId, start, end, orderByComparator };
3363                    }
3364    
3365                    List<DDMStructure> list = (List<DDMStructure>)FinderCacheUtil.getResult(finderPath,
3366                                    finderArgs, this);
3367    
3368                    if ((list != null) && !list.isEmpty()) {
3369                            for (DDMStructure ddmStructure : list) {
3370                                    if ((classNameId != ddmStructure.getClassNameId())) {
3371                                            list = null;
3372    
3373                                            break;
3374                                    }
3375                            }
3376                    }
3377    
3378                    if (list == null) {
3379                            StringBundler query = null;
3380    
3381                            if (orderByComparator != null) {
3382                                    query = new StringBundler(3 +
3383                                                    (orderByComparator.getOrderByFields().length * 3));
3384                            }
3385                            else {
3386                                    query = new StringBundler(3);
3387                            }
3388    
3389                            query.append(_SQL_SELECT_DDMSTRUCTURE_WHERE);
3390    
3391                            query.append(_FINDER_COLUMN_CLASSNAMEID_CLASSNAMEID_2);
3392    
3393                            if (orderByComparator != null) {
3394                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
3395                                            orderByComparator);
3396                            }
3397                            else
3398                             if (pagination) {
3399                                    query.append(DDMStructureModelImpl.ORDER_BY_JPQL);
3400                            }
3401    
3402                            String sql = query.toString();
3403    
3404                            Session session = null;
3405    
3406                            try {
3407                                    session = openSession();
3408    
3409                                    Query q = session.createQuery(sql);
3410    
3411                                    QueryPos qPos = QueryPos.getInstance(q);
3412    
3413                                    qPos.add(classNameId);
3414    
3415                                    if (!pagination) {
3416                                            list = (List<DDMStructure>)QueryUtil.list(q, getDialect(),
3417                                                            start, end, false);
3418    
3419                                            Collections.sort(list);
3420    
3421                                            list = new UnmodifiableList<DDMStructure>(list);
3422                                    }
3423                                    else {
3424                                            list = (List<DDMStructure>)QueryUtil.list(q, getDialect(),
3425                                                            start, end);
3426                                    }
3427    
3428                                    cacheResult(list);
3429    
3430                                    FinderCacheUtil.putResult(finderPath, finderArgs, list);
3431                            }
3432                            catch (Exception e) {
3433                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
3434    
3435                                    throw processException(e);
3436                            }
3437                            finally {
3438                                    closeSession(session);
3439                            }
3440                    }
3441    
3442                    return list;
3443            }
3444    
3445            /**
3446             * Returns the first d d m structure in the ordered set where classNameId = &#63;.
3447             *
3448             * @param classNameId the class name ID
3449             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
3450             * @return the first matching d d m structure
3451             * @throws com.liferay.portlet.dynamicdatamapping.NoSuchStructureException if a matching d d m structure could not be found
3452             * @throws SystemException if a system exception occurred
3453             */
3454            @Override
3455            public DDMStructure findByClassNameId_First(long classNameId,
3456                    OrderByComparator orderByComparator)
3457                    throws NoSuchStructureException, SystemException {
3458                    DDMStructure ddmStructure = fetchByClassNameId_First(classNameId,
3459                                    orderByComparator);
3460    
3461                    if (ddmStructure != null) {
3462                            return ddmStructure;
3463                    }
3464    
3465                    StringBundler msg = new StringBundler(4);
3466    
3467                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
3468    
3469                    msg.append("classNameId=");
3470                    msg.append(classNameId);
3471    
3472                    msg.append(StringPool.CLOSE_CURLY_BRACE);
3473    
3474                    throw new NoSuchStructureException(msg.toString());
3475            }
3476    
3477            /**
3478             * Returns the first d d m structure in the ordered set where classNameId = &#63;.
3479             *
3480             * @param classNameId the class name ID
3481             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
3482             * @return the first matching d d m structure, or <code>null</code> if a matching d d m structure could not be found
3483             * @throws SystemException if a system exception occurred
3484             */
3485            @Override
3486            public DDMStructure fetchByClassNameId_First(long classNameId,
3487                    OrderByComparator orderByComparator) throws SystemException {
3488                    List<DDMStructure> list = findByClassNameId(classNameId, 0, 1,
3489                                    orderByComparator);
3490    
3491                    if (!list.isEmpty()) {
3492                            return list.get(0);
3493                    }
3494    
3495                    return null;
3496            }
3497    
3498            /**
3499             * Returns the last d d m structure in the ordered set where classNameId = &#63;.
3500             *
3501             * @param classNameId the class name ID
3502             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
3503             * @return the last matching d d m structure
3504             * @throws com.liferay.portlet.dynamicdatamapping.NoSuchStructureException if a matching d d m structure could not be found
3505             * @throws SystemException if a system exception occurred
3506             */
3507            @Override
3508            public DDMStructure findByClassNameId_Last(long classNameId,
3509                    OrderByComparator orderByComparator)
3510                    throws NoSuchStructureException, SystemException {
3511                    DDMStructure ddmStructure = fetchByClassNameId_Last(classNameId,
3512                                    orderByComparator);
3513    
3514                    if (ddmStructure != null) {
3515                            return ddmStructure;
3516                    }
3517    
3518                    StringBundler msg = new StringBundler(4);
3519    
3520                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
3521    
3522                    msg.append("classNameId=");
3523                    msg.append(classNameId);
3524    
3525                    msg.append(StringPool.CLOSE_CURLY_BRACE);
3526    
3527                    throw new NoSuchStructureException(msg.toString());
3528            }
3529    
3530            /**
3531             * Returns the last d d m structure in the ordered set where classNameId = &#63;.
3532             *
3533             * @param classNameId the class name ID
3534             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
3535             * @return the last matching d d m structure, or <code>null</code> if a matching d d m structure could not be found
3536             * @throws SystemException if a system exception occurred
3537             */
3538            @Override
3539            public DDMStructure fetchByClassNameId_Last(long classNameId,
3540                    OrderByComparator orderByComparator) throws SystemException {
3541                    int count = countByClassNameId(classNameId);
3542    
3543                    if (count == 0) {
3544                            return null;
3545                    }
3546    
3547                    List<DDMStructure> list = findByClassNameId(classNameId, count - 1,
3548                                    count, orderByComparator);
3549    
3550                    if (!list.isEmpty()) {
3551                            return list.get(0);
3552                    }
3553    
3554                    return null;
3555            }
3556    
3557            /**
3558             * Returns the d d m structures before and after the current d d m structure in the ordered set where classNameId = &#63;.
3559             *
3560             * @param structureId the primary key of the current d d m structure
3561             * @param classNameId the class name ID
3562             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
3563             * @return the previous, current, and next d d m structure
3564             * @throws com.liferay.portlet.dynamicdatamapping.NoSuchStructureException if a d d m structure with the primary key could not be found
3565             * @throws SystemException if a system exception occurred
3566             */
3567            @Override
3568            public DDMStructure[] findByClassNameId_PrevAndNext(long structureId,
3569                    long classNameId, OrderByComparator orderByComparator)
3570                    throws NoSuchStructureException, SystemException {
3571                    DDMStructure ddmStructure = findByPrimaryKey(structureId);
3572    
3573                    Session session = null;
3574    
3575                    try {
3576                            session = openSession();
3577    
3578                            DDMStructure[] array = new DDMStructureImpl[3];
3579    
3580                            array[0] = getByClassNameId_PrevAndNext(session, ddmStructure,
3581                                            classNameId, orderByComparator, true);
3582    
3583                            array[1] = ddmStructure;
3584    
3585                            array[2] = getByClassNameId_PrevAndNext(session, ddmStructure,
3586                                            classNameId, orderByComparator, false);
3587    
3588                            return array;
3589                    }
3590                    catch (Exception e) {
3591                            throw processException(e);
3592                    }
3593                    finally {
3594                            closeSession(session);
3595                    }
3596            }
3597    
3598            protected DDMStructure getByClassNameId_PrevAndNext(Session session,
3599                    DDMStructure ddmStructure, long classNameId,
3600                    OrderByComparator orderByComparator, boolean previous) {
3601                    StringBundler query = null;
3602    
3603                    if (orderByComparator != null) {
3604                            query = new StringBundler(6 +
3605                                            (orderByComparator.getOrderByFields().length * 6));
3606                    }
3607                    else {
3608                            query = new StringBundler(3);
3609                    }
3610    
3611                    query.append(_SQL_SELECT_DDMSTRUCTURE_WHERE);
3612    
3613                    query.append(_FINDER_COLUMN_CLASSNAMEID_CLASSNAMEID_2);
3614    
3615                    if (orderByComparator != null) {
3616                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
3617    
3618                            if (orderByConditionFields.length > 0) {
3619                                    query.append(WHERE_AND);
3620                            }
3621    
3622                            for (int i = 0; i < orderByConditionFields.length; i++) {
3623                                    query.append(_ORDER_BY_ENTITY_ALIAS);
3624                                    query.append(orderByConditionFields[i]);
3625    
3626                                    if ((i + 1) < orderByConditionFields.length) {
3627                                            if (orderByComparator.isAscending() ^ previous) {
3628                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
3629                                            }
3630                                            else {
3631                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
3632                                            }
3633                                    }
3634                                    else {
3635                                            if (orderByComparator.isAscending() ^ previous) {
3636                                                    query.append(WHERE_GREATER_THAN);
3637                                            }
3638                                            else {
3639                                                    query.append(WHERE_LESSER_THAN);
3640                                            }
3641                                    }
3642                            }
3643    
3644                            query.append(ORDER_BY_CLAUSE);
3645    
3646                            String[] orderByFields = orderByComparator.getOrderByFields();
3647    
3648                            for (int i = 0; i < orderByFields.length; i++) {
3649                                    query.append(_ORDER_BY_ENTITY_ALIAS);
3650                                    query.append(orderByFields[i]);
3651    
3652                                    if ((i + 1) < orderByFields.length) {
3653                                            if (orderByComparator.isAscending() ^ previous) {
3654                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
3655                                            }
3656                                            else {
3657                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
3658                                            }
3659                                    }
3660                                    else {
3661                                            if (orderByComparator.isAscending() ^ previous) {
3662                                                    query.append(ORDER_BY_ASC);
3663                                            }
3664                                            else {
3665                                                    query.append(ORDER_BY_DESC);
3666                                            }
3667                                    }
3668                            }
3669                    }
3670                    else {
3671                            query.append(DDMStructureModelImpl.ORDER_BY_JPQL);
3672                    }
3673    
3674                    String sql = query.toString();
3675    
3676                    Query q = session.createQuery(sql);
3677    
3678                    q.setFirstResult(0);
3679                    q.setMaxResults(2);
3680    
3681                    QueryPos qPos = QueryPos.getInstance(q);
3682    
3683                    qPos.add(classNameId);
3684    
3685                    if (orderByComparator != null) {
3686                            Object[] values = orderByComparator.getOrderByConditionValues(ddmStructure);
3687    
3688                            for (Object value : values) {
3689                                    qPos.add(value);
3690                            }
3691                    }
3692    
3693                    List<DDMStructure> list = q.list();
3694    
3695                    if (list.size() == 2) {
3696                            return list.get(1);
3697                    }
3698                    else {
3699                            return null;
3700                    }
3701            }
3702    
3703            /**
3704             * Removes all the d d m structures where classNameId = &#63; from the database.
3705             *
3706             * @param classNameId the class name ID
3707             * @throws SystemException if a system exception occurred
3708             */
3709            @Override
3710            public void removeByClassNameId(long classNameId) throws SystemException {
3711                    for (DDMStructure ddmStructure : findByClassNameId(classNameId,
3712                                    QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
3713                            remove(ddmStructure);
3714                    }
3715            }
3716    
3717            /**
3718             * Returns the number of d d m structures where classNameId = &#63;.
3719             *
3720             * @param classNameId the class name ID
3721             * @return the number of matching d d m structures
3722             * @throws SystemException if a system exception occurred
3723             */
3724            @Override
3725            public int countByClassNameId(long classNameId) throws SystemException {
3726                    FinderPath finderPath = FINDER_PATH_COUNT_BY_CLASSNAMEID;
3727    
3728                    Object[] finderArgs = new Object[] { classNameId };
3729    
3730                    Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
3731                                    this);
3732    
3733                    if (count == null) {
3734                            StringBundler query = new StringBundler(2);
3735    
3736                            query.append(_SQL_COUNT_DDMSTRUCTURE_WHERE);
3737    
3738                            query.append(_FINDER_COLUMN_CLASSNAMEID_CLASSNAMEID_2);
3739    
3740                            String sql = query.toString();
3741    
3742                            Session session = null;
3743    
3744                            try {
3745                                    session = openSession();
3746    
3747                                    Query q = session.createQuery(sql);
3748    
3749                                    QueryPos qPos = QueryPos.getInstance(q);
3750    
3751                                    qPos.add(classNameId);
3752    
3753                                    count = (Long)q.uniqueResult();
3754    
3755                                    FinderCacheUtil.putResult(finderPath, finderArgs, count);
3756                            }
3757                            catch (Exception e) {
3758                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
3759    
3760                                    throw processException(e);
3761                            }
3762                            finally {
3763                                    closeSession(session);
3764                            }
3765                    }
3766    
3767                    return count.intValue();
3768            }
3769    
3770            private static final String _FINDER_COLUMN_CLASSNAMEID_CLASSNAMEID_2 = "ddmStructure.classNameId = ?";
3771            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_STRUCTUREKEY =
3772                    new FinderPath(DDMStructureModelImpl.ENTITY_CACHE_ENABLED,
3773                            DDMStructureModelImpl.FINDER_CACHE_ENABLED, DDMStructureImpl.class,
3774                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByStructureKey",
3775                            new String[] {
3776                                    String.class.getName(),
3777                                    
3778                            Integer.class.getName(), Integer.class.getName(),
3779                                    OrderByComparator.class.getName()
3780                            });
3781            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_STRUCTUREKEY =
3782                    new FinderPath(DDMStructureModelImpl.ENTITY_CACHE_ENABLED,
3783                            DDMStructureModelImpl.FINDER_CACHE_ENABLED, DDMStructureImpl.class,
3784                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByStructureKey",
3785                            new String[] { String.class.getName() },
3786                            DDMStructureModelImpl.STRUCTUREKEY_COLUMN_BITMASK);
3787            public static final FinderPath FINDER_PATH_COUNT_BY_STRUCTUREKEY = new FinderPath(DDMStructureModelImpl.ENTITY_CACHE_ENABLED,
3788                            DDMStructureModelImpl.FINDER_CACHE_ENABLED, Long.class,
3789                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByStructureKey",
3790                            new String[] { String.class.getName() });
3791    
3792            /**
3793             * Returns all the d d m structures where structureKey = &#63;.
3794             *
3795             * @param structureKey the structure key
3796             * @return the matching d d m structures
3797             * @throws SystemException if a system exception occurred
3798             */
3799            @Override
3800            public List<DDMStructure> findByStructureKey(String structureKey)
3801                    throws SystemException {
3802                    return findByStructureKey(structureKey, QueryUtil.ALL_POS,
3803                            QueryUtil.ALL_POS, null);
3804            }
3805    
3806            /**
3807             * Returns a range of all the d d m structures where structureKey = &#63;.
3808             *
3809             * <p>
3810             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portlet.dynamicdatamapping.model.impl.DDMStructureModelImpl}. 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.
3811             * </p>
3812             *
3813             * @param structureKey the structure key
3814             * @param start the lower bound of the range of d d m structures
3815             * @param end the upper bound of the range of d d m structures (not inclusive)
3816             * @return the range of matching d d m structures
3817             * @throws SystemException if a system exception occurred
3818             */
3819            @Override
3820            public List<DDMStructure> findByStructureKey(String structureKey,
3821                    int start, int end) throws SystemException {
3822                    return findByStructureKey(structureKey, start, end, null);
3823            }
3824    
3825            /**
3826             * Returns an ordered range of all the d d m structures where structureKey = &#63;.
3827             *
3828             * <p>
3829             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portlet.dynamicdatamapping.model.impl.DDMStructureModelImpl}. 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.
3830             * </p>
3831             *
3832             * @param structureKey the structure key
3833             * @param start the lower bound of the range of d d m structures
3834             * @param end the upper bound of the range of d d m structures (not inclusive)
3835             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
3836             * @return the ordered range of matching d d m structures
3837             * @throws SystemException if a system exception occurred
3838             */
3839            @Override
3840            public List<DDMStructure> findByStructureKey(String structureKey,
3841                    int start, int end, OrderByComparator orderByComparator)
3842                    throws SystemException {
3843                    boolean pagination = true;
3844                    FinderPath finderPath = null;
3845                    Object[] finderArgs = null;
3846    
3847                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
3848                                    (orderByComparator == null)) {
3849                            pagination = false;
3850                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_STRUCTUREKEY;
3851                            finderArgs = new Object[] { structureKey };
3852                    }
3853                    else {
3854                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_STRUCTUREKEY;
3855                            finderArgs = new Object[] {
3856                                            structureKey,
3857                                            
3858                                            start, end, orderByComparator
3859                                    };
3860                    }
3861    
3862                    List<DDMStructure> list = (List<DDMStructure>)FinderCacheUtil.getResult(finderPath,
3863                                    finderArgs, this);
3864    
3865                    if ((list != null) && !list.isEmpty()) {
3866                            for (DDMStructure ddmStructure : list) {
3867                                    if (!Validator.equals(structureKey,
3868                                                            ddmStructure.getStructureKey())) {
3869                                            list = null;
3870    
3871                                            break;
3872                                    }
3873                            }
3874                    }
3875    
3876                    if (list == null) {
3877                            StringBundler query = null;
3878    
3879                            if (orderByComparator != null) {
3880                                    query = new StringBundler(3 +
3881                                                    (orderByComparator.getOrderByFields().length * 3));
3882                            }
3883                            else {
3884                                    query = new StringBundler(3);
3885                            }
3886    
3887                            query.append(_SQL_SELECT_DDMSTRUCTURE_WHERE);
3888    
3889                            boolean bindStructureKey = false;
3890    
3891                            if (structureKey == null) {
3892                                    query.append(_FINDER_COLUMN_STRUCTUREKEY_STRUCTUREKEY_1);
3893                            }
3894                            else if (structureKey.equals(StringPool.BLANK)) {
3895                                    query.append(_FINDER_COLUMN_STRUCTUREKEY_STRUCTUREKEY_3);
3896                            }
3897                            else {
3898                                    bindStructureKey = true;
3899    
3900                                    query.append(_FINDER_COLUMN_STRUCTUREKEY_STRUCTUREKEY_2);
3901                            }
3902    
3903                            if (orderByComparator != null) {
3904                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
3905                                            orderByComparator);
3906                            }
3907                            else
3908                             if (pagination) {
3909                                    query.append(DDMStructureModelImpl.ORDER_BY_JPQL);
3910                            }
3911    
3912                            String sql = query.toString();
3913    
3914                            Session session = null;
3915    
3916                            try {
3917                                    session = openSession();
3918    
3919                                    Query q = session.createQuery(sql);
3920    
3921                                    QueryPos qPos = QueryPos.getInstance(q);
3922    
3923                                    if (bindStructureKey) {
3924                                            qPos.add(structureKey);
3925                                    }
3926    
3927                                    if (!pagination) {
3928                                            list = (List<DDMStructure>)QueryUtil.list(q, getDialect(),
3929                                                            start, end, false);
3930    
3931                                            Collections.sort(list);
3932    
3933                                            list = new UnmodifiableList<DDMStructure>(list);
3934                                    }
3935                                    else {
3936                                            list = (List<DDMStructure>)QueryUtil.list(q, getDialect(),
3937                                                            start, end);
3938                                    }
3939    
3940                                    cacheResult(list);
3941    
3942                                    FinderCacheUtil.putResult(finderPath, finderArgs, list);
3943                            }
3944                            catch (Exception e) {
3945                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
3946    
3947                                    throw processException(e);
3948                            }
3949                            finally {
3950                                    closeSession(session);
3951                            }
3952                    }
3953    
3954                    return list;
3955            }
3956    
3957            /**
3958             * Returns the first d d m structure in the ordered set where structureKey = &#63;.
3959             *
3960             * @param structureKey the structure key
3961             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
3962             * @return the first matching d d m structure
3963             * @throws com.liferay.portlet.dynamicdatamapping.NoSuchStructureException if a matching d d m structure could not be found
3964             * @throws SystemException if a system exception occurred
3965             */
3966            @Override
3967            public DDMStructure findByStructureKey_First(String structureKey,
3968                    OrderByComparator orderByComparator)
3969                    throws NoSuchStructureException, SystemException {
3970                    DDMStructure ddmStructure = fetchByStructureKey_First(structureKey,
3971                                    orderByComparator);
3972    
3973                    if (ddmStructure != null) {
3974                            return ddmStructure;
3975                    }
3976    
3977                    StringBundler msg = new StringBundler(4);
3978    
3979                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
3980    
3981                    msg.append("structureKey=");
3982                    msg.append(structureKey);
3983    
3984                    msg.append(StringPool.CLOSE_CURLY_BRACE);
3985    
3986                    throw new NoSuchStructureException(msg.toString());
3987            }
3988    
3989            /**
3990             * Returns the first d d m structure in the ordered set where structureKey = &#63;.
3991             *
3992             * @param structureKey the structure key
3993             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
3994             * @return the first matching d d m structure, or <code>null</code> if a matching d d m structure could not be found
3995             * @throws SystemException if a system exception occurred
3996             */
3997            @Override
3998            public DDMStructure fetchByStructureKey_First(String structureKey,
3999                    OrderByComparator orderByComparator) throws SystemException {
4000                    List<DDMStructure> list = findByStructureKey(structureKey, 0, 1,
4001                                    orderByComparator);
4002    
4003                    if (!list.isEmpty()) {
4004                            return list.get(0);
4005                    }
4006    
4007                    return null;
4008            }
4009    
4010            /**
4011             * Returns the last d d m structure in the ordered set where structureKey = &#63;.
4012             *
4013             * @param structureKey the structure key
4014             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
4015             * @return the last matching d d m structure
4016             * @throws com.liferay.portlet.dynamicdatamapping.NoSuchStructureException if a matching d d m structure could not be found
4017             * @throws SystemException if a system exception occurred
4018             */
4019            @Override
4020            public DDMStructure findByStructureKey_Last(String structureKey,
4021                    OrderByComparator orderByComparator)
4022                    throws NoSuchStructureException, SystemException {
4023                    DDMStructure ddmStructure = fetchByStructureKey_Last(structureKey,
4024                                    orderByComparator);
4025    
4026                    if (ddmStructure != null) {
4027                            return ddmStructure;
4028                    }
4029    
4030                    StringBundler msg = new StringBundler(4);
4031    
4032                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
4033    
4034                    msg.append("structureKey=");
4035                    msg.append(structureKey);
4036    
4037                    msg.append(StringPool.CLOSE_CURLY_BRACE);
4038    
4039                    throw new NoSuchStructureException(msg.toString());
4040            }
4041    
4042            /**
4043             * Returns the last d d m structure in the ordered set where structureKey = &#63;.
4044             *
4045             * @param structureKey the structure key
4046             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
4047             * @return the last matching d d m structure, or <code>null</code> if a matching d d m structure could not be found
4048             * @throws SystemException if a system exception occurred
4049             */
4050            @Override
4051            public DDMStructure fetchByStructureKey_Last(String structureKey,
4052                    OrderByComparator orderByComparator) throws SystemException {
4053                    int count = countByStructureKey(structureKey);
4054    
4055                    if (count == 0) {
4056                            return null;
4057                    }
4058    
4059                    List<DDMStructure> list = findByStructureKey(structureKey, count - 1,
4060                                    count, orderByComparator);
4061    
4062                    if (!list.isEmpty()) {
4063                            return list.get(0);
4064                    }
4065    
4066                    return null;
4067            }
4068    
4069            /**
4070             * Returns the d d m structures before and after the current d d m structure in the ordered set where structureKey = &#63;.
4071             *
4072             * @param structureId the primary key of the current d d m structure
4073             * @param structureKey the structure key
4074             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
4075             * @return the previous, current, and next d d m structure
4076             * @throws com.liferay.portlet.dynamicdatamapping.NoSuchStructureException if a d d m structure with the primary key could not be found
4077             * @throws SystemException if a system exception occurred
4078             */
4079            @Override
4080            public DDMStructure[] findByStructureKey_PrevAndNext(long structureId,
4081                    String structureKey, OrderByComparator orderByComparator)
4082                    throws NoSuchStructureException, SystemException {
4083                    DDMStructure ddmStructure = findByPrimaryKey(structureId);
4084    
4085                    Session session = null;
4086    
4087                    try {
4088                            session = openSession();
4089    
4090                            DDMStructure[] array = new DDMStructureImpl[3];
4091    
4092                            array[0] = getByStructureKey_PrevAndNext(session, ddmStructure,
4093                                            structureKey, orderByComparator, true);
4094    
4095                            array[1] = ddmStructure;
4096    
4097                            array[2] = getByStructureKey_PrevAndNext(session, ddmStructure,
4098                                            structureKey, orderByComparator, false);
4099    
4100                            return array;
4101                    }
4102                    catch (Exception e) {
4103                            throw processException(e);
4104                    }
4105                    finally {
4106                            closeSession(session);
4107                    }
4108            }
4109    
4110            protected DDMStructure getByStructureKey_PrevAndNext(Session session,
4111                    DDMStructure ddmStructure, String structureKey,
4112                    OrderByComparator orderByComparator, boolean previous) {
4113                    StringBundler query = null;
4114    
4115                    if (orderByComparator != null) {
4116                            query = new StringBundler(6 +
4117                                            (orderByComparator.getOrderByFields().length * 6));
4118                    }
4119                    else {
4120                            query = new StringBundler(3);
4121                    }
4122    
4123                    query.append(_SQL_SELECT_DDMSTRUCTURE_WHERE);
4124    
4125                    boolean bindStructureKey = false;
4126    
4127                    if (structureKey == null) {
4128                            query.append(_FINDER_COLUMN_STRUCTUREKEY_STRUCTUREKEY_1);
4129                    }
4130                    else if (structureKey.equals(StringPool.BLANK)) {
4131                            query.append(_FINDER_COLUMN_STRUCTUREKEY_STRUCTUREKEY_3);
4132                    }
4133                    else {
4134                            bindStructureKey = true;
4135    
4136                            query.append(_FINDER_COLUMN_STRUCTUREKEY_STRUCTUREKEY_2);
4137                    }
4138    
4139                    if (orderByComparator != null) {
4140                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
4141    
4142                            if (orderByConditionFields.length > 0) {
4143                                    query.append(WHERE_AND);
4144                            }
4145    
4146                            for (int i = 0; i < orderByConditionFields.length; i++) {
4147                                    query.append(_ORDER_BY_ENTITY_ALIAS);
4148                                    query.append(orderByConditionFields[i]);
4149    
4150                                    if ((i + 1) < orderByConditionFields.length) {
4151                                            if (orderByComparator.isAscending() ^ previous) {
4152                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
4153                                            }
4154                                            else {
4155                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
4156                                            }
4157                                    }
4158                                    else {
4159                                            if (orderByComparator.isAscending() ^ previous) {
4160                                                    query.append(WHERE_GREATER_THAN);
4161                                            }
4162                                            else {
4163                                                    query.append(WHERE_LESSER_THAN);
4164                                            }
4165                                    }
4166                            }
4167    
4168                            query.append(ORDER_BY_CLAUSE);
4169    
4170                            String[] orderByFields = orderByComparator.getOrderByFields();
4171    
4172                            for (int i = 0; i < orderByFields.length; i++) {
4173                                    query.append(_ORDER_BY_ENTITY_ALIAS);
4174                                    query.append(orderByFields[i]);
4175    
4176                                    if ((i + 1) < orderByFields.length) {
4177                                            if (orderByComparator.isAscending() ^ previous) {
4178                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
4179                                            }
4180                                            else {
4181                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
4182                                            }
4183                                    }
4184                                    else {
4185                                            if (orderByComparator.isAscending() ^ previous) {
4186                                                    query.append(ORDER_BY_ASC);
4187                                            }
4188                                            else {
4189                                                    query.append(ORDER_BY_DESC);
4190                                            }
4191                                    }
4192                            }
4193                    }
4194                    else {
4195                            query.append(DDMStructureModelImpl.ORDER_BY_JPQL);
4196                    }
4197    
4198                    String sql = query.toString();
4199    
4200                    Query q = session.createQuery(sql);
4201    
4202                    q.setFirstResult(0);
4203                    q.setMaxResults(2);
4204    
4205                    QueryPos qPos = QueryPos.getInstance(q);
4206    
4207                    if (bindStructureKey) {
4208                            qPos.add(structureKey);
4209                    }
4210    
4211                    if (orderByComparator != null) {
4212                            Object[] values = orderByComparator.getOrderByConditionValues(ddmStructure);
4213    
4214                            for (Object value : values) {
4215                                    qPos.add(value);
4216                            }
4217                    }
4218    
4219                    List<DDMStructure> list = q.list();
4220    
4221                    if (list.size() == 2) {
4222                            return list.get(1);
4223                    }
4224                    else {
4225                            return null;
4226                    }
4227            }
4228    
4229            /**
4230             * Removes all the d d m structures where structureKey = &#63; from the database.
4231             *
4232             * @param structureKey the structure key
4233             * @throws SystemException if a system exception occurred
4234             */
4235            @Override
4236            public void removeByStructureKey(String structureKey)
4237                    throws SystemException {
4238                    for (DDMStructure ddmStructure : findByStructureKey(structureKey,
4239                                    QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
4240                            remove(ddmStructure);
4241                    }
4242            }
4243    
4244            /**
4245             * Returns the number of d d m structures where structureKey = &#63;.
4246             *
4247             * @param structureKey the structure key
4248             * @return the number of matching d d m structures
4249             * @throws SystemException if a system exception occurred
4250             */
4251            @Override
4252            public int countByStructureKey(String structureKey)
4253                    throws SystemException {
4254                    FinderPath finderPath = FINDER_PATH_COUNT_BY_STRUCTUREKEY;
4255    
4256                    Object[] finderArgs = new Object[] { structureKey };
4257    
4258                    Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
4259                                    this);
4260    
4261                    if (count == null) {
4262                            StringBundler query = new StringBundler(2);
4263    
4264                            query.append(_SQL_COUNT_DDMSTRUCTURE_WHERE);
4265    
4266                            boolean bindStructureKey = false;
4267    
4268                            if (structureKey == null) {
4269                                    query.append(_FINDER_COLUMN_STRUCTUREKEY_STRUCTUREKEY_1);
4270                            }
4271                            else if (structureKey.equals(StringPool.BLANK)) {
4272                                    query.append(_FINDER_COLUMN_STRUCTUREKEY_STRUCTUREKEY_3);
4273                            }
4274                            else {
4275                                    bindStructureKey = true;
4276    
4277                                    query.append(_FINDER_COLUMN_STRUCTUREKEY_STRUCTUREKEY_2);
4278                            }
4279    
4280                            String sql = query.toString();
4281    
4282                            Session session = null;
4283    
4284                            try {
4285                                    session = openSession();
4286    
4287                                    Query q = session.createQuery(sql);
4288    
4289                                    QueryPos qPos = QueryPos.getInstance(q);
4290    
4291                                    if (bindStructureKey) {
4292                                            qPos.add(structureKey);
4293                                    }
4294    
4295                                    count = (Long)q.uniqueResult();
4296    
4297                                    FinderCacheUtil.putResult(finderPath, finderArgs, count);
4298                            }
4299                            catch (Exception e) {
4300                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
4301    
4302                                    throw processException(e);
4303                            }
4304                            finally {
4305                                    closeSession(session);
4306                            }
4307                    }
4308    
4309                    return count.intValue();
4310            }
4311    
4312            private static final String _FINDER_COLUMN_STRUCTUREKEY_STRUCTUREKEY_1 = "ddmStructure.structureKey IS NULL";
4313            private static final String _FINDER_COLUMN_STRUCTUREKEY_STRUCTUREKEY_2 = "ddmStructure.structureKey = ?";
4314            private static final String _FINDER_COLUMN_STRUCTUREKEY_STRUCTUREKEY_3 = "(ddmStructure.structureKey IS NULL OR ddmStructure.structureKey = '')";
4315            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_G_P = new FinderPath(DDMStructureModelImpl.ENTITY_CACHE_ENABLED,
4316                            DDMStructureModelImpl.FINDER_CACHE_ENABLED, DDMStructureImpl.class,
4317                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByG_P",
4318                            new String[] {
4319                                    Long.class.getName(), Long.class.getName(),
4320                                    
4321                            Integer.class.getName(), Integer.class.getName(),
4322                                    OrderByComparator.class.getName()
4323                            });
4324            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_P = new FinderPath(DDMStructureModelImpl.ENTITY_CACHE_ENABLED,
4325                            DDMStructureModelImpl.FINDER_CACHE_ENABLED, DDMStructureImpl.class,
4326                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByG_P",
4327                            new String[] { Long.class.getName(), Long.class.getName() },
4328                            DDMStructureModelImpl.GROUPID_COLUMN_BITMASK |
4329                            DDMStructureModelImpl.PARENTSTRUCTUREID_COLUMN_BITMASK);
4330            public static final FinderPath FINDER_PATH_COUNT_BY_G_P = new FinderPath(DDMStructureModelImpl.ENTITY_CACHE_ENABLED,
4331                            DDMStructureModelImpl.FINDER_CACHE_ENABLED, Long.class,
4332                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByG_P",
4333                            new String[] { Long.class.getName(), Long.class.getName() });
4334    
4335            /**
4336             * Returns all the d d m structures where groupId = &#63; and parentStructureId = &#63;.
4337             *
4338             * @param groupId the group ID
4339             * @param parentStructureId the parent structure ID
4340             * @return the matching d d m structures
4341             * @throws SystemException if a system exception occurred
4342             */
4343            @Override
4344            public List<DDMStructure> findByG_P(long groupId, long parentStructureId)
4345                    throws SystemException {
4346                    return findByG_P(groupId, parentStructureId, QueryUtil.ALL_POS,
4347                            QueryUtil.ALL_POS, null);
4348            }
4349    
4350            /**
4351             * Returns a range of all the d d m structures where groupId = &#63; and parentStructureId = &#63;.
4352             *
4353             * <p>
4354             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portlet.dynamicdatamapping.model.impl.DDMStructureModelImpl}. 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.
4355             * </p>
4356             *
4357             * @param groupId the group ID
4358             * @param parentStructureId the parent structure ID
4359             * @param start the lower bound of the range of d d m structures
4360             * @param end the upper bound of the range of d d m structures (not inclusive)
4361             * @return the range of matching d d m structures
4362             * @throws SystemException if a system exception occurred
4363             */
4364            @Override
4365            public List<DDMStructure> findByG_P(long groupId, long parentStructureId,
4366                    int start, int end) throws SystemException {
4367                    return findByG_P(groupId, parentStructureId, start, end, null);
4368            }
4369    
4370            /**
4371             * Returns an ordered range of all the d d m structures where groupId = &#63; and parentStructureId = &#63;.
4372             *
4373             * <p>
4374             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portlet.dynamicdatamapping.model.impl.DDMStructureModelImpl}. 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.
4375             * </p>
4376             *
4377             * @param groupId the group ID
4378             * @param parentStructureId the parent structure ID
4379             * @param start the lower bound of the range of d d m structures
4380             * @param end the upper bound of the range of d d m structures (not inclusive)
4381             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
4382             * @return the ordered range of matching d d m structures
4383             * @throws SystemException if a system exception occurred
4384             */
4385            @Override
4386            public List<DDMStructure> findByG_P(long groupId, long parentStructureId,
4387                    int start, int end, OrderByComparator orderByComparator)
4388                    throws SystemException {
4389                    boolean pagination = true;
4390                    FinderPath finderPath = null;
4391                    Object[] finderArgs = null;
4392    
4393                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
4394                                    (orderByComparator == null)) {
4395                            pagination = false;
4396                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_P;
4397                            finderArgs = new Object[] { groupId, parentStructureId };
4398                    }
4399                    else {
4400                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_G_P;
4401                            finderArgs = new Object[] {
4402                                            groupId, parentStructureId,
4403                                            
4404                                            start, end, orderByComparator
4405                                    };
4406                    }
4407    
4408                    List<DDMStructure> list = (List<DDMStructure>)FinderCacheUtil.getResult(finderPath,
4409                                    finderArgs, this);
4410    
4411                    if ((list != null) && !list.isEmpty()) {
4412                            for (DDMStructure ddmStructure : list) {
4413                                    if ((groupId != ddmStructure.getGroupId()) ||
4414                                                    (parentStructureId != ddmStructure.getParentStructureId())) {
4415                                            list = null;
4416    
4417                                            break;
4418                                    }
4419                            }
4420                    }
4421    
4422                    if (list == null) {
4423                            StringBundler query = null;
4424    
4425                            if (orderByComparator != null) {
4426                                    query = new StringBundler(4 +
4427                                                    (orderByComparator.getOrderByFields().length * 3));
4428                            }
4429                            else {
4430                                    query = new StringBundler(4);
4431                            }
4432    
4433                            query.append(_SQL_SELECT_DDMSTRUCTURE_WHERE);
4434    
4435                            query.append(_FINDER_COLUMN_G_P_GROUPID_2);
4436    
4437                            query.append(_FINDER_COLUMN_G_P_PARENTSTRUCTUREID_2);
4438    
4439                            if (orderByComparator != null) {
4440                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
4441                                            orderByComparator);
4442                            }
4443                            else
4444                             if (pagination) {
4445                                    query.append(DDMStructureModelImpl.ORDER_BY_JPQL);
4446                            }
4447    
4448                            String sql = query.toString();
4449    
4450                            Session session = null;
4451    
4452                            try {
4453                                    session = openSession();
4454    
4455                                    Query q = session.createQuery(sql);
4456    
4457                                    QueryPos qPos = QueryPos.getInstance(q);
4458    
4459                                    qPos.add(groupId);
4460    
4461                                    qPos.add(parentStructureId);
4462    
4463                                    if (!pagination) {
4464                                            list = (List<DDMStructure>)QueryUtil.list(q, getDialect(),
4465                                                            start, end, false);
4466    
4467                                            Collections.sort(list);
4468    
4469                                            list = new UnmodifiableList<DDMStructure>(list);
4470                                    }
4471                                    else {
4472                                            list = (List<DDMStructure>)QueryUtil.list(q, getDialect(),
4473                                                            start, end);
4474                                    }
4475    
4476                                    cacheResult(list);
4477    
4478                                    FinderCacheUtil.putResult(finderPath, finderArgs, list);
4479                            }
4480                            catch (Exception e) {
4481                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
4482    
4483                                    throw processException(e);
4484                            }
4485                            finally {
4486                                    closeSession(session);
4487                            }
4488                    }
4489    
4490                    return list;
4491            }
4492    
4493            /**
4494             * Returns the first d d m structure in the ordered set where groupId = &#63; and parentStructureId = &#63;.
4495             *
4496             * @param groupId the group ID
4497             * @param parentStructureId the parent structure ID
4498             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
4499             * @return the first matching d d m structure
4500             * @throws com.liferay.portlet.dynamicdatamapping.NoSuchStructureException if a matching d d m structure could not be found
4501             * @throws SystemException if a system exception occurred
4502             */
4503            @Override
4504            public DDMStructure findByG_P_First(long groupId, long parentStructureId,
4505                    OrderByComparator orderByComparator)
4506                    throws NoSuchStructureException, SystemException {
4507                    DDMStructure ddmStructure = fetchByG_P_First(groupId,
4508                                    parentStructureId, orderByComparator);
4509    
4510                    if (ddmStructure != null) {
4511                            return ddmStructure;
4512                    }
4513    
4514                    StringBundler msg = new StringBundler(6);
4515    
4516                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
4517    
4518                    msg.append("groupId=");
4519                    msg.append(groupId);
4520    
4521                    msg.append(", parentStructureId=");
4522                    msg.append(parentStructureId);
4523    
4524                    msg.append(StringPool.CLOSE_CURLY_BRACE);
4525    
4526                    throw new NoSuchStructureException(msg.toString());
4527            }
4528    
4529            /**
4530             * Returns the first d d m structure in the ordered set where groupId = &#63; and parentStructureId = &#63;.
4531             *
4532             * @param groupId the group ID
4533             * @param parentStructureId the parent structure ID
4534             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
4535             * @return the first matching d d m structure, or <code>null</code> if a matching d d m structure could not be found
4536             * @throws SystemException if a system exception occurred
4537             */
4538            @Override
4539            public DDMStructure fetchByG_P_First(long groupId, long parentStructureId,
4540                    OrderByComparator orderByComparator) throws SystemException {
4541                    List<DDMStructure> list = findByG_P(groupId, parentStructureId, 0, 1,
4542                                    orderByComparator);
4543    
4544                    if (!list.isEmpty()) {
4545                            return list.get(0);
4546                    }
4547    
4548                    return null;
4549            }
4550    
4551            /**
4552             * Returns the last d d m structure in the ordered set where groupId = &#63; and parentStructureId = &#63;.
4553             *
4554             * @param groupId the group ID
4555             * @param parentStructureId the parent structure ID
4556             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
4557             * @return the last matching d d m structure
4558             * @throws com.liferay.portlet.dynamicdatamapping.NoSuchStructureException if a matching d d m structure could not be found
4559             * @throws SystemException if a system exception occurred
4560             */
4561            @Override
4562            public DDMStructure findByG_P_Last(long groupId, long parentStructureId,
4563                    OrderByComparator orderByComparator)
4564                    throws NoSuchStructureException, SystemException {
4565                    DDMStructure ddmStructure = fetchByG_P_Last(groupId, parentStructureId,
4566                                    orderByComparator);
4567    
4568                    if (ddmStructure != null) {
4569                            return ddmStructure;
4570                    }
4571    
4572                    StringBundler msg = new StringBundler(6);
4573    
4574                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
4575    
4576                    msg.append("groupId=");
4577                    msg.append(groupId);
4578    
4579                    msg.append(", parentStructureId=");
4580                    msg.append(parentStructureId);
4581    
4582                    msg.append(StringPool.CLOSE_CURLY_BRACE);
4583    
4584                    throw new NoSuchStructureException(msg.toString());
4585            }
4586    
4587            /**
4588             * Returns the last d d m structure in the ordered set where groupId = &#63; and parentStructureId = &#63;.
4589             *
4590             * @param groupId the group ID
4591             * @param parentStructureId the parent structure ID
4592             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
4593             * @return the last matching d d m structure, or <code>null</code> if a matching d d m structure could not be found
4594             * @throws SystemException if a system exception occurred
4595             */
4596            @Override
4597            public DDMStructure fetchByG_P_Last(long groupId, long parentStructureId,
4598                    OrderByComparator orderByComparator) throws SystemException {
4599                    int count = countByG_P(groupId, parentStructureId);
4600    
4601                    if (count == 0) {
4602                            return null;
4603                    }
4604    
4605                    List<DDMStructure> list = findByG_P(groupId, parentStructureId,
4606                                    count - 1, count, orderByComparator);
4607    
4608                    if (!list.isEmpty()) {
4609                            return list.get(0);
4610                    }
4611    
4612                    return null;
4613            }
4614    
4615            /**
4616             * Returns the d d m structures before and after the current d d m structure in the ordered set where groupId = &#63; and parentStructureId = &#63;.
4617             *
4618             * @param structureId the primary key of the current d d m structure
4619             * @param groupId the group ID
4620             * @param parentStructureId the parent structure ID
4621             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
4622             * @return the previous, current, and next d d m structure
4623             * @throws com.liferay.portlet.dynamicdatamapping.NoSuchStructureException if a d d m structure with the primary key could not be found
4624             * @throws SystemException if a system exception occurred
4625             */
4626            @Override
4627            public DDMStructure[] findByG_P_PrevAndNext(long structureId, long groupId,
4628                    long parentStructureId, OrderByComparator orderByComparator)
4629                    throws NoSuchStructureException, SystemException {
4630                    DDMStructure ddmStructure = findByPrimaryKey(structureId);
4631    
4632                    Session session = null;
4633    
4634                    try {
4635                            session = openSession();
4636    
4637                            DDMStructure[] array = new DDMStructureImpl[3];
4638    
4639                            array[0] = getByG_P_PrevAndNext(session, ddmStructure, groupId,
4640                                            parentStructureId, orderByComparator, true);
4641    
4642                            array[1] = ddmStructure;
4643    
4644                            array[2] = getByG_P_PrevAndNext(session, ddmStructure, groupId,
4645                                            parentStructureId, orderByComparator, false);
4646    
4647                            return array;
4648                    }
4649                    catch (Exception e) {
4650                            throw processException(e);
4651                    }
4652                    finally {
4653                            closeSession(session);
4654                    }
4655            }
4656    
4657            protected DDMStructure getByG_P_PrevAndNext(Session session,
4658                    DDMStructure ddmStructure, long groupId, long parentStructureId,
4659                    OrderByComparator orderByComparator, boolean previous) {
4660                    StringBundler query = null;
4661    
4662                    if (orderByComparator != null) {
4663                            query = new StringBundler(6 +
4664                                            (orderByComparator.getOrderByFields().length * 6));
4665                    }
4666                    else {
4667                            query = new StringBundler(3);
4668                    }
4669    
4670                    query.append(_SQL_SELECT_DDMSTRUCTURE_WHERE);
4671    
4672                    query.append(_FINDER_COLUMN_G_P_GROUPID_2);
4673    
4674                    query.append(_FINDER_COLUMN_G_P_PARENTSTRUCTUREID_2);
4675    
4676                    if (orderByComparator != null) {
4677                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
4678    
4679                            if (orderByConditionFields.length > 0) {
4680                                    query.append(WHERE_AND);
4681                            }
4682    
4683                            for (int i = 0; i < orderByConditionFields.length; i++) {
4684                                    query.append(_ORDER_BY_ENTITY_ALIAS);
4685                                    query.append(orderByConditionFields[i]);
4686    
4687                                    if ((i + 1) < orderByConditionFields.length) {
4688                                            if (orderByComparator.isAscending() ^ previous) {
4689                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
4690                                            }
4691                                            else {
4692                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
4693                                            }
4694                                    }
4695                                    else {
4696                                            if (orderByComparator.isAscending() ^ previous) {
4697                                                    query.append(WHERE_GREATER_THAN);
4698                                            }
4699                                            else {
4700                                                    query.append(WHERE_LESSER_THAN);
4701                                            }
4702                                    }
4703                            }
4704    
4705                            query.append(ORDER_BY_CLAUSE);
4706    
4707                            String[] orderByFields = orderByComparator.getOrderByFields();
4708    
4709                            for (int i = 0; i < orderByFields.length; i++) {
4710                                    query.append(_ORDER_BY_ENTITY_ALIAS);
4711                                    query.append(orderByFields[i]);
4712    
4713                                    if ((i + 1) < orderByFields.length) {
4714                                            if (orderByComparator.isAscending() ^ previous) {
4715                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
4716                                            }
4717                                            else {
4718                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
4719                                            }
4720                                    }
4721                                    else {
4722                                            if (orderByComparator.isAscending() ^ previous) {
4723                                                    query.append(ORDER_BY_ASC);
4724                                            }
4725                                            else {
4726                                                    query.append(ORDER_BY_DESC);
4727                                            }
4728                                    }
4729                            }
4730                    }
4731                    else {
4732                            query.append(DDMStructureModelImpl.ORDER_BY_JPQL);
4733                    }
4734    
4735                    String sql = query.toString();
4736    
4737                    Query q = session.createQuery(sql);
4738    
4739                    q.setFirstResult(0);
4740                    q.setMaxResults(2);
4741    
4742                    QueryPos qPos = QueryPos.getInstance(q);
4743    
4744                    qPos.add(groupId);
4745    
4746                    qPos.add(parentStructureId);
4747    
4748                    if (orderByComparator != null) {
4749                            Object[] values = orderByComparator.getOrderByConditionValues(ddmStructure);
4750    
4751                            for (Object value : values) {
4752                                    qPos.add(value);
4753                            }
4754                    }
4755    
4756                    List<DDMStructure> list = q.list();
4757    
4758                    if (list.size() == 2) {
4759                            return list.get(1);
4760                    }
4761                    else {
4762                            return null;
4763                    }
4764            }
4765    
4766            /**
4767             * Returns all the d d m structures that the user has permission to view where groupId = &#63; and parentStructureId = &#63;.
4768             *
4769             * @param groupId the group ID
4770             * @param parentStructureId the parent structure ID
4771             * @return the matching d d m structures that the user has permission to view
4772             * @throws SystemException if a system exception occurred
4773             */
4774            @Override
4775            public List<DDMStructure> filterFindByG_P(long groupId,
4776                    long parentStructureId) throws SystemException {
4777                    return filterFindByG_P(groupId, parentStructureId, QueryUtil.ALL_POS,
4778                            QueryUtil.ALL_POS, null);
4779            }
4780    
4781            /**
4782             * Returns a range of all the d d m structures that the user has permission to view where groupId = &#63; and parentStructureId = &#63;.
4783             *
4784             * <p>
4785             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portlet.dynamicdatamapping.model.impl.DDMStructureModelImpl}. 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.
4786             * </p>
4787             *
4788             * @param groupId the group ID
4789             * @param parentStructureId the parent structure ID
4790             * @param start the lower bound of the range of d d m structures
4791             * @param end the upper bound of the range of d d m structures (not inclusive)
4792             * @return the range of matching d d m structures that the user has permission to view
4793             * @throws SystemException if a system exception occurred
4794             */
4795            @Override
4796            public List<DDMStructure> filterFindByG_P(long groupId,
4797                    long parentStructureId, int start, int end) throws SystemException {
4798                    return filterFindByG_P(groupId, parentStructureId, start, end, null);
4799            }
4800    
4801            /**
4802             * Returns an ordered range of all the d d m structures that the user has permissions to view where groupId = &#63; and parentStructureId = &#63;.
4803             *
4804             * <p>
4805             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portlet.dynamicdatamapping.model.impl.DDMStructureModelImpl}. 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.
4806             * </p>
4807             *
4808             * @param groupId the group ID
4809             * @param parentStructureId the parent structure ID
4810             * @param start the lower bound of the range of d d m structures
4811             * @param end the upper bound of the range of d d m structures (not inclusive)
4812             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
4813             * @return the ordered range of matching d d m structures that the user has permission to view
4814             * @throws SystemException if a system exception occurred
4815             */
4816            @Override
4817            public List<DDMStructure> filterFindByG_P(long groupId,
4818                    long parentStructureId, int start, int end,
4819                    OrderByComparator orderByComparator) throws SystemException {
4820                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
4821                            return findByG_P(groupId, parentStructureId, start, end,
4822                                    orderByComparator);
4823                    }
4824    
4825                    StringBundler query = null;
4826    
4827                    if (orderByComparator != null) {
4828                            query = new StringBundler(4 +
4829                                            (orderByComparator.getOrderByFields().length * 3));
4830                    }
4831                    else {
4832                            query = new StringBundler(4);
4833                    }
4834    
4835                    if (getDB().isSupportsInlineDistinct()) {
4836                            query.append(_FILTER_SQL_SELECT_DDMSTRUCTURE_WHERE);
4837                    }
4838                    else {
4839                            query.append(_FILTER_SQL_SELECT_DDMSTRUCTURE_NO_INLINE_DISTINCT_WHERE_1);
4840                    }
4841    
4842                    query.append(_FINDER_COLUMN_G_P_GROUPID_2);
4843    
4844                    query.append(_FINDER_COLUMN_G_P_PARENTSTRUCTUREID_2);
4845    
4846                    if (!getDB().isSupportsInlineDistinct()) {
4847                            query.append(_FILTER_SQL_SELECT_DDMSTRUCTURE_NO_INLINE_DISTINCT_WHERE_2);
4848                    }
4849    
4850                    if (orderByComparator != null) {
4851                            if (getDB().isSupportsInlineDistinct()) {
4852                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
4853                                            orderByComparator, true);
4854                            }
4855                            else {
4856                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_TABLE,
4857                                            orderByComparator, true);
4858                            }
4859                    }
4860                    else {
4861                            if (getDB().isSupportsInlineDistinct()) {
4862                                    query.append(DDMStructureModelImpl.ORDER_BY_JPQL);
4863                            }
4864                            else {
4865                                    query.append(DDMStructureModelImpl.ORDER_BY_SQL);
4866                            }
4867                    }
4868    
4869                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
4870                                    DDMStructure.class.getName(),
4871                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
4872    
4873                    Session session = null;
4874    
4875                    try {
4876                            session = openSession();
4877    
4878                            SQLQuery q = session.createSQLQuery(sql);
4879    
4880                            if (getDB().isSupportsInlineDistinct()) {
4881                                    q.addEntity(_FILTER_ENTITY_ALIAS, DDMStructureImpl.class);
4882                            }
4883                            else {
4884                                    q.addEntity(_FILTER_ENTITY_TABLE, DDMStructureImpl.class);
4885                            }
4886    
4887                            QueryPos qPos = QueryPos.getInstance(q);
4888    
4889                            qPos.add(groupId);
4890    
4891                            qPos.add(parentStructureId);
4892    
4893                            return (List<DDMStructure>)QueryUtil.list(q, getDialect(), start,
4894                                    end);
4895                    }
4896                    catch (Exception e) {
4897                            throw processException(e);
4898                    }
4899                    finally {
4900                            closeSession(session);
4901                    }
4902            }
4903    
4904            /**
4905             * Returns the d d m structures before and after the current d d m structure in the ordered set of d d m structures that the user has permission to view where groupId = &#63; and parentStructureId = &#63;.
4906             *
4907             * @param structureId the primary key of the current d d m structure
4908             * @param groupId the group ID
4909             * @param parentStructureId the parent structure ID
4910             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
4911             * @return the previous, current, and next d d m structure
4912             * @throws com.liferay.portlet.dynamicdatamapping.NoSuchStructureException if a d d m structure with the primary key could not be found
4913             * @throws SystemException if a system exception occurred
4914             */
4915            @Override
4916            public DDMStructure[] filterFindByG_P_PrevAndNext(long structureId,
4917                    long groupId, long parentStructureId,
4918                    OrderByComparator orderByComparator)
4919                    throws NoSuchStructureException, SystemException {
4920                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
4921                            return findByG_P_PrevAndNext(structureId, groupId,
4922                                    parentStructureId, orderByComparator);
4923                    }
4924    
4925                    DDMStructure ddmStructure = findByPrimaryKey(structureId);
4926    
4927                    Session session = null;
4928    
4929                    try {
4930                            session = openSession();
4931    
4932                            DDMStructure[] array = new DDMStructureImpl[3];
4933    
4934                            array[0] = filterGetByG_P_PrevAndNext(session, ddmStructure,
4935                                            groupId, parentStructureId, orderByComparator, true);
4936    
4937                            array[1] = ddmStructure;
4938    
4939                            array[2] = filterGetByG_P_PrevAndNext(session, ddmStructure,
4940                                            groupId, parentStructureId, orderByComparator, false);
4941    
4942                            return array;
4943                    }
4944                    catch (Exception e) {
4945                            throw processException(e);
4946                    }
4947                    finally {
4948                            closeSession(session);
4949                    }
4950            }
4951    
4952            protected DDMStructure filterGetByG_P_PrevAndNext(Session session,
4953                    DDMStructure ddmStructure, long groupId, long parentStructureId,
4954                    OrderByComparator orderByComparator, boolean previous) {
4955                    StringBundler query = null;
4956    
4957                    if (orderByComparator != null) {
4958                            query = new StringBundler(6 +
4959                                            (orderByComparator.getOrderByFields().length * 6));
4960                    }
4961                    else {
4962                            query = new StringBundler(3);
4963                    }
4964    
4965                    if (getDB().isSupportsInlineDistinct()) {
4966                            query.append(_FILTER_SQL_SELECT_DDMSTRUCTURE_WHERE);
4967                    }
4968                    else {
4969                            query.append(_FILTER_SQL_SELECT_DDMSTRUCTURE_NO_INLINE_DISTINCT_WHERE_1);
4970                    }
4971    
4972                    query.append(_FINDER_COLUMN_G_P_GROUPID_2);
4973    
4974                    query.append(_FINDER_COLUMN_G_P_PARENTSTRUCTUREID_2);
4975    
4976                    if (!getDB().isSupportsInlineDistinct()) {
4977                            query.append(_FILTER_SQL_SELECT_DDMSTRUCTURE_NO_INLINE_DISTINCT_WHERE_2);
4978                    }
4979    
4980                    if (orderByComparator != null) {
4981                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
4982    
4983                            if (orderByConditionFields.length > 0) {
4984                                    query.append(WHERE_AND);
4985                            }
4986    
4987                            for (int i = 0; i < orderByConditionFields.length; i++) {
4988                                    if (getDB().isSupportsInlineDistinct()) {
4989                                            query.append(_ORDER_BY_ENTITY_ALIAS);
4990                                    }
4991                                    else {
4992                                            query.append(_ORDER_BY_ENTITY_TABLE);
4993                                    }
4994    
4995                                    query.append(orderByConditionFields[i]);
4996    
4997                                    if ((i + 1) < orderByConditionFields.length) {
4998                                            if (orderByComparator.isAscending() ^ previous) {
4999                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
5000                                            }
5001                                            else {
5002                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
5003                                            }
5004                                    }
5005                                    else {
5006                                            if (orderByComparator.isAscending() ^ previous) {
5007                                                    query.append(WHERE_GREATER_THAN);
5008                                            }
5009                                            else {
5010                                                    query.append(WHERE_LESSER_THAN);
5011                                            }
5012                                    }
5013                            }
5014    
5015                            query.append(ORDER_BY_CLAUSE);
5016    
5017                            String[] orderByFields = orderByComparator.getOrderByFields();
5018    
5019                            for (int i = 0; i < orderByFields.length; i++) {
5020                                    if (getDB().isSupportsInlineDistinct()) {
5021                                            query.append(_ORDER_BY_ENTITY_ALIAS);
5022                                    }
5023                                    else {
5024                                            query.append(_ORDER_BY_ENTITY_TABLE);
5025                                    }
5026    
5027                                    query.append(orderByFields[i]);
5028    
5029                                    if ((i + 1) < orderByFields.length) {
5030                                            if (orderByComparator.isAscending() ^ previous) {
5031                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
5032                                            }
5033                                            else {
5034                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
5035                                            }
5036                                    }
5037                                    else {
5038                                            if (orderByComparator.isAscending() ^ previous) {
5039                                                    query.append(ORDER_BY_ASC);
5040                                            }
5041                                            else {
5042                                                    query.append(ORDER_BY_DESC);
5043                                            }
5044                                    }
5045                            }
5046                    }
5047                    else {
5048                            if (getDB().isSupportsInlineDistinct()) {
5049                                    query.append(DDMStructureModelImpl.ORDER_BY_JPQL);
5050                            }
5051                            else {
5052                                    query.append(DDMStructureModelImpl.ORDER_BY_SQL);
5053                            }
5054                    }
5055    
5056                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
5057                                    DDMStructure.class.getName(),
5058                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
5059    
5060                    SQLQuery q = session.createSQLQuery(sql);
5061    
5062                    q.setFirstResult(0);
5063                    q.setMaxResults(2);
5064    
5065                    if (getDB().isSupportsInlineDistinct()) {
5066                            q.addEntity(_FILTER_ENTITY_ALIAS, DDMStructureImpl.class);
5067                    }
5068                    else {
5069                            q.addEntity(_FILTER_ENTITY_TABLE, DDMStructureImpl.class);
5070                    }
5071    
5072                    QueryPos qPos = QueryPos.getInstance(q);
5073    
5074                    qPos.add(groupId);
5075    
5076                    qPos.add(parentStructureId);
5077    
5078                    if (orderByComparator != null) {
5079                            Object[] values = orderByComparator.getOrderByConditionValues(ddmStructure);
5080    
5081                            for (Object value : values) {
5082                                    qPos.add(value);
5083                            }
5084                    }
5085    
5086                    List<DDMStructure> list = q.list();
5087    
5088                    if (list.size() == 2) {
5089                            return list.get(1);
5090                    }
5091                    else {
5092                            return null;
5093                    }
5094            }
5095    
5096            /**
5097             * Removes all the d d m structures where groupId = &#63; and parentStructureId = &#63; from the database.
5098             *
5099             * @param groupId the group ID
5100             * @param parentStructureId the parent structure ID
5101             * @throws SystemException if a system exception occurred
5102             */
5103            @Override
5104            public void removeByG_P(long groupId, long parentStructureId)
5105                    throws SystemException {
5106                    for (DDMStructure ddmStructure : findByG_P(groupId, parentStructureId,
5107                                    QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
5108                            remove(ddmStructure);
5109                    }
5110            }
5111    
5112            /**
5113             * Returns the number of d d m structures where groupId = &#63; and parentStructureId = &#63;.
5114             *
5115             * @param groupId the group ID
5116             * @param parentStructureId the parent structure ID
5117             * @return the number of matching d d m structures
5118             * @throws SystemException if a system exception occurred
5119             */
5120            @Override
5121            public int countByG_P(long groupId, long parentStructureId)
5122                    throws SystemException {
5123                    FinderPath finderPath = FINDER_PATH_COUNT_BY_G_P;
5124    
5125                    Object[] finderArgs = new Object[] { groupId, parentStructureId };
5126    
5127                    Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
5128                                    this);
5129    
5130                    if (count == null) {
5131                            StringBundler query = new StringBundler(3);
5132    
5133                            query.append(_SQL_COUNT_DDMSTRUCTURE_WHERE);
5134    
5135                            query.append(_FINDER_COLUMN_G_P_GROUPID_2);
5136    
5137                            query.append(_FINDER_COLUMN_G_P_PARENTSTRUCTUREID_2);
5138    
5139                            String sql = query.toString();
5140    
5141                            Session session = null;
5142    
5143                            try {
5144                                    session = openSession();
5145    
5146                                    Query q = session.createQuery(sql);
5147    
5148                                    QueryPos qPos = QueryPos.getInstance(q);
5149    
5150                                    qPos.add(groupId);
5151    
5152                                    qPos.add(parentStructureId);
5153    
5154                                    count = (Long)q.uniqueResult();
5155    
5156                                    FinderCacheUtil.putResult(finderPath, finderArgs, count);
5157                            }
5158                            catch (Exception e) {
5159                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
5160    
5161                                    throw processException(e);
5162                            }
5163                            finally {
5164                                    closeSession(session);
5165                            }
5166                    }
5167    
5168                    return count.intValue();
5169            }
5170    
5171            /**
5172             * Returns the number of d d m structures that the user has permission to view where groupId = &#63; and parentStructureId = &#63;.
5173             *
5174             * @param groupId the group ID
5175             * @param parentStructureId the parent structure ID
5176             * @return the number of matching d d m structures that the user has permission to view
5177             * @throws SystemException if a system exception occurred
5178             */
5179            @Override
5180            public int filterCountByG_P(long groupId, long parentStructureId)
5181                    throws SystemException {
5182                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
5183                            return countByG_P(groupId, parentStructureId);
5184                    }
5185    
5186                    StringBundler query = new StringBundler(3);
5187    
5188                    query.append(_FILTER_SQL_COUNT_DDMSTRUCTURE_WHERE);
5189    
5190                    query.append(_FINDER_COLUMN_G_P_GROUPID_2);
5191    
5192                    query.append(_FINDER_COLUMN_G_P_PARENTSTRUCTUREID_2);
5193    
5194                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
5195                                    DDMStructure.class.getName(),
5196                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
5197    
5198                    Session session = null;
5199    
5200                    try {
5201                            session = openSession();
5202    
5203                            SQLQuery q = session.createSQLQuery(sql);
5204    
5205                            q.addScalar(COUNT_COLUMN_NAME,
5206                                    com.liferay.portal.kernel.dao.orm.Type.LONG);
5207    
5208                            QueryPos qPos = QueryPos.getInstance(q);
5209    
5210                            qPos.add(groupId);
5211    
5212                            qPos.add(parentStructureId);
5213    
5214                            Long count = (Long)q.uniqueResult();
5215    
5216                            return count.intValue();
5217                    }
5218                    catch (Exception e) {
5219                            throw processException(e);
5220                    }
5221                    finally {
5222                            closeSession(session);
5223                    }
5224            }
5225    
5226            private static final String _FINDER_COLUMN_G_P_GROUPID_2 = "ddmStructure.groupId = ? AND ";
5227            private static final String _FINDER_COLUMN_G_P_PARENTSTRUCTUREID_2 = "ddmStructure.parentStructureId = ?";
5228            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_G_C = new FinderPath(DDMStructureModelImpl.ENTITY_CACHE_ENABLED,
5229                            DDMStructureModelImpl.FINDER_CACHE_ENABLED, DDMStructureImpl.class,
5230                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByG_C",
5231                            new String[] {
5232                                    Long.class.getName(), Long.class.getName(),
5233                                    
5234                            Integer.class.getName(), Integer.class.getName(),
5235                                    OrderByComparator.class.getName()
5236                            });
5237            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_C = new FinderPath(DDMStructureModelImpl.ENTITY_CACHE_ENABLED,
5238                            DDMStructureModelImpl.FINDER_CACHE_ENABLED, DDMStructureImpl.class,
5239                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByG_C",
5240                            new String[] { Long.class.getName(), Long.class.getName() },
5241                            DDMStructureModelImpl.GROUPID_COLUMN_BITMASK |
5242                            DDMStructureModelImpl.CLASSNAMEID_COLUMN_BITMASK);
5243            public static final FinderPath FINDER_PATH_COUNT_BY_G_C = new FinderPath(DDMStructureModelImpl.ENTITY_CACHE_ENABLED,
5244                            DDMStructureModelImpl.FINDER_CACHE_ENABLED, Long.class,
5245                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByG_C",
5246                            new String[] { Long.class.getName(), Long.class.getName() });
5247            public static final FinderPath FINDER_PATH_WITH_PAGINATION_COUNT_BY_G_C = new FinderPath(DDMStructureModelImpl.ENTITY_CACHE_ENABLED,
5248                            DDMStructureModelImpl.FINDER_CACHE_ENABLED, Long.class,
5249                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "countByG_C",
5250                            new String[] { Long.class.getName(), Long.class.getName() });
5251    
5252            /**
5253             * Returns all the d d m structures where groupId = &#63; and classNameId = &#63;.
5254             *
5255             * @param groupId the group ID
5256             * @param classNameId the class name ID
5257             * @return the matching d d m structures
5258             * @throws SystemException if a system exception occurred
5259             */
5260            @Override
5261            public List<DDMStructure> findByG_C(long groupId, long classNameId)
5262                    throws SystemException {
5263                    return findByG_C(groupId, classNameId, QueryUtil.ALL_POS,
5264                            QueryUtil.ALL_POS, null);
5265            }
5266    
5267            /**
5268             * Returns a range of all the d d m structures where groupId = &#63; and classNameId = &#63;.
5269             *
5270             * <p>
5271             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portlet.dynamicdatamapping.model.impl.DDMStructureModelImpl}. 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.
5272             * </p>
5273             *
5274             * @param groupId the group ID
5275             * @param classNameId the class name ID
5276             * @param start the lower bound of the range of d d m structures
5277             * @param end the upper bound of the range of d d m structures (not inclusive)
5278             * @return the range of matching d d m structures
5279             * @throws SystemException if a system exception occurred
5280             */
5281            @Override
5282            public List<DDMStructure> findByG_C(long groupId, long classNameId,
5283                    int start, int end) throws SystemException {
5284                    return findByG_C(groupId, classNameId, start, end, null);
5285            }
5286    
5287            /**
5288             * Returns an ordered range of all the d d m structures where groupId = &#63; and classNameId = &#63;.
5289             *
5290             * <p>
5291             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portlet.dynamicdatamapping.model.impl.DDMStructureModelImpl}. 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.
5292             * </p>
5293             *
5294             * @param groupId the group ID
5295             * @param classNameId the class name ID
5296             * @param start the lower bound of the range of d d m structures
5297             * @param end the upper bound of the range of d d m structures (not inclusive)
5298             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
5299             * @return the ordered range of matching d d m structures
5300             * @throws SystemException if a system exception occurred
5301             */
5302            @Override
5303            public List<DDMStructure> findByG_C(long groupId, long classNameId,
5304                    int start, int end, OrderByComparator orderByComparator)
5305                    throws SystemException {
5306                    boolean pagination = true;
5307                    FinderPath finderPath = null;
5308                    Object[] finderArgs = null;
5309    
5310                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
5311                                    (orderByComparator == null)) {
5312                            pagination = false;
5313                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_C;
5314                            finderArgs = new Object[] { groupId, classNameId };
5315                    }
5316                    else {
5317                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_G_C;
5318                            finderArgs = new Object[] {
5319                                            groupId, classNameId,
5320                                            
5321                                            start, end, orderByComparator
5322                                    };
5323                    }
5324    
5325                    List<DDMStructure> list = (List<DDMStructure>)FinderCacheUtil.getResult(finderPath,
5326                                    finderArgs, this);
5327    
5328                    if ((list != null) && !list.isEmpty()) {
5329                            for (DDMStructure ddmStructure : list) {
5330                                    if ((groupId != ddmStructure.getGroupId()) ||
5331                                                    (classNameId != ddmStructure.getClassNameId())) {
5332                                            list = null;
5333    
5334                                            break;
5335                                    }
5336                            }
5337                    }
5338    
5339                    if (list == null) {
5340                            StringBundler query = null;
5341    
5342                            if (orderByComparator != null) {
5343                                    query = new StringBundler(4 +
5344                                                    (orderByComparator.getOrderByFields().length * 3));
5345                            }
5346                            else {
5347                                    query = new StringBundler(4);
5348                            }
5349    
5350                            query.append(_SQL_SELECT_DDMSTRUCTURE_WHERE);
5351    
5352                            query.append(_FINDER_COLUMN_G_C_GROUPID_2);
5353    
5354                            query.append(_FINDER_COLUMN_G_C_CLASSNAMEID_2);
5355    
5356                            if (orderByComparator != null) {
5357                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
5358                                            orderByComparator);
5359                            }
5360                            else
5361                             if (pagination) {
5362                                    query.append(DDMStructureModelImpl.ORDER_BY_JPQL);
5363                            }
5364    
5365                            String sql = query.toString();
5366    
5367                            Session session = null;
5368    
5369                            try {
5370                                    session = openSession();
5371    
5372                                    Query q = session.createQuery(sql);
5373    
5374                                    QueryPos qPos = QueryPos.getInstance(q);
5375    
5376                                    qPos.add(groupId);
5377    
5378                                    qPos.add(classNameId);
5379    
5380                                    if (!pagination) {
5381                                            list = (List<DDMStructure>)QueryUtil.list(q, getDialect(),
5382                                                            start, end, false);
5383    
5384                                            Collections.sort(list);
5385    
5386                                            list = new UnmodifiableList<DDMStructure>(list);
5387                                    }
5388                                    else {
5389                                            list = (List<DDMStructure>)QueryUtil.list(q, getDialect(),
5390                                                            start, end);
5391                                    }
5392    
5393                                    cacheResult(list);
5394    
5395                                    FinderCacheUtil.putResult(finderPath, finderArgs, list);
5396                            }
5397                            catch (Exception e) {
5398                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
5399    
5400                                    throw processException(e);
5401                            }
5402                            finally {
5403                                    closeSession(session);
5404                            }
5405                    }
5406    
5407                    return list;
5408            }
5409    
5410            /**
5411             * Returns the first d d m structure in the ordered set where groupId = &#63; and classNameId = &#63;.
5412             *
5413             * @param groupId the group ID
5414             * @param classNameId the class name ID
5415             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
5416             * @return the first matching d d m structure
5417             * @throws com.liferay.portlet.dynamicdatamapping.NoSuchStructureException if a matching d d m structure could not be found
5418             * @throws SystemException if a system exception occurred
5419             */
5420            @Override
5421            public DDMStructure findByG_C_First(long groupId, long classNameId,
5422                    OrderByComparator orderByComparator)
5423                    throws NoSuchStructureException, SystemException {
5424                    DDMStructure ddmStructure = fetchByG_C_First(groupId, classNameId,
5425                                    orderByComparator);
5426    
5427                    if (ddmStructure != null) {
5428                            return ddmStructure;
5429                    }
5430    
5431                    StringBundler msg = new StringBundler(6);
5432    
5433                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
5434    
5435                    msg.append("groupId=");
5436                    msg.append(groupId);
5437    
5438                    msg.append(", classNameId=");
5439                    msg.append(classNameId);
5440    
5441                    msg.append(StringPool.CLOSE_CURLY_BRACE);
5442    
5443                    throw new NoSuchStructureException(msg.toString());
5444            }
5445    
5446            /**
5447             * Returns the first d d m structure in the ordered set where groupId = &#63; and classNameId = &#63;.
5448             *
5449             * @param groupId the group ID
5450             * @param classNameId the class name ID
5451             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
5452             * @return the first matching d d m structure, or <code>null</code> if a matching d d m structure could not be found
5453             * @throws SystemException if a system exception occurred
5454             */
5455            @Override
5456            public DDMStructure fetchByG_C_First(long groupId, long classNameId,
5457                    OrderByComparator orderByComparator) throws SystemException {
5458                    List<DDMStructure> list = findByG_C(groupId, classNameId, 0, 1,
5459                                    orderByComparator);
5460    
5461                    if (!list.isEmpty()) {
5462                            return list.get(0);
5463                    }
5464    
5465                    return null;
5466            }
5467    
5468            /**
5469             * Returns the last d d m structure in the ordered set where groupId = &#63; and classNameId = &#63;.
5470             *
5471             * @param groupId the group ID
5472             * @param classNameId the class name ID
5473             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
5474             * @return the last matching d d m structure
5475             * @throws com.liferay.portlet.dynamicdatamapping.NoSuchStructureException if a matching d d m structure could not be found
5476             * @throws SystemException if a system exception occurred
5477             */
5478            @Override
5479            public DDMStructure findByG_C_Last(long groupId, long classNameId,
5480                    OrderByComparator orderByComparator)
5481                    throws NoSuchStructureException, SystemException {
5482                    DDMStructure ddmStructure = fetchByG_C_Last(groupId, classNameId,
5483                                    orderByComparator);
5484    
5485                    if (ddmStructure != null) {
5486                            return ddmStructure;
5487                    }
5488    
5489                    StringBundler msg = new StringBundler(6);
5490    
5491                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
5492    
5493                    msg.append("groupId=");
5494                    msg.append(groupId);
5495    
5496                    msg.append(", classNameId=");
5497                    msg.append(classNameId);
5498    
5499                    msg.append(StringPool.CLOSE_CURLY_BRACE);
5500    
5501                    throw new NoSuchStructureException(msg.toString());
5502            }
5503    
5504            /**
5505             * Returns the last d d m structure in the ordered set where groupId = &#63; and classNameId = &#63;.
5506             *
5507             * @param groupId the group ID
5508             * @param classNameId the class name ID
5509             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
5510             * @return the last matching d d m structure, or <code>null</code> if a matching d d m structure could not be found
5511             * @throws SystemException if a system exception occurred
5512             */
5513            @Override
5514            public DDMStructure fetchByG_C_Last(long groupId, long classNameId,
5515                    OrderByComparator orderByComparator) throws SystemException {
5516                    int count = countByG_C(groupId, classNameId);
5517    
5518                    if (count == 0) {
5519                            return null;
5520                    }
5521    
5522                    List<DDMStructure> list = findByG_C(groupId, classNameId, count - 1,
5523                                    count, orderByComparator);
5524    
5525                    if (!list.isEmpty()) {
5526                            return list.get(0);
5527                    }
5528    
5529                    return null;
5530            }
5531    
5532            /**
5533             * Returns the d d m structures before and after the current d d m structure in the ordered set where groupId = &#63; and classNameId = &#63;.
5534             *
5535             * @param structureId the primary key of the current d d m structure
5536             * @param groupId the group ID
5537             * @param classNameId the class name ID
5538             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
5539             * @return the previous, current, and next d d m structure
5540             * @throws com.liferay.portlet.dynamicdatamapping.NoSuchStructureException if a d d m structure with the primary key could not be found
5541             * @throws SystemException if a system exception occurred
5542             */
5543            @Override
5544            public DDMStructure[] findByG_C_PrevAndNext(long structureId, long groupId,
5545                    long classNameId, OrderByComparator orderByComparator)
5546                    throws NoSuchStructureException, SystemException {
5547                    DDMStructure ddmStructure = findByPrimaryKey(structureId);
5548    
5549                    Session session = null;
5550    
5551                    try {
5552                            session = openSession();
5553    
5554                            DDMStructure[] array = new DDMStructureImpl[3];
5555    
5556                            array[0] = getByG_C_PrevAndNext(session, ddmStructure, groupId,
5557                                            classNameId, orderByComparator, true);
5558    
5559                            array[1] = ddmStructure;
5560    
5561                            array[2] = getByG_C_PrevAndNext(session, ddmStructure, groupId,
5562                                            classNameId, orderByComparator, false);
5563    
5564                            return array;
5565                    }
5566                    catch (Exception e) {
5567                            throw processException(e);
5568                    }
5569                    finally {
5570                            closeSession(session);
5571                    }
5572            }
5573    
5574            protected DDMStructure getByG_C_PrevAndNext(Session session,
5575                    DDMStructure ddmStructure, long groupId, long classNameId,
5576                    OrderByComparator orderByComparator, boolean previous) {
5577                    StringBundler query = null;
5578    
5579                    if (orderByComparator != null) {
5580                            query = new StringBundler(6 +
5581                                            (orderByComparator.getOrderByFields().length * 6));
5582                    }
5583                    else {
5584                            query = new StringBundler(3);
5585                    }
5586    
5587                    query.append(_SQL_SELECT_DDMSTRUCTURE_WHERE);
5588    
5589                    query.append(_FINDER_COLUMN_G_C_GROUPID_2);
5590    
5591                    query.append(_FINDER_COLUMN_G_C_CLASSNAMEID_2);
5592    
5593                    if (orderByComparator != null) {
5594                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
5595    
5596                            if (orderByConditionFields.length > 0) {
5597                                    query.append(WHERE_AND);
5598                            }
5599    
5600                            for (int i = 0; i < orderByConditionFields.length; i++) {
5601                                    query.append(_ORDER_BY_ENTITY_ALIAS);
5602                                    query.append(orderByConditionFields[i]);
5603    
5604                                    if ((i + 1) < orderByConditionFields.length) {
5605                                            if (orderByComparator.isAscending() ^ previous) {
5606                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
5607                                            }
5608                                            else {
5609                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
5610                                            }
5611                                    }
5612                                    else {
5613                                            if (orderByComparator.isAscending() ^ previous) {
5614                                                    query.append(WHERE_GREATER_THAN);
5615                                            }
5616                                            else {
5617                                                    query.append(WHERE_LESSER_THAN);
5618                                            }
5619                                    }
5620                            }
5621    
5622                            query.append(ORDER_BY_CLAUSE);
5623    
5624                            String[] orderByFields = orderByComparator.getOrderByFields();
5625    
5626                            for (int i = 0; i < orderByFields.length; i++) {
5627                                    query.append(_ORDER_BY_ENTITY_ALIAS);
5628                                    query.append(orderByFields[i]);
5629    
5630                                    if ((i + 1) < orderByFields.length) {
5631                                            if (orderByComparator.isAscending() ^ previous) {
5632                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
5633                                            }
5634                                            else {
5635                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
5636                                            }
5637                                    }
5638                                    else {
5639                                            if (orderByComparator.isAscending() ^ previous) {
5640                                                    query.append(ORDER_BY_ASC);
5641                                            }
5642                                            else {
5643                                                    query.append(ORDER_BY_DESC);
5644                                            }
5645                                    }
5646                            }
5647                    }
5648                    else {
5649                            query.append(DDMStructureModelImpl.ORDER_BY_JPQL);
5650                    }
5651    
5652                    String sql = query.toString();
5653    
5654                    Query q = session.createQuery(sql);
5655    
5656                    q.setFirstResult(0);
5657                    q.setMaxResults(2);
5658    
5659                    QueryPos qPos = QueryPos.getInstance(q);
5660    
5661                    qPos.add(groupId);
5662    
5663                    qPos.add(classNameId);
5664    
5665                    if (orderByComparator != null) {
5666                            Object[] values = orderByComparator.getOrderByConditionValues(ddmStructure);
5667    
5668                            for (Object value : values) {
5669                                    qPos.add(value);
5670                            }
5671                    }
5672    
5673                    List<DDMStructure> list = q.list();
5674    
5675                    if (list.size() == 2) {
5676                            return list.get(1);
5677                    }
5678                    else {
5679                            return null;
5680                    }
5681            }
5682    
5683            /**
5684             * Returns all the d d m structures that the user has permission to view where groupId = &#63; and classNameId = &#63;.
5685             *
5686             * @param groupId the group ID
5687             * @param classNameId the class name ID
5688             * @return the matching d d m structures that the user has permission to view
5689             * @throws SystemException if a system exception occurred
5690             */
5691            @Override
5692            public List<DDMStructure> filterFindByG_C(long groupId, long classNameId)
5693                    throws SystemException {
5694                    return filterFindByG_C(groupId, classNameId, QueryUtil.ALL_POS,
5695                            QueryUtil.ALL_POS, null);
5696            }
5697    
5698            /**
5699             * Returns a range of all the d d m structures that the user has permission to view where groupId = &#63; and classNameId = &#63;.
5700             *
5701             * <p>
5702             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portlet.dynamicdatamapping.model.impl.DDMStructureModelImpl}. 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.
5703             * </p>
5704             *
5705             * @param groupId the group ID
5706             * @param classNameId the class name ID
5707             * @param start the lower bound of the range of d d m structures
5708             * @param end the upper bound of the range of d d m structures (not inclusive)
5709             * @return the range of matching d d m structures that the user has permission to view
5710             * @throws SystemException if a system exception occurred
5711             */
5712            @Override
5713            public List<DDMStructure> filterFindByG_C(long groupId, long classNameId,
5714                    int start, int end) throws SystemException {
5715                    return filterFindByG_C(groupId, classNameId, start, end, null);
5716            }
5717    
5718            /**
5719             * Returns an ordered range of all the d d m structures that the user has permissions to view where groupId = &#63; and classNameId = &#63;.
5720             *
5721             * <p>
5722             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portlet.dynamicdatamapping.model.impl.DDMStructureModelImpl}. 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.
5723             * </p>
5724             *
5725             * @param groupId the group ID
5726             * @param classNameId the class name ID
5727             * @param start the lower bound of the range of d d m structures
5728             * @param end the upper bound of the range of d d m structures (not inclusive)
5729             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
5730             * @return the ordered range of matching d d m structures that the user has permission to view
5731             * @throws SystemException if a system exception occurred
5732             */
5733            @Override
5734            public List<DDMStructure> filterFindByG_C(long groupId, long classNameId,
5735                    int start, int end, OrderByComparator orderByComparator)
5736                    throws SystemException {
5737                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
5738                            return findByG_C(groupId, classNameId, start, end, orderByComparator);
5739                    }
5740    
5741                    StringBundler query = null;
5742    
5743                    if (orderByComparator != null) {
5744                            query = new StringBundler(4 +
5745                                            (orderByComparator.getOrderByFields().length * 3));
5746                    }
5747                    else {
5748                            query = new StringBundler(4);
5749                    }
5750    
5751                    if (getDB().isSupportsInlineDistinct()) {
5752                            query.append(_FILTER_SQL_SELECT_DDMSTRUCTURE_WHERE);
5753                    }
5754                    else {
5755                            query.append(_FILTER_SQL_SELECT_DDMSTRUCTURE_NO_INLINE_DISTINCT_WHERE_1);
5756                    }
5757    
5758                    query.append(_FINDER_COLUMN_G_C_GROUPID_2);
5759    
5760                    query.append(_FINDER_COLUMN_G_C_CLASSNAMEID_2);
5761    
5762                    if (!getDB().isSupportsInlineDistinct()) {
5763                            query.append(_FILTER_SQL_SELECT_DDMSTRUCTURE_NO_INLINE_DISTINCT_WHERE_2);
5764                    }
5765    
5766                    if (orderByComparator != null) {
5767                            if (getDB().isSupportsInlineDistinct()) {
5768                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
5769                                            orderByComparator, true);
5770                            }
5771                            else {
5772                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_TABLE,
5773                                            orderByComparator, true);
5774                            }
5775                    }
5776                    else {
5777                            if (getDB().isSupportsInlineDistinct()) {
5778                                    query.append(DDMStructureModelImpl.ORDER_BY_JPQL);
5779                            }
5780                            else {
5781                                    query.append(DDMStructureModelImpl.ORDER_BY_SQL);
5782                            }
5783                    }
5784    
5785                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
5786                                    DDMStructure.class.getName(),
5787                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
5788    
5789                    Session session = null;
5790    
5791                    try {
5792                            session = openSession();
5793    
5794                            SQLQuery q = session.createSQLQuery(sql);
5795    
5796                            if (getDB().isSupportsInlineDistinct()) {
5797                                    q.addEntity(_FILTER_ENTITY_ALIAS, DDMStructureImpl.class);
5798                            }
5799                            else {
5800                                    q.addEntity(_FILTER_ENTITY_TABLE, DDMStructureImpl.class);
5801                            }
5802    
5803                            QueryPos qPos = QueryPos.getInstance(q);
5804    
5805                            qPos.add(groupId);
5806    
5807                            qPos.add(classNameId);
5808    
5809                            return (List<DDMStructure>)QueryUtil.list(q, getDialect(), start,
5810                                    end);
5811                    }
5812                    catch (Exception e) {
5813                            throw processException(e);
5814                    }
5815                    finally {
5816                            closeSession(session);
5817                    }
5818            }
5819    
5820            /**
5821             * Returns the d d m structures before and after the current d d m structure in the ordered set of d d m structures that the user has permission to view where groupId = &#63; and classNameId = &#63;.
5822             *
5823             * @param structureId the primary key of the current d d m structure
5824             * @param groupId the group ID
5825             * @param classNameId the class name ID
5826             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
5827             * @return the previous, current, and next d d m structure
5828             * @throws com.liferay.portlet.dynamicdatamapping.NoSuchStructureException if a d d m structure with the primary key could not be found
5829             * @throws SystemException if a system exception occurred
5830             */
5831            @Override
5832            public DDMStructure[] filterFindByG_C_PrevAndNext(long structureId,
5833                    long groupId, long classNameId, OrderByComparator orderByComparator)
5834                    throws NoSuchStructureException, SystemException {
5835                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
5836                            return findByG_C_PrevAndNext(structureId, groupId, classNameId,
5837                                    orderByComparator);
5838                    }
5839    
5840                    DDMStructure ddmStructure = findByPrimaryKey(structureId);
5841    
5842                    Session session = null;
5843    
5844                    try {
5845                            session = openSession();
5846    
5847                            DDMStructure[] array = new DDMStructureImpl[3];
5848    
5849                            array[0] = filterGetByG_C_PrevAndNext(session, ddmStructure,
5850                                            groupId, classNameId, orderByComparator, true);
5851    
5852                            array[1] = ddmStructure;
5853    
5854                            array[2] = filterGetByG_C_PrevAndNext(session, ddmStructure,
5855                                            groupId, classNameId, orderByComparator, false);
5856    
5857                            return array;
5858                    }
5859                    catch (Exception e) {
5860                            throw processException(e);
5861                    }
5862                    finally {
5863                            closeSession(session);
5864                    }
5865            }
5866    
5867            protected DDMStructure filterGetByG_C_PrevAndNext(Session session,
5868                    DDMStructure ddmStructure, long groupId, long classNameId,
5869                    OrderByComparator orderByComparator, boolean previous) {
5870                    StringBundler query = null;
5871    
5872                    if (orderByComparator != null) {
5873                            query = new StringBundler(6 +
5874                                            (orderByComparator.getOrderByFields().length * 6));
5875                    }
5876                    else {
5877                            query = new StringBundler(3);
5878                    }
5879    
5880                    if (getDB().isSupportsInlineDistinct()) {
5881                            query.append(_FILTER_SQL_SELECT_DDMSTRUCTURE_WHERE);
5882                    }
5883                    else {
5884                            query.append(_FILTER_SQL_SELECT_DDMSTRUCTURE_NO_INLINE_DISTINCT_WHERE_1);
5885                    }
5886    
5887                    query.append(_FINDER_COLUMN_G_C_GROUPID_2);
5888    
5889                    query.append(_FINDER_COLUMN_G_C_CLASSNAMEID_2);
5890    
5891                    if (!getDB().isSupportsInlineDistinct()) {
5892                            query.append(_FILTER_SQL_SELECT_DDMSTRUCTURE_NO_INLINE_DISTINCT_WHERE_2);
5893                    }
5894    
5895                    if (orderByComparator != null) {
5896                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
5897    
5898                            if (orderByConditionFields.length > 0) {
5899                                    query.append(WHERE_AND);
5900                            }
5901    
5902                            for (int i = 0; i < orderByConditionFields.length; i++) {
5903                                    if (getDB().isSupportsInlineDistinct()) {
5904                                            query.append(_ORDER_BY_ENTITY_ALIAS);
5905                                    }
5906                                    else {
5907                                            query.append(_ORDER_BY_ENTITY_TABLE);
5908                                    }
5909    
5910                                    query.append(orderByConditionFields[i]);
5911    
5912                                    if ((i + 1) < orderByConditionFields.length) {
5913                                            if (orderByComparator.isAscending() ^ previous) {
5914                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
5915                                            }
5916                                            else {
5917                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
5918                                            }
5919                                    }
5920                                    else {
5921                                            if (orderByComparator.isAscending() ^ previous) {
5922                                                    query.append(WHERE_GREATER_THAN);
5923                                            }
5924                                            else {
5925                                                    query.append(WHERE_LESSER_THAN);
5926                                            }
5927                                    }
5928                            }
5929    
5930                            query.append(ORDER_BY_CLAUSE);
5931    
5932                            String[] orderByFields = orderByComparator.getOrderByFields();
5933    
5934                            for (int i = 0; i < orderByFields.length; i++) {
5935                                    if (getDB().isSupportsInlineDistinct()) {
5936                                            query.append(_ORDER_BY_ENTITY_ALIAS);
5937                                    }
5938                                    else {
5939                                            query.append(_ORDER_BY_ENTITY_TABLE);
5940                                    }
5941    
5942                                    query.append(orderByFields[i]);
5943    
5944                                    if ((i + 1) < orderByFields.length) {
5945                                            if (orderByComparator.isAscending() ^ previous) {
5946                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
5947                                            }
5948                                            else {
5949                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
5950                                            }
5951                                    }
5952                                    else {
5953                                            if (orderByComparator.isAscending() ^ previous) {
5954                                                    query.append(ORDER_BY_ASC);
5955                                            }
5956                                            else {
5957                                                    query.append(ORDER_BY_DESC);
5958                                            }
5959                                    }
5960                            }
5961                    }
5962                    else {
5963                            if (getDB().isSupportsInlineDistinct()) {
5964                                    query.append(DDMStructureModelImpl.ORDER_BY_JPQL);
5965                            }
5966                            else {
5967                                    query.append(DDMStructureModelImpl.ORDER_BY_SQL);
5968                            }
5969                    }
5970    
5971                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
5972                                    DDMStructure.class.getName(),
5973                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
5974    
5975                    SQLQuery q = session.createSQLQuery(sql);
5976    
5977                    q.setFirstResult(0);
5978                    q.setMaxResults(2);
5979    
5980                    if (getDB().isSupportsInlineDistinct()) {
5981                            q.addEntity(_FILTER_ENTITY_ALIAS, DDMStructureImpl.class);
5982                    }
5983                    else {
5984                            q.addEntity(_FILTER_ENTITY_TABLE, DDMStructureImpl.class);
5985                    }
5986    
5987                    QueryPos qPos = QueryPos.getInstance(q);
5988    
5989                    qPos.add(groupId);
5990    
5991                    qPos.add(classNameId);
5992    
5993                    if (orderByComparator != null) {
5994                            Object[] values = orderByComparator.getOrderByConditionValues(ddmStructure);
5995    
5996                            for (Object value : values) {
5997                                    qPos.add(value);
5998                            }
5999                    }
6000    
6001                    List<DDMStructure> list = q.list();
6002    
6003                    if (list.size() == 2) {
6004                            return list.get(1);
6005                    }
6006                    else {
6007                            return null;
6008                    }
6009            }
6010    
6011            /**
6012             * Returns all the d d m structures that the user has permission to view where groupId = any &#63; and classNameId = &#63;.
6013             *
6014             * @param groupIds the group IDs
6015             * @param classNameId the class name ID
6016             * @return the matching d d m structures that the user has permission to view
6017             * @throws SystemException if a system exception occurred
6018             */
6019            @Override
6020            public List<DDMStructure> filterFindByG_C(long[] groupIds, long classNameId)
6021                    throws SystemException {
6022                    return filterFindByG_C(groupIds, classNameId, QueryUtil.ALL_POS,
6023                            QueryUtil.ALL_POS, null);
6024            }
6025    
6026            /**
6027             * Returns a range of all the d d m structures that the user has permission to view where groupId = any &#63; and classNameId = &#63;.
6028             *
6029             * <p>
6030             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portlet.dynamicdatamapping.model.impl.DDMStructureModelImpl}. 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.
6031             * </p>
6032             *
6033             * @param groupIds the group IDs
6034             * @param classNameId the class name ID
6035             * @param start the lower bound of the range of d d m structures
6036             * @param end the upper bound of the range of d d m structures (not inclusive)
6037             * @return the range of matching d d m structures that the user has permission to view
6038             * @throws SystemException if a system exception occurred
6039             */
6040            @Override
6041            public List<DDMStructure> filterFindByG_C(long[] groupIds,
6042                    long classNameId, int start, int end) throws SystemException {
6043                    return filterFindByG_C(groupIds, classNameId, start, end, null);
6044            }
6045    
6046            /**
6047             * Returns an ordered range of all the d d m structures that the user has permission to view where groupId = any &#63; and classNameId = &#63;.
6048             *
6049             * <p>
6050             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portlet.dynamicdatamapping.model.impl.DDMStructureModelImpl}. 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.
6051             * </p>
6052             *
6053             * @param groupIds the group IDs
6054             * @param classNameId the class name ID
6055             * @param start the lower bound of the range of d d m structures
6056             * @param end the upper bound of the range of d d m structures (not inclusive)
6057             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
6058             * @return the ordered range of matching d d m structures that the user has permission to view
6059             * @throws SystemException if a system exception occurred
6060             */
6061            @Override
6062            public List<DDMStructure> filterFindByG_C(long[] groupIds,
6063                    long classNameId, int start, int end,
6064                    OrderByComparator orderByComparator) throws SystemException {
6065                    if (!InlineSQLHelperUtil.isEnabled(groupIds)) {
6066                            return findByG_C(groupIds, classNameId, start, end,
6067                                    orderByComparator);
6068                    }
6069    
6070                    StringBundler query = new StringBundler();
6071    
6072                    if (getDB().isSupportsInlineDistinct()) {
6073                            query.append(_FILTER_SQL_SELECT_DDMSTRUCTURE_WHERE);
6074                    }
6075                    else {
6076                            query.append(_FILTER_SQL_SELECT_DDMSTRUCTURE_NO_INLINE_DISTINCT_WHERE_1);
6077                    }
6078    
6079                    boolean conjunctionable = false;
6080    
6081                    if ((groupIds == null) || (groupIds.length > 0)) {
6082                            if (conjunctionable) {
6083                                    query.append(WHERE_AND);
6084                            }
6085    
6086                            query.append(StringPool.OPEN_PARENTHESIS);
6087    
6088                            for (int i = 0; i < groupIds.length; i++) {
6089                                    query.append(_FINDER_COLUMN_G_C_GROUPID_5);
6090    
6091                                    if ((i + 1) < groupIds.length) {
6092                                            query.append(WHERE_OR);
6093                                    }
6094                            }
6095    
6096                            query.append(StringPool.CLOSE_PARENTHESIS);
6097    
6098                            conjunctionable = true;
6099                    }
6100    
6101                    if (conjunctionable) {
6102                            query.append(WHERE_AND);
6103                    }
6104    
6105                    query.append(_FINDER_COLUMN_G_C_CLASSNAMEID_5);
6106    
6107                    conjunctionable = true;
6108    
6109                    if (!getDB().isSupportsInlineDistinct()) {
6110                            query.append(_FILTER_SQL_SELECT_DDMSTRUCTURE_NO_INLINE_DISTINCT_WHERE_2);
6111                    }
6112    
6113                    if (orderByComparator != null) {
6114                            if (getDB().isSupportsInlineDistinct()) {
6115                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
6116                                            orderByComparator, true);
6117                            }
6118                            else {
6119                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_TABLE,
6120                                            orderByComparator, true);
6121                            }
6122                    }
6123                    else {
6124                            if (getDB().isSupportsInlineDistinct()) {
6125                                    query.append(DDMStructureModelImpl.ORDER_BY_JPQL);
6126                            }
6127                            else {
6128                                    query.append(DDMStructureModelImpl.ORDER_BY_SQL);
6129                            }
6130                    }
6131    
6132                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
6133                                    DDMStructure.class.getName(),
6134                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupIds);
6135    
6136                    Session session = null;
6137    
6138                    try {
6139                            session = openSession();
6140    
6141                            SQLQuery q = session.createSQLQuery(sql);
6142    
6143                            if (getDB().isSupportsInlineDistinct()) {
6144                                    q.addEntity(_FILTER_ENTITY_ALIAS, DDMStructureImpl.class);
6145                            }
6146                            else {
6147                                    q.addEntity(_FILTER_ENTITY_TABLE, DDMStructureImpl.class);
6148                            }
6149    
6150                            QueryPos qPos = QueryPos.getInstance(q);
6151    
6152                            if (groupIds != null) {
6153                                    qPos.add(groupIds);
6154                            }
6155    
6156                            qPos.add(classNameId);
6157    
6158                            return (List<DDMStructure>)QueryUtil.list(q, getDialect(), start,
6159                                    end);
6160                    }
6161                    catch (Exception e) {
6162                            throw processException(e);
6163                    }
6164                    finally {
6165                            closeSession(session);
6166                    }
6167            }
6168    
6169            /**
6170             * Returns all the d d m structures where groupId = any &#63; and classNameId = &#63;.
6171             *
6172             * <p>
6173             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portlet.dynamicdatamapping.model.impl.DDMStructureModelImpl}. 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.
6174             * </p>
6175             *
6176             * @param groupIds the group IDs
6177             * @param classNameId the class name ID
6178             * @return the matching d d m structures
6179             * @throws SystemException if a system exception occurred
6180             */
6181            @Override
6182            public List<DDMStructure> findByG_C(long[] groupIds, long classNameId)
6183                    throws SystemException {
6184                    return findByG_C(groupIds, classNameId, QueryUtil.ALL_POS,
6185                            QueryUtil.ALL_POS, null);
6186            }
6187    
6188            /**
6189             * Returns a range of all the d d m structures where groupId = any &#63; and classNameId = &#63;.
6190             *
6191             * <p>
6192             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portlet.dynamicdatamapping.model.impl.DDMStructureModelImpl}. 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.
6193             * </p>
6194             *
6195             * @param groupIds the group IDs
6196             * @param classNameId the class name ID
6197             * @param start the lower bound of the range of d d m structures
6198             * @param end the upper bound of the range of d d m structures (not inclusive)
6199             * @return the range of matching d d m structures
6200             * @throws SystemException if a system exception occurred
6201             */
6202            @Override
6203            public List<DDMStructure> findByG_C(long[] groupIds, long classNameId,
6204                    int start, int end) throws SystemException {
6205                    return findByG_C(groupIds, classNameId, start, end, null);
6206            }
6207    
6208            /**
6209             * Returns an ordered range of all the d d m structures where groupId = any &#63; and classNameId = &#63;.
6210             *
6211             * <p>
6212             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portlet.dynamicdatamapping.model.impl.DDMStructureModelImpl}. 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.
6213             * </p>
6214             *
6215             * @param groupIds the group IDs
6216             * @param classNameId the class name ID
6217             * @param start the lower bound of the range of d d m structures
6218             * @param end the upper bound of the range of d d m structures (not inclusive)
6219             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
6220             * @return the ordered range of matching d d m structures
6221             * @throws SystemException if a system exception occurred
6222             */
6223            @Override
6224            public List<DDMStructure> findByG_C(long[] groupIds, long classNameId,
6225                    int start, int end, OrderByComparator orderByComparator)
6226                    throws SystemException {
6227                    if ((groupIds != null) && (groupIds.length == 1)) {
6228                            return findByG_C(groupIds[0], classNameId, start, end,
6229                                    orderByComparator);
6230                    }
6231    
6232                    boolean pagination = true;
6233                    Object[] finderArgs = null;
6234    
6235                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
6236                                    (orderByComparator == null)) {
6237                            pagination = false;
6238                            finderArgs = new Object[] { StringUtil.merge(groupIds), classNameId };
6239                    }
6240                    else {
6241                            finderArgs = new Object[] {
6242                                            StringUtil.merge(groupIds), classNameId,
6243                                            
6244                                            start, end, orderByComparator
6245                                    };
6246                    }
6247    
6248                    List<DDMStructure> list = (List<DDMStructure>)FinderCacheUtil.getResult(FINDER_PATH_WITH_PAGINATION_FIND_BY_G_C,
6249                                    finderArgs, this);
6250    
6251                    if ((list != null) && !list.isEmpty()) {
6252                            for (DDMStructure ddmStructure : list) {
6253                                    if (!ArrayUtil.contains(groupIds, ddmStructure.getGroupId()) ||
6254                                                    (classNameId != ddmStructure.getClassNameId())) {
6255                                            list = null;
6256    
6257                                            break;
6258                                    }
6259                            }
6260                    }
6261    
6262                    if (list == null) {
6263                            StringBundler query = new StringBundler();
6264    
6265                            query.append(_SQL_SELECT_DDMSTRUCTURE_WHERE);
6266    
6267                            boolean conjunctionable = false;
6268    
6269                            if ((groupIds == null) || (groupIds.length > 0)) {
6270                                    if (conjunctionable) {
6271                                            query.append(WHERE_AND);
6272                                    }
6273    
6274                                    query.append(StringPool.OPEN_PARENTHESIS);
6275    
6276                                    for (int i = 0; i < groupIds.length; i++) {
6277                                            query.append(_FINDER_COLUMN_G_C_GROUPID_5);
6278    
6279                                            if ((i + 1) < groupIds.length) {
6280                                                    query.append(WHERE_OR);
6281                                            }
6282                                    }
6283    
6284                                    query.append(StringPool.CLOSE_PARENTHESIS);
6285    
6286                                    conjunctionable = true;
6287                            }
6288    
6289                            if (conjunctionable) {
6290                                    query.append(WHERE_AND);
6291                            }
6292    
6293                            query.append(_FINDER_COLUMN_G_C_CLASSNAMEID_5);
6294    
6295                            conjunctionable = true;
6296    
6297                            if (orderByComparator != null) {
6298                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
6299                                            orderByComparator);
6300                            }
6301                            else
6302                             if (pagination) {
6303                                    query.append(DDMStructureModelImpl.ORDER_BY_JPQL);
6304                            }
6305    
6306                            String sql = query.toString();
6307    
6308                            Session session = null;
6309    
6310                            try {
6311                                    session = openSession();
6312    
6313                                    Query q = session.createQuery(sql);
6314    
6315                                    QueryPos qPos = QueryPos.getInstance(q);
6316    
6317                                    if (groupIds != null) {
6318                                            qPos.add(groupIds);
6319                                    }
6320    
6321                                    qPos.add(classNameId);
6322    
6323                                    if (!pagination) {
6324                                            list = (List<DDMStructure>)QueryUtil.list(q, getDialect(),
6325                                                            start, end, false);
6326    
6327                                            Collections.sort(list);
6328    
6329                                            list = new UnmodifiableList<DDMStructure>(list);
6330                                    }
6331                                    else {
6332                                            list = (List<DDMStructure>)QueryUtil.list(q, getDialect(),
6333                                                            start, end);
6334                                    }
6335    
6336                                    cacheResult(list);
6337    
6338                                    FinderCacheUtil.putResult(FINDER_PATH_WITH_PAGINATION_FIND_BY_G_C,
6339                                            finderArgs, list);
6340                            }
6341                            catch (Exception e) {
6342                                    FinderCacheUtil.removeResult(FINDER_PATH_WITH_PAGINATION_FIND_BY_G_C,
6343                                            finderArgs);
6344    
6345                                    throw processException(e);
6346                            }
6347                            finally {
6348                                    closeSession(session);
6349                            }
6350                    }
6351    
6352                    return list;
6353            }
6354    
6355            /**
6356             * Removes all the d d m structures where groupId = &#63; and classNameId = &#63; from the database.
6357             *
6358             * @param groupId the group ID
6359             * @param classNameId the class name ID
6360             * @throws SystemException if a system exception occurred
6361             */
6362            @Override
6363            public void removeByG_C(long groupId, long classNameId)
6364                    throws SystemException {
6365                    for (DDMStructure ddmStructure : findByG_C(groupId, classNameId,
6366                                    QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
6367                            remove(ddmStructure);
6368                    }
6369            }
6370    
6371            /**
6372             * Returns the number of d d m structures where groupId = &#63; and classNameId = &#63;.
6373             *
6374             * @param groupId the group ID
6375             * @param classNameId the class name ID
6376             * @return the number of matching d d m structures
6377             * @throws SystemException if a system exception occurred
6378             */
6379            @Override
6380            public int countByG_C(long groupId, long classNameId)
6381                    throws SystemException {
6382                    FinderPath finderPath = FINDER_PATH_COUNT_BY_G_C;
6383    
6384                    Object[] finderArgs = new Object[] { groupId, classNameId };
6385    
6386                    Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
6387                                    this);
6388    
6389                    if (count == null) {
6390                            StringBundler query = new StringBundler(3);
6391    
6392                            query.append(_SQL_COUNT_DDMSTRUCTURE_WHERE);
6393    
6394                            query.append(_FINDER_COLUMN_G_C_GROUPID_2);
6395    
6396                            query.append(_FINDER_COLUMN_G_C_CLASSNAMEID_2);
6397    
6398                            String sql = query.toString();
6399    
6400                            Session session = null;
6401    
6402                            try {
6403                                    session = openSession();
6404    
6405                                    Query q = session.createQuery(sql);
6406    
6407                                    QueryPos qPos = QueryPos.getInstance(q);
6408    
6409                                    qPos.add(groupId);
6410    
6411                                    qPos.add(classNameId);
6412    
6413                                    count = (Long)q.uniqueResult();
6414    
6415                                    FinderCacheUtil.putResult(finderPath, finderArgs, count);
6416                            }
6417                            catch (Exception e) {
6418                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
6419    
6420                                    throw processException(e);
6421                            }
6422                            finally {
6423                                    closeSession(session);
6424                            }
6425                    }
6426    
6427                    return count.intValue();
6428            }
6429    
6430            /**
6431             * Returns the number of d d m structures where groupId = any &#63; and classNameId = &#63;.
6432             *
6433             * @param groupIds the group IDs
6434             * @param classNameId the class name ID
6435             * @return the number of matching d d m structures
6436             * @throws SystemException if a system exception occurred
6437             */
6438            @Override
6439            public int countByG_C(long[] groupIds, long classNameId)
6440                    throws SystemException {
6441                    Object[] finderArgs = new Object[] {
6442                                    StringUtil.merge(groupIds), classNameId
6443                            };
6444    
6445                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_WITH_PAGINATION_COUNT_BY_G_C,
6446                                    finderArgs, this);
6447    
6448                    if (count == null) {
6449                            StringBundler query = new StringBundler();
6450    
6451                            query.append(_SQL_COUNT_DDMSTRUCTURE_WHERE);
6452    
6453                            boolean conjunctionable = false;
6454    
6455                            if ((groupIds == null) || (groupIds.length > 0)) {
6456                                    if (conjunctionable) {
6457                                            query.append(WHERE_AND);
6458                                    }
6459    
6460                                    query.append(StringPool.OPEN_PARENTHESIS);
6461    
6462                                    for (int i = 0; i < groupIds.length; i++) {
6463                                            query.append(_FINDER_COLUMN_G_C_GROUPID_5);
6464    
6465                                            if ((i + 1) < groupIds.length) {
6466                                                    query.append(WHERE_OR);
6467                                            }
6468                                    }
6469    
6470                                    query.append(StringPool.CLOSE_PARENTHESIS);
6471    
6472                                    conjunctionable = true;
6473                            }
6474    
6475                            if (conjunctionable) {
6476                                    query.append(WHERE_AND);
6477                            }
6478    
6479                            query.append(_FINDER_COLUMN_G_C_CLASSNAMEID_5);
6480    
6481                            conjunctionable = true;
6482    
6483                            String sql = query.toString();
6484    
6485                            Session session = null;
6486    
6487                            try {
6488                                    session = openSession();
6489    
6490                                    Query q = session.createQuery(sql);
6491    
6492                                    QueryPos qPos = QueryPos.getInstance(q);
6493    
6494                                    if (groupIds != null) {
6495                                            qPos.add(groupIds);
6496                                    }
6497    
6498                                    qPos.add(classNameId);
6499    
6500                                    count = (Long)q.uniqueResult();
6501    
6502                                    FinderCacheUtil.putResult(FINDER_PATH_WITH_PAGINATION_COUNT_BY_G_C,
6503                                            finderArgs, count);
6504                            }
6505                            catch (Exception e) {
6506                                    FinderCacheUtil.removeResult(FINDER_PATH_WITH_PAGINATION_COUNT_BY_G_C,
6507                                            finderArgs);
6508    
6509                                    throw processException(e);
6510                            }
6511                            finally {
6512                                    closeSession(session);
6513                            }
6514                    }
6515    
6516                    return count.intValue();
6517            }
6518    
6519            /**
6520             * Returns the number of d d m structures that the user has permission to view where groupId = &#63; and classNameId = &#63;.
6521             *
6522             * @param groupId the group ID
6523             * @param classNameId the class name ID
6524             * @return the number of matching d d m structures that the user has permission to view
6525             * @throws SystemException if a system exception occurred
6526             */
6527            @Override
6528            public int filterCountByG_C(long groupId, long classNameId)
6529                    throws SystemException {
6530                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
6531                            return countByG_C(groupId, classNameId);
6532                    }
6533    
6534                    StringBundler query = new StringBundler(3);
6535    
6536                    query.append(_FILTER_SQL_COUNT_DDMSTRUCTURE_WHERE);
6537    
6538                    query.append(_FINDER_COLUMN_G_C_GROUPID_2);
6539    
6540                    query.append(_FINDER_COLUMN_G_C_CLASSNAMEID_2);
6541    
6542                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
6543                                    DDMStructure.class.getName(),
6544                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
6545    
6546                    Session session = null;
6547    
6548                    try {
6549                            session = openSession();
6550    
6551                            SQLQuery q = session.createSQLQuery(sql);
6552    
6553                            q.addScalar(COUNT_COLUMN_NAME,
6554                                    com.liferay.portal.kernel.dao.orm.Type.LONG);
6555    
6556                            QueryPos qPos = QueryPos.getInstance(q);
6557    
6558                            qPos.add(groupId);
6559    
6560                            qPos.add(classNameId);
6561    
6562                            Long count = (Long)q.uniqueResult();
6563    
6564                            return count.intValue();
6565                    }
6566                    catch (Exception e) {
6567                            throw processException(e);
6568                    }
6569                    finally {
6570                            closeSession(session);
6571                    }
6572            }
6573    
6574            /**
6575             * Returns the number of d d m structures that the user has permission to view where groupId = any &#63; and classNameId = &#63;.
6576             *
6577             * @param groupIds the group IDs
6578             * @param classNameId the class name ID
6579             * @return the number of matching d d m structures that the user has permission to view
6580             * @throws SystemException if a system exception occurred
6581             */
6582            @Override
6583            public int filterCountByG_C(long[] groupIds, long classNameId)
6584                    throws SystemException {
6585                    if (!InlineSQLHelperUtil.isEnabled(groupIds)) {
6586                            return countByG_C(groupIds, classNameId);
6587                    }
6588    
6589                    StringBundler query = new StringBundler();
6590    
6591                    query.append(_FILTER_SQL_COUNT_DDMSTRUCTURE_WHERE);
6592    
6593                    boolean conjunctionable = false;
6594    
6595                    if ((groupIds == null) || (groupIds.length > 0)) {
6596                            if (conjunctionable) {
6597                                    query.append(WHERE_AND);
6598                            }
6599    
6600                            query.append(StringPool.OPEN_PARENTHESIS);
6601    
6602                            for (int i = 0; i < groupIds.length; i++) {
6603                                    query.append(_FINDER_COLUMN_G_C_GROUPID_5);
6604    
6605                                    if ((i + 1) < groupIds.length) {
6606                                            query.append(WHERE_OR);
6607                                    }
6608                            }
6609    
6610                            query.append(StringPool.CLOSE_PARENTHESIS);
6611    
6612                            conjunctionable = true;
6613                    }
6614    
6615                    if (conjunctionable) {
6616                            query.append(WHERE_AND);
6617                    }
6618    
6619                    query.append(_FINDER_COLUMN_G_C_CLASSNAMEID_5);
6620    
6621                    conjunctionable = true;
6622    
6623                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
6624                                    DDMStructure.class.getName(),
6625                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupIds);
6626    
6627                    Session session = null;
6628    
6629                    try {
6630                            session = openSession();
6631    
6632                            SQLQuery q = session.createSQLQuery(sql);
6633    
6634                            q.addScalar(COUNT_COLUMN_NAME,
6635                                    com.liferay.portal.kernel.dao.orm.Type.LONG);
6636    
6637                            QueryPos qPos = QueryPos.getInstance(q);
6638    
6639                            if (groupIds != null) {
6640                                    qPos.add(groupIds);
6641                            }
6642    
6643                            qPos.add(classNameId);
6644    
6645                            Long count = (Long)q.uniqueResult();
6646    
6647                            return count.intValue();
6648                    }
6649                    catch (Exception e) {
6650                            throw processException(e);
6651                    }
6652                    finally {
6653                            closeSession(session);
6654                    }
6655            }
6656    
6657            private static final String _FINDER_COLUMN_G_C_GROUPID_2 = "ddmStructure.groupId = ? AND ";
6658            private static final String _FINDER_COLUMN_G_C_GROUPID_5 = "(" +
6659                    removeConjunction(_FINDER_COLUMN_G_C_GROUPID_2) + ")";
6660            private static final String _FINDER_COLUMN_G_C_CLASSNAMEID_2 = "ddmStructure.classNameId = ?";
6661            private static final String _FINDER_COLUMN_G_C_CLASSNAMEID_5 = "(" +
6662                    removeConjunction(_FINDER_COLUMN_G_C_CLASSNAMEID_2) + ")";
6663            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_C_C = new FinderPath(DDMStructureModelImpl.ENTITY_CACHE_ENABLED,
6664                            DDMStructureModelImpl.FINDER_CACHE_ENABLED, DDMStructureImpl.class,
6665                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByC_C",
6666                            new String[] {
6667                                    Long.class.getName(), Long.class.getName(),
6668                                    
6669                            Integer.class.getName(), Integer.class.getName(),
6670                                    OrderByComparator.class.getName()
6671                            });
6672            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_C = new FinderPath(DDMStructureModelImpl.ENTITY_CACHE_ENABLED,
6673                            DDMStructureModelImpl.FINDER_CACHE_ENABLED, DDMStructureImpl.class,
6674                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByC_C",
6675                            new String[] { Long.class.getName(), Long.class.getName() },
6676                            DDMStructureModelImpl.COMPANYID_COLUMN_BITMASK |
6677                            DDMStructureModelImpl.CLASSNAMEID_COLUMN_BITMASK);
6678            public static final FinderPath FINDER_PATH_COUNT_BY_C_C = new FinderPath(DDMStructureModelImpl.ENTITY_CACHE_ENABLED,
6679                            DDMStructureModelImpl.FINDER_CACHE_ENABLED, Long.class,
6680                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByC_C",
6681                            new String[] { Long.class.getName(), Long.class.getName() });
6682    
6683            /**
6684             * Returns all the d d m structures where companyId = &#63; and classNameId = &#63;.
6685             *
6686             * @param companyId the company ID
6687             * @param classNameId the class name ID
6688             * @return the matching d d m structures
6689             * @throws SystemException if a system exception occurred
6690             */
6691            @Override
6692            public List<DDMStructure> findByC_C(long companyId, long classNameId)
6693                    throws SystemException {
6694                    return findByC_C(companyId, classNameId, QueryUtil.ALL_POS,
6695                            QueryUtil.ALL_POS, null);
6696            }
6697    
6698            /**
6699             * Returns a range of all the d d m structures where companyId = &#63; and classNameId = &#63;.
6700             *
6701             * <p>
6702             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portlet.dynamicdatamapping.model.impl.DDMStructureModelImpl}. 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.
6703             * </p>
6704             *
6705             * @param companyId the company ID
6706             * @param classNameId the class name ID
6707             * @param start the lower bound of the range of d d m structures
6708             * @param end the upper bound of the range of d d m structures (not inclusive)
6709             * @return the range of matching d d m structures
6710             * @throws SystemException if a system exception occurred
6711             */
6712            @Override
6713            public List<DDMStructure> findByC_C(long companyId, long classNameId,
6714                    int start, int end) throws SystemException {
6715                    return findByC_C(companyId, classNameId, start, end, null);
6716            }
6717    
6718            /**
6719             * Returns an ordered range of all the d d m structures where companyId = &#63; and classNameId = &#63;.
6720             *
6721             * <p>
6722             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portlet.dynamicdatamapping.model.impl.DDMStructureModelImpl}. 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.
6723             * </p>
6724             *
6725             * @param companyId the company ID
6726             * @param classNameId the class name ID
6727             * @param start the lower bound of the range of d d m structures
6728             * @param end the upper bound of the range of d d m structures (not inclusive)
6729             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
6730             * @return the ordered range of matching d d m structures
6731             * @throws SystemException if a system exception occurred
6732             */
6733            @Override
6734            public List<DDMStructure> findByC_C(long companyId, long classNameId,
6735                    int start, int end, OrderByComparator orderByComparator)
6736                    throws SystemException {
6737                    boolean pagination = true;
6738                    FinderPath finderPath = null;
6739                    Object[] finderArgs = null;
6740    
6741                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
6742                                    (orderByComparator == null)) {
6743                            pagination = false;
6744                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_C;
6745                            finderArgs = new Object[] { companyId, classNameId };
6746                    }
6747                    else {
6748                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_C_C;
6749                            finderArgs = new Object[] {
6750                                            companyId, classNameId,
6751                                            
6752                                            start, end, orderByComparator
6753                                    };
6754                    }
6755    
6756                    List<DDMStructure> list = (List<DDMStructure>)FinderCacheUtil.getResult(finderPath,
6757                                    finderArgs, this);
6758    
6759                    if ((list != null) && !list.isEmpty()) {
6760                            for (DDMStructure ddmStructure : list) {
6761                                    if ((companyId != ddmStructure.getCompanyId()) ||
6762                                                    (classNameId != ddmStructure.getClassNameId())) {
6763                                            list = null;
6764    
6765                                            break;
6766                                    }
6767                            }
6768                    }
6769    
6770                    if (list == null) {
6771                            StringBundler query = null;
6772    
6773                            if (orderByComparator != null) {
6774                                    query = new StringBundler(4 +
6775                                                    (orderByComparator.getOrderByFields().length * 3));
6776                            }
6777                            else {
6778                                    query = new StringBundler(4);
6779                            }
6780    
6781                            query.append(_SQL_SELECT_DDMSTRUCTURE_WHERE);
6782    
6783                            query.append(_FINDER_COLUMN_C_C_COMPANYID_2);
6784    
6785                            query.append(_FINDER_COLUMN_C_C_CLASSNAMEID_2);
6786    
6787                            if (orderByComparator != null) {
6788                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
6789                                            orderByComparator);
6790                            }
6791                            else
6792                             if (pagination) {
6793                                    query.append(DDMStructureModelImpl.ORDER_BY_JPQL);
6794                            }
6795    
6796                            String sql = query.toString();
6797    
6798                            Session session = null;
6799    
6800                            try {
6801                                    session = openSession();
6802    
6803                                    Query q = session.createQuery(sql);
6804    
6805                                    QueryPos qPos = QueryPos.getInstance(q);
6806    
6807                                    qPos.add(companyId);
6808    
6809                                    qPos.add(classNameId);
6810    
6811                                    if (!pagination) {
6812                                            list = (List<DDMStructure>)QueryUtil.list(q, getDialect(),
6813                                                            start, end, false);
6814    
6815                                            Collections.sort(list);
6816    
6817                                            list = new UnmodifiableList<DDMStructure>(list);
6818                                    }
6819                                    else {
6820                                            list = (List<DDMStructure>)QueryUtil.list(q, getDialect(),
6821                                                            start, end);
6822                                    }
6823    
6824                                    cacheResult(list);
6825    
6826                                    FinderCacheUtil.putResult(finderPath, finderArgs, list);
6827                            }
6828                            catch (Exception e) {
6829                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
6830    
6831                                    throw processException(e);
6832                            }
6833                            finally {
6834                                    closeSession(session);
6835                            }
6836                    }
6837    
6838                    return list;
6839            }
6840    
6841            /**
6842             * Returns the first d d m structure in the ordered set where companyId = &#63; and classNameId = &#63;.
6843             *
6844             * @param companyId the company ID
6845             * @param classNameId the class name ID
6846             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
6847             * @return the first matching d d m structure
6848             * @throws com.liferay.portlet.dynamicdatamapping.NoSuchStructureException if a matching d d m structure could not be found
6849             * @throws SystemException if a system exception occurred
6850             */
6851            @Override
6852            public DDMStructure findByC_C_First(long companyId, long classNameId,
6853                    OrderByComparator orderByComparator)
6854                    throws NoSuchStructureException, SystemException {
6855                    DDMStructure ddmStructure = fetchByC_C_First(companyId, classNameId,
6856                                    orderByComparator);
6857    
6858                    if (ddmStructure != null) {
6859                            return ddmStructure;
6860                    }
6861    
6862                    StringBundler msg = new StringBundler(6);
6863    
6864                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
6865    
6866                    msg.append("companyId=");
6867                    msg.append(companyId);
6868    
6869                    msg.append(", classNameId=");
6870                    msg.append(classNameId);
6871    
6872                    msg.append(StringPool.CLOSE_CURLY_BRACE);
6873    
6874                    throw new NoSuchStructureException(msg.toString());
6875            }
6876    
6877            /**
6878             * Returns the first d d m structure in the ordered set where companyId = &#63; and classNameId = &#63;.
6879             *
6880             * @param companyId the company ID
6881             * @param classNameId the class name ID
6882             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
6883             * @return the first matching d d m structure, or <code>null</code> if a matching d d m structure could not be found
6884             * @throws SystemException if a system exception occurred
6885             */
6886            @Override
6887            public DDMStructure fetchByC_C_First(long companyId, long classNameId,
6888                    OrderByComparator orderByComparator) throws SystemException {
6889                    List<DDMStructure> list = findByC_C(companyId, classNameId, 0, 1,
6890                                    orderByComparator);
6891    
6892                    if (!list.isEmpty()) {
6893                            return list.get(0);
6894                    }
6895    
6896                    return null;
6897            }
6898    
6899            /**
6900             * Returns the last d d m structure in the ordered set where companyId = &#63; and classNameId = &#63;.
6901             *
6902             * @param companyId the company ID
6903             * @param classNameId the class name ID
6904             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
6905             * @return the last matching d d m structure
6906             * @throws com.liferay.portlet.dynamicdatamapping.NoSuchStructureException if a matching d d m structure could not be found
6907             * @throws SystemException if a system exception occurred
6908             */
6909            @Override
6910            public DDMStructure findByC_C_Last(long companyId, long classNameId,
6911                    OrderByComparator orderByComparator)
6912                    throws NoSuchStructureException, SystemException {
6913                    DDMStructure ddmStructure = fetchByC_C_Last(companyId, classNameId,
6914                                    orderByComparator);
6915    
6916                    if (ddmStructure != null) {
6917                            return ddmStructure;
6918                    }
6919    
6920                    StringBundler msg = new StringBundler(6);
6921    
6922                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
6923    
6924                    msg.append("companyId=");
6925                    msg.append(companyId);
6926    
6927                    msg.append(", classNameId=");
6928                    msg.append(classNameId);
6929    
6930                    msg.append(StringPool.CLOSE_CURLY_BRACE);
6931    
6932                    throw new NoSuchStructureException(msg.toString());
6933            }
6934    
6935            /**
6936             * Returns the last d d m structure in the ordered set where companyId = &#63; and classNameId = &#63;.
6937             *
6938             * @param companyId the company ID
6939             * @param classNameId the class name ID
6940             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
6941             * @return the last matching d d m structure, or <code>null</code> if a matching d d m structure could not be found
6942             * @throws SystemException if a system exception occurred
6943             */
6944            @Override
6945            public DDMStructure fetchByC_C_Last(long companyId, long classNameId,
6946                    OrderByComparator orderByComparator) throws SystemException {
6947                    int count = countByC_C(companyId, classNameId);
6948    
6949                    if (count == 0) {
6950                            return null;
6951                    }
6952    
6953                    List<DDMStructure> list = findByC_C(companyId, classNameId, count - 1,
6954                                    count, orderByComparator);
6955    
6956                    if (!list.isEmpty()) {
6957                            return list.get(0);
6958                    }
6959    
6960                    return null;
6961            }
6962    
6963            /**
6964             * Returns the d d m structures before and after the current d d m structure in the ordered set where companyId = &#63; and classNameId = &#63;.
6965             *
6966             * @param structureId the primary key of the current d d m structure
6967             * @param companyId the company ID
6968             * @param classNameId the class name ID
6969             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
6970             * @return the previous, current, and next d d m structure
6971             * @throws com.liferay.portlet.dynamicdatamapping.NoSuchStructureException if a d d m structure with the primary key could not be found
6972             * @throws SystemException if a system exception occurred
6973             */
6974            @Override
6975            public DDMStructure[] findByC_C_PrevAndNext(long structureId,
6976                    long companyId, long classNameId, OrderByComparator orderByComparator)
6977                    throws NoSuchStructureException, SystemException {
6978                    DDMStructure ddmStructure = findByPrimaryKey(structureId);
6979    
6980                    Session session = null;
6981    
6982                    try {
6983                            session = openSession();
6984    
6985                            DDMStructure[] array = new DDMStructureImpl[3];
6986    
6987                            array[0] = getByC_C_PrevAndNext(session, ddmStructure, companyId,
6988                                            classNameId, orderByComparator, true);
6989    
6990                            array[1] = ddmStructure;
6991    
6992                            array[2] = getByC_C_PrevAndNext(session, ddmStructure, companyId,
6993                                            classNameId, orderByComparator, false);
6994    
6995                            return array;
6996                    }
6997                    catch (Exception e) {
6998                            throw processException(e);
6999                    }
7000                    finally {
7001                            closeSession(session);
7002                    }
7003            }
7004    
7005            protected DDMStructure getByC_C_PrevAndNext(Session session,
7006                    DDMStructure ddmStructure, long companyId, long classNameId,
7007                    OrderByComparator orderByComparator, boolean previous) {
7008                    StringBundler query = null;
7009    
7010                    if (orderByComparator != null) {
7011                            query = new StringBundler(6 +
7012                                            (orderByComparator.getOrderByFields().length * 6));
7013                    }
7014                    else {
7015                            query = new StringBundler(3);
7016                    }
7017    
7018                    query.append(_SQL_SELECT_DDMSTRUCTURE_WHERE);
7019    
7020                    query.append(_FINDER_COLUMN_C_C_COMPANYID_2);
7021    
7022                    query.append(_FINDER_COLUMN_C_C_CLASSNAMEID_2);
7023    
7024                    if (orderByComparator != null) {
7025                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
7026    
7027                            if (orderByConditionFields.length > 0) {
7028                                    query.append(WHERE_AND);
7029                            }
7030    
7031                            for (int i = 0; i < orderByConditionFields.length; i++) {
7032                                    query.append(_ORDER_BY_ENTITY_ALIAS);
7033                                    query.append(orderByConditionFields[i]);
7034    
7035                                    if ((i + 1) < orderByConditionFields.length) {
7036                                            if (orderByComparator.isAscending() ^ previous) {
7037                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
7038                                            }
7039                                            else {
7040                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
7041                                            }
7042                                    }
7043                                    else {
7044                                            if (orderByComparator.isAscending() ^ previous) {
7045                                                    query.append(WHERE_GREATER_THAN);
7046                                            }
7047                                            else {
7048                                                    query.append(WHERE_LESSER_THAN);
7049                                            }
7050                                    }
7051                            }
7052    
7053                            query.append(ORDER_BY_CLAUSE);
7054    
7055                            String[] orderByFields = orderByComparator.getOrderByFields();
7056    
7057                            for (int i = 0; i < orderByFields.length; i++) {
7058                                    query.append(_ORDER_BY_ENTITY_ALIAS);
7059                                    query.append(orderByFields[i]);
7060    
7061                                    if ((i + 1) < orderByFields.length) {
7062                                            if (orderByComparator.isAscending() ^ previous) {
7063                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
7064                                            }
7065                                            else {
7066                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
7067                                            }
7068                                    }
7069                                    else {
7070                                            if (orderByComparator.isAscending() ^ previous) {
7071                                                    query.append(ORDER_BY_ASC);
7072                                            }
7073                                            else {
7074                                                    query.append(ORDER_BY_DESC);
7075                                            }
7076                                    }
7077                            }
7078                    }
7079                    else {
7080                            query.append(DDMStructureModelImpl.ORDER_BY_JPQL);
7081                    }
7082    
7083                    String sql = query.toString();
7084    
7085                    Query q = session.createQuery(sql);
7086    
7087                    q.setFirstResult(0);
7088                    q.setMaxResults(2);
7089    
7090                    QueryPos qPos = QueryPos.getInstance(q);
7091    
7092                    qPos.add(companyId);
7093    
7094                    qPos.add(classNameId);
7095    
7096                    if (orderByComparator != null) {
7097                            Object[] values = orderByComparator.getOrderByConditionValues(ddmStructure);
7098    
7099                            for (Object value : values) {
7100                                    qPos.add(value);
7101                            }
7102                    }
7103    
7104                    List<DDMStructure> list = q.list();
7105    
7106                    if (list.size() == 2) {
7107                            return list.get(1);
7108                    }
7109                    else {
7110                            return null;
7111                    }
7112            }
7113    
7114            /**
7115             * Removes all the d d m structures where companyId = &#63; and classNameId = &#63; from the database.
7116             *
7117             * @param companyId the company ID
7118             * @param classNameId the class name ID
7119             * @throws SystemException if a system exception occurred
7120             */
7121            @Override
7122            public void removeByC_C(long companyId, long classNameId)
7123                    throws SystemException {
7124                    for (DDMStructure ddmStructure : findByC_C(companyId, classNameId,
7125                                    QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
7126                            remove(ddmStructure);
7127                    }
7128            }
7129    
7130            /**
7131             * Returns the number of d d m structures where companyId = &#63; and classNameId = &#63;.
7132             *
7133             * @param companyId the company ID
7134             * @param classNameId the class name ID
7135             * @return the number of matching d d m structures
7136             * @throws SystemException if a system exception occurred
7137             */
7138            @Override
7139            public int countByC_C(long companyId, long classNameId)
7140                    throws SystemException {
7141                    FinderPath finderPath = FINDER_PATH_COUNT_BY_C_C;
7142    
7143                    Object[] finderArgs = new Object[] { companyId, classNameId };
7144    
7145                    Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
7146                                    this);
7147    
7148                    if (count == null) {
7149                            StringBundler query = new StringBundler(3);
7150    
7151                            query.append(_SQL_COUNT_DDMSTRUCTURE_WHERE);
7152    
7153                            query.append(_FINDER_COLUMN_C_C_COMPANYID_2);
7154    
7155                            query.append(_FINDER_COLUMN_C_C_CLASSNAMEID_2);
7156    
7157                            String sql = query.toString();
7158    
7159                            Session session = null;
7160    
7161                            try {
7162                                    session = openSession();
7163    
7164                                    Query q = session.createQuery(sql);
7165    
7166                                    QueryPos qPos = QueryPos.getInstance(q);
7167    
7168                                    qPos.add(companyId);
7169    
7170                                    qPos.add(classNameId);
7171    
7172                                    count = (Long)q.uniqueResult();
7173    
7174                                    FinderCacheUtil.putResult(finderPath, finderArgs, count);
7175                            }
7176                            catch (Exception e) {
7177                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
7178    
7179                                    throw processException(e);
7180                            }
7181                            finally {
7182                                    closeSession(session);
7183                            }
7184                    }
7185    
7186                    return count.intValue();
7187            }
7188    
7189            private static final String _FINDER_COLUMN_C_C_COMPANYID_2 = "ddmStructure.companyId = ? AND ";
7190            private static final String _FINDER_COLUMN_C_C_CLASSNAMEID_2 = "ddmStructure.classNameId = ?";
7191            public static final FinderPath FINDER_PATH_FETCH_BY_G_C_S = new FinderPath(DDMStructureModelImpl.ENTITY_CACHE_ENABLED,
7192                            DDMStructureModelImpl.FINDER_CACHE_ENABLED, DDMStructureImpl.class,
7193                            FINDER_CLASS_NAME_ENTITY, "fetchByG_C_S",
7194                            new String[] {
7195                                    Long.class.getName(), Long.class.getName(),
7196                                    String.class.getName()
7197                            },
7198                            DDMStructureModelImpl.GROUPID_COLUMN_BITMASK |
7199                            DDMStructureModelImpl.CLASSNAMEID_COLUMN_BITMASK |
7200                            DDMStructureModelImpl.STRUCTUREKEY_COLUMN_BITMASK);
7201            public static final FinderPath FINDER_PATH_COUNT_BY_G_C_S = new FinderPath(DDMStructureModelImpl.ENTITY_CACHE_ENABLED,
7202                            DDMStructureModelImpl.FINDER_CACHE_ENABLED, Long.class,
7203                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByG_C_S",
7204                            new String[] {
7205                                    Long.class.getName(), Long.class.getName(),
7206                                    String.class.getName()
7207                            });
7208    
7209            /**
7210             * Returns the d d m structure where groupId = &#63; and classNameId = &#63; and structureKey = &#63; or throws a {@link com.liferay.portlet.dynamicdatamapping.NoSuchStructureException} if it could not be found.
7211             *
7212             * @param groupId the group ID
7213             * @param classNameId the class name ID
7214             * @param structureKey the structure key
7215             * @return the matching d d m structure
7216             * @throws com.liferay.portlet.dynamicdatamapping.NoSuchStructureException if a matching d d m structure could not be found
7217             * @throws SystemException if a system exception occurred
7218             */
7219            @Override
7220            public DDMStructure findByG_C_S(long groupId, long classNameId,
7221                    String structureKey) throws NoSuchStructureException, SystemException {
7222                    DDMStructure ddmStructure = fetchByG_C_S(groupId, classNameId,
7223                                    structureKey);
7224    
7225                    if (ddmStructure == null) {
7226                            StringBundler msg = new StringBundler(8);
7227    
7228                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
7229    
7230                            msg.append("groupId=");
7231                            msg.append(groupId);
7232    
7233                            msg.append(", classNameId=");
7234                            msg.append(classNameId);
7235    
7236                            msg.append(", structureKey=");
7237                            msg.append(structureKey);
7238    
7239                            msg.append(StringPool.CLOSE_CURLY_BRACE);
7240    
7241                            if (_log.isWarnEnabled()) {
7242                                    _log.warn(msg.toString());
7243                            }
7244    
7245                            throw new NoSuchStructureException(msg.toString());
7246                    }
7247    
7248                    return ddmStructure;
7249            }
7250    
7251            /**
7252             * Returns the d d m structure where groupId = &#63; and classNameId = &#63; and structureKey = &#63; or returns <code>null</code> if it could not be found. Uses the finder cache.
7253             *
7254             * @param groupId the group ID
7255             * @param classNameId the class name ID
7256             * @param structureKey the structure key
7257             * @return the matching d d m structure, or <code>null</code> if a matching d d m structure could not be found
7258             * @throws SystemException if a system exception occurred
7259             */
7260            @Override
7261            public DDMStructure fetchByG_C_S(long groupId, long classNameId,
7262                    String structureKey) throws SystemException {
7263                    return fetchByG_C_S(groupId, classNameId, structureKey, true);
7264            }
7265    
7266            /**
7267             * Returns the d d m structure where groupId = &#63; and classNameId = &#63; and structureKey = &#63; or returns <code>null</code> if it could not be found, optionally using the finder cache.
7268             *
7269             * @param groupId the group ID
7270             * @param classNameId the class name ID
7271             * @param structureKey the structure key
7272             * @param retrieveFromCache whether to use the finder cache
7273             * @return the matching d d m structure, or <code>null</code> if a matching d d m structure could not be found
7274             * @throws SystemException if a system exception occurred
7275             */
7276            @Override
7277            public DDMStructure fetchByG_C_S(long groupId, long classNameId,
7278                    String structureKey, boolean retrieveFromCache)
7279                    throws SystemException {
7280                    Object[] finderArgs = new Object[] { groupId, classNameId, structureKey };
7281    
7282                    Object result = null;
7283    
7284                    if (retrieveFromCache) {
7285                            result = FinderCacheUtil.getResult(FINDER_PATH_FETCH_BY_G_C_S,
7286                                            finderArgs, this);
7287                    }
7288    
7289                    if (result instanceof DDMStructure) {
7290                            DDMStructure ddmStructure = (DDMStructure)result;
7291    
7292                            if ((groupId != ddmStructure.getGroupId()) ||
7293                                            (classNameId != ddmStructure.getClassNameId()) ||
7294                                            !Validator.equals(structureKey,
7295                                                    ddmStructure.getStructureKey())) {
7296                                    result = null;
7297                            }
7298                    }
7299    
7300                    if (result == null) {
7301                            StringBundler query = new StringBundler(5);
7302    
7303                            query.append(_SQL_SELECT_DDMSTRUCTURE_WHERE);
7304    
7305                            query.append(_FINDER_COLUMN_G_C_S_GROUPID_2);
7306    
7307                            query.append(_FINDER_COLUMN_G_C_S_CLASSNAMEID_2);
7308    
7309                            boolean bindStructureKey = false;
7310    
7311                            if (structureKey == null) {
7312                                    query.append(_FINDER_COLUMN_G_C_S_STRUCTUREKEY_1);
7313                            }
7314                            else if (structureKey.equals(StringPool.BLANK)) {
7315                                    query.append(_FINDER_COLUMN_G_C_S_STRUCTUREKEY_3);
7316                            }
7317                            else {
7318                                    bindStructureKey = true;
7319    
7320                                    query.append(_FINDER_COLUMN_G_C_S_STRUCTUREKEY_2);
7321                            }
7322    
7323                            String sql = query.toString();
7324    
7325                            Session session = null;
7326    
7327                            try {
7328                                    session = openSession();
7329    
7330                                    Query q = session.createQuery(sql);
7331    
7332                                    QueryPos qPos = QueryPos.getInstance(q);
7333    
7334                                    qPos.add(groupId);
7335    
7336                                    qPos.add(classNameId);
7337    
7338                                    if (bindStructureKey) {
7339                                            qPos.add(structureKey);
7340                                    }
7341    
7342                                    List<DDMStructure> list = q.list();
7343    
7344                                    if (list.isEmpty()) {
7345                                            FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_G_C_S,
7346                                                    finderArgs, list);
7347                                    }
7348                                    else {
7349                                            DDMStructure ddmStructure = list.get(0);
7350    
7351                                            result = ddmStructure;
7352    
7353                                            cacheResult(ddmStructure);
7354    
7355                                            if ((ddmStructure.getGroupId() != groupId) ||
7356                                                            (ddmStructure.getClassNameId() != classNameId) ||
7357                                                            (ddmStructure.getStructureKey() == null) ||
7358                                                            !ddmStructure.getStructureKey().equals(structureKey)) {
7359                                                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_G_C_S,
7360                                                            finderArgs, ddmStructure);
7361                                            }
7362                                    }
7363                            }
7364                            catch (Exception e) {
7365                                    FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_G_C_S,
7366                                            finderArgs);
7367    
7368                                    throw processException(e);
7369                            }
7370                            finally {
7371                                    closeSession(session);
7372                            }
7373                    }
7374    
7375                    if (result instanceof List<?>) {
7376                            return null;
7377                    }
7378                    else {
7379                            return (DDMStructure)result;
7380                    }
7381            }
7382    
7383            /**
7384             * Removes the d d m structure where groupId = &#63; and classNameId = &#63; and structureKey = &#63; from the database.
7385             *
7386             * @param groupId the group ID
7387             * @param classNameId the class name ID
7388             * @param structureKey the structure key
7389             * @return the d d m structure that was removed
7390             * @throws SystemException if a system exception occurred
7391             */
7392            @Override
7393            public DDMStructure removeByG_C_S(long groupId, long classNameId,
7394                    String structureKey) throws NoSuchStructureException, SystemException {
7395                    DDMStructure ddmStructure = findByG_C_S(groupId, classNameId,
7396                                    structureKey);
7397    
7398                    return remove(ddmStructure);
7399            }
7400    
7401            /**
7402             * Returns the number of d d m structures where groupId = &#63; and classNameId = &#63; and structureKey = &#63;.
7403             *
7404             * @param groupId the group ID
7405             * @param classNameId the class name ID
7406             * @param structureKey the structure key
7407             * @return the number of matching d d m structures
7408             * @throws SystemException if a system exception occurred
7409             */
7410            @Override
7411            public int countByG_C_S(long groupId, long classNameId, String structureKey)
7412                    throws SystemException {
7413                    FinderPath finderPath = FINDER_PATH_COUNT_BY_G_C_S;
7414    
7415                    Object[] finderArgs = new Object[] { groupId, classNameId, structureKey };
7416    
7417                    Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
7418                                    this);
7419    
7420                    if (count == null) {
7421                            StringBundler query = new StringBundler(4);
7422    
7423                            query.append(_SQL_COUNT_DDMSTRUCTURE_WHERE);
7424    
7425                            query.append(_FINDER_COLUMN_G_C_S_GROUPID_2);
7426    
7427                            query.append(_FINDER_COLUMN_G_C_S_CLASSNAMEID_2);
7428    
7429                            boolean bindStructureKey = false;
7430    
7431                            if (structureKey == null) {
7432                                    query.append(_FINDER_COLUMN_G_C_S_STRUCTUREKEY_1);
7433                            }
7434                            else if (structureKey.equals(StringPool.BLANK)) {
7435                                    query.append(_FINDER_COLUMN_G_C_S_STRUCTUREKEY_3);
7436                            }
7437                            else {
7438                                    bindStructureKey = true;
7439    
7440                                    query.append(_FINDER_COLUMN_G_C_S_STRUCTUREKEY_2);
7441                            }
7442    
7443                            String sql = query.toString();
7444    
7445                            Session session = null;
7446    
7447                            try {
7448                                    session = openSession();
7449    
7450                                    Query q = session.createQuery(sql);
7451    
7452                                    QueryPos qPos = QueryPos.getInstance(q);
7453    
7454                                    qPos.add(groupId);
7455    
7456                                    qPos.add(classNameId);
7457    
7458                                    if (bindStructureKey) {
7459                                            qPos.add(structureKey);
7460                                    }
7461    
7462                                    count = (Long)q.uniqueResult();
7463    
7464                                    FinderCacheUtil.putResult(finderPath, finderArgs, count);
7465                            }
7466                            catch (Exception e) {
7467                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
7468    
7469                                    throw processException(e);
7470                            }
7471                            finally {
7472                                    closeSession(session);
7473                            }
7474                    }
7475    
7476                    return count.intValue();
7477            }
7478    
7479            private static final String _FINDER_COLUMN_G_C_S_GROUPID_2 = "ddmStructure.groupId = ? AND ";
7480            private static final String _FINDER_COLUMN_G_C_S_CLASSNAMEID_2 = "ddmStructure.classNameId = ? AND ";
7481            private static final String _FINDER_COLUMN_G_C_S_STRUCTUREKEY_1 = "ddmStructure.structureKey IS NULL";
7482            private static final String _FINDER_COLUMN_G_C_S_STRUCTUREKEY_2 = "ddmStructure.structureKey = ?";
7483            private static final String _FINDER_COLUMN_G_C_S_STRUCTUREKEY_3 = "(ddmStructure.structureKey IS NULL OR ddmStructure.structureKey = '')";
7484            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_G_N_D = new FinderPath(DDMStructureModelImpl.ENTITY_CACHE_ENABLED,
7485                            DDMStructureModelImpl.FINDER_CACHE_ENABLED, DDMStructureImpl.class,
7486                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByG_N_D",
7487                            new String[] {
7488                                    Long.class.getName(), String.class.getName(),
7489                                    String.class.getName(),
7490                                    
7491                            Integer.class.getName(), Integer.class.getName(),
7492                                    OrderByComparator.class.getName()
7493                            });
7494            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_N_D = new FinderPath(DDMStructureModelImpl.ENTITY_CACHE_ENABLED,
7495                            DDMStructureModelImpl.FINDER_CACHE_ENABLED, DDMStructureImpl.class,
7496                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByG_N_D",
7497                            new String[] {
7498                                    Long.class.getName(), String.class.getName(),
7499                                    String.class.getName()
7500                            },
7501                            DDMStructureModelImpl.GROUPID_COLUMN_BITMASK |
7502                            DDMStructureModelImpl.NAME_COLUMN_BITMASK |
7503                            DDMStructureModelImpl.DESCRIPTION_COLUMN_BITMASK);
7504            public static final FinderPath FINDER_PATH_COUNT_BY_G_N_D = new FinderPath(DDMStructureModelImpl.ENTITY_CACHE_ENABLED,
7505                            DDMStructureModelImpl.FINDER_CACHE_ENABLED, Long.class,
7506                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByG_N_D",
7507                            new String[] {
7508                                    Long.class.getName(), String.class.getName(),
7509                                    String.class.getName()
7510                            });
7511    
7512            /**
7513             * Returns all the d d m structures where groupId = &#63; and name = &#63; and description = &#63;.
7514             *
7515             * @param groupId the group ID
7516             * @param name the name
7517             * @param description the description
7518             * @return the matching d d m structures
7519             * @throws SystemException if a system exception occurred
7520             */
7521            @Override
7522            public List<DDMStructure> findByG_N_D(long groupId, String name,
7523                    String description) throws SystemException {
7524                    return findByG_N_D(groupId, name, description, QueryUtil.ALL_POS,
7525                            QueryUtil.ALL_POS, null);
7526            }
7527    
7528            /**
7529             * Returns a range of all the d d m structures where groupId = &#63; and name = &#63; and description = &#63;.
7530             *
7531             * <p>
7532             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portlet.dynamicdatamapping.model.impl.DDMStructureModelImpl}. 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.
7533             * </p>
7534             *
7535             * @param groupId the group ID
7536             * @param name the name
7537             * @param description the description
7538             * @param start the lower bound of the range of d d m structures
7539             * @param end the upper bound of the range of d d m structures (not inclusive)
7540             * @return the range of matching d d m structures
7541             * @throws SystemException if a system exception occurred
7542             */
7543            @Override
7544            public List<DDMStructure> findByG_N_D(long groupId, String name,
7545                    String description, int start, int end) throws SystemException {
7546                    return findByG_N_D(groupId, name, description, start, end, null);
7547            }
7548    
7549            /**
7550             * Returns an ordered range of all the d d m structures where groupId = &#63; and name = &#63; and description = &#63;.
7551             *
7552             * <p>
7553             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portlet.dynamicdatamapping.model.impl.DDMStructureModelImpl}. 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.
7554             * </p>
7555             *
7556             * @param groupId the group ID
7557             * @param name the name
7558             * @param description the description
7559             * @param start the lower bound of the range of d d m structures
7560             * @param end the upper bound of the range of d d m structures (not inclusive)
7561             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
7562             * @return the ordered range of matching d d m structures
7563             * @throws SystemException if a system exception occurred
7564             */
7565            @Override
7566            public List<DDMStructure> findByG_N_D(long groupId, String name,
7567                    String description, int start, int end,
7568                    OrderByComparator orderByComparator) throws SystemException {
7569                    boolean pagination = true;
7570                    FinderPath finderPath = null;
7571                    Object[] finderArgs = null;
7572    
7573                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
7574                                    (orderByComparator == null)) {
7575                            pagination = false;
7576                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_N_D;
7577                            finderArgs = new Object[] { groupId, name, description };
7578                    }
7579                    else {
7580                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_G_N_D;
7581                            finderArgs = new Object[] {
7582                                            groupId, name, description,
7583                                            
7584                                            start, end, orderByComparator
7585                                    };
7586                    }
7587    
7588                    List<DDMStructure> list = (List<DDMStructure>)FinderCacheUtil.getResult(finderPath,
7589                                    finderArgs, this);
7590    
7591                    if ((list != null) && !list.isEmpty()) {
7592                            for (DDMStructure ddmStructure : list) {
7593                                    if ((groupId != ddmStructure.getGroupId()) ||
7594                                                    !Validator.equals(name, ddmStructure.getName()) ||
7595                                                    !Validator.equals(description,
7596                                                            ddmStructure.getDescription())) {
7597                                            list = null;
7598    
7599                                            break;
7600                                    }
7601                            }
7602                    }
7603    
7604                    if (list == null) {
7605                            StringBundler query = null;
7606    
7607                            if (orderByComparator != null) {
7608                                    query = new StringBundler(5 +
7609                                                    (orderByComparator.getOrderByFields().length * 3));
7610                            }
7611                            else {
7612                                    query = new StringBundler(5);
7613                            }
7614    
7615                            query.append(_SQL_SELECT_DDMSTRUCTURE_WHERE);
7616    
7617                            query.append(_FINDER_COLUMN_G_N_D_GROUPID_2);
7618    
7619                            boolean bindName = false;
7620    
7621                            if (name == null) {
7622                                    query.append(_FINDER_COLUMN_G_N_D_NAME_1);
7623                            }
7624                            else if (name.equals(StringPool.BLANK)) {
7625                                    query.append(_FINDER_COLUMN_G_N_D_NAME_3);
7626                            }
7627                            else {
7628                                    bindName = true;
7629    
7630                                    query.append(_FINDER_COLUMN_G_N_D_NAME_2);
7631                            }
7632    
7633                            boolean bindDescription = false;
7634    
7635                            if (description == null) {
7636                                    query.append(_FINDER_COLUMN_G_N_D_DESCRIPTION_1);
7637                            }
7638                            else if (description.equals(StringPool.BLANK)) {
7639                                    query.append(_FINDER_COLUMN_G_N_D_DESCRIPTION_3);
7640                            }
7641                            else {
7642                                    bindDescription = true;
7643    
7644                                    query.append(_FINDER_COLUMN_G_N_D_DESCRIPTION_2);
7645                            }
7646    
7647                            if (orderByComparator != null) {
7648                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
7649                                            orderByComparator);
7650                            }
7651                            else
7652                             if (pagination) {
7653                                    query.append(DDMStructureModelImpl.ORDER_BY_JPQL);
7654                            }
7655    
7656                            String sql = query.toString();
7657    
7658                            Session session = null;
7659    
7660                            try {
7661                                    session = openSession();
7662    
7663                                    Query q = session.createQuery(sql);
7664    
7665                                    QueryPos qPos = QueryPos.getInstance(q);
7666    
7667                                    qPos.add(groupId);
7668    
7669                                    if (bindName) {
7670                                            qPos.add(name);
7671                                    }
7672    
7673                                    if (bindDescription) {
7674                                            qPos.add(description);
7675                                    }
7676    
7677                                    if (!pagination) {
7678                                            list = (List<DDMStructure>)QueryUtil.list(q, getDialect(),
7679                                                            start, end, false);
7680    
7681                                            Collections.sort(list);
7682    
7683                                            list = new UnmodifiableList<DDMStructure>(list);
7684                                    }
7685                                    else {
7686                                            list = (List<DDMStructure>)QueryUtil.list(q, getDialect(),
7687                                                            start, end);
7688                                    }
7689    
7690                                    cacheResult(list);
7691    
7692                                    FinderCacheUtil.putResult(finderPath, finderArgs, list);
7693                            }
7694                            catch (Exception e) {
7695                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
7696    
7697                                    throw processException(e);
7698                            }
7699                            finally {
7700                                    closeSession(session);
7701                            }
7702                    }
7703    
7704                    return list;
7705            }
7706    
7707            /**
7708             * Returns the first d d m structure in the ordered set where groupId = &#63; and name = &#63; and description = &#63;.
7709             *
7710             * @param groupId the group ID
7711             * @param name the name
7712             * @param description the description
7713             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
7714             * @return the first matching d d m structure
7715             * @throws com.liferay.portlet.dynamicdatamapping.NoSuchStructureException if a matching d d m structure could not be found
7716             * @throws SystemException if a system exception occurred
7717             */
7718            @Override
7719            public DDMStructure findByG_N_D_First(long groupId, String name,
7720                    String description, OrderByComparator orderByComparator)
7721                    throws NoSuchStructureException, SystemException {
7722                    DDMStructure ddmStructure = fetchByG_N_D_First(groupId, name,
7723                                    description, orderByComparator);
7724    
7725                    if (ddmStructure != null) {
7726                            return ddmStructure;
7727                    }
7728    
7729                    StringBundler msg = new StringBundler(8);
7730    
7731                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
7732    
7733                    msg.append("groupId=");
7734                    msg.append(groupId);
7735    
7736                    msg.append(", name=");
7737                    msg.append(name);
7738    
7739                    msg.append(", description=");
7740                    msg.append(description);
7741    
7742                    msg.append(StringPool.CLOSE_CURLY_BRACE);
7743    
7744                    throw new NoSuchStructureException(msg.toString());
7745            }
7746    
7747            /**
7748             * Returns the first d d m structure in the ordered set where groupId = &#63; and name = &#63; and description = &#63;.
7749             *
7750             * @param groupId the group ID
7751             * @param name the name
7752             * @param description the description
7753             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
7754             * @return the first matching d d m structure, or <code>null</code> if a matching d d m structure could not be found
7755             * @throws SystemException if a system exception occurred
7756             */
7757            @Override
7758            public DDMStructure fetchByG_N_D_First(long groupId, String name,
7759                    String description, OrderByComparator orderByComparator)
7760                    throws SystemException {
7761                    List<DDMStructure> list = findByG_N_D(groupId, name, description, 0, 1,
7762                                    orderByComparator);
7763    
7764                    if (!list.isEmpty()) {
7765                            return list.get(0);
7766                    }
7767    
7768                    return null;
7769            }
7770    
7771            /**
7772             * Returns the last d d m structure in the ordered set where groupId = &#63; and name = &#63; and description = &#63;.
7773             *
7774             * @param groupId the group ID
7775             * @param name the name
7776             * @param description the description
7777             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
7778             * @return the last matching d d m structure
7779             * @throws com.liferay.portlet.dynamicdatamapping.NoSuchStructureException if a matching d d m structure could not be found
7780             * @throws SystemException if a system exception occurred
7781             */
7782            @Override
7783            public DDMStructure findByG_N_D_Last(long groupId, String name,
7784                    String description, OrderByComparator orderByComparator)
7785                    throws NoSuchStructureException, SystemException {
7786                    DDMStructure ddmStructure = fetchByG_N_D_Last(groupId, name,
7787                                    description, orderByComparator);
7788    
7789                    if (ddmStructure != null) {
7790                            return ddmStructure;
7791                    }
7792    
7793                    StringBundler msg = new StringBundler(8);
7794    
7795                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
7796    
7797                    msg.append("groupId=");
7798                    msg.append(groupId);
7799    
7800                    msg.append(", name=");
7801                    msg.append(name);
7802    
7803                    msg.append(", description=");
7804                    msg.append(description);
7805    
7806                    msg.append(StringPool.CLOSE_CURLY_BRACE);
7807    
7808                    throw new NoSuchStructureException(msg.toString());
7809            }
7810    
7811            /**
7812             * Returns the last d d m structure in the ordered set where groupId = &#63; and name = &#63; and description = &#63;.
7813             *
7814             * @param groupId the group ID
7815             * @param name the name
7816             * @param description the description
7817             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
7818             * @return the last matching d d m structure, or <code>null</code> if a matching d d m structure could not be found
7819             * @throws SystemException if a system exception occurred
7820             */
7821            @Override
7822            public DDMStructure fetchByG_N_D_Last(long groupId, String name,
7823                    String description, OrderByComparator orderByComparator)
7824                    throws SystemException {
7825                    int count = countByG_N_D(groupId, name, description);
7826    
7827                    if (count == 0) {
7828                            return null;
7829                    }
7830    
7831                    List<DDMStructure> list = findByG_N_D(groupId, name, description,
7832                                    count - 1, count, orderByComparator);
7833    
7834                    if (!list.isEmpty()) {
7835                            return list.get(0);
7836                    }
7837    
7838                    return null;
7839            }
7840    
7841            /**
7842             * Returns the d d m structures before and after the current d d m structure in the ordered set where groupId = &#63; and name = &#63; and description = &#63;.
7843             *
7844             * @param structureId the primary key of the current d d m structure
7845             * @param groupId the group ID
7846             * @param name the name
7847             * @param description the description
7848             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
7849             * @return the previous, current, and next d d m structure
7850             * @throws com.liferay.portlet.dynamicdatamapping.NoSuchStructureException if a d d m structure with the primary key could not be found
7851             * @throws SystemException if a system exception occurred
7852             */
7853            @Override
7854            public DDMStructure[] findByG_N_D_PrevAndNext(long structureId,
7855                    long groupId, String name, String description,
7856                    OrderByComparator orderByComparator)
7857                    throws NoSuchStructureException, SystemException {
7858                    DDMStructure ddmStructure = findByPrimaryKey(structureId);
7859    
7860                    Session session = null;
7861    
7862                    try {
7863                            session = openSession();
7864    
7865                            DDMStructure[] array = new DDMStructureImpl[3];
7866    
7867                            array[0] = getByG_N_D_PrevAndNext(session, ddmStructure, groupId,
7868                                            name, description, orderByComparator, true);
7869    
7870                            array[1] = ddmStructure;
7871    
7872                            array[2] = getByG_N_D_PrevAndNext(session, ddmStructure, groupId,
7873                                            name, description, orderByComparator, false);
7874    
7875                            return array;
7876                    }
7877                    catch (Exception e) {
7878                            throw processException(e);
7879                    }
7880                    finally {
7881                            closeSession(session);
7882                    }
7883            }
7884    
7885            protected DDMStructure getByG_N_D_PrevAndNext(Session session,
7886                    DDMStructure ddmStructure, long groupId, String name,
7887                    String description, OrderByComparator orderByComparator,
7888                    boolean previous) {
7889                    StringBundler query = null;
7890    
7891                    if (orderByComparator != null) {
7892                            query = new StringBundler(6 +
7893                                            (orderByComparator.getOrderByFields().length * 6));
7894                    }
7895                    else {
7896                            query = new StringBundler(3);
7897                    }
7898    
7899                    query.append(_SQL_SELECT_DDMSTRUCTURE_WHERE);
7900    
7901                    query.append(_FINDER_COLUMN_G_N_D_GROUPID_2);
7902    
7903                    boolean bindName = false;
7904    
7905                    if (name == null) {
7906                            query.append(_FINDER_COLUMN_G_N_D_NAME_1);
7907                    }
7908                    else if (name.equals(StringPool.BLANK)) {
7909                            query.append(_FINDER_COLUMN_G_N_D_NAME_3);
7910                    }
7911                    else {
7912                            bindName = true;
7913    
7914                            query.append(_FINDER_COLUMN_G_N_D_NAME_2);
7915                    }
7916    
7917                    boolean bindDescription = false;
7918    
7919                    if (description == null) {
7920                            query.append(_FINDER_COLUMN_G_N_D_DESCRIPTION_1);
7921                    }
7922                    else if (description.equals(StringPool.BLANK)) {
7923                            query.append(_FINDER_COLUMN_G_N_D_DESCRIPTION_3);
7924                    }
7925                    else {
7926                            bindDescription = true;
7927    
7928                            query.append(_FINDER_COLUMN_G_N_D_DESCRIPTION_2);
7929                    }
7930    
7931                    if (orderByComparator != null) {
7932                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
7933    
7934                            if (orderByConditionFields.length > 0) {
7935                                    query.append(WHERE_AND);
7936                            }
7937    
7938                            for (int i = 0; i < orderByConditionFields.length; i++) {
7939                                    query.append(_ORDER_BY_ENTITY_ALIAS);
7940                                    query.append(orderByConditionFields[i]);
7941    
7942                                    if ((i + 1) < orderByConditionFields.length) {
7943                                            if (orderByComparator.isAscending() ^ previous) {
7944                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
7945                                            }
7946                                            else {
7947                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
7948                                            }
7949                                    }
7950                                    else {
7951                                            if (orderByComparator.isAscending() ^ previous) {
7952                                                    query.append(WHERE_GREATER_THAN);
7953                                            }
7954                                            else {
7955                                                    query.append(WHERE_LESSER_THAN);
7956                                            }
7957                                    }
7958                            }
7959    
7960                            query.append(ORDER_BY_CLAUSE);
7961    
7962                            String[] orderByFields = orderByComparator.getOrderByFields();
7963    
7964                            for (int i = 0; i < orderByFields.length; i++) {
7965                                    query.append(_ORDER_BY_ENTITY_ALIAS);
7966                                    query.append(orderByFields[i]);
7967    
7968                                    if ((i + 1) < orderByFields.length) {
7969                                            if (orderByComparator.isAscending() ^ previous) {
7970                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
7971                                            }
7972                                            else {
7973                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
7974                                            }
7975                                    }
7976                                    else {
7977                                            if (orderByComparator.isAscending() ^ previous) {
7978                                                    query.append(ORDER_BY_ASC);
7979                                            }
7980                                            else {
7981                                                    query.append(ORDER_BY_DESC);
7982                                            }
7983                                    }
7984                            }
7985                    }
7986                    else {
7987                            query.append(DDMStructureModelImpl.ORDER_BY_JPQL);
7988                    }
7989    
7990                    String sql = query.toString();
7991    
7992                    Query q = session.createQuery(sql);
7993    
7994                    q.setFirstResult(0);
7995                    q.setMaxResults(2);
7996    
7997                    QueryPos qPos = QueryPos.getInstance(q);
7998    
7999                    qPos.add(groupId);
8000    
8001                    if (bindName) {
8002                            qPos.add(name);
8003                    }
8004    
8005                    if (bindDescription) {
8006                            qPos.add(description);
8007                    }
8008    
8009                    if (orderByComparator != null) {
8010                            Object[] values = orderByComparator.getOrderByConditionValues(ddmStructure);
8011    
8012                            for (Object value : values) {
8013                                    qPos.add(value);
8014                            }
8015                    }
8016    
8017                    List<DDMStructure> list = q.list();
8018    
8019                    if (list.size() == 2) {
8020                            return list.get(1);
8021                    }
8022                    else {
8023                            return null;
8024                    }
8025            }
8026    
8027            /**
8028             * Returns all the d d m structures that the user has permission to view where groupId = &#63; and name = &#63; and description = &#63;.
8029             *
8030             * @param groupId the group ID
8031             * @param name the name
8032             * @param description the description
8033             * @return the matching d d m structures that the user has permission to view
8034             * @throws SystemException if a system exception occurred
8035             */
8036            @Override
8037            public List<DDMStructure> filterFindByG_N_D(long groupId, String name,
8038                    String description) throws SystemException {
8039                    return filterFindByG_N_D(groupId, name, description, QueryUtil.ALL_POS,
8040                            QueryUtil.ALL_POS, null);
8041            }
8042    
8043            /**
8044             * Returns a range of all the d d m structures that the user has permission to view where groupId = &#63; and name = &#63; and description = &#63;.
8045             *
8046             * <p>
8047             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portlet.dynamicdatamapping.model.impl.DDMStructureModelImpl}. 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.
8048             * </p>
8049             *
8050             * @param groupId the group ID
8051             * @param name the name
8052             * @param description the description
8053             * @param start the lower bound of the range of d d m structures
8054             * @param end the upper bound of the range of d d m structures (not inclusive)
8055             * @return the range of matching d d m structures that the user has permission to view
8056             * @throws SystemException if a system exception occurred
8057             */
8058            @Override
8059            public List<DDMStructure> filterFindByG_N_D(long groupId, String name,
8060                    String description, int start, int end) throws SystemException {
8061                    return filterFindByG_N_D(groupId, name, description, start, end, null);
8062            }
8063    
8064            /**
8065             * Returns an ordered range of all the d d m structures that the user has permissions to view where groupId = &#63; and name = &#63; and description = &#63;.
8066             *
8067             * <p>
8068             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portlet.dynamicdatamapping.model.impl.DDMStructureModelImpl}. 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.
8069             * </p>
8070             *
8071             * @param groupId the group ID
8072             * @param name the name
8073             * @param description the description
8074             * @param start the lower bound of the range of d d m structures
8075             * @param end the upper bound of the range of d d m structures (not inclusive)
8076             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
8077             * @return the ordered range of matching d d m structures that the user has permission to view
8078             * @throws SystemException if a system exception occurred
8079             */
8080            @Override
8081            public List<DDMStructure> filterFindByG_N_D(long groupId, String name,
8082                    String description, int start, int end,
8083                    OrderByComparator orderByComparator) throws SystemException {
8084                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
8085                            return findByG_N_D(groupId, name, description, start, end,
8086                                    orderByComparator);
8087                    }
8088    
8089                    StringBundler query = null;
8090    
8091                    if (orderByComparator != null) {
8092                            query = new StringBundler(5 +
8093                                            (orderByComparator.getOrderByFields().length * 3));
8094                    }
8095                    else {
8096                            query = new StringBundler(5);
8097                    }
8098    
8099                    if (getDB().isSupportsInlineDistinct()) {
8100                            query.append(_FILTER_SQL_SELECT_DDMSTRUCTURE_WHERE);
8101                    }
8102                    else {
8103                            query.append(_FILTER_SQL_SELECT_DDMSTRUCTURE_NO_INLINE_DISTINCT_WHERE_1);
8104                    }
8105    
8106                    query.append(_FINDER_COLUMN_G_N_D_GROUPID_2);
8107    
8108                    boolean bindName = false;
8109    
8110                    if (name == null) {
8111                            query.append(_FINDER_COLUMN_G_N_D_NAME_1);
8112                    }
8113                    else if (name.equals(StringPool.BLANK)) {
8114                            query.append(_FINDER_COLUMN_G_N_D_NAME_3);
8115                    }
8116                    else {
8117                            bindName = true;
8118    
8119                            query.append(_FINDER_COLUMN_G_N_D_NAME_2);
8120                    }
8121    
8122                    boolean bindDescription = false;
8123    
8124                    if (description == null) {
8125                            query.append(_FINDER_COLUMN_G_N_D_DESCRIPTION_1);
8126                    }
8127                    else if (description.equals(StringPool.BLANK)) {
8128                            query.append(_FINDER_COLUMN_G_N_D_DESCRIPTION_3);
8129                    }
8130                    else {
8131                            bindDescription = true;
8132    
8133                            query.append(_FINDER_COLUMN_G_N_D_DESCRIPTION_2);
8134                    }
8135    
8136                    if (!getDB().isSupportsInlineDistinct()) {
8137                            query.append(_FILTER_SQL_SELECT_DDMSTRUCTURE_NO_INLINE_DISTINCT_WHERE_2);
8138                    }
8139    
8140                    if (orderByComparator != null) {
8141                            if (getDB().isSupportsInlineDistinct()) {
8142                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
8143                                            orderByComparator, true);
8144                            }
8145                            else {
8146                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_TABLE,
8147                                            orderByComparator, true);
8148                            }
8149                    }
8150                    else {
8151                            if (getDB().isSupportsInlineDistinct()) {
8152                                    query.append(DDMStructureModelImpl.ORDER_BY_JPQL);
8153                            }
8154                            else {
8155                                    query.append(DDMStructureModelImpl.ORDER_BY_SQL);
8156                            }
8157                    }
8158    
8159                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
8160                                    DDMStructure.class.getName(),
8161                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
8162    
8163                    Session session = null;
8164    
8165                    try {
8166                            session = openSession();
8167    
8168                            SQLQuery q = session.createSQLQuery(sql);
8169    
8170                            if (getDB().isSupportsInlineDistinct()) {
8171                                    q.addEntity(_FILTER_ENTITY_ALIAS, DDMStructureImpl.class);
8172                            }
8173                            else {
8174                                    q.addEntity(_FILTER_ENTITY_TABLE, DDMStructureImpl.class);
8175                            }
8176    
8177                            QueryPos qPos = QueryPos.getInstance(q);
8178    
8179                            qPos.add(groupId);
8180    
8181                            if (bindName) {
8182                                    qPos.add(name);
8183                            }
8184    
8185                            if (bindDescription) {
8186                                    qPos.add(description);
8187                            }
8188    
8189                            return (List<DDMStructure>)QueryUtil.list(q, getDialect(), start,
8190                                    end);
8191                    }
8192                    catch (Exception e) {
8193                            throw processException(e);
8194                    }
8195                    finally {
8196                            closeSession(session);
8197                    }
8198            }
8199    
8200            /**
8201             * Returns the d d m structures before and after the current d d m structure in the ordered set of d d m structures that the user has permission to view where groupId = &#63; and name = &#63; and description = &#63;.
8202             *
8203             * @param structureId the primary key of the current d d m structure
8204             * @param groupId the group ID
8205             * @param name the name
8206             * @param description the description
8207             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
8208             * @return the previous, current, and next d d m structure
8209             * @throws com.liferay.portlet.dynamicdatamapping.NoSuchStructureException if a d d m structure with the primary key could not be found
8210             * @throws SystemException if a system exception occurred
8211             */
8212            @Override
8213            public DDMStructure[] filterFindByG_N_D_PrevAndNext(long structureId,
8214                    long groupId, String name, String description,
8215                    OrderByComparator orderByComparator)
8216                    throws NoSuchStructureException, SystemException {
8217                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
8218                            return findByG_N_D_PrevAndNext(structureId, groupId, name,
8219                                    description, orderByComparator);
8220                    }
8221    
8222                    DDMStructure ddmStructure = findByPrimaryKey(structureId);
8223    
8224                    Session session = null;
8225    
8226                    try {
8227                            session = openSession();
8228    
8229                            DDMStructure[] array = new DDMStructureImpl[3];
8230    
8231                            array[0] = filterGetByG_N_D_PrevAndNext(session, ddmStructure,
8232                                            groupId, name, description, orderByComparator, true);
8233    
8234                            array[1] = ddmStructure;
8235    
8236                            array[2] = filterGetByG_N_D_PrevAndNext(session, ddmStructure,
8237                                            groupId, name, description, orderByComparator, false);
8238    
8239                            return array;
8240                    }
8241                    catch (Exception e) {
8242                            throw processException(e);
8243                    }
8244                    finally {
8245                            closeSession(session);
8246                    }
8247            }
8248    
8249            protected DDMStructure filterGetByG_N_D_PrevAndNext(Session session,
8250                    DDMStructure ddmStructure, long groupId, String name,
8251                    String description, OrderByComparator orderByComparator,
8252                    boolean previous) {
8253                    StringBundler query = null;
8254    
8255                    if (orderByComparator != null) {
8256                            query = new StringBundler(6 +
8257                                            (orderByComparator.getOrderByFields().length * 6));
8258                    }
8259                    else {
8260                            query = new StringBundler(3);
8261                    }
8262    
8263                    if (getDB().isSupportsInlineDistinct()) {
8264                            query.append(_FILTER_SQL_SELECT_DDMSTRUCTURE_WHERE);
8265                    }
8266                    else {
8267                            query.append(_FILTER_SQL_SELECT_DDMSTRUCTURE_NO_INLINE_DISTINCT_WHERE_1);
8268                    }
8269    
8270                    query.append(_FINDER_COLUMN_G_N_D_GROUPID_2);
8271    
8272                    boolean bindName = false;
8273    
8274                    if (name == null) {
8275                            query.append(_FINDER_COLUMN_G_N_D_NAME_1);
8276                    }
8277                    else if (name.equals(StringPool.BLANK)) {
8278                            query.append(_FINDER_COLUMN_G_N_D_NAME_3);
8279                    }
8280                    else {
8281                            bindName = true;
8282    
8283                            query.append(_FINDER_COLUMN_G_N_D_NAME_2);
8284                    }
8285    
8286                    boolean bindDescription = false;
8287    
8288                    if (description == null) {
8289                            query.append(_FINDER_COLUMN_G_N_D_DESCRIPTION_1);
8290                    }
8291                    else if (description.equals(StringPool.BLANK)) {
8292                            query.append(_FINDER_COLUMN_G_N_D_DESCRIPTION_3);
8293                    }
8294                    else {
8295                            bindDescription = true;
8296    
8297                            query.append(_FINDER_COLUMN_G_N_D_DESCRIPTION_2);
8298                    }
8299    
8300                    if (!getDB().isSupportsInlineDistinct()) {
8301                            query.append(_FILTER_SQL_SELECT_DDMSTRUCTURE_NO_INLINE_DISTINCT_WHERE_2);
8302                    }
8303    
8304                    if (orderByComparator != null) {
8305                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
8306    
8307                            if (orderByConditionFields.length > 0) {
8308                                    query.append(WHERE_AND);
8309                            }
8310    
8311                            for (int i = 0; i < orderByConditionFields.length; i++) {
8312                                    if (getDB().isSupportsInlineDistinct()) {
8313                                            query.append(_ORDER_BY_ENTITY_ALIAS);
8314                                    }
8315                                    else {
8316                                            query.append(_ORDER_BY_ENTITY_TABLE);
8317                                    }
8318    
8319                                    query.append(orderByConditionFields[i]);
8320    
8321                                    if ((i + 1) < orderByConditionFields.length) {
8322                                            if (orderByComparator.isAscending() ^ previous) {
8323                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
8324                                            }
8325                                            else {
8326                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
8327                                            }
8328                                    }
8329                                    else {
8330                                            if (orderByComparator.isAscending() ^ previous) {
8331                                                    query.append(WHERE_GREATER_THAN);
8332                                            }
8333                                            else {
8334                                                    query.append(WHERE_LESSER_THAN);
8335                                            }
8336                                    }
8337                            }
8338    
8339                            query.append(ORDER_BY_CLAUSE);
8340    
8341                            String[] orderByFields = orderByComparator.getOrderByFields();
8342    
8343                            for (int i = 0; i < orderByFields.length; i++) {
8344                                    if (getDB().isSupportsInlineDistinct()) {
8345                                            query.append(_ORDER_BY_ENTITY_ALIAS);
8346                                    }
8347                                    else {
8348                                            query.append(_ORDER_BY_ENTITY_TABLE);
8349                                    }
8350    
8351                                    query.append(orderByFields[i]);
8352    
8353                                    if ((i + 1) < orderByFields.length) {
8354                                            if (orderByComparator.isAscending() ^ previous) {
8355                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
8356                                            }
8357                                            else {
8358                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
8359                                            }
8360                                    }
8361                                    else {
8362                                            if (orderByComparator.isAscending() ^ previous) {
8363                                                    query.append(ORDER_BY_ASC);
8364                                            }
8365                                            else {
8366                                                    query.append(ORDER_BY_DESC);
8367                                            }
8368                                    }
8369                            }
8370                    }
8371                    else {
8372                            if (getDB().isSupportsInlineDistinct()) {
8373                                    query.append(DDMStructureModelImpl.ORDER_BY_JPQL);
8374                            }
8375                            else {
8376                                    query.append(DDMStructureModelImpl.ORDER_BY_SQL);
8377                            }
8378                    }
8379    
8380                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
8381                                    DDMStructure.class.getName(),
8382                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
8383    
8384                    SQLQuery q = session.createSQLQuery(sql);
8385    
8386                    q.setFirstResult(0);
8387                    q.setMaxResults(2);
8388    
8389                    if (getDB().isSupportsInlineDistinct()) {
8390                            q.addEntity(_FILTER_ENTITY_ALIAS, DDMStructureImpl.class);
8391                    }
8392                    else {
8393                            q.addEntity(_FILTER_ENTITY_TABLE, DDMStructureImpl.class);
8394                    }
8395    
8396                    QueryPos qPos = QueryPos.getInstance(q);
8397    
8398                    qPos.add(groupId);
8399    
8400                    if (bindName) {
8401                            qPos.add(name);
8402                    }
8403    
8404                    if (bindDescription) {
8405                            qPos.add(description);
8406                    }
8407    
8408                    if (orderByComparator != null) {
8409                            Object[] values = orderByComparator.getOrderByConditionValues(ddmStructure);
8410    
8411                            for (Object value : values) {
8412                                    qPos.add(value);
8413                            }
8414                    }
8415    
8416                    List<DDMStructure> list = q.list();
8417    
8418                    if (list.size() == 2) {
8419                            return list.get(1);
8420                    }
8421                    else {
8422                            return null;
8423                    }
8424            }
8425    
8426            /**
8427             * Removes all the d d m structures where groupId = &#63; and name = &#63; and description = &#63; from the database.
8428             *
8429             * @param groupId the group ID
8430             * @param name the name
8431             * @param description the description
8432             * @throws SystemException if a system exception occurred
8433             */
8434            @Override
8435            public void removeByG_N_D(long groupId, String name, String description)
8436                    throws SystemException {
8437                    for (DDMStructure ddmStructure : findByG_N_D(groupId, name,
8438                                    description, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
8439                            remove(ddmStructure);
8440                    }
8441            }
8442    
8443            /**
8444             * Returns the number of d d m structures where groupId = &#63; and name = &#63; and description = &#63;.
8445             *
8446             * @param groupId the group ID
8447             * @param name the name
8448             * @param description the description
8449             * @return the number of matching d d m structures
8450             * @throws SystemException if a system exception occurred
8451             */
8452            @Override
8453            public int countByG_N_D(long groupId, String name, String description)
8454                    throws SystemException {
8455                    FinderPath finderPath = FINDER_PATH_COUNT_BY_G_N_D;
8456    
8457                    Object[] finderArgs = new Object[] { groupId, name, description };
8458    
8459                    Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
8460                                    this);
8461    
8462                    if (count == null) {
8463                            StringBundler query = new StringBundler(4);
8464    
8465                            query.append(_SQL_COUNT_DDMSTRUCTURE_WHERE);
8466    
8467                            query.append(_FINDER_COLUMN_G_N_D_GROUPID_2);
8468    
8469                            boolean bindName = false;
8470    
8471                            if (name == null) {
8472                                    query.append(_FINDER_COLUMN_G_N_D_NAME_1);
8473                            }
8474                            else if (name.equals(StringPool.BLANK)) {
8475                                    query.append(_FINDER_COLUMN_G_N_D_NAME_3);
8476                            }
8477                            else {
8478                                    bindName = true;
8479    
8480                                    query.append(_FINDER_COLUMN_G_N_D_NAME_2);
8481                            }
8482    
8483                            boolean bindDescription = false;
8484    
8485                            if (description == null) {
8486                                    query.append(_FINDER_COLUMN_G_N_D_DESCRIPTION_1);
8487                            }
8488                            else if (description.equals(StringPool.BLANK)) {
8489                                    query.append(_FINDER_COLUMN_G_N_D_DESCRIPTION_3);
8490                            }
8491                            else {
8492                                    bindDescription = true;
8493    
8494                                    query.append(_FINDER_COLUMN_G_N_D_DESCRIPTION_2);
8495                            }
8496    
8497                            String sql = query.toString();
8498    
8499                            Session session = null;
8500    
8501                            try {
8502                                    session = openSession();
8503    
8504                                    Query q = session.createQuery(sql);
8505    
8506                                    QueryPos qPos = QueryPos.getInstance(q);
8507    
8508                                    qPos.add(groupId);
8509    
8510                                    if (bindName) {
8511                                            qPos.add(name);
8512                                    }
8513    
8514                                    if (bindDescription) {
8515                                            qPos.add(description);
8516                                    }
8517    
8518                                    count = (Long)q.uniqueResult();
8519    
8520                                    FinderCacheUtil.putResult(finderPath, finderArgs, count);
8521                            }
8522                            catch (Exception e) {
8523                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
8524    
8525                                    throw processException(e);
8526                            }
8527                            finally {
8528                                    closeSession(session);
8529                            }
8530                    }
8531    
8532                    return count.intValue();
8533            }
8534    
8535            /**
8536             * Returns the number of d d m structures that the user has permission to view where groupId = &#63; and name = &#63; and description = &#63;.
8537             *
8538             * @param groupId the group ID
8539             * @param name the name
8540             * @param description the description
8541             * @return the number of matching d d m structures that the user has permission to view
8542             * @throws SystemException if a system exception occurred
8543             */
8544            @Override
8545            public int filterCountByG_N_D(long groupId, String name, String description)
8546                    throws SystemException {
8547                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
8548                            return countByG_N_D(groupId, name, description);
8549                    }
8550    
8551                    StringBundler query = new StringBundler(4);
8552    
8553                    query.append(_FILTER_SQL_COUNT_DDMSTRUCTURE_WHERE);
8554    
8555                    query.append(_FINDER_COLUMN_G_N_D_GROUPID_2);
8556    
8557                    boolean bindName = false;
8558    
8559                    if (name == null) {
8560                            query.append(_FINDER_COLUMN_G_N_D_NAME_1);
8561                    }
8562                    else if (name.equals(StringPool.BLANK)) {
8563                            query.append(_FINDER_COLUMN_G_N_D_NAME_3);
8564                    }
8565                    else {
8566                            bindName = true;
8567    
8568                            query.append(_FINDER_COLUMN_G_N_D_NAME_2);
8569                    }
8570    
8571                    boolean bindDescription = false;
8572    
8573                    if (description == null) {
8574                            query.append(_FINDER_COLUMN_G_N_D_DESCRIPTION_1);
8575                    }
8576                    else if (description.equals(StringPool.BLANK)) {
8577                            query.append(_FINDER_COLUMN_G_N_D_DESCRIPTION_3);
8578                    }
8579                    else {
8580                            bindDescription = true;
8581    
8582                            query.append(_FINDER_COLUMN_G_N_D_DESCRIPTION_2);
8583                    }
8584    
8585                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
8586                                    DDMStructure.class.getName(),
8587                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
8588    
8589                    Session session = null;
8590    
8591                    try {
8592                            session = openSession();
8593    
8594                            SQLQuery q = session.createSQLQuery(sql);
8595    
8596                            q.addScalar(COUNT_COLUMN_NAME,
8597                                    com.liferay.portal.kernel.dao.orm.Type.LONG);
8598    
8599                            QueryPos qPos = QueryPos.getInstance(q);
8600    
8601                            qPos.add(groupId);
8602    
8603                            if (bindName) {
8604                                    qPos.add(name);
8605                            }
8606    
8607                            if (bindDescription) {
8608                                    qPos.add(description);
8609                            }
8610    
8611                            Long count = (Long)q.uniqueResult();
8612    
8613                            return count.intValue();
8614                    }
8615                    catch (Exception e) {
8616                            throw processException(e);
8617                    }
8618                    finally {
8619                            closeSession(session);
8620                    }
8621            }
8622    
8623            private static final String _FINDER_COLUMN_G_N_D_GROUPID_2 = "ddmStructure.groupId = ? AND ";
8624            private static final String _FINDER_COLUMN_G_N_D_NAME_1 = "ddmStructure.name IS NULL AND ";
8625            private static final String _FINDER_COLUMN_G_N_D_NAME_2 = "ddmStructure.name = ? AND ";
8626            private static final String _FINDER_COLUMN_G_N_D_NAME_3 = "(ddmStructure.name IS NULL OR ddmStructure.name = '') AND ";
8627            private static final String _FINDER_COLUMN_G_N_D_DESCRIPTION_1 = "ddmStructure.description IS NULL";
8628            private static final String _FINDER_COLUMN_G_N_D_DESCRIPTION_2 = "ddmStructure.description = ?";
8629            private static final String _FINDER_COLUMN_G_N_D_DESCRIPTION_3 = "(ddmStructure.description IS NULL OR ddmStructure.description = '')";
8630    
8631            public DDMStructurePersistenceImpl() {
8632                    setModelClass(DDMStructure.class);
8633            }
8634    
8635            /**
8636             * Caches the d d m structure in the entity cache if it is enabled.
8637             *
8638             * @param ddmStructure the d d m structure
8639             */
8640            @Override
8641            public void cacheResult(DDMStructure ddmStructure) {
8642                    EntityCacheUtil.putResult(DDMStructureModelImpl.ENTITY_CACHE_ENABLED,
8643                            DDMStructureImpl.class, ddmStructure.getPrimaryKey(), ddmStructure);
8644    
8645                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_UUID_G,
8646                            new Object[] { ddmStructure.getUuid(), ddmStructure.getGroupId() },
8647                            ddmStructure);
8648    
8649                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_G_C_S,
8650                            new Object[] {
8651                                    ddmStructure.getGroupId(), ddmStructure.getClassNameId(),
8652                                    ddmStructure.getStructureKey()
8653                            }, ddmStructure);
8654    
8655                    ddmStructure.resetOriginalValues();
8656            }
8657    
8658            /**
8659             * Caches the d d m structures in the entity cache if it is enabled.
8660             *
8661             * @param ddmStructures the d d m structures
8662             */
8663            @Override
8664            public void cacheResult(List<DDMStructure> ddmStructures) {
8665                    for (DDMStructure ddmStructure : ddmStructures) {
8666                            if (EntityCacheUtil.getResult(
8667                                                    DDMStructureModelImpl.ENTITY_CACHE_ENABLED,
8668                                                    DDMStructureImpl.class, ddmStructure.getPrimaryKey()) == null) {
8669                                    cacheResult(ddmStructure);
8670                            }
8671                            else {
8672                                    ddmStructure.resetOriginalValues();
8673                            }
8674                    }
8675            }
8676    
8677            /**
8678             * Clears the cache for all d d m structures.
8679             *
8680             * <p>
8681             * The {@link com.liferay.portal.kernel.dao.orm.EntityCache} and {@link com.liferay.portal.kernel.dao.orm.FinderCache} are both cleared by this method.
8682             * </p>
8683             */
8684            @Override
8685            public void clearCache() {
8686                    if (_HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE) {
8687                            CacheRegistryUtil.clear(DDMStructureImpl.class.getName());
8688                    }
8689    
8690                    EntityCacheUtil.clearCache(DDMStructureImpl.class.getName());
8691    
8692                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_ENTITY);
8693                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
8694                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
8695            }
8696    
8697            /**
8698             * Clears the cache for the d d m structure.
8699             *
8700             * <p>
8701             * The {@link com.liferay.portal.kernel.dao.orm.EntityCache} and {@link com.liferay.portal.kernel.dao.orm.FinderCache} are both cleared by this method.
8702             * </p>
8703             */
8704            @Override
8705            public void clearCache(DDMStructure ddmStructure) {
8706                    EntityCacheUtil.removeResult(DDMStructureModelImpl.ENTITY_CACHE_ENABLED,
8707                            DDMStructureImpl.class, ddmStructure.getPrimaryKey());
8708    
8709                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
8710                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
8711    
8712                    clearUniqueFindersCache(ddmStructure);
8713            }
8714    
8715            @Override
8716            public void clearCache(List<DDMStructure> ddmStructures) {
8717                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
8718                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
8719    
8720                    for (DDMStructure ddmStructure : ddmStructures) {
8721                            EntityCacheUtil.removeResult(DDMStructureModelImpl.ENTITY_CACHE_ENABLED,
8722                                    DDMStructureImpl.class, ddmStructure.getPrimaryKey());
8723    
8724                            clearUniqueFindersCache(ddmStructure);
8725                    }
8726            }
8727    
8728            protected void cacheUniqueFindersCache(DDMStructure ddmStructure) {
8729                    if (ddmStructure.isNew()) {
8730                            Object[] args = new Object[] {
8731                                            ddmStructure.getUuid(), ddmStructure.getGroupId()
8732                                    };
8733    
8734                            FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_UUID_G, args,
8735                                    Long.valueOf(1));
8736                            FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_UUID_G, args,
8737                                    ddmStructure);
8738    
8739                            args = new Object[] {
8740                                            ddmStructure.getGroupId(), ddmStructure.getClassNameId(),
8741                                            ddmStructure.getStructureKey()
8742                                    };
8743    
8744                            FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_G_C_S, args,
8745                                    Long.valueOf(1));
8746                            FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_G_C_S, args,
8747                                    ddmStructure);
8748                    }
8749                    else {
8750                            DDMStructureModelImpl ddmStructureModelImpl = (DDMStructureModelImpl)ddmStructure;
8751    
8752                            if ((ddmStructureModelImpl.getColumnBitmask() &
8753                                            FINDER_PATH_FETCH_BY_UUID_G.getColumnBitmask()) != 0) {
8754                                    Object[] args = new Object[] {
8755                                                    ddmStructure.getUuid(), ddmStructure.getGroupId()
8756                                            };
8757    
8758                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_UUID_G, args,
8759                                            Long.valueOf(1));
8760                                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_UUID_G, args,
8761                                            ddmStructure);
8762                            }
8763    
8764                            if ((ddmStructureModelImpl.getColumnBitmask() &
8765                                            FINDER_PATH_FETCH_BY_G_C_S.getColumnBitmask()) != 0) {
8766                                    Object[] args = new Object[] {
8767                                                    ddmStructure.getGroupId(), ddmStructure.getClassNameId(),
8768                                                    ddmStructure.getStructureKey()
8769                                            };
8770    
8771                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_G_C_S, args,
8772                                            Long.valueOf(1));
8773                                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_G_C_S, args,
8774                                            ddmStructure);
8775                            }
8776                    }
8777            }
8778    
8779            protected void clearUniqueFindersCache(DDMStructure ddmStructure) {
8780                    DDMStructureModelImpl ddmStructureModelImpl = (DDMStructureModelImpl)ddmStructure;
8781    
8782                    Object[] args = new Object[] {
8783                                    ddmStructure.getUuid(), ddmStructure.getGroupId()
8784                            };
8785    
8786                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_UUID_G, args);
8787                    FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_UUID_G, args);
8788    
8789                    if ((ddmStructureModelImpl.getColumnBitmask() &
8790                                    FINDER_PATH_FETCH_BY_UUID_G.getColumnBitmask()) != 0) {
8791                            args = new Object[] {
8792                                            ddmStructureModelImpl.getOriginalUuid(),
8793                                            ddmStructureModelImpl.getOriginalGroupId()
8794                                    };
8795    
8796                            FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_UUID_G, args);
8797                            FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_UUID_G, args);
8798                    }
8799    
8800                    args = new Object[] {
8801                                    ddmStructure.getGroupId(), ddmStructure.getClassNameId(),
8802                                    ddmStructure.getStructureKey()
8803                            };
8804    
8805                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_G_C_S, args);
8806                    FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_G_C_S, args);
8807    
8808                    if ((ddmStructureModelImpl.getColumnBitmask() &
8809                                    FINDER_PATH_FETCH_BY_G_C_S.getColumnBitmask()) != 0) {
8810                            args = new Object[] {
8811                                            ddmStructureModelImpl.getOriginalGroupId(),
8812                                            ddmStructureModelImpl.getOriginalClassNameId(),
8813                                            ddmStructureModelImpl.getOriginalStructureKey()
8814                                    };
8815    
8816                            FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_G_C_S, args);
8817                            FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_G_C_S, args);
8818                    }
8819            }
8820    
8821            /**
8822             * Creates a new d d m structure with the primary key. Does not add the d d m structure to the database.
8823             *
8824             * @param structureId the primary key for the new d d m structure
8825             * @return the new d d m structure
8826             */
8827            @Override
8828            public DDMStructure create(long structureId) {
8829                    DDMStructure ddmStructure = new DDMStructureImpl();
8830    
8831                    ddmStructure.setNew(true);
8832                    ddmStructure.setPrimaryKey(structureId);
8833    
8834                    String uuid = PortalUUIDUtil.generate();
8835    
8836                    ddmStructure.setUuid(uuid);
8837    
8838                    return ddmStructure;
8839            }
8840    
8841            /**
8842             * Removes the d d m structure with the primary key from the database. Also notifies the appropriate model listeners.
8843             *
8844             * @param structureId the primary key of the d d m structure
8845             * @return the d d m structure that was removed
8846             * @throws com.liferay.portlet.dynamicdatamapping.NoSuchStructureException if a d d m structure with the primary key could not be found
8847             * @throws SystemException if a system exception occurred
8848             */
8849            @Override
8850            public DDMStructure remove(long structureId)
8851                    throws NoSuchStructureException, SystemException {
8852                    return remove((Serializable)structureId);
8853            }
8854    
8855            /**
8856             * Removes the d d m structure with the primary key from the database. Also notifies the appropriate model listeners.
8857             *
8858             * @param primaryKey the primary key of the d d m structure
8859             * @return the d d m structure that was removed
8860             * @throws com.liferay.portlet.dynamicdatamapping.NoSuchStructureException if a d d m structure with the primary key could not be found
8861             * @throws SystemException if a system exception occurred
8862             */
8863            @Override
8864            public DDMStructure remove(Serializable primaryKey)
8865                    throws NoSuchStructureException, SystemException {
8866                    Session session = null;
8867    
8868                    try {
8869                            session = openSession();
8870    
8871                            DDMStructure ddmStructure = (DDMStructure)session.get(DDMStructureImpl.class,
8872                                            primaryKey);
8873    
8874                            if (ddmStructure == null) {
8875                                    if (_log.isWarnEnabled()) {
8876                                            _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + primaryKey);
8877                                    }
8878    
8879                                    throw new NoSuchStructureException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
8880                                            primaryKey);
8881                            }
8882    
8883                            return remove(ddmStructure);
8884                    }
8885                    catch (NoSuchStructureException nsee) {
8886                            throw nsee;
8887                    }
8888                    catch (Exception e) {
8889                            throw processException(e);
8890                    }
8891                    finally {
8892                            closeSession(session);
8893                    }
8894            }
8895    
8896            @Override
8897            protected DDMStructure removeImpl(DDMStructure ddmStructure)
8898                    throws SystemException {
8899                    ddmStructure = toUnwrappedModel(ddmStructure);
8900    
8901                    ddmStructureToDLFileEntryTypeTableMapper.deleteLeftPrimaryKeyTableMappings(ddmStructure.getPrimaryKey());
8902    
8903                    Session session = null;
8904    
8905                    try {
8906                            session = openSession();
8907    
8908                            if (!session.contains(ddmStructure)) {
8909                                    ddmStructure = (DDMStructure)session.get(DDMStructureImpl.class,
8910                                                    ddmStructure.getPrimaryKeyObj());
8911                            }
8912    
8913                            if (ddmStructure != null) {
8914                                    session.delete(ddmStructure);
8915                            }
8916                    }
8917                    catch (Exception e) {
8918                            throw processException(e);
8919                    }
8920                    finally {
8921                            closeSession(session);
8922                    }
8923    
8924                    if (ddmStructure != null) {
8925                            clearCache(ddmStructure);
8926                    }
8927    
8928                    return ddmStructure;
8929            }
8930    
8931            @Override
8932            public DDMStructure updateImpl(
8933                    com.liferay.portlet.dynamicdatamapping.model.DDMStructure ddmStructure)
8934                    throws SystemException {
8935                    ddmStructure = toUnwrappedModel(ddmStructure);
8936    
8937                    boolean isNew = ddmStructure.isNew();
8938    
8939                    DDMStructureModelImpl ddmStructureModelImpl = (DDMStructureModelImpl)ddmStructure;
8940    
8941                    if (Validator.isNull(ddmStructure.getUuid())) {
8942                            String uuid = PortalUUIDUtil.generate();
8943    
8944                            ddmStructure.setUuid(uuid);
8945                    }
8946    
8947                    Session session = null;
8948    
8949                    try {
8950                            session = openSession();
8951    
8952                            if (ddmStructure.isNew()) {
8953                                    session.save(ddmStructure);
8954    
8955                                    ddmStructure.setNew(false);
8956                            }
8957                            else {
8958                                    session.merge(ddmStructure);
8959                            }
8960                    }
8961                    catch (Exception e) {
8962                            throw processException(e);
8963                    }
8964                    finally {
8965                            closeSession(session);
8966                    }
8967    
8968                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
8969    
8970                    if (isNew || !DDMStructureModelImpl.COLUMN_BITMASK_ENABLED) {
8971                            FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
8972                    }
8973    
8974                    else {
8975                            if ((ddmStructureModelImpl.getColumnBitmask() &
8976                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID.getColumnBitmask()) != 0) {
8977                                    Object[] args = new Object[] {
8978                                                    ddmStructureModelImpl.getOriginalUuid()
8979                                            };
8980    
8981                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_UUID, args);
8982                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID,
8983                                            args);
8984    
8985                                    args = new Object[] { ddmStructureModelImpl.getUuid() };
8986    
8987                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_UUID, args);
8988                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID,
8989                                            args);
8990                            }
8991    
8992                            if ((ddmStructureModelImpl.getColumnBitmask() &
8993                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID_C.getColumnBitmask()) != 0) {
8994                                    Object[] args = new Object[] {
8995                                                    ddmStructureModelImpl.getOriginalUuid(),
8996                                                    ddmStructureModelImpl.getOriginalCompanyId()
8997                                            };
8998    
8999                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_UUID_C, args);
9000                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID_C,
9001                                            args);
9002    
9003                                    args = new Object[] {
9004                                                    ddmStructureModelImpl.getUuid(),
9005                                                    ddmStructureModelImpl.getCompanyId()
9006                                            };
9007    
9008                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_UUID_C, args);
9009                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID_C,
9010                                            args);
9011                            }
9012    
9013                            if ((ddmStructureModelImpl.getColumnBitmask() &
9014                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_GROUPID.getColumnBitmask()) != 0) {
9015                                    Object[] args = new Object[] {
9016                                                    ddmStructureModelImpl.getOriginalGroupId()
9017                                            };
9018    
9019                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_GROUPID, args);
9020                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_GROUPID,
9021                                            args);
9022    
9023                                    args = new Object[] { ddmStructureModelImpl.getGroupId() };
9024    
9025                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_GROUPID, args);
9026                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_GROUPID,
9027                                            args);
9028                            }
9029    
9030                            if ((ddmStructureModelImpl.getColumnBitmask() &
9031                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_PARENTSTRUCTUREID.getColumnBitmask()) != 0) {
9032                                    Object[] args = new Object[] {
9033                                                    ddmStructureModelImpl.getOriginalParentStructureId()
9034                                            };
9035    
9036                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_PARENTSTRUCTUREID,
9037                                            args);
9038                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_PARENTSTRUCTUREID,
9039                                            args);
9040    
9041                                    args = new Object[] { ddmStructureModelImpl.getParentStructureId() };
9042    
9043                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_PARENTSTRUCTUREID,
9044                                            args);
9045                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_PARENTSTRUCTUREID,
9046                                            args);
9047                            }
9048    
9049                            if ((ddmStructureModelImpl.getColumnBitmask() &
9050                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_CLASSNAMEID.getColumnBitmask()) != 0) {
9051                                    Object[] args = new Object[] {
9052                                                    ddmStructureModelImpl.getOriginalClassNameId()
9053                                            };
9054    
9055                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_CLASSNAMEID,
9056                                            args);
9057                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_CLASSNAMEID,
9058                                            args);
9059    
9060                                    args = new Object[] { ddmStructureModelImpl.getClassNameId() };
9061    
9062                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_CLASSNAMEID,
9063                                            args);
9064                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_CLASSNAMEID,
9065                                            args);
9066                            }
9067    
9068                            if ((ddmStructureModelImpl.getColumnBitmask() &
9069                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_STRUCTUREKEY.getColumnBitmask()) != 0) {
9070                                    Object[] args = new Object[] {
9071                                                    ddmStructureModelImpl.getOriginalStructureKey()
9072                                            };
9073    
9074                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_STRUCTUREKEY,
9075                                            args);
9076                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_STRUCTUREKEY,
9077                                            args);
9078    
9079                                    args = new Object[] { ddmStructureModelImpl.getStructureKey() };
9080    
9081                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_STRUCTUREKEY,
9082                                            args);
9083                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_STRUCTUREKEY,
9084                                            args);
9085                            }
9086    
9087                            if ((ddmStructureModelImpl.getColumnBitmask() &
9088                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_P.getColumnBitmask()) != 0) {
9089                                    Object[] args = new Object[] {
9090                                                    ddmStructureModelImpl.getOriginalGroupId(),
9091                                                    ddmStructureModelImpl.getOriginalParentStructureId()
9092                                            };
9093    
9094                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_G_P, args);
9095                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_P,
9096                                            args);
9097    
9098                                    args = new Object[] {
9099                                                    ddmStructureModelImpl.getGroupId(),
9100                                                    ddmStructureModelImpl.getParentStructureId()
9101                                            };
9102    
9103                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_G_P, args);
9104                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_P,
9105                                            args);
9106                            }
9107    
9108                            if ((ddmStructureModelImpl.getColumnBitmask() &
9109                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_C.getColumnBitmask()) != 0) {
9110                                    Object[] args = new Object[] {
9111                                                    ddmStructureModelImpl.getOriginalGroupId(),
9112                                                    ddmStructureModelImpl.getOriginalClassNameId()
9113                                            };
9114    
9115                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_G_C, args);
9116                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_C,
9117                                            args);
9118    
9119                                    args = new Object[] {
9120                                                    ddmStructureModelImpl.getGroupId(),
9121                                                    ddmStructureModelImpl.getClassNameId()
9122                                            };
9123    
9124                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_G_C, args);
9125                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_C,
9126                                            args);
9127                            }
9128    
9129                            if ((ddmStructureModelImpl.getColumnBitmask() &
9130                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_C.getColumnBitmask()) != 0) {
9131                                    Object[] args = new Object[] {
9132                                                    ddmStructureModelImpl.getOriginalCompanyId(),
9133                                                    ddmStructureModelImpl.getOriginalClassNameId()
9134                                            };
9135    
9136                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_C_C, args);
9137                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_C,
9138                                            args);
9139    
9140                                    args = new Object[] {
9141                                                    ddmStructureModelImpl.getCompanyId(),
9142                                                    ddmStructureModelImpl.getClassNameId()
9143                                            };
9144    
9145                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_C_C, args);
9146                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_C,
9147                                            args);
9148                            }
9149    
9150                            if ((ddmStructureModelImpl.getColumnBitmask() &
9151                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_N_D.getColumnBitmask()) != 0) {
9152                                    Object[] args = new Object[] {
9153                                                    ddmStructureModelImpl.getOriginalGroupId(),
9154                                                    ddmStructureModelImpl.getOriginalName(),
9155                                                    ddmStructureModelImpl.getOriginalDescription()
9156                                            };
9157    
9158                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_G_N_D, args);
9159                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_N_D,
9160                                            args);
9161    
9162                                    args = new Object[] {
9163                                                    ddmStructureModelImpl.getGroupId(),
9164                                                    ddmStructureModelImpl.getName(),
9165                                                    ddmStructureModelImpl.getDescription()
9166                                            };
9167    
9168                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_G_N_D, args);
9169                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_N_D,
9170                                            args);
9171                            }
9172                    }
9173    
9174                    EntityCacheUtil.putResult(DDMStructureModelImpl.ENTITY_CACHE_ENABLED,
9175                            DDMStructureImpl.class, ddmStructure.getPrimaryKey(), ddmStructure);
9176    
9177                    clearUniqueFindersCache(ddmStructure);
9178                    cacheUniqueFindersCache(ddmStructure);
9179    
9180                    return ddmStructure;
9181            }
9182    
9183            protected DDMStructure toUnwrappedModel(DDMStructure ddmStructure) {
9184                    if (ddmStructure instanceof DDMStructureImpl) {
9185                            return ddmStructure;
9186                    }
9187    
9188                    DDMStructureImpl ddmStructureImpl = new DDMStructureImpl();
9189    
9190                    ddmStructureImpl.setNew(ddmStructure.isNew());
9191                    ddmStructureImpl.setPrimaryKey(ddmStructure.getPrimaryKey());
9192    
9193                    ddmStructureImpl.setUuid(ddmStructure.getUuid());
9194                    ddmStructureImpl.setStructureId(ddmStructure.getStructureId());
9195                    ddmStructureImpl.setGroupId(ddmStructure.getGroupId());
9196                    ddmStructureImpl.setCompanyId(ddmStructure.getCompanyId());
9197                    ddmStructureImpl.setUserId(ddmStructure.getUserId());
9198                    ddmStructureImpl.setUserName(ddmStructure.getUserName());
9199                    ddmStructureImpl.setCreateDate(ddmStructure.getCreateDate());
9200                    ddmStructureImpl.setModifiedDate(ddmStructure.getModifiedDate());
9201                    ddmStructureImpl.setParentStructureId(ddmStructure.getParentStructureId());
9202                    ddmStructureImpl.setClassNameId(ddmStructure.getClassNameId());
9203                    ddmStructureImpl.setStructureKey(ddmStructure.getStructureKey());
9204                    ddmStructureImpl.setName(ddmStructure.getName());
9205                    ddmStructureImpl.setDescription(ddmStructure.getDescription());
9206                    ddmStructureImpl.setXsd(ddmStructure.getXsd());
9207                    ddmStructureImpl.setStorageType(ddmStructure.getStorageType());
9208                    ddmStructureImpl.setType(ddmStructure.getType());
9209    
9210                    return ddmStructureImpl;
9211            }
9212    
9213            /**
9214             * Returns the d d m structure with the primary key or throws a {@link com.liferay.portal.NoSuchModelException} if it could not be found.
9215             *
9216             * @param primaryKey the primary key of the d d m structure
9217             * @return the d d m structure
9218             * @throws com.liferay.portlet.dynamicdatamapping.NoSuchStructureException if a d d m structure with the primary key could not be found
9219             * @throws SystemException if a system exception occurred
9220             */
9221            @Override
9222            public DDMStructure findByPrimaryKey(Serializable primaryKey)
9223                    throws NoSuchStructureException, SystemException {
9224                    DDMStructure ddmStructure = fetchByPrimaryKey(primaryKey);
9225    
9226                    if (ddmStructure == null) {
9227                            if (_log.isWarnEnabled()) {
9228                                    _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + primaryKey);
9229                            }
9230    
9231                            throw new NoSuchStructureException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
9232                                    primaryKey);
9233                    }
9234    
9235                    return ddmStructure;
9236            }
9237    
9238            /**
9239             * Returns the d d m structure with the primary key or throws a {@link com.liferay.portlet.dynamicdatamapping.NoSuchStructureException} if it could not be found.
9240             *
9241             * @param structureId the primary key of the d d m structure
9242             * @return the d d m structure
9243             * @throws com.liferay.portlet.dynamicdatamapping.NoSuchStructureException if a d d m structure with the primary key could not be found
9244             * @throws SystemException if a system exception occurred
9245             */
9246            @Override
9247            public DDMStructure findByPrimaryKey(long structureId)
9248                    throws NoSuchStructureException, SystemException {
9249                    return findByPrimaryKey((Serializable)structureId);
9250            }
9251    
9252            /**
9253             * Returns the d d m structure with the primary key or returns <code>null</code> if it could not be found.
9254             *
9255             * @param primaryKey the primary key of the d d m structure
9256             * @return the d d m structure, or <code>null</code> if a d d m structure with the primary key could not be found
9257             * @throws SystemException if a system exception occurred
9258             */
9259            @Override
9260            public DDMStructure fetchByPrimaryKey(Serializable primaryKey)
9261                    throws SystemException {
9262                    DDMStructure ddmStructure = (DDMStructure)EntityCacheUtil.getResult(DDMStructureModelImpl.ENTITY_CACHE_ENABLED,
9263                                    DDMStructureImpl.class, primaryKey);
9264    
9265                    if (ddmStructure == _nullDDMStructure) {
9266                            return null;
9267                    }
9268    
9269                    if (ddmStructure == null) {
9270                            Session session = null;
9271    
9272                            try {
9273                                    session = openSession();
9274    
9275                                    ddmStructure = (DDMStructure)session.get(DDMStructureImpl.class,
9276                                                    primaryKey);
9277    
9278                                    if (ddmStructure != null) {
9279                                            cacheResult(ddmStructure);
9280                                    }
9281                                    else {
9282                                            EntityCacheUtil.putResult(DDMStructureModelImpl.ENTITY_CACHE_ENABLED,
9283                                                    DDMStructureImpl.class, primaryKey, _nullDDMStructure);
9284                                    }
9285                            }
9286                            catch (Exception e) {
9287                                    EntityCacheUtil.removeResult(DDMStructureModelImpl.ENTITY_CACHE_ENABLED,
9288                                            DDMStructureImpl.class, primaryKey);
9289    
9290                                    throw processException(e);
9291                            }
9292                            finally {
9293                                    closeSession(session);
9294                            }
9295                    }
9296    
9297                    return ddmStructure;
9298            }
9299    
9300            /**
9301             * Returns the d d m structure with the primary key or returns <code>null</code> if it could not be found.
9302             *
9303             * @param structureId the primary key of the d d m structure
9304             * @return the d d m structure, or <code>null</code> if a d d m structure with the primary key could not be found
9305             * @throws SystemException if a system exception occurred
9306             */
9307            @Override
9308            public DDMStructure fetchByPrimaryKey(long structureId)
9309                    throws SystemException {
9310                    return fetchByPrimaryKey((Serializable)structureId);
9311            }
9312    
9313            /**
9314             * Returns all the d d m structures.
9315             *
9316             * @return the d d m structures
9317             * @throws SystemException if a system exception occurred
9318             */
9319            @Override
9320            public List<DDMStructure> findAll() throws SystemException {
9321                    return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
9322            }
9323    
9324            /**
9325             * Returns a range of all the d d m structures.
9326             *
9327             * <p>
9328             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portlet.dynamicdatamapping.model.impl.DDMStructureModelImpl}. 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.
9329             * </p>
9330             *
9331             * @param start the lower bound of the range of d d m structures
9332             * @param end the upper bound of the range of d d m structures (not inclusive)
9333             * @return the range of d d m structures
9334             * @throws SystemException if a system exception occurred
9335             */
9336            @Override
9337            public List<DDMStructure> findAll(int start, int end)
9338                    throws SystemException {
9339                    return findAll(start, end, null);
9340            }
9341    
9342            /**
9343             * Returns an ordered range of all the d d m structures.
9344             *
9345             * <p>
9346             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portlet.dynamicdatamapping.model.impl.DDMStructureModelImpl}. 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.
9347             * </p>
9348             *
9349             * @param start the lower bound of the range of d d m structures
9350             * @param end the upper bound of the range of d d m structures (not inclusive)
9351             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
9352             * @return the ordered range of d d m structures
9353             * @throws SystemException if a system exception occurred
9354             */
9355            @Override
9356            public List<DDMStructure> findAll(int start, int end,
9357                    OrderByComparator orderByComparator) throws SystemException {
9358                    boolean pagination = true;
9359                    FinderPath finderPath = null;
9360                    Object[] finderArgs = null;
9361    
9362                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
9363                                    (orderByComparator == null)) {
9364                            pagination = false;
9365                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL;
9366                            finderArgs = FINDER_ARGS_EMPTY;
9367                    }
9368                    else {
9369                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_ALL;
9370                            finderArgs = new Object[] { start, end, orderByComparator };
9371                    }
9372    
9373                    List<DDMStructure> list = (List<DDMStructure>)FinderCacheUtil.getResult(finderPath,
9374                                    finderArgs, this);
9375    
9376                    if (list == null) {
9377                            StringBundler query = null;
9378                            String sql = null;
9379    
9380                            if (orderByComparator != null) {
9381                                    query = new StringBundler(2 +
9382                                                    (orderByComparator.getOrderByFields().length * 3));
9383    
9384                                    query.append(_SQL_SELECT_DDMSTRUCTURE);
9385    
9386                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
9387                                            orderByComparator);
9388    
9389                                    sql = query.toString();
9390                            }
9391                            else {
9392                                    sql = _SQL_SELECT_DDMSTRUCTURE;
9393    
9394                                    if (pagination) {
9395                                            sql = sql.concat(DDMStructureModelImpl.ORDER_BY_JPQL);
9396                                    }
9397                            }
9398    
9399                            Session session = null;
9400    
9401                            try {
9402                                    session = openSession();
9403    
9404                                    Query q = session.createQuery(sql);
9405    
9406                                    if (!pagination) {
9407                                            list = (List<DDMStructure>)QueryUtil.list(q, getDialect(),
9408                                                            start, end, false);
9409    
9410                                            Collections.sort(list);
9411    
9412                                            list = new UnmodifiableList<DDMStructure>(list);
9413                                    }
9414                                    else {
9415                                            list = (List<DDMStructure>)QueryUtil.list(q, getDialect(),
9416                                                            start, end);
9417                                    }
9418    
9419                                    cacheResult(list);
9420    
9421                                    FinderCacheUtil.putResult(finderPath, finderArgs, list);
9422                            }
9423                            catch (Exception e) {
9424                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
9425    
9426                                    throw processException(e);
9427                            }
9428                            finally {
9429                                    closeSession(session);
9430                            }
9431                    }
9432    
9433                    return list;
9434            }
9435    
9436            /**
9437             * Removes all the d d m structures from the database.
9438             *
9439             * @throws SystemException if a system exception occurred
9440             */
9441            @Override
9442            public void removeAll() throws SystemException {
9443                    for (DDMStructure ddmStructure : findAll()) {
9444                            remove(ddmStructure);
9445                    }
9446            }
9447    
9448            /**
9449             * Returns the number of d d m structures.
9450             *
9451             * @return the number of d d m structures
9452             * @throws SystemException if a system exception occurred
9453             */
9454            @Override
9455            public int countAll() throws SystemException {
9456                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_ALL,
9457                                    FINDER_ARGS_EMPTY, this);
9458    
9459                    if (count == null) {
9460                            Session session = null;
9461    
9462                            try {
9463                                    session = openSession();
9464    
9465                                    Query q = session.createQuery(_SQL_COUNT_DDMSTRUCTURE);
9466    
9467                                    count = (Long)q.uniqueResult();
9468    
9469                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_ALL,
9470                                            FINDER_ARGS_EMPTY, count);
9471                            }
9472                            catch (Exception e) {
9473                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_ALL,
9474                                            FINDER_ARGS_EMPTY);
9475    
9476                                    throw processException(e);
9477                            }
9478                            finally {
9479                                    closeSession(session);
9480                            }
9481                    }
9482    
9483                    return count.intValue();
9484            }
9485    
9486            /**
9487             * Returns all the document library file entry types associated with the d d m structure.
9488             *
9489             * @param pk the primary key of the d d m structure
9490             * @return the document library file entry types associated with the d d m structure
9491             * @throws SystemException if a system exception occurred
9492             */
9493            @Override
9494            public List<com.liferay.portlet.documentlibrary.model.DLFileEntryType> getDLFileEntryTypes(
9495                    long pk) throws SystemException {
9496                    return getDLFileEntryTypes(pk, QueryUtil.ALL_POS, QueryUtil.ALL_POS);
9497            }
9498    
9499            /**
9500             * Returns a range of all the document library file entry types associated with the d d m structure.
9501             *
9502             * <p>
9503             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portlet.dynamicdatamapping.model.impl.DDMStructureModelImpl}. 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.
9504             * </p>
9505             *
9506             * @param pk the primary key of the d d m structure
9507             * @param start the lower bound of the range of d d m structures
9508             * @param end the upper bound of the range of d d m structures (not inclusive)
9509             * @return the range of document library file entry types associated with the d d m structure
9510             * @throws SystemException if a system exception occurred
9511             */
9512            @Override
9513            public List<com.liferay.portlet.documentlibrary.model.DLFileEntryType> getDLFileEntryTypes(
9514                    long pk, int start, int end) throws SystemException {
9515                    return getDLFileEntryTypes(pk, start, end, null);
9516            }
9517    
9518            /**
9519             * Returns an ordered range of all the document library file entry types associated with the d d m structure.
9520             *
9521             * <p>
9522             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portlet.dynamicdatamapping.model.impl.DDMStructureModelImpl}. 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.
9523             * </p>
9524             *
9525             * @param pk the primary key of the d d m structure
9526             * @param start the lower bound of the range of d d m structures
9527             * @param end the upper bound of the range of d d m structures (not inclusive)
9528             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
9529             * @return the ordered range of document library file entry types associated with the d d m structure
9530             * @throws SystemException if a system exception occurred
9531             */
9532            @Override
9533            public List<com.liferay.portlet.documentlibrary.model.DLFileEntryType> getDLFileEntryTypes(
9534                    long pk, int start, int end, OrderByComparator orderByComparator)
9535                    throws SystemException {
9536                    return ddmStructureToDLFileEntryTypeTableMapper.getRightBaseModels(pk,
9537                            start, end, orderByComparator);
9538            }
9539    
9540            /**
9541             * Returns the number of document library file entry types associated with the d d m structure.
9542             *
9543             * @param pk the primary key of the d d m structure
9544             * @return the number of document library file entry types associated with the d d m structure
9545             * @throws SystemException if a system exception occurred
9546             */
9547            @Override
9548            public int getDLFileEntryTypesSize(long pk) throws SystemException {
9549                    long[] pks = ddmStructureToDLFileEntryTypeTableMapper.getRightPrimaryKeys(pk);
9550    
9551                    return pks.length;
9552            }
9553    
9554            /**
9555             * Returns <code>true</code> if the document library file entry type is associated with the d d m structure.
9556             *
9557             * @param pk the primary key of the d d m structure
9558             * @param dlFileEntryTypePK the primary key of the document library file entry type
9559             * @return <code>true</code> if the document library file entry type is associated with the d d m structure; <code>false</code> otherwise
9560             * @throws SystemException if a system exception occurred
9561             */
9562            @Override
9563            public boolean containsDLFileEntryType(long pk, long dlFileEntryTypePK)
9564                    throws SystemException {
9565                    return ddmStructureToDLFileEntryTypeTableMapper.containsTableMapping(pk,
9566                            dlFileEntryTypePK);
9567            }
9568    
9569            /**
9570             * Returns <code>true</code> if the d d m structure has any document library file entry types associated with it.
9571             *
9572             * @param pk the primary key of the d d m structure to check for associations with document library file entry types
9573             * @return <code>true</code> if the d d m structure has any document library file entry types associated with it; <code>false</code> otherwise
9574             * @throws SystemException if a system exception occurred
9575             */
9576            @Override
9577            public boolean containsDLFileEntryTypes(long pk) throws SystemException {
9578                    if (getDLFileEntryTypesSize(pk) > 0) {
9579                            return true;
9580                    }
9581                    else {
9582                            return false;
9583                    }
9584            }
9585    
9586            /**
9587             * Adds an association between the d d m structure and the document library file entry type. Also notifies the appropriate model listeners and clears the mapping table finder cache.
9588             *
9589             * @param pk the primary key of the d d m structure
9590             * @param dlFileEntryTypePK the primary key of the document library file entry type
9591             * @throws SystemException if a system exception occurred
9592             */
9593            @Override
9594            public void addDLFileEntryType(long pk, long dlFileEntryTypePK)
9595                    throws SystemException {
9596                    ddmStructureToDLFileEntryTypeTableMapper.addTableMapping(pk,
9597                            dlFileEntryTypePK);
9598            }
9599    
9600            /**
9601             * Adds an association between the d d m structure and the document library file entry type. Also notifies the appropriate model listeners and clears the mapping table finder cache.
9602             *
9603             * @param pk the primary key of the d d m structure
9604             * @param dlFileEntryType the document library file entry type
9605             * @throws SystemException if a system exception occurred
9606             */
9607            @Override
9608            public void addDLFileEntryType(long pk,
9609                    com.liferay.portlet.documentlibrary.model.DLFileEntryType dlFileEntryType)
9610                    throws SystemException {
9611                    ddmStructureToDLFileEntryTypeTableMapper.addTableMapping(pk,
9612                            dlFileEntryType.getPrimaryKey());
9613            }
9614    
9615            /**
9616             * Adds an association between the d d m structure and the document library file entry types. Also notifies the appropriate model listeners and clears the mapping table finder cache.
9617             *
9618             * @param pk the primary key of the d d m structure
9619             * @param dlFileEntryTypePKs the primary keys of the document library file entry types
9620             * @throws SystemException if a system exception occurred
9621             */
9622            @Override
9623            public void addDLFileEntryTypes(long pk, long[] dlFileEntryTypePKs)
9624                    throws SystemException {
9625                    for (long dlFileEntryTypePK : dlFileEntryTypePKs) {
9626                            ddmStructureToDLFileEntryTypeTableMapper.addTableMapping(pk,
9627                                    dlFileEntryTypePK);
9628                    }
9629            }
9630    
9631            /**
9632             * Adds an association between the d d m structure and the document library file entry types. Also notifies the appropriate model listeners and clears the mapping table finder cache.
9633             *
9634             * @param pk the primary key of the d d m structure
9635             * @param dlFileEntryTypes the document library file entry types
9636             * @throws SystemException if a system exception occurred
9637             */
9638            @Override
9639            public void addDLFileEntryTypes(long pk,
9640                    List<com.liferay.portlet.documentlibrary.model.DLFileEntryType> dlFileEntryTypes)
9641                    throws SystemException {
9642                    for (com.liferay.portlet.documentlibrary.model.DLFileEntryType dlFileEntryType : dlFileEntryTypes) {
9643                            ddmStructureToDLFileEntryTypeTableMapper.addTableMapping(pk,
9644                                    dlFileEntryType.getPrimaryKey());
9645                    }
9646            }
9647    
9648            /**
9649             * Clears all associations between the d d m structure and its document library file entry types. Also notifies the appropriate model listeners and clears the mapping table finder cache.
9650             *
9651             * @param pk the primary key of the d d m structure to clear the associated document library file entry types from
9652             * @throws SystemException if a system exception occurred
9653             */
9654            @Override
9655            public void clearDLFileEntryTypes(long pk) throws SystemException {
9656                    ddmStructureToDLFileEntryTypeTableMapper.deleteLeftPrimaryKeyTableMappings(pk);
9657            }
9658    
9659            /**
9660             * Removes the association between the d d m structure and the document library file entry type. Also notifies the appropriate model listeners and clears the mapping table finder cache.
9661             *
9662             * @param pk the primary key of the d d m structure
9663             * @param dlFileEntryTypePK the primary key of the document library file entry type
9664             * @throws SystemException if a system exception occurred
9665             */
9666            @Override
9667            public void removeDLFileEntryType(long pk, long dlFileEntryTypePK)
9668                    throws SystemException {
9669                    ddmStructureToDLFileEntryTypeTableMapper.deleteTableMapping(pk,
9670                            dlFileEntryTypePK);
9671            }
9672    
9673            /**
9674             * Removes the association between the d d m structure and the document library file entry type. Also notifies the appropriate model listeners and clears the mapping table finder cache.
9675             *
9676             * @param pk the primary key of the d d m structure
9677             * @param dlFileEntryType the document library file entry type
9678             * @throws SystemException if a system exception occurred
9679             */
9680            @Override
9681            public void removeDLFileEntryType(long pk,
9682                    com.liferay.portlet.documentlibrary.model.DLFileEntryType dlFileEntryType)
9683                    throws SystemException {
9684                    ddmStructureToDLFileEntryTypeTableMapper.deleteTableMapping(pk,
9685                            dlFileEntryType.getPrimaryKey());
9686            }
9687    
9688            /**
9689             * Removes the association between the d d m structure and the document library file entry types. Also notifies the appropriate model listeners and clears the mapping table finder cache.
9690             *
9691             * @param pk the primary key of the d d m structure
9692             * @param dlFileEntryTypePKs the primary keys of the document library file entry types
9693             * @throws SystemException if a system exception occurred
9694             */
9695            @Override
9696            public void removeDLFileEntryTypes(long pk, long[] dlFileEntryTypePKs)
9697                    throws SystemException {
9698                    for (long dlFileEntryTypePK : dlFileEntryTypePKs) {
9699                            ddmStructureToDLFileEntryTypeTableMapper.deleteTableMapping(pk,
9700                                    dlFileEntryTypePK);
9701                    }
9702            }
9703    
9704            /**
9705             * Removes the association between the d d m structure and the document library file entry types. Also notifies the appropriate model listeners and clears the mapping table finder cache.
9706             *
9707             * @param pk the primary key of the d d m structure
9708             * @param dlFileEntryTypes the document library file entry types
9709             * @throws SystemException if a system exception occurred
9710             */
9711            @Override
9712            public void removeDLFileEntryTypes(long pk,
9713                    List<com.liferay.portlet.documentlibrary.model.DLFileEntryType> dlFileEntryTypes)
9714                    throws SystemException {
9715                    for (com.liferay.portlet.documentlibrary.model.DLFileEntryType dlFileEntryType : dlFileEntryTypes) {
9716                            ddmStructureToDLFileEntryTypeTableMapper.deleteTableMapping(pk,
9717                                    dlFileEntryType.getPrimaryKey());
9718                    }
9719            }
9720    
9721            /**
9722             * Sets the document library file entry types associated with the d d m structure, removing and adding associations as necessary. Also notifies the appropriate model listeners and clears the mapping table finder cache.
9723             *
9724             * @param pk the primary key of the d d m structure
9725             * @param dlFileEntryTypePKs the primary keys of the document library file entry types to be associated with the d d m structure
9726             * @throws SystemException if a system exception occurred
9727             */
9728            @Override
9729            public void setDLFileEntryTypes(long pk, long[] dlFileEntryTypePKs)
9730                    throws SystemException {
9731                    Set<Long> newDLFileEntryTypePKsSet = SetUtil.fromArray(dlFileEntryTypePKs);
9732                    Set<Long> oldDLFileEntryTypePKsSet = SetUtil.fromArray(ddmStructureToDLFileEntryTypeTableMapper.getRightPrimaryKeys(
9733                                            pk));
9734    
9735                    Set<Long> removeDLFileEntryTypePKsSet = new HashSet<Long>(oldDLFileEntryTypePKsSet);
9736    
9737                    removeDLFileEntryTypePKsSet.removeAll(newDLFileEntryTypePKsSet);
9738    
9739                    for (long removeDLFileEntryTypePK : removeDLFileEntryTypePKsSet) {
9740                            ddmStructureToDLFileEntryTypeTableMapper.deleteTableMapping(pk,
9741                                    removeDLFileEntryTypePK);
9742                    }
9743    
9744                    newDLFileEntryTypePKsSet.removeAll(oldDLFileEntryTypePKsSet);
9745    
9746                    for (long newDLFileEntryTypePK : newDLFileEntryTypePKsSet) {
9747                            ddmStructureToDLFileEntryTypeTableMapper.addTableMapping(pk,
9748                                    newDLFileEntryTypePK);
9749                    }
9750            }
9751    
9752            /**
9753             * Sets the document library file entry types associated with the d d m structure, removing and adding associations as necessary. Also notifies the appropriate model listeners and clears the mapping table finder cache.
9754             *
9755             * @param pk the primary key of the d d m structure
9756             * @param dlFileEntryTypes the document library file entry types to be associated with the d d m structure
9757             * @throws SystemException if a system exception occurred
9758             */
9759            @Override
9760            public void setDLFileEntryTypes(long pk,
9761                    List<com.liferay.portlet.documentlibrary.model.DLFileEntryType> dlFileEntryTypes)
9762                    throws SystemException {
9763                    try {
9764                            long[] dlFileEntryTypePKs = new long[dlFileEntryTypes.size()];
9765    
9766                            for (int i = 0; i < dlFileEntryTypes.size(); i++) {
9767                                    com.liferay.portlet.documentlibrary.model.DLFileEntryType dlFileEntryType =
9768                                            dlFileEntryTypes.get(i);
9769    
9770                                    dlFileEntryTypePKs[i] = dlFileEntryType.getPrimaryKey();
9771                            }
9772    
9773                            setDLFileEntryTypes(pk, dlFileEntryTypePKs);
9774                    }
9775                    catch (Exception e) {
9776                            throw processException(e);
9777                    }
9778                    finally {
9779                            FinderCacheUtil.clearCache(DDMStructureModelImpl.MAPPING_TABLE_DLFILEENTRYTYPES_DDMSTRUCTURES_NAME);
9780                    }
9781            }
9782    
9783            @Override
9784            protected Set<String> getBadColumnNames() {
9785                    return _badColumnNames;
9786            }
9787    
9788            /**
9789             * Initializes the d d m structure persistence.
9790             */
9791            public void afterPropertiesSet() {
9792                    String[] listenerClassNames = StringUtil.split(GetterUtil.getString(
9793                                            com.liferay.portal.util.PropsUtil.get(
9794                                                    "value.object.listener.com.liferay.portlet.dynamicdatamapping.model.DDMStructure")));
9795    
9796                    if (listenerClassNames.length > 0) {
9797                            try {
9798                                    List<ModelListener<DDMStructure>> listenersList = new ArrayList<ModelListener<DDMStructure>>();
9799    
9800                                    for (String listenerClassName : listenerClassNames) {
9801                                            listenersList.add((ModelListener<DDMStructure>)InstanceFactory.newInstance(
9802                                                            getClassLoader(), listenerClassName));
9803                                    }
9804    
9805                                    listeners = listenersList.toArray(new ModelListener[listenersList.size()]);
9806                            }
9807                            catch (Exception e) {
9808                                    _log.error(e);
9809                            }
9810                    }
9811    
9812                    ddmStructureToDLFileEntryTypeTableMapper = TableMapperFactory.getTableMapper("DLFileEntryTypes_DDMStructures",
9813                                    "structureId", "fileEntryTypeId", this,
9814                                    dlFileEntryTypePersistence);
9815            }
9816    
9817            public void destroy() {
9818                    EntityCacheUtil.removeCache(DDMStructureImpl.class.getName());
9819                    FinderCacheUtil.removeCache(FINDER_CLASS_NAME_ENTITY);
9820                    FinderCacheUtil.removeCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
9821                    FinderCacheUtil.removeCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
9822    
9823                    TableMapperFactory.removeTableMapper("DLFileEntryTypes_DDMStructures");
9824            }
9825    
9826            @BeanReference(type = DLFileEntryTypePersistence.class)
9827            protected DLFileEntryTypePersistence dlFileEntryTypePersistence;
9828            protected TableMapper<DDMStructure, com.liferay.portlet.documentlibrary.model.DLFileEntryType> ddmStructureToDLFileEntryTypeTableMapper;
9829            private static final String _SQL_SELECT_DDMSTRUCTURE = "SELECT ddmStructure FROM DDMStructure ddmStructure";
9830            private static final String _SQL_SELECT_DDMSTRUCTURE_WHERE = "SELECT ddmStructure FROM DDMStructure ddmStructure WHERE ";
9831            private static final String _SQL_COUNT_DDMSTRUCTURE = "SELECT COUNT(ddmStructure) FROM DDMStructure ddmStructure";
9832            private static final String _SQL_COUNT_DDMSTRUCTURE_WHERE = "SELECT COUNT(ddmStructure) FROM DDMStructure ddmStructure WHERE ";
9833            private static final String _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN = "ddmStructure.structureId";
9834            private static final String _FILTER_SQL_SELECT_DDMSTRUCTURE_WHERE = "SELECT DISTINCT {ddmStructure.*} FROM DDMStructure ddmStructure WHERE ";
9835            private static final String _FILTER_SQL_SELECT_DDMSTRUCTURE_NO_INLINE_DISTINCT_WHERE_1 =
9836                    "SELECT {DDMStructure.*} FROM (SELECT DISTINCT ddmStructure.structureId FROM DDMStructure ddmStructure WHERE ";
9837            private static final String _FILTER_SQL_SELECT_DDMSTRUCTURE_NO_INLINE_DISTINCT_WHERE_2 =
9838                    ") TEMP_TABLE INNER JOIN DDMStructure ON TEMP_TABLE.structureId = DDMStructure.structureId";
9839            private static final String _FILTER_SQL_COUNT_DDMSTRUCTURE_WHERE = "SELECT COUNT(DISTINCT ddmStructure.structureId) AS COUNT_VALUE FROM DDMStructure ddmStructure WHERE ";
9840            private static final String _FILTER_ENTITY_ALIAS = "ddmStructure";
9841            private static final String _FILTER_ENTITY_TABLE = "DDMStructure";
9842            private static final String _ORDER_BY_ENTITY_ALIAS = "ddmStructure.";
9843            private static final String _ORDER_BY_ENTITY_TABLE = "DDMStructure.";
9844            private static final String _NO_SUCH_ENTITY_WITH_PRIMARY_KEY = "No DDMStructure exists with the primary key ";
9845            private static final String _NO_SUCH_ENTITY_WITH_KEY = "No DDMStructure exists with the key {";
9846            private static final boolean _HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE = com.liferay.portal.util.PropsValues.HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE;
9847            private static Log _log = LogFactoryUtil.getLog(DDMStructurePersistenceImpl.class);
9848            private static Set<String> _badColumnNames = SetUtil.fromArray(new String[] {
9849                                    "uuid", "type"
9850                            });
9851            private static DDMStructure _nullDDMStructure = new DDMStructureImpl() {
9852                            @Override
9853                            public Object clone() {
9854                                    return this;
9855                            }
9856    
9857                            @Override
9858                            public CacheModel<DDMStructure> toCacheModel() {
9859                                    return _nullDDMStructureCacheModel;
9860                            }
9861                    };
9862    
9863            private static CacheModel<DDMStructure> _nullDDMStructureCacheModel = new CacheModel<DDMStructure>() {
9864                            @Override
9865                            public DDMStructure toEntityModel() {
9866                                    return _nullDDMStructure;
9867                            }
9868                    };
9869    }