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