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.bean.BeanReference;
019    import com.liferay.portal.kernel.cache.CacheRegistryUtil;
020    import com.liferay.portal.kernel.dao.orm.EntityCacheUtil;
021    import com.liferay.portal.kernel.dao.orm.FinderCacheUtil;
022    import com.liferay.portal.kernel.dao.orm.FinderPath;
023    import com.liferay.portal.kernel.dao.orm.Query;
024    import com.liferay.portal.kernel.dao.orm.QueryPos;
025    import com.liferay.portal.kernel.dao.orm.QueryUtil;
026    import com.liferay.portal.kernel.dao.orm.SQLQuery;
027    import com.liferay.portal.kernel.dao.orm.Session;
028    import com.liferay.portal.kernel.exception.SystemException;
029    import com.liferay.portal.kernel.log.Log;
030    import com.liferay.portal.kernel.log.LogFactoryUtil;
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.Validator;
038    import com.liferay.portal.kernel.uuid.PortalUUIDUtil;
039    import com.liferay.portal.model.CacheModel;
040    import com.liferay.portal.model.ModelListener;
041    import com.liferay.portal.security.permission.InlineSQLHelperUtil;
042    import com.liferay.portal.service.persistence.BatchSessionUtil;
043    import com.liferay.portal.service.persistence.ResourcePersistence;
044    import com.liferay.portal.service.persistence.UserPersistence;
045    import com.liferay.portal.service.persistence.impl.BasePersistenceImpl;
046    
047    import com.liferay.portlet.documentlibrary.service.persistence.DLFileEntryTypePersistence;
048    import com.liferay.portlet.dynamicdatamapping.NoSuchStructureException;
049    import com.liferay.portlet.dynamicdatamapping.model.DDMStructure;
050    import com.liferay.portlet.dynamicdatamapping.model.impl.DDMStructureImpl;
051    import com.liferay.portlet.dynamicdatamapping.model.impl.DDMStructureModelImpl;
052    
053    import java.io.Serializable;
054    
055    import java.util.ArrayList;
056    import java.util.Collections;
057    import java.util.List;
058    
059    /**
060     * The persistence implementation for the d d m structure service.
061     *
062     * <p>
063     * Caching information and settings can be found in <code>portal.properties</code>
064     * </p>
065     *
066     * @author Brian Wing Shun Chan
067     * @see DDMStructurePersistence
068     * @see DDMStructureUtil
069     * @generated
070     */
071    public class DDMStructurePersistenceImpl extends BasePersistenceImpl<DDMStructure>
072            implements DDMStructurePersistence {
073            /*
074             * NOTE FOR DEVELOPERS:
075             *
076             * 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.
077             */
078            public static final String FINDER_CLASS_NAME_ENTITY = DDMStructureImpl.class.getName();
079            public static final String FINDER_CLASS_NAME_LIST_WITH_PAGINATION = FINDER_CLASS_NAME_ENTITY +
080                    ".List1";
081            public static final String FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION = FINDER_CLASS_NAME_ENTITY +
082                    ".List2";
083            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_UUID = new FinderPath(DDMStructureModelImpl.ENTITY_CACHE_ENABLED,
084                            DDMStructureModelImpl.FINDER_CACHE_ENABLED, DDMStructureImpl.class,
085                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByUuid",
086                            new String[] {
087                                    String.class.getName(),
088                                    
089                            "java.lang.Integer", "java.lang.Integer",
090                                    "com.liferay.portal.kernel.util.OrderByComparator"
091                            });
092            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID = new FinderPath(DDMStructureModelImpl.ENTITY_CACHE_ENABLED,
093                            DDMStructureModelImpl.FINDER_CACHE_ENABLED, DDMStructureImpl.class,
094                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByUuid",
095                            new String[] { String.class.getName() },
096                            DDMStructureModelImpl.UUID_COLUMN_BITMASK);
097            public static final FinderPath FINDER_PATH_COUNT_BY_UUID = new FinderPath(DDMStructureModelImpl.ENTITY_CACHE_ENABLED,
098                            DDMStructureModelImpl.FINDER_CACHE_ENABLED, Long.class,
099                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByUuid",
100                            new String[] { String.class.getName() });
101            public static final FinderPath FINDER_PATH_FETCH_BY_UUID_G = new FinderPath(DDMStructureModelImpl.ENTITY_CACHE_ENABLED,
102                            DDMStructureModelImpl.FINDER_CACHE_ENABLED, DDMStructureImpl.class,
103                            FINDER_CLASS_NAME_ENTITY, "fetchByUUID_G",
104                            new String[] { String.class.getName(), Long.class.getName() },
105                            DDMStructureModelImpl.UUID_COLUMN_BITMASK |
106                            DDMStructureModelImpl.GROUPID_COLUMN_BITMASK);
107            public static final FinderPath FINDER_PATH_COUNT_BY_UUID_G = new FinderPath(DDMStructureModelImpl.ENTITY_CACHE_ENABLED,
108                            DDMStructureModelImpl.FINDER_CACHE_ENABLED, Long.class,
109                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByUUID_G",
110                            new String[] { String.class.getName(), Long.class.getName() });
111            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_GROUPID = new FinderPath(DDMStructureModelImpl.ENTITY_CACHE_ENABLED,
112                            DDMStructureModelImpl.FINDER_CACHE_ENABLED, DDMStructureImpl.class,
113                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByGroupId",
114                            new String[] {
115                                    Long.class.getName(),
116                                    
117                            "java.lang.Integer", "java.lang.Integer",
118                                    "com.liferay.portal.kernel.util.OrderByComparator"
119                            });
120            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_GROUPID =
121                    new FinderPath(DDMStructureModelImpl.ENTITY_CACHE_ENABLED,
122                            DDMStructureModelImpl.FINDER_CACHE_ENABLED, DDMStructureImpl.class,
123                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByGroupId",
124                            new String[] { Long.class.getName() },
125                            DDMStructureModelImpl.GROUPID_COLUMN_BITMASK);
126            public static final FinderPath FINDER_PATH_COUNT_BY_GROUPID = new FinderPath(DDMStructureModelImpl.ENTITY_CACHE_ENABLED,
127                            DDMStructureModelImpl.FINDER_CACHE_ENABLED, Long.class,
128                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByGroupId",
129                            new String[] { Long.class.getName() });
130            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_CLASSNAMEID =
131                    new FinderPath(DDMStructureModelImpl.ENTITY_CACHE_ENABLED,
132                            DDMStructureModelImpl.FINDER_CACHE_ENABLED, DDMStructureImpl.class,
133                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByClassNameId",
134                            new String[] {
135                                    Long.class.getName(),
136                                    
137                            "java.lang.Integer", "java.lang.Integer",
138                                    "com.liferay.portal.kernel.util.OrderByComparator"
139                            });
140            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_CLASSNAMEID =
141                    new FinderPath(DDMStructureModelImpl.ENTITY_CACHE_ENABLED,
142                            DDMStructureModelImpl.FINDER_CACHE_ENABLED, DDMStructureImpl.class,
143                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByClassNameId",
144                            new String[] { Long.class.getName() },
145                            DDMStructureModelImpl.CLASSNAMEID_COLUMN_BITMASK);
146            public static final FinderPath FINDER_PATH_COUNT_BY_CLASSNAMEID = new FinderPath(DDMStructureModelImpl.ENTITY_CACHE_ENABLED,
147                            DDMStructureModelImpl.FINDER_CACHE_ENABLED, Long.class,
148                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByClassNameId",
149                            new String[] { Long.class.getName() });
150            public static final FinderPath FINDER_PATH_FETCH_BY_G_S = new FinderPath(DDMStructureModelImpl.ENTITY_CACHE_ENABLED,
151                            DDMStructureModelImpl.FINDER_CACHE_ENABLED, DDMStructureImpl.class,
152                            FINDER_CLASS_NAME_ENTITY, "fetchByG_S",
153                            new String[] { Long.class.getName(), String.class.getName() },
154                            DDMStructureModelImpl.GROUPID_COLUMN_BITMASK |
155                            DDMStructureModelImpl.STRUCTUREKEY_COLUMN_BITMASK);
156            public static final FinderPath FINDER_PATH_COUNT_BY_G_S = new FinderPath(DDMStructureModelImpl.ENTITY_CACHE_ENABLED,
157                            DDMStructureModelImpl.FINDER_CACHE_ENABLED, Long.class,
158                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByG_S",
159                            new String[] { Long.class.getName(), String.class.getName() });
160            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_G_N_D = new FinderPath(DDMStructureModelImpl.ENTITY_CACHE_ENABLED,
161                            DDMStructureModelImpl.FINDER_CACHE_ENABLED, DDMStructureImpl.class,
162                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByG_N_D",
163                            new String[] {
164                                    Long.class.getName(), String.class.getName(),
165                                    String.class.getName(),
166                                    
167                            "java.lang.Integer", "java.lang.Integer",
168                                    "com.liferay.portal.kernel.util.OrderByComparator"
169                            });
170            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_N_D = new FinderPath(DDMStructureModelImpl.ENTITY_CACHE_ENABLED,
171                            DDMStructureModelImpl.FINDER_CACHE_ENABLED, DDMStructureImpl.class,
172                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByG_N_D",
173                            new String[] {
174                                    Long.class.getName(), String.class.getName(),
175                                    String.class.getName()
176                            },
177                            DDMStructureModelImpl.GROUPID_COLUMN_BITMASK |
178                            DDMStructureModelImpl.NAME_COLUMN_BITMASK |
179                            DDMStructureModelImpl.DESCRIPTION_COLUMN_BITMASK);
180            public static final FinderPath FINDER_PATH_COUNT_BY_G_N_D = new FinderPath(DDMStructureModelImpl.ENTITY_CACHE_ENABLED,
181                            DDMStructureModelImpl.FINDER_CACHE_ENABLED, Long.class,
182                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByG_N_D",
183                            new String[] {
184                                    Long.class.getName(), String.class.getName(),
185                                    String.class.getName()
186                            });
187            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_ALL = new FinderPath(DDMStructureModelImpl.ENTITY_CACHE_ENABLED,
188                            DDMStructureModelImpl.FINDER_CACHE_ENABLED, DDMStructureImpl.class,
189                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findAll", new String[0]);
190            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL = new FinderPath(DDMStructureModelImpl.ENTITY_CACHE_ENABLED,
191                            DDMStructureModelImpl.FINDER_CACHE_ENABLED, DDMStructureImpl.class,
192                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findAll", new String[0]);
193            public static final FinderPath FINDER_PATH_COUNT_ALL = new FinderPath(DDMStructureModelImpl.ENTITY_CACHE_ENABLED,
194                            DDMStructureModelImpl.FINDER_CACHE_ENABLED, Long.class,
195                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countAll", new String[0]);
196    
197            /**
198             * Caches the d d m structure in the entity cache if it is enabled.
199             *
200             * @param ddmStructure the d d m structure
201             */
202            public void cacheResult(DDMStructure ddmStructure) {
203                    EntityCacheUtil.putResult(DDMStructureModelImpl.ENTITY_CACHE_ENABLED,
204                            DDMStructureImpl.class, ddmStructure.getPrimaryKey(), ddmStructure);
205    
206                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_UUID_G,
207                            new Object[] {
208                                    ddmStructure.getUuid(), Long.valueOf(ddmStructure.getGroupId())
209                            }, ddmStructure);
210    
211                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_G_S,
212                            new Object[] {
213                                    Long.valueOf(ddmStructure.getGroupId()),
214                                    
215                            ddmStructure.getStructureKey()
216                            }, ddmStructure);
217    
218                    ddmStructure.resetOriginalValues();
219            }
220    
221            /**
222             * Caches the d d m structures in the entity cache if it is enabled.
223             *
224             * @param ddmStructures the d d m structures
225             */
226            public void cacheResult(List<DDMStructure> ddmStructures) {
227                    for (DDMStructure ddmStructure : ddmStructures) {
228                            if (EntityCacheUtil.getResult(
229                                                    DDMStructureModelImpl.ENTITY_CACHE_ENABLED,
230                                                    DDMStructureImpl.class, ddmStructure.getPrimaryKey()) == null) {
231                                    cacheResult(ddmStructure);
232                            }
233                            else {
234                                    ddmStructure.resetOriginalValues();
235                            }
236                    }
237            }
238    
239            /**
240             * Clears the cache for all d d m structures.
241             *
242             * <p>
243             * The {@link com.liferay.portal.kernel.dao.orm.EntityCache} and {@link com.liferay.portal.kernel.dao.orm.FinderCache} are both cleared by this method.
244             * </p>
245             */
246            @Override
247            public void clearCache() {
248                    if (_HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE) {
249                            CacheRegistryUtil.clear(DDMStructureImpl.class.getName());
250                    }
251    
252                    EntityCacheUtil.clearCache(DDMStructureImpl.class.getName());
253    
254                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_ENTITY);
255                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
256                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
257            }
258    
259            /**
260             * Clears the cache for the d d m structure.
261             *
262             * <p>
263             * The {@link com.liferay.portal.kernel.dao.orm.EntityCache} and {@link com.liferay.portal.kernel.dao.orm.FinderCache} are both cleared by this method.
264             * </p>
265             */
266            @Override
267            public void clearCache(DDMStructure ddmStructure) {
268                    EntityCacheUtil.removeResult(DDMStructureModelImpl.ENTITY_CACHE_ENABLED,
269                            DDMStructureImpl.class, ddmStructure.getPrimaryKey());
270    
271                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
272                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
273    
274                    clearUniqueFindersCache(ddmStructure);
275            }
276    
277            @Override
278            public void clearCache(List<DDMStructure> ddmStructures) {
279                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
280                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
281    
282                    for (DDMStructure ddmStructure : ddmStructures) {
283                            EntityCacheUtil.removeResult(DDMStructureModelImpl.ENTITY_CACHE_ENABLED,
284                                    DDMStructureImpl.class, ddmStructure.getPrimaryKey());
285    
286                            clearUniqueFindersCache(ddmStructure);
287                    }
288            }
289    
290            protected void clearUniqueFindersCache(DDMStructure ddmStructure) {
291                    FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_UUID_G,
292                            new Object[] {
293                                    ddmStructure.getUuid(), Long.valueOf(ddmStructure.getGroupId())
294                            });
295    
296                    FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_G_S,
297                            new Object[] {
298                                    Long.valueOf(ddmStructure.getGroupId()),
299                                    
300                            ddmStructure.getStructureKey()
301                            });
302            }
303    
304            /**
305             * Creates a new d d m structure with the primary key. Does not add the d d m structure to the database.
306             *
307             * @param structureId the primary key for the new d d m structure
308             * @return the new d d m structure
309             */
310            public DDMStructure create(long structureId) {
311                    DDMStructure ddmStructure = new DDMStructureImpl();
312    
313                    ddmStructure.setNew(true);
314                    ddmStructure.setPrimaryKey(structureId);
315    
316                    String uuid = PortalUUIDUtil.generate();
317    
318                    ddmStructure.setUuid(uuid);
319    
320                    return ddmStructure;
321            }
322    
323            /**
324             * Removes the d d m structure with the primary key from the database. Also notifies the appropriate model listeners.
325             *
326             * @param structureId the primary key of the d d m structure
327             * @return the d d m structure that was removed
328             * @throws com.liferay.portlet.dynamicdatamapping.NoSuchStructureException if a d d m structure with the primary key could not be found
329             * @throws SystemException if a system exception occurred
330             */
331            public DDMStructure remove(long structureId)
332                    throws NoSuchStructureException, SystemException {
333                    return remove(Long.valueOf(structureId));
334            }
335    
336            /**
337             * Removes the d d m structure with the primary key from the database. Also notifies the appropriate model listeners.
338             *
339             * @param primaryKey the primary key of the d d m structure
340             * @return the d d m structure that was removed
341             * @throws com.liferay.portlet.dynamicdatamapping.NoSuchStructureException if a d d m structure with the primary key could not be found
342             * @throws SystemException if a system exception occurred
343             */
344            @Override
345            public DDMStructure remove(Serializable primaryKey)
346                    throws NoSuchStructureException, SystemException {
347                    Session session = null;
348    
349                    try {
350                            session = openSession();
351    
352                            DDMStructure ddmStructure = (DDMStructure)session.get(DDMStructureImpl.class,
353                                            primaryKey);
354    
355                            if (ddmStructure == null) {
356                                    if (_log.isWarnEnabled()) {
357                                            _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + primaryKey);
358                                    }
359    
360                                    throw new NoSuchStructureException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
361                                            primaryKey);
362                            }
363    
364                            return remove(ddmStructure);
365                    }
366                    catch (NoSuchStructureException nsee) {
367                            throw nsee;
368                    }
369                    catch (Exception e) {
370                            throw processException(e);
371                    }
372                    finally {
373                            closeSession(session);
374                    }
375            }
376    
377            @Override
378            protected DDMStructure removeImpl(DDMStructure ddmStructure)
379                    throws SystemException {
380                    ddmStructure = toUnwrappedModel(ddmStructure);
381    
382                    Session session = null;
383    
384                    try {
385                            session = openSession();
386    
387                            BatchSessionUtil.delete(session, ddmStructure);
388                    }
389                    catch (Exception e) {
390                            throw processException(e);
391                    }
392                    finally {
393                            closeSession(session);
394                    }
395    
396                    clearCache(ddmStructure);
397    
398                    return ddmStructure;
399            }
400    
401            @Override
402            public DDMStructure updateImpl(
403                    com.liferay.portlet.dynamicdatamapping.model.DDMStructure ddmStructure,
404                    boolean merge) throws SystemException {
405                    ddmStructure = toUnwrappedModel(ddmStructure);
406    
407                    boolean isNew = ddmStructure.isNew();
408    
409                    DDMStructureModelImpl ddmStructureModelImpl = (DDMStructureModelImpl)ddmStructure;
410    
411                    if (Validator.isNull(ddmStructure.getUuid())) {
412                            String uuid = PortalUUIDUtil.generate();
413    
414                            ddmStructure.setUuid(uuid);
415                    }
416    
417                    Session session = null;
418    
419                    try {
420                            session = openSession();
421    
422                            BatchSessionUtil.update(session, ddmStructure, merge);
423    
424                            ddmStructure.setNew(false);
425                    }
426                    catch (Exception e) {
427                            throw processException(e);
428                    }
429                    finally {
430                            closeSession(session);
431                    }
432    
433                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
434    
435                    if (isNew || !DDMStructureModelImpl.COLUMN_BITMASK_ENABLED) {
436                            FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
437                    }
438                    else {
439                            if ((ddmStructureModelImpl.getColumnBitmask() &
440                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID.getColumnBitmask()) != 0) {
441                                    Object[] args = new Object[] {
442                                                    ddmStructureModelImpl.getOriginalUuid()
443                                            };
444    
445                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_UUID, args);
446                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID,
447                                            args);
448    
449                                    args = new Object[] { ddmStructureModelImpl.getUuid() };
450    
451                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_UUID, args);
452                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID,
453                                            args);
454                            }
455    
456                            if ((ddmStructureModelImpl.getColumnBitmask() &
457                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_GROUPID.getColumnBitmask()) != 0) {
458                                    Object[] args = new Object[] {
459                                                    Long.valueOf(ddmStructureModelImpl.getOriginalGroupId())
460                                            };
461    
462                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_GROUPID, args);
463                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_GROUPID,
464                                            args);
465    
466                                    args = new Object[] {
467                                                    Long.valueOf(ddmStructureModelImpl.getGroupId())
468                                            };
469    
470                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_GROUPID, args);
471                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_GROUPID,
472                                            args);
473                            }
474    
475                            if ((ddmStructureModelImpl.getColumnBitmask() &
476                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_CLASSNAMEID.getColumnBitmask()) != 0) {
477                                    Object[] args = new Object[] {
478                                                    Long.valueOf(ddmStructureModelImpl.getOriginalClassNameId())
479                                            };
480    
481                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_CLASSNAMEID,
482                                            args);
483                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_CLASSNAMEID,
484                                            args);
485    
486                                    args = new Object[] {
487                                                    Long.valueOf(ddmStructureModelImpl.getClassNameId())
488                                            };
489    
490                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_CLASSNAMEID,
491                                            args);
492                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_CLASSNAMEID,
493                                            args);
494                            }
495    
496                            if ((ddmStructureModelImpl.getColumnBitmask() &
497                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_N_D.getColumnBitmask()) != 0) {
498                                    Object[] args = new Object[] {
499                                                    Long.valueOf(ddmStructureModelImpl.getOriginalGroupId()),
500                                                    
501                                                    ddmStructureModelImpl.getOriginalName(),
502                                                    
503                                                    ddmStructureModelImpl.getOriginalDescription()
504                                            };
505    
506                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_G_N_D, args);
507                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_N_D,
508                                            args);
509    
510                                    args = new Object[] {
511                                                    Long.valueOf(ddmStructureModelImpl.getGroupId()),
512                                                    
513                                                    ddmStructureModelImpl.getName(),
514                                                    
515                                                    ddmStructureModelImpl.getDescription()
516                                            };
517    
518                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_G_N_D, args);
519                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_N_D,
520                                            args);
521                            }
522                    }
523    
524                    EntityCacheUtil.putResult(DDMStructureModelImpl.ENTITY_CACHE_ENABLED,
525                            DDMStructureImpl.class, ddmStructure.getPrimaryKey(), ddmStructure);
526    
527                    if (isNew) {
528                            FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_UUID_G,
529                                    new Object[] {
530                                            ddmStructure.getUuid(),
531                                            Long.valueOf(ddmStructure.getGroupId())
532                                    }, ddmStructure);
533    
534                            FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_G_S,
535                                    new Object[] {
536                                            Long.valueOf(ddmStructure.getGroupId()),
537                                            
538                                    ddmStructure.getStructureKey()
539                                    }, ddmStructure);
540                    }
541                    else {
542                            if ((ddmStructureModelImpl.getColumnBitmask() &
543                                            FINDER_PATH_FETCH_BY_UUID_G.getColumnBitmask()) != 0) {
544                                    Object[] args = new Object[] {
545                                                    ddmStructureModelImpl.getOriginalUuid(),
546                                                    Long.valueOf(ddmStructureModelImpl.getOriginalGroupId())
547                                            };
548    
549                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_UUID_G, args);
550                                    FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_UUID_G, args);
551    
552                                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_UUID_G,
553                                            new Object[] {
554                                                    ddmStructure.getUuid(),
555                                                    Long.valueOf(ddmStructure.getGroupId())
556                                            }, ddmStructure);
557                            }
558    
559                            if ((ddmStructureModelImpl.getColumnBitmask() &
560                                            FINDER_PATH_FETCH_BY_G_S.getColumnBitmask()) != 0) {
561                                    Object[] args = new Object[] {
562                                                    Long.valueOf(ddmStructureModelImpl.getOriginalGroupId()),
563                                                    
564                                                    ddmStructureModelImpl.getOriginalStructureKey()
565                                            };
566    
567                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_G_S, args);
568                                    FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_G_S, args);
569    
570                                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_G_S,
571                                            new Object[] {
572                                                    Long.valueOf(ddmStructure.getGroupId()),
573                                                    
574                                            ddmStructure.getStructureKey()
575                                            }, ddmStructure);
576                            }
577                    }
578    
579                    return ddmStructure;
580            }
581    
582            protected DDMStructure toUnwrappedModel(DDMStructure ddmStructure) {
583                    if (ddmStructure instanceof DDMStructureImpl) {
584                            return ddmStructure;
585                    }
586    
587                    DDMStructureImpl ddmStructureImpl = new DDMStructureImpl();
588    
589                    ddmStructureImpl.setNew(ddmStructure.isNew());
590                    ddmStructureImpl.setPrimaryKey(ddmStructure.getPrimaryKey());
591    
592                    ddmStructureImpl.setUuid(ddmStructure.getUuid());
593                    ddmStructureImpl.setStructureId(ddmStructure.getStructureId());
594                    ddmStructureImpl.setGroupId(ddmStructure.getGroupId());
595                    ddmStructureImpl.setCompanyId(ddmStructure.getCompanyId());
596                    ddmStructureImpl.setUserId(ddmStructure.getUserId());
597                    ddmStructureImpl.setUserName(ddmStructure.getUserName());
598                    ddmStructureImpl.setCreateDate(ddmStructure.getCreateDate());
599                    ddmStructureImpl.setModifiedDate(ddmStructure.getModifiedDate());
600                    ddmStructureImpl.setClassNameId(ddmStructure.getClassNameId());
601                    ddmStructureImpl.setStructureKey(ddmStructure.getStructureKey());
602                    ddmStructureImpl.setName(ddmStructure.getName());
603                    ddmStructureImpl.setDescription(ddmStructure.getDescription());
604                    ddmStructureImpl.setXsd(ddmStructure.getXsd());
605                    ddmStructureImpl.setStorageType(ddmStructure.getStorageType());
606                    ddmStructureImpl.setType(ddmStructure.getType());
607    
608                    return ddmStructureImpl;
609            }
610    
611            /**
612             * Returns the d d m structure with the primary key or throws a {@link com.liferay.portal.NoSuchModelException} if it could not be found.
613             *
614             * @param primaryKey the primary key of the d d m structure
615             * @return the d d m structure
616             * @throws com.liferay.portal.NoSuchModelException if a d d m structure with the primary key could not be found
617             * @throws SystemException if a system exception occurred
618             */
619            @Override
620            public DDMStructure findByPrimaryKey(Serializable primaryKey)
621                    throws NoSuchModelException, SystemException {
622                    return findByPrimaryKey(((Long)primaryKey).longValue());
623            }
624    
625            /**
626             * 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.
627             *
628             * @param structureId the primary key of the d d m structure
629             * @return the d d m structure
630             * @throws com.liferay.portlet.dynamicdatamapping.NoSuchStructureException if a d d m structure with the primary key could not be found
631             * @throws SystemException if a system exception occurred
632             */
633            public DDMStructure findByPrimaryKey(long structureId)
634                    throws NoSuchStructureException, SystemException {
635                    DDMStructure ddmStructure = fetchByPrimaryKey(structureId);
636    
637                    if (ddmStructure == null) {
638                            if (_log.isWarnEnabled()) {
639                                    _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + structureId);
640                            }
641    
642                            throw new NoSuchStructureException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
643                                    structureId);
644                    }
645    
646                    return ddmStructure;
647            }
648    
649            /**
650             * Returns the d d m structure with the primary key or returns <code>null</code> if it could not be found.
651             *
652             * @param primaryKey the primary key of the d d m structure
653             * @return the d d m structure, or <code>null</code> if a d d m structure with the primary key could not be found
654             * @throws SystemException if a system exception occurred
655             */
656            @Override
657            public DDMStructure fetchByPrimaryKey(Serializable primaryKey)
658                    throws SystemException {
659                    return fetchByPrimaryKey(((Long)primaryKey).longValue());
660            }
661    
662            /**
663             * Returns the d d m structure with the primary key or returns <code>null</code> if it could not be found.
664             *
665             * @param structureId the primary key of the d d m structure
666             * @return the d d m structure, or <code>null</code> if a d d m structure with the primary key could not be found
667             * @throws SystemException if a system exception occurred
668             */
669            public DDMStructure fetchByPrimaryKey(long structureId)
670                    throws SystemException {
671                    DDMStructure ddmStructure = (DDMStructure)EntityCacheUtil.getResult(DDMStructureModelImpl.ENTITY_CACHE_ENABLED,
672                                    DDMStructureImpl.class, structureId);
673    
674                    if (ddmStructure == _nullDDMStructure) {
675                            return null;
676                    }
677    
678                    if (ddmStructure == null) {
679                            Session session = null;
680    
681                            boolean hasException = false;
682    
683                            try {
684                                    session = openSession();
685    
686                                    ddmStructure = (DDMStructure)session.get(DDMStructureImpl.class,
687                                                    Long.valueOf(structureId));
688                            }
689                            catch (Exception e) {
690                                    hasException = true;
691    
692                                    throw processException(e);
693                            }
694                            finally {
695                                    if (ddmStructure != null) {
696                                            cacheResult(ddmStructure);
697                                    }
698                                    else if (!hasException) {
699                                            EntityCacheUtil.putResult(DDMStructureModelImpl.ENTITY_CACHE_ENABLED,
700                                                    DDMStructureImpl.class, structureId, _nullDDMStructure);
701                                    }
702    
703                                    closeSession(session);
704                            }
705                    }
706    
707                    return ddmStructure;
708            }
709    
710            /**
711             * Returns all the d d m structures where uuid = &#63;.
712             *
713             * @param uuid the uuid
714             * @return the matching d d m structures
715             * @throws SystemException if a system exception occurred
716             */
717            public List<DDMStructure> findByUuid(String uuid) throws SystemException {
718                    return findByUuid(uuid, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
719            }
720    
721            /**
722             * Returns a range of all the d d m structures where uuid = &#63;.
723             *
724             * <p>
725             * 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.
726             * </p>
727             *
728             * @param uuid the uuid
729             * @param start the lower bound of the range of d d m structures
730             * @param end the upper bound of the range of d d m structures (not inclusive)
731             * @return the range of matching d d m structures
732             * @throws SystemException if a system exception occurred
733             */
734            public List<DDMStructure> findByUuid(String uuid, int start, int end)
735                    throws SystemException {
736                    return findByUuid(uuid, start, end, null);
737            }
738    
739            /**
740             * Returns an ordered range of all the d d m structures where uuid = &#63;.
741             *
742             * <p>
743             * 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.
744             * </p>
745             *
746             * @param uuid the uuid
747             * @param start the lower bound of the range of d d m structures
748             * @param end the upper bound of the range of d d m structures (not inclusive)
749             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
750             * @return the ordered range of matching d d m structures
751             * @throws SystemException if a system exception occurred
752             */
753            public List<DDMStructure> findByUuid(String uuid, int start, int end,
754                    OrderByComparator orderByComparator) throws SystemException {
755                    FinderPath finderPath = null;
756                    Object[] finderArgs = null;
757    
758                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
759                                    (orderByComparator == null)) {
760                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID;
761                            finderArgs = new Object[] { uuid };
762                    }
763                    else {
764                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_UUID;
765                            finderArgs = new Object[] { uuid, start, end, orderByComparator };
766                    }
767    
768                    List<DDMStructure> list = (List<DDMStructure>)FinderCacheUtil.getResult(finderPath,
769                                    finderArgs, this);
770    
771                    if ((list != null) && !list.isEmpty()) {
772                            for (DDMStructure ddmStructure : list) {
773                                    if (!Validator.equals(uuid, ddmStructure.getUuid())) {
774                                            list = null;
775    
776                                            break;
777                                    }
778                            }
779                    }
780    
781                    if (list == null) {
782                            StringBundler query = null;
783    
784                            if (orderByComparator != null) {
785                                    query = new StringBundler(3 +
786                                                    (orderByComparator.getOrderByFields().length * 3));
787                            }
788                            else {
789                                    query = new StringBundler(2);
790                            }
791    
792                            query.append(_SQL_SELECT_DDMSTRUCTURE_WHERE);
793    
794                            if (uuid == null) {
795                                    query.append(_FINDER_COLUMN_UUID_UUID_1);
796                            }
797                            else {
798                                    if (uuid.equals(StringPool.BLANK)) {
799                                            query.append(_FINDER_COLUMN_UUID_UUID_3);
800                                    }
801                                    else {
802                                            query.append(_FINDER_COLUMN_UUID_UUID_2);
803                                    }
804                            }
805    
806                            if (orderByComparator != null) {
807                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
808                                            orderByComparator);
809                            }
810    
811                            String sql = query.toString();
812    
813                            Session session = null;
814    
815                            try {
816                                    session = openSession();
817    
818                                    Query q = session.createQuery(sql);
819    
820                                    QueryPos qPos = QueryPos.getInstance(q);
821    
822                                    if (uuid != null) {
823                                            qPos.add(uuid);
824                                    }
825    
826                                    list = (List<DDMStructure>)QueryUtil.list(q, getDialect(),
827                                                    start, end);
828                            }
829                            catch (Exception e) {
830                                    throw processException(e);
831                            }
832                            finally {
833                                    if (list == null) {
834                                            FinderCacheUtil.removeResult(finderPath, finderArgs);
835                                    }
836                                    else {
837                                            cacheResult(list);
838    
839                                            FinderCacheUtil.putResult(finderPath, finderArgs, list);
840                                    }
841    
842                                    closeSession(session);
843                            }
844                    }
845    
846                    return list;
847            }
848    
849            /**
850             * Returns the first d d m structure in the ordered set where uuid = &#63;.
851             *
852             * <p>
853             * 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.
854             * </p>
855             *
856             * @param uuid the uuid
857             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
858             * @return the first matching d d m structure
859             * @throws com.liferay.portlet.dynamicdatamapping.NoSuchStructureException if a matching d d m structure could not be found
860             * @throws SystemException if a system exception occurred
861             */
862            public DDMStructure findByUuid_First(String uuid,
863                    OrderByComparator orderByComparator)
864                    throws NoSuchStructureException, SystemException {
865                    List<DDMStructure> list = findByUuid(uuid, 0, 1, orderByComparator);
866    
867                    if (list.isEmpty()) {
868                            StringBundler msg = new StringBundler(4);
869    
870                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
871    
872                            msg.append("uuid=");
873                            msg.append(uuid);
874    
875                            msg.append(StringPool.CLOSE_CURLY_BRACE);
876    
877                            throw new NoSuchStructureException(msg.toString());
878                    }
879                    else {
880                            return list.get(0);
881                    }
882            }
883    
884            /**
885             * Returns the last d d m structure in the ordered set where uuid = &#63;.
886             *
887             * <p>
888             * 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.
889             * </p>
890             *
891             * @param uuid the uuid
892             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
893             * @return the last matching d d m structure
894             * @throws com.liferay.portlet.dynamicdatamapping.NoSuchStructureException if a matching d d m structure could not be found
895             * @throws SystemException if a system exception occurred
896             */
897            public DDMStructure findByUuid_Last(String uuid,
898                    OrderByComparator orderByComparator)
899                    throws NoSuchStructureException, SystemException {
900                    int count = countByUuid(uuid);
901    
902                    List<DDMStructure> list = findByUuid(uuid, count - 1, count,
903                                    orderByComparator);
904    
905                    if (list.isEmpty()) {
906                            StringBundler msg = new StringBundler(4);
907    
908                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
909    
910                            msg.append("uuid=");
911                            msg.append(uuid);
912    
913                            msg.append(StringPool.CLOSE_CURLY_BRACE);
914    
915                            throw new NoSuchStructureException(msg.toString());
916                    }
917                    else {
918                            return list.get(0);
919                    }
920            }
921    
922            /**
923             * Returns the d d m structures before and after the current d d m structure in the ordered set where uuid = &#63;.
924             *
925             * <p>
926             * 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.
927             * </p>
928             *
929             * @param structureId the primary key of the current d d m structure
930             * @param uuid the uuid
931             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
932             * @return the previous, current, and next d d m structure
933             * @throws com.liferay.portlet.dynamicdatamapping.NoSuchStructureException if a d d m structure with the primary key could not be found
934             * @throws SystemException if a system exception occurred
935             */
936            public DDMStructure[] findByUuid_PrevAndNext(long structureId, String uuid,
937                    OrderByComparator orderByComparator)
938                    throws NoSuchStructureException, SystemException {
939                    DDMStructure ddmStructure = findByPrimaryKey(structureId);
940    
941                    Session session = null;
942    
943                    try {
944                            session = openSession();
945    
946                            DDMStructure[] array = new DDMStructureImpl[3];
947    
948                            array[0] = getByUuid_PrevAndNext(session, ddmStructure, uuid,
949                                            orderByComparator, true);
950    
951                            array[1] = ddmStructure;
952    
953                            array[2] = getByUuid_PrevAndNext(session, ddmStructure, uuid,
954                                            orderByComparator, false);
955    
956                            return array;
957                    }
958                    catch (Exception e) {
959                            throw processException(e);
960                    }
961                    finally {
962                            closeSession(session);
963                    }
964            }
965    
966            protected DDMStructure getByUuid_PrevAndNext(Session session,
967                    DDMStructure ddmStructure, String uuid,
968                    OrderByComparator orderByComparator, boolean previous) {
969                    StringBundler query = null;
970    
971                    if (orderByComparator != null) {
972                            query = new StringBundler(6 +
973                                            (orderByComparator.getOrderByFields().length * 6));
974                    }
975                    else {
976                            query = new StringBundler(3);
977                    }
978    
979                    query.append(_SQL_SELECT_DDMSTRUCTURE_WHERE);
980    
981                    if (uuid == null) {
982                            query.append(_FINDER_COLUMN_UUID_UUID_1);
983                    }
984                    else {
985                            if (uuid.equals(StringPool.BLANK)) {
986                                    query.append(_FINDER_COLUMN_UUID_UUID_3);
987                            }
988                            else {
989                                    query.append(_FINDER_COLUMN_UUID_UUID_2);
990                            }
991                    }
992    
993                    if (orderByComparator != null) {
994                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
995    
996                            if (orderByConditionFields.length > 0) {
997                                    query.append(WHERE_AND);
998                            }
999    
1000                            for (int i = 0; i < orderByConditionFields.length; i++) {
1001                                    query.append(_ORDER_BY_ENTITY_ALIAS);
1002                                    query.append(orderByConditionFields[i]);
1003    
1004                                    if ((i + 1) < orderByConditionFields.length) {
1005                                            if (orderByComparator.isAscending() ^ previous) {
1006                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
1007                                            }
1008                                            else {
1009                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
1010                                            }
1011                                    }
1012                                    else {
1013                                            if (orderByComparator.isAscending() ^ previous) {
1014                                                    query.append(WHERE_GREATER_THAN);
1015                                            }
1016                                            else {
1017                                                    query.append(WHERE_LESSER_THAN);
1018                                            }
1019                                    }
1020                            }
1021    
1022                            query.append(ORDER_BY_CLAUSE);
1023    
1024                            String[] orderByFields = orderByComparator.getOrderByFields();
1025    
1026                            for (int i = 0; i < orderByFields.length; i++) {
1027                                    query.append(_ORDER_BY_ENTITY_ALIAS);
1028                                    query.append(orderByFields[i]);
1029    
1030                                    if ((i + 1) < orderByFields.length) {
1031                                            if (orderByComparator.isAscending() ^ previous) {
1032                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
1033                                            }
1034                                            else {
1035                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
1036                                            }
1037                                    }
1038                                    else {
1039                                            if (orderByComparator.isAscending() ^ previous) {
1040                                                    query.append(ORDER_BY_ASC);
1041                                            }
1042                                            else {
1043                                                    query.append(ORDER_BY_DESC);
1044                                            }
1045                                    }
1046                            }
1047                    }
1048    
1049                    String sql = query.toString();
1050    
1051                    Query q = session.createQuery(sql);
1052    
1053                    q.setFirstResult(0);
1054                    q.setMaxResults(2);
1055    
1056                    QueryPos qPos = QueryPos.getInstance(q);
1057    
1058                    if (uuid != null) {
1059                            qPos.add(uuid);
1060                    }
1061    
1062                    if (orderByComparator != null) {
1063                            Object[] values = orderByComparator.getOrderByConditionValues(ddmStructure);
1064    
1065                            for (Object value : values) {
1066                                    qPos.add(value);
1067                            }
1068                    }
1069    
1070                    List<DDMStructure> list = q.list();
1071    
1072                    if (list.size() == 2) {
1073                            return list.get(1);
1074                    }
1075                    else {
1076                            return null;
1077                    }
1078            }
1079    
1080            /**
1081             * 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.
1082             *
1083             * @param uuid the uuid
1084             * @param groupId the group ID
1085             * @return the matching d d m structure
1086             * @throws com.liferay.portlet.dynamicdatamapping.NoSuchStructureException if a matching d d m structure could not be found
1087             * @throws SystemException if a system exception occurred
1088             */
1089            public DDMStructure findByUUID_G(String uuid, long groupId)
1090                    throws NoSuchStructureException, SystemException {
1091                    DDMStructure ddmStructure = fetchByUUID_G(uuid, groupId);
1092    
1093                    if (ddmStructure == null) {
1094                            StringBundler msg = new StringBundler(6);
1095    
1096                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1097    
1098                            msg.append("uuid=");
1099                            msg.append(uuid);
1100    
1101                            msg.append(", groupId=");
1102                            msg.append(groupId);
1103    
1104                            msg.append(StringPool.CLOSE_CURLY_BRACE);
1105    
1106                            if (_log.isWarnEnabled()) {
1107                                    _log.warn(msg.toString());
1108                            }
1109    
1110                            throw new NoSuchStructureException(msg.toString());
1111                    }
1112    
1113                    return ddmStructure;
1114            }
1115    
1116            /**
1117             * 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.
1118             *
1119             * @param uuid the uuid
1120             * @param groupId the group ID
1121             * @return the matching d d m structure, or <code>null</code> if a matching d d m structure could not be found
1122             * @throws SystemException if a system exception occurred
1123             */
1124            public DDMStructure fetchByUUID_G(String uuid, long groupId)
1125                    throws SystemException {
1126                    return fetchByUUID_G(uuid, groupId, true);
1127            }
1128    
1129            /**
1130             * 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.
1131             *
1132             * @param uuid the uuid
1133             * @param groupId the group ID
1134             * @param retrieveFromCache whether to use the finder cache
1135             * @return the matching d d m structure, or <code>null</code> if a matching d d m structure could not be found
1136             * @throws SystemException if a system exception occurred
1137             */
1138            public DDMStructure fetchByUUID_G(String uuid, long groupId,
1139                    boolean retrieveFromCache) throws SystemException {
1140                    Object[] finderArgs = new Object[] { uuid, groupId };
1141    
1142                    Object result = null;
1143    
1144                    if (retrieveFromCache) {
1145                            result = FinderCacheUtil.getResult(FINDER_PATH_FETCH_BY_UUID_G,
1146                                            finderArgs, this);
1147                    }
1148    
1149                    if (result instanceof DDMStructure) {
1150                            DDMStructure ddmStructure = (DDMStructure)result;
1151    
1152                            if (!Validator.equals(uuid, ddmStructure.getUuid()) ||
1153                                            (groupId != ddmStructure.getGroupId())) {
1154                                    result = null;
1155                            }
1156                    }
1157    
1158                    if (result == null) {
1159                            StringBundler query = new StringBundler(3);
1160    
1161                            query.append(_SQL_SELECT_DDMSTRUCTURE_WHERE);
1162    
1163                            if (uuid == null) {
1164                                    query.append(_FINDER_COLUMN_UUID_G_UUID_1);
1165                            }
1166                            else {
1167                                    if (uuid.equals(StringPool.BLANK)) {
1168                                            query.append(_FINDER_COLUMN_UUID_G_UUID_3);
1169                                    }
1170                                    else {
1171                                            query.append(_FINDER_COLUMN_UUID_G_UUID_2);
1172                                    }
1173                            }
1174    
1175                            query.append(_FINDER_COLUMN_UUID_G_GROUPID_2);
1176    
1177                            String sql = query.toString();
1178    
1179                            Session session = null;
1180    
1181                            try {
1182                                    session = openSession();
1183    
1184                                    Query q = session.createQuery(sql);
1185    
1186                                    QueryPos qPos = QueryPos.getInstance(q);
1187    
1188                                    if (uuid != null) {
1189                                            qPos.add(uuid);
1190                                    }
1191    
1192                                    qPos.add(groupId);
1193    
1194                                    List<DDMStructure> list = q.list();
1195    
1196                                    result = list;
1197    
1198                                    DDMStructure ddmStructure = null;
1199    
1200                                    if (list.isEmpty()) {
1201                                            FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_UUID_G,
1202                                                    finderArgs, list);
1203                                    }
1204                                    else {
1205                                            ddmStructure = list.get(0);
1206    
1207                                            cacheResult(ddmStructure);
1208    
1209                                            if ((ddmStructure.getUuid() == null) ||
1210                                                            !ddmStructure.getUuid().equals(uuid) ||
1211                                                            (ddmStructure.getGroupId() != groupId)) {
1212                                                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_UUID_G,
1213                                                            finderArgs, ddmStructure);
1214                                            }
1215                                    }
1216    
1217                                    return ddmStructure;
1218                            }
1219                            catch (Exception e) {
1220                                    throw processException(e);
1221                            }
1222                            finally {
1223                                    if (result == null) {
1224                                            FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_UUID_G,
1225                                                    finderArgs);
1226                                    }
1227    
1228                                    closeSession(session);
1229                            }
1230                    }
1231                    else {
1232                            if (result instanceof List<?>) {
1233                                    return null;
1234                            }
1235                            else {
1236                                    return (DDMStructure)result;
1237                            }
1238                    }
1239            }
1240    
1241            /**
1242             * Returns all the d d m structures where groupId = &#63;.
1243             *
1244             * @param groupId the group ID
1245             * @return the matching d d m structures
1246             * @throws SystemException if a system exception occurred
1247             */
1248            public List<DDMStructure> findByGroupId(long groupId)
1249                    throws SystemException {
1250                    return findByGroupId(groupId, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
1251            }
1252    
1253            /**
1254             * Returns a range of all the d d m structures where groupId = &#63;.
1255             *
1256             * <p>
1257             * 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.
1258             * </p>
1259             *
1260             * @param groupId the group ID
1261             * @param start the lower bound of the range of d d m structures
1262             * @param end the upper bound of the range of d d m structures (not inclusive)
1263             * @return the range of matching d d m structures
1264             * @throws SystemException if a system exception occurred
1265             */
1266            public List<DDMStructure> findByGroupId(long groupId, int start, int end)
1267                    throws SystemException {
1268                    return findByGroupId(groupId, start, end, null);
1269            }
1270    
1271            /**
1272             * Returns an ordered range of all the d d m structures where groupId = &#63;.
1273             *
1274             * <p>
1275             * 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.
1276             * </p>
1277             *
1278             * @param groupId the group ID
1279             * @param start the lower bound of the range of d d m structures
1280             * @param end the upper bound of the range of d d m structures (not inclusive)
1281             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
1282             * @return the ordered range of matching d d m structures
1283             * @throws SystemException if a system exception occurred
1284             */
1285            public List<DDMStructure> findByGroupId(long groupId, int start, int end,
1286                    OrderByComparator orderByComparator) throws SystemException {
1287                    FinderPath finderPath = null;
1288                    Object[] finderArgs = null;
1289    
1290                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
1291                                    (orderByComparator == null)) {
1292                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_GROUPID;
1293                            finderArgs = new Object[] { groupId };
1294                    }
1295                    else {
1296                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_GROUPID;
1297                            finderArgs = new Object[] { groupId, start, end, orderByComparator };
1298                    }
1299    
1300                    List<DDMStructure> list = (List<DDMStructure>)FinderCacheUtil.getResult(finderPath,
1301                                    finderArgs, this);
1302    
1303                    if ((list != null) && !list.isEmpty()) {
1304                            for (DDMStructure ddmStructure : list) {
1305                                    if ((groupId != ddmStructure.getGroupId())) {
1306                                            list = null;
1307    
1308                                            break;
1309                                    }
1310                            }
1311                    }
1312    
1313                    if (list == null) {
1314                            StringBundler query = null;
1315    
1316                            if (orderByComparator != null) {
1317                                    query = new StringBundler(3 +
1318                                                    (orderByComparator.getOrderByFields().length * 3));
1319                            }
1320                            else {
1321                                    query = new StringBundler(2);
1322                            }
1323    
1324                            query.append(_SQL_SELECT_DDMSTRUCTURE_WHERE);
1325    
1326                            query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
1327    
1328                            if (orderByComparator != null) {
1329                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1330                                            orderByComparator);
1331                            }
1332    
1333                            String sql = query.toString();
1334    
1335                            Session session = null;
1336    
1337                            try {
1338                                    session = openSession();
1339    
1340                                    Query q = session.createQuery(sql);
1341    
1342                                    QueryPos qPos = QueryPos.getInstance(q);
1343    
1344                                    qPos.add(groupId);
1345    
1346                                    list = (List<DDMStructure>)QueryUtil.list(q, getDialect(),
1347                                                    start, end);
1348                            }
1349                            catch (Exception e) {
1350                                    throw processException(e);
1351                            }
1352                            finally {
1353                                    if (list == null) {
1354                                            FinderCacheUtil.removeResult(finderPath, finderArgs);
1355                                    }
1356                                    else {
1357                                            cacheResult(list);
1358    
1359                                            FinderCacheUtil.putResult(finderPath, finderArgs, list);
1360                                    }
1361    
1362                                    closeSession(session);
1363                            }
1364                    }
1365    
1366                    return list;
1367            }
1368    
1369            /**
1370             * Returns the first d d m structure in the ordered set where groupId = &#63;.
1371             *
1372             * <p>
1373             * 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.
1374             * </p>
1375             *
1376             * @param groupId the group ID
1377             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1378             * @return the first matching d d m structure
1379             * @throws com.liferay.portlet.dynamicdatamapping.NoSuchStructureException if a matching d d m structure could not be found
1380             * @throws SystemException if a system exception occurred
1381             */
1382            public DDMStructure findByGroupId_First(long groupId,
1383                    OrderByComparator orderByComparator)
1384                    throws NoSuchStructureException, SystemException {
1385                    List<DDMStructure> list = findByGroupId(groupId, 0, 1, orderByComparator);
1386    
1387                    if (list.isEmpty()) {
1388                            StringBundler msg = new StringBundler(4);
1389    
1390                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1391    
1392                            msg.append("groupId=");
1393                            msg.append(groupId);
1394    
1395                            msg.append(StringPool.CLOSE_CURLY_BRACE);
1396    
1397                            throw new NoSuchStructureException(msg.toString());
1398                    }
1399                    else {
1400                            return list.get(0);
1401                    }
1402            }
1403    
1404            /**
1405             * Returns the last d d m structure in the ordered set where groupId = &#63;.
1406             *
1407             * <p>
1408             * 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.
1409             * </p>
1410             *
1411             * @param groupId the group ID
1412             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1413             * @return the last matching d d m structure
1414             * @throws com.liferay.portlet.dynamicdatamapping.NoSuchStructureException if a matching d d m structure could not be found
1415             * @throws SystemException if a system exception occurred
1416             */
1417            public DDMStructure findByGroupId_Last(long groupId,
1418                    OrderByComparator orderByComparator)
1419                    throws NoSuchStructureException, SystemException {
1420                    int count = countByGroupId(groupId);
1421    
1422                    List<DDMStructure> list = findByGroupId(groupId, count - 1, count,
1423                                    orderByComparator);
1424    
1425                    if (list.isEmpty()) {
1426                            StringBundler msg = new StringBundler(4);
1427    
1428                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1429    
1430                            msg.append("groupId=");
1431                            msg.append(groupId);
1432    
1433                            msg.append(StringPool.CLOSE_CURLY_BRACE);
1434    
1435                            throw new NoSuchStructureException(msg.toString());
1436                    }
1437                    else {
1438                            return list.get(0);
1439                    }
1440            }
1441    
1442            /**
1443             * Returns the d d m structures before and after the current d d m structure in the ordered set where groupId = &#63;.
1444             *
1445             * <p>
1446             * 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.
1447             * </p>
1448             *
1449             * @param structureId the primary key of the current d d m structure
1450             * @param groupId the group ID
1451             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1452             * @return the previous, current, and next d d m structure
1453             * @throws com.liferay.portlet.dynamicdatamapping.NoSuchStructureException if a d d m structure with the primary key could not be found
1454             * @throws SystemException if a system exception occurred
1455             */
1456            public DDMStructure[] findByGroupId_PrevAndNext(long structureId,
1457                    long groupId, OrderByComparator orderByComparator)
1458                    throws NoSuchStructureException, SystemException {
1459                    DDMStructure ddmStructure = findByPrimaryKey(structureId);
1460    
1461                    Session session = null;
1462    
1463                    try {
1464                            session = openSession();
1465    
1466                            DDMStructure[] array = new DDMStructureImpl[3];
1467    
1468                            array[0] = getByGroupId_PrevAndNext(session, ddmStructure, groupId,
1469                                            orderByComparator, true);
1470    
1471                            array[1] = ddmStructure;
1472    
1473                            array[2] = getByGroupId_PrevAndNext(session, ddmStructure, groupId,
1474                                            orderByComparator, false);
1475    
1476                            return array;
1477                    }
1478                    catch (Exception e) {
1479                            throw processException(e);
1480                    }
1481                    finally {
1482                            closeSession(session);
1483                    }
1484            }
1485    
1486            protected DDMStructure getByGroupId_PrevAndNext(Session session,
1487                    DDMStructure ddmStructure, long groupId,
1488                    OrderByComparator orderByComparator, boolean previous) {
1489                    StringBundler query = null;
1490    
1491                    if (orderByComparator != null) {
1492                            query = new StringBundler(6 +
1493                                            (orderByComparator.getOrderByFields().length * 6));
1494                    }
1495                    else {
1496                            query = new StringBundler(3);
1497                    }
1498    
1499                    query.append(_SQL_SELECT_DDMSTRUCTURE_WHERE);
1500    
1501                    query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
1502    
1503                    if (orderByComparator != null) {
1504                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
1505    
1506                            if (orderByConditionFields.length > 0) {
1507                                    query.append(WHERE_AND);
1508                            }
1509    
1510                            for (int i = 0; i < orderByConditionFields.length; i++) {
1511                                    query.append(_ORDER_BY_ENTITY_ALIAS);
1512                                    query.append(orderByConditionFields[i]);
1513    
1514                                    if ((i + 1) < orderByConditionFields.length) {
1515                                            if (orderByComparator.isAscending() ^ previous) {
1516                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
1517                                            }
1518                                            else {
1519                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
1520                                            }
1521                                    }
1522                                    else {
1523                                            if (orderByComparator.isAscending() ^ previous) {
1524                                                    query.append(WHERE_GREATER_THAN);
1525                                            }
1526                                            else {
1527                                                    query.append(WHERE_LESSER_THAN);
1528                                            }
1529                                    }
1530                            }
1531    
1532                            query.append(ORDER_BY_CLAUSE);
1533    
1534                            String[] orderByFields = orderByComparator.getOrderByFields();
1535    
1536                            for (int i = 0; i < orderByFields.length; i++) {
1537                                    query.append(_ORDER_BY_ENTITY_ALIAS);
1538                                    query.append(orderByFields[i]);
1539    
1540                                    if ((i + 1) < orderByFields.length) {
1541                                            if (orderByComparator.isAscending() ^ previous) {
1542                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
1543                                            }
1544                                            else {
1545                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
1546                                            }
1547                                    }
1548                                    else {
1549                                            if (orderByComparator.isAscending() ^ previous) {
1550                                                    query.append(ORDER_BY_ASC);
1551                                            }
1552                                            else {
1553                                                    query.append(ORDER_BY_DESC);
1554                                            }
1555                                    }
1556                            }
1557                    }
1558    
1559                    String sql = query.toString();
1560    
1561                    Query q = session.createQuery(sql);
1562    
1563                    q.setFirstResult(0);
1564                    q.setMaxResults(2);
1565    
1566                    QueryPos qPos = QueryPos.getInstance(q);
1567    
1568                    qPos.add(groupId);
1569    
1570                    if (orderByComparator != null) {
1571                            Object[] values = orderByComparator.getOrderByConditionValues(ddmStructure);
1572    
1573                            for (Object value : values) {
1574                                    qPos.add(value);
1575                            }
1576                    }
1577    
1578                    List<DDMStructure> list = q.list();
1579    
1580                    if (list.size() == 2) {
1581                            return list.get(1);
1582                    }
1583                    else {
1584                            return null;
1585                    }
1586            }
1587    
1588            /**
1589             * Returns all the d d m structures that the user has permission to view where groupId = &#63;.
1590             *
1591             * @param groupId the group ID
1592             * @return the matching d d m structures that the user has permission to view
1593             * @throws SystemException if a system exception occurred
1594             */
1595            public List<DDMStructure> filterFindByGroupId(long groupId)
1596                    throws SystemException {
1597                    return filterFindByGroupId(groupId, QueryUtil.ALL_POS,
1598                            QueryUtil.ALL_POS, null);
1599            }
1600    
1601            /**
1602             * Returns a range of all the d d m structures that the user has permission to view where groupId = &#63;.
1603             *
1604             * <p>
1605             * 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.
1606             * </p>
1607             *
1608             * @param groupId the group ID
1609             * @param start the lower bound of the range of d d m structures
1610             * @param end the upper bound of the range of d d m structures (not inclusive)
1611             * @return the range of matching d d m structures that the user has permission to view
1612             * @throws SystemException if a system exception occurred
1613             */
1614            public List<DDMStructure> filterFindByGroupId(long groupId, int start,
1615                    int end) throws SystemException {
1616                    return filterFindByGroupId(groupId, start, end, null);
1617            }
1618    
1619            /**
1620             * Returns an ordered range of all the d d m structures that the user has permissions to view where groupId = &#63;.
1621             *
1622             * <p>
1623             * 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.
1624             * </p>
1625             *
1626             * @param groupId the group ID
1627             * @param start the lower bound of the range of d d m structures
1628             * @param end the upper bound of the range of d d m structures (not inclusive)
1629             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
1630             * @return the ordered range of matching d d m structures that the user has permission to view
1631             * @throws SystemException if a system exception occurred
1632             */
1633            public List<DDMStructure> filterFindByGroupId(long groupId, int start,
1634                    int end, OrderByComparator orderByComparator) throws SystemException {
1635                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
1636                            return findByGroupId(groupId, start, end, orderByComparator);
1637                    }
1638    
1639                    StringBundler query = null;
1640    
1641                    if (orderByComparator != null) {
1642                            query = new StringBundler(3 +
1643                                            (orderByComparator.getOrderByFields().length * 3));
1644                    }
1645                    else {
1646                            query = new StringBundler(2);
1647                    }
1648    
1649                    if (getDB().isSupportsInlineDistinct()) {
1650                            query.append(_FILTER_SQL_SELECT_DDMSTRUCTURE_WHERE);
1651                    }
1652                    else {
1653                            query.append(_FILTER_SQL_SELECT_DDMSTRUCTURE_NO_INLINE_DISTINCT_WHERE_1);
1654                    }
1655    
1656                    query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
1657    
1658                    if (!getDB().isSupportsInlineDistinct()) {
1659                            query.append(_FILTER_SQL_SELECT_DDMSTRUCTURE_NO_INLINE_DISTINCT_WHERE_2);
1660                    }
1661    
1662                    if (orderByComparator != null) {
1663                            if (getDB().isSupportsInlineDistinct()) {
1664                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1665                                            orderByComparator);
1666                            }
1667                            else {
1668                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_TABLE,
1669                                            orderByComparator);
1670                            }
1671                    }
1672    
1673                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
1674                                    DDMStructure.class.getName(),
1675                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
1676    
1677                    Session session = null;
1678    
1679                    try {
1680                            session = openSession();
1681    
1682                            SQLQuery q = session.createSQLQuery(sql);
1683    
1684                            if (getDB().isSupportsInlineDistinct()) {
1685                                    q.addEntity(_FILTER_ENTITY_ALIAS, DDMStructureImpl.class);
1686                            }
1687                            else {
1688                                    q.addEntity(_FILTER_ENTITY_TABLE, DDMStructureImpl.class);
1689                            }
1690    
1691                            QueryPos qPos = QueryPos.getInstance(q);
1692    
1693                            qPos.add(groupId);
1694    
1695                            return (List<DDMStructure>)QueryUtil.list(q, getDialect(), start,
1696                                    end);
1697                    }
1698                    catch (Exception e) {
1699                            throw processException(e);
1700                    }
1701                    finally {
1702                            closeSession(session);
1703                    }
1704            }
1705    
1706            /**
1707             * 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;.
1708             *
1709             * @param structureId the primary key of the current d d m structure
1710             * @param groupId the group ID
1711             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1712             * @return the previous, current, and next d d m structure
1713             * @throws com.liferay.portlet.dynamicdatamapping.NoSuchStructureException if a d d m structure with the primary key could not be found
1714             * @throws SystemException if a system exception occurred
1715             */
1716            public DDMStructure[] filterFindByGroupId_PrevAndNext(long structureId,
1717                    long groupId, OrderByComparator orderByComparator)
1718                    throws NoSuchStructureException, SystemException {
1719                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
1720                            return findByGroupId_PrevAndNext(structureId, groupId,
1721                                    orderByComparator);
1722                    }
1723    
1724                    DDMStructure ddmStructure = findByPrimaryKey(structureId);
1725    
1726                    Session session = null;
1727    
1728                    try {
1729                            session = openSession();
1730    
1731                            DDMStructure[] array = new DDMStructureImpl[3];
1732    
1733                            array[0] = filterGetByGroupId_PrevAndNext(session, ddmStructure,
1734                                            groupId, orderByComparator, true);
1735    
1736                            array[1] = ddmStructure;
1737    
1738                            array[2] = filterGetByGroupId_PrevAndNext(session, ddmStructure,
1739                                            groupId, orderByComparator, false);
1740    
1741                            return array;
1742                    }
1743                    catch (Exception e) {
1744                            throw processException(e);
1745                    }
1746                    finally {
1747                            closeSession(session);
1748                    }
1749            }
1750    
1751            protected DDMStructure filterGetByGroupId_PrevAndNext(Session session,
1752                    DDMStructure ddmStructure, long groupId,
1753                    OrderByComparator orderByComparator, boolean previous) {
1754                    StringBundler query = null;
1755    
1756                    if (orderByComparator != null) {
1757                            query = new StringBundler(6 +
1758                                            (orderByComparator.getOrderByFields().length * 6));
1759                    }
1760                    else {
1761                            query = new StringBundler(3);
1762                    }
1763    
1764                    if (getDB().isSupportsInlineDistinct()) {
1765                            query.append(_FILTER_SQL_SELECT_DDMSTRUCTURE_WHERE);
1766                    }
1767                    else {
1768                            query.append(_FILTER_SQL_SELECT_DDMSTRUCTURE_NO_INLINE_DISTINCT_WHERE_1);
1769                    }
1770    
1771                    query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
1772    
1773                    if (!getDB().isSupportsInlineDistinct()) {
1774                            query.append(_FILTER_SQL_SELECT_DDMSTRUCTURE_NO_INLINE_DISTINCT_WHERE_2);
1775                    }
1776    
1777                    if (orderByComparator != null) {
1778                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
1779    
1780                            if (orderByConditionFields.length > 0) {
1781                                    query.append(WHERE_AND);
1782                            }
1783    
1784                            for (int i = 0; i < orderByConditionFields.length; i++) {
1785                                    if (getDB().isSupportsInlineDistinct()) {
1786                                            query.append(_ORDER_BY_ENTITY_ALIAS);
1787                                    }
1788                                    else {
1789                                            query.append(_ORDER_BY_ENTITY_TABLE);
1790                                    }
1791    
1792                                    query.append(orderByConditionFields[i]);
1793    
1794                                    if ((i + 1) < orderByConditionFields.length) {
1795                                            if (orderByComparator.isAscending() ^ previous) {
1796                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
1797                                            }
1798                                            else {
1799                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
1800                                            }
1801                                    }
1802                                    else {
1803                                            if (orderByComparator.isAscending() ^ previous) {
1804                                                    query.append(WHERE_GREATER_THAN);
1805                                            }
1806                                            else {
1807                                                    query.append(WHERE_LESSER_THAN);
1808                                            }
1809                                    }
1810                            }
1811    
1812                            query.append(ORDER_BY_CLAUSE);
1813    
1814                            String[] orderByFields = orderByComparator.getOrderByFields();
1815    
1816                            for (int i = 0; i < orderByFields.length; i++) {
1817                                    if (getDB().isSupportsInlineDistinct()) {
1818                                            query.append(_ORDER_BY_ENTITY_ALIAS);
1819                                    }
1820                                    else {
1821                                            query.append(_ORDER_BY_ENTITY_TABLE);
1822                                    }
1823    
1824                                    query.append(orderByFields[i]);
1825    
1826                                    if ((i + 1) < orderByFields.length) {
1827                                            if (orderByComparator.isAscending() ^ previous) {
1828                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
1829                                            }
1830                                            else {
1831                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
1832                                            }
1833                                    }
1834                                    else {
1835                                            if (orderByComparator.isAscending() ^ previous) {
1836                                                    query.append(ORDER_BY_ASC);
1837                                            }
1838                                            else {
1839                                                    query.append(ORDER_BY_DESC);
1840                                            }
1841                                    }
1842                            }
1843                    }
1844    
1845                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
1846                                    DDMStructure.class.getName(),
1847                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
1848    
1849                    SQLQuery q = session.createSQLQuery(sql);
1850    
1851                    q.setFirstResult(0);
1852                    q.setMaxResults(2);
1853    
1854                    if (getDB().isSupportsInlineDistinct()) {
1855                            q.addEntity(_FILTER_ENTITY_ALIAS, DDMStructureImpl.class);
1856                    }
1857                    else {
1858                            q.addEntity(_FILTER_ENTITY_TABLE, DDMStructureImpl.class);
1859                    }
1860    
1861                    QueryPos qPos = QueryPos.getInstance(q);
1862    
1863                    qPos.add(groupId);
1864    
1865                    if (orderByComparator != null) {
1866                            Object[] values = orderByComparator.getOrderByConditionValues(ddmStructure);
1867    
1868                            for (Object value : values) {
1869                                    qPos.add(value);
1870                            }
1871                    }
1872    
1873                    List<DDMStructure> list = q.list();
1874    
1875                    if (list.size() == 2) {
1876                            return list.get(1);
1877                    }
1878                    else {
1879                            return null;
1880                    }
1881            }
1882    
1883            /**
1884             * Returns all the d d m structures where classNameId = &#63;.
1885             *
1886             * @param classNameId the class name ID
1887             * @return the matching d d m structures
1888             * @throws SystemException if a system exception occurred
1889             */
1890            public List<DDMStructure> findByClassNameId(long classNameId)
1891                    throws SystemException {
1892                    return findByClassNameId(classNameId, QueryUtil.ALL_POS,
1893                            QueryUtil.ALL_POS, null);
1894            }
1895    
1896            /**
1897             * Returns a range of all the d d m structures where classNameId = &#63;.
1898             *
1899             * <p>
1900             * 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.
1901             * </p>
1902             *
1903             * @param classNameId the class name ID
1904             * @param start the lower bound of the range of d d m structures
1905             * @param end the upper bound of the range of d d m structures (not inclusive)
1906             * @return the range of matching d d m structures
1907             * @throws SystemException if a system exception occurred
1908             */
1909            public List<DDMStructure> findByClassNameId(long classNameId, int start,
1910                    int end) throws SystemException {
1911                    return findByClassNameId(classNameId, start, end, null);
1912            }
1913    
1914            /**
1915             * Returns an ordered range of all the d d m structures where classNameId = &#63;.
1916             *
1917             * <p>
1918             * 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.
1919             * </p>
1920             *
1921             * @param classNameId the class name ID
1922             * @param start the lower bound of the range of d d m structures
1923             * @param end the upper bound of the range of d d m structures (not inclusive)
1924             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
1925             * @return the ordered range of matching d d m structures
1926             * @throws SystemException if a system exception occurred
1927             */
1928            public List<DDMStructure> findByClassNameId(long classNameId, int start,
1929                    int end, OrderByComparator orderByComparator) throws SystemException {
1930                    FinderPath finderPath = null;
1931                    Object[] finderArgs = null;
1932    
1933                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
1934                                    (orderByComparator == null)) {
1935                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_CLASSNAMEID;
1936                            finderArgs = new Object[] { classNameId };
1937                    }
1938                    else {
1939                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_CLASSNAMEID;
1940                            finderArgs = new Object[] { classNameId, start, end, orderByComparator };
1941                    }
1942    
1943                    List<DDMStructure> list = (List<DDMStructure>)FinderCacheUtil.getResult(finderPath,
1944                                    finderArgs, this);
1945    
1946                    if ((list != null) && !list.isEmpty()) {
1947                            for (DDMStructure ddmStructure : list) {
1948                                    if ((classNameId != ddmStructure.getClassNameId())) {
1949                                            list = null;
1950    
1951                                            break;
1952                                    }
1953                            }
1954                    }
1955    
1956                    if (list == null) {
1957                            StringBundler query = null;
1958    
1959                            if (orderByComparator != null) {
1960                                    query = new StringBundler(3 +
1961                                                    (orderByComparator.getOrderByFields().length * 3));
1962                            }
1963                            else {
1964                                    query = new StringBundler(2);
1965                            }
1966    
1967                            query.append(_SQL_SELECT_DDMSTRUCTURE_WHERE);
1968    
1969                            query.append(_FINDER_COLUMN_CLASSNAMEID_CLASSNAMEID_2);
1970    
1971                            if (orderByComparator != null) {
1972                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1973                                            orderByComparator);
1974                            }
1975    
1976                            String sql = query.toString();
1977    
1978                            Session session = null;
1979    
1980                            try {
1981                                    session = openSession();
1982    
1983                                    Query q = session.createQuery(sql);
1984    
1985                                    QueryPos qPos = QueryPos.getInstance(q);
1986    
1987                                    qPos.add(classNameId);
1988    
1989                                    list = (List<DDMStructure>)QueryUtil.list(q, getDialect(),
1990                                                    start, end);
1991                            }
1992                            catch (Exception e) {
1993                                    throw processException(e);
1994                            }
1995                            finally {
1996                                    if (list == null) {
1997                                            FinderCacheUtil.removeResult(finderPath, finderArgs);
1998                                    }
1999                                    else {
2000                                            cacheResult(list);
2001    
2002                                            FinderCacheUtil.putResult(finderPath, finderArgs, list);
2003                                    }
2004    
2005                                    closeSession(session);
2006                            }
2007                    }
2008    
2009                    return list;
2010            }
2011    
2012            /**
2013             * Returns the first d d m structure in the ordered set where classNameId = &#63;.
2014             *
2015             * <p>
2016             * 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.
2017             * </p>
2018             *
2019             * @param classNameId the class name ID
2020             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
2021             * @return the first matching d d m structure
2022             * @throws com.liferay.portlet.dynamicdatamapping.NoSuchStructureException if a matching d d m structure could not be found
2023             * @throws SystemException if a system exception occurred
2024             */
2025            public DDMStructure findByClassNameId_First(long classNameId,
2026                    OrderByComparator orderByComparator)
2027                    throws NoSuchStructureException, SystemException {
2028                    List<DDMStructure> list = findByClassNameId(classNameId, 0, 1,
2029                                    orderByComparator);
2030    
2031                    if (list.isEmpty()) {
2032                            StringBundler msg = new StringBundler(4);
2033    
2034                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
2035    
2036                            msg.append("classNameId=");
2037                            msg.append(classNameId);
2038    
2039                            msg.append(StringPool.CLOSE_CURLY_BRACE);
2040    
2041                            throw new NoSuchStructureException(msg.toString());
2042                    }
2043                    else {
2044                            return list.get(0);
2045                    }
2046            }
2047    
2048            /**
2049             * Returns the last d d m structure in the ordered set where classNameId = &#63;.
2050             *
2051             * <p>
2052             * 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.
2053             * </p>
2054             *
2055             * @param classNameId the class name ID
2056             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
2057             * @return the last matching d d m structure
2058             * @throws com.liferay.portlet.dynamicdatamapping.NoSuchStructureException if a matching d d m structure could not be found
2059             * @throws SystemException if a system exception occurred
2060             */
2061            public DDMStructure findByClassNameId_Last(long classNameId,
2062                    OrderByComparator orderByComparator)
2063                    throws NoSuchStructureException, SystemException {
2064                    int count = countByClassNameId(classNameId);
2065    
2066                    List<DDMStructure> list = findByClassNameId(classNameId, count - 1,
2067                                    count, orderByComparator);
2068    
2069                    if (list.isEmpty()) {
2070                            StringBundler msg = new StringBundler(4);
2071    
2072                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
2073    
2074                            msg.append("classNameId=");
2075                            msg.append(classNameId);
2076    
2077                            msg.append(StringPool.CLOSE_CURLY_BRACE);
2078    
2079                            throw new NoSuchStructureException(msg.toString());
2080                    }
2081                    else {
2082                            return list.get(0);
2083                    }
2084            }
2085    
2086            /**
2087             * Returns the d d m structures before and after the current d d m structure in the ordered set where classNameId = &#63;.
2088             *
2089             * <p>
2090             * 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.
2091             * </p>
2092             *
2093             * @param structureId the primary key of the current d d m structure
2094             * @param classNameId the class name ID
2095             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
2096             * @return the previous, current, and next d d m structure
2097             * @throws com.liferay.portlet.dynamicdatamapping.NoSuchStructureException if a d d m structure with the primary key could not be found
2098             * @throws SystemException if a system exception occurred
2099             */
2100            public DDMStructure[] findByClassNameId_PrevAndNext(long structureId,
2101                    long classNameId, OrderByComparator orderByComparator)
2102                    throws NoSuchStructureException, SystemException {
2103                    DDMStructure ddmStructure = findByPrimaryKey(structureId);
2104    
2105                    Session session = null;
2106    
2107                    try {
2108                            session = openSession();
2109    
2110                            DDMStructure[] array = new DDMStructureImpl[3];
2111    
2112                            array[0] = getByClassNameId_PrevAndNext(session, ddmStructure,
2113                                            classNameId, orderByComparator, true);
2114    
2115                            array[1] = ddmStructure;
2116    
2117                            array[2] = getByClassNameId_PrevAndNext(session, ddmStructure,
2118                                            classNameId, orderByComparator, false);
2119    
2120                            return array;
2121                    }
2122                    catch (Exception e) {
2123                            throw processException(e);
2124                    }
2125                    finally {
2126                            closeSession(session);
2127                    }
2128            }
2129    
2130            protected DDMStructure getByClassNameId_PrevAndNext(Session session,
2131                    DDMStructure ddmStructure, long classNameId,
2132                    OrderByComparator orderByComparator, boolean previous) {
2133                    StringBundler query = null;
2134    
2135                    if (orderByComparator != null) {
2136                            query = new StringBundler(6 +
2137                                            (orderByComparator.getOrderByFields().length * 6));
2138                    }
2139                    else {
2140                            query = new StringBundler(3);
2141                    }
2142    
2143                    query.append(_SQL_SELECT_DDMSTRUCTURE_WHERE);
2144    
2145                    query.append(_FINDER_COLUMN_CLASSNAMEID_CLASSNAMEID_2);
2146    
2147                    if (orderByComparator != null) {
2148                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
2149    
2150                            if (orderByConditionFields.length > 0) {
2151                                    query.append(WHERE_AND);
2152                            }
2153    
2154                            for (int i = 0; i < orderByConditionFields.length; i++) {
2155                                    query.append(_ORDER_BY_ENTITY_ALIAS);
2156                                    query.append(orderByConditionFields[i]);
2157    
2158                                    if ((i + 1) < orderByConditionFields.length) {
2159                                            if (orderByComparator.isAscending() ^ previous) {
2160                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
2161                                            }
2162                                            else {
2163                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
2164                                            }
2165                                    }
2166                                    else {
2167                                            if (orderByComparator.isAscending() ^ previous) {
2168                                                    query.append(WHERE_GREATER_THAN);
2169                                            }
2170                                            else {
2171                                                    query.append(WHERE_LESSER_THAN);
2172                                            }
2173                                    }
2174                            }
2175    
2176                            query.append(ORDER_BY_CLAUSE);
2177    
2178                            String[] orderByFields = orderByComparator.getOrderByFields();
2179    
2180                            for (int i = 0; i < orderByFields.length; i++) {
2181                                    query.append(_ORDER_BY_ENTITY_ALIAS);
2182                                    query.append(orderByFields[i]);
2183    
2184                                    if ((i + 1) < orderByFields.length) {
2185                                            if (orderByComparator.isAscending() ^ previous) {
2186                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
2187                                            }
2188                                            else {
2189                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
2190                                            }
2191                                    }
2192                                    else {
2193                                            if (orderByComparator.isAscending() ^ previous) {
2194                                                    query.append(ORDER_BY_ASC);
2195                                            }
2196                                            else {
2197                                                    query.append(ORDER_BY_DESC);
2198                                            }
2199                                    }
2200                            }
2201                    }
2202    
2203                    String sql = query.toString();
2204    
2205                    Query q = session.createQuery(sql);
2206    
2207                    q.setFirstResult(0);
2208                    q.setMaxResults(2);
2209    
2210                    QueryPos qPos = QueryPos.getInstance(q);
2211    
2212                    qPos.add(classNameId);
2213    
2214                    if (orderByComparator != null) {
2215                            Object[] values = orderByComparator.getOrderByConditionValues(ddmStructure);
2216    
2217                            for (Object value : values) {
2218                                    qPos.add(value);
2219                            }
2220                    }
2221    
2222                    List<DDMStructure> list = q.list();
2223    
2224                    if (list.size() == 2) {
2225                            return list.get(1);
2226                    }
2227                    else {
2228                            return null;
2229                    }
2230            }
2231    
2232            /**
2233             * 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.
2234             *
2235             * @param groupId the group ID
2236             * @param structureKey the structure key
2237             * @return the matching d d m structure
2238             * @throws com.liferay.portlet.dynamicdatamapping.NoSuchStructureException if a matching d d m structure could not be found
2239             * @throws SystemException if a system exception occurred
2240             */
2241            public DDMStructure findByG_S(long groupId, String structureKey)
2242                    throws NoSuchStructureException, SystemException {
2243                    DDMStructure ddmStructure = fetchByG_S(groupId, structureKey);
2244    
2245                    if (ddmStructure == null) {
2246                            StringBundler msg = new StringBundler(6);
2247    
2248                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
2249    
2250                            msg.append("groupId=");
2251                            msg.append(groupId);
2252    
2253                            msg.append(", structureKey=");
2254                            msg.append(structureKey);
2255    
2256                            msg.append(StringPool.CLOSE_CURLY_BRACE);
2257    
2258                            if (_log.isWarnEnabled()) {
2259                                    _log.warn(msg.toString());
2260                            }
2261    
2262                            throw new NoSuchStructureException(msg.toString());
2263                    }
2264    
2265                    return ddmStructure;
2266            }
2267    
2268            /**
2269             * 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.
2270             *
2271             * @param groupId the group ID
2272             * @param structureKey the structure key
2273             * @return the matching d d m structure, or <code>null</code> if a matching d d m structure could not be found
2274             * @throws SystemException if a system exception occurred
2275             */
2276            public DDMStructure fetchByG_S(long groupId, String structureKey)
2277                    throws SystemException {
2278                    return fetchByG_S(groupId, structureKey, true);
2279            }
2280    
2281            /**
2282             * 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.
2283             *
2284             * @param groupId the group ID
2285             * @param structureKey the structure key
2286             * @param retrieveFromCache whether to use the finder cache
2287             * @return the matching d d m structure, or <code>null</code> if a matching d d m structure could not be found
2288             * @throws SystemException if a system exception occurred
2289             */
2290            public DDMStructure fetchByG_S(long groupId, String structureKey,
2291                    boolean retrieveFromCache) throws SystemException {
2292                    Object[] finderArgs = new Object[] { groupId, structureKey };
2293    
2294                    Object result = null;
2295    
2296                    if (retrieveFromCache) {
2297                            result = FinderCacheUtil.getResult(FINDER_PATH_FETCH_BY_G_S,
2298                                            finderArgs, this);
2299                    }
2300    
2301                    if (result instanceof DDMStructure) {
2302                            DDMStructure ddmStructure = (DDMStructure)result;
2303    
2304                            if ((groupId != ddmStructure.getGroupId()) ||
2305                                            !Validator.equals(structureKey,
2306                                                    ddmStructure.getStructureKey())) {
2307                                    result = null;
2308                            }
2309                    }
2310    
2311                    if (result == null) {
2312                            StringBundler query = new StringBundler(3);
2313    
2314                            query.append(_SQL_SELECT_DDMSTRUCTURE_WHERE);
2315    
2316                            query.append(_FINDER_COLUMN_G_S_GROUPID_2);
2317    
2318                            if (structureKey == null) {
2319                                    query.append(_FINDER_COLUMN_G_S_STRUCTUREKEY_1);
2320                            }
2321                            else {
2322                                    if (structureKey.equals(StringPool.BLANK)) {
2323                                            query.append(_FINDER_COLUMN_G_S_STRUCTUREKEY_3);
2324                                    }
2325                                    else {
2326                                            query.append(_FINDER_COLUMN_G_S_STRUCTUREKEY_2);
2327                                    }
2328                            }
2329    
2330                            String sql = query.toString();
2331    
2332                            Session session = null;
2333    
2334                            try {
2335                                    session = openSession();
2336    
2337                                    Query q = session.createQuery(sql);
2338    
2339                                    QueryPos qPos = QueryPos.getInstance(q);
2340    
2341                                    qPos.add(groupId);
2342    
2343                                    if (structureKey != null) {
2344                                            qPos.add(structureKey);
2345                                    }
2346    
2347                                    List<DDMStructure> list = q.list();
2348    
2349                                    result = list;
2350    
2351                                    DDMStructure ddmStructure = null;
2352    
2353                                    if (list.isEmpty()) {
2354                                            FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_G_S,
2355                                                    finderArgs, list);
2356                                    }
2357                                    else {
2358                                            ddmStructure = list.get(0);
2359    
2360                                            cacheResult(ddmStructure);
2361    
2362                                            if ((ddmStructure.getGroupId() != groupId) ||
2363                                                            (ddmStructure.getStructureKey() == null) ||
2364                                                            !ddmStructure.getStructureKey().equals(structureKey)) {
2365                                                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_G_S,
2366                                                            finderArgs, ddmStructure);
2367                                            }
2368                                    }
2369    
2370                                    return ddmStructure;
2371                            }
2372                            catch (Exception e) {
2373                                    throw processException(e);
2374                            }
2375                            finally {
2376                                    if (result == null) {
2377                                            FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_G_S,
2378                                                    finderArgs);
2379                                    }
2380    
2381                                    closeSession(session);
2382                            }
2383                    }
2384                    else {
2385                            if (result instanceof List<?>) {
2386                                    return null;
2387                            }
2388                            else {
2389                                    return (DDMStructure)result;
2390                            }
2391                    }
2392            }
2393    
2394            /**
2395             * Returns all the d d m structures where groupId = &#63; and name = &#63; and description = &#63;.
2396             *
2397             * @param groupId the group ID
2398             * @param name the name
2399             * @param description the description
2400             * @return the matching d d m structures
2401             * @throws SystemException if a system exception occurred
2402             */
2403            public List<DDMStructure> findByG_N_D(long groupId, String name,
2404                    String description) throws SystemException {
2405                    return findByG_N_D(groupId, name, description, QueryUtil.ALL_POS,
2406                            QueryUtil.ALL_POS, null);
2407            }
2408    
2409            /**
2410             * Returns a range of all the d d m structures where groupId = &#63; and name = &#63; and description = &#63;.
2411             *
2412             * <p>
2413             * 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.
2414             * </p>
2415             *
2416             * @param groupId the group ID
2417             * @param name the name
2418             * @param description the description
2419             * @param start the lower bound of the range of d d m structures
2420             * @param end the upper bound of the range of d d m structures (not inclusive)
2421             * @return the range of matching d d m structures
2422             * @throws SystemException if a system exception occurred
2423             */
2424            public List<DDMStructure> findByG_N_D(long groupId, String name,
2425                    String description, int start, int end) throws SystemException {
2426                    return findByG_N_D(groupId, name, description, start, end, null);
2427            }
2428    
2429            /**
2430             * Returns an ordered range of all the d d m structures where groupId = &#63; and name = &#63; and description = &#63;.
2431             *
2432             * <p>
2433             * 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.
2434             * </p>
2435             *
2436             * @param groupId the group ID
2437             * @param name the name
2438             * @param description the description
2439             * @param start the lower bound of the range of d d m structures
2440             * @param end the upper bound of the range of d d m structures (not inclusive)
2441             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
2442             * @return the ordered range of matching d d m structures
2443             * @throws SystemException if a system exception occurred
2444             */
2445            public List<DDMStructure> findByG_N_D(long groupId, String name,
2446                    String description, int start, int end,
2447                    OrderByComparator orderByComparator) throws SystemException {
2448                    FinderPath finderPath = null;
2449                    Object[] finderArgs = null;
2450    
2451                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
2452                                    (orderByComparator == null)) {
2453                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_N_D;
2454                            finderArgs = new Object[] { groupId, name, description };
2455                    }
2456                    else {
2457                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_G_N_D;
2458                            finderArgs = new Object[] {
2459                                            groupId, name, description,
2460                                            
2461                                            start, end, orderByComparator
2462                                    };
2463                    }
2464    
2465                    List<DDMStructure> list = (List<DDMStructure>)FinderCacheUtil.getResult(finderPath,
2466                                    finderArgs, this);
2467    
2468                    if ((list != null) && !list.isEmpty()) {
2469                            for (DDMStructure ddmStructure : list) {
2470                                    if ((groupId != ddmStructure.getGroupId()) ||
2471                                                    !Validator.equals(name, ddmStructure.getName()) ||
2472                                                    !Validator.equals(description,
2473                                                            ddmStructure.getDescription())) {
2474                                            list = null;
2475    
2476                                            break;
2477                                    }
2478                            }
2479                    }
2480    
2481                    if (list == null) {
2482                            StringBundler query = null;
2483    
2484                            if (orderByComparator != null) {
2485                                    query = new StringBundler(5 +
2486                                                    (orderByComparator.getOrderByFields().length * 3));
2487                            }
2488                            else {
2489                                    query = new StringBundler(4);
2490                            }
2491    
2492                            query.append(_SQL_SELECT_DDMSTRUCTURE_WHERE);
2493    
2494                            query.append(_FINDER_COLUMN_G_N_D_GROUPID_2);
2495    
2496                            if (name == null) {
2497                                    query.append(_FINDER_COLUMN_G_N_D_NAME_1);
2498                            }
2499                            else {
2500                                    if (name.equals(StringPool.BLANK)) {
2501                                            query.append(_FINDER_COLUMN_G_N_D_NAME_3);
2502                                    }
2503                                    else {
2504                                            query.append(_FINDER_COLUMN_G_N_D_NAME_2);
2505                                    }
2506                            }
2507    
2508                            if (description == null) {
2509                                    query.append(_FINDER_COLUMN_G_N_D_DESCRIPTION_1);
2510                            }
2511                            else {
2512                                    if (description.equals(StringPool.BLANK)) {
2513                                            query.append(_FINDER_COLUMN_G_N_D_DESCRIPTION_3);
2514                                    }
2515                                    else {
2516                                            query.append(_FINDER_COLUMN_G_N_D_DESCRIPTION_2);
2517                                    }
2518                            }
2519    
2520                            if (orderByComparator != null) {
2521                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
2522                                            orderByComparator);
2523                            }
2524    
2525                            String sql = query.toString();
2526    
2527                            Session session = null;
2528    
2529                            try {
2530                                    session = openSession();
2531    
2532                                    Query q = session.createQuery(sql);
2533    
2534                                    QueryPos qPos = QueryPos.getInstance(q);
2535    
2536                                    qPos.add(groupId);
2537    
2538                                    if (name != null) {
2539                                            qPos.add(name);
2540                                    }
2541    
2542                                    if (description != null) {
2543                                            qPos.add(description);
2544                                    }
2545    
2546                                    list = (List<DDMStructure>)QueryUtil.list(q, getDialect(),
2547                                                    start, end);
2548                            }
2549                            catch (Exception e) {
2550                                    throw processException(e);
2551                            }
2552                            finally {
2553                                    if (list == null) {
2554                                            FinderCacheUtil.removeResult(finderPath, finderArgs);
2555                                    }
2556                                    else {
2557                                            cacheResult(list);
2558    
2559                                            FinderCacheUtil.putResult(finderPath, finderArgs, list);
2560                                    }
2561    
2562                                    closeSession(session);
2563                            }
2564                    }
2565    
2566                    return list;
2567            }
2568    
2569            /**
2570             * Returns the first d d m structure in the ordered set where groupId = &#63; and name = &#63; and description = &#63;.
2571             *
2572             * <p>
2573             * 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.
2574             * </p>
2575             *
2576             * @param groupId the group ID
2577             * @param name the name
2578             * @param description the description
2579             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
2580             * @return the first matching d d m structure
2581             * @throws com.liferay.portlet.dynamicdatamapping.NoSuchStructureException if a matching d d m structure could not be found
2582             * @throws SystemException if a system exception occurred
2583             */
2584            public DDMStructure findByG_N_D_First(long groupId, String name,
2585                    String description, OrderByComparator orderByComparator)
2586                    throws NoSuchStructureException, SystemException {
2587                    List<DDMStructure> list = findByG_N_D(groupId, name, description, 0, 1,
2588                                    orderByComparator);
2589    
2590                    if (list.isEmpty()) {
2591                            StringBundler msg = new StringBundler(8);
2592    
2593                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
2594    
2595                            msg.append("groupId=");
2596                            msg.append(groupId);
2597    
2598                            msg.append(", name=");
2599                            msg.append(name);
2600    
2601                            msg.append(", description=");
2602                            msg.append(description);
2603    
2604                            msg.append(StringPool.CLOSE_CURLY_BRACE);
2605    
2606                            throw new NoSuchStructureException(msg.toString());
2607                    }
2608                    else {
2609                            return list.get(0);
2610                    }
2611            }
2612    
2613            /**
2614             * Returns the last d d m structure in the ordered set where groupId = &#63; and name = &#63; and description = &#63;.
2615             *
2616             * <p>
2617             * 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.
2618             * </p>
2619             *
2620             * @param groupId the group ID
2621             * @param name the name
2622             * @param description the description
2623             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
2624             * @return the last matching d d m structure
2625             * @throws com.liferay.portlet.dynamicdatamapping.NoSuchStructureException if a matching d d m structure could not be found
2626             * @throws SystemException if a system exception occurred
2627             */
2628            public DDMStructure findByG_N_D_Last(long groupId, String name,
2629                    String description, OrderByComparator orderByComparator)
2630                    throws NoSuchStructureException, SystemException {
2631                    int count = countByG_N_D(groupId, name, description);
2632    
2633                    List<DDMStructure> list = findByG_N_D(groupId, name, description,
2634                                    count - 1, count, orderByComparator);
2635    
2636                    if (list.isEmpty()) {
2637                            StringBundler msg = new StringBundler(8);
2638    
2639                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
2640    
2641                            msg.append("groupId=");
2642                            msg.append(groupId);
2643    
2644                            msg.append(", name=");
2645                            msg.append(name);
2646    
2647                            msg.append(", description=");
2648                            msg.append(description);
2649    
2650                            msg.append(StringPool.CLOSE_CURLY_BRACE);
2651    
2652                            throw new NoSuchStructureException(msg.toString());
2653                    }
2654                    else {
2655                            return list.get(0);
2656                    }
2657            }
2658    
2659            /**
2660             * 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;.
2661             *
2662             * <p>
2663             * 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.
2664             * </p>
2665             *
2666             * @param structureId the primary key of the current d d m structure
2667             * @param groupId the group ID
2668             * @param name the name
2669             * @param description the description
2670             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
2671             * @return the previous, current, and next d d m structure
2672             * @throws com.liferay.portlet.dynamicdatamapping.NoSuchStructureException if a d d m structure with the primary key could not be found
2673             * @throws SystemException if a system exception occurred
2674             */
2675            public DDMStructure[] findByG_N_D_PrevAndNext(long structureId,
2676                    long groupId, String name, String description,
2677                    OrderByComparator orderByComparator)
2678                    throws NoSuchStructureException, SystemException {
2679                    DDMStructure ddmStructure = findByPrimaryKey(structureId);
2680    
2681                    Session session = null;
2682    
2683                    try {
2684                            session = openSession();
2685    
2686                            DDMStructure[] array = new DDMStructureImpl[3];
2687    
2688                            array[0] = getByG_N_D_PrevAndNext(session, ddmStructure, groupId,
2689                                            name, description, orderByComparator, true);
2690    
2691                            array[1] = ddmStructure;
2692    
2693                            array[2] = getByG_N_D_PrevAndNext(session, ddmStructure, groupId,
2694                                            name, description, orderByComparator, false);
2695    
2696                            return array;
2697                    }
2698                    catch (Exception e) {
2699                            throw processException(e);
2700                    }
2701                    finally {
2702                            closeSession(session);
2703                    }
2704            }
2705    
2706            protected DDMStructure getByG_N_D_PrevAndNext(Session session,
2707                    DDMStructure ddmStructure, long groupId, String name,
2708                    String description, OrderByComparator orderByComparator,
2709                    boolean previous) {
2710                    StringBundler query = null;
2711    
2712                    if (orderByComparator != null) {
2713                            query = new StringBundler(6 +
2714                                            (orderByComparator.getOrderByFields().length * 6));
2715                    }
2716                    else {
2717                            query = new StringBundler(3);
2718                    }
2719    
2720                    query.append(_SQL_SELECT_DDMSTRUCTURE_WHERE);
2721    
2722                    query.append(_FINDER_COLUMN_G_N_D_GROUPID_2);
2723    
2724                    if (name == null) {
2725                            query.append(_FINDER_COLUMN_G_N_D_NAME_1);
2726                    }
2727                    else {
2728                            if (name.equals(StringPool.BLANK)) {
2729                                    query.append(_FINDER_COLUMN_G_N_D_NAME_3);
2730                            }
2731                            else {
2732                                    query.append(_FINDER_COLUMN_G_N_D_NAME_2);
2733                            }
2734                    }
2735    
2736                    if (description == null) {
2737                            query.append(_FINDER_COLUMN_G_N_D_DESCRIPTION_1);
2738                    }
2739                    else {
2740                            if (description.equals(StringPool.BLANK)) {
2741                                    query.append(_FINDER_COLUMN_G_N_D_DESCRIPTION_3);
2742                            }
2743                            else {
2744                                    query.append(_FINDER_COLUMN_G_N_D_DESCRIPTION_2);
2745                            }
2746                    }
2747    
2748                    if (orderByComparator != null) {
2749                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
2750    
2751                            if (orderByConditionFields.length > 0) {
2752                                    query.append(WHERE_AND);
2753                            }
2754    
2755                            for (int i = 0; i < orderByConditionFields.length; i++) {
2756                                    query.append(_ORDER_BY_ENTITY_ALIAS);
2757                                    query.append(orderByConditionFields[i]);
2758    
2759                                    if ((i + 1) < orderByConditionFields.length) {
2760                                            if (orderByComparator.isAscending() ^ previous) {
2761                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
2762                                            }
2763                                            else {
2764                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
2765                                            }
2766                                    }
2767                                    else {
2768                                            if (orderByComparator.isAscending() ^ previous) {
2769                                                    query.append(WHERE_GREATER_THAN);
2770                                            }
2771                                            else {
2772                                                    query.append(WHERE_LESSER_THAN);
2773                                            }
2774                                    }
2775                            }
2776    
2777                            query.append(ORDER_BY_CLAUSE);
2778    
2779                            String[] orderByFields = orderByComparator.getOrderByFields();
2780    
2781                            for (int i = 0; i < orderByFields.length; i++) {
2782                                    query.append(_ORDER_BY_ENTITY_ALIAS);
2783                                    query.append(orderByFields[i]);
2784    
2785                                    if ((i + 1) < orderByFields.length) {
2786                                            if (orderByComparator.isAscending() ^ previous) {
2787                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
2788                                            }
2789                                            else {
2790                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
2791                                            }
2792                                    }
2793                                    else {
2794                                            if (orderByComparator.isAscending() ^ previous) {
2795                                                    query.append(ORDER_BY_ASC);
2796                                            }
2797                                            else {
2798                                                    query.append(ORDER_BY_DESC);
2799                                            }
2800                                    }
2801                            }
2802                    }
2803    
2804                    String sql = query.toString();
2805    
2806                    Query q = session.createQuery(sql);
2807    
2808                    q.setFirstResult(0);
2809                    q.setMaxResults(2);
2810    
2811                    QueryPos qPos = QueryPos.getInstance(q);
2812    
2813                    qPos.add(groupId);
2814    
2815                    if (name != null) {
2816                            qPos.add(name);
2817                    }
2818    
2819                    if (description != null) {
2820                            qPos.add(description);
2821                    }
2822    
2823                    if (orderByComparator != null) {
2824                            Object[] values = orderByComparator.getOrderByConditionValues(ddmStructure);
2825    
2826                            for (Object value : values) {
2827                                    qPos.add(value);
2828                            }
2829                    }
2830    
2831                    List<DDMStructure> list = q.list();
2832    
2833                    if (list.size() == 2) {
2834                            return list.get(1);
2835                    }
2836                    else {
2837                            return null;
2838                    }
2839            }
2840    
2841            /**
2842             * Returns all the d d m structures that the user has permission to view where groupId = &#63; and name = &#63; and description = &#63;.
2843             *
2844             * @param groupId the group ID
2845             * @param name the name
2846             * @param description the description
2847             * @return the matching d d m structures that the user has permission to view
2848             * @throws SystemException if a system exception occurred
2849             */
2850            public List<DDMStructure> filterFindByG_N_D(long groupId, String name,
2851                    String description) throws SystemException {
2852                    return filterFindByG_N_D(groupId, name, description, QueryUtil.ALL_POS,
2853                            QueryUtil.ALL_POS, null);
2854            }
2855    
2856            /**
2857             * 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;.
2858             *
2859             * <p>
2860             * 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.
2861             * </p>
2862             *
2863             * @param groupId the group ID
2864             * @param name the name
2865             * @param description the description
2866             * @param start the lower bound of the range of d d m structures
2867             * @param end the upper bound of the range of d d m structures (not inclusive)
2868             * @return the range of matching d d m structures that the user has permission to view
2869             * @throws SystemException if a system exception occurred
2870             */
2871            public List<DDMStructure> filterFindByG_N_D(long groupId, String name,
2872                    String description, int start, int end) throws SystemException {
2873                    return filterFindByG_N_D(groupId, name, description, start, end, null);
2874            }
2875    
2876            /**
2877             * 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;.
2878             *
2879             * <p>
2880             * 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.
2881             * </p>
2882             *
2883             * @param groupId the group ID
2884             * @param name the name
2885             * @param description the description
2886             * @param start the lower bound of the range of d d m structures
2887             * @param end the upper bound of the range of d d m structures (not inclusive)
2888             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
2889             * @return the ordered range of matching d d m structures that the user has permission to view
2890             * @throws SystemException if a system exception occurred
2891             */
2892            public List<DDMStructure> filterFindByG_N_D(long groupId, String name,
2893                    String description, int start, int end,
2894                    OrderByComparator orderByComparator) throws SystemException {
2895                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
2896                            return findByG_N_D(groupId, name, description, start, end,
2897                                    orderByComparator);
2898                    }
2899    
2900                    StringBundler query = null;
2901    
2902                    if (orderByComparator != null) {
2903                            query = new StringBundler(5 +
2904                                            (orderByComparator.getOrderByFields().length * 3));
2905                    }
2906                    else {
2907                            query = new StringBundler(4);
2908                    }
2909    
2910                    if (getDB().isSupportsInlineDistinct()) {
2911                            query.append(_FILTER_SQL_SELECT_DDMSTRUCTURE_WHERE);
2912                    }
2913                    else {
2914                            query.append(_FILTER_SQL_SELECT_DDMSTRUCTURE_NO_INLINE_DISTINCT_WHERE_1);
2915                    }
2916    
2917                    query.append(_FINDER_COLUMN_G_N_D_GROUPID_2);
2918    
2919                    if (name == null) {
2920                            query.append(_FINDER_COLUMN_G_N_D_NAME_1);
2921                    }
2922                    else {
2923                            if (name.equals(StringPool.BLANK)) {
2924                                    query.append(_FINDER_COLUMN_G_N_D_NAME_3);
2925                            }
2926                            else {
2927                                    query.append(_FINDER_COLUMN_G_N_D_NAME_2);
2928                            }
2929                    }
2930    
2931                    if (description == null) {
2932                            query.append(_FINDER_COLUMN_G_N_D_DESCRIPTION_1);
2933                    }
2934                    else {
2935                            if (description.equals(StringPool.BLANK)) {
2936                                    query.append(_FINDER_COLUMN_G_N_D_DESCRIPTION_3);
2937                            }
2938                            else {
2939                                    query.append(_FINDER_COLUMN_G_N_D_DESCRIPTION_2);
2940                            }
2941                    }
2942    
2943                    if (!getDB().isSupportsInlineDistinct()) {
2944                            query.append(_FILTER_SQL_SELECT_DDMSTRUCTURE_NO_INLINE_DISTINCT_WHERE_2);
2945                    }
2946    
2947                    if (orderByComparator != null) {
2948                            if (getDB().isSupportsInlineDistinct()) {
2949                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
2950                                            orderByComparator);
2951                            }
2952                            else {
2953                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_TABLE,
2954                                            orderByComparator);
2955                            }
2956                    }
2957    
2958                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
2959                                    DDMStructure.class.getName(),
2960                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
2961    
2962                    Session session = null;
2963    
2964                    try {
2965                            session = openSession();
2966    
2967                            SQLQuery q = session.createSQLQuery(sql);
2968    
2969                            if (getDB().isSupportsInlineDistinct()) {
2970                                    q.addEntity(_FILTER_ENTITY_ALIAS, DDMStructureImpl.class);
2971                            }
2972                            else {
2973                                    q.addEntity(_FILTER_ENTITY_TABLE, DDMStructureImpl.class);
2974                            }
2975    
2976                            QueryPos qPos = QueryPos.getInstance(q);
2977    
2978                            qPos.add(groupId);
2979    
2980                            if (name != null) {
2981                                    qPos.add(name);
2982                            }
2983    
2984                            if (description != null) {
2985                                    qPos.add(description);
2986                            }
2987    
2988                            return (List<DDMStructure>)QueryUtil.list(q, getDialect(), start,
2989                                    end);
2990                    }
2991                    catch (Exception e) {
2992                            throw processException(e);
2993                    }
2994                    finally {
2995                            closeSession(session);
2996                    }
2997            }
2998    
2999            /**
3000             * 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;.
3001             *
3002             * @param structureId the primary key of the current d d m structure
3003             * @param groupId the group ID
3004             * @param name the name
3005             * @param description the description
3006             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
3007             * @return the previous, current, and next d d m structure
3008             * @throws com.liferay.portlet.dynamicdatamapping.NoSuchStructureException if a d d m structure with the primary key could not be found
3009             * @throws SystemException if a system exception occurred
3010             */
3011            public DDMStructure[] filterFindByG_N_D_PrevAndNext(long structureId,
3012                    long groupId, String name, String description,
3013                    OrderByComparator orderByComparator)
3014                    throws NoSuchStructureException, SystemException {
3015                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
3016                            return findByG_N_D_PrevAndNext(structureId, groupId, name,
3017                                    description, orderByComparator);
3018                    }
3019    
3020                    DDMStructure ddmStructure = findByPrimaryKey(structureId);
3021    
3022                    Session session = null;
3023    
3024                    try {
3025                            session = openSession();
3026    
3027                            DDMStructure[] array = new DDMStructureImpl[3];
3028    
3029                            array[0] = filterGetByG_N_D_PrevAndNext(session, ddmStructure,
3030                                            groupId, name, description, orderByComparator, true);
3031    
3032                            array[1] = ddmStructure;
3033    
3034                            array[2] = filterGetByG_N_D_PrevAndNext(session, ddmStructure,
3035                                            groupId, name, description, orderByComparator, false);
3036    
3037                            return array;
3038                    }
3039                    catch (Exception e) {
3040                            throw processException(e);
3041                    }
3042                    finally {
3043                            closeSession(session);
3044                    }
3045            }
3046    
3047            protected DDMStructure filterGetByG_N_D_PrevAndNext(Session session,
3048                    DDMStructure ddmStructure, long groupId, String name,
3049                    String description, OrderByComparator orderByComparator,
3050                    boolean previous) {
3051                    StringBundler query = null;
3052    
3053                    if (orderByComparator != null) {
3054                            query = new StringBundler(6 +
3055                                            (orderByComparator.getOrderByFields().length * 6));
3056                    }
3057                    else {
3058                            query = new StringBundler(3);
3059                    }
3060    
3061                    if (getDB().isSupportsInlineDistinct()) {
3062                            query.append(_FILTER_SQL_SELECT_DDMSTRUCTURE_WHERE);
3063                    }
3064                    else {
3065                            query.append(_FILTER_SQL_SELECT_DDMSTRUCTURE_NO_INLINE_DISTINCT_WHERE_1);
3066                    }
3067    
3068                    query.append(_FINDER_COLUMN_G_N_D_GROUPID_2);
3069    
3070                    if (name == null) {
3071                            query.append(_FINDER_COLUMN_G_N_D_NAME_1);
3072                    }
3073                    else {
3074                            if (name.equals(StringPool.BLANK)) {
3075                                    query.append(_FINDER_COLUMN_G_N_D_NAME_3);
3076                            }
3077                            else {
3078                                    query.append(_FINDER_COLUMN_G_N_D_NAME_2);
3079                            }
3080                    }
3081    
3082                    if (description == null) {
3083                            query.append(_FINDER_COLUMN_G_N_D_DESCRIPTION_1);
3084                    }
3085                    else {
3086                            if (description.equals(StringPool.BLANK)) {
3087                                    query.append(_FINDER_COLUMN_G_N_D_DESCRIPTION_3);
3088                            }
3089                            else {
3090                                    query.append(_FINDER_COLUMN_G_N_D_DESCRIPTION_2);
3091                            }
3092                    }
3093    
3094                    if (!getDB().isSupportsInlineDistinct()) {
3095                            query.append(_FILTER_SQL_SELECT_DDMSTRUCTURE_NO_INLINE_DISTINCT_WHERE_2);
3096                    }
3097    
3098                    if (orderByComparator != null) {
3099                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
3100    
3101                            if (orderByConditionFields.length > 0) {
3102                                    query.append(WHERE_AND);
3103                            }
3104    
3105                            for (int i = 0; i < orderByConditionFields.length; i++) {
3106                                    if (getDB().isSupportsInlineDistinct()) {
3107                                            query.append(_ORDER_BY_ENTITY_ALIAS);
3108                                    }
3109                                    else {
3110                                            query.append(_ORDER_BY_ENTITY_TABLE);
3111                                    }
3112    
3113                                    query.append(orderByConditionFields[i]);
3114    
3115                                    if ((i + 1) < orderByConditionFields.length) {
3116                                            if (orderByComparator.isAscending() ^ previous) {
3117                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
3118                                            }
3119                                            else {
3120                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
3121                                            }
3122                                    }
3123                                    else {
3124                                            if (orderByComparator.isAscending() ^ previous) {
3125                                                    query.append(WHERE_GREATER_THAN);
3126                                            }
3127                                            else {
3128                                                    query.append(WHERE_LESSER_THAN);
3129                                            }
3130                                    }
3131                            }
3132    
3133                            query.append(ORDER_BY_CLAUSE);
3134    
3135                            String[] orderByFields = orderByComparator.getOrderByFields();
3136    
3137                            for (int i = 0; i < orderByFields.length; i++) {
3138                                    if (getDB().isSupportsInlineDistinct()) {
3139                                            query.append(_ORDER_BY_ENTITY_ALIAS);
3140                                    }
3141                                    else {
3142                                            query.append(_ORDER_BY_ENTITY_TABLE);
3143                                    }
3144    
3145                                    query.append(orderByFields[i]);
3146    
3147                                    if ((i + 1) < orderByFields.length) {
3148                                            if (orderByComparator.isAscending() ^ previous) {
3149                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
3150                                            }
3151                                            else {
3152                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
3153                                            }
3154                                    }
3155                                    else {
3156                                            if (orderByComparator.isAscending() ^ previous) {
3157                                                    query.append(ORDER_BY_ASC);
3158                                            }
3159                                            else {
3160                                                    query.append(ORDER_BY_DESC);
3161                                            }
3162                                    }
3163                            }
3164                    }
3165    
3166                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
3167                                    DDMStructure.class.getName(),
3168                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
3169    
3170                    SQLQuery q = session.createSQLQuery(sql);
3171    
3172                    q.setFirstResult(0);
3173                    q.setMaxResults(2);
3174    
3175                    if (getDB().isSupportsInlineDistinct()) {
3176                            q.addEntity(_FILTER_ENTITY_ALIAS, DDMStructureImpl.class);
3177                    }
3178                    else {
3179                            q.addEntity(_FILTER_ENTITY_TABLE, DDMStructureImpl.class);
3180                    }
3181    
3182                    QueryPos qPos = QueryPos.getInstance(q);
3183    
3184                    qPos.add(groupId);
3185    
3186                    if (name != null) {
3187                            qPos.add(name);
3188                    }
3189    
3190                    if (description != null) {
3191                            qPos.add(description);
3192                    }
3193    
3194                    if (orderByComparator != null) {
3195                            Object[] values = orderByComparator.getOrderByConditionValues(ddmStructure);
3196    
3197                            for (Object value : values) {
3198                                    qPos.add(value);
3199                            }
3200                    }
3201    
3202                    List<DDMStructure> list = q.list();
3203    
3204                    if (list.size() == 2) {
3205                            return list.get(1);
3206                    }
3207                    else {
3208                            return null;
3209                    }
3210            }
3211    
3212            /**
3213             * Returns all the d d m structures.
3214             *
3215             * @return the d d m structures
3216             * @throws SystemException if a system exception occurred
3217             */
3218            public List<DDMStructure> findAll() throws SystemException {
3219                    return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
3220            }
3221    
3222            /**
3223             * Returns a range of all the d d m structures.
3224             *
3225             * <p>
3226             * 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.
3227             * </p>
3228             *
3229             * @param start the lower bound of the range of d d m structures
3230             * @param end the upper bound of the range of d d m structures (not inclusive)
3231             * @return the range of d d m structures
3232             * @throws SystemException if a system exception occurred
3233             */
3234            public List<DDMStructure> findAll(int start, int end)
3235                    throws SystemException {
3236                    return findAll(start, end, null);
3237            }
3238    
3239            /**
3240             * Returns an ordered range of all the d d m structures.
3241             *
3242             * <p>
3243             * 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.
3244             * </p>
3245             *
3246             * @param start the lower bound of the range of d d m structures
3247             * @param end the upper bound of the range of d d m structures (not inclusive)
3248             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
3249             * @return the ordered range of d d m structures
3250             * @throws SystemException if a system exception occurred
3251             */
3252            public List<DDMStructure> findAll(int start, int end,
3253                    OrderByComparator orderByComparator) throws SystemException {
3254                    FinderPath finderPath = null;
3255                    Object[] finderArgs = new Object[] { start, end, orderByComparator };
3256    
3257                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
3258                                    (orderByComparator == null)) {
3259                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL;
3260                            finderArgs = FINDER_ARGS_EMPTY;
3261                    }
3262                    else {
3263                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_ALL;
3264                            finderArgs = new Object[] { start, end, orderByComparator };
3265                    }
3266    
3267                    List<DDMStructure> list = (List<DDMStructure>)FinderCacheUtil.getResult(finderPath,
3268                                    finderArgs, this);
3269    
3270                    if (list == null) {
3271                            StringBundler query = null;
3272                            String sql = null;
3273    
3274                            if (orderByComparator != null) {
3275                                    query = new StringBundler(2 +
3276                                                    (orderByComparator.getOrderByFields().length * 3));
3277    
3278                                    query.append(_SQL_SELECT_DDMSTRUCTURE);
3279    
3280                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
3281                                            orderByComparator);
3282    
3283                                    sql = query.toString();
3284                            }
3285                            else {
3286                                    sql = _SQL_SELECT_DDMSTRUCTURE;
3287                            }
3288    
3289                            Session session = null;
3290    
3291                            try {
3292                                    session = openSession();
3293    
3294                                    Query q = session.createQuery(sql);
3295    
3296                                    if (orderByComparator == null) {
3297                                            list = (List<DDMStructure>)QueryUtil.list(q, getDialect(),
3298                                                            start, end, false);
3299    
3300                                            Collections.sort(list);
3301                                    }
3302                                    else {
3303                                            list = (List<DDMStructure>)QueryUtil.list(q, getDialect(),
3304                                                            start, end);
3305                                    }
3306                            }
3307                            catch (Exception e) {
3308                                    throw processException(e);
3309                            }
3310                            finally {
3311                                    if (list == null) {
3312                                            FinderCacheUtil.removeResult(finderPath, finderArgs);
3313                                    }
3314                                    else {
3315                                            cacheResult(list);
3316    
3317                                            FinderCacheUtil.putResult(finderPath, finderArgs, list);
3318                                    }
3319    
3320                                    closeSession(session);
3321                            }
3322                    }
3323    
3324                    return list;
3325            }
3326    
3327            /**
3328             * Removes all the d d m structures where uuid = &#63; from the database.
3329             *
3330             * @param uuid the uuid
3331             * @throws SystemException if a system exception occurred
3332             */
3333            public void removeByUuid(String uuid) throws SystemException {
3334                    for (DDMStructure ddmStructure : findByUuid(uuid)) {
3335                            remove(ddmStructure);
3336                    }
3337            }
3338    
3339            /**
3340             * Removes the d d m structure where uuid = &#63; and groupId = &#63; from the database.
3341             *
3342             * @param uuid the uuid
3343             * @param groupId the group ID
3344             * @throws SystemException if a system exception occurred
3345             */
3346            public void removeByUUID_G(String uuid, long groupId)
3347                    throws NoSuchStructureException, SystemException {
3348                    DDMStructure ddmStructure = findByUUID_G(uuid, groupId);
3349    
3350                    remove(ddmStructure);
3351            }
3352    
3353            /**
3354             * Removes all the d d m structures where groupId = &#63; from the database.
3355             *
3356             * @param groupId the group ID
3357             * @throws SystemException if a system exception occurred
3358             */
3359            public void removeByGroupId(long groupId) throws SystemException {
3360                    for (DDMStructure ddmStructure : findByGroupId(groupId)) {
3361                            remove(ddmStructure);
3362                    }
3363            }
3364    
3365            /**
3366             * Removes all the d d m structures where classNameId = &#63; from the database.
3367             *
3368             * @param classNameId the class name ID
3369             * @throws SystemException if a system exception occurred
3370             */
3371            public void removeByClassNameId(long classNameId) throws SystemException {
3372                    for (DDMStructure ddmStructure : findByClassNameId(classNameId)) {
3373                            remove(ddmStructure);
3374                    }
3375            }
3376    
3377            /**
3378             * Removes the d d m structure where groupId = &#63; and structureKey = &#63; from the database.
3379             *
3380             * @param groupId the group ID
3381             * @param structureKey the structure key
3382             * @throws SystemException if a system exception occurred
3383             */
3384            public void removeByG_S(long groupId, String structureKey)
3385                    throws NoSuchStructureException, SystemException {
3386                    DDMStructure ddmStructure = findByG_S(groupId, structureKey);
3387    
3388                    remove(ddmStructure);
3389            }
3390    
3391            /**
3392             * Removes all the d d m structures where groupId = &#63; and name = &#63; and description = &#63; from the database.
3393             *
3394             * @param groupId the group ID
3395             * @param name the name
3396             * @param description the description
3397             * @throws SystemException if a system exception occurred
3398             */
3399            public void removeByG_N_D(long groupId, String name, String description)
3400                    throws SystemException {
3401                    for (DDMStructure ddmStructure : findByG_N_D(groupId, name, description)) {
3402                            remove(ddmStructure);
3403                    }
3404            }
3405    
3406            /**
3407             * Removes all the d d m structures from the database.
3408             *
3409             * @throws SystemException if a system exception occurred
3410             */
3411            public void removeAll() throws SystemException {
3412                    for (DDMStructure ddmStructure : findAll()) {
3413                            remove(ddmStructure);
3414                    }
3415            }
3416    
3417            /**
3418             * Returns the number of d d m structures where uuid = &#63;.
3419             *
3420             * @param uuid the uuid
3421             * @return the number of matching d d m structures
3422             * @throws SystemException if a system exception occurred
3423             */
3424            public int countByUuid(String uuid) throws SystemException {
3425                    Object[] finderArgs = new Object[] { uuid };
3426    
3427                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_UUID,
3428                                    finderArgs, this);
3429    
3430                    if (count == null) {
3431                            StringBundler query = new StringBundler(2);
3432    
3433                            query.append(_SQL_COUNT_DDMSTRUCTURE_WHERE);
3434    
3435                            if (uuid == null) {
3436                                    query.append(_FINDER_COLUMN_UUID_UUID_1);
3437                            }
3438                            else {
3439                                    if (uuid.equals(StringPool.BLANK)) {
3440                                            query.append(_FINDER_COLUMN_UUID_UUID_3);
3441                                    }
3442                                    else {
3443                                            query.append(_FINDER_COLUMN_UUID_UUID_2);
3444                                    }
3445                            }
3446    
3447                            String sql = query.toString();
3448    
3449                            Session session = null;
3450    
3451                            try {
3452                                    session = openSession();
3453    
3454                                    Query q = session.createQuery(sql);
3455    
3456                                    QueryPos qPos = QueryPos.getInstance(q);
3457    
3458                                    if (uuid != null) {
3459                                            qPos.add(uuid);
3460                                    }
3461    
3462                                    count = (Long)q.uniqueResult();
3463                            }
3464                            catch (Exception e) {
3465                                    throw processException(e);
3466                            }
3467                            finally {
3468                                    if (count == null) {
3469                                            count = Long.valueOf(0);
3470                                    }
3471    
3472                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_UUID,
3473                                            finderArgs, count);
3474    
3475                                    closeSession(session);
3476                            }
3477                    }
3478    
3479                    return count.intValue();
3480            }
3481    
3482            /**
3483             * Returns the number of d d m structures where uuid = &#63; and groupId = &#63;.
3484             *
3485             * @param uuid the uuid
3486             * @param groupId the group ID
3487             * @return the number of matching d d m structures
3488             * @throws SystemException if a system exception occurred
3489             */
3490            public int countByUUID_G(String uuid, long groupId)
3491                    throws SystemException {
3492                    Object[] finderArgs = new Object[] { uuid, groupId };
3493    
3494                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_UUID_G,
3495                                    finderArgs, this);
3496    
3497                    if (count == null) {
3498                            StringBundler query = new StringBundler(3);
3499    
3500                            query.append(_SQL_COUNT_DDMSTRUCTURE_WHERE);
3501    
3502                            if (uuid == null) {
3503                                    query.append(_FINDER_COLUMN_UUID_G_UUID_1);
3504                            }
3505                            else {
3506                                    if (uuid.equals(StringPool.BLANK)) {
3507                                            query.append(_FINDER_COLUMN_UUID_G_UUID_3);
3508                                    }
3509                                    else {
3510                                            query.append(_FINDER_COLUMN_UUID_G_UUID_2);
3511                                    }
3512                            }
3513    
3514                            query.append(_FINDER_COLUMN_UUID_G_GROUPID_2);
3515    
3516                            String sql = query.toString();
3517    
3518                            Session session = null;
3519    
3520                            try {
3521                                    session = openSession();
3522    
3523                                    Query q = session.createQuery(sql);
3524    
3525                                    QueryPos qPos = QueryPos.getInstance(q);
3526    
3527                                    if (uuid != null) {
3528                                            qPos.add(uuid);
3529                                    }
3530    
3531                                    qPos.add(groupId);
3532    
3533                                    count = (Long)q.uniqueResult();
3534                            }
3535                            catch (Exception e) {
3536                                    throw processException(e);
3537                            }
3538                            finally {
3539                                    if (count == null) {
3540                                            count = Long.valueOf(0);
3541                                    }
3542    
3543                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_UUID_G,
3544                                            finderArgs, count);
3545    
3546                                    closeSession(session);
3547                            }
3548                    }
3549    
3550                    return count.intValue();
3551            }
3552    
3553            /**
3554             * Returns the number of d d m structures where groupId = &#63;.
3555             *
3556             * @param groupId the group ID
3557             * @return the number of matching d d m structures
3558             * @throws SystemException if a system exception occurred
3559             */
3560            public int countByGroupId(long groupId) throws SystemException {
3561                    Object[] finderArgs = new Object[] { groupId };
3562    
3563                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_GROUPID,
3564                                    finderArgs, this);
3565    
3566                    if (count == null) {
3567                            StringBundler query = new StringBundler(2);
3568    
3569                            query.append(_SQL_COUNT_DDMSTRUCTURE_WHERE);
3570    
3571                            query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
3572    
3573                            String sql = query.toString();
3574    
3575                            Session session = null;
3576    
3577                            try {
3578                                    session = openSession();
3579    
3580                                    Query q = session.createQuery(sql);
3581    
3582                                    QueryPos qPos = QueryPos.getInstance(q);
3583    
3584                                    qPos.add(groupId);
3585    
3586                                    count = (Long)q.uniqueResult();
3587                            }
3588                            catch (Exception e) {
3589                                    throw processException(e);
3590                            }
3591                            finally {
3592                                    if (count == null) {
3593                                            count = Long.valueOf(0);
3594                                    }
3595    
3596                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_GROUPID,
3597                                            finderArgs, count);
3598    
3599                                    closeSession(session);
3600                            }
3601                    }
3602    
3603                    return count.intValue();
3604            }
3605    
3606            /**
3607             * Returns the number of d d m structures that the user has permission to view where groupId = &#63;.
3608             *
3609             * @param groupId the group ID
3610             * @return the number of matching d d m structures that the user has permission to view
3611             * @throws SystemException if a system exception occurred
3612             */
3613            public int filterCountByGroupId(long groupId) throws SystemException {
3614                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
3615                            return countByGroupId(groupId);
3616                    }
3617    
3618                    StringBundler query = new StringBundler(2);
3619    
3620                    query.append(_FILTER_SQL_COUNT_DDMSTRUCTURE_WHERE);
3621    
3622                    query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
3623    
3624                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
3625                                    DDMStructure.class.getName(),
3626                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
3627    
3628                    Session session = null;
3629    
3630                    try {
3631                            session = openSession();
3632    
3633                            SQLQuery q = session.createSQLQuery(sql);
3634    
3635                            q.addScalar(COUNT_COLUMN_NAME,
3636                                    com.liferay.portal.kernel.dao.orm.Type.LONG);
3637    
3638                            QueryPos qPos = QueryPos.getInstance(q);
3639    
3640                            qPos.add(groupId);
3641    
3642                            Long count = (Long)q.uniqueResult();
3643    
3644                            return count.intValue();
3645                    }
3646                    catch (Exception e) {
3647                            throw processException(e);
3648                    }
3649                    finally {
3650                            closeSession(session);
3651                    }
3652            }
3653    
3654            /**
3655             * Returns the number of d d m structures where classNameId = &#63;.
3656             *
3657             * @param classNameId the class name ID
3658             * @return the number of matching d d m structures
3659             * @throws SystemException if a system exception occurred
3660             */
3661            public int countByClassNameId(long classNameId) throws SystemException {
3662                    Object[] finderArgs = new Object[] { classNameId };
3663    
3664                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_CLASSNAMEID,
3665                                    finderArgs, this);
3666    
3667                    if (count == null) {
3668                            StringBundler query = new StringBundler(2);
3669    
3670                            query.append(_SQL_COUNT_DDMSTRUCTURE_WHERE);
3671    
3672                            query.append(_FINDER_COLUMN_CLASSNAMEID_CLASSNAMEID_2);
3673    
3674                            String sql = query.toString();
3675    
3676                            Session session = null;
3677    
3678                            try {
3679                                    session = openSession();
3680    
3681                                    Query q = session.createQuery(sql);
3682    
3683                                    QueryPos qPos = QueryPos.getInstance(q);
3684    
3685                                    qPos.add(classNameId);
3686    
3687                                    count = (Long)q.uniqueResult();
3688                            }
3689                            catch (Exception e) {
3690                                    throw processException(e);
3691                            }
3692                            finally {
3693                                    if (count == null) {
3694                                            count = Long.valueOf(0);
3695                                    }
3696    
3697                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_CLASSNAMEID,
3698                                            finderArgs, count);
3699    
3700                                    closeSession(session);
3701                            }
3702                    }
3703    
3704                    return count.intValue();
3705            }
3706    
3707            /**
3708             * Returns the number of d d m structures where groupId = &#63; and structureKey = &#63;.
3709             *
3710             * @param groupId the group ID
3711             * @param structureKey the structure key
3712             * @return the number of matching d d m structures
3713             * @throws SystemException if a system exception occurred
3714             */
3715            public int countByG_S(long groupId, String structureKey)
3716                    throws SystemException {
3717                    Object[] finderArgs = new Object[] { groupId, structureKey };
3718    
3719                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_G_S,
3720                                    finderArgs, this);
3721    
3722                    if (count == null) {
3723                            StringBundler query = new StringBundler(3);
3724    
3725                            query.append(_SQL_COUNT_DDMSTRUCTURE_WHERE);
3726    
3727                            query.append(_FINDER_COLUMN_G_S_GROUPID_2);
3728    
3729                            if (structureKey == null) {
3730                                    query.append(_FINDER_COLUMN_G_S_STRUCTUREKEY_1);
3731                            }
3732                            else {
3733                                    if (structureKey.equals(StringPool.BLANK)) {
3734                                            query.append(_FINDER_COLUMN_G_S_STRUCTUREKEY_3);
3735                                    }
3736                                    else {
3737                                            query.append(_FINDER_COLUMN_G_S_STRUCTUREKEY_2);
3738                                    }
3739                            }
3740    
3741                            String sql = query.toString();
3742    
3743                            Session session = null;
3744    
3745                            try {
3746                                    session = openSession();
3747    
3748                                    Query q = session.createQuery(sql);
3749    
3750                                    QueryPos qPos = QueryPos.getInstance(q);
3751    
3752                                    qPos.add(groupId);
3753    
3754                                    if (structureKey != null) {
3755                                            qPos.add(structureKey);
3756                                    }
3757    
3758                                    count = (Long)q.uniqueResult();
3759                            }
3760                            catch (Exception e) {
3761                                    throw processException(e);
3762                            }
3763                            finally {
3764                                    if (count == null) {
3765                                            count = Long.valueOf(0);
3766                                    }
3767    
3768                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_G_S, finderArgs,
3769                                            count);
3770    
3771                                    closeSession(session);
3772                            }
3773                    }
3774    
3775                    return count.intValue();
3776            }
3777    
3778            /**
3779             * Returns the number of d d m structures where groupId = &#63; and name = &#63; and description = &#63;.
3780             *
3781             * @param groupId the group ID
3782             * @param name the name
3783             * @param description the description
3784             * @return the number of matching d d m structures
3785             * @throws SystemException if a system exception occurred
3786             */
3787            public int countByG_N_D(long groupId, String name, String description)
3788                    throws SystemException {
3789                    Object[] finderArgs = new Object[] { groupId, name, description };
3790    
3791                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_G_N_D,
3792                                    finderArgs, this);
3793    
3794                    if (count == null) {
3795                            StringBundler query = new StringBundler(4);
3796    
3797                            query.append(_SQL_COUNT_DDMSTRUCTURE_WHERE);
3798    
3799                            query.append(_FINDER_COLUMN_G_N_D_GROUPID_2);
3800    
3801                            if (name == null) {
3802                                    query.append(_FINDER_COLUMN_G_N_D_NAME_1);
3803                            }
3804                            else {
3805                                    if (name.equals(StringPool.BLANK)) {
3806                                            query.append(_FINDER_COLUMN_G_N_D_NAME_3);
3807                                    }
3808                                    else {
3809                                            query.append(_FINDER_COLUMN_G_N_D_NAME_2);
3810                                    }
3811                            }
3812    
3813                            if (description == null) {
3814                                    query.append(_FINDER_COLUMN_G_N_D_DESCRIPTION_1);
3815                            }
3816                            else {
3817                                    if (description.equals(StringPool.BLANK)) {
3818                                            query.append(_FINDER_COLUMN_G_N_D_DESCRIPTION_3);
3819                                    }
3820                                    else {
3821                                            query.append(_FINDER_COLUMN_G_N_D_DESCRIPTION_2);
3822                                    }
3823                            }
3824    
3825                            String sql = query.toString();
3826    
3827                            Session session = null;
3828    
3829                            try {
3830                                    session = openSession();
3831    
3832                                    Query q = session.createQuery(sql);
3833    
3834                                    QueryPos qPos = QueryPos.getInstance(q);
3835    
3836                                    qPos.add(groupId);
3837    
3838                                    if (name != null) {
3839                                            qPos.add(name);
3840                                    }
3841    
3842                                    if (description != null) {
3843                                            qPos.add(description);
3844                                    }
3845    
3846                                    count = (Long)q.uniqueResult();
3847                            }
3848                            catch (Exception e) {
3849                                    throw processException(e);
3850                            }
3851                            finally {
3852                                    if (count == null) {
3853                                            count = Long.valueOf(0);
3854                                    }
3855    
3856                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_G_N_D,
3857                                            finderArgs, count);
3858    
3859                                    closeSession(session);
3860                            }
3861                    }
3862    
3863                    return count.intValue();
3864            }
3865    
3866            /**
3867             * Returns the number of d d m structures that the user has permission to view where groupId = &#63; and name = &#63; and description = &#63;.
3868             *
3869             * @param groupId the group ID
3870             * @param name the name
3871             * @param description the description
3872             * @return the number of matching d d m structures that the user has permission to view
3873             * @throws SystemException if a system exception occurred
3874             */
3875            public int filterCountByG_N_D(long groupId, String name, String description)
3876                    throws SystemException {
3877                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
3878                            return countByG_N_D(groupId, name, description);
3879                    }
3880    
3881                    StringBundler query = new StringBundler(4);
3882    
3883                    query.append(_FILTER_SQL_COUNT_DDMSTRUCTURE_WHERE);
3884    
3885                    query.append(_FINDER_COLUMN_G_N_D_GROUPID_2);
3886    
3887                    if (name == null) {
3888                            query.append(_FINDER_COLUMN_G_N_D_NAME_1);
3889                    }
3890                    else {
3891                            if (name.equals(StringPool.BLANK)) {
3892                                    query.append(_FINDER_COLUMN_G_N_D_NAME_3);
3893                            }
3894                            else {
3895                                    query.append(_FINDER_COLUMN_G_N_D_NAME_2);
3896                            }
3897                    }
3898    
3899                    if (description == null) {
3900                            query.append(_FINDER_COLUMN_G_N_D_DESCRIPTION_1);
3901                    }
3902                    else {
3903                            if (description.equals(StringPool.BLANK)) {
3904                                    query.append(_FINDER_COLUMN_G_N_D_DESCRIPTION_3);
3905                            }
3906                            else {
3907                                    query.append(_FINDER_COLUMN_G_N_D_DESCRIPTION_2);
3908                            }
3909                    }
3910    
3911                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
3912                                    DDMStructure.class.getName(),
3913                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
3914    
3915                    Session session = null;
3916    
3917                    try {
3918                            session = openSession();
3919    
3920                            SQLQuery q = session.createSQLQuery(sql);
3921    
3922                            q.addScalar(COUNT_COLUMN_NAME,
3923                                    com.liferay.portal.kernel.dao.orm.Type.LONG);
3924    
3925                            QueryPos qPos = QueryPos.getInstance(q);
3926    
3927                            qPos.add(groupId);
3928    
3929                            if (name != null) {
3930                                    qPos.add(name);
3931                            }
3932    
3933                            if (description != null) {
3934                                    qPos.add(description);
3935                            }
3936    
3937                            Long count = (Long)q.uniqueResult();
3938    
3939                            return count.intValue();
3940                    }
3941                    catch (Exception e) {
3942                            throw processException(e);
3943                    }
3944                    finally {
3945                            closeSession(session);
3946                    }
3947            }
3948    
3949            /**
3950             * Returns the number of d d m structures.
3951             *
3952             * @return the number of d d m structures
3953             * @throws SystemException if a system exception occurred
3954             */
3955            public int countAll() throws SystemException {
3956                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_ALL,
3957                                    FINDER_ARGS_EMPTY, this);
3958    
3959                    if (count == null) {
3960                            Session session = null;
3961    
3962                            try {
3963                                    session = openSession();
3964    
3965                                    Query q = session.createQuery(_SQL_COUNT_DDMSTRUCTURE);
3966    
3967                                    count = (Long)q.uniqueResult();
3968                            }
3969                            catch (Exception e) {
3970                                    throw processException(e);
3971                            }
3972                            finally {
3973                                    if (count == null) {
3974                                            count = Long.valueOf(0);
3975                                    }
3976    
3977                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_ALL,
3978                                            FINDER_ARGS_EMPTY, count);
3979    
3980                                    closeSession(session);
3981                            }
3982                    }
3983    
3984                    return count.intValue();
3985            }
3986    
3987            /**
3988             * Initializes the d d m structure persistence.
3989             */
3990            public void afterPropertiesSet() {
3991                    String[] listenerClassNames = StringUtil.split(GetterUtil.getString(
3992                                            com.liferay.portal.util.PropsUtil.get(
3993                                                    "value.object.listener.com.liferay.portlet.dynamicdatamapping.model.DDMStructure")));
3994    
3995                    if (listenerClassNames.length > 0) {
3996                            try {
3997                                    List<ModelListener<DDMStructure>> listenersList = new ArrayList<ModelListener<DDMStructure>>();
3998    
3999                                    for (String listenerClassName : listenerClassNames) {
4000                                            listenersList.add((ModelListener<DDMStructure>)InstanceFactory.newInstance(
4001                                                            listenerClassName));
4002                                    }
4003    
4004                                    listeners = listenersList.toArray(new ModelListener[listenersList.size()]);
4005                            }
4006                            catch (Exception e) {
4007                                    _log.error(e);
4008                            }
4009                    }
4010            }
4011    
4012            public void destroy() {
4013                    EntityCacheUtil.removeCache(DDMStructureImpl.class.getName());
4014                    FinderCacheUtil.removeCache(FINDER_CLASS_NAME_ENTITY);
4015                    FinderCacheUtil.removeCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
4016            }
4017    
4018            @BeanReference(type = DDMContentPersistence.class)
4019            protected DDMContentPersistence ddmContentPersistence;
4020            @BeanReference(type = DDMStorageLinkPersistence.class)
4021            protected DDMStorageLinkPersistence ddmStorageLinkPersistence;
4022            @BeanReference(type = DDMStructurePersistence.class)
4023            protected DDMStructurePersistence ddmStructurePersistence;
4024            @BeanReference(type = DDMStructureLinkPersistence.class)
4025            protected DDMStructureLinkPersistence ddmStructureLinkPersistence;
4026            @BeanReference(type = DDMTemplatePersistence.class)
4027            protected DDMTemplatePersistence ddmTemplatePersistence;
4028            @BeanReference(type = ResourcePersistence.class)
4029            protected ResourcePersistence resourcePersistence;
4030            @BeanReference(type = UserPersistence.class)
4031            protected UserPersistence userPersistence;
4032            @BeanReference(type = DLFileEntryTypePersistence.class)
4033            protected DLFileEntryTypePersistence dlFileEntryTypePersistence;
4034            private static final String _SQL_SELECT_DDMSTRUCTURE = "SELECT ddmStructure FROM DDMStructure ddmStructure";
4035            private static final String _SQL_SELECT_DDMSTRUCTURE_WHERE = "SELECT ddmStructure FROM DDMStructure ddmStructure WHERE ";
4036            private static final String _SQL_COUNT_DDMSTRUCTURE = "SELECT COUNT(ddmStructure) FROM DDMStructure ddmStructure";
4037            private static final String _SQL_COUNT_DDMSTRUCTURE_WHERE = "SELECT COUNT(ddmStructure) FROM DDMStructure ddmStructure WHERE ";
4038            private static final String _FINDER_COLUMN_UUID_UUID_1 = "ddmStructure.uuid IS NULL";
4039            private static final String _FINDER_COLUMN_UUID_UUID_2 = "ddmStructure.uuid = ?";
4040            private static final String _FINDER_COLUMN_UUID_UUID_3 = "(ddmStructure.uuid IS NULL OR ddmStructure.uuid = ?)";
4041            private static final String _FINDER_COLUMN_UUID_G_UUID_1 = "ddmStructure.uuid IS NULL AND ";
4042            private static final String _FINDER_COLUMN_UUID_G_UUID_2 = "ddmStructure.uuid = ? AND ";
4043            private static final String _FINDER_COLUMN_UUID_G_UUID_3 = "(ddmStructure.uuid IS NULL OR ddmStructure.uuid = ?) AND ";
4044            private static final String _FINDER_COLUMN_UUID_G_GROUPID_2 = "ddmStructure.groupId = ?";
4045            private static final String _FINDER_COLUMN_GROUPID_GROUPID_2 = "ddmStructure.groupId = ?";
4046            private static final String _FINDER_COLUMN_CLASSNAMEID_CLASSNAMEID_2 = "ddmStructure.classNameId = ?";
4047            private static final String _FINDER_COLUMN_G_S_GROUPID_2 = "ddmStructure.groupId = ? AND ";
4048            private static final String _FINDER_COLUMN_G_S_STRUCTUREKEY_1 = "ddmStructure.structureKey IS NULL";
4049            private static final String _FINDER_COLUMN_G_S_STRUCTUREKEY_2 = "ddmStructure.structureKey = ?";
4050            private static final String _FINDER_COLUMN_G_S_STRUCTUREKEY_3 = "(ddmStructure.structureKey IS NULL OR ddmStructure.structureKey = ?)";
4051            private static final String _FINDER_COLUMN_G_N_D_GROUPID_2 = "ddmStructure.groupId = ? AND ";
4052            private static final String _FINDER_COLUMN_G_N_D_NAME_1 = "ddmStructure.name IS NULL AND ";
4053            private static final String _FINDER_COLUMN_G_N_D_NAME_2 = "ddmStructure.name = ? AND ";
4054            private static final String _FINDER_COLUMN_G_N_D_NAME_3 = "(ddmStructure.name IS NULL OR ddmStructure.name = ?) AND ";
4055            private static final String _FINDER_COLUMN_G_N_D_DESCRIPTION_1 = "ddmStructure.description IS NULL";
4056            private static final String _FINDER_COLUMN_G_N_D_DESCRIPTION_2 = "ddmStructure.description = ?";
4057            private static final String _FINDER_COLUMN_G_N_D_DESCRIPTION_3 = "(ddmStructure.description IS NULL OR ddmStructure.description = ?)";
4058            private static final String _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN = "ddmStructure.structureId";
4059            private static final String _FILTER_SQL_SELECT_DDMSTRUCTURE_WHERE = "SELECT DISTINCT {ddmStructure.*} FROM DDMStructure ddmStructure WHERE ";
4060            private static final String _FILTER_SQL_SELECT_DDMSTRUCTURE_NO_INLINE_DISTINCT_WHERE_1 =
4061                    "SELECT {DDMStructure.*} FROM (SELECT DISTINCT ddmStructure.structureId FROM DDMStructure ddmStructure WHERE ";
4062            private static final String _FILTER_SQL_SELECT_DDMSTRUCTURE_NO_INLINE_DISTINCT_WHERE_2 =
4063                    ") TEMP_TABLE INNER JOIN DDMStructure ON TEMP_TABLE.structureId = DDMStructure.structureId";
4064            private static final String _FILTER_SQL_COUNT_DDMSTRUCTURE_WHERE = "SELECT COUNT(DISTINCT ddmStructure.structureId) AS COUNT_VALUE FROM DDMStructure ddmStructure WHERE ";
4065            private static final String _FILTER_ENTITY_ALIAS = "ddmStructure";
4066            private static final String _FILTER_ENTITY_TABLE = "DDMStructure";
4067            private static final String _ORDER_BY_ENTITY_ALIAS = "ddmStructure.";
4068            private static final String _ORDER_BY_ENTITY_TABLE = "DDMStructure.";
4069            private static final String _NO_SUCH_ENTITY_WITH_PRIMARY_KEY = "No DDMStructure exists with the primary key ";
4070            private static final String _NO_SUCH_ENTITY_WITH_KEY = "No DDMStructure exists with the key {";
4071            private static final boolean _HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE = com.liferay.portal.util.PropsValues.HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE;
4072            private static Log _log = LogFactoryUtil.getLog(DDMStructurePersistenceImpl.class);
4073            private static DDMStructure _nullDDMStructure = new DDMStructureImpl() {
4074                            @Override
4075                            public Object clone() {
4076                                    return this;
4077                            }
4078    
4079                            @Override
4080                            public CacheModel<DDMStructure> toCacheModel() {
4081                                    return _nullDDMStructureCacheModel;
4082                            }
4083                    };
4084    
4085            private static CacheModel<DDMStructure> _nullDDMStructureCacheModel = new CacheModel<DDMStructure>() {
4086                            public DDMStructure toEntityModel() {
4087                                    return _nullDDMStructure;
4088                            }
4089                    };
4090    }