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