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