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