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