001    /**
002     * Copyright (c) 2000-2012 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.cache.CacheRegistryUtil;
018    import com.liferay.portal.kernel.dao.orm.EntityCacheUtil;
019    import com.liferay.portal.kernel.dao.orm.FinderCacheUtil;
020    import com.liferay.portal.kernel.dao.orm.FinderPath;
021    import com.liferay.portal.kernel.dao.orm.Query;
022    import com.liferay.portal.kernel.dao.orm.QueryPos;
023    import com.liferay.portal.kernel.dao.orm.QueryUtil;
024    import com.liferay.portal.kernel.dao.orm.SQLQuery;
025    import com.liferay.portal.kernel.dao.orm.Session;
026    import com.liferay.portal.kernel.exception.SystemException;
027    import com.liferay.portal.kernel.log.Log;
028    import com.liferay.portal.kernel.log.LogFactoryUtil;
029    import com.liferay.portal.kernel.util.ArrayUtil;
030    import com.liferay.portal.kernel.util.GetterUtil;
031    import com.liferay.portal.kernel.util.InstanceFactory;
032    import com.liferay.portal.kernel.util.OrderByComparator;
033    import com.liferay.portal.kernel.util.StringBundler;
034    import com.liferay.portal.kernel.util.StringPool;
035    import com.liferay.portal.kernel.util.StringUtil;
036    import com.liferay.portal.kernel.util.UnmodifiableList;
037    import com.liferay.portal.kernel.util.Validator;
038    import com.liferay.portal.kernel.uuid.PortalUUIDUtil;
039    import com.liferay.portal.model.CacheModel;
040    import com.liferay.portal.model.ModelListener;
041    import com.liferay.portal.security.permission.InlineSQLHelperUtil;
042    import com.liferay.portal.service.persistence.impl.BasePersistenceImpl;
043    
044    import com.liferay.portlet.dynamicdatamapping.NoSuchStructureException;
045    import com.liferay.portlet.dynamicdatamapping.model.DDMStructure;
046    import com.liferay.portlet.dynamicdatamapping.model.impl.DDMStructureImpl;
047    import com.liferay.portlet.dynamicdatamapping.model.impl.DDMStructureModelImpl;
048    
049    import java.io.Serializable;
050    
051    import java.util.ArrayList;
052    import java.util.Collections;
053    import java.util.List;
054    
055    /**
056     * The persistence implementation for the d d m structure service.
057     *
058     * <p>
059     * Caching information and settings can be found in <code>portal.properties</code>
060     * </p>
061     *
062     * @author Brian Wing Shun Chan
063     * @see DDMStructurePersistence
064     * @see DDMStructureUtil
065     * @generated
066     */
067    public class DDMStructurePersistenceImpl extends BasePersistenceImpl<DDMStructure>
068            implements DDMStructurePersistence {
069            /*
070             * NOTE FOR DEVELOPERS:
071             *
072             * 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.
073             */
074            public static final String FINDER_CLASS_NAME_ENTITY = DDMStructureImpl.class.getName();
075            public static final String FINDER_CLASS_NAME_LIST_WITH_PAGINATION = FINDER_CLASS_NAME_ENTITY +
076                    ".List1";
077            public static final String FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION = FINDER_CLASS_NAME_ENTITY +
078                    ".List2";
079            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_ALL = new FinderPath(DDMStructureModelImpl.ENTITY_CACHE_ENABLED,
080                            DDMStructureModelImpl.FINDER_CACHE_ENABLED, DDMStructureImpl.class,
081                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findAll", new String[0]);
082            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL = new FinderPath(DDMStructureModelImpl.ENTITY_CACHE_ENABLED,
083                            DDMStructureModelImpl.FINDER_CACHE_ENABLED, DDMStructureImpl.class,
084                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findAll", new String[0]);
085            public static final FinderPath FINDER_PATH_COUNT_ALL = new FinderPath(DDMStructureModelImpl.ENTITY_CACHE_ENABLED,
086                            DDMStructureModelImpl.FINDER_CACHE_ENABLED, Long.class,
087                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countAll", new String[0]);
088            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_UUID = new FinderPath(DDMStructureModelImpl.ENTITY_CACHE_ENABLED,
089                            DDMStructureModelImpl.FINDER_CACHE_ENABLED, DDMStructureImpl.class,
090                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByUuid",
091                            new String[] {
092                                    String.class.getName(),
093                                    
094                            Integer.class.getName(), Integer.class.getName(),
095                                    OrderByComparator.class.getName()
096                            });
097            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID = new FinderPath(DDMStructureModelImpl.ENTITY_CACHE_ENABLED,
098                            DDMStructureModelImpl.FINDER_CACHE_ENABLED, DDMStructureImpl.class,
099                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByUuid",
100                            new String[] { String.class.getName() },
101                            DDMStructureModelImpl.UUID_COLUMN_BITMASK);
102            public static final FinderPath FINDER_PATH_COUNT_BY_UUID = new FinderPath(DDMStructureModelImpl.ENTITY_CACHE_ENABLED,
103                            DDMStructureModelImpl.FINDER_CACHE_ENABLED, Long.class,
104                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByUuid",
105                            new String[] { String.class.getName() });
106    
107            /**
108             * Returns all the d d m structures where uuid = &#63;.
109             *
110             * @param uuid the uuid
111             * @return the matching d d m structures
112             * @throws SystemException if a system exception occurred
113             */
114            public List<DDMStructure> findByUuid(String uuid) throws SystemException {
115                    return findByUuid(uuid, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
116            }
117    
118            /**
119             * Returns a range of all the d d m structures where uuid = &#63;.
120             *
121             * <p>
122             * 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.
123             * </p>
124             *
125             * @param uuid the uuid
126             * @param start the lower bound of the range of d d m structures
127             * @param end the upper bound of the range of d d m structures (not inclusive)
128             * @return the range of matching d d m structures
129             * @throws SystemException if a system exception occurred
130             */
131            public List<DDMStructure> findByUuid(String uuid, int start, int end)
132                    throws SystemException {
133                    return findByUuid(uuid, start, end, null);
134            }
135    
136            /**
137             * Returns an ordered range of all the d d m structures where uuid = &#63;.
138             *
139             * <p>
140             * 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.
141             * </p>
142             *
143             * @param uuid the uuid
144             * @param start the lower bound of the range of d d m structures
145             * @param end the upper bound of the range of d d m structures (not inclusive)
146             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
147             * @return the ordered range of matching d d m structures
148             * @throws SystemException if a system exception occurred
149             */
150            public List<DDMStructure> findByUuid(String uuid, int start, int end,
151                    OrderByComparator orderByComparator) throws SystemException {
152                    boolean pagination = true;
153                    FinderPath finderPath = null;
154                    Object[] finderArgs = null;
155    
156                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
157                                    (orderByComparator == null)) {
158                            pagination = false;
159                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID;
160                            finderArgs = new Object[] { uuid };
161                    }
162                    else {
163                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_UUID;
164                            finderArgs = new Object[] { uuid, start, end, orderByComparator };
165                    }
166    
167                    List<DDMStructure> list = (List<DDMStructure>)FinderCacheUtil.getResult(finderPath,
168                                    finderArgs, this);
169    
170                    if ((list != null) && !list.isEmpty()) {
171                            for (DDMStructure ddmStructure : list) {
172                                    if (!Validator.equals(uuid, ddmStructure.getUuid())) {
173                                            list = null;
174    
175                                            break;
176                                    }
177                            }
178                    }
179    
180                    if (list == null) {
181                            StringBundler query = null;
182    
183                            if (orderByComparator != null) {
184                                    query = new StringBundler(3 +
185                                                    (orderByComparator.getOrderByFields().length * 3));
186                            }
187                            else {
188                                    query = new StringBundler(3);
189                            }
190    
191                            query.append(_SQL_SELECT_DDMSTRUCTURE_WHERE);
192    
193                            boolean bindUuid = false;
194    
195                            if (uuid == null) {
196                                    query.append(_FINDER_COLUMN_UUID_UUID_1);
197                            }
198                            else if (uuid.equals(StringPool.BLANK)) {
199                                    query.append(_FINDER_COLUMN_UUID_UUID_3);
200                            }
201                            else {
202                                    bindUuid = true;
203    
204                                    query.append(_FINDER_COLUMN_UUID_UUID_2);
205                            }
206    
207                            if (orderByComparator != null) {
208                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
209                                            orderByComparator);
210                            }
211                            else
212                             if (pagination) {
213                                    query.append(DDMStructureModelImpl.ORDER_BY_JPQL);
214                            }
215    
216                            String sql = query.toString();
217    
218                            Session session = null;
219    
220                            try {
221                                    session = openSession();
222    
223                                    Query q = session.createQuery(sql);
224    
225                                    QueryPos qPos = QueryPos.getInstance(q);
226    
227                                    if (bindUuid) {
228                                            qPos.add(uuid);
229                                    }
230    
231                                    if (!pagination) {
232                                            list = (List<DDMStructure>)QueryUtil.list(q, getDialect(),
233                                                            start, end, false);
234    
235                                            Collections.sort(list);
236    
237                                            list = new UnmodifiableList<DDMStructure>(list);
238                                    }
239                                    else {
240                                            list = (List<DDMStructure>)QueryUtil.list(q, getDialect(),
241                                                            start, end);
242                                    }
243    
244                                    cacheResult(list);
245    
246                                    FinderCacheUtil.putResult(finderPath, finderArgs, list);
247                            }
248                            catch (Exception e) {
249                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
250    
251                                    throw processException(e);
252                            }
253                            finally {
254                                    closeSession(session);
255                            }
256                    }
257    
258                    return list;
259            }
260    
261            /**
262             * Returns the first d d m structure in the ordered set where uuid = &#63;.
263             *
264             * @param uuid the uuid
265             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
266             * @return the first matching d d m structure
267             * @throws com.liferay.portlet.dynamicdatamapping.NoSuchStructureException if a matching d d m structure could not be found
268             * @throws SystemException if a system exception occurred
269             */
270            public DDMStructure findByUuid_First(String uuid,
271                    OrderByComparator orderByComparator)
272                    throws NoSuchStructureException, SystemException {
273                    DDMStructure ddmStructure = fetchByUuid_First(uuid, orderByComparator);
274    
275                    if (ddmStructure != null) {
276                            return ddmStructure;
277                    }
278    
279                    StringBundler msg = new StringBundler(4);
280    
281                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
282    
283                    msg.append("uuid=");
284                    msg.append(uuid);
285    
286                    msg.append(StringPool.CLOSE_CURLY_BRACE);
287    
288                    throw new NoSuchStructureException(msg.toString());
289            }
290    
291            /**
292             * Returns the first d d m structure in the ordered set where uuid = &#63;.
293             *
294             * @param uuid the uuid
295             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
296             * @return the first matching d d m structure, or <code>null</code> if a matching d d m structure could not be found
297             * @throws SystemException if a system exception occurred
298             */
299            public DDMStructure fetchByUuid_First(String uuid,
300                    OrderByComparator orderByComparator) throws SystemException {
301                    List<DDMStructure> list = findByUuid(uuid, 0, 1, orderByComparator);
302    
303                    if (!list.isEmpty()) {
304                            return list.get(0);
305                    }
306    
307                    return null;
308            }
309    
310            /**
311             * Returns the last d d m structure in the ordered set where uuid = &#63;.
312             *
313             * @param uuid the uuid
314             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
315             * @return the last matching d d m structure
316             * @throws com.liferay.portlet.dynamicdatamapping.NoSuchStructureException if a matching d d m structure could not be found
317             * @throws SystemException if a system exception occurred
318             */
319            public DDMStructure findByUuid_Last(String uuid,
320                    OrderByComparator orderByComparator)
321                    throws NoSuchStructureException, SystemException {
322                    DDMStructure ddmStructure = fetchByUuid_Last(uuid, orderByComparator);
323    
324                    if (ddmStructure != null) {
325                            return ddmStructure;
326                    }
327    
328                    StringBundler msg = new StringBundler(4);
329    
330                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
331    
332                    msg.append("uuid=");
333                    msg.append(uuid);
334    
335                    msg.append(StringPool.CLOSE_CURLY_BRACE);
336    
337                    throw new NoSuchStructureException(msg.toString());
338            }
339    
340            /**
341             * Returns the last d d m structure in the ordered set where uuid = &#63;.
342             *
343             * @param uuid the uuid
344             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
345             * @return the last matching d d m structure, or <code>null</code> if a matching d d m structure could not be found
346             * @throws SystemException if a system exception occurred
347             */
348            public DDMStructure fetchByUuid_Last(String uuid,
349                    OrderByComparator orderByComparator) throws SystemException {
350                    int count = countByUuid(uuid);
351    
352                    List<DDMStructure> list = findByUuid(uuid, count - 1, count,
353                                    orderByComparator);
354    
355                    if (!list.isEmpty()) {
356                            return list.get(0);
357                    }
358    
359                    return null;
360            }
361    
362            /**
363             * Returns the d d m structures before and after the current d d m structure in the ordered set where uuid = &#63;.
364             *
365             * @param structureId the primary key of the current d d m structure
366             * @param uuid the uuid
367             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
368             * @return the previous, current, and next d d m structure
369             * @throws com.liferay.portlet.dynamicdatamapping.NoSuchStructureException if a d d m structure with the primary key could not be found
370             * @throws SystemException if a system exception occurred
371             */
372            public DDMStructure[] findByUuid_PrevAndNext(long structureId, String uuid,
373                    OrderByComparator orderByComparator)
374                    throws NoSuchStructureException, SystemException {
375                    DDMStructure ddmStructure = findByPrimaryKey(structureId);
376    
377                    Session session = null;
378    
379                    try {
380                            session = openSession();
381    
382                            DDMStructure[] array = new DDMStructureImpl[3];
383    
384                            array[0] = getByUuid_PrevAndNext(session, ddmStructure, uuid,
385                                            orderByComparator, true);
386    
387                            array[1] = ddmStructure;
388    
389                            array[2] = getByUuid_PrevAndNext(session, ddmStructure, uuid,
390                                            orderByComparator, false);
391    
392                            return array;
393                    }
394                    catch (Exception e) {
395                            throw processException(e);
396                    }
397                    finally {
398                            closeSession(session);
399                    }
400            }
401    
402            protected DDMStructure getByUuid_PrevAndNext(Session session,
403                    DDMStructure ddmStructure, String uuid,
404                    OrderByComparator orderByComparator, boolean previous) {
405                    StringBundler query = null;
406    
407                    if (orderByComparator != null) {
408                            query = new StringBundler(6 +
409                                            (orderByComparator.getOrderByFields().length * 6));
410                    }
411                    else {
412                            query = new StringBundler(3);
413                    }
414    
415                    query.append(_SQL_SELECT_DDMSTRUCTURE_WHERE);
416    
417                    boolean bindUuid = false;
418    
419                    if (uuid == null) {
420                            query.append(_FINDER_COLUMN_UUID_UUID_1);
421                    }
422                    else if (uuid.equals(StringPool.BLANK)) {
423                            query.append(_FINDER_COLUMN_UUID_UUID_3);
424                    }
425                    else {
426                            bindUuid = true;
427    
428                            query.append(_FINDER_COLUMN_UUID_UUID_2);
429                    }
430    
431                    if (orderByComparator != null) {
432                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
433    
434                            if (orderByConditionFields.length > 0) {
435                                    query.append(WHERE_AND);
436                            }
437    
438                            for (int i = 0; i < orderByConditionFields.length; i++) {
439                                    query.append(_ORDER_BY_ENTITY_ALIAS);
440                                    query.append(orderByConditionFields[i]);
441    
442                                    if ((i + 1) < orderByConditionFields.length) {
443                                            if (orderByComparator.isAscending() ^ previous) {
444                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
445                                            }
446                                            else {
447                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
448                                            }
449                                    }
450                                    else {
451                                            if (orderByComparator.isAscending() ^ previous) {
452                                                    query.append(WHERE_GREATER_THAN);
453                                            }
454                                            else {
455                                                    query.append(WHERE_LESSER_THAN);
456                                            }
457                                    }
458                            }
459    
460                            query.append(ORDER_BY_CLAUSE);
461    
462                            String[] orderByFields = orderByComparator.getOrderByFields();
463    
464                            for (int i = 0; i < orderByFields.length; i++) {
465                                    query.append(_ORDER_BY_ENTITY_ALIAS);
466                                    query.append(orderByFields[i]);
467    
468                                    if ((i + 1) < orderByFields.length) {
469                                            if (orderByComparator.isAscending() ^ previous) {
470                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
471                                            }
472                                            else {
473                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
474                                            }
475                                    }
476                                    else {
477                                            if (orderByComparator.isAscending() ^ previous) {
478                                                    query.append(ORDER_BY_ASC);
479                                            }
480                                            else {
481                                                    query.append(ORDER_BY_DESC);
482                                            }
483                                    }
484                            }
485                    }
486                    else {
487                            query.append(DDMStructureModelImpl.ORDER_BY_JPQL);
488                    }
489    
490                    String sql = query.toString();
491    
492                    Query q = session.createQuery(sql);
493    
494                    q.setFirstResult(0);
495                    q.setMaxResults(2);
496    
497                    QueryPos qPos = QueryPos.getInstance(q);
498    
499                    if (bindUuid) {
500                            qPos.add(uuid);
501                    }
502    
503                    if (orderByComparator != null) {
504                            Object[] values = orderByComparator.getOrderByConditionValues(ddmStructure);
505    
506                            for (Object value : values) {
507                                    qPos.add(value);
508                            }
509                    }
510    
511                    List<DDMStructure> list = q.list();
512    
513                    if (list.size() == 2) {
514                            return list.get(1);
515                    }
516                    else {
517                            return null;
518                    }
519            }
520    
521            /**
522             * Removes all the d d m structures where uuid = &#63; from the database.
523             *
524             * @param uuid the uuid
525             * @throws SystemException if a system exception occurred
526             */
527            public void removeByUuid(String uuid) throws SystemException {
528                    for (DDMStructure ddmStructure : findByUuid(uuid, QueryUtil.ALL_POS,
529                                    QueryUtil.ALL_POS, null)) {
530                            remove(ddmStructure);
531                    }
532            }
533    
534            /**
535             * Returns the number of d d m structures where uuid = &#63;.
536             *
537             * @param uuid the uuid
538             * @return the number of matching d d m structures
539             * @throws SystemException if a system exception occurred
540             */
541            public int countByUuid(String uuid) throws SystemException {
542                    FinderPath finderPath = FINDER_PATH_COUNT_BY_UUID;
543    
544                    Object[] finderArgs = new Object[] { uuid };
545    
546                    Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
547                                    this);
548    
549                    if (count == null) {
550                            StringBundler query = new StringBundler(2);
551    
552                            query.append(_SQL_COUNT_DDMSTRUCTURE_WHERE);
553    
554                            boolean bindUuid = false;
555    
556                            if (uuid == null) {
557                                    query.append(_FINDER_COLUMN_UUID_UUID_1);
558                            }
559                            else if (uuid.equals(StringPool.BLANK)) {
560                                    query.append(_FINDER_COLUMN_UUID_UUID_3);
561                            }
562                            else {
563                                    bindUuid = true;
564    
565                                    query.append(_FINDER_COLUMN_UUID_UUID_2);
566                            }
567    
568                            String sql = query.toString();
569    
570                            Session session = null;
571    
572                            try {
573                                    session = openSession();
574    
575                                    Query q = session.createQuery(sql);
576    
577                                    QueryPos qPos = QueryPos.getInstance(q);
578    
579                                    if (bindUuid) {
580                                            qPos.add(uuid);
581                                    }
582    
583                                    count = (Long)q.uniqueResult();
584    
585                                    FinderCacheUtil.putResult(finderPath, finderArgs, count);
586                            }
587                            catch (Exception e) {
588                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
589    
590                                    throw processException(e);
591                            }
592                            finally {
593                                    closeSession(session);
594                            }
595                    }
596    
597                    return count.intValue();
598            }
599    
600            private static final String _FINDER_COLUMN_UUID_UUID_1 = "ddmStructure.uuid IS NULL";
601            private static final String _FINDER_COLUMN_UUID_UUID_2 = "ddmStructure.uuid = ?";
602            private static final String _FINDER_COLUMN_UUID_UUID_3 = "(ddmStructure.uuid IS NULL OR ddmStructure.uuid = '')";
603            public static final FinderPath FINDER_PATH_FETCH_BY_UUID_G = new FinderPath(DDMStructureModelImpl.ENTITY_CACHE_ENABLED,
604                            DDMStructureModelImpl.FINDER_CACHE_ENABLED, DDMStructureImpl.class,
605                            FINDER_CLASS_NAME_ENTITY, "fetchByUUID_G",
606                            new String[] { String.class.getName(), Long.class.getName() },
607                            DDMStructureModelImpl.UUID_COLUMN_BITMASK |
608                            DDMStructureModelImpl.GROUPID_COLUMN_BITMASK);
609            public static final FinderPath FINDER_PATH_COUNT_BY_UUID_G = new FinderPath(DDMStructureModelImpl.ENTITY_CACHE_ENABLED,
610                            DDMStructureModelImpl.FINDER_CACHE_ENABLED, Long.class,
611                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByUUID_G",
612                            new String[] { String.class.getName(), Long.class.getName() });
613    
614            /**
615             * 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.
616             *
617             * @param uuid the uuid
618             * @param groupId the group ID
619             * @return the matching d d m structure
620             * @throws com.liferay.portlet.dynamicdatamapping.NoSuchStructureException if a matching d d m structure could not be found
621             * @throws SystemException if a system exception occurred
622             */
623            public DDMStructure findByUUID_G(String uuid, long groupId)
624                    throws NoSuchStructureException, SystemException {
625                    DDMStructure ddmStructure = fetchByUUID_G(uuid, groupId);
626    
627                    if (ddmStructure == null) {
628                            StringBundler msg = new StringBundler(6);
629    
630                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
631    
632                            msg.append("uuid=");
633                            msg.append(uuid);
634    
635                            msg.append(", groupId=");
636                            msg.append(groupId);
637    
638                            msg.append(StringPool.CLOSE_CURLY_BRACE);
639    
640                            if (_log.isWarnEnabled()) {
641                                    _log.warn(msg.toString());
642                            }
643    
644                            throw new NoSuchStructureException(msg.toString());
645                    }
646    
647                    return ddmStructure;
648            }
649    
650            /**
651             * 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.
652             *
653             * @param uuid the uuid
654             * @param groupId the group ID
655             * @return the matching d d m structure, or <code>null</code> if a matching d d m structure could not be found
656             * @throws SystemException if a system exception occurred
657             */
658            public DDMStructure fetchByUUID_G(String uuid, long groupId)
659                    throws SystemException {
660                    return fetchByUUID_G(uuid, groupId, true);
661            }
662    
663            /**
664             * 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.
665             *
666             * @param uuid the uuid
667             * @param groupId the group ID
668             * @param retrieveFromCache whether to use the finder cache
669             * @return the matching d d m structure, or <code>null</code> if a matching d d m structure could not be found
670             * @throws SystemException if a system exception occurred
671             */
672            public DDMStructure fetchByUUID_G(String uuid, long groupId,
673                    boolean retrieveFromCache) throws SystemException {
674                    Object[] finderArgs = new Object[] { uuid, groupId };
675    
676                    Object result = null;
677    
678                    if (retrieveFromCache) {
679                            result = FinderCacheUtil.getResult(FINDER_PATH_FETCH_BY_UUID_G,
680                                            finderArgs, this);
681                    }
682    
683                    if (result instanceof DDMStructure) {
684                            DDMStructure ddmStructure = (DDMStructure)result;
685    
686                            if (!Validator.equals(uuid, ddmStructure.getUuid()) ||
687                                            (groupId != ddmStructure.getGroupId())) {
688                                    result = null;
689                            }
690                    }
691    
692                    if (result == null) {
693                            StringBundler query = new StringBundler(4);
694    
695                            query.append(_SQL_SELECT_DDMSTRUCTURE_WHERE);
696    
697                            boolean bindUuid = false;
698    
699                            if (uuid == null) {
700                                    query.append(_FINDER_COLUMN_UUID_G_UUID_1);
701                            }
702                            else if (uuid.equals(StringPool.BLANK)) {
703                                    query.append(_FINDER_COLUMN_UUID_G_UUID_3);
704                            }
705                            else {
706                                    bindUuid = true;
707    
708                                    query.append(_FINDER_COLUMN_UUID_G_UUID_2);
709                            }
710    
711                            query.append(_FINDER_COLUMN_UUID_G_GROUPID_2);
712    
713                            String sql = query.toString();
714    
715                            Session session = null;
716    
717                            try {
718                                    session = openSession();
719    
720                                    Query q = session.createQuery(sql);
721    
722                                    QueryPos qPos = QueryPos.getInstance(q);
723    
724                                    if (bindUuid) {
725                                            qPos.add(uuid);
726                                    }
727    
728                                    qPos.add(groupId);
729    
730                                    List<DDMStructure> list = q.list();
731    
732                                    if (list.isEmpty()) {
733                                            FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_UUID_G,
734                                                    finderArgs, list);
735                                    }
736                                    else {
737                                            DDMStructure ddmStructure = list.get(0);
738    
739                                            result = ddmStructure;
740    
741                                            cacheResult(ddmStructure);
742    
743                                            if ((ddmStructure.getUuid() == null) ||
744                                                            !ddmStructure.getUuid().equals(uuid) ||
745                                                            (ddmStructure.getGroupId() != groupId)) {
746                                                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_UUID_G,
747                                                            finderArgs, ddmStructure);
748                                            }
749                                    }
750                            }
751                            catch (Exception e) {
752                                    FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_UUID_G,
753                                            finderArgs);
754    
755                                    throw processException(e);
756                            }
757                            finally {
758                                    closeSession(session);
759                            }
760                    }
761    
762                    if (result instanceof List<?>) {
763                            return null;
764                    }
765                    else {
766                            return (DDMStructure)result;
767                    }
768            }
769    
770            /**
771             * Removes the d d m structure where uuid = &#63; and groupId = &#63; from the database.
772             *
773             * @param uuid the uuid
774             * @param groupId the group ID
775             * @return the d d m structure that was removed
776             * @throws SystemException if a system exception occurred
777             */
778            public DDMStructure removeByUUID_G(String uuid, long groupId)
779                    throws NoSuchStructureException, SystemException {
780                    DDMStructure ddmStructure = findByUUID_G(uuid, groupId);
781    
782                    return remove(ddmStructure);
783            }
784    
785            /**
786             * Returns the number of d d m structures where uuid = &#63; and groupId = &#63;.
787             *
788             * @param uuid the uuid
789             * @param groupId the group ID
790             * @return the number of matching d d m structures
791             * @throws SystemException if a system exception occurred
792             */
793            public int countByUUID_G(String uuid, long groupId)
794                    throws SystemException {
795                    FinderPath finderPath = FINDER_PATH_COUNT_BY_UUID_G;
796    
797                    Object[] finderArgs = new Object[] { uuid, groupId };
798    
799                    Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
800                                    this);
801    
802                    if (count == null) {
803                            StringBundler query = new StringBundler(3);
804    
805                            query.append(_SQL_COUNT_DDMSTRUCTURE_WHERE);
806    
807                            boolean bindUuid = false;
808    
809                            if (uuid == null) {
810                                    query.append(_FINDER_COLUMN_UUID_G_UUID_1);
811                            }
812                            else if (uuid.equals(StringPool.BLANK)) {
813                                    query.append(_FINDER_COLUMN_UUID_G_UUID_3);
814                            }
815                            else {
816                                    bindUuid = true;
817    
818                                    query.append(_FINDER_COLUMN_UUID_G_UUID_2);
819                            }
820    
821                            query.append(_FINDER_COLUMN_UUID_G_GROUPID_2);
822    
823                            String sql = query.toString();
824    
825                            Session session = null;
826    
827                            try {
828                                    session = openSession();
829    
830                                    Query q = session.createQuery(sql);
831    
832                                    QueryPos qPos = QueryPos.getInstance(q);
833    
834                                    if (bindUuid) {
835                                            qPos.add(uuid);
836                                    }
837    
838                                    qPos.add(groupId);
839    
840                                    count = (Long)q.uniqueResult();
841    
842                                    FinderCacheUtil.putResult(finderPath, finderArgs, count);
843                            }
844                            catch (Exception e) {
845                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
846    
847                                    throw processException(e);
848                            }
849                            finally {
850                                    closeSession(session);
851                            }
852                    }
853    
854                    return count.intValue();
855            }
856    
857            private static final String _FINDER_COLUMN_UUID_G_UUID_1 = "ddmStructure.uuid IS NULL AND ";
858            private static final String _FINDER_COLUMN_UUID_G_UUID_2 = "ddmStructure.uuid = ? AND ";
859            private static final String _FINDER_COLUMN_UUID_G_UUID_3 = "(ddmStructure.uuid IS NULL OR ddmStructure.uuid = '') AND ";
860            private static final String _FINDER_COLUMN_UUID_G_GROUPID_2 = "ddmStructure.groupId = ?";
861            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_UUID_C = new FinderPath(DDMStructureModelImpl.ENTITY_CACHE_ENABLED,
862                            DDMStructureModelImpl.FINDER_CACHE_ENABLED, DDMStructureImpl.class,
863                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByUuid_C",
864                            new String[] {
865                                    String.class.getName(), Long.class.getName(),
866                                    
867                            Integer.class.getName(), Integer.class.getName(),
868                                    OrderByComparator.class.getName()
869                            });
870            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID_C =
871                    new FinderPath(DDMStructureModelImpl.ENTITY_CACHE_ENABLED,
872                            DDMStructureModelImpl.FINDER_CACHE_ENABLED, DDMStructureImpl.class,
873                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByUuid_C",
874                            new String[] { String.class.getName(), Long.class.getName() },
875                            DDMStructureModelImpl.UUID_COLUMN_BITMASK |
876                            DDMStructureModelImpl.COMPANYID_COLUMN_BITMASK);
877            public static final FinderPath FINDER_PATH_COUNT_BY_UUID_C = new FinderPath(DDMStructureModelImpl.ENTITY_CACHE_ENABLED,
878                            DDMStructureModelImpl.FINDER_CACHE_ENABLED, Long.class,
879                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByUuid_C",
880                            new String[] { String.class.getName(), Long.class.getName() });
881    
882            /**
883             * Returns all the d d m structures where uuid = &#63; and companyId = &#63;.
884             *
885             * @param uuid the uuid
886             * @param companyId the company ID
887             * @return the matching d d m structures
888             * @throws SystemException if a system exception occurred
889             */
890            public List<DDMStructure> findByUuid_C(String uuid, long companyId)
891                    throws SystemException {
892                    return findByUuid_C(uuid, companyId, QueryUtil.ALL_POS,
893                            QueryUtil.ALL_POS, null);
894            }
895    
896            /**
897             * Returns a range of all the d d m structures where uuid = &#63; and companyId = &#63;.
898             *
899             * <p>
900             * 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.
901             * </p>
902             *
903             * @param uuid the uuid
904             * @param companyId the company ID
905             * @param start the lower bound of the range of d d m structures
906             * @param end the upper bound of the range of d d m structures (not inclusive)
907             * @return the range of matching d d m structures
908             * @throws SystemException if a system exception occurred
909             */
910            public List<DDMStructure> findByUuid_C(String uuid, long companyId,
911                    int start, int end) throws SystemException {
912                    return findByUuid_C(uuid, companyId, start, end, null);
913            }
914    
915            /**
916             * Returns an ordered range of all the d d m structures where uuid = &#63; and companyId = &#63;.
917             *
918             * <p>
919             * 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.
920             * </p>
921             *
922             * @param uuid the uuid
923             * @param companyId the company ID
924             * @param start the lower bound of the range of d d m structures
925             * @param end the upper bound of the range of d d m structures (not inclusive)
926             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
927             * @return the ordered range of matching d d m structures
928             * @throws SystemException if a system exception occurred
929             */
930            public List<DDMStructure> findByUuid_C(String uuid, long companyId,
931                    int start, int end, OrderByComparator orderByComparator)
932                    throws SystemException {
933                    boolean pagination = true;
934                    FinderPath finderPath = null;
935                    Object[] finderArgs = null;
936    
937                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
938                                    (orderByComparator == null)) {
939                            pagination = false;
940                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID_C;
941                            finderArgs = new Object[] { uuid, companyId };
942                    }
943                    else {
944                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_UUID_C;
945                            finderArgs = new Object[] {
946                                            uuid, companyId,
947                                            
948                                            start, end, orderByComparator
949                                    };
950                    }
951    
952                    List<DDMStructure> list = (List<DDMStructure>)FinderCacheUtil.getResult(finderPath,
953                                    finderArgs, this);
954    
955                    if ((list != null) && !list.isEmpty()) {
956                            for (DDMStructure ddmStructure : list) {
957                                    if (!Validator.equals(uuid, ddmStructure.getUuid()) ||
958                                                    (companyId != ddmStructure.getCompanyId())) {
959                                            list = null;
960    
961                                            break;
962                                    }
963                            }
964                    }
965    
966                    if (list == null) {
967                            StringBundler query = null;
968    
969                            if (orderByComparator != null) {
970                                    query = new StringBundler(4 +
971                                                    (orderByComparator.getOrderByFields().length * 3));
972                            }
973                            else {
974                                    query = new StringBundler(4);
975                            }
976    
977                            query.append(_SQL_SELECT_DDMSTRUCTURE_WHERE);
978    
979                            boolean bindUuid = false;
980    
981                            if (uuid == null) {
982                                    query.append(_FINDER_COLUMN_UUID_C_UUID_1);
983                            }
984                            else if (uuid.equals(StringPool.BLANK)) {
985                                    query.append(_FINDER_COLUMN_UUID_C_UUID_3);
986                            }
987                            else {
988                                    bindUuid = true;
989    
990                                    query.append(_FINDER_COLUMN_UUID_C_UUID_2);
991                            }
992    
993                            query.append(_FINDER_COLUMN_UUID_C_COMPANYID_2);
994    
995                            if (orderByComparator != null) {
996                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
997                                            orderByComparator);
998                            }
999                            else
1000                             if (pagination) {
1001                                    query.append(DDMStructureModelImpl.ORDER_BY_JPQL);
1002                            }
1003    
1004                            String sql = query.toString();
1005    
1006                            Session session = null;
1007    
1008                            try {
1009                                    session = openSession();
1010    
1011                                    Query q = session.createQuery(sql);
1012    
1013                                    QueryPos qPos = QueryPos.getInstance(q);
1014    
1015                                    if (bindUuid) {
1016                                            qPos.add(uuid);
1017                                    }
1018    
1019                                    qPos.add(companyId);
1020    
1021                                    if (!pagination) {
1022                                            list = (List<DDMStructure>)QueryUtil.list(q, getDialect(),
1023                                                            start, end, false);
1024    
1025                                            Collections.sort(list);
1026    
1027                                            list = new UnmodifiableList<DDMStructure>(list);
1028                                    }
1029                                    else {
1030                                            list = (List<DDMStructure>)QueryUtil.list(q, getDialect(),
1031                                                            start, end);
1032                                    }
1033    
1034                                    cacheResult(list);
1035    
1036                                    FinderCacheUtil.putResult(finderPath, finderArgs, list);
1037                            }
1038                            catch (Exception e) {
1039                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
1040    
1041                                    throw processException(e);
1042                            }
1043                            finally {
1044                                    closeSession(session);
1045                            }
1046                    }
1047    
1048                    return list;
1049            }
1050    
1051            /**
1052             * Returns the first d d m structure in the ordered set where uuid = &#63; and companyId = &#63;.
1053             *
1054             * @param uuid the uuid
1055             * @param companyId the company ID
1056             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1057             * @return the first matching d d m structure
1058             * @throws com.liferay.portlet.dynamicdatamapping.NoSuchStructureException if a matching d d m structure could not be found
1059             * @throws SystemException if a system exception occurred
1060             */
1061            public DDMStructure findByUuid_C_First(String uuid, long companyId,
1062                    OrderByComparator orderByComparator)
1063                    throws NoSuchStructureException, SystemException {
1064                    DDMStructure ddmStructure = fetchByUuid_C_First(uuid, companyId,
1065                                    orderByComparator);
1066    
1067                    if (ddmStructure != null) {
1068                            return ddmStructure;
1069                    }
1070    
1071                    StringBundler msg = new StringBundler(6);
1072    
1073                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1074    
1075                    msg.append("uuid=");
1076                    msg.append(uuid);
1077    
1078                    msg.append(", companyId=");
1079                    msg.append(companyId);
1080    
1081                    msg.append(StringPool.CLOSE_CURLY_BRACE);
1082    
1083                    throw new NoSuchStructureException(msg.toString());
1084            }
1085    
1086            /**
1087             * Returns the first d d m structure in the ordered set where uuid = &#63; and companyId = &#63;.
1088             *
1089             * @param uuid the uuid
1090             * @param companyId the company ID
1091             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1092             * @return the first matching d d m structure, or <code>null</code> if a matching d d m structure could not be found
1093             * @throws SystemException if a system exception occurred
1094             */
1095            public DDMStructure fetchByUuid_C_First(String uuid, long companyId,
1096                    OrderByComparator orderByComparator) throws SystemException {
1097                    List<DDMStructure> list = findByUuid_C(uuid, companyId, 0, 1,
1098                                    orderByComparator);
1099    
1100                    if (!list.isEmpty()) {
1101                            return list.get(0);
1102                    }
1103    
1104                    return null;
1105            }
1106    
1107            /**
1108             * Returns the last d d m structure in the ordered set where uuid = &#63; and companyId = &#63;.
1109             *
1110             * @param uuid the uuid
1111             * @param companyId the company ID
1112             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1113             * @return the last matching d d m structure
1114             * @throws com.liferay.portlet.dynamicdatamapping.NoSuchStructureException if a matching d d m structure could not be found
1115             * @throws SystemException if a system exception occurred
1116             */
1117            public DDMStructure findByUuid_C_Last(String uuid, long companyId,
1118                    OrderByComparator orderByComparator)
1119                    throws NoSuchStructureException, SystemException {
1120                    DDMStructure ddmStructure = fetchByUuid_C_Last(uuid, companyId,
1121                                    orderByComparator);
1122    
1123                    if (ddmStructure != null) {
1124                            return ddmStructure;
1125                    }
1126    
1127                    StringBundler msg = new StringBundler(6);
1128    
1129                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1130    
1131                    msg.append("uuid=");
1132                    msg.append(uuid);
1133    
1134                    msg.append(", companyId=");
1135                    msg.append(companyId);
1136    
1137                    msg.append(StringPool.CLOSE_CURLY_BRACE);
1138    
1139                    throw new NoSuchStructureException(msg.toString());
1140            }
1141    
1142            /**
1143             * Returns the last d d m structure in the ordered set where uuid = &#63; and companyId = &#63;.
1144             *
1145             * @param uuid the uuid
1146             * @param companyId the company ID
1147             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1148             * @return the last matching d d m structure, or <code>null</code> if a matching d d m structure could not be found
1149             * @throws SystemException if a system exception occurred
1150             */
1151            public DDMStructure fetchByUuid_C_Last(String uuid, long companyId,
1152                    OrderByComparator orderByComparator) throws SystemException {
1153                    int count = countByUuid_C(uuid, companyId);
1154    
1155                    List<DDMStructure> list = findByUuid_C(uuid, companyId, count - 1,
1156                                    count, orderByComparator);
1157    
1158                    if (!list.isEmpty()) {
1159                            return list.get(0);
1160                    }
1161    
1162                    return null;
1163            }
1164    
1165            /**
1166             * 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;.
1167             *
1168             * @param structureId the primary key of the current d d m structure
1169             * @param uuid the uuid
1170             * @param companyId the company ID
1171             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1172             * @return the previous, current, and next d d m structure
1173             * @throws com.liferay.portlet.dynamicdatamapping.NoSuchStructureException if a d d m structure with the primary key could not be found
1174             * @throws SystemException if a system exception occurred
1175             */
1176            public DDMStructure[] findByUuid_C_PrevAndNext(long structureId,
1177                    String uuid, long companyId, OrderByComparator orderByComparator)
1178                    throws NoSuchStructureException, SystemException {
1179                    DDMStructure ddmStructure = findByPrimaryKey(structureId);
1180    
1181                    Session session = null;
1182    
1183                    try {
1184                            session = openSession();
1185    
1186                            DDMStructure[] array = new DDMStructureImpl[3];
1187    
1188                            array[0] = getByUuid_C_PrevAndNext(session, ddmStructure, uuid,
1189                                            companyId, orderByComparator, true);
1190    
1191                            array[1] = ddmStructure;
1192    
1193                            array[2] = getByUuid_C_PrevAndNext(session, ddmStructure, uuid,
1194                                            companyId, orderByComparator, false);
1195    
1196                            return array;
1197                    }
1198                    catch (Exception e) {
1199                            throw processException(e);
1200                    }
1201                    finally {
1202                            closeSession(session);
1203                    }
1204            }
1205    
1206            protected DDMStructure getByUuid_C_PrevAndNext(Session session,
1207                    DDMStructure ddmStructure, String uuid, long companyId,
1208                    OrderByComparator orderByComparator, boolean previous) {
1209                    StringBundler query = null;
1210    
1211                    if (orderByComparator != null) {
1212                            query = new StringBundler(6 +
1213                                            (orderByComparator.getOrderByFields().length * 6));
1214                    }
1215                    else {
1216                            query = new StringBundler(3);
1217                    }
1218    
1219                    query.append(_SQL_SELECT_DDMSTRUCTURE_WHERE);
1220    
1221                    boolean bindUuid = false;
1222    
1223                    if (uuid == null) {
1224                            query.append(_FINDER_COLUMN_UUID_C_UUID_1);
1225                    }
1226                    else if (uuid.equals(StringPool.BLANK)) {
1227                            query.append(_FINDER_COLUMN_UUID_C_UUID_3);
1228                    }
1229                    else {
1230                            bindUuid = true;
1231    
1232                            query.append(_FINDER_COLUMN_UUID_C_UUID_2);
1233                    }
1234    
1235                    query.append(_FINDER_COLUMN_UUID_C_COMPANYID_2);
1236    
1237                    if (orderByComparator != null) {
1238                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
1239    
1240                            if (orderByConditionFields.length > 0) {
1241                                    query.append(WHERE_AND);
1242                            }
1243    
1244                            for (int i = 0; i < orderByConditionFields.length; i++) {
1245                                    query.append(_ORDER_BY_ENTITY_ALIAS);
1246                                    query.append(orderByConditionFields[i]);
1247    
1248                                    if ((i + 1) < orderByConditionFields.length) {
1249                                            if (orderByComparator.isAscending() ^ previous) {
1250                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
1251                                            }
1252                                            else {
1253                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
1254                                            }
1255                                    }
1256                                    else {
1257                                            if (orderByComparator.isAscending() ^ previous) {
1258                                                    query.append(WHERE_GREATER_THAN);
1259                                            }
1260                                            else {
1261                                                    query.append(WHERE_LESSER_THAN);
1262                                            }
1263                                    }
1264                            }
1265    
1266                            query.append(ORDER_BY_CLAUSE);
1267    
1268                            String[] orderByFields = orderByComparator.getOrderByFields();
1269    
1270                            for (int i = 0; i < orderByFields.length; i++) {
1271                                    query.append(_ORDER_BY_ENTITY_ALIAS);
1272                                    query.append(orderByFields[i]);
1273    
1274                                    if ((i + 1) < orderByFields.length) {
1275                                            if (orderByComparator.isAscending() ^ previous) {
1276                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
1277                                            }
1278                                            else {
1279                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
1280                                            }
1281                                    }
1282                                    else {
1283                                            if (orderByComparator.isAscending() ^ previous) {
1284                                                    query.append(ORDER_BY_ASC);
1285                                            }
1286                                            else {
1287                                                    query.append(ORDER_BY_DESC);
1288                                            }
1289                                    }
1290                            }
1291                    }
1292                    else {
1293                            query.append(DDMStructureModelImpl.ORDER_BY_JPQL);
1294                    }
1295    
1296                    String sql = query.toString();
1297    
1298                    Query q = session.createQuery(sql);
1299    
1300                    q.setFirstResult(0);
1301                    q.setMaxResults(2);
1302    
1303                    QueryPos qPos = QueryPos.getInstance(q);
1304    
1305                    if (bindUuid) {
1306                            qPos.add(uuid);
1307                    }
1308    
1309                    qPos.add(companyId);
1310    
1311                    if (orderByComparator != null) {
1312                            Object[] values = orderByComparator.getOrderByConditionValues(ddmStructure);
1313    
1314                            for (Object value : values) {
1315                                    qPos.add(value);
1316                            }
1317                    }
1318    
1319                    List<DDMStructure> list = q.list();
1320    
1321                    if (list.size() == 2) {
1322                            return list.get(1);
1323                    }
1324                    else {
1325                            return null;
1326                    }
1327            }
1328    
1329            /**
1330             * Removes all the d d m structures where uuid = &#63; and companyId = &#63; from the database.
1331             *
1332             * @param uuid the uuid
1333             * @param companyId the company ID
1334             * @throws SystemException if a system exception occurred
1335             */
1336            public void removeByUuid_C(String uuid, long companyId)
1337                    throws SystemException {
1338                    for (DDMStructure ddmStructure : findByUuid_C(uuid, companyId,
1339                                    QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
1340                            remove(ddmStructure);
1341                    }
1342            }
1343    
1344            /**
1345             * Returns the number of d d m structures where uuid = &#63; and companyId = &#63;.
1346             *
1347             * @param uuid the uuid
1348             * @param companyId the company ID
1349             * @return the number of matching d d m structures
1350             * @throws SystemException if a system exception occurred
1351             */
1352            public int countByUuid_C(String uuid, long companyId)
1353                    throws SystemException {
1354                    FinderPath finderPath = FINDER_PATH_COUNT_BY_UUID_C;
1355    
1356                    Object[] finderArgs = new Object[] { uuid, companyId };
1357    
1358                    Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
1359                                    this);
1360    
1361                    if (count == null) {
1362                            StringBundler query = new StringBundler(3);
1363    
1364                            query.append(_SQL_COUNT_DDMSTRUCTURE_WHERE);
1365    
1366                            boolean bindUuid = false;
1367    
1368                            if (uuid == null) {
1369                                    query.append(_FINDER_COLUMN_UUID_C_UUID_1);
1370                            }
1371                            else if (uuid.equals(StringPool.BLANK)) {
1372                                    query.append(_FINDER_COLUMN_UUID_C_UUID_3);
1373                            }
1374                            else {
1375                                    bindUuid = true;
1376    
1377                                    query.append(_FINDER_COLUMN_UUID_C_UUID_2);
1378                            }
1379    
1380                            query.append(_FINDER_COLUMN_UUID_C_COMPANYID_2);
1381    
1382                            String sql = query.toString();
1383    
1384                            Session session = null;
1385    
1386                            try {
1387                                    session = openSession();
1388    
1389                                    Query q = session.createQuery(sql);
1390    
1391                                    QueryPos qPos = QueryPos.getInstance(q);
1392    
1393                                    if (bindUuid) {
1394                                            qPos.add(uuid);
1395                                    }
1396    
1397                                    qPos.add(companyId);
1398    
1399                                    count = (Long)q.uniqueResult();
1400    
1401                                    FinderCacheUtil.putResult(finderPath, finderArgs, count);
1402                            }
1403                            catch (Exception e) {
1404                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
1405    
1406                                    throw processException(e);
1407                            }
1408                            finally {
1409                                    closeSession(session);
1410                            }
1411                    }
1412    
1413                    return count.intValue();
1414            }
1415    
1416            private static final String _FINDER_COLUMN_UUID_C_UUID_1 = "ddmStructure.uuid IS NULL AND ";
1417            private static final String _FINDER_COLUMN_UUID_C_UUID_2 = "ddmStructure.uuid = ? AND ";
1418            private static final String _FINDER_COLUMN_UUID_C_UUID_3 = "(ddmStructure.uuid IS NULL OR ddmStructure.uuid = '') AND ";
1419            private static final String _FINDER_COLUMN_UUID_C_COMPANYID_2 = "ddmStructure.companyId = ?";
1420            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_GROUPID = new FinderPath(DDMStructureModelImpl.ENTITY_CACHE_ENABLED,
1421                            DDMStructureModelImpl.FINDER_CACHE_ENABLED, DDMStructureImpl.class,
1422                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByGroupId",
1423                            new String[] {
1424                                    Long.class.getName(),
1425                                    
1426                            Integer.class.getName(), Integer.class.getName(),
1427                                    OrderByComparator.class.getName()
1428                            });
1429            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_GROUPID =
1430                    new FinderPath(DDMStructureModelImpl.ENTITY_CACHE_ENABLED,
1431                            DDMStructureModelImpl.FINDER_CACHE_ENABLED, DDMStructureImpl.class,
1432                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByGroupId",
1433                            new String[] { Long.class.getName() },
1434                            DDMStructureModelImpl.GROUPID_COLUMN_BITMASK);
1435            public static final FinderPath FINDER_PATH_COUNT_BY_GROUPID = new FinderPath(DDMStructureModelImpl.ENTITY_CACHE_ENABLED,
1436                            DDMStructureModelImpl.FINDER_CACHE_ENABLED, Long.class,
1437                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByGroupId",
1438                            new String[] { Long.class.getName() });
1439            public static final FinderPath FINDER_PATH_WITH_PAGINATION_COUNT_BY_GROUPID = new FinderPath(DDMStructureModelImpl.ENTITY_CACHE_ENABLED,
1440                            DDMStructureModelImpl.FINDER_CACHE_ENABLED, Long.class,
1441                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "countByGroupId",
1442                            new String[] { Long.class.getName() });
1443    
1444            /**
1445             * Returns all the d d m structures where groupId = &#63;.
1446             *
1447             * @param groupId the group ID
1448             * @return the matching d d m structures
1449             * @throws SystemException if a system exception occurred
1450             */
1451            public List<DDMStructure> findByGroupId(long groupId)
1452                    throws SystemException {
1453                    return findByGroupId(groupId, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
1454            }
1455    
1456            /**
1457             * Returns a range of all the d d m structures where groupId = &#63;.
1458             *
1459             * <p>
1460             * 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.
1461             * </p>
1462             *
1463             * @param groupId the group ID
1464             * @param start the lower bound of the range of d d m structures
1465             * @param end the upper bound of the range of d d m structures (not inclusive)
1466             * @return the range of matching d d m structures
1467             * @throws SystemException if a system exception occurred
1468             */
1469            public List<DDMStructure> findByGroupId(long groupId, int start, int end)
1470                    throws SystemException {
1471                    return findByGroupId(groupId, start, end, null);
1472            }
1473    
1474            /**
1475             * Returns an ordered range of all the d d m structures where groupId = &#63;.
1476             *
1477             * <p>
1478             * 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.
1479             * </p>
1480             *
1481             * @param groupId the group ID
1482             * @param start the lower bound of the range of d d m structures
1483             * @param end the upper bound of the range of d d m structures (not inclusive)
1484             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
1485             * @return the ordered range of matching d d m structures
1486             * @throws SystemException if a system exception occurred
1487             */
1488            public List<DDMStructure> findByGroupId(long groupId, int start, int end,
1489                    OrderByComparator orderByComparator) throws SystemException {
1490                    boolean pagination = true;
1491                    FinderPath finderPath = null;
1492                    Object[] finderArgs = null;
1493    
1494                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
1495                                    (orderByComparator == null)) {
1496                            pagination = false;
1497                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_GROUPID;
1498                            finderArgs = new Object[] { groupId };
1499                    }
1500                    else {
1501                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_GROUPID;
1502                            finderArgs = new Object[] { groupId, start, end, orderByComparator };
1503                    }
1504    
1505                    List<DDMStructure> list = (List<DDMStructure>)FinderCacheUtil.getResult(finderPath,
1506                                    finderArgs, this);
1507    
1508                    if ((list != null) && !list.isEmpty()) {
1509                            for (DDMStructure ddmStructure : list) {
1510                                    if ((groupId != ddmStructure.getGroupId())) {
1511                                            list = null;
1512    
1513                                            break;
1514                                    }
1515                            }
1516                    }
1517    
1518                    if (list == null) {
1519                            StringBundler query = null;
1520    
1521                            if (orderByComparator != null) {
1522                                    query = new StringBundler(3 +
1523                                                    (orderByComparator.getOrderByFields().length * 3));
1524                            }
1525                            else {
1526                                    query = new StringBundler(3);
1527                            }
1528    
1529                            query.append(_SQL_SELECT_DDMSTRUCTURE_WHERE);
1530    
1531                            query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
1532    
1533                            if (orderByComparator != null) {
1534                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1535                                            orderByComparator);
1536                            }
1537                            else
1538                             if (pagination) {
1539                                    query.append(DDMStructureModelImpl.ORDER_BY_JPQL);
1540                            }
1541    
1542                            String sql = query.toString();
1543    
1544                            Session session = null;
1545    
1546                            try {
1547                                    session = openSession();
1548    
1549                                    Query q = session.createQuery(sql);
1550    
1551                                    QueryPos qPos = QueryPos.getInstance(q);
1552    
1553                                    qPos.add(groupId);
1554    
1555                                    if (!pagination) {
1556                                            list = (List<DDMStructure>)QueryUtil.list(q, getDialect(),
1557                                                            start, end, false);
1558    
1559                                            Collections.sort(list);
1560    
1561                                            list = new UnmodifiableList<DDMStructure>(list);
1562                                    }
1563                                    else {
1564                                            list = (List<DDMStructure>)QueryUtil.list(q, getDialect(),
1565                                                            start, end);
1566                                    }
1567    
1568                                    cacheResult(list);
1569    
1570                                    FinderCacheUtil.putResult(finderPath, finderArgs, list);
1571                            }
1572                            catch (Exception e) {
1573                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
1574    
1575                                    throw processException(e);
1576                            }
1577                            finally {
1578                                    closeSession(session);
1579                            }
1580                    }
1581    
1582                    return list;
1583            }
1584    
1585            /**
1586             * Returns the first d d m structure in the ordered set where groupId = &#63;.
1587             *
1588             * @param groupId the group ID
1589             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1590             * @return the first matching d d m structure
1591             * @throws com.liferay.portlet.dynamicdatamapping.NoSuchStructureException if a matching d d m structure could not be found
1592             * @throws SystemException if a system exception occurred
1593             */
1594            public DDMStructure findByGroupId_First(long groupId,
1595                    OrderByComparator orderByComparator)
1596                    throws NoSuchStructureException, SystemException {
1597                    DDMStructure ddmStructure = fetchByGroupId_First(groupId,
1598                                    orderByComparator);
1599    
1600                    if (ddmStructure != null) {
1601                            return ddmStructure;
1602                    }
1603    
1604                    StringBundler msg = new StringBundler(4);
1605    
1606                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1607    
1608                    msg.append("groupId=");
1609                    msg.append(groupId);
1610    
1611                    msg.append(StringPool.CLOSE_CURLY_BRACE);
1612    
1613                    throw new NoSuchStructureException(msg.toString());
1614            }
1615    
1616            /**
1617             * Returns the first d d m structure in the ordered set where groupId = &#63;.
1618             *
1619             * @param groupId the group ID
1620             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1621             * @return the first matching d d m structure, or <code>null</code> if a matching d d m structure could not be found
1622             * @throws SystemException if a system exception occurred
1623             */
1624            public DDMStructure fetchByGroupId_First(long groupId,
1625                    OrderByComparator orderByComparator) throws SystemException {
1626                    List<DDMStructure> list = findByGroupId(groupId, 0, 1, orderByComparator);
1627    
1628                    if (!list.isEmpty()) {
1629                            return list.get(0);
1630                    }
1631    
1632                    return null;
1633            }
1634    
1635            /**
1636             * Returns the last d d m structure in the ordered set where groupId = &#63;.
1637             *
1638             * @param groupId the group ID
1639             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1640             * @return the last matching d d m structure
1641             * @throws com.liferay.portlet.dynamicdatamapping.NoSuchStructureException if a matching d d m structure could not be found
1642             * @throws SystemException if a system exception occurred
1643             */
1644            public DDMStructure findByGroupId_Last(long groupId,
1645                    OrderByComparator orderByComparator)
1646                    throws NoSuchStructureException, SystemException {
1647                    DDMStructure ddmStructure = fetchByGroupId_Last(groupId,
1648                                    orderByComparator);
1649    
1650                    if (ddmStructure != null) {
1651                            return ddmStructure;
1652                    }
1653    
1654                    StringBundler msg = new StringBundler(4);
1655    
1656                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1657    
1658                    msg.append("groupId=");
1659                    msg.append(groupId);
1660    
1661                    msg.append(StringPool.CLOSE_CURLY_BRACE);
1662    
1663                    throw new NoSuchStructureException(msg.toString());
1664            }
1665    
1666            /**
1667             * Returns the last d d m structure in the ordered set where groupId = &#63;.
1668             *
1669             * @param groupId the group ID
1670             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1671             * @return the last matching d d m structure, or <code>null</code> if a matching d d m structure could not be found
1672             * @throws SystemException if a system exception occurred
1673             */
1674            public DDMStructure fetchByGroupId_Last(long groupId,
1675                    OrderByComparator orderByComparator) throws SystemException {
1676                    int count = countByGroupId(groupId);
1677    
1678                    List<DDMStructure> list = findByGroupId(groupId, count - 1, count,
1679                                    orderByComparator);
1680    
1681                    if (!list.isEmpty()) {
1682                            return list.get(0);
1683                    }
1684    
1685                    return null;
1686            }
1687    
1688            /**
1689             * Returns the d d m structures before and after the current d d m structure in the ordered set where groupId = &#63;.
1690             *
1691             * @param structureId the primary key of the current d d m structure
1692             * @param groupId the group ID
1693             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1694             * @return the previous, current, and next d d m structure
1695             * @throws com.liferay.portlet.dynamicdatamapping.NoSuchStructureException if a d d m structure with the primary key could not be found
1696             * @throws SystemException if a system exception occurred
1697             */
1698            public DDMStructure[] findByGroupId_PrevAndNext(long structureId,
1699                    long groupId, OrderByComparator orderByComparator)
1700                    throws NoSuchStructureException, SystemException {
1701                    DDMStructure ddmStructure = findByPrimaryKey(structureId);
1702    
1703                    Session session = null;
1704    
1705                    try {
1706                            session = openSession();
1707    
1708                            DDMStructure[] array = new DDMStructureImpl[3];
1709    
1710                            array[0] = getByGroupId_PrevAndNext(session, ddmStructure, groupId,
1711                                            orderByComparator, true);
1712    
1713                            array[1] = ddmStructure;
1714    
1715                            array[2] = getByGroupId_PrevAndNext(session, ddmStructure, groupId,
1716                                            orderByComparator, false);
1717    
1718                            return array;
1719                    }
1720                    catch (Exception e) {
1721                            throw processException(e);
1722                    }
1723                    finally {
1724                            closeSession(session);
1725                    }
1726            }
1727    
1728            protected DDMStructure getByGroupId_PrevAndNext(Session session,
1729                    DDMStructure ddmStructure, long groupId,
1730                    OrderByComparator orderByComparator, boolean previous) {
1731                    StringBundler query = null;
1732    
1733                    if (orderByComparator != null) {
1734                            query = new StringBundler(6 +
1735                                            (orderByComparator.getOrderByFields().length * 6));
1736                    }
1737                    else {
1738                            query = new StringBundler(3);
1739                    }
1740    
1741                    query.append(_SQL_SELECT_DDMSTRUCTURE_WHERE);
1742    
1743                    query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
1744    
1745                    if (orderByComparator != null) {
1746                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
1747    
1748                            if (orderByConditionFields.length > 0) {
1749                                    query.append(WHERE_AND);
1750                            }
1751    
1752                            for (int i = 0; i < orderByConditionFields.length; i++) {
1753                                    query.append(_ORDER_BY_ENTITY_ALIAS);
1754                                    query.append(orderByConditionFields[i]);
1755    
1756                                    if ((i + 1) < orderByConditionFields.length) {
1757                                            if (orderByComparator.isAscending() ^ previous) {
1758                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
1759                                            }
1760                                            else {
1761                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
1762                                            }
1763                                    }
1764                                    else {
1765                                            if (orderByComparator.isAscending() ^ previous) {
1766                                                    query.append(WHERE_GREATER_THAN);
1767                                            }
1768                                            else {
1769                                                    query.append(WHERE_LESSER_THAN);
1770                                            }
1771                                    }
1772                            }
1773    
1774                            query.append(ORDER_BY_CLAUSE);
1775    
1776                            String[] orderByFields = orderByComparator.getOrderByFields();
1777    
1778                            for (int i = 0; i < orderByFields.length; i++) {
1779                                    query.append(_ORDER_BY_ENTITY_ALIAS);
1780                                    query.append(orderByFields[i]);
1781    
1782                                    if ((i + 1) < orderByFields.length) {
1783                                            if (orderByComparator.isAscending() ^ previous) {
1784                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
1785                                            }
1786                                            else {
1787                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
1788                                            }
1789                                    }
1790                                    else {
1791                                            if (orderByComparator.isAscending() ^ previous) {
1792                                                    query.append(ORDER_BY_ASC);
1793                                            }
1794                                            else {
1795                                                    query.append(ORDER_BY_DESC);
1796                                            }
1797                                    }
1798                            }
1799                    }
1800                    else {
1801                            query.append(DDMStructureModelImpl.ORDER_BY_JPQL);
1802                    }
1803    
1804                    String sql = query.toString();
1805    
1806                    Query q = session.createQuery(sql);
1807    
1808                    q.setFirstResult(0);
1809                    q.setMaxResults(2);
1810    
1811                    QueryPos qPos = QueryPos.getInstance(q);
1812    
1813                    qPos.add(groupId);
1814    
1815                    if (orderByComparator != null) {
1816                            Object[] values = orderByComparator.getOrderByConditionValues(ddmStructure);
1817    
1818                            for (Object value : values) {
1819                                    qPos.add(value);
1820                            }
1821                    }
1822    
1823                    List<DDMStructure> list = q.list();
1824    
1825                    if (list.size() == 2) {
1826                            return list.get(1);
1827                    }
1828                    else {
1829                            return null;
1830                    }
1831            }
1832    
1833            /**
1834             * Returns all the d d m structures that the user has permission to view where groupId = &#63;.
1835             *
1836             * @param groupId the group ID
1837             * @return the matching d d m structures that the user has permission to view
1838             * @throws SystemException if a system exception occurred
1839             */
1840            public List<DDMStructure> filterFindByGroupId(long groupId)
1841                    throws SystemException {
1842                    return filterFindByGroupId(groupId, QueryUtil.ALL_POS,
1843                            QueryUtil.ALL_POS, null);
1844            }
1845    
1846            /**
1847             * Returns a range of all the d d m structures that the user has permission to view where groupId = &#63;.
1848             *
1849             * <p>
1850             * 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.
1851             * </p>
1852             *
1853             * @param groupId the group ID
1854             * @param start the lower bound of the range of d d m structures
1855             * @param end the upper bound of the range of d d m structures (not inclusive)
1856             * @return the range of matching d d m structures that the user has permission to view
1857             * @throws SystemException if a system exception occurred
1858             */
1859            public List<DDMStructure> filterFindByGroupId(long groupId, int start,
1860                    int end) throws SystemException {
1861                    return filterFindByGroupId(groupId, start, end, null);
1862            }
1863    
1864            /**
1865             * Returns an ordered range of all the d d m structures that the user has permissions to view where groupId = &#63;.
1866             *
1867             * <p>
1868             * 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.
1869             * </p>
1870             *
1871             * @param groupId the group ID
1872             * @param start the lower bound of the range of d d m structures
1873             * @param end the upper bound of the range of d d m structures (not inclusive)
1874             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
1875             * @return the ordered range of matching d d m structures that the user has permission to view
1876             * @throws SystemException if a system exception occurred
1877             */
1878            public List<DDMStructure> filterFindByGroupId(long groupId, int start,
1879                    int end, OrderByComparator orderByComparator) throws SystemException {
1880                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
1881                            return findByGroupId(groupId, start, end, orderByComparator);
1882                    }
1883    
1884                    StringBundler query = null;
1885    
1886                    if (orderByComparator != null) {
1887                            query = new StringBundler(3 +
1888                                            (orderByComparator.getOrderByFields().length * 3));
1889                    }
1890                    else {
1891                            query = new StringBundler(3);
1892                    }
1893    
1894                    if (getDB().isSupportsInlineDistinct()) {
1895                            query.append(_FILTER_SQL_SELECT_DDMSTRUCTURE_WHERE);
1896                    }
1897                    else {
1898                            query.append(_FILTER_SQL_SELECT_DDMSTRUCTURE_NO_INLINE_DISTINCT_WHERE_1);
1899                    }
1900    
1901                    query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
1902    
1903                    if (!getDB().isSupportsInlineDistinct()) {
1904                            query.append(_FILTER_SQL_SELECT_DDMSTRUCTURE_NO_INLINE_DISTINCT_WHERE_2);
1905                    }
1906    
1907                    if (orderByComparator != null) {
1908                            if (getDB().isSupportsInlineDistinct()) {
1909                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1910                                            orderByComparator);
1911                            }
1912                            else {
1913                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_TABLE,
1914                                            orderByComparator);
1915                            }
1916                    }
1917                    else {
1918                            if (getDB().isSupportsInlineDistinct()) {
1919                                    query.append(DDMStructureModelImpl.ORDER_BY_JPQL);
1920                            }
1921                            else {
1922                                    query.append(DDMStructureModelImpl.ORDER_BY_SQL);
1923                            }
1924                    }
1925    
1926                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
1927                                    DDMStructure.class.getName(),
1928                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
1929    
1930                    Session session = null;
1931    
1932                    try {
1933                            session = openSession();
1934    
1935                            SQLQuery q = session.createSQLQuery(sql);
1936    
1937                            if (getDB().isSupportsInlineDistinct()) {
1938                                    q.addEntity(_FILTER_ENTITY_ALIAS, DDMStructureImpl.class);
1939                            }
1940                            else {
1941                                    q.addEntity(_FILTER_ENTITY_TABLE, DDMStructureImpl.class);
1942                            }
1943    
1944                            QueryPos qPos = QueryPos.getInstance(q);
1945    
1946                            qPos.add(groupId);
1947    
1948                            return (List<DDMStructure>)QueryUtil.list(q, getDialect(), start,
1949                                    end);
1950                    }
1951                    catch (Exception e) {
1952                            throw processException(e);
1953                    }
1954                    finally {
1955                            closeSession(session);
1956                    }
1957            }
1958    
1959            /**
1960             * 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;.
1961             *
1962             * @param structureId the primary key of the current d d m structure
1963             * @param groupId the group ID
1964             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1965             * @return the previous, current, and next d d m structure
1966             * @throws com.liferay.portlet.dynamicdatamapping.NoSuchStructureException if a d d m structure with the primary key could not be found
1967             * @throws SystemException if a system exception occurred
1968             */
1969            public DDMStructure[] filterFindByGroupId_PrevAndNext(long structureId,
1970                    long groupId, OrderByComparator orderByComparator)
1971                    throws NoSuchStructureException, SystemException {
1972                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
1973                            return findByGroupId_PrevAndNext(structureId, groupId,
1974                                    orderByComparator);
1975                    }
1976    
1977                    DDMStructure ddmStructure = findByPrimaryKey(structureId);
1978    
1979                    Session session = null;
1980    
1981                    try {
1982                            session = openSession();
1983    
1984                            DDMStructure[] array = new DDMStructureImpl[3];
1985    
1986                            array[0] = filterGetByGroupId_PrevAndNext(session, ddmStructure,
1987                                            groupId, orderByComparator, true);
1988    
1989                            array[1] = ddmStructure;
1990    
1991                            array[2] = filterGetByGroupId_PrevAndNext(session, ddmStructure,
1992                                            groupId, orderByComparator, false);
1993    
1994                            return array;
1995                    }
1996                    catch (Exception e) {
1997                            throw processException(e);
1998                    }
1999                    finally {
2000                            closeSession(session);
2001                    }
2002            }
2003    
2004            protected DDMStructure filterGetByGroupId_PrevAndNext(Session session,
2005                    DDMStructure ddmStructure, long groupId,
2006                    OrderByComparator orderByComparator, boolean previous) {
2007                    StringBundler query = null;
2008    
2009                    if (orderByComparator != null) {
2010                            query = new StringBundler(6 +
2011                                            (orderByComparator.getOrderByFields().length * 6));
2012                    }
2013                    else {
2014                            query = new StringBundler(3);
2015                    }
2016    
2017                    if (getDB().isSupportsInlineDistinct()) {
2018                            query.append(_FILTER_SQL_SELECT_DDMSTRUCTURE_WHERE);
2019                    }
2020                    else {
2021                            query.append(_FILTER_SQL_SELECT_DDMSTRUCTURE_NO_INLINE_DISTINCT_WHERE_1);
2022                    }
2023    
2024                    query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
2025    
2026                    if (!getDB().isSupportsInlineDistinct()) {
2027                            query.append(_FILTER_SQL_SELECT_DDMSTRUCTURE_NO_INLINE_DISTINCT_WHERE_2);
2028                    }
2029    
2030                    if (orderByComparator != null) {
2031                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
2032    
2033                            if (orderByConditionFields.length > 0) {
2034                                    query.append(WHERE_AND);
2035                            }
2036    
2037                            for (int i = 0; i < orderByConditionFields.length; i++) {
2038                                    if (getDB().isSupportsInlineDistinct()) {
2039                                            query.append(_ORDER_BY_ENTITY_ALIAS);
2040                                    }
2041                                    else {
2042                                            query.append(_ORDER_BY_ENTITY_TABLE);
2043                                    }
2044    
2045                                    query.append(orderByConditionFields[i]);
2046    
2047                                    if ((i + 1) < orderByConditionFields.length) {
2048                                            if (orderByComparator.isAscending() ^ previous) {
2049                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
2050                                            }
2051                                            else {
2052                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
2053                                            }
2054                                    }
2055                                    else {
2056                                            if (orderByComparator.isAscending() ^ previous) {
2057                                                    query.append(WHERE_GREATER_THAN);
2058                                            }
2059                                            else {
2060                                                    query.append(WHERE_LESSER_THAN);
2061                                            }
2062                                    }
2063                            }
2064    
2065                            query.append(ORDER_BY_CLAUSE);
2066    
2067                            String[] orderByFields = orderByComparator.getOrderByFields();
2068    
2069                            for (int i = 0; i < orderByFields.length; i++) {
2070                                    if (getDB().isSupportsInlineDistinct()) {
2071                                            query.append(_ORDER_BY_ENTITY_ALIAS);
2072                                    }
2073                                    else {
2074                                            query.append(_ORDER_BY_ENTITY_TABLE);
2075                                    }
2076    
2077                                    query.append(orderByFields[i]);
2078    
2079                                    if ((i + 1) < orderByFields.length) {
2080                                            if (orderByComparator.isAscending() ^ previous) {
2081                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
2082                                            }
2083                                            else {
2084                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
2085                                            }
2086                                    }
2087                                    else {
2088                                            if (orderByComparator.isAscending() ^ previous) {
2089                                                    query.append(ORDER_BY_ASC);
2090                                            }
2091                                            else {
2092                                                    query.append(ORDER_BY_DESC);
2093                                            }
2094                                    }
2095                            }
2096                    }
2097                    else {
2098                            if (getDB().isSupportsInlineDistinct()) {
2099                                    query.append(DDMStructureModelImpl.ORDER_BY_JPQL);
2100                            }
2101                            else {
2102                                    query.append(DDMStructureModelImpl.ORDER_BY_SQL);
2103                            }
2104                    }
2105    
2106                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
2107                                    DDMStructure.class.getName(),
2108                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
2109    
2110                    SQLQuery q = session.createSQLQuery(sql);
2111    
2112                    q.setFirstResult(0);
2113                    q.setMaxResults(2);
2114    
2115                    if (getDB().isSupportsInlineDistinct()) {
2116                            q.addEntity(_FILTER_ENTITY_ALIAS, DDMStructureImpl.class);
2117                    }
2118                    else {
2119                            q.addEntity(_FILTER_ENTITY_TABLE, DDMStructureImpl.class);
2120                    }
2121    
2122                    QueryPos qPos = QueryPos.getInstance(q);
2123    
2124                    qPos.add(groupId);
2125    
2126                    if (orderByComparator != null) {
2127                            Object[] values = orderByComparator.getOrderByConditionValues(ddmStructure);
2128    
2129                            for (Object value : values) {
2130                                    qPos.add(value);
2131                            }
2132                    }
2133    
2134                    List<DDMStructure> list = q.list();
2135    
2136                    if (list.size() == 2) {
2137                            return list.get(1);
2138                    }
2139                    else {
2140                            return null;
2141                    }
2142            }
2143    
2144            /**
2145             * Returns all the d d m structures that the user has permission to view where groupId = any &#63;.
2146             *
2147             * @param groupIds the group IDs
2148             * @return the matching d d m structures that the user has permission to view
2149             * @throws SystemException if a system exception occurred
2150             */
2151            public List<DDMStructure> filterFindByGroupId(long[] groupIds)
2152                    throws SystemException {
2153                    return filterFindByGroupId(groupIds, QueryUtil.ALL_POS,
2154                            QueryUtil.ALL_POS, null);
2155            }
2156    
2157            /**
2158             * Returns a range of all the d d m structures that the user has permission to view where groupId = any &#63;.
2159             *
2160             * <p>
2161             * 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.
2162             * </p>
2163             *
2164             * @param groupIds the group IDs
2165             * @param start the lower bound of the range of d d m structures
2166             * @param end the upper bound of the range of d d m structures (not inclusive)
2167             * @return the range of matching d d m structures that the user has permission to view
2168             * @throws SystemException if a system exception occurred
2169             */
2170            public List<DDMStructure> filterFindByGroupId(long[] groupIds, int start,
2171                    int end) throws SystemException {
2172                    return filterFindByGroupId(groupIds, start, end, null);
2173            }
2174    
2175            /**
2176             * Returns an ordered range of all the d d m structures that the user has permission to view where groupId = any &#63;.
2177             *
2178             * <p>
2179             * 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.
2180             * </p>
2181             *
2182             * @param groupIds the group IDs
2183             * @param start the lower bound of the range of d d m structures
2184             * @param end the upper bound of the range of d d m structures (not inclusive)
2185             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
2186             * @return the ordered range of matching d d m structures that the user has permission to view
2187             * @throws SystemException if a system exception occurred
2188             */
2189            public List<DDMStructure> filterFindByGroupId(long[] groupIds, int start,
2190                    int end, OrderByComparator orderByComparator) throws SystemException {
2191                    if (!InlineSQLHelperUtil.isEnabled(groupIds)) {
2192                            return findByGroupId(groupIds, start, end, orderByComparator);
2193                    }
2194    
2195                    StringBundler query = new StringBundler();
2196    
2197                    if (getDB().isSupportsInlineDistinct()) {
2198                            query.append(_FILTER_SQL_SELECT_DDMSTRUCTURE_WHERE);
2199                    }
2200                    else {
2201                            query.append(_FILTER_SQL_SELECT_DDMSTRUCTURE_NO_INLINE_DISTINCT_WHERE_1);
2202                    }
2203    
2204                    boolean conjunctionable = false;
2205    
2206                    if ((groupIds == null) || (groupIds.length > 0)) {
2207                            if (conjunctionable) {
2208                                    query.append(WHERE_AND);
2209                            }
2210    
2211                            query.append(StringPool.OPEN_PARENTHESIS);
2212    
2213                            for (int i = 0; i < groupIds.length; i++) {
2214                                    query.append(_FINDER_COLUMN_GROUPID_GROUPID_5);
2215    
2216                                    if ((i + 1) < groupIds.length) {
2217                                            query.append(WHERE_OR);
2218                                    }
2219                            }
2220    
2221                            query.append(StringPool.CLOSE_PARENTHESIS);
2222    
2223                            conjunctionable = true;
2224                    }
2225    
2226                    if (!getDB().isSupportsInlineDistinct()) {
2227                            query.append(_FILTER_SQL_SELECT_DDMSTRUCTURE_NO_INLINE_DISTINCT_WHERE_2);
2228                    }
2229    
2230                    if (orderByComparator != null) {
2231                            if (getDB().isSupportsInlineDistinct()) {
2232                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
2233                                            orderByComparator);
2234                            }
2235                            else {
2236                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_TABLE,
2237                                            orderByComparator);
2238                            }
2239                    }
2240                    else {
2241                            if (getDB().isSupportsInlineDistinct()) {
2242                                    query.append(DDMStructureModelImpl.ORDER_BY_JPQL);
2243                            }
2244                            else {
2245                                    query.append(DDMStructureModelImpl.ORDER_BY_SQL);
2246                            }
2247                    }
2248    
2249                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
2250                                    DDMStructure.class.getName(),
2251                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupIds);
2252    
2253                    Session session = null;
2254    
2255                    try {
2256                            session = openSession();
2257    
2258                            SQLQuery q = session.createSQLQuery(sql);
2259    
2260                            if (getDB().isSupportsInlineDistinct()) {
2261                                    q.addEntity(_FILTER_ENTITY_ALIAS, DDMStructureImpl.class);
2262                            }
2263                            else {
2264                                    q.addEntity(_FILTER_ENTITY_TABLE, DDMStructureImpl.class);
2265                            }
2266    
2267                            QueryPos qPos = QueryPos.getInstance(q);
2268    
2269                            if (groupIds != null) {
2270                                    qPos.add(groupIds);
2271                            }
2272    
2273                            return (List<DDMStructure>)QueryUtil.list(q, getDialect(), start,
2274                                    end);
2275                    }
2276                    catch (Exception e) {
2277                            throw processException(e);
2278                    }
2279                    finally {
2280                            closeSession(session);
2281                    }
2282            }
2283    
2284            /**
2285             * Returns all the d d m structures where groupId = any &#63;.
2286             *
2287             * <p>
2288             * 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.
2289             * </p>
2290             *
2291             * @param groupIds the group IDs
2292             * @return the matching d d m structures
2293             * @throws SystemException if a system exception occurred
2294             */
2295            public List<DDMStructure> findByGroupId(long[] groupIds)
2296                    throws SystemException {
2297                    return findByGroupId(groupIds, QueryUtil.ALL_POS, QueryUtil.ALL_POS,
2298                            null);
2299            }
2300    
2301            /**
2302             * Returns a range of all the d d m structures where groupId = any &#63;.
2303             *
2304             * <p>
2305             * 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.
2306             * </p>
2307             *
2308             * @param groupIds the group IDs
2309             * @param start the lower bound of the range of d d m structures
2310             * @param end the upper bound of the range of d d m structures (not inclusive)
2311             * @return the range of matching d d m structures
2312             * @throws SystemException if a system exception occurred
2313             */
2314            public List<DDMStructure> findByGroupId(long[] groupIds, int start, int end)
2315                    throws SystemException {
2316                    return findByGroupId(groupIds, start, end, null);
2317            }
2318    
2319            /**
2320             * Returns an ordered range of all the d d m structures where groupId = any &#63;.
2321             *
2322             * <p>
2323             * 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.
2324             * </p>
2325             *
2326             * @param groupIds the group IDs
2327             * @param start the lower bound of the range of d d m structures
2328             * @param end the upper bound of the range of d d m structures (not inclusive)
2329             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
2330             * @return the ordered range of matching d d m structures
2331             * @throws SystemException if a system exception occurred
2332             */
2333            public List<DDMStructure> findByGroupId(long[] groupIds, int start,
2334                    int end, OrderByComparator orderByComparator) throws SystemException {
2335                    if ((groupIds != null) && (groupIds.length == 1)) {
2336                            return findByGroupId(groupIds[0], start, end, orderByComparator);
2337                    }
2338    
2339                    boolean pagination = true;
2340                    Object[] finderArgs = null;
2341    
2342                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
2343                                    (orderByComparator == null)) {
2344                            pagination = false;
2345                            finderArgs = new Object[] { StringUtil.merge(groupIds) };
2346                    }
2347                    else {
2348                            finderArgs = new Object[] {
2349                                            StringUtil.merge(groupIds),
2350                                            
2351                                            start, end, orderByComparator
2352                                    };
2353                    }
2354    
2355                    List<DDMStructure> list = (List<DDMStructure>)FinderCacheUtil.getResult(FINDER_PATH_WITH_PAGINATION_FIND_BY_GROUPID,
2356                                    finderArgs, this);
2357    
2358                    if ((list != null) && !list.isEmpty()) {
2359                            for (DDMStructure ddmStructure : list) {
2360                                    if (!ArrayUtil.contains(groupIds, ddmStructure.getGroupId())) {
2361                                            list = null;
2362    
2363                                            break;
2364                                    }
2365                            }
2366                    }
2367    
2368                    if (list == null) {
2369                            StringBundler query = new StringBundler();
2370    
2371                            query.append(_SQL_SELECT_DDMSTRUCTURE_WHERE);
2372    
2373                            boolean conjunctionable = false;
2374    
2375                            if ((groupIds == null) || (groupIds.length > 0)) {
2376                                    if (conjunctionable) {
2377                                            query.append(WHERE_AND);
2378                                    }
2379    
2380                                    query.append(StringPool.OPEN_PARENTHESIS);
2381    
2382                                    for (int i = 0; i < groupIds.length; i++) {
2383                                            query.append(_FINDER_COLUMN_GROUPID_GROUPID_5);
2384    
2385                                            if ((i + 1) < groupIds.length) {
2386                                                    query.append(WHERE_OR);
2387                                            }
2388                                    }
2389    
2390                                    query.append(StringPool.CLOSE_PARENTHESIS);
2391    
2392                                    conjunctionable = true;
2393                            }
2394    
2395                            if (orderByComparator != null) {
2396                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
2397                                            orderByComparator);
2398                            }
2399                            else
2400                             if (pagination) {
2401                                    query.append(DDMStructureModelImpl.ORDER_BY_JPQL);
2402                            }
2403    
2404                            String sql = query.toString();
2405    
2406                            Session session = null;
2407    
2408                            try {
2409                                    session = openSession();
2410    
2411                                    Query q = session.createQuery(sql);
2412    
2413                                    QueryPos qPos = QueryPos.getInstance(q);
2414    
2415                                    if (groupIds != null) {
2416                                            qPos.add(groupIds);
2417                                    }
2418    
2419                                    if (!pagination) {
2420                                            list = (List<DDMStructure>)QueryUtil.list(q, getDialect(),
2421                                                            start, end, false);
2422    
2423                                            Collections.sort(list);
2424    
2425                                            list = new UnmodifiableList<DDMStructure>(list);
2426                                    }
2427                                    else {
2428                                            list = (List<DDMStructure>)QueryUtil.list(q, getDialect(),
2429                                                            start, end);
2430                                    }
2431    
2432                                    cacheResult(list);
2433    
2434                                    FinderCacheUtil.putResult(FINDER_PATH_WITH_PAGINATION_FIND_BY_GROUPID,
2435                                            finderArgs, list);
2436                            }
2437                            catch (Exception e) {
2438                                    FinderCacheUtil.removeResult(FINDER_PATH_WITH_PAGINATION_FIND_BY_GROUPID,
2439                                            finderArgs);
2440    
2441                                    throw processException(e);
2442                            }
2443                            finally {
2444                                    closeSession(session);
2445                            }
2446                    }
2447    
2448                    return list;
2449            }
2450    
2451            /**
2452             * Removes all the d d m structures where groupId = &#63; from the database.
2453             *
2454             * @param groupId the group ID
2455             * @throws SystemException if a system exception occurred
2456             */
2457            public void removeByGroupId(long groupId) throws SystemException {
2458                    for (DDMStructure ddmStructure : findByGroupId(groupId,
2459                                    QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
2460                            remove(ddmStructure);
2461                    }
2462            }
2463    
2464            /**
2465             * Returns the number of d d m structures where groupId = &#63;.
2466             *
2467             * @param groupId the group ID
2468             * @return the number of matching d d m structures
2469             * @throws SystemException if a system exception occurred
2470             */
2471            public int countByGroupId(long groupId) throws SystemException {
2472                    FinderPath finderPath = FINDER_PATH_COUNT_BY_GROUPID;
2473    
2474                    Object[] finderArgs = new Object[] { groupId };
2475    
2476                    Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
2477                                    this);
2478    
2479                    if (count == null) {
2480                            StringBundler query = new StringBundler(2);
2481    
2482                            query.append(_SQL_COUNT_DDMSTRUCTURE_WHERE);
2483    
2484                            query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
2485    
2486                            String sql = query.toString();
2487    
2488                            Session session = null;
2489    
2490                            try {
2491                                    session = openSession();
2492    
2493                                    Query q = session.createQuery(sql);
2494    
2495                                    QueryPos qPos = QueryPos.getInstance(q);
2496    
2497                                    qPos.add(groupId);
2498    
2499                                    count = (Long)q.uniqueResult();
2500    
2501                                    FinderCacheUtil.putResult(finderPath, finderArgs, count);
2502                            }
2503                            catch (Exception e) {
2504                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
2505    
2506                                    throw processException(e);
2507                            }
2508                            finally {
2509                                    closeSession(session);
2510                            }
2511                    }
2512    
2513                    return count.intValue();
2514            }
2515    
2516            /**
2517             * Returns the number of d d m structures where groupId = any &#63;.
2518             *
2519             * @param groupIds the group IDs
2520             * @return the number of matching d d m structures
2521             * @throws SystemException if a system exception occurred
2522             */
2523            public int countByGroupId(long[] groupIds) throws SystemException {
2524                    Object[] finderArgs = new Object[] { StringUtil.merge(groupIds) };
2525    
2526                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_WITH_PAGINATION_COUNT_BY_GROUPID,
2527                                    finderArgs, this);
2528    
2529                    if (count == null) {
2530                            StringBundler query = new StringBundler();
2531    
2532                            query.append(_SQL_COUNT_DDMSTRUCTURE_WHERE);
2533    
2534                            boolean conjunctionable = false;
2535    
2536                            if ((groupIds == null) || (groupIds.length > 0)) {
2537                                    if (conjunctionable) {
2538                                            query.append(WHERE_AND);
2539                                    }
2540    
2541                                    query.append(StringPool.OPEN_PARENTHESIS);
2542    
2543                                    for (int i = 0; i < groupIds.length; i++) {
2544                                            query.append(_FINDER_COLUMN_GROUPID_GROUPID_5);
2545    
2546                                            if ((i + 1) < groupIds.length) {
2547                                                    query.append(WHERE_OR);
2548                                            }
2549                                    }
2550    
2551                                    query.append(StringPool.CLOSE_PARENTHESIS);
2552    
2553                                    conjunctionable = true;
2554                            }
2555    
2556                            String sql = query.toString();
2557    
2558                            Session session = null;
2559    
2560                            try {
2561                                    session = openSession();
2562    
2563                                    Query q = session.createQuery(sql);
2564    
2565                                    QueryPos qPos = QueryPos.getInstance(q);
2566    
2567                                    if (groupIds != null) {
2568                                            qPos.add(groupIds);
2569                                    }
2570    
2571                                    count = (Long)q.uniqueResult();
2572    
2573                                    FinderCacheUtil.putResult(FINDER_PATH_WITH_PAGINATION_COUNT_BY_GROUPID,
2574                                            finderArgs, count);
2575                            }
2576                            catch (Exception e) {
2577                                    FinderCacheUtil.removeResult(FINDER_PATH_WITH_PAGINATION_COUNT_BY_GROUPID,
2578                                            finderArgs);
2579    
2580                                    throw processException(e);
2581                            }
2582                            finally {
2583                                    closeSession(session);
2584                            }
2585                    }
2586    
2587                    return count.intValue();
2588            }
2589    
2590            /**
2591             * Returns the number of d d m structures that the user has permission to view where groupId = &#63;.
2592             *
2593             * @param groupId the group ID
2594             * @return the number of matching d d m structures that the user has permission to view
2595             * @throws SystemException if a system exception occurred
2596             */
2597            public int filterCountByGroupId(long groupId) throws SystemException {
2598                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
2599                            return countByGroupId(groupId);
2600                    }
2601    
2602                    StringBundler query = new StringBundler(2);
2603    
2604                    query.append(_FILTER_SQL_COUNT_DDMSTRUCTURE_WHERE);
2605    
2606                    query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
2607    
2608                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
2609                                    DDMStructure.class.getName(),
2610                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
2611    
2612                    Session session = null;
2613    
2614                    try {
2615                            session = openSession();
2616    
2617                            SQLQuery q = session.createSQLQuery(sql);
2618    
2619                            q.addScalar(COUNT_COLUMN_NAME,
2620                                    com.liferay.portal.kernel.dao.orm.Type.LONG);
2621    
2622                            QueryPos qPos = QueryPos.getInstance(q);
2623    
2624                            qPos.add(groupId);
2625    
2626                            Long count = (Long)q.uniqueResult();
2627    
2628                            return count.intValue();
2629                    }
2630                    catch (Exception e) {
2631                            throw processException(e);
2632                    }
2633                    finally {
2634                            closeSession(session);
2635                    }
2636            }
2637    
2638            /**
2639             * Returns the number of d d m structures that the user has permission to view where groupId = any &#63;.
2640             *
2641             * @param groupIds the group IDs
2642             * @return the number of matching d d m structures that the user has permission to view
2643             * @throws SystemException if a system exception occurred
2644             */
2645            public int filterCountByGroupId(long[] groupIds) throws SystemException {
2646                    if (!InlineSQLHelperUtil.isEnabled(groupIds)) {
2647                            return countByGroupId(groupIds);
2648                    }
2649    
2650                    StringBundler query = new StringBundler();
2651    
2652                    query.append(_FILTER_SQL_COUNT_DDMSTRUCTURE_WHERE);
2653    
2654                    boolean conjunctionable = false;
2655    
2656                    if ((groupIds == null) || (groupIds.length > 0)) {
2657                            if (conjunctionable) {
2658                                    query.append(WHERE_AND);
2659                            }
2660    
2661                            query.append(StringPool.OPEN_PARENTHESIS);
2662    
2663                            for (int i = 0; i < groupIds.length; i++) {
2664                                    query.append(_FINDER_COLUMN_GROUPID_GROUPID_5);
2665    
2666                                    if ((i + 1) < groupIds.length) {
2667                                            query.append(WHERE_OR);
2668                                    }
2669                            }
2670    
2671                            query.append(StringPool.CLOSE_PARENTHESIS);
2672    
2673                            conjunctionable = true;
2674                    }
2675    
2676                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
2677                                    DDMStructure.class.getName(),
2678                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupIds);
2679    
2680                    Session session = null;
2681    
2682                    try {
2683                            session = openSession();
2684    
2685                            SQLQuery q = session.createSQLQuery(sql);
2686    
2687                            q.addScalar(COUNT_COLUMN_NAME,
2688                                    com.liferay.portal.kernel.dao.orm.Type.LONG);
2689    
2690                            QueryPos qPos = QueryPos.getInstance(q);
2691    
2692                            if (groupIds != null) {
2693                                    qPos.add(groupIds);
2694                            }
2695    
2696                            Long count = (Long)q.uniqueResult();
2697    
2698                            return count.intValue();
2699                    }
2700                    catch (Exception e) {
2701                            throw processException(e);
2702                    }
2703                    finally {
2704                            closeSession(session);
2705                    }
2706            }
2707    
2708            private static final String _FINDER_COLUMN_GROUPID_GROUPID_2 = "ddmStructure.groupId = ?";
2709            private static final String _FINDER_COLUMN_GROUPID_GROUPID_5 = "(" +
2710                    removeConjunction(_FINDER_COLUMN_GROUPID_GROUPID_2) + ")";
2711            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_CLASSNAMEID =
2712                    new FinderPath(DDMStructureModelImpl.ENTITY_CACHE_ENABLED,
2713                            DDMStructureModelImpl.FINDER_CACHE_ENABLED, DDMStructureImpl.class,
2714                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByClassNameId",
2715                            new String[] {
2716                                    Long.class.getName(),
2717                                    
2718                            Integer.class.getName(), Integer.class.getName(),
2719                                    OrderByComparator.class.getName()
2720                            });
2721            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_CLASSNAMEID =
2722                    new FinderPath(DDMStructureModelImpl.ENTITY_CACHE_ENABLED,
2723                            DDMStructureModelImpl.FINDER_CACHE_ENABLED, DDMStructureImpl.class,
2724                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByClassNameId",
2725                            new String[] { Long.class.getName() },
2726                            DDMStructureModelImpl.CLASSNAMEID_COLUMN_BITMASK);
2727            public static final FinderPath FINDER_PATH_COUNT_BY_CLASSNAMEID = new FinderPath(DDMStructureModelImpl.ENTITY_CACHE_ENABLED,
2728                            DDMStructureModelImpl.FINDER_CACHE_ENABLED, Long.class,
2729                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByClassNameId",
2730                            new String[] { Long.class.getName() });
2731    
2732            /**
2733             * Returns all the d d m structures where classNameId = &#63;.
2734             *
2735             * @param classNameId the class name ID
2736             * @return the matching d d m structures
2737             * @throws SystemException if a system exception occurred
2738             */
2739            public List<DDMStructure> findByClassNameId(long classNameId)
2740                    throws SystemException {
2741                    return findByClassNameId(classNameId, QueryUtil.ALL_POS,
2742                            QueryUtil.ALL_POS, null);
2743            }
2744    
2745            /**
2746             * Returns a range of all the d d m structures where classNameId = &#63;.
2747             *
2748             * <p>
2749             * 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.
2750             * </p>
2751             *
2752             * @param classNameId the class name ID
2753             * @param start the lower bound of the range of d d m structures
2754             * @param end the upper bound of the range of d d m structures (not inclusive)
2755             * @return the range of matching d d m structures
2756             * @throws SystemException if a system exception occurred
2757             */
2758            public List<DDMStructure> findByClassNameId(long classNameId, int start,
2759                    int end) throws SystemException {
2760                    return findByClassNameId(classNameId, start, end, null);
2761            }
2762    
2763            /**
2764             * Returns an ordered range of all the d d m structures where classNameId = &#63;.
2765             *
2766             * <p>
2767             * 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.
2768             * </p>
2769             *
2770             * @param classNameId the class name ID
2771             * @param start the lower bound of the range of d d m structures
2772             * @param end the upper bound of the range of d d m structures (not inclusive)
2773             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
2774             * @return the ordered range of matching d d m structures
2775             * @throws SystemException if a system exception occurred
2776             */
2777            public List<DDMStructure> findByClassNameId(long classNameId, int start,
2778                    int end, OrderByComparator orderByComparator) throws SystemException {
2779                    boolean pagination = true;
2780                    FinderPath finderPath = null;
2781                    Object[] finderArgs = null;
2782    
2783                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
2784                                    (orderByComparator == null)) {
2785                            pagination = false;
2786                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_CLASSNAMEID;
2787                            finderArgs = new Object[] { classNameId };
2788                    }
2789                    else {
2790                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_CLASSNAMEID;
2791                            finderArgs = new Object[] { classNameId, start, end, orderByComparator };
2792                    }
2793    
2794                    List<DDMStructure> list = (List<DDMStructure>)FinderCacheUtil.getResult(finderPath,
2795                                    finderArgs, this);
2796    
2797                    if ((list != null) && !list.isEmpty()) {
2798                            for (DDMStructure ddmStructure : list) {
2799                                    if ((classNameId != ddmStructure.getClassNameId())) {
2800                                            list = null;
2801    
2802                                            break;
2803                                    }
2804                            }
2805                    }
2806    
2807                    if (list == null) {
2808                            StringBundler query = null;
2809    
2810                            if (orderByComparator != null) {
2811                                    query = new StringBundler(3 +
2812                                                    (orderByComparator.getOrderByFields().length * 3));
2813                            }
2814                            else {
2815                                    query = new StringBundler(3);
2816                            }
2817    
2818                            query.append(_SQL_SELECT_DDMSTRUCTURE_WHERE);
2819    
2820                            query.append(_FINDER_COLUMN_CLASSNAMEID_CLASSNAMEID_2);
2821    
2822                            if (orderByComparator != null) {
2823                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
2824                                            orderByComparator);
2825                            }
2826                            else
2827                             if (pagination) {
2828                                    query.append(DDMStructureModelImpl.ORDER_BY_JPQL);
2829                            }
2830    
2831                            String sql = query.toString();
2832    
2833                            Session session = null;
2834    
2835                            try {
2836                                    session = openSession();
2837    
2838                                    Query q = session.createQuery(sql);
2839    
2840                                    QueryPos qPos = QueryPos.getInstance(q);
2841    
2842                                    qPos.add(classNameId);
2843    
2844                                    if (!pagination) {
2845                                            list = (List<DDMStructure>)QueryUtil.list(q, getDialect(),
2846                                                            start, end, false);
2847    
2848                                            Collections.sort(list);
2849    
2850                                            list = new UnmodifiableList<DDMStructure>(list);
2851                                    }
2852                                    else {
2853                                            list = (List<DDMStructure>)QueryUtil.list(q, getDialect(),
2854                                                            start, end);
2855                                    }
2856    
2857                                    cacheResult(list);
2858    
2859                                    FinderCacheUtil.putResult(finderPath, finderArgs, list);
2860                            }
2861                            catch (Exception e) {
2862                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
2863    
2864                                    throw processException(e);
2865                            }
2866                            finally {
2867                                    closeSession(session);
2868                            }
2869                    }
2870    
2871                    return list;
2872            }
2873    
2874            /**
2875             * Returns the first d d m structure in the ordered set where classNameId = &#63;.
2876             *
2877             * @param classNameId the class name ID
2878             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
2879             * @return the first matching d d m structure
2880             * @throws com.liferay.portlet.dynamicdatamapping.NoSuchStructureException if a matching d d m structure could not be found
2881             * @throws SystemException if a system exception occurred
2882             */
2883            public DDMStructure findByClassNameId_First(long classNameId,
2884                    OrderByComparator orderByComparator)
2885                    throws NoSuchStructureException, SystemException {
2886                    DDMStructure ddmStructure = fetchByClassNameId_First(classNameId,
2887                                    orderByComparator);
2888    
2889                    if (ddmStructure != null) {
2890                            return ddmStructure;
2891                    }
2892    
2893                    StringBundler msg = new StringBundler(4);
2894    
2895                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
2896    
2897                    msg.append("classNameId=");
2898                    msg.append(classNameId);
2899    
2900                    msg.append(StringPool.CLOSE_CURLY_BRACE);
2901    
2902                    throw new NoSuchStructureException(msg.toString());
2903            }
2904    
2905            /**
2906             * Returns the first d d m structure in the ordered set where classNameId = &#63;.
2907             *
2908             * @param classNameId the class name ID
2909             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
2910             * @return the first matching d d m structure, or <code>null</code> if a matching d d m structure could not be found
2911             * @throws SystemException if a system exception occurred
2912             */
2913            public DDMStructure fetchByClassNameId_First(long classNameId,
2914                    OrderByComparator orderByComparator) throws SystemException {
2915                    List<DDMStructure> list = findByClassNameId(classNameId, 0, 1,
2916                                    orderByComparator);
2917    
2918                    if (!list.isEmpty()) {
2919                            return list.get(0);
2920                    }
2921    
2922                    return null;
2923            }
2924    
2925            /**
2926             * Returns the last d d m structure in the ordered set where classNameId = &#63;.
2927             *
2928             * @param classNameId the class name ID
2929             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
2930             * @return the last matching d d m structure
2931             * @throws com.liferay.portlet.dynamicdatamapping.NoSuchStructureException if a matching d d m structure could not be found
2932             * @throws SystemException if a system exception occurred
2933             */
2934            public DDMStructure findByClassNameId_Last(long classNameId,
2935                    OrderByComparator orderByComparator)
2936                    throws NoSuchStructureException, SystemException {
2937                    DDMStructure ddmStructure = fetchByClassNameId_Last(classNameId,
2938                                    orderByComparator);
2939    
2940                    if (ddmStructure != null) {
2941                            return ddmStructure;
2942                    }
2943    
2944                    StringBundler msg = new StringBundler(4);
2945    
2946                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
2947    
2948                    msg.append("classNameId=");
2949                    msg.append(classNameId);
2950    
2951                    msg.append(StringPool.CLOSE_CURLY_BRACE);
2952    
2953                    throw new NoSuchStructureException(msg.toString());
2954            }
2955    
2956            /**
2957             * Returns the last d d m structure in the ordered set where classNameId = &#63;.
2958             *
2959             * @param classNameId the class name ID
2960             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
2961             * @return the last matching d d m structure, or <code>null</code> if a matching d d m structure could not be found
2962             * @throws SystemException if a system exception occurred
2963             */
2964            public DDMStructure fetchByClassNameId_Last(long classNameId,
2965                    OrderByComparator orderByComparator) throws SystemException {
2966                    int count = countByClassNameId(classNameId);
2967    
2968                    List<DDMStructure> list = findByClassNameId(classNameId, count - 1,
2969                                    count, orderByComparator);
2970    
2971                    if (!list.isEmpty()) {
2972                            return list.get(0);
2973                    }
2974    
2975                    return null;
2976            }
2977    
2978            /**
2979             * Returns the d d m structures before and after the current d d m structure in the ordered set where classNameId = &#63;.
2980             *
2981             * @param structureId the primary key of the current d d m structure
2982             * @param classNameId the class name ID
2983             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
2984             * @return the previous, current, and next d d m structure
2985             * @throws com.liferay.portlet.dynamicdatamapping.NoSuchStructureException if a d d m structure with the primary key could not be found
2986             * @throws SystemException if a system exception occurred
2987             */
2988            public DDMStructure[] findByClassNameId_PrevAndNext(long structureId,
2989                    long classNameId, OrderByComparator orderByComparator)
2990                    throws NoSuchStructureException, SystemException {
2991                    DDMStructure ddmStructure = findByPrimaryKey(structureId);
2992    
2993                    Session session = null;
2994    
2995                    try {
2996                            session = openSession();
2997    
2998                            DDMStructure[] array = new DDMStructureImpl[3];
2999    
3000                            array[0] = getByClassNameId_PrevAndNext(session, ddmStructure,
3001                                            classNameId, orderByComparator, true);
3002    
3003                            array[1] = ddmStructure;
3004    
3005                            array[2] = getByClassNameId_PrevAndNext(session, ddmStructure,
3006                                            classNameId, orderByComparator, false);
3007    
3008                            return array;
3009                    }
3010                    catch (Exception e) {
3011                            throw processException(e);
3012                    }
3013                    finally {
3014                            closeSession(session);
3015                    }
3016            }
3017    
3018            protected DDMStructure getByClassNameId_PrevAndNext(Session session,
3019                    DDMStructure ddmStructure, long classNameId,
3020                    OrderByComparator orderByComparator, boolean previous) {
3021                    StringBundler query = null;
3022    
3023                    if (orderByComparator != null) {
3024                            query = new StringBundler(6 +
3025                                            (orderByComparator.getOrderByFields().length * 6));
3026                    }
3027                    else {
3028                            query = new StringBundler(3);
3029                    }
3030    
3031                    query.append(_SQL_SELECT_DDMSTRUCTURE_WHERE);
3032    
3033                    query.append(_FINDER_COLUMN_CLASSNAMEID_CLASSNAMEID_2);
3034    
3035                    if (orderByComparator != null) {
3036                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
3037    
3038                            if (orderByConditionFields.length > 0) {
3039                                    query.append(WHERE_AND);
3040                            }
3041    
3042                            for (int i = 0; i < orderByConditionFields.length; i++) {
3043                                    query.append(_ORDER_BY_ENTITY_ALIAS);
3044                                    query.append(orderByConditionFields[i]);
3045    
3046                                    if ((i + 1) < orderByConditionFields.length) {
3047                                            if (orderByComparator.isAscending() ^ previous) {
3048                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
3049                                            }
3050                                            else {
3051                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
3052                                            }
3053                                    }
3054                                    else {
3055                                            if (orderByComparator.isAscending() ^ previous) {
3056                                                    query.append(WHERE_GREATER_THAN);
3057                                            }
3058                                            else {
3059                                                    query.append(WHERE_LESSER_THAN);
3060                                            }
3061                                    }
3062                            }
3063    
3064                            query.append(ORDER_BY_CLAUSE);
3065    
3066                            String[] orderByFields = orderByComparator.getOrderByFields();
3067    
3068                            for (int i = 0; i < orderByFields.length; i++) {
3069                                    query.append(_ORDER_BY_ENTITY_ALIAS);
3070                                    query.append(orderByFields[i]);
3071    
3072                                    if ((i + 1) < orderByFields.length) {
3073                                            if (orderByComparator.isAscending() ^ previous) {
3074                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
3075                                            }
3076                                            else {
3077                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
3078                                            }
3079                                    }
3080                                    else {
3081                                            if (orderByComparator.isAscending() ^ previous) {
3082                                                    query.append(ORDER_BY_ASC);
3083                                            }
3084                                            else {
3085                                                    query.append(ORDER_BY_DESC);
3086                                            }
3087                                    }
3088                            }
3089                    }
3090                    else {
3091                            query.append(DDMStructureModelImpl.ORDER_BY_JPQL);
3092                    }
3093    
3094                    String sql = query.toString();
3095    
3096                    Query q = session.createQuery(sql);
3097    
3098                    q.setFirstResult(0);
3099                    q.setMaxResults(2);
3100    
3101                    QueryPos qPos = QueryPos.getInstance(q);
3102    
3103                    qPos.add(classNameId);
3104    
3105                    if (orderByComparator != null) {
3106                            Object[] values = orderByComparator.getOrderByConditionValues(ddmStructure);
3107    
3108                            for (Object value : values) {
3109                                    qPos.add(value);
3110                            }
3111                    }
3112    
3113                    List<DDMStructure> list = q.list();
3114    
3115                    if (list.size() == 2) {
3116                            return list.get(1);
3117                    }
3118                    else {
3119                            return null;
3120                    }
3121            }
3122    
3123            /**
3124             * Removes all the d d m structures where classNameId = &#63; from the database.
3125             *
3126             * @param classNameId the class name ID
3127             * @throws SystemException if a system exception occurred
3128             */
3129            public void removeByClassNameId(long classNameId) throws SystemException {
3130                    for (DDMStructure ddmStructure : findByClassNameId(classNameId,
3131                                    QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
3132                            remove(ddmStructure);
3133                    }
3134            }
3135    
3136            /**
3137             * Returns the number of d d m structures where classNameId = &#63;.
3138             *
3139             * @param classNameId the class name ID
3140             * @return the number of matching d d m structures
3141             * @throws SystemException if a system exception occurred
3142             */
3143            public int countByClassNameId(long classNameId) throws SystemException {
3144                    FinderPath finderPath = FINDER_PATH_COUNT_BY_CLASSNAMEID;
3145    
3146                    Object[] finderArgs = new Object[] { classNameId };
3147    
3148                    Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
3149                                    this);
3150    
3151                    if (count == null) {
3152                            StringBundler query = new StringBundler(2);
3153    
3154                            query.append(_SQL_COUNT_DDMSTRUCTURE_WHERE);
3155    
3156                            query.append(_FINDER_COLUMN_CLASSNAMEID_CLASSNAMEID_2);
3157    
3158                            String sql = query.toString();
3159    
3160                            Session session = null;
3161    
3162                            try {
3163                                    session = openSession();
3164    
3165                                    Query q = session.createQuery(sql);
3166    
3167                                    QueryPos qPos = QueryPos.getInstance(q);
3168    
3169                                    qPos.add(classNameId);
3170    
3171                                    count = (Long)q.uniqueResult();
3172    
3173                                    FinderCacheUtil.putResult(finderPath, finderArgs, count);
3174                            }
3175                            catch (Exception e) {
3176                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
3177    
3178                                    throw processException(e);
3179                            }
3180                            finally {
3181                                    closeSession(session);
3182                            }
3183                    }
3184    
3185                    return count.intValue();
3186            }
3187    
3188            private static final String _FINDER_COLUMN_CLASSNAMEID_CLASSNAMEID_2 = "ddmStructure.classNameId = ?";
3189            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_STRUCTUREKEY =
3190                    new FinderPath(DDMStructureModelImpl.ENTITY_CACHE_ENABLED,
3191                            DDMStructureModelImpl.FINDER_CACHE_ENABLED, DDMStructureImpl.class,
3192                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByStructureKey",
3193                            new String[] {
3194                                    String.class.getName(),
3195                                    
3196                            Integer.class.getName(), Integer.class.getName(),
3197                                    OrderByComparator.class.getName()
3198                            });
3199            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_STRUCTUREKEY =
3200                    new FinderPath(DDMStructureModelImpl.ENTITY_CACHE_ENABLED,
3201                            DDMStructureModelImpl.FINDER_CACHE_ENABLED, DDMStructureImpl.class,
3202                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByStructureKey",
3203                            new String[] { String.class.getName() },
3204                            DDMStructureModelImpl.STRUCTUREKEY_COLUMN_BITMASK);
3205            public static final FinderPath FINDER_PATH_COUNT_BY_STRUCTUREKEY = new FinderPath(DDMStructureModelImpl.ENTITY_CACHE_ENABLED,
3206                            DDMStructureModelImpl.FINDER_CACHE_ENABLED, Long.class,
3207                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByStructureKey",
3208                            new String[] { String.class.getName() });
3209    
3210            /**
3211             * Returns all the d d m structures where structureKey = &#63;.
3212             *
3213             * @param structureKey the structure key
3214             * @return the matching d d m structures
3215             * @throws SystemException if a system exception occurred
3216             */
3217            public List<DDMStructure> findByStructureKey(String structureKey)
3218                    throws SystemException {
3219                    return findByStructureKey(structureKey, QueryUtil.ALL_POS,
3220                            QueryUtil.ALL_POS, null);
3221            }
3222    
3223            /**
3224             * Returns a range of all the d d m structures where structureKey = &#63;.
3225             *
3226             * <p>
3227             * 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.
3228             * </p>
3229             *
3230             * @param structureKey the structure key
3231             * @param start the lower bound of the range of d d m structures
3232             * @param end the upper bound of the range of d d m structures (not inclusive)
3233             * @return the range of matching d d m structures
3234             * @throws SystemException if a system exception occurred
3235             */
3236            public List<DDMStructure> findByStructureKey(String structureKey,
3237                    int start, int end) throws SystemException {
3238                    return findByStructureKey(structureKey, start, end, null);
3239            }
3240    
3241            /**
3242             * Returns an ordered range of all the d d m structures where structureKey = &#63;.
3243             *
3244             * <p>
3245             * 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.
3246             * </p>
3247             *
3248             * @param structureKey the structure key
3249             * @param start the lower bound of the range of d d m structures
3250             * @param end the upper bound of the range of d d m structures (not inclusive)
3251             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
3252             * @return the ordered range of matching d d m structures
3253             * @throws SystemException if a system exception occurred
3254             */
3255            public List<DDMStructure> findByStructureKey(String structureKey,
3256                    int start, int end, OrderByComparator orderByComparator)
3257                    throws SystemException {
3258                    boolean pagination = true;
3259                    FinderPath finderPath = null;
3260                    Object[] finderArgs = null;
3261    
3262                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
3263                                    (orderByComparator == null)) {
3264                            pagination = false;
3265                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_STRUCTUREKEY;
3266                            finderArgs = new Object[] { structureKey };
3267                    }
3268                    else {
3269                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_STRUCTUREKEY;
3270                            finderArgs = new Object[] {
3271                                            structureKey,
3272                                            
3273                                            start, end, orderByComparator
3274                                    };
3275                    }
3276    
3277                    List<DDMStructure> list = (List<DDMStructure>)FinderCacheUtil.getResult(finderPath,
3278                                    finderArgs, this);
3279    
3280                    if ((list != null) && !list.isEmpty()) {
3281                            for (DDMStructure ddmStructure : list) {
3282                                    if (!Validator.equals(structureKey,
3283                                                            ddmStructure.getStructureKey())) {
3284                                            list = null;
3285    
3286                                            break;
3287                                    }
3288                            }
3289                    }
3290    
3291                    if (list == null) {
3292                            StringBundler query = null;
3293    
3294                            if (orderByComparator != null) {
3295                                    query = new StringBundler(3 +
3296                                                    (orderByComparator.getOrderByFields().length * 3));
3297                            }
3298                            else {
3299                                    query = new StringBundler(3);
3300                            }
3301    
3302                            query.append(_SQL_SELECT_DDMSTRUCTURE_WHERE);
3303    
3304                            boolean bindStructureKey = false;
3305    
3306                            if (structureKey == null) {
3307                                    query.append(_FINDER_COLUMN_STRUCTUREKEY_STRUCTUREKEY_1);
3308                            }
3309                            else if (structureKey.equals(StringPool.BLANK)) {
3310                                    query.append(_FINDER_COLUMN_STRUCTUREKEY_STRUCTUREKEY_3);
3311                            }
3312                            else {
3313                                    bindStructureKey = true;
3314    
3315                                    query.append(_FINDER_COLUMN_STRUCTUREKEY_STRUCTUREKEY_2);
3316                            }
3317    
3318                            if (orderByComparator != null) {
3319                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
3320                                            orderByComparator);
3321                            }
3322                            else
3323                             if (pagination) {
3324                                    query.append(DDMStructureModelImpl.ORDER_BY_JPQL);
3325                            }
3326    
3327                            String sql = query.toString();
3328    
3329                            Session session = null;
3330    
3331                            try {
3332                                    session = openSession();
3333    
3334                                    Query q = session.createQuery(sql);
3335    
3336                                    QueryPos qPos = QueryPos.getInstance(q);
3337    
3338                                    if (bindStructureKey) {
3339                                            qPos.add(structureKey);
3340                                    }
3341    
3342                                    if (!pagination) {
3343                                            list = (List<DDMStructure>)QueryUtil.list(q, getDialect(),
3344                                                            start, end, false);
3345    
3346                                            Collections.sort(list);
3347    
3348                                            list = new UnmodifiableList<DDMStructure>(list);
3349                                    }
3350                                    else {
3351                                            list = (List<DDMStructure>)QueryUtil.list(q, getDialect(),
3352                                                            start, end);
3353                                    }
3354    
3355                                    cacheResult(list);
3356    
3357                                    FinderCacheUtil.putResult(finderPath, finderArgs, list);
3358                            }
3359                            catch (Exception e) {
3360                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
3361    
3362                                    throw processException(e);
3363                            }
3364                            finally {
3365                                    closeSession(session);
3366                            }
3367                    }
3368    
3369                    return list;
3370            }
3371    
3372            /**
3373             * Returns the first d d m structure in the ordered set where structureKey = &#63;.
3374             *
3375             * @param structureKey the structure key
3376             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
3377             * @return the first matching d d m structure
3378             * @throws com.liferay.portlet.dynamicdatamapping.NoSuchStructureException if a matching d d m structure could not be found
3379             * @throws SystemException if a system exception occurred
3380             */
3381            public DDMStructure findByStructureKey_First(String structureKey,
3382                    OrderByComparator orderByComparator)
3383                    throws NoSuchStructureException, SystemException {
3384                    DDMStructure ddmStructure = fetchByStructureKey_First(structureKey,
3385                                    orderByComparator);
3386    
3387                    if (ddmStructure != null) {
3388                            return ddmStructure;
3389                    }
3390    
3391                    StringBundler msg = new StringBundler(4);
3392    
3393                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
3394    
3395                    msg.append("structureKey=");
3396                    msg.append(structureKey);
3397    
3398                    msg.append(StringPool.CLOSE_CURLY_BRACE);
3399    
3400                    throw new NoSuchStructureException(msg.toString());
3401            }
3402    
3403            /**
3404             * Returns the first d d m structure in the ordered set where structureKey = &#63;.
3405             *
3406             * @param structureKey the structure key
3407             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
3408             * @return the first matching d d m structure, or <code>null</code> if a matching d d m structure could not be found
3409             * @throws SystemException if a system exception occurred
3410             */
3411            public DDMStructure fetchByStructureKey_First(String structureKey,
3412                    OrderByComparator orderByComparator) throws SystemException {
3413                    List<DDMStructure> list = findByStructureKey(structureKey, 0, 1,
3414                                    orderByComparator);
3415    
3416                    if (!list.isEmpty()) {
3417                            return list.get(0);
3418                    }
3419    
3420                    return null;
3421            }
3422    
3423            /**
3424             * Returns the last d d m structure in the ordered set where structureKey = &#63;.
3425             *
3426             * @param structureKey the structure key
3427             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
3428             * @return the last matching d d m structure
3429             * @throws com.liferay.portlet.dynamicdatamapping.NoSuchStructureException if a matching d d m structure could not be found
3430             * @throws SystemException if a system exception occurred
3431             */
3432            public DDMStructure findByStructureKey_Last(String structureKey,
3433                    OrderByComparator orderByComparator)
3434                    throws NoSuchStructureException, SystemException {
3435                    DDMStructure ddmStructure = fetchByStructureKey_Last(structureKey,
3436                                    orderByComparator);
3437    
3438                    if (ddmStructure != null) {
3439                            return ddmStructure;
3440                    }
3441    
3442                    StringBundler msg = new StringBundler(4);
3443    
3444                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
3445    
3446                    msg.append("structureKey=");
3447                    msg.append(structureKey);
3448    
3449                    msg.append(StringPool.CLOSE_CURLY_BRACE);
3450    
3451                    throw new NoSuchStructureException(msg.toString());
3452            }
3453    
3454            /**
3455             * Returns the last d d m structure in the ordered set where structureKey = &#63;.
3456             *
3457             * @param structureKey the structure key
3458             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
3459             * @return the last matching d d m structure, or <code>null</code> if a matching d d m structure could not be found
3460             * @throws SystemException if a system exception occurred
3461             */
3462            public DDMStructure fetchByStructureKey_Last(String structureKey,
3463                    OrderByComparator orderByComparator) throws SystemException {
3464                    int count = countByStructureKey(structureKey);
3465    
3466                    List<DDMStructure> list = findByStructureKey(structureKey, count - 1,
3467                                    count, orderByComparator);
3468    
3469                    if (!list.isEmpty()) {
3470                            return list.get(0);
3471                    }
3472    
3473                    return null;
3474            }
3475    
3476            /**
3477             * Returns the d d m structures before and after the current d d m structure in the ordered set where structureKey = &#63;.
3478             *
3479             * @param structureId the primary key of the current d d m structure
3480             * @param structureKey the structure key
3481             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
3482             * @return the previous, current, and next d d m structure
3483             * @throws com.liferay.portlet.dynamicdatamapping.NoSuchStructureException if a d d m structure with the primary key could not be found
3484             * @throws SystemException if a system exception occurred
3485             */
3486            public DDMStructure[] findByStructureKey_PrevAndNext(long structureId,
3487                    String structureKey, OrderByComparator orderByComparator)
3488                    throws NoSuchStructureException, SystemException {
3489                    DDMStructure ddmStructure = findByPrimaryKey(structureId);
3490    
3491                    Session session = null;
3492    
3493                    try {
3494                            session = openSession();
3495    
3496                            DDMStructure[] array = new DDMStructureImpl[3];
3497    
3498                            array[0] = getByStructureKey_PrevAndNext(session, ddmStructure,
3499                                            structureKey, orderByComparator, true);
3500    
3501                            array[1] = ddmStructure;
3502    
3503                            array[2] = getByStructureKey_PrevAndNext(session, ddmStructure,
3504                                            structureKey, orderByComparator, false);
3505    
3506                            return array;
3507                    }
3508                    catch (Exception e) {
3509                            throw processException(e);
3510                    }
3511                    finally {
3512                            closeSession(session);
3513                    }
3514            }
3515    
3516            protected DDMStructure getByStructureKey_PrevAndNext(Session session,
3517                    DDMStructure ddmStructure, String structureKey,
3518                    OrderByComparator orderByComparator, boolean previous) {
3519                    StringBundler query = null;
3520    
3521                    if (orderByComparator != null) {
3522                            query = new StringBundler(6 +
3523                                            (orderByComparator.getOrderByFields().length * 6));
3524                    }
3525                    else {
3526                            query = new StringBundler(3);
3527                    }
3528    
3529                    query.append(_SQL_SELECT_DDMSTRUCTURE_WHERE);
3530    
3531                    boolean bindStructureKey = false;
3532    
3533                    if (structureKey == null) {
3534                            query.append(_FINDER_COLUMN_STRUCTUREKEY_STRUCTUREKEY_1);
3535                    }
3536                    else if (structureKey.equals(StringPool.BLANK)) {
3537                            query.append(_FINDER_COLUMN_STRUCTUREKEY_STRUCTUREKEY_3);
3538                    }
3539                    else {
3540                            bindStructureKey = true;
3541    
3542                            query.append(_FINDER_COLUMN_STRUCTUREKEY_STRUCTUREKEY_2);
3543                    }
3544    
3545                    if (orderByComparator != null) {
3546                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
3547    
3548                            if (orderByConditionFields.length > 0) {
3549                                    query.append(WHERE_AND);
3550                            }
3551    
3552                            for (int i = 0; i < orderByConditionFields.length; i++) {
3553                                    query.append(_ORDER_BY_ENTITY_ALIAS);
3554                                    query.append(orderByConditionFields[i]);
3555    
3556                                    if ((i + 1) < orderByConditionFields.length) {
3557                                            if (orderByComparator.isAscending() ^ previous) {
3558                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
3559                                            }
3560                                            else {
3561                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
3562                                            }
3563                                    }
3564                                    else {
3565                                            if (orderByComparator.isAscending() ^ previous) {
3566                                                    query.append(WHERE_GREATER_THAN);
3567                                            }
3568                                            else {
3569                                                    query.append(WHERE_LESSER_THAN);
3570                                            }
3571                                    }
3572                            }
3573    
3574                            query.append(ORDER_BY_CLAUSE);
3575    
3576                            String[] orderByFields = orderByComparator.getOrderByFields();
3577    
3578                            for (int i = 0; i < orderByFields.length; i++) {
3579                                    query.append(_ORDER_BY_ENTITY_ALIAS);
3580                                    query.append(orderByFields[i]);
3581    
3582                                    if ((i + 1) < orderByFields.length) {
3583                                            if (orderByComparator.isAscending() ^ previous) {
3584                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
3585                                            }
3586                                            else {
3587                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
3588                                            }
3589                                    }
3590                                    else {
3591                                            if (orderByComparator.isAscending() ^ previous) {
3592                                                    query.append(ORDER_BY_ASC);
3593                                            }
3594                                            else {
3595                                                    query.append(ORDER_BY_DESC);
3596                                            }
3597                                    }
3598                            }
3599                    }
3600                    else {
3601                            query.append(DDMStructureModelImpl.ORDER_BY_JPQL);
3602                    }
3603    
3604                    String sql = query.toString();
3605    
3606                    Query q = session.createQuery(sql);
3607    
3608                    q.setFirstResult(0);
3609                    q.setMaxResults(2);
3610    
3611                    QueryPos qPos = QueryPos.getInstance(q);
3612    
3613                    if (bindStructureKey) {
3614                            qPos.add(structureKey);
3615                    }
3616    
3617                    if (orderByComparator != null) {
3618                            Object[] values = orderByComparator.getOrderByConditionValues(ddmStructure);
3619    
3620                            for (Object value : values) {
3621                                    qPos.add(value);
3622                            }
3623                    }
3624    
3625                    List<DDMStructure> list = q.list();
3626    
3627                    if (list.size() == 2) {
3628                            return list.get(1);
3629                    }
3630                    else {
3631                            return null;
3632                    }
3633            }
3634    
3635            /**
3636             * Removes all the d d m structures where structureKey = &#63; from the database.
3637             *
3638             * @param structureKey the structure key
3639             * @throws SystemException if a system exception occurred
3640             */
3641            public void removeByStructureKey(String structureKey)
3642                    throws SystemException {
3643                    for (DDMStructure ddmStructure : findByStructureKey(structureKey,
3644                                    QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
3645                            remove(ddmStructure);
3646                    }
3647            }
3648    
3649            /**
3650             * Returns the number of d d m structures where structureKey = &#63;.
3651             *
3652             * @param structureKey the structure key
3653             * @return the number of matching d d m structures
3654             * @throws SystemException if a system exception occurred
3655             */
3656            public int countByStructureKey(String structureKey)
3657                    throws SystemException {
3658                    FinderPath finderPath = FINDER_PATH_COUNT_BY_STRUCTUREKEY;
3659    
3660                    Object[] finderArgs = new Object[] { structureKey };
3661    
3662                    Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
3663                                    this);
3664    
3665                    if (count == null) {
3666                            StringBundler query = new StringBundler(2);
3667    
3668                            query.append(_SQL_COUNT_DDMSTRUCTURE_WHERE);
3669    
3670                            boolean bindStructureKey = false;
3671    
3672                            if (structureKey == null) {
3673                                    query.append(_FINDER_COLUMN_STRUCTUREKEY_STRUCTUREKEY_1);
3674                            }
3675                            else if (structureKey.equals(StringPool.BLANK)) {
3676                                    query.append(_FINDER_COLUMN_STRUCTUREKEY_STRUCTUREKEY_3);
3677                            }
3678                            else {
3679                                    bindStructureKey = true;
3680    
3681                                    query.append(_FINDER_COLUMN_STRUCTUREKEY_STRUCTUREKEY_2);
3682                            }
3683    
3684                            String sql = query.toString();
3685    
3686                            Session session = null;
3687    
3688                            try {
3689                                    session = openSession();
3690    
3691                                    Query q = session.createQuery(sql);
3692    
3693                                    QueryPos qPos = QueryPos.getInstance(q);
3694    
3695                                    if (bindStructureKey) {
3696                                            qPos.add(structureKey);
3697                                    }
3698    
3699                                    count = (Long)q.uniqueResult();
3700    
3701                                    FinderCacheUtil.putResult(finderPath, finderArgs, count);
3702                            }
3703                            catch (Exception e) {
3704                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
3705    
3706                                    throw processException(e);
3707                            }
3708                            finally {
3709                                    closeSession(session);
3710                            }
3711                    }
3712    
3713                    return count.intValue();
3714            }
3715    
3716            private static final String _FINDER_COLUMN_STRUCTUREKEY_STRUCTUREKEY_1 = "ddmStructure.structureKey IS NULL";
3717            private static final String _FINDER_COLUMN_STRUCTUREKEY_STRUCTUREKEY_2 = "ddmStructure.structureKey = ?";
3718            private static final String _FINDER_COLUMN_STRUCTUREKEY_STRUCTUREKEY_3 = "(ddmStructure.structureKey IS NULL OR ddmStructure.structureKey = '')";
3719            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_G_C = new FinderPath(DDMStructureModelImpl.ENTITY_CACHE_ENABLED,
3720                            DDMStructureModelImpl.FINDER_CACHE_ENABLED, DDMStructureImpl.class,
3721                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByG_C",
3722                            new String[] {
3723                                    Long.class.getName(), Long.class.getName(),
3724                                    
3725                            Integer.class.getName(), Integer.class.getName(),
3726                                    OrderByComparator.class.getName()
3727                            });
3728            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_C = new FinderPath(DDMStructureModelImpl.ENTITY_CACHE_ENABLED,
3729                            DDMStructureModelImpl.FINDER_CACHE_ENABLED, DDMStructureImpl.class,
3730                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByG_C",
3731                            new String[] { Long.class.getName(), Long.class.getName() },
3732                            DDMStructureModelImpl.GROUPID_COLUMN_BITMASK |
3733                            DDMStructureModelImpl.CLASSNAMEID_COLUMN_BITMASK);
3734            public static final FinderPath FINDER_PATH_COUNT_BY_G_C = new FinderPath(DDMStructureModelImpl.ENTITY_CACHE_ENABLED,
3735                            DDMStructureModelImpl.FINDER_CACHE_ENABLED, Long.class,
3736                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByG_C",
3737                            new String[] { Long.class.getName(), Long.class.getName() });
3738    
3739            /**
3740             * Returns all the d d m structures where groupId = &#63; and classNameId = &#63;.
3741             *
3742             * @param groupId the group ID
3743             * @param classNameId the class name ID
3744             * @return the matching d d m structures
3745             * @throws SystemException if a system exception occurred
3746             */
3747            public List<DDMStructure> findByG_C(long groupId, long classNameId)
3748                    throws SystemException {
3749                    return findByG_C(groupId, classNameId, QueryUtil.ALL_POS,
3750                            QueryUtil.ALL_POS, null);
3751            }
3752    
3753            /**
3754             * Returns a range of all the d d m structures where groupId = &#63; and classNameId = &#63;.
3755             *
3756             * <p>
3757             * 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.
3758             * </p>
3759             *
3760             * @param groupId the group ID
3761             * @param classNameId the class name ID
3762             * @param start the lower bound of the range of d d m structures
3763             * @param end the upper bound of the range of d d m structures (not inclusive)
3764             * @return the range of matching d d m structures
3765             * @throws SystemException if a system exception occurred
3766             */
3767            public List<DDMStructure> findByG_C(long groupId, long classNameId,
3768                    int start, int end) throws SystemException {
3769                    return findByG_C(groupId, classNameId, start, end, null);
3770            }
3771    
3772            /**
3773             * Returns an ordered range of all the d d m structures where groupId = &#63; and classNameId = &#63;.
3774             *
3775             * <p>
3776             * 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.
3777             * </p>
3778             *
3779             * @param groupId the group ID
3780             * @param classNameId the class name ID
3781             * @param start the lower bound of the range of d d m structures
3782             * @param end the upper bound of the range of d d m structures (not inclusive)
3783             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
3784             * @return the ordered range of matching d d m structures
3785             * @throws SystemException if a system exception occurred
3786             */
3787            public List<DDMStructure> findByG_C(long groupId, long classNameId,
3788                    int start, int end, OrderByComparator orderByComparator)
3789                    throws SystemException {
3790                    boolean pagination = true;
3791                    FinderPath finderPath = null;
3792                    Object[] finderArgs = null;
3793    
3794                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
3795                                    (orderByComparator == null)) {
3796                            pagination = false;
3797                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_C;
3798                            finderArgs = new Object[] { groupId, classNameId };
3799                    }
3800                    else {
3801                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_G_C;
3802                            finderArgs = new Object[] {
3803                                            groupId, classNameId,
3804                                            
3805                                            start, end, orderByComparator
3806                                    };
3807                    }
3808    
3809                    List<DDMStructure> list = (List<DDMStructure>)FinderCacheUtil.getResult(finderPath,
3810                                    finderArgs, this);
3811    
3812                    if ((list != null) && !list.isEmpty()) {
3813                            for (DDMStructure ddmStructure : list) {
3814                                    if ((groupId != ddmStructure.getGroupId()) ||
3815                                                    (classNameId != ddmStructure.getClassNameId())) {
3816                                            list = null;
3817    
3818                                            break;
3819                                    }
3820                            }
3821                    }
3822    
3823                    if (list == null) {
3824                            StringBundler query = null;
3825    
3826                            if (orderByComparator != null) {
3827                                    query = new StringBundler(4 +
3828                                                    (orderByComparator.getOrderByFields().length * 3));
3829                            }
3830                            else {
3831                                    query = new StringBundler(4);
3832                            }
3833    
3834                            query.append(_SQL_SELECT_DDMSTRUCTURE_WHERE);
3835    
3836                            query.append(_FINDER_COLUMN_G_C_GROUPID_2);
3837    
3838                            query.append(_FINDER_COLUMN_G_C_CLASSNAMEID_2);
3839    
3840                            if (orderByComparator != null) {
3841                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
3842                                            orderByComparator);
3843                            }
3844                            else
3845                             if (pagination) {
3846                                    query.append(DDMStructureModelImpl.ORDER_BY_JPQL);
3847                            }
3848    
3849                            String sql = query.toString();
3850    
3851                            Session session = null;
3852    
3853                            try {
3854                                    session = openSession();
3855    
3856                                    Query q = session.createQuery(sql);
3857    
3858                                    QueryPos qPos = QueryPos.getInstance(q);
3859    
3860                                    qPos.add(groupId);
3861    
3862                                    qPos.add(classNameId);
3863    
3864                                    if (!pagination) {
3865                                            list = (List<DDMStructure>)QueryUtil.list(q, getDialect(),
3866                                                            start, end, false);
3867    
3868                                            Collections.sort(list);
3869    
3870                                            list = new UnmodifiableList<DDMStructure>(list);
3871                                    }
3872                                    else {
3873                                            list = (List<DDMStructure>)QueryUtil.list(q, getDialect(),
3874                                                            start, end);
3875                                    }
3876    
3877                                    cacheResult(list);
3878    
3879                                    FinderCacheUtil.putResult(finderPath, finderArgs, list);
3880                            }
3881                            catch (Exception e) {
3882                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
3883    
3884                                    throw processException(e);
3885                            }
3886                            finally {
3887                                    closeSession(session);
3888                            }
3889                    }
3890    
3891                    return list;
3892            }
3893    
3894            /**
3895             * Returns the first d d m structure in the ordered set where groupId = &#63; and classNameId = &#63;.
3896             *
3897             * @param groupId the group ID
3898             * @param classNameId the class name ID
3899             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
3900             * @return the first matching d d m structure
3901             * @throws com.liferay.portlet.dynamicdatamapping.NoSuchStructureException if a matching d d m structure could not be found
3902             * @throws SystemException if a system exception occurred
3903             */
3904            public DDMStructure findByG_C_First(long groupId, long classNameId,
3905                    OrderByComparator orderByComparator)
3906                    throws NoSuchStructureException, SystemException {
3907                    DDMStructure ddmStructure = fetchByG_C_First(groupId, classNameId,
3908                                    orderByComparator);
3909    
3910                    if (ddmStructure != null) {
3911                            return ddmStructure;
3912                    }
3913    
3914                    StringBundler msg = new StringBundler(6);
3915    
3916                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
3917    
3918                    msg.append("groupId=");
3919                    msg.append(groupId);
3920    
3921                    msg.append(", classNameId=");
3922                    msg.append(classNameId);
3923    
3924                    msg.append(StringPool.CLOSE_CURLY_BRACE);
3925    
3926                    throw new NoSuchStructureException(msg.toString());
3927            }
3928    
3929            /**
3930             * Returns the first d d m structure in the ordered set where groupId = &#63; and classNameId = &#63;.
3931             *
3932             * @param groupId the group ID
3933             * @param classNameId the class name ID
3934             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
3935             * @return the first matching d d m structure, or <code>null</code> if a matching d d m structure could not be found
3936             * @throws SystemException if a system exception occurred
3937             */
3938            public DDMStructure fetchByG_C_First(long groupId, long classNameId,
3939                    OrderByComparator orderByComparator) throws SystemException {
3940                    List<DDMStructure> list = findByG_C(groupId, classNameId, 0, 1,
3941                                    orderByComparator);
3942    
3943                    if (!list.isEmpty()) {
3944                            return list.get(0);
3945                    }
3946    
3947                    return null;
3948            }
3949    
3950            /**
3951             * Returns the last d d m structure in the ordered set where groupId = &#63; and classNameId = &#63;.
3952             *
3953             * @param groupId the group ID
3954             * @param classNameId the class name ID
3955             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
3956             * @return the last matching d d m structure
3957             * @throws com.liferay.portlet.dynamicdatamapping.NoSuchStructureException if a matching d d m structure could not be found
3958             * @throws SystemException if a system exception occurred
3959             */
3960            public DDMStructure findByG_C_Last(long groupId, long classNameId,
3961                    OrderByComparator orderByComparator)
3962                    throws NoSuchStructureException, SystemException {
3963                    DDMStructure ddmStructure = fetchByG_C_Last(groupId, classNameId,
3964                                    orderByComparator);
3965    
3966                    if (ddmStructure != null) {
3967                            return ddmStructure;
3968                    }
3969    
3970                    StringBundler msg = new StringBundler(6);
3971    
3972                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
3973    
3974                    msg.append("groupId=");
3975                    msg.append(groupId);
3976    
3977                    msg.append(", classNameId=");
3978                    msg.append(classNameId);
3979    
3980                    msg.append(StringPool.CLOSE_CURLY_BRACE);
3981    
3982                    throw new NoSuchStructureException(msg.toString());
3983            }
3984    
3985            /**
3986             * Returns the last d d m structure in the ordered set where groupId = &#63; and classNameId = &#63;.
3987             *
3988             * @param groupId the group ID
3989             * @param classNameId the class name ID
3990             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
3991             * @return the last matching d d m structure, or <code>null</code> if a matching d d m structure could not be found
3992             * @throws SystemException if a system exception occurred
3993             */
3994            public DDMStructure fetchByG_C_Last(long groupId, long classNameId,
3995                    OrderByComparator orderByComparator) throws SystemException {
3996                    int count = countByG_C(groupId, classNameId);
3997    
3998                    List<DDMStructure> list = findByG_C(groupId, classNameId, count - 1,
3999                                    count, orderByComparator);
4000    
4001                    if (!list.isEmpty()) {
4002                            return list.get(0);
4003                    }
4004    
4005                    return null;
4006            }
4007    
4008            /**
4009             * 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;.
4010             *
4011             * @param structureId the primary key of the current d d m structure
4012             * @param groupId the group ID
4013             * @param classNameId the class name ID
4014             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
4015             * @return the previous, current, and next d d m structure
4016             * @throws com.liferay.portlet.dynamicdatamapping.NoSuchStructureException if a d d m structure with the primary key could not be found
4017             * @throws SystemException if a system exception occurred
4018             */
4019            public DDMStructure[] findByG_C_PrevAndNext(long structureId, long groupId,
4020                    long classNameId, OrderByComparator orderByComparator)
4021                    throws NoSuchStructureException, SystemException {
4022                    DDMStructure ddmStructure = findByPrimaryKey(structureId);
4023    
4024                    Session session = null;
4025    
4026                    try {
4027                            session = openSession();
4028    
4029                            DDMStructure[] array = new DDMStructureImpl[3];
4030    
4031                            array[0] = getByG_C_PrevAndNext(session, ddmStructure, groupId,
4032                                            classNameId, orderByComparator, true);
4033    
4034                            array[1] = ddmStructure;
4035    
4036                            array[2] = getByG_C_PrevAndNext(session, ddmStructure, groupId,
4037                                            classNameId, orderByComparator, false);
4038    
4039                            return array;
4040                    }
4041                    catch (Exception e) {
4042                            throw processException(e);
4043                    }
4044                    finally {
4045                            closeSession(session);
4046                    }
4047            }
4048    
4049            protected DDMStructure getByG_C_PrevAndNext(Session session,
4050                    DDMStructure ddmStructure, long groupId, long classNameId,
4051                    OrderByComparator orderByComparator, boolean previous) {
4052                    StringBundler query = null;
4053    
4054                    if (orderByComparator != null) {
4055                            query = new StringBundler(6 +
4056                                            (orderByComparator.getOrderByFields().length * 6));
4057                    }
4058                    else {
4059                            query = new StringBundler(3);
4060                    }
4061    
4062                    query.append(_SQL_SELECT_DDMSTRUCTURE_WHERE);
4063    
4064                    query.append(_FINDER_COLUMN_G_C_GROUPID_2);
4065    
4066                    query.append(_FINDER_COLUMN_G_C_CLASSNAMEID_2);
4067    
4068                    if (orderByComparator != null) {
4069                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
4070    
4071                            if (orderByConditionFields.length > 0) {
4072                                    query.append(WHERE_AND);
4073                            }
4074    
4075                            for (int i = 0; i < orderByConditionFields.length; i++) {
4076                                    query.append(_ORDER_BY_ENTITY_ALIAS);
4077                                    query.append(orderByConditionFields[i]);
4078    
4079                                    if ((i + 1) < orderByConditionFields.length) {
4080                                            if (orderByComparator.isAscending() ^ previous) {
4081                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
4082                                            }
4083                                            else {
4084                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
4085                                            }
4086                                    }
4087                                    else {
4088                                            if (orderByComparator.isAscending() ^ previous) {
4089                                                    query.append(WHERE_GREATER_THAN);
4090                                            }
4091                                            else {
4092                                                    query.append(WHERE_LESSER_THAN);
4093                                            }
4094                                    }
4095                            }
4096    
4097                            query.append(ORDER_BY_CLAUSE);
4098    
4099                            String[] orderByFields = orderByComparator.getOrderByFields();
4100    
4101                            for (int i = 0; i < orderByFields.length; i++) {
4102                                    query.append(_ORDER_BY_ENTITY_ALIAS);
4103                                    query.append(orderByFields[i]);
4104    
4105                                    if ((i + 1) < orderByFields.length) {
4106                                            if (orderByComparator.isAscending() ^ previous) {
4107                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
4108                                            }
4109                                            else {
4110                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
4111                                            }
4112                                    }
4113                                    else {
4114                                            if (orderByComparator.isAscending() ^ previous) {
4115                                                    query.append(ORDER_BY_ASC);
4116                                            }
4117                                            else {
4118                                                    query.append(ORDER_BY_DESC);
4119                                            }
4120                                    }
4121                            }
4122                    }
4123                    else {
4124                            query.append(DDMStructureModelImpl.ORDER_BY_JPQL);
4125                    }
4126    
4127                    String sql = query.toString();
4128    
4129                    Query q = session.createQuery(sql);
4130    
4131                    q.setFirstResult(0);
4132                    q.setMaxResults(2);
4133    
4134                    QueryPos qPos = QueryPos.getInstance(q);
4135    
4136                    qPos.add(groupId);
4137    
4138                    qPos.add(classNameId);
4139    
4140                    if (orderByComparator != null) {
4141                            Object[] values = orderByComparator.getOrderByConditionValues(ddmStructure);
4142    
4143                            for (Object value : values) {
4144                                    qPos.add(value);
4145                            }
4146                    }
4147    
4148                    List<DDMStructure> list = q.list();
4149    
4150                    if (list.size() == 2) {
4151                            return list.get(1);
4152                    }
4153                    else {
4154                            return null;
4155                    }
4156            }
4157    
4158            /**
4159             * Returns all the d d m structures that the user has permission to view where groupId = &#63; and classNameId = &#63;.
4160             *
4161             * @param groupId the group ID
4162             * @param classNameId the class name ID
4163             * @return the matching d d m structures that the user has permission to view
4164             * @throws SystemException if a system exception occurred
4165             */
4166            public List<DDMStructure> filterFindByG_C(long groupId, long classNameId)
4167                    throws SystemException {
4168                    return filterFindByG_C(groupId, classNameId, QueryUtil.ALL_POS,
4169                            QueryUtil.ALL_POS, null);
4170            }
4171    
4172            /**
4173             * Returns a range of all the d d m structures that the user has permission to view where groupId = &#63; and classNameId = &#63;.
4174             *
4175             * <p>
4176             * 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.
4177             * </p>
4178             *
4179             * @param groupId the group ID
4180             * @param classNameId the class name ID
4181             * @param start the lower bound of the range of d d m structures
4182             * @param end the upper bound of the range of d d m structures (not inclusive)
4183             * @return the range of matching d d m structures that the user has permission to view
4184             * @throws SystemException if a system exception occurred
4185             */
4186            public List<DDMStructure> filterFindByG_C(long groupId, long classNameId,
4187                    int start, int end) throws SystemException {
4188                    return filterFindByG_C(groupId, classNameId, start, end, null);
4189            }
4190    
4191            /**
4192             * Returns an ordered range of all the d d m structures that the user has permissions to view where groupId = &#63; and classNameId = &#63;.
4193             *
4194             * <p>
4195             * 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.
4196             * </p>
4197             *
4198             * @param groupId the group ID
4199             * @param classNameId the class name ID
4200             * @param start the lower bound of the range of d d m structures
4201             * @param end the upper bound of the range of d d m structures (not inclusive)
4202             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
4203             * @return the ordered range of matching d d m structures that the user has permission to view
4204             * @throws SystemException if a system exception occurred
4205             */
4206            public List<DDMStructure> filterFindByG_C(long groupId, long classNameId,
4207                    int start, int end, OrderByComparator orderByComparator)
4208                    throws SystemException {
4209                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
4210                            return findByG_C(groupId, classNameId, start, end, orderByComparator);
4211                    }
4212    
4213                    StringBundler query = null;
4214    
4215                    if (orderByComparator != null) {
4216                            query = new StringBundler(4 +
4217                                            (orderByComparator.getOrderByFields().length * 3));
4218                    }
4219                    else {
4220                            query = new StringBundler(4);
4221                    }
4222    
4223                    if (getDB().isSupportsInlineDistinct()) {
4224                            query.append(_FILTER_SQL_SELECT_DDMSTRUCTURE_WHERE);
4225                    }
4226                    else {
4227                            query.append(_FILTER_SQL_SELECT_DDMSTRUCTURE_NO_INLINE_DISTINCT_WHERE_1);
4228                    }
4229    
4230                    query.append(_FINDER_COLUMN_G_C_GROUPID_2);
4231    
4232                    query.append(_FINDER_COLUMN_G_C_CLASSNAMEID_2);
4233    
4234                    if (!getDB().isSupportsInlineDistinct()) {
4235                            query.append(_FILTER_SQL_SELECT_DDMSTRUCTURE_NO_INLINE_DISTINCT_WHERE_2);
4236                    }
4237    
4238                    if (orderByComparator != null) {
4239                            if (getDB().isSupportsInlineDistinct()) {
4240                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
4241                                            orderByComparator);
4242                            }
4243                            else {
4244                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_TABLE,
4245                                            orderByComparator);
4246                            }
4247                    }
4248                    else {
4249                            if (getDB().isSupportsInlineDistinct()) {
4250                                    query.append(DDMStructureModelImpl.ORDER_BY_JPQL);
4251                            }
4252                            else {
4253                                    query.append(DDMStructureModelImpl.ORDER_BY_SQL);
4254                            }
4255                    }
4256    
4257                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
4258                                    DDMStructure.class.getName(),
4259                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
4260    
4261                    Session session = null;
4262    
4263                    try {
4264                            session = openSession();
4265    
4266                            SQLQuery q = session.createSQLQuery(sql);
4267    
4268                            if (getDB().isSupportsInlineDistinct()) {
4269                                    q.addEntity(_FILTER_ENTITY_ALIAS, DDMStructureImpl.class);
4270                            }
4271                            else {
4272                                    q.addEntity(_FILTER_ENTITY_TABLE, DDMStructureImpl.class);
4273                            }
4274    
4275                            QueryPos qPos = QueryPos.getInstance(q);
4276    
4277                            qPos.add(groupId);
4278    
4279                            qPos.add(classNameId);
4280    
4281                            return (List<DDMStructure>)QueryUtil.list(q, getDialect(), start,
4282                                    end);
4283                    }
4284                    catch (Exception e) {
4285                            throw processException(e);
4286                    }
4287                    finally {
4288                            closeSession(session);
4289                    }
4290            }
4291    
4292            /**
4293             * 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;.
4294             *
4295             * @param structureId the primary key of the current d d m structure
4296             * @param groupId the group ID
4297             * @param classNameId the class name ID
4298             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
4299             * @return the previous, current, and next d d m structure
4300             * @throws com.liferay.portlet.dynamicdatamapping.NoSuchStructureException if a d d m structure with the primary key could not be found
4301             * @throws SystemException if a system exception occurred
4302             */
4303            public DDMStructure[] filterFindByG_C_PrevAndNext(long structureId,
4304                    long groupId, long classNameId, OrderByComparator orderByComparator)
4305                    throws NoSuchStructureException, SystemException {
4306                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
4307                            return findByG_C_PrevAndNext(structureId, groupId, classNameId,
4308                                    orderByComparator);
4309                    }
4310    
4311                    DDMStructure ddmStructure = findByPrimaryKey(structureId);
4312    
4313                    Session session = null;
4314    
4315                    try {
4316                            session = openSession();
4317    
4318                            DDMStructure[] array = new DDMStructureImpl[3];
4319    
4320                            array[0] = filterGetByG_C_PrevAndNext(session, ddmStructure,
4321                                            groupId, classNameId, orderByComparator, true);
4322    
4323                            array[1] = ddmStructure;
4324    
4325                            array[2] = filterGetByG_C_PrevAndNext(session, ddmStructure,
4326                                            groupId, classNameId, orderByComparator, false);
4327    
4328                            return array;
4329                    }
4330                    catch (Exception e) {
4331                            throw processException(e);
4332                    }
4333                    finally {
4334                            closeSession(session);
4335                    }
4336            }
4337    
4338            protected DDMStructure filterGetByG_C_PrevAndNext(Session session,
4339                    DDMStructure ddmStructure, long groupId, long classNameId,
4340                    OrderByComparator orderByComparator, boolean previous) {
4341                    StringBundler query = null;
4342    
4343                    if (orderByComparator != null) {
4344                            query = new StringBundler(6 +
4345                                            (orderByComparator.getOrderByFields().length * 6));
4346                    }
4347                    else {
4348                            query = new StringBundler(3);
4349                    }
4350    
4351                    if (getDB().isSupportsInlineDistinct()) {
4352                            query.append(_FILTER_SQL_SELECT_DDMSTRUCTURE_WHERE);
4353                    }
4354                    else {
4355                            query.append(_FILTER_SQL_SELECT_DDMSTRUCTURE_NO_INLINE_DISTINCT_WHERE_1);
4356                    }
4357    
4358                    query.append(_FINDER_COLUMN_G_C_GROUPID_2);
4359    
4360                    query.append(_FINDER_COLUMN_G_C_CLASSNAMEID_2);
4361    
4362                    if (!getDB().isSupportsInlineDistinct()) {
4363                            query.append(_FILTER_SQL_SELECT_DDMSTRUCTURE_NO_INLINE_DISTINCT_WHERE_2);
4364                    }
4365    
4366                    if (orderByComparator != null) {
4367                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
4368    
4369                            if (orderByConditionFields.length > 0) {
4370                                    query.append(WHERE_AND);
4371                            }
4372    
4373                            for (int i = 0; i < orderByConditionFields.length; i++) {
4374                                    if (getDB().isSupportsInlineDistinct()) {
4375                                            query.append(_ORDER_BY_ENTITY_ALIAS);
4376                                    }
4377                                    else {
4378                                            query.append(_ORDER_BY_ENTITY_TABLE);
4379                                    }
4380    
4381                                    query.append(orderByConditionFields[i]);
4382    
4383                                    if ((i + 1) < orderByConditionFields.length) {
4384                                            if (orderByComparator.isAscending() ^ previous) {
4385                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
4386                                            }
4387                                            else {
4388                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
4389                                            }
4390                                    }
4391                                    else {
4392                                            if (orderByComparator.isAscending() ^ previous) {
4393                                                    query.append(WHERE_GREATER_THAN);
4394                                            }
4395                                            else {
4396                                                    query.append(WHERE_LESSER_THAN);
4397                                            }
4398                                    }
4399                            }
4400    
4401                            query.append(ORDER_BY_CLAUSE);
4402    
4403                            String[] orderByFields = orderByComparator.getOrderByFields();
4404    
4405                            for (int i = 0; i < orderByFields.length; i++) {
4406                                    if (getDB().isSupportsInlineDistinct()) {
4407                                            query.append(_ORDER_BY_ENTITY_ALIAS);
4408                                    }
4409                                    else {
4410                                            query.append(_ORDER_BY_ENTITY_TABLE);
4411                                    }
4412    
4413                                    query.append(orderByFields[i]);
4414    
4415                                    if ((i + 1) < orderByFields.length) {
4416                                            if (orderByComparator.isAscending() ^ previous) {
4417                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
4418                                            }
4419                                            else {
4420                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
4421                                            }
4422                                    }
4423                                    else {
4424                                            if (orderByComparator.isAscending() ^ previous) {
4425                                                    query.append(ORDER_BY_ASC);
4426                                            }
4427                                            else {
4428                                                    query.append(ORDER_BY_DESC);
4429                                            }
4430                                    }
4431                            }
4432                    }
4433                    else {
4434                            if (getDB().isSupportsInlineDistinct()) {
4435                                    query.append(DDMStructureModelImpl.ORDER_BY_JPQL);
4436                            }
4437                            else {
4438                                    query.append(DDMStructureModelImpl.ORDER_BY_SQL);
4439                            }
4440                    }
4441    
4442                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
4443                                    DDMStructure.class.getName(),
4444                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
4445    
4446                    SQLQuery q = session.createSQLQuery(sql);
4447    
4448                    q.setFirstResult(0);
4449                    q.setMaxResults(2);
4450    
4451                    if (getDB().isSupportsInlineDistinct()) {
4452                            q.addEntity(_FILTER_ENTITY_ALIAS, DDMStructureImpl.class);
4453                    }
4454                    else {
4455                            q.addEntity(_FILTER_ENTITY_TABLE, DDMStructureImpl.class);
4456                    }
4457    
4458                    QueryPos qPos = QueryPos.getInstance(q);
4459    
4460                    qPos.add(groupId);
4461    
4462                    qPos.add(classNameId);
4463    
4464                    if (orderByComparator != null) {
4465                            Object[] values = orderByComparator.getOrderByConditionValues(ddmStructure);
4466    
4467                            for (Object value : values) {
4468                                    qPos.add(value);
4469                            }
4470                    }
4471    
4472                    List<DDMStructure> list = q.list();
4473    
4474                    if (list.size() == 2) {
4475                            return list.get(1);
4476                    }
4477                    else {
4478                            return null;
4479                    }
4480            }
4481    
4482            /**
4483             * Removes all the d d m structures where groupId = &#63; and classNameId = &#63; from the database.
4484             *
4485             * @param groupId the group ID
4486             * @param classNameId the class name ID
4487             * @throws SystemException if a system exception occurred
4488             */
4489            public void removeByG_C(long groupId, long classNameId)
4490                    throws SystemException {
4491                    for (DDMStructure ddmStructure : findByG_C(groupId, classNameId,
4492                                    QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
4493                            remove(ddmStructure);
4494                    }
4495            }
4496    
4497            /**
4498             * Returns the number of d d m structures where groupId = &#63; and classNameId = &#63;.
4499             *
4500             * @param groupId the group ID
4501             * @param classNameId the class name ID
4502             * @return the number of matching d d m structures
4503             * @throws SystemException if a system exception occurred
4504             */
4505            public int countByG_C(long groupId, long classNameId)
4506                    throws SystemException {
4507                    FinderPath finderPath = FINDER_PATH_COUNT_BY_G_C;
4508    
4509                    Object[] finderArgs = new Object[] { groupId, classNameId };
4510    
4511                    Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
4512                                    this);
4513    
4514                    if (count == null) {
4515                            StringBundler query = new StringBundler(3);
4516    
4517                            query.append(_SQL_COUNT_DDMSTRUCTURE_WHERE);
4518    
4519                            query.append(_FINDER_COLUMN_G_C_GROUPID_2);
4520    
4521                            query.append(_FINDER_COLUMN_G_C_CLASSNAMEID_2);
4522    
4523                            String sql = query.toString();
4524    
4525                            Session session = null;
4526    
4527                            try {
4528                                    session = openSession();
4529    
4530                                    Query q = session.createQuery(sql);
4531    
4532                                    QueryPos qPos = QueryPos.getInstance(q);
4533    
4534                                    qPos.add(groupId);
4535    
4536                                    qPos.add(classNameId);
4537    
4538                                    count = (Long)q.uniqueResult();
4539    
4540                                    FinderCacheUtil.putResult(finderPath, finderArgs, count);
4541                            }
4542                            catch (Exception e) {
4543                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
4544    
4545                                    throw processException(e);
4546                            }
4547                            finally {
4548                                    closeSession(session);
4549                            }
4550                    }
4551    
4552                    return count.intValue();
4553            }
4554    
4555            /**
4556             * Returns the number of d d m structures that the user has permission to view where groupId = &#63; and classNameId = &#63;.
4557             *
4558             * @param groupId the group ID
4559             * @param classNameId the class name ID
4560             * @return the number of matching d d m structures that the user has permission to view
4561             * @throws SystemException if a system exception occurred
4562             */
4563            public int filterCountByG_C(long groupId, long classNameId)
4564                    throws SystemException {
4565                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
4566                            return countByG_C(groupId, classNameId);
4567                    }
4568    
4569                    StringBundler query = new StringBundler(3);
4570    
4571                    query.append(_FILTER_SQL_COUNT_DDMSTRUCTURE_WHERE);
4572    
4573                    query.append(_FINDER_COLUMN_G_C_GROUPID_2);
4574    
4575                    query.append(_FINDER_COLUMN_G_C_CLASSNAMEID_2);
4576    
4577                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
4578                                    DDMStructure.class.getName(),
4579                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
4580    
4581                    Session session = null;
4582    
4583                    try {
4584                            session = openSession();
4585    
4586                            SQLQuery q = session.createSQLQuery(sql);
4587    
4588                            q.addScalar(COUNT_COLUMN_NAME,
4589                                    com.liferay.portal.kernel.dao.orm.Type.LONG);
4590    
4591                            QueryPos qPos = QueryPos.getInstance(q);
4592    
4593                            qPos.add(groupId);
4594    
4595                            qPos.add(classNameId);
4596    
4597                            Long count = (Long)q.uniqueResult();
4598    
4599                            return count.intValue();
4600                    }
4601                    catch (Exception e) {
4602                            throw processException(e);
4603                    }
4604                    finally {
4605                            closeSession(session);
4606                    }
4607            }
4608    
4609            private static final String _FINDER_COLUMN_G_C_GROUPID_2 = "ddmStructure.groupId = ? AND ";
4610            private static final String _FINDER_COLUMN_G_C_CLASSNAMEID_2 = "ddmStructure.classNameId = ?";
4611            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_C_C = new FinderPath(DDMStructureModelImpl.ENTITY_CACHE_ENABLED,
4612                            DDMStructureModelImpl.FINDER_CACHE_ENABLED, DDMStructureImpl.class,
4613                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByC_C",
4614                            new String[] {
4615                                    Long.class.getName(), Long.class.getName(),
4616                                    
4617                            Integer.class.getName(), Integer.class.getName(),
4618                                    OrderByComparator.class.getName()
4619                            });
4620            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_C = new FinderPath(DDMStructureModelImpl.ENTITY_CACHE_ENABLED,
4621                            DDMStructureModelImpl.FINDER_CACHE_ENABLED, DDMStructureImpl.class,
4622                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByC_C",
4623                            new String[] { Long.class.getName(), Long.class.getName() },
4624                            DDMStructureModelImpl.COMPANYID_COLUMN_BITMASK |
4625                            DDMStructureModelImpl.CLASSNAMEID_COLUMN_BITMASK);
4626            public static final FinderPath FINDER_PATH_COUNT_BY_C_C = new FinderPath(DDMStructureModelImpl.ENTITY_CACHE_ENABLED,
4627                            DDMStructureModelImpl.FINDER_CACHE_ENABLED, Long.class,
4628                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByC_C",
4629                            new String[] { Long.class.getName(), Long.class.getName() });
4630    
4631            /**
4632             * Returns all the d d m structures where companyId = &#63; and classNameId = &#63;.
4633             *
4634             * @param companyId the company ID
4635             * @param classNameId the class name ID
4636             * @return the matching d d m structures
4637             * @throws SystemException if a system exception occurred
4638             */
4639            public List<DDMStructure> findByC_C(long companyId, long classNameId)
4640                    throws SystemException {
4641                    return findByC_C(companyId, classNameId, QueryUtil.ALL_POS,
4642                            QueryUtil.ALL_POS, null);
4643            }
4644    
4645            /**
4646             * Returns a range of all the d d m structures where companyId = &#63; and classNameId = &#63;.
4647             *
4648             * <p>
4649             * 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.
4650             * </p>
4651             *
4652             * @param companyId the company ID
4653             * @param classNameId the class name ID
4654             * @param start the lower bound of the range of d d m structures
4655             * @param end the upper bound of the range of d d m structures (not inclusive)
4656             * @return the range of matching d d m structures
4657             * @throws SystemException if a system exception occurred
4658             */
4659            public List<DDMStructure> findByC_C(long companyId, long classNameId,
4660                    int start, int end) throws SystemException {
4661                    return findByC_C(companyId, classNameId, start, end, null);
4662            }
4663    
4664            /**
4665             * Returns an ordered range of all the d d m structures where companyId = &#63; and classNameId = &#63;.
4666             *
4667             * <p>
4668             * 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.
4669             * </p>
4670             *
4671             * @param companyId the company ID
4672             * @param classNameId the class name ID
4673             * @param start the lower bound of the range of d d m structures
4674             * @param end the upper bound of the range of d d m structures (not inclusive)
4675             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
4676             * @return the ordered range of matching d d m structures
4677             * @throws SystemException if a system exception occurred
4678             */
4679            public List<DDMStructure> findByC_C(long companyId, long classNameId,
4680                    int start, int end, OrderByComparator orderByComparator)
4681                    throws SystemException {
4682                    boolean pagination = true;
4683                    FinderPath finderPath = null;
4684                    Object[] finderArgs = null;
4685    
4686                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
4687                                    (orderByComparator == null)) {
4688                            pagination = false;
4689                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_C;
4690                            finderArgs = new Object[] { companyId, classNameId };
4691                    }
4692                    else {
4693                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_C_C;
4694                            finderArgs = new Object[] {
4695                                            companyId, classNameId,
4696                                            
4697                                            start, end, orderByComparator
4698                                    };
4699                    }
4700    
4701                    List<DDMStructure> list = (List<DDMStructure>)FinderCacheUtil.getResult(finderPath,
4702                                    finderArgs, this);
4703    
4704                    if ((list != null) && !list.isEmpty()) {
4705                            for (DDMStructure ddmStructure : list) {
4706                                    if ((companyId != ddmStructure.getCompanyId()) ||
4707                                                    (classNameId != ddmStructure.getClassNameId())) {
4708                                            list = null;
4709    
4710                                            break;
4711                                    }
4712                            }
4713                    }
4714    
4715                    if (list == null) {
4716                            StringBundler query = null;
4717    
4718                            if (orderByComparator != null) {
4719                                    query = new StringBundler(4 +
4720                                                    (orderByComparator.getOrderByFields().length * 3));
4721                            }
4722                            else {
4723                                    query = new StringBundler(4);
4724                            }
4725    
4726                            query.append(_SQL_SELECT_DDMSTRUCTURE_WHERE);
4727    
4728                            query.append(_FINDER_COLUMN_C_C_COMPANYID_2);
4729    
4730                            query.append(_FINDER_COLUMN_C_C_CLASSNAMEID_2);
4731    
4732                            if (orderByComparator != null) {
4733                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
4734                                            orderByComparator);
4735                            }
4736                            else
4737                             if (pagination) {
4738                                    query.append(DDMStructureModelImpl.ORDER_BY_JPQL);
4739                            }
4740    
4741                            String sql = query.toString();
4742    
4743                            Session session = null;
4744    
4745                            try {
4746                                    session = openSession();
4747    
4748                                    Query q = session.createQuery(sql);
4749    
4750                                    QueryPos qPos = QueryPos.getInstance(q);
4751    
4752                                    qPos.add(companyId);
4753    
4754                                    qPos.add(classNameId);
4755    
4756                                    if (!pagination) {
4757                                            list = (List<DDMStructure>)QueryUtil.list(q, getDialect(),
4758                                                            start, end, false);
4759    
4760                                            Collections.sort(list);
4761    
4762                                            list = new UnmodifiableList<DDMStructure>(list);
4763                                    }
4764                                    else {
4765                                            list = (List<DDMStructure>)QueryUtil.list(q, getDialect(),
4766                                                            start, end);
4767                                    }
4768    
4769                                    cacheResult(list);
4770    
4771                                    FinderCacheUtil.putResult(finderPath, finderArgs, list);
4772                            }
4773                            catch (Exception e) {
4774                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
4775    
4776                                    throw processException(e);
4777                            }
4778                            finally {
4779                                    closeSession(session);
4780                            }
4781                    }
4782    
4783                    return list;
4784            }
4785    
4786            /**
4787             * Returns the first d d m structure in the ordered set where companyId = &#63; and classNameId = &#63;.
4788             *
4789             * @param companyId the company ID
4790             * @param classNameId the class name ID
4791             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
4792             * @return the first matching d d m structure
4793             * @throws com.liferay.portlet.dynamicdatamapping.NoSuchStructureException if a matching d d m structure could not be found
4794             * @throws SystemException if a system exception occurred
4795             */
4796            public DDMStructure findByC_C_First(long companyId, long classNameId,
4797                    OrderByComparator orderByComparator)
4798                    throws NoSuchStructureException, SystemException {
4799                    DDMStructure ddmStructure = fetchByC_C_First(companyId, classNameId,
4800                                    orderByComparator);
4801    
4802                    if (ddmStructure != null) {
4803                            return ddmStructure;
4804                    }
4805    
4806                    StringBundler msg = new StringBundler(6);
4807    
4808                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
4809    
4810                    msg.append("companyId=");
4811                    msg.append(companyId);
4812    
4813                    msg.append(", classNameId=");
4814                    msg.append(classNameId);
4815    
4816                    msg.append(StringPool.CLOSE_CURLY_BRACE);
4817    
4818                    throw new NoSuchStructureException(msg.toString());
4819            }
4820    
4821            /**
4822             * Returns the first d d m structure in the ordered set where companyId = &#63; and classNameId = &#63;.
4823             *
4824             * @param companyId the company ID
4825             * @param classNameId the class name ID
4826             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
4827             * @return the first matching d d m structure, or <code>null</code> if a matching d d m structure could not be found
4828             * @throws SystemException if a system exception occurred
4829             */
4830            public DDMStructure fetchByC_C_First(long companyId, long classNameId,
4831                    OrderByComparator orderByComparator) throws SystemException {
4832                    List<DDMStructure> list = findByC_C(companyId, classNameId, 0, 1,
4833                                    orderByComparator);
4834    
4835                    if (!list.isEmpty()) {
4836                            return list.get(0);
4837                    }
4838    
4839                    return null;
4840            }
4841    
4842            /**
4843             * Returns the last d d m structure in the ordered set where companyId = &#63; and classNameId = &#63;.
4844             *
4845             * @param companyId the company ID
4846             * @param classNameId the class name ID
4847             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
4848             * @return the last matching d d m structure
4849             * @throws com.liferay.portlet.dynamicdatamapping.NoSuchStructureException if a matching d d m structure could not be found
4850             * @throws SystemException if a system exception occurred
4851             */
4852            public DDMStructure findByC_C_Last(long companyId, long classNameId,
4853                    OrderByComparator orderByComparator)
4854                    throws NoSuchStructureException, SystemException {
4855                    DDMStructure ddmStructure = fetchByC_C_Last(companyId, classNameId,
4856                                    orderByComparator);
4857    
4858                    if (ddmStructure != null) {
4859                            return ddmStructure;
4860                    }
4861    
4862                    StringBundler msg = new StringBundler(6);
4863    
4864                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
4865    
4866                    msg.append("companyId=");
4867                    msg.append(companyId);
4868    
4869                    msg.append(", classNameId=");
4870                    msg.append(classNameId);
4871    
4872                    msg.append(StringPool.CLOSE_CURLY_BRACE);
4873    
4874                    throw new NoSuchStructureException(msg.toString());
4875            }
4876    
4877            /**
4878             * Returns the last d d m structure in the ordered set where companyId = &#63; and classNameId = &#63;.
4879             *
4880             * @param companyId the company ID
4881             * @param classNameId the class name ID
4882             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
4883             * @return the last matching d d m structure, or <code>null</code> if a matching d d m structure could not be found
4884             * @throws SystemException if a system exception occurred
4885             */
4886            public DDMStructure fetchByC_C_Last(long companyId, long classNameId,
4887                    OrderByComparator orderByComparator) throws SystemException {
4888                    int count = countByC_C(companyId, classNameId);
4889    
4890                    List<DDMStructure> list = findByC_C(companyId, classNameId, count - 1,
4891                                    count, orderByComparator);
4892    
4893                    if (!list.isEmpty()) {
4894                            return list.get(0);
4895                    }
4896    
4897                    return null;
4898            }
4899    
4900            /**
4901             * 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;.
4902             *
4903             * @param structureId the primary key of the current d d m structure
4904             * @param companyId the company ID
4905             * @param classNameId the class name ID
4906             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
4907             * @return the previous, current, and next d d m structure
4908             * @throws com.liferay.portlet.dynamicdatamapping.NoSuchStructureException if a d d m structure with the primary key could not be found
4909             * @throws SystemException if a system exception occurred
4910             */
4911            public DDMStructure[] findByC_C_PrevAndNext(long structureId,
4912                    long companyId, long classNameId, OrderByComparator orderByComparator)
4913                    throws NoSuchStructureException, SystemException {
4914                    DDMStructure ddmStructure = findByPrimaryKey(structureId);
4915    
4916                    Session session = null;
4917    
4918                    try {
4919                            session = openSession();
4920    
4921                            DDMStructure[] array = new DDMStructureImpl[3];
4922    
4923                            array[0] = getByC_C_PrevAndNext(session, ddmStructure, companyId,
4924                                            classNameId, orderByComparator, true);
4925    
4926                            array[1] = ddmStructure;
4927    
4928                            array[2] = getByC_C_PrevAndNext(session, ddmStructure, companyId,
4929                                            classNameId, orderByComparator, false);
4930    
4931                            return array;
4932                    }
4933                    catch (Exception e) {
4934                            throw processException(e);
4935                    }
4936                    finally {
4937                            closeSession(session);
4938                    }
4939            }
4940    
4941            protected DDMStructure getByC_C_PrevAndNext(Session session,
4942                    DDMStructure ddmStructure, long companyId, long classNameId,
4943                    OrderByComparator orderByComparator, boolean previous) {
4944                    StringBundler query = null;
4945    
4946                    if (orderByComparator != null) {
4947                            query = new StringBundler(6 +
4948                                            (orderByComparator.getOrderByFields().length * 6));
4949                    }
4950                    else {
4951                            query = new StringBundler(3);
4952                    }
4953    
4954                    query.append(_SQL_SELECT_DDMSTRUCTURE_WHERE);
4955    
4956                    query.append(_FINDER_COLUMN_C_C_COMPANYID_2);
4957    
4958                    query.append(_FINDER_COLUMN_C_C_CLASSNAMEID_2);
4959    
4960                    if (orderByComparator != null) {
4961                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
4962    
4963                            if (orderByConditionFields.length > 0) {
4964                                    query.append(WHERE_AND);
4965                            }
4966    
4967                            for (int i = 0; i < orderByConditionFields.length; i++) {
4968                                    query.append(_ORDER_BY_ENTITY_ALIAS);
4969                                    query.append(orderByConditionFields[i]);
4970    
4971                                    if ((i + 1) < orderByConditionFields.length) {
4972                                            if (orderByComparator.isAscending() ^ previous) {
4973                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
4974                                            }
4975                                            else {
4976                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
4977                                            }
4978                                    }
4979                                    else {
4980                                            if (orderByComparator.isAscending() ^ previous) {
4981                                                    query.append(WHERE_GREATER_THAN);
4982                                            }
4983                                            else {
4984                                                    query.append(WHERE_LESSER_THAN);
4985                                            }
4986                                    }
4987                            }
4988    
4989                            query.append(ORDER_BY_CLAUSE);
4990    
4991                            String[] orderByFields = orderByComparator.getOrderByFields();
4992    
4993                            for (int i = 0; i < orderByFields.length; i++) {
4994                                    query.append(_ORDER_BY_ENTITY_ALIAS);
4995                                    query.append(orderByFields[i]);
4996    
4997                                    if ((i + 1) < orderByFields.length) {
4998                                            if (orderByComparator.isAscending() ^ previous) {
4999                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
5000                                            }
5001                                            else {
5002                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
5003                                            }
5004                                    }
5005                                    else {
5006                                            if (orderByComparator.isAscending() ^ previous) {
5007                                                    query.append(ORDER_BY_ASC);
5008                                            }
5009                                            else {
5010                                                    query.append(ORDER_BY_DESC);
5011                                            }
5012                                    }
5013                            }
5014                    }
5015                    else {
5016                            query.append(DDMStructureModelImpl.ORDER_BY_JPQL);
5017                    }
5018    
5019                    String sql = query.toString();
5020    
5021                    Query q = session.createQuery(sql);
5022    
5023                    q.setFirstResult(0);
5024                    q.setMaxResults(2);
5025    
5026                    QueryPos qPos = QueryPos.getInstance(q);
5027    
5028                    qPos.add(companyId);
5029    
5030                    qPos.add(classNameId);
5031    
5032                    if (orderByComparator != null) {
5033                            Object[] values = orderByComparator.getOrderByConditionValues(ddmStructure);
5034    
5035                            for (Object value : values) {
5036                                    qPos.add(value);
5037                            }
5038                    }
5039    
5040                    List<DDMStructure> list = q.list();
5041    
5042                    if (list.size() == 2) {
5043                            return list.get(1);
5044                    }
5045                    else {
5046                            return null;
5047                    }
5048            }
5049    
5050            /**
5051             * Removes all the d d m structures where companyId = &#63; and classNameId = &#63; from the database.
5052             *
5053             * @param companyId the company ID
5054             * @param classNameId the class name ID
5055             * @throws SystemException if a system exception occurred
5056             */
5057            public void removeByC_C(long companyId, long classNameId)
5058                    throws SystemException {
5059                    for (DDMStructure ddmStructure : findByC_C(companyId, classNameId,
5060                                    QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
5061                            remove(ddmStructure);
5062                    }
5063            }
5064    
5065            /**
5066             * Returns the number of d d m structures where companyId = &#63; and classNameId = &#63;.
5067             *
5068             * @param companyId the company ID
5069             * @param classNameId the class name ID
5070             * @return the number of matching d d m structures
5071             * @throws SystemException if a system exception occurred
5072             */
5073            public int countByC_C(long companyId, long classNameId)
5074                    throws SystemException {
5075                    FinderPath finderPath = FINDER_PATH_COUNT_BY_C_C;
5076    
5077                    Object[] finderArgs = new Object[] { companyId, classNameId };
5078    
5079                    Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
5080                                    this);
5081    
5082                    if (count == null) {
5083                            StringBundler query = new StringBundler(3);
5084    
5085                            query.append(_SQL_COUNT_DDMSTRUCTURE_WHERE);
5086    
5087                            query.append(_FINDER_COLUMN_C_C_COMPANYID_2);
5088    
5089                            query.append(_FINDER_COLUMN_C_C_CLASSNAMEID_2);
5090    
5091                            String sql = query.toString();
5092    
5093                            Session session = null;
5094    
5095                            try {
5096                                    session = openSession();
5097    
5098                                    Query q = session.createQuery(sql);
5099    
5100                                    QueryPos qPos = QueryPos.getInstance(q);
5101    
5102                                    qPos.add(companyId);
5103    
5104                                    qPos.add(classNameId);
5105    
5106                                    count = (Long)q.uniqueResult();
5107    
5108                                    FinderCacheUtil.putResult(finderPath, finderArgs, count);
5109                            }
5110                            catch (Exception e) {
5111                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
5112    
5113                                    throw processException(e);
5114                            }
5115                            finally {
5116                                    closeSession(session);
5117                            }
5118                    }
5119    
5120                    return count.intValue();
5121            }
5122    
5123            private static final String _FINDER_COLUMN_C_C_COMPANYID_2 = "ddmStructure.companyId = ? AND ";
5124            private static final String _FINDER_COLUMN_C_C_CLASSNAMEID_2 = "ddmStructure.classNameId = ?";
5125            public static final FinderPath FINDER_PATH_FETCH_BY_G_C_S = new FinderPath(DDMStructureModelImpl.ENTITY_CACHE_ENABLED,
5126                            DDMStructureModelImpl.FINDER_CACHE_ENABLED, DDMStructureImpl.class,
5127                            FINDER_CLASS_NAME_ENTITY, "fetchByG_C_S",
5128                            new String[] {
5129                                    Long.class.getName(), Long.class.getName(),
5130                                    String.class.getName()
5131                            },
5132                            DDMStructureModelImpl.GROUPID_COLUMN_BITMASK |
5133                            DDMStructureModelImpl.CLASSNAMEID_COLUMN_BITMASK |
5134                            DDMStructureModelImpl.STRUCTUREKEY_COLUMN_BITMASK);
5135            public static final FinderPath FINDER_PATH_COUNT_BY_G_C_S = new FinderPath(DDMStructureModelImpl.ENTITY_CACHE_ENABLED,
5136                            DDMStructureModelImpl.FINDER_CACHE_ENABLED, Long.class,
5137                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByG_C_S",
5138                            new String[] {
5139                                    Long.class.getName(), Long.class.getName(),
5140                                    String.class.getName()
5141                            });
5142    
5143            /**
5144             * 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.
5145             *
5146             * @param groupId the group ID
5147             * @param classNameId the class name ID
5148             * @param structureKey the structure key
5149             * @return the matching d d m structure
5150             * @throws com.liferay.portlet.dynamicdatamapping.NoSuchStructureException if a matching d d m structure could not be found
5151             * @throws SystemException if a system exception occurred
5152             */
5153            public DDMStructure findByG_C_S(long groupId, long classNameId,
5154                    String structureKey) throws NoSuchStructureException, SystemException {
5155                    DDMStructure ddmStructure = fetchByG_C_S(groupId, classNameId,
5156                                    structureKey);
5157    
5158                    if (ddmStructure == null) {
5159                            StringBundler msg = new StringBundler(8);
5160    
5161                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
5162    
5163                            msg.append("groupId=");
5164                            msg.append(groupId);
5165    
5166                            msg.append(", classNameId=");
5167                            msg.append(classNameId);
5168    
5169                            msg.append(", structureKey=");
5170                            msg.append(structureKey);
5171    
5172                            msg.append(StringPool.CLOSE_CURLY_BRACE);
5173    
5174                            if (_log.isWarnEnabled()) {
5175                                    _log.warn(msg.toString());
5176                            }
5177    
5178                            throw new NoSuchStructureException(msg.toString());
5179                    }
5180    
5181                    return ddmStructure;
5182            }
5183    
5184            /**
5185             * 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.
5186             *
5187             * @param groupId the group ID
5188             * @param classNameId the class name ID
5189             * @param structureKey the structure key
5190             * @return the matching d d m structure, or <code>null</code> if a matching d d m structure could not be found
5191             * @throws SystemException if a system exception occurred
5192             */
5193            public DDMStructure fetchByG_C_S(long groupId, long classNameId,
5194                    String structureKey) throws SystemException {
5195                    return fetchByG_C_S(groupId, classNameId, structureKey, true);
5196            }
5197    
5198            /**
5199             * 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.
5200             *
5201             * @param groupId the group ID
5202             * @param classNameId the class name ID
5203             * @param structureKey the structure key
5204             * @param retrieveFromCache whether to use the finder cache
5205             * @return the matching d d m structure, or <code>null</code> if a matching d d m structure could not be found
5206             * @throws SystemException if a system exception occurred
5207             */
5208            public DDMStructure fetchByG_C_S(long groupId, long classNameId,
5209                    String structureKey, boolean retrieveFromCache)
5210                    throws SystemException {
5211                    Object[] finderArgs = new Object[] { groupId, classNameId, structureKey };
5212    
5213                    Object result = null;
5214    
5215                    if (retrieveFromCache) {
5216                            result = FinderCacheUtil.getResult(FINDER_PATH_FETCH_BY_G_C_S,
5217                                            finderArgs, this);
5218                    }
5219    
5220                    if (result instanceof DDMStructure) {
5221                            DDMStructure ddmStructure = (DDMStructure)result;
5222    
5223                            if ((groupId != ddmStructure.getGroupId()) ||
5224                                            (classNameId != ddmStructure.getClassNameId()) ||
5225                                            !Validator.equals(structureKey,
5226                                                    ddmStructure.getStructureKey())) {
5227                                    result = null;
5228                            }
5229                    }
5230    
5231                    if (result == null) {
5232                            StringBundler query = new StringBundler(5);
5233    
5234                            query.append(_SQL_SELECT_DDMSTRUCTURE_WHERE);
5235    
5236                            query.append(_FINDER_COLUMN_G_C_S_GROUPID_2);
5237    
5238                            query.append(_FINDER_COLUMN_G_C_S_CLASSNAMEID_2);
5239    
5240                            boolean bindStructureKey = false;
5241    
5242                            if (structureKey == null) {
5243                                    query.append(_FINDER_COLUMN_G_C_S_STRUCTUREKEY_1);
5244                            }
5245                            else if (structureKey.equals(StringPool.BLANK)) {
5246                                    query.append(_FINDER_COLUMN_G_C_S_STRUCTUREKEY_3);
5247                            }
5248                            else {
5249                                    bindStructureKey = true;
5250    
5251                                    query.append(_FINDER_COLUMN_G_C_S_STRUCTUREKEY_2);
5252                            }
5253    
5254                            String sql = query.toString();
5255    
5256                            Session session = null;
5257    
5258                            try {
5259                                    session = openSession();
5260    
5261                                    Query q = session.createQuery(sql);
5262    
5263                                    QueryPos qPos = QueryPos.getInstance(q);
5264    
5265                                    qPos.add(groupId);
5266    
5267                                    qPos.add(classNameId);
5268    
5269                                    if (bindStructureKey) {
5270                                            qPos.add(structureKey);
5271                                    }
5272    
5273                                    List<DDMStructure> list = q.list();
5274    
5275                                    if (list.isEmpty()) {
5276                                            FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_G_C_S,
5277                                                    finderArgs, list);
5278                                    }
5279                                    else {
5280                                            DDMStructure ddmStructure = list.get(0);
5281    
5282                                            result = ddmStructure;
5283    
5284                                            cacheResult(ddmStructure);
5285    
5286                                            if ((ddmStructure.getGroupId() != groupId) ||
5287                                                            (ddmStructure.getClassNameId() != classNameId) ||
5288                                                            (ddmStructure.getStructureKey() == null) ||
5289                                                            !ddmStructure.getStructureKey().equals(structureKey)) {
5290                                                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_G_C_S,
5291                                                            finderArgs, ddmStructure);
5292                                            }
5293                                    }
5294                            }
5295                            catch (Exception e) {
5296                                    FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_G_C_S,
5297                                            finderArgs);
5298    
5299                                    throw processException(e);
5300                            }
5301                            finally {
5302                                    closeSession(session);
5303                            }
5304                    }
5305    
5306                    if (result instanceof List<?>) {
5307                            return null;
5308                    }
5309                    else {
5310                            return (DDMStructure)result;
5311                    }
5312            }
5313    
5314            /**
5315             * Removes the d d m structure where groupId = &#63; and classNameId = &#63; and structureKey = &#63; from the database.
5316             *
5317             * @param groupId the group ID
5318             * @param classNameId the class name ID
5319             * @param structureKey the structure key
5320             * @return the d d m structure that was removed
5321             * @throws SystemException if a system exception occurred
5322             */
5323            public DDMStructure removeByG_C_S(long groupId, long classNameId,
5324                    String structureKey) throws NoSuchStructureException, SystemException {
5325                    DDMStructure ddmStructure = findByG_C_S(groupId, classNameId,
5326                                    structureKey);
5327    
5328                    return remove(ddmStructure);
5329            }
5330    
5331            /**
5332             * Returns the number of d d m structures where groupId = &#63; and classNameId = &#63; and structureKey = &#63;.
5333             *
5334             * @param groupId the group ID
5335             * @param classNameId the class name ID
5336             * @param structureKey the structure key
5337             * @return the number of matching d d m structures
5338             * @throws SystemException if a system exception occurred
5339             */
5340            public int countByG_C_S(long groupId, long classNameId, String structureKey)
5341                    throws SystemException {
5342                    FinderPath finderPath = FINDER_PATH_COUNT_BY_G_C_S;
5343    
5344                    Object[] finderArgs = new Object[] { groupId, classNameId, structureKey };
5345    
5346                    Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
5347                                    this);
5348    
5349                    if (count == null) {
5350                            StringBundler query = new StringBundler(4);
5351    
5352                            query.append(_SQL_COUNT_DDMSTRUCTURE_WHERE);
5353    
5354                            query.append(_FINDER_COLUMN_G_C_S_GROUPID_2);
5355    
5356                            query.append(_FINDER_COLUMN_G_C_S_CLASSNAMEID_2);
5357    
5358                            boolean bindStructureKey = false;
5359    
5360                            if (structureKey == null) {
5361                                    query.append(_FINDER_COLUMN_G_C_S_STRUCTUREKEY_1);
5362                            }
5363                            else if (structureKey.equals(StringPool.BLANK)) {
5364                                    query.append(_FINDER_COLUMN_G_C_S_STRUCTUREKEY_3);
5365                            }
5366                            else {
5367                                    bindStructureKey = true;
5368    
5369                                    query.append(_FINDER_COLUMN_G_C_S_STRUCTUREKEY_2);
5370                            }
5371    
5372                            String sql = query.toString();
5373    
5374                            Session session = null;
5375    
5376                            try {
5377                                    session = openSession();
5378    
5379                                    Query q = session.createQuery(sql);
5380    
5381                                    QueryPos qPos = QueryPos.getInstance(q);
5382    
5383                                    qPos.add(groupId);
5384    
5385                                    qPos.add(classNameId);
5386    
5387                                    if (bindStructureKey) {
5388                                            qPos.add(structureKey);
5389                                    }
5390    
5391                                    count = (Long)q.uniqueResult();
5392    
5393                                    FinderCacheUtil.putResult(finderPath, finderArgs, count);
5394                            }
5395                            catch (Exception e) {
5396                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
5397    
5398                                    throw processException(e);
5399                            }
5400                            finally {
5401                                    closeSession(session);
5402                            }
5403                    }
5404    
5405                    return count.intValue();
5406            }
5407    
5408            private static final String _FINDER_COLUMN_G_C_S_GROUPID_2 = "ddmStructure.groupId = ? AND ";
5409            private static final String _FINDER_COLUMN_G_C_S_CLASSNAMEID_2 = "ddmStructure.classNameId = ? AND ";
5410            private static final String _FINDER_COLUMN_G_C_S_STRUCTUREKEY_1 = "ddmStructure.structureKey IS NULL";
5411            private static final String _FINDER_COLUMN_G_C_S_STRUCTUREKEY_2 = "ddmStructure.structureKey = ?";
5412            private static final String _FINDER_COLUMN_G_C_S_STRUCTUREKEY_3 = "(ddmStructure.structureKey IS NULL OR ddmStructure.structureKey = '')";
5413            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_G_N_D = new FinderPath(DDMStructureModelImpl.ENTITY_CACHE_ENABLED,
5414                            DDMStructureModelImpl.FINDER_CACHE_ENABLED, DDMStructureImpl.class,
5415                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByG_N_D",
5416                            new String[] {
5417                                    Long.class.getName(), String.class.getName(),
5418                                    String.class.getName(),
5419                                    
5420                            Integer.class.getName(), Integer.class.getName(),
5421                                    OrderByComparator.class.getName()
5422                            });
5423            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_N_D = new FinderPath(DDMStructureModelImpl.ENTITY_CACHE_ENABLED,
5424                            DDMStructureModelImpl.FINDER_CACHE_ENABLED, DDMStructureImpl.class,
5425                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByG_N_D",
5426                            new String[] {
5427                                    Long.class.getName(), String.class.getName(),
5428                                    String.class.getName()
5429                            },
5430                            DDMStructureModelImpl.GROUPID_COLUMN_BITMASK |
5431                            DDMStructureModelImpl.NAME_COLUMN_BITMASK |
5432                            DDMStructureModelImpl.DESCRIPTION_COLUMN_BITMASK);
5433            public static final FinderPath FINDER_PATH_COUNT_BY_G_N_D = new FinderPath(DDMStructureModelImpl.ENTITY_CACHE_ENABLED,
5434                            DDMStructureModelImpl.FINDER_CACHE_ENABLED, Long.class,
5435                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByG_N_D",
5436                            new String[] {
5437                                    Long.class.getName(), String.class.getName(),
5438                                    String.class.getName()
5439                            });
5440    
5441            /**
5442             * Returns all the d d m structures where groupId = &#63; and name = &#63; and description = &#63;.
5443             *
5444             * @param groupId the group ID
5445             * @param name the name
5446             * @param description the description
5447             * @return the matching d d m structures
5448             * @throws SystemException if a system exception occurred
5449             */
5450            public List<DDMStructure> findByG_N_D(long groupId, String name,
5451                    String description) throws SystemException {
5452                    return findByG_N_D(groupId, name, description, QueryUtil.ALL_POS,
5453                            QueryUtil.ALL_POS, null);
5454            }
5455    
5456            /**
5457             * Returns a range of all the d d m structures where groupId = &#63; and name = &#63; and description = &#63;.
5458             *
5459             * <p>
5460             * 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.
5461             * </p>
5462             *
5463             * @param groupId the group ID
5464             * @param name the name
5465             * @param description the description
5466             * @param start the lower bound of the range of d d m structures
5467             * @param end the upper bound of the range of d d m structures (not inclusive)
5468             * @return the range of matching d d m structures
5469             * @throws SystemException if a system exception occurred
5470             */
5471            public List<DDMStructure> findByG_N_D(long groupId, String name,
5472                    String description, int start, int end) throws SystemException {
5473                    return findByG_N_D(groupId, name, description, start, end, null);
5474            }
5475    
5476            /**
5477             * Returns an ordered range of all the d d m structures where groupId = &#63; and name = &#63; and description = &#63;.
5478             *
5479             * <p>
5480             * 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.
5481             * </p>
5482             *
5483             * @param groupId the group ID
5484             * @param name the name
5485             * @param description the description
5486             * @param start the lower bound of the range of d d m structures
5487             * @param end the upper bound of the range of d d m structures (not inclusive)
5488             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
5489             * @return the ordered range of matching d d m structures
5490             * @throws SystemException if a system exception occurred
5491             */
5492            public List<DDMStructure> findByG_N_D(long groupId, String name,
5493                    String description, int start, int end,
5494                    OrderByComparator orderByComparator) throws SystemException {
5495                    boolean pagination = true;
5496                    FinderPath finderPath = null;
5497                    Object[] finderArgs = null;
5498    
5499                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
5500                                    (orderByComparator == null)) {
5501                            pagination = false;
5502                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_N_D;
5503                            finderArgs = new Object[] { groupId, name, description };
5504                    }
5505                    else {
5506                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_G_N_D;
5507                            finderArgs = new Object[] {
5508                                            groupId, name, description,
5509                                            
5510                                            start, end, orderByComparator
5511                                    };
5512                    }
5513    
5514                    List<DDMStructure> list = (List<DDMStructure>)FinderCacheUtil.getResult(finderPath,
5515                                    finderArgs, this);
5516    
5517                    if ((list != null) && !list.isEmpty()) {
5518                            for (DDMStructure ddmStructure : list) {
5519                                    if ((groupId != ddmStructure.getGroupId()) ||
5520                                                    !Validator.equals(name, ddmStructure.getName()) ||
5521                                                    !Validator.equals(description,
5522                                                            ddmStructure.getDescription())) {
5523                                            list = null;
5524    
5525                                            break;
5526                                    }
5527                            }
5528                    }
5529    
5530                    if (list == null) {
5531                            StringBundler query = null;
5532    
5533                            if (orderByComparator != null) {
5534                                    query = new StringBundler(5 +
5535                                                    (orderByComparator.getOrderByFields().length * 3));
5536                            }
5537                            else {
5538                                    query = new StringBundler(5);
5539                            }
5540    
5541                            query.append(_SQL_SELECT_DDMSTRUCTURE_WHERE);
5542    
5543                            query.append(_FINDER_COLUMN_G_N_D_GROUPID_2);
5544    
5545                            boolean bindName = false;
5546    
5547                            if (name == null) {
5548                                    query.append(_FINDER_COLUMN_G_N_D_NAME_1);
5549                            }
5550                            else if (name.equals(StringPool.BLANK)) {
5551                                    query.append(_FINDER_COLUMN_G_N_D_NAME_3);
5552                            }
5553                            else {
5554                                    bindName = true;
5555    
5556                                    query.append(_FINDER_COLUMN_G_N_D_NAME_2);
5557                            }
5558    
5559                            boolean bindDescription = false;
5560    
5561                            if (description == null) {
5562                                    query.append(_FINDER_COLUMN_G_N_D_DESCRIPTION_1);
5563                            }
5564                            else if (description.equals(StringPool.BLANK)) {
5565                                    query.append(_FINDER_COLUMN_G_N_D_DESCRIPTION_3);
5566                            }
5567                            else {
5568                                    bindDescription = true;
5569    
5570                                    query.append(_FINDER_COLUMN_G_N_D_DESCRIPTION_2);
5571                            }
5572    
5573                            if (orderByComparator != null) {
5574                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
5575                                            orderByComparator);
5576                            }
5577                            else
5578                             if (pagination) {
5579                                    query.append(DDMStructureModelImpl.ORDER_BY_JPQL);
5580                            }
5581    
5582                            String sql = query.toString();
5583    
5584                            Session session = null;
5585    
5586                            try {
5587                                    session = openSession();
5588    
5589                                    Query q = session.createQuery(sql);
5590    
5591                                    QueryPos qPos = QueryPos.getInstance(q);
5592    
5593                                    qPos.add(groupId);
5594    
5595                                    if (bindName) {
5596                                            qPos.add(name);
5597                                    }
5598    
5599                                    if (bindDescription) {
5600                                            qPos.add(description);
5601                                    }
5602    
5603                                    if (!pagination) {
5604                                            list = (List<DDMStructure>)QueryUtil.list(q, getDialect(),
5605                                                            start, end, false);
5606    
5607                                            Collections.sort(list);
5608    
5609                                            list = new UnmodifiableList<DDMStructure>(list);
5610                                    }
5611                                    else {
5612                                            list = (List<DDMStructure>)QueryUtil.list(q, getDialect(),
5613                                                            start, end);
5614                                    }
5615    
5616                                    cacheResult(list);
5617    
5618                                    FinderCacheUtil.putResult(finderPath, finderArgs, list);
5619                            }
5620                            catch (Exception e) {
5621                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
5622    
5623                                    throw processException(e);
5624                            }
5625                            finally {
5626                                    closeSession(session);
5627                            }
5628                    }
5629    
5630                    return list;
5631            }
5632    
5633            /**
5634             * Returns the first d d m structure in the ordered set where groupId = &#63; and name = &#63; and description = &#63;.
5635             *
5636             * @param groupId the group ID
5637             * @param name the name
5638             * @param description the description
5639             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
5640             * @return the first matching d d m structure
5641             * @throws com.liferay.portlet.dynamicdatamapping.NoSuchStructureException if a matching d d m structure could not be found
5642             * @throws SystemException if a system exception occurred
5643             */
5644            public DDMStructure findByG_N_D_First(long groupId, String name,
5645                    String description, OrderByComparator orderByComparator)
5646                    throws NoSuchStructureException, SystemException {
5647                    DDMStructure ddmStructure = fetchByG_N_D_First(groupId, name,
5648                                    description, orderByComparator);
5649    
5650                    if (ddmStructure != null) {
5651                            return ddmStructure;
5652                    }
5653    
5654                    StringBundler msg = new StringBundler(8);
5655    
5656                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
5657    
5658                    msg.append("groupId=");
5659                    msg.append(groupId);
5660    
5661                    msg.append(", name=");
5662                    msg.append(name);
5663    
5664                    msg.append(", description=");
5665                    msg.append(description);
5666    
5667                    msg.append(StringPool.CLOSE_CURLY_BRACE);
5668    
5669                    throw new NoSuchStructureException(msg.toString());
5670            }
5671    
5672            /**
5673             * Returns the first d d m structure in the ordered set where groupId = &#63; and name = &#63; and description = &#63;.
5674             *
5675             * @param groupId the group ID
5676             * @param name the name
5677             * @param description the description
5678             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
5679             * @return the first matching d d m structure, or <code>null</code> if a matching d d m structure could not be found
5680             * @throws SystemException if a system exception occurred
5681             */
5682            public DDMStructure fetchByG_N_D_First(long groupId, String name,
5683                    String description, OrderByComparator orderByComparator)
5684                    throws SystemException {
5685                    List<DDMStructure> list = findByG_N_D(groupId, name, description, 0, 1,
5686                                    orderByComparator);
5687    
5688                    if (!list.isEmpty()) {
5689                            return list.get(0);
5690                    }
5691    
5692                    return null;
5693            }
5694    
5695            /**
5696             * Returns the last d d m structure in the ordered set where groupId = &#63; and name = &#63; and description = &#63;.
5697             *
5698             * @param groupId the group ID
5699             * @param name the name
5700             * @param description the description
5701             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
5702             * @return the last matching d d m structure
5703             * @throws com.liferay.portlet.dynamicdatamapping.NoSuchStructureException if a matching d d m structure could not be found
5704             * @throws SystemException if a system exception occurred
5705             */
5706            public DDMStructure findByG_N_D_Last(long groupId, String name,
5707                    String description, OrderByComparator orderByComparator)
5708                    throws NoSuchStructureException, SystemException {
5709                    DDMStructure ddmStructure = fetchByG_N_D_Last(groupId, name,
5710                                    description, orderByComparator);
5711    
5712                    if (ddmStructure != null) {
5713                            return ddmStructure;
5714                    }
5715    
5716                    StringBundler msg = new StringBundler(8);
5717    
5718                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
5719    
5720                    msg.append("groupId=");
5721                    msg.append(groupId);
5722    
5723                    msg.append(", name=");
5724                    msg.append(name);
5725    
5726                    msg.append(", description=");
5727                    msg.append(description);
5728    
5729                    msg.append(StringPool.CLOSE_CURLY_BRACE);
5730    
5731                    throw new NoSuchStructureException(msg.toString());
5732            }
5733    
5734            /**
5735             * Returns the last d d m structure in the ordered set where groupId = &#63; and name = &#63; and description = &#63;.
5736             *
5737             * @param groupId the group ID
5738             * @param name the name
5739             * @param description the description
5740             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
5741             * @return the last matching d d m structure, or <code>null</code> if a matching d d m structure could not be found
5742             * @throws SystemException if a system exception occurred
5743             */
5744            public DDMStructure fetchByG_N_D_Last(long groupId, String name,
5745                    String description, OrderByComparator orderByComparator)
5746                    throws SystemException {
5747                    int count = countByG_N_D(groupId, name, description);
5748    
5749                    List<DDMStructure> list = findByG_N_D(groupId, name, description,
5750                                    count - 1, count, orderByComparator);
5751    
5752                    if (!list.isEmpty()) {
5753                            return list.get(0);
5754                    }
5755    
5756                    return null;
5757            }
5758    
5759            /**
5760             * 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;.
5761             *
5762             * @param structureId the primary key of the current d d m structure
5763             * @param groupId the group ID
5764             * @param name the name
5765             * @param description the description
5766             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
5767             * @return the previous, current, and next d d m structure
5768             * @throws com.liferay.portlet.dynamicdatamapping.NoSuchStructureException if a d d m structure with the primary key could not be found
5769             * @throws SystemException if a system exception occurred
5770             */
5771            public DDMStructure[] findByG_N_D_PrevAndNext(long structureId,
5772                    long groupId, String name, String description,
5773                    OrderByComparator orderByComparator)
5774                    throws NoSuchStructureException, SystemException {
5775                    DDMStructure ddmStructure = findByPrimaryKey(structureId);
5776    
5777                    Session session = null;
5778    
5779                    try {
5780                            session = openSession();
5781    
5782                            DDMStructure[] array = new DDMStructureImpl[3];
5783    
5784                            array[0] = getByG_N_D_PrevAndNext(session, ddmStructure, groupId,
5785                                            name, description, orderByComparator, true);
5786    
5787                            array[1] = ddmStructure;
5788    
5789                            array[2] = getByG_N_D_PrevAndNext(session, ddmStructure, groupId,
5790                                            name, description, orderByComparator, false);
5791    
5792                            return array;
5793                    }
5794                    catch (Exception e) {
5795                            throw processException(e);
5796                    }
5797                    finally {
5798                            closeSession(session);
5799                    }
5800            }
5801    
5802            protected DDMStructure getByG_N_D_PrevAndNext(Session session,
5803                    DDMStructure ddmStructure, long groupId, String name,
5804                    String description, OrderByComparator orderByComparator,
5805                    boolean previous) {
5806                    StringBundler query = null;
5807    
5808                    if (orderByComparator != null) {
5809                            query = new StringBundler(6 +
5810                                            (orderByComparator.getOrderByFields().length * 6));
5811                    }
5812                    else {
5813                            query = new StringBundler(3);
5814                    }
5815    
5816                    query.append(_SQL_SELECT_DDMSTRUCTURE_WHERE);
5817    
5818                    query.append(_FINDER_COLUMN_G_N_D_GROUPID_2);
5819    
5820                    boolean bindName = false;
5821    
5822                    if (name == null) {
5823                            query.append(_FINDER_COLUMN_G_N_D_NAME_1);
5824                    }
5825                    else if (name.equals(StringPool.BLANK)) {
5826                            query.append(_FINDER_COLUMN_G_N_D_NAME_3);
5827                    }
5828                    else {
5829                            bindName = true;
5830    
5831                            query.append(_FINDER_COLUMN_G_N_D_NAME_2);
5832                    }
5833    
5834                    boolean bindDescription = false;
5835    
5836                    if (description == null) {
5837                            query.append(_FINDER_COLUMN_G_N_D_DESCRIPTION_1);
5838                    }
5839                    else if (description.equals(StringPool.BLANK)) {
5840                            query.append(_FINDER_COLUMN_G_N_D_DESCRIPTION_3);
5841                    }
5842                    else {
5843                            bindDescription = true;
5844    
5845                            query.append(_FINDER_COLUMN_G_N_D_DESCRIPTION_2);
5846                    }
5847    
5848                    if (orderByComparator != null) {
5849                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
5850    
5851                            if (orderByConditionFields.length > 0) {
5852                                    query.append(WHERE_AND);
5853                            }
5854    
5855                            for (int i = 0; i < orderByConditionFields.length; i++) {
5856                                    query.append(_ORDER_BY_ENTITY_ALIAS);
5857                                    query.append(orderByConditionFields[i]);
5858    
5859                                    if ((i + 1) < orderByConditionFields.length) {
5860                                            if (orderByComparator.isAscending() ^ previous) {
5861                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
5862                                            }
5863                                            else {
5864                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
5865                                            }
5866                                    }
5867                                    else {
5868                                            if (orderByComparator.isAscending() ^ previous) {
5869                                                    query.append(WHERE_GREATER_THAN);
5870                                            }
5871                                            else {
5872                                                    query.append(WHERE_LESSER_THAN);
5873                                            }
5874                                    }
5875                            }
5876    
5877                            query.append(ORDER_BY_CLAUSE);
5878    
5879                            String[] orderByFields = orderByComparator.getOrderByFields();
5880    
5881                            for (int i = 0; i < orderByFields.length; i++) {
5882                                    query.append(_ORDER_BY_ENTITY_ALIAS);
5883                                    query.append(orderByFields[i]);
5884    
5885                                    if ((i + 1) < orderByFields.length) {
5886                                            if (orderByComparator.isAscending() ^ previous) {
5887                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
5888                                            }
5889                                            else {
5890                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
5891                                            }
5892                                    }
5893                                    else {
5894                                            if (orderByComparator.isAscending() ^ previous) {
5895                                                    query.append(ORDER_BY_ASC);
5896                                            }
5897                                            else {
5898                                                    query.append(ORDER_BY_DESC);
5899                                            }
5900                                    }
5901                            }
5902                    }
5903                    else {
5904                            query.append(DDMStructureModelImpl.ORDER_BY_JPQL);
5905                    }
5906    
5907                    String sql = query.toString();
5908    
5909                    Query q = session.createQuery(sql);
5910    
5911                    q.setFirstResult(0);
5912                    q.setMaxResults(2);
5913    
5914                    QueryPos qPos = QueryPos.getInstance(q);
5915    
5916                    qPos.add(groupId);
5917    
5918                    if (bindName) {
5919                            qPos.add(name);
5920                    }
5921    
5922                    if (bindDescription) {
5923                            qPos.add(description);
5924                    }
5925    
5926                    if (orderByComparator != null) {
5927                            Object[] values = orderByComparator.getOrderByConditionValues(ddmStructure);
5928    
5929                            for (Object value : values) {
5930                                    qPos.add(value);
5931                            }
5932                    }
5933    
5934                    List<DDMStructure> list = q.list();
5935    
5936                    if (list.size() == 2) {
5937                            return list.get(1);
5938                    }
5939                    else {
5940                            return null;
5941                    }
5942            }
5943    
5944            /**
5945             * Returns all the d d m structures that the user has permission to view where groupId = &#63; and name = &#63; and description = &#63;.
5946             *
5947             * @param groupId the group ID
5948             * @param name the name
5949             * @param description the description
5950             * @return the matching d d m structures that the user has permission to view
5951             * @throws SystemException if a system exception occurred
5952             */
5953            public List<DDMStructure> filterFindByG_N_D(long groupId, String name,
5954                    String description) throws SystemException {
5955                    return filterFindByG_N_D(groupId, name, description, QueryUtil.ALL_POS,
5956                            QueryUtil.ALL_POS, null);
5957            }
5958    
5959            /**
5960             * 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;.
5961             *
5962             * <p>
5963             * 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.
5964             * </p>
5965             *
5966             * @param groupId the group ID
5967             * @param name the name
5968             * @param description the description
5969             * @param start the lower bound of the range of d d m structures
5970             * @param end the upper bound of the range of d d m structures (not inclusive)
5971             * @return the range of matching d d m structures that the user has permission to view
5972             * @throws SystemException if a system exception occurred
5973             */
5974            public List<DDMStructure> filterFindByG_N_D(long groupId, String name,
5975                    String description, int start, int end) throws SystemException {
5976                    return filterFindByG_N_D(groupId, name, description, start, end, null);
5977            }
5978    
5979            /**
5980             * 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;.
5981             *
5982             * <p>
5983             * 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.
5984             * </p>
5985             *
5986             * @param groupId the group ID
5987             * @param name the name
5988             * @param description the description
5989             * @param start the lower bound of the range of d d m structures
5990             * @param end the upper bound of the range of d d m structures (not inclusive)
5991             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
5992             * @return the ordered range of matching d d m structures that the user has permission to view
5993             * @throws SystemException if a system exception occurred
5994             */
5995            public List<DDMStructure> filterFindByG_N_D(long groupId, String name,
5996                    String description, int start, int end,
5997                    OrderByComparator orderByComparator) throws SystemException {
5998                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
5999                            return findByG_N_D(groupId, name, description, start, end,
6000                                    orderByComparator);
6001                    }
6002    
6003                    StringBundler query = null;
6004    
6005                    if (orderByComparator != null) {
6006                            query = new StringBundler(5 +
6007                                            (orderByComparator.getOrderByFields().length * 3));
6008                    }
6009                    else {
6010                            query = new StringBundler(5);
6011                    }
6012    
6013                    if (getDB().isSupportsInlineDistinct()) {
6014                            query.append(_FILTER_SQL_SELECT_DDMSTRUCTURE_WHERE);
6015                    }
6016                    else {
6017                            query.append(_FILTER_SQL_SELECT_DDMSTRUCTURE_NO_INLINE_DISTINCT_WHERE_1);
6018                    }
6019    
6020                    query.append(_FINDER_COLUMN_G_N_D_GROUPID_2);
6021    
6022                    boolean bindName = false;
6023    
6024                    if (name == null) {
6025                            query.append(_FINDER_COLUMN_G_N_D_NAME_1);
6026                    }
6027                    else if (name.equals(StringPool.BLANK)) {
6028                            query.append(_FINDER_COLUMN_G_N_D_NAME_3);
6029                    }
6030                    else {
6031                            bindName = true;
6032    
6033                            query.append(_FINDER_COLUMN_G_N_D_NAME_2);
6034                    }
6035    
6036                    boolean bindDescription = false;
6037    
6038                    if (description == null) {
6039                            query.append(_FINDER_COLUMN_G_N_D_DESCRIPTION_1);
6040                    }
6041                    else if (description.equals(StringPool.BLANK)) {
6042                            query.append(_FINDER_COLUMN_G_N_D_DESCRIPTION_3);
6043                    }
6044                    else {
6045                            bindDescription = true;
6046    
6047                            query.append(_FINDER_COLUMN_G_N_D_DESCRIPTION_2);
6048                    }
6049    
6050                    if (!getDB().isSupportsInlineDistinct()) {
6051                            query.append(_FILTER_SQL_SELECT_DDMSTRUCTURE_NO_INLINE_DISTINCT_WHERE_2);
6052                    }
6053    
6054                    if (orderByComparator != null) {
6055                            if (getDB().isSupportsInlineDistinct()) {
6056                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
6057                                            orderByComparator);
6058                            }
6059                            else {
6060                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_TABLE,
6061                                            orderByComparator);
6062                            }
6063                    }
6064                    else {
6065                            if (getDB().isSupportsInlineDistinct()) {
6066                                    query.append(DDMStructureModelImpl.ORDER_BY_JPQL);
6067                            }
6068                            else {
6069                                    query.append(DDMStructureModelImpl.ORDER_BY_SQL);
6070                            }
6071                    }
6072    
6073                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
6074                                    DDMStructure.class.getName(),
6075                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
6076    
6077                    Session session = null;
6078    
6079                    try {
6080                            session = openSession();
6081    
6082                            SQLQuery q = session.createSQLQuery(sql);
6083    
6084                            if (getDB().isSupportsInlineDistinct()) {
6085                                    q.addEntity(_FILTER_ENTITY_ALIAS, DDMStructureImpl.class);
6086                            }
6087                            else {
6088                                    q.addEntity(_FILTER_ENTITY_TABLE, DDMStructureImpl.class);
6089                            }
6090    
6091                            QueryPos qPos = QueryPos.getInstance(q);
6092    
6093                            qPos.add(groupId);
6094    
6095                            if (bindName) {
6096                                    qPos.add(name);
6097                            }
6098    
6099                            if (bindDescription) {
6100                                    qPos.add(description);
6101                            }
6102    
6103                            return (List<DDMStructure>)QueryUtil.list(q, getDialect(), start,
6104                                    end);
6105                    }
6106                    catch (Exception e) {
6107                            throw processException(e);
6108                    }
6109                    finally {
6110                            closeSession(session);
6111                    }
6112            }
6113    
6114            /**
6115             * 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;.
6116             *
6117             * @param structureId the primary key of the current d d m structure
6118             * @param groupId the group ID
6119             * @param name the name
6120             * @param description the description
6121             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
6122             * @return the previous, current, and next d d m structure
6123             * @throws com.liferay.portlet.dynamicdatamapping.NoSuchStructureException if a d d m structure with the primary key could not be found
6124             * @throws SystemException if a system exception occurred
6125             */
6126            public DDMStructure[] filterFindByG_N_D_PrevAndNext(long structureId,
6127                    long groupId, String name, String description,
6128                    OrderByComparator orderByComparator)
6129                    throws NoSuchStructureException, SystemException {
6130                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
6131                            return findByG_N_D_PrevAndNext(structureId, groupId, name,
6132                                    description, orderByComparator);
6133                    }
6134    
6135                    DDMStructure ddmStructure = findByPrimaryKey(structureId);
6136    
6137                    Session session = null;
6138    
6139                    try {
6140                            session = openSession();
6141    
6142                            DDMStructure[] array = new DDMStructureImpl[3];
6143    
6144                            array[0] = filterGetByG_N_D_PrevAndNext(session, ddmStructure,
6145                                            groupId, name, description, orderByComparator, true);
6146    
6147                            array[1] = ddmStructure;
6148    
6149                            array[2] = filterGetByG_N_D_PrevAndNext(session, ddmStructure,
6150                                            groupId, name, description, orderByComparator, false);
6151    
6152                            return array;
6153                    }
6154                    catch (Exception e) {
6155                            throw processException(e);
6156                    }
6157                    finally {
6158                            closeSession(session);
6159                    }
6160            }
6161    
6162            protected DDMStructure filterGetByG_N_D_PrevAndNext(Session session,
6163                    DDMStructure ddmStructure, long groupId, String name,
6164                    String description, OrderByComparator orderByComparator,
6165                    boolean previous) {
6166                    StringBundler query = null;
6167    
6168                    if (orderByComparator != null) {
6169                            query = new StringBundler(6 +
6170                                            (orderByComparator.getOrderByFields().length * 6));
6171                    }
6172                    else {
6173                            query = new StringBundler(3);
6174                    }
6175    
6176                    if (getDB().isSupportsInlineDistinct()) {
6177                            query.append(_FILTER_SQL_SELECT_DDMSTRUCTURE_WHERE);
6178                    }
6179                    else {
6180                            query.append(_FILTER_SQL_SELECT_DDMSTRUCTURE_NO_INLINE_DISTINCT_WHERE_1);
6181                    }
6182    
6183                    query.append(_FINDER_COLUMN_G_N_D_GROUPID_2);
6184    
6185                    boolean bindName = false;
6186    
6187                    if (name == null) {
6188                            query.append(_FINDER_COLUMN_G_N_D_NAME_1);
6189                    }
6190                    else if (name.equals(StringPool.BLANK)) {
6191                            query.append(_FINDER_COLUMN_G_N_D_NAME_3);
6192                    }
6193                    else {
6194                            bindName = true;
6195    
6196                            query.append(_FINDER_COLUMN_G_N_D_NAME_2);
6197                    }
6198    
6199                    boolean bindDescription = false;
6200    
6201                    if (description == null) {
6202                            query.append(_FINDER_COLUMN_G_N_D_DESCRIPTION_1);
6203                    }
6204                    else if (description.equals(StringPool.BLANK)) {
6205                            query.append(_FINDER_COLUMN_G_N_D_DESCRIPTION_3);
6206                    }
6207                    else {
6208                            bindDescription = true;
6209    
6210                            query.append(_FINDER_COLUMN_G_N_D_DESCRIPTION_2);
6211                    }
6212    
6213                    if (!getDB().isSupportsInlineDistinct()) {
6214                            query.append(_FILTER_SQL_SELECT_DDMSTRUCTURE_NO_INLINE_DISTINCT_WHERE_2);
6215                    }
6216    
6217                    if (orderByComparator != null) {
6218                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
6219    
6220                            if (orderByConditionFields.length > 0) {
6221                                    query.append(WHERE_AND);
6222                            }
6223    
6224                            for (int i = 0; i < orderByConditionFields.length; i++) {
6225                                    if (getDB().isSupportsInlineDistinct()) {
6226                                            query.append(_ORDER_BY_ENTITY_ALIAS);
6227                                    }
6228                                    else {
6229                                            query.append(_ORDER_BY_ENTITY_TABLE);
6230                                    }
6231    
6232                                    query.append(orderByConditionFields[i]);
6233    
6234                                    if ((i + 1) < orderByConditionFields.length) {
6235                                            if (orderByComparator.isAscending() ^ previous) {
6236                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
6237                                            }
6238                                            else {
6239                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
6240                                            }
6241                                    }
6242                                    else {
6243                                            if (orderByComparator.isAscending() ^ previous) {
6244                                                    query.append(WHERE_GREATER_THAN);
6245                                            }
6246                                            else {
6247                                                    query.append(WHERE_LESSER_THAN);
6248                                            }
6249                                    }
6250                            }
6251    
6252                            query.append(ORDER_BY_CLAUSE);
6253    
6254                            String[] orderByFields = orderByComparator.getOrderByFields();
6255    
6256                            for (int i = 0; i < orderByFields.length; i++) {
6257                                    if (getDB().isSupportsInlineDistinct()) {
6258                                            query.append(_ORDER_BY_ENTITY_ALIAS);
6259                                    }
6260                                    else {
6261                                            query.append(_ORDER_BY_ENTITY_TABLE);
6262                                    }
6263    
6264                                    query.append(orderByFields[i]);
6265    
6266                                    if ((i + 1) < orderByFields.length) {
6267                                            if (orderByComparator.isAscending() ^ previous) {
6268                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
6269                                            }
6270                                            else {
6271                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
6272                                            }
6273                                    }
6274                                    else {
6275                                            if (orderByComparator.isAscending() ^ previous) {
6276                                                    query.append(ORDER_BY_ASC);
6277                                            }
6278                                            else {
6279                                                    query.append(ORDER_BY_DESC);
6280                                            }
6281                                    }
6282                            }
6283                    }
6284                    else {
6285                            if (getDB().isSupportsInlineDistinct()) {
6286                                    query.append(DDMStructureModelImpl.ORDER_BY_JPQL);
6287                            }
6288                            else {
6289                                    query.append(DDMStructureModelImpl.ORDER_BY_SQL);
6290                            }
6291                    }
6292    
6293                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
6294                                    DDMStructure.class.getName(),
6295                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
6296    
6297                    SQLQuery q = session.createSQLQuery(sql);
6298    
6299                    q.setFirstResult(0);
6300                    q.setMaxResults(2);
6301    
6302                    if (getDB().isSupportsInlineDistinct()) {
6303                            q.addEntity(_FILTER_ENTITY_ALIAS, DDMStructureImpl.class);
6304                    }
6305                    else {
6306                            q.addEntity(_FILTER_ENTITY_TABLE, DDMStructureImpl.class);
6307                    }
6308    
6309                    QueryPos qPos = QueryPos.getInstance(q);
6310    
6311                    qPos.add(groupId);
6312    
6313                    if (bindName) {
6314                            qPos.add(name);
6315                    }
6316    
6317                    if (bindDescription) {
6318                            qPos.add(description);
6319                    }
6320    
6321                    if (orderByComparator != null) {
6322                            Object[] values = orderByComparator.getOrderByConditionValues(ddmStructure);
6323    
6324                            for (Object value : values) {
6325                                    qPos.add(value);
6326                            }
6327                    }
6328    
6329                    List<DDMStructure> list = q.list();
6330    
6331                    if (list.size() == 2) {
6332                            return list.get(1);
6333                    }
6334                    else {
6335                            return null;
6336                    }
6337            }
6338    
6339            /**
6340             * Removes all the d d m structures where groupId = &#63; and name = &#63; and description = &#63; from the database.
6341             *
6342             * @param groupId the group ID
6343             * @param name the name
6344             * @param description the description
6345             * @throws SystemException if a system exception occurred
6346             */
6347            public void removeByG_N_D(long groupId, String name, String description)
6348                    throws SystemException {
6349                    for (DDMStructure ddmStructure : findByG_N_D(groupId, name,
6350                                    description, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
6351                            remove(ddmStructure);
6352                    }
6353            }
6354    
6355            /**
6356             * Returns the number of d d m structures where groupId = &#63; and name = &#63; and description = &#63;.
6357             *
6358             * @param groupId the group ID
6359             * @param name the name
6360             * @param description the description
6361             * @return the number of matching d d m structures
6362             * @throws SystemException if a system exception occurred
6363             */
6364            public int countByG_N_D(long groupId, String name, String description)
6365                    throws SystemException {
6366                    FinderPath finderPath = FINDER_PATH_COUNT_BY_G_N_D;
6367    
6368                    Object[] finderArgs = new Object[] { groupId, name, description };
6369    
6370                    Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
6371                                    this);
6372    
6373                    if (count == null) {
6374                            StringBundler query = new StringBundler(4);
6375    
6376                            query.append(_SQL_COUNT_DDMSTRUCTURE_WHERE);
6377    
6378                            query.append(_FINDER_COLUMN_G_N_D_GROUPID_2);
6379    
6380                            boolean bindName = false;
6381    
6382                            if (name == null) {
6383                                    query.append(_FINDER_COLUMN_G_N_D_NAME_1);
6384                            }
6385                            else if (name.equals(StringPool.BLANK)) {
6386                                    query.append(_FINDER_COLUMN_G_N_D_NAME_3);
6387                            }
6388                            else {
6389                                    bindName = true;
6390    
6391                                    query.append(_FINDER_COLUMN_G_N_D_NAME_2);
6392                            }
6393    
6394                            boolean bindDescription = false;
6395    
6396                            if (description == null) {
6397                                    query.append(_FINDER_COLUMN_G_N_D_DESCRIPTION_1);
6398                            }
6399                            else if (description.equals(StringPool.BLANK)) {
6400                                    query.append(_FINDER_COLUMN_G_N_D_DESCRIPTION_3);
6401                            }
6402                            else {
6403                                    bindDescription = true;
6404    
6405                                    query.append(_FINDER_COLUMN_G_N_D_DESCRIPTION_2);
6406                            }
6407    
6408                            String sql = query.toString();
6409    
6410                            Session session = null;
6411    
6412                            try {
6413                                    session = openSession();
6414    
6415                                    Query q = session.createQuery(sql);
6416    
6417                                    QueryPos qPos = QueryPos.getInstance(q);
6418    
6419                                    qPos.add(groupId);
6420    
6421                                    if (bindName) {
6422                                            qPos.add(name);
6423                                    }
6424    
6425                                    if (bindDescription) {
6426                                            qPos.add(description);
6427                                    }
6428    
6429                                    count = (Long)q.uniqueResult();
6430    
6431                                    FinderCacheUtil.putResult(finderPath, finderArgs, count);
6432                            }
6433                            catch (Exception e) {
6434                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
6435    
6436                                    throw processException(e);
6437                            }
6438                            finally {
6439                                    closeSession(session);
6440                            }
6441                    }
6442    
6443                    return count.intValue();
6444            }
6445    
6446            /**
6447             * Returns the number of d d m structures that the user has permission to view where groupId = &#63; and name = &#63; and description = &#63;.
6448             *
6449             * @param groupId the group ID
6450             * @param name the name
6451             * @param description the description
6452             * @return the number of matching d d m structures that the user has permission to view
6453             * @throws SystemException if a system exception occurred
6454             */
6455            public int filterCountByG_N_D(long groupId, String name, String description)
6456                    throws SystemException {
6457                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
6458                            return countByG_N_D(groupId, name, description);
6459                    }
6460    
6461                    StringBundler query = new StringBundler(4);
6462    
6463                    query.append(_FILTER_SQL_COUNT_DDMSTRUCTURE_WHERE);
6464    
6465                    query.append(_FINDER_COLUMN_G_N_D_GROUPID_2);
6466    
6467                    boolean bindName = false;
6468    
6469                    if (name == null) {
6470                            query.append(_FINDER_COLUMN_G_N_D_NAME_1);
6471                    }
6472                    else if (name.equals(StringPool.BLANK)) {
6473                            query.append(_FINDER_COLUMN_G_N_D_NAME_3);
6474                    }
6475                    else {
6476                            bindName = true;
6477    
6478                            query.append(_FINDER_COLUMN_G_N_D_NAME_2);
6479                    }
6480    
6481                    boolean bindDescription = false;
6482    
6483                    if (description == null) {
6484                            query.append(_FINDER_COLUMN_G_N_D_DESCRIPTION_1);
6485                    }
6486                    else if (description.equals(StringPool.BLANK)) {
6487                            query.append(_FINDER_COLUMN_G_N_D_DESCRIPTION_3);
6488                    }
6489                    else {
6490                            bindDescription = true;
6491    
6492                            query.append(_FINDER_COLUMN_G_N_D_DESCRIPTION_2);
6493                    }
6494    
6495                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
6496                                    DDMStructure.class.getName(),
6497                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
6498    
6499                    Session session = null;
6500    
6501                    try {
6502                            session = openSession();
6503    
6504                            SQLQuery q = session.createSQLQuery(sql);
6505    
6506                            q.addScalar(COUNT_COLUMN_NAME,
6507                                    com.liferay.portal.kernel.dao.orm.Type.LONG);
6508    
6509                            QueryPos qPos = QueryPos.getInstance(q);
6510    
6511                            qPos.add(groupId);
6512    
6513                            if (bindName) {
6514                                    qPos.add(name);
6515                            }
6516    
6517                            if (bindDescription) {
6518                                    qPos.add(description);
6519                            }
6520    
6521                            Long count = (Long)q.uniqueResult();
6522    
6523                            return count.intValue();
6524                    }
6525                    catch (Exception e) {
6526                            throw processException(e);
6527                    }
6528                    finally {
6529                            closeSession(session);
6530                    }
6531            }
6532    
6533            private static final String _FINDER_COLUMN_G_N_D_GROUPID_2 = "ddmStructure.groupId = ? AND ";
6534            private static final String _FINDER_COLUMN_G_N_D_NAME_1 = "ddmStructure.name IS NULL AND ";
6535            private static final String _FINDER_COLUMN_G_N_D_NAME_2 = "ddmStructure.name = ? AND ";
6536            private static final String _FINDER_COLUMN_G_N_D_NAME_3 = "(ddmStructure.name IS NULL OR ddmStructure.name = '') AND ";
6537            private static final String _FINDER_COLUMN_G_N_D_DESCRIPTION_1 = "ddmStructure.description IS NULL";
6538            private static final String _FINDER_COLUMN_G_N_D_DESCRIPTION_2 = "ddmStructure.description = ?";
6539            private static final String _FINDER_COLUMN_G_N_D_DESCRIPTION_3 = "(ddmStructure.description IS NULL OR ddmStructure.description = '')";
6540    
6541            /**
6542             * Caches the d d m structure in the entity cache if it is enabled.
6543             *
6544             * @param ddmStructure the d d m structure
6545             */
6546            public void cacheResult(DDMStructure ddmStructure) {
6547                    EntityCacheUtil.putResult(DDMStructureModelImpl.ENTITY_CACHE_ENABLED,
6548                            DDMStructureImpl.class, ddmStructure.getPrimaryKey(), ddmStructure);
6549    
6550                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_UUID_G,
6551                            new Object[] { ddmStructure.getUuid(), ddmStructure.getGroupId() },
6552                            ddmStructure);
6553    
6554                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_G_C_S,
6555                            new Object[] {
6556                                    ddmStructure.getGroupId(), ddmStructure.getClassNameId(),
6557                                    ddmStructure.getStructureKey()
6558                            }, ddmStructure);
6559    
6560                    ddmStructure.resetOriginalValues();
6561            }
6562    
6563            /**
6564             * Caches the d d m structures in the entity cache if it is enabled.
6565             *
6566             * @param ddmStructures the d d m structures
6567             */
6568            public void cacheResult(List<DDMStructure> ddmStructures) {
6569                    for (DDMStructure ddmStructure : ddmStructures) {
6570                            if (EntityCacheUtil.getResult(
6571                                                    DDMStructureModelImpl.ENTITY_CACHE_ENABLED,
6572                                                    DDMStructureImpl.class, ddmStructure.getPrimaryKey()) == null) {
6573                                    cacheResult(ddmStructure);
6574                            }
6575                            else {
6576                                    ddmStructure.resetOriginalValues();
6577                            }
6578                    }
6579            }
6580    
6581            /**
6582             * Clears the cache for all d d m structures.
6583             *
6584             * <p>
6585             * The {@link com.liferay.portal.kernel.dao.orm.EntityCache} and {@link com.liferay.portal.kernel.dao.orm.FinderCache} are both cleared by this method.
6586             * </p>
6587             */
6588            @Override
6589            public void clearCache() {
6590                    if (_HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE) {
6591                            CacheRegistryUtil.clear(DDMStructureImpl.class.getName());
6592                    }
6593    
6594                    EntityCacheUtil.clearCache(DDMStructureImpl.class.getName());
6595    
6596                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_ENTITY);
6597                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
6598                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
6599            }
6600    
6601            /**
6602             * Clears the cache for the d d m structure.
6603             *
6604             * <p>
6605             * The {@link com.liferay.portal.kernel.dao.orm.EntityCache} and {@link com.liferay.portal.kernel.dao.orm.FinderCache} are both cleared by this method.
6606             * </p>
6607             */
6608            @Override
6609            public void clearCache(DDMStructure ddmStructure) {
6610                    EntityCacheUtil.removeResult(DDMStructureModelImpl.ENTITY_CACHE_ENABLED,
6611                            DDMStructureImpl.class, ddmStructure.getPrimaryKey());
6612    
6613                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
6614                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
6615    
6616                    clearUniqueFindersCache(ddmStructure);
6617            }
6618    
6619            @Override
6620            public void clearCache(List<DDMStructure> ddmStructures) {
6621                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
6622                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
6623    
6624                    for (DDMStructure ddmStructure : ddmStructures) {
6625                            EntityCacheUtil.removeResult(DDMStructureModelImpl.ENTITY_CACHE_ENABLED,
6626                                    DDMStructureImpl.class, ddmStructure.getPrimaryKey());
6627    
6628                            clearUniqueFindersCache(ddmStructure);
6629                    }
6630            }
6631    
6632            protected void cacheUniqueFindersCache(DDMStructure ddmStructure) {
6633                    if (ddmStructure.isNew()) {
6634                            Object[] args = new Object[] {
6635                                            ddmStructure.getUuid(), ddmStructure.getGroupId()
6636                                    };
6637    
6638                            FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_UUID_G, args,
6639                                    Long.valueOf(1));
6640                            FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_UUID_G, args,
6641                                    ddmStructure);
6642    
6643                            args = new Object[] {
6644                                            ddmStructure.getGroupId(), ddmStructure.getClassNameId(),
6645                                            ddmStructure.getStructureKey()
6646                                    };
6647    
6648                            FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_G_C_S, args,
6649                                    Long.valueOf(1));
6650                            FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_G_C_S, args,
6651                                    ddmStructure);
6652                    }
6653                    else {
6654                            DDMStructureModelImpl ddmStructureModelImpl = (DDMStructureModelImpl)ddmStructure;
6655    
6656                            if ((ddmStructureModelImpl.getColumnBitmask() &
6657                                            FINDER_PATH_FETCH_BY_UUID_G.getColumnBitmask()) != 0) {
6658                                    Object[] args = new Object[] {
6659                                                    ddmStructure.getUuid(), ddmStructure.getGroupId()
6660                                            };
6661    
6662                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_UUID_G, args,
6663                                            Long.valueOf(1));
6664                                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_UUID_G, args,
6665                                            ddmStructure);
6666                            }
6667    
6668                            if ((ddmStructureModelImpl.getColumnBitmask() &
6669                                            FINDER_PATH_FETCH_BY_G_C_S.getColumnBitmask()) != 0) {
6670                                    Object[] args = new Object[] {
6671                                                    ddmStructure.getGroupId(), ddmStructure.getClassNameId(),
6672                                                    ddmStructure.getStructureKey()
6673                                            };
6674    
6675                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_G_C_S, args,
6676                                            Long.valueOf(1));
6677                                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_G_C_S, args,
6678                                            ddmStructure);
6679                            }
6680                    }
6681            }
6682    
6683            protected void clearUniqueFindersCache(DDMStructure ddmStructure) {
6684                    DDMStructureModelImpl ddmStructureModelImpl = (DDMStructureModelImpl)ddmStructure;
6685    
6686                    Object[] args = new Object[] {
6687                                    ddmStructure.getUuid(), ddmStructure.getGroupId()
6688                            };
6689    
6690                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_UUID_G, args);
6691                    FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_UUID_G, args);
6692    
6693                    if ((ddmStructureModelImpl.getColumnBitmask() &
6694                                    FINDER_PATH_FETCH_BY_UUID_G.getColumnBitmask()) != 0) {
6695                            args = new Object[] {
6696                                            ddmStructureModelImpl.getOriginalUuid(),
6697                                            ddmStructureModelImpl.getOriginalGroupId()
6698                                    };
6699    
6700                            FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_UUID_G, args);
6701                            FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_UUID_G, args);
6702                    }
6703    
6704                    args = new Object[] {
6705                                    ddmStructure.getGroupId(), ddmStructure.getClassNameId(),
6706                                    ddmStructure.getStructureKey()
6707                            };
6708    
6709                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_G_C_S, args);
6710                    FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_G_C_S, args);
6711    
6712                    if ((ddmStructureModelImpl.getColumnBitmask() &
6713                                    FINDER_PATH_FETCH_BY_G_C_S.getColumnBitmask()) != 0) {
6714                            args = new Object[] {
6715                                            ddmStructureModelImpl.getOriginalGroupId(),
6716                                            ddmStructureModelImpl.getOriginalClassNameId(),
6717                                            ddmStructureModelImpl.getOriginalStructureKey()
6718                                    };
6719    
6720                            FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_G_C_S, args);
6721                            FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_G_C_S, args);
6722                    }
6723            }
6724    
6725            /**
6726             * Creates a new d d m structure with the primary key. Does not add the d d m structure to the database.
6727             *
6728             * @param structureId the primary key for the new d d m structure
6729             * @return the new d d m structure
6730             */
6731            public DDMStructure create(long structureId) {
6732                    DDMStructure ddmStructure = new DDMStructureImpl();
6733    
6734                    ddmStructure.setNew(true);
6735                    ddmStructure.setPrimaryKey(structureId);
6736    
6737                    String uuid = PortalUUIDUtil.generate();
6738    
6739                    ddmStructure.setUuid(uuid);
6740    
6741                    return ddmStructure;
6742            }
6743    
6744            /**
6745             * Removes the d d m structure with the primary key from the database. Also notifies the appropriate model listeners.
6746             *
6747             * @param structureId the primary key of the d d m structure
6748             * @return the d d m structure that was removed
6749             * @throws com.liferay.portlet.dynamicdatamapping.NoSuchStructureException if a d d m structure with the primary key could not be found
6750             * @throws SystemException if a system exception occurred
6751             */
6752            public DDMStructure remove(long structureId)
6753                    throws NoSuchStructureException, SystemException {
6754                    return remove((Serializable)structureId);
6755            }
6756    
6757            /**
6758             * Removes the d d m structure with the primary key from the database. Also notifies the appropriate model listeners.
6759             *
6760             * @param primaryKey the primary key of the d d m structure
6761             * @return the d d m structure that was removed
6762             * @throws com.liferay.portlet.dynamicdatamapping.NoSuchStructureException if a d d m structure with the primary key could not be found
6763             * @throws SystemException if a system exception occurred
6764             */
6765            @Override
6766            public DDMStructure remove(Serializable primaryKey)
6767                    throws NoSuchStructureException, SystemException {
6768                    Session session = null;
6769    
6770                    try {
6771                            session = openSession();
6772    
6773                            DDMStructure ddmStructure = (DDMStructure)session.get(DDMStructureImpl.class,
6774                                            primaryKey);
6775    
6776                            if (ddmStructure == null) {
6777                                    if (_log.isWarnEnabled()) {
6778                                            _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + primaryKey);
6779                                    }
6780    
6781                                    throw new NoSuchStructureException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
6782                                            primaryKey);
6783                            }
6784    
6785                            return remove(ddmStructure);
6786                    }
6787                    catch (NoSuchStructureException nsee) {
6788                            throw nsee;
6789                    }
6790                    catch (Exception e) {
6791                            throw processException(e);
6792                    }
6793                    finally {
6794                            closeSession(session);
6795                    }
6796            }
6797    
6798            @Override
6799            protected DDMStructure removeImpl(DDMStructure ddmStructure)
6800                    throws SystemException {
6801                    ddmStructure = toUnwrappedModel(ddmStructure);
6802    
6803                    Session session = null;
6804    
6805                    try {
6806                            session = openSession();
6807    
6808                            if (!session.contains(ddmStructure)) {
6809                                    ddmStructure = (DDMStructure)session.get(DDMStructureImpl.class,
6810                                                    ddmStructure.getPrimaryKeyObj());
6811                            }
6812    
6813                            if (ddmStructure != null) {
6814                                    session.delete(ddmStructure);
6815                            }
6816                    }
6817                    catch (Exception e) {
6818                            throw processException(e);
6819                    }
6820                    finally {
6821                            closeSession(session);
6822                    }
6823    
6824                    if (ddmStructure != null) {
6825                            clearCache(ddmStructure);
6826                    }
6827    
6828                    return ddmStructure;
6829            }
6830    
6831            @Override
6832            public DDMStructure updateImpl(
6833                    com.liferay.portlet.dynamicdatamapping.model.DDMStructure ddmStructure)
6834                    throws SystemException {
6835                    ddmStructure = toUnwrappedModel(ddmStructure);
6836    
6837                    boolean isNew = ddmStructure.isNew();
6838    
6839                    DDMStructureModelImpl ddmStructureModelImpl = (DDMStructureModelImpl)ddmStructure;
6840    
6841                    if (Validator.isNull(ddmStructure.getUuid())) {
6842                            String uuid = PortalUUIDUtil.generate();
6843    
6844                            ddmStructure.setUuid(uuid);
6845                    }
6846    
6847                    Session session = null;
6848    
6849                    try {
6850                            session = openSession();
6851    
6852                            if (ddmStructure.isNew()) {
6853                                    session.save(ddmStructure);
6854    
6855                                    ddmStructure.setNew(false);
6856                            }
6857                            else {
6858                                    session.merge(ddmStructure);
6859                            }
6860                    }
6861                    catch (Exception e) {
6862                            throw processException(e);
6863                    }
6864                    finally {
6865                            closeSession(session);
6866                    }
6867    
6868                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
6869    
6870                    if (isNew || !DDMStructureModelImpl.COLUMN_BITMASK_ENABLED) {
6871                            FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
6872                    }
6873    
6874                    else {
6875                            if ((ddmStructureModelImpl.getColumnBitmask() &
6876                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID.getColumnBitmask()) != 0) {
6877                                    Object[] args = new Object[] {
6878                                                    ddmStructureModelImpl.getOriginalUuid()
6879                                            };
6880    
6881                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_UUID, args);
6882                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID,
6883                                            args);
6884    
6885                                    args = new Object[] { ddmStructureModelImpl.getUuid() };
6886    
6887                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_UUID, args);
6888                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID,
6889                                            args);
6890                            }
6891    
6892                            if ((ddmStructureModelImpl.getColumnBitmask() &
6893                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID_C.getColumnBitmask()) != 0) {
6894                                    Object[] args = new Object[] {
6895                                                    ddmStructureModelImpl.getOriginalUuid(),
6896                                                    ddmStructureModelImpl.getOriginalCompanyId()
6897                                            };
6898    
6899                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_UUID_C, args);
6900                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID_C,
6901                                            args);
6902    
6903                                    args = new Object[] {
6904                                                    ddmStructureModelImpl.getUuid(),
6905                                                    ddmStructureModelImpl.getCompanyId()
6906                                            };
6907    
6908                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_UUID_C, args);
6909                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID_C,
6910                                            args);
6911                            }
6912    
6913                            if ((ddmStructureModelImpl.getColumnBitmask() &
6914                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_GROUPID.getColumnBitmask()) != 0) {
6915                                    Object[] args = new Object[] {
6916                                                    ddmStructureModelImpl.getOriginalGroupId()
6917                                            };
6918    
6919                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_GROUPID, args);
6920                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_GROUPID,
6921                                            args);
6922    
6923                                    args = new Object[] { ddmStructureModelImpl.getGroupId() };
6924    
6925                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_GROUPID, args);
6926                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_GROUPID,
6927                                            args);
6928                            }
6929    
6930                            if ((ddmStructureModelImpl.getColumnBitmask() &
6931                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_CLASSNAMEID.getColumnBitmask()) != 0) {
6932                                    Object[] args = new Object[] {
6933                                                    ddmStructureModelImpl.getOriginalClassNameId()
6934                                            };
6935    
6936                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_CLASSNAMEID,
6937                                            args);
6938                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_CLASSNAMEID,
6939                                            args);
6940    
6941                                    args = new Object[] { ddmStructureModelImpl.getClassNameId() };
6942    
6943                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_CLASSNAMEID,
6944                                            args);
6945                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_CLASSNAMEID,
6946                                            args);
6947                            }
6948    
6949                            if ((ddmStructureModelImpl.getColumnBitmask() &
6950                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_STRUCTUREKEY.getColumnBitmask()) != 0) {
6951                                    Object[] args = new Object[] {
6952                                                    ddmStructureModelImpl.getOriginalStructureKey()
6953                                            };
6954    
6955                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_STRUCTUREKEY,
6956                                            args);
6957                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_STRUCTUREKEY,
6958                                            args);
6959    
6960                                    args = new Object[] { ddmStructureModelImpl.getStructureKey() };
6961    
6962                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_STRUCTUREKEY,
6963                                            args);
6964                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_STRUCTUREKEY,
6965                                            args);
6966                            }
6967    
6968                            if ((ddmStructureModelImpl.getColumnBitmask() &
6969                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_C.getColumnBitmask()) != 0) {
6970                                    Object[] args = new Object[] {
6971                                                    ddmStructureModelImpl.getOriginalGroupId(),
6972                                                    ddmStructureModelImpl.getOriginalClassNameId()
6973                                            };
6974    
6975                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_G_C, args);
6976                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_C,
6977                                            args);
6978    
6979                                    args = new Object[] {
6980                                                    ddmStructureModelImpl.getGroupId(),
6981                                                    ddmStructureModelImpl.getClassNameId()
6982                                            };
6983    
6984                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_G_C, args);
6985                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_C,
6986                                            args);
6987                            }
6988    
6989                            if ((ddmStructureModelImpl.getColumnBitmask() &
6990                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_C.getColumnBitmask()) != 0) {
6991                                    Object[] args = new Object[] {
6992                                                    ddmStructureModelImpl.getOriginalCompanyId(),
6993                                                    ddmStructureModelImpl.getOriginalClassNameId()
6994                                            };
6995    
6996                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_C_C, args);
6997                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_C,
6998                                            args);
6999    
7000                                    args = new Object[] {
7001                                                    ddmStructureModelImpl.getCompanyId(),
7002                                                    ddmStructureModelImpl.getClassNameId()
7003                                            };
7004    
7005                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_C_C, args);
7006                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_C,
7007                                            args);
7008                            }
7009    
7010                            if ((ddmStructureModelImpl.getColumnBitmask() &
7011                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_N_D.getColumnBitmask()) != 0) {
7012                                    Object[] args = new Object[] {
7013                                                    ddmStructureModelImpl.getOriginalGroupId(),
7014                                                    ddmStructureModelImpl.getOriginalName(),
7015                                                    ddmStructureModelImpl.getOriginalDescription()
7016                                            };
7017    
7018                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_G_N_D, args);
7019                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_N_D,
7020                                            args);
7021    
7022                                    args = new Object[] {
7023                                                    ddmStructureModelImpl.getGroupId(),
7024                                                    ddmStructureModelImpl.getName(),
7025                                                    ddmStructureModelImpl.getDescription()
7026                                            };
7027    
7028                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_G_N_D, args);
7029                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_N_D,
7030                                            args);
7031                            }
7032                    }
7033    
7034                    EntityCacheUtil.putResult(DDMStructureModelImpl.ENTITY_CACHE_ENABLED,
7035                            DDMStructureImpl.class, ddmStructure.getPrimaryKey(), ddmStructure);
7036    
7037                    clearUniqueFindersCache(ddmStructure);
7038                    cacheUniqueFindersCache(ddmStructure);
7039    
7040                    return ddmStructure;
7041            }
7042    
7043            protected DDMStructure toUnwrappedModel(DDMStructure ddmStructure) {
7044                    if (ddmStructure instanceof DDMStructureImpl) {
7045                            return ddmStructure;
7046                    }
7047    
7048                    DDMStructureImpl ddmStructureImpl = new DDMStructureImpl();
7049    
7050                    ddmStructureImpl.setNew(ddmStructure.isNew());
7051                    ddmStructureImpl.setPrimaryKey(ddmStructure.getPrimaryKey());
7052    
7053                    ddmStructureImpl.setUuid(ddmStructure.getUuid());
7054                    ddmStructureImpl.setStructureId(ddmStructure.getStructureId());
7055                    ddmStructureImpl.setGroupId(ddmStructure.getGroupId());
7056                    ddmStructureImpl.setCompanyId(ddmStructure.getCompanyId());
7057                    ddmStructureImpl.setUserId(ddmStructure.getUserId());
7058                    ddmStructureImpl.setUserName(ddmStructure.getUserName());
7059                    ddmStructureImpl.setCreateDate(ddmStructure.getCreateDate());
7060                    ddmStructureImpl.setModifiedDate(ddmStructure.getModifiedDate());
7061                    ddmStructureImpl.setParentStructureId(ddmStructure.getParentStructureId());
7062                    ddmStructureImpl.setClassNameId(ddmStructure.getClassNameId());
7063                    ddmStructureImpl.setStructureKey(ddmStructure.getStructureKey());
7064                    ddmStructureImpl.setName(ddmStructure.getName());
7065                    ddmStructureImpl.setDescription(ddmStructure.getDescription());
7066                    ddmStructureImpl.setXsd(ddmStructure.getXsd());
7067                    ddmStructureImpl.setStorageType(ddmStructure.getStorageType());
7068                    ddmStructureImpl.setType(ddmStructure.getType());
7069    
7070                    return ddmStructureImpl;
7071            }
7072    
7073            /**
7074             * Returns the d d m structure with the primary key or throws a {@link com.liferay.portal.NoSuchModelException} if it could not be found.
7075             *
7076             * @param primaryKey the primary key of the d d m structure
7077             * @return the d d m structure
7078             * @throws com.liferay.portlet.dynamicdatamapping.NoSuchStructureException if a d d m structure with the primary key could not be found
7079             * @throws SystemException if a system exception occurred
7080             */
7081            @Override
7082            public DDMStructure findByPrimaryKey(Serializable primaryKey)
7083                    throws NoSuchStructureException, SystemException {
7084                    DDMStructure ddmStructure = fetchByPrimaryKey(primaryKey);
7085    
7086                    if (ddmStructure == null) {
7087                            if (_log.isWarnEnabled()) {
7088                                    _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + primaryKey);
7089                            }
7090    
7091                            throw new NoSuchStructureException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
7092                                    primaryKey);
7093                    }
7094    
7095                    return ddmStructure;
7096            }
7097    
7098            /**
7099             * 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.
7100             *
7101             * @param structureId the primary key of the d d m structure
7102             * @return the d d m structure
7103             * @throws com.liferay.portlet.dynamicdatamapping.NoSuchStructureException if a d d m structure with the primary key could not be found
7104             * @throws SystemException if a system exception occurred
7105             */
7106            public DDMStructure findByPrimaryKey(long structureId)
7107                    throws NoSuchStructureException, SystemException {
7108                    return findByPrimaryKey((Serializable)structureId);
7109            }
7110    
7111            /**
7112             * Returns the d d m structure with the primary key or returns <code>null</code> if it could not be found.
7113             *
7114             * @param primaryKey the primary key of the d d m structure
7115             * @return the d d m structure, or <code>null</code> if a d d m structure with the primary key could not be found
7116             * @throws SystemException if a system exception occurred
7117             */
7118            @Override
7119            public DDMStructure fetchByPrimaryKey(Serializable primaryKey)
7120                    throws SystemException {
7121                    DDMStructure ddmStructure = (DDMStructure)EntityCacheUtil.getResult(DDMStructureModelImpl.ENTITY_CACHE_ENABLED,
7122                                    DDMStructureImpl.class, primaryKey);
7123    
7124                    if (ddmStructure == _nullDDMStructure) {
7125                            return null;
7126                    }
7127    
7128                    if (ddmStructure == null) {
7129                            Session session = null;
7130    
7131                            try {
7132                                    session = openSession();
7133    
7134                                    ddmStructure = (DDMStructure)session.get(DDMStructureImpl.class,
7135                                                    primaryKey);
7136    
7137                                    if (ddmStructure != null) {
7138                                            cacheResult(ddmStructure);
7139                                    }
7140                                    else {
7141                                            EntityCacheUtil.putResult(DDMStructureModelImpl.ENTITY_CACHE_ENABLED,
7142                                                    DDMStructureImpl.class, primaryKey, _nullDDMStructure);
7143                                    }
7144                            }
7145                            catch (Exception e) {
7146                                    EntityCacheUtil.removeResult(DDMStructureModelImpl.ENTITY_CACHE_ENABLED,
7147                                            DDMStructureImpl.class, primaryKey);
7148    
7149                                    throw processException(e);
7150                            }
7151                            finally {
7152                                    closeSession(session);
7153                            }
7154                    }
7155    
7156                    return ddmStructure;
7157            }
7158    
7159            /**
7160             * Returns the d d m structure with the primary key or returns <code>null</code> if it could not be found.
7161             *
7162             * @param structureId the primary key of the d d m structure
7163             * @return the d d m structure, or <code>null</code> if a d d m structure with the primary key could not be found
7164             * @throws SystemException if a system exception occurred
7165             */
7166            public DDMStructure fetchByPrimaryKey(long structureId)
7167                    throws SystemException {
7168                    return fetchByPrimaryKey((Serializable)structureId);
7169            }
7170    
7171            /**
7172             * Returns all the d d m structures.
7173             *
7174             * @return the d d m structures
7175             * @throws SystemException if a system exception occurred
7176             */
7177            public List<DDMStructure> findAll() throws SystemException {
7178                    return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
7179            }
7180    
7181            /**
7182             * Returns a range of all the d d m structures.
7183             *
7184             * <p>
7185             * 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.
7186             * </p>
7187             *
7188             * @param start the lower bound of the range of d d m structures
7189             * @param end the upper bound of the range of d d m structures (not inclusive)
7190             * @return the range of d d m structures
7191             * @throws SystemException if a system exception occurred
7192             */
7193            public List<DDMStructure> findAll(int start, int end)
7194                    throws SystemException {
7195                    return findAll(start, end, null);
7196            }
7197    
7198            /**
7199             * Returns an ordered range of all the d d m structures.
7200             *
7201             * <p>
7202             * 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.
7203             * </p>
7204             *
7205             * @param start the lower bound of the range of d d m structures
7206             * @param end the upper bound of the range of d d m structures (not inclusive)
7207             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
7208             * @return the ordered range of d d m structures
7209             * @throws SystemException if a system exception occurred
7210             */
7211            public List<DDMStructure> findAll(int start, int end,
7212                    OrderByComparator orderByComparator) throws SystemException {
7213                    boolean pagination = true;
7214                    FinderPath finderPath = null;
7215                    Object[] finderArgs = null;
7216    
7217                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
7218                                    (orderByComparator == null)) {
7219                            pagination = false;
7220                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL;
7221                            finderArgs = FINDER_ARGS_EMPTY;
7222                    }
7223                    else {
7224                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_ALL;
7225                            finderArgs = new Object[] { start, end, orderByComparator };
7226                    }
7227    
7228                    List<DDMStructure> list = (List<DDMStructure>)FinderCacheUtil.getResult(finderPath,
7229                                    finderArgs, this);
7230    
7231                    if (list == null) {
7232                            StringBundler query = null;
7233                            String sql = null;
7234    
7235                            if (orderByComparator != null) {
7236                                    query = new StringBundler(2 +
7237                                                    (orderByComparator.getOrderByFields().length * 3));
7238    
7239                                    query.append(_SQL_SELECT_DDMSTRUCTURE);
7240    
7241                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
7242                                            orderByComparator);
7243    
7244                                    sql = query.toString();
7245                            }
7246                            else {
7247                                    sql = _SQL_SELECT_DDMSTRUCTURE;
7248    
7249                                    if (pagination) {
7250                                            sql = sql.concat(DDMStructureModelImpl.ORDER_BY_JPQL);
7251                                    }
7252                            }
7253    
7254                            Session session = null;
7255    
7256                            try {
7257                                    session = openSession();
7258    
7259                                    Query q = session.createQuery(sql);
7260    
7261                                    if (!pagination) {
7262                                            list = (List<DDMStructure>)QueryUtil.list(q, getDialect(),
7263                                                            start, end, false);
7264    
7265                                            Collections.sort(list);
7266    
7267                                            list = new UnmodifiableList<DDMStructure>(list);
7268                                    }
7269                                    else {
7270                                            list = (List<DDMStructure>)QueryUtil.list(q, getDialect(),
7271                                                            start, end);
7272                                    }
7273    
7274                                    cacheResult(list);
7275    
7276                                    FinderCacheUtil.putResult(finderPath, finderArgs, list);
7277                            }
7278                            catch (Exception e) {
7279                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
7280    
7281                                    throw processException(e);
7282                            }
7283                            finally {
7284                                    closeSession(session);
7285                            }
7286                    }
7287    
7288                    return list;
7289            }
7290    
7291            /**
7292             * Removes all the d d m structures from the database.
7293             *
7294             * @throws SystemException if a system exception occurred
7295             */
7296            public void removeAll() throws SystemException {
7297                    for (DDMStructure ddmStructure : findAll()) {
7298                            remove(ddmStructure);
7299                    }
7300            }
7301    
7302            /**
7303             * Returns the number of d d m structures.
7304             *
7305             * @return the number of d d m structures
7306             * @throws SystemException if a system exception occurred
7307             */
7308            public int countAll() throws SystemException {
7309                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_ALL,
7310                                    FINDER_ARGS_EMPTY, this);
7311    
7312                    if (count == null) {
7313                            Session session = null;
7314    
7315                            try {
7316                                    session = openSession();
7317    
7318                                    Query q = session.createQuery(_SQL_COUNT_DDMSTRUCTURE);
7319    
7320                                    count = (Long)q.uniqueResult();
7321    
7322                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_ALL,
7323                                            FINDER_ARGS_EMPTY, count);
7324                            }
7325                            catch (Exception e) {
7326                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_ALL,
7327                                            FINDER_ARGS_EMPTY);
7328    
7329                                    throw processException(e);
7330                            }
7331                            finally {
7332                                    closeSession(session);
7333                            }
7334                    }
7335    
7336                    return count.intValue();
7337            }
7338    
7339            /**
7340             * Initializes the d d m structure persistence.
7341             */
7342            public void afterPropertiesSet() {
7343                    String[] listenerClassNames = StringUtil.split(GetterUtil.getString(
7344                                            com.liferay.portal.util.PropsUtil.get(
7345                                                    "value.object.listener.com.liferay.portlet.dynamicdatamapping.model.DDMStructure")));
7346    
7347                    if (listenerClassNames.length > 0) {
7348                            try {
7349                                    List<ModelListener<DDMStructure>> listenersList = new ArrayList<ModelListener<DDMStructure>>();
7350    
7351                                    for (String listenerClassName : listenerClassNames) {
7352                                            listenersList.add((ModelListener<DDMStructure>)InstanceFactory.newInstance(
7353                                                            listenerClassName));
7354                                    }
7355    
7356                                    listeners = listenersList.toArray(new ModelListener[listenersList.size()]);
7357                            }
7358                            catch (Exception e) {
7359                                    _log.error(e);
7360                            }
7361                    }
7362            }
7363    
7364            public void destroy() {
7365                    EntityCacheUtil.removeCache(DDMStructureImpl.class.getName());
7366                    FinderCacheUtil.removeCache(FINDER_CLASS_NAME_ENTITY);
7367                    FinderCacheUtil.removeCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
7368                    FinderCacheUtil.removeCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
7369            }
7370    
7371            private static final String _SQL_SELECT_DDMSTRUCTURE = "SELECT ddmStructure FROM DDMStructure ddmStructure";
7372            private static final String _SQL_SELECT_DDMSTRUCTURE_WHERE = "SELECT ddmStructure FROM DDMStructure ddmStructure WHERE ";
7373            private static final String _SQL_COUNT_DDMSTRUCTURE = "SELECT COUNT(ddmStructure) FROM DDMStructure ddmStructure";
7374            private static final String _SQL_COUNT_DDMSTRUCTURE_WHERE = "SELECT COUNT(ddmStructure) FROM DDMStructure ddmStructure WHERE ";
7375            private static final String _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN = "ddmStructure.structureId";
7376            private static final String _FILTER_SQL_SELECT_DDMSTRUCTURE_WHERE = "SELECT DISTINCT {ddmStructure.*} FROM DDMStructure ddmStructure WHERE ";
7377            private static final String _FILTER_SQL_SELECT_DDMSTRUCTURE_NO_INLINE_DISTINCT_WHERE_1 =
7378                    "SELECT {DDMStructure.*} FROM (SELECT DISTINCT ddmStructure.structureId FROM DDMStructure ddmStructure WHERE ";
7379            private static final String _FILTER_SQL_SELECT_DDMSTRUCTURE_NO_INLINE_DISTINCT_WHERE_2 =
7380                    ") TEMP_TABLE INNER JOIN DDMStructure ON TEMP_TABLE.structureId = DDMStructure.structureId";
7381            private static final String _FILTER_SQL_COUNT_DDMSTRUCTURE_WHERE = "SELECT COUNT(DISTINCT ddmStructure.structureId) AS COUNT_VALUE FROM DDMStructure ddmStructure WHERE ";
7382            private static final String _FILTER_ENTITY_ALIAS = "ddmStructure";
7383            private static final String _FILTER_ENTITY_TABLE = "DDMStructure";
7384            private static final String _ORDER_BY_ENTITY_ALIAS = "ddmStructure.";
7385            private static final String _ORDER_BY_ENTITY_TABLE = "DDMStructure.";
7386            private static final String _NO_SUCH_ENTITY_WITH_PRIMARY_KEY = "No DDMStructure exists with the primary key ";
7387            private static final String _NO_SUCH_ENTITY_WITH_KEY = "No DDMStructure exists with the key {";
7388            private static final boolean _HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE = com.liferay.portal.util.PropsValues.HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE;
7389            private static Log _log = LogFactoryUtil.getLog(DDMStructurePersistenceImpl.class);
7390            private static DDMStructure _nullDDMStructure = new DDMStructureImpl() {
7391                            @Override
7392                            public Object clone() {
7393                                    return this;
7394                            }
7395    
7396                            @Override
7397                            public CacheModel<DDMStructure> toCacheModel() {
7398                                    return _nullDDMStructureCacheModel;
7399                            }
7400                    };
7401    
7402            private static CacheModel<DDMStructure> _nullDDMStructureCacheModel = new CacheModel<DDMStructure>() {
7403                            public DDMStructure toEntityModel() {
7404                                    return _nullDDMStructure;
7405                            }
7406                    };
7407    }