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