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.model.CacheModel;
038    import com.liferay.portal.model.ModelListener;
039    import com.liferay.portal.security.permission.InlineSQLHelperUtil;
040    import com.liferay.portal.service.persistence.BatchSessionUtil;
041    import com.liferay.portal.service.persistence.ResourcePersistence;
042    import com.liferay.portal.service.persistence.UserPersistence;
043    import com.liferay.portal.service.persistence.impl.BasePersistenceImpl;
044    
045    import com.liferay.portlet.dynamicdatamapping.NoSuchStructureLinkException;
046    import com.liferay.portlet.dynamicdatamapping.model.DDMStructureLink;
047    import com.liferay.portlet.dynamicdatamapping.model.impl.DDMStructureLinkImpl;
048    import com.liferay.portlet.dynamicdatamapping.model.impl.DDMStructureLinkModelImpl;
049    
050    import java.io.Serializable;
051    
052    import java.util.ArrayList;
053    import java.util.Collections;
054    import java.util.List;
055    
056    /**
057     * The persistence implementation for the d d m structure link service.
058     *
059     * <p>
060     * Caching information and settings can be found in <code>portal.properties</code>
061     * </p>
062     *
063     * @author Brian Wing Shun Chan
064     * @see DDMStructureLinkPersistence
065     * @see DDMStructureLinkUtil
066     * @generated
067     */
068    public class DDMStructureLinkPersistenceImpl extends BasePersistenceImpl<DDMStructureLink>
069            implements DDMStructureLinkPersistence {
070            /*
071             * NOTE FOR DEVELOPERS:
072             *
073             * Never modify or reference this class directly. Always use {@link DDMStructureLinkUtil} to access the d d m structure link persistence. Modify <code>service.xml</code> and rerun ServiceBuilder to regenerate this class.
074             */
075            public static final String FINDER_CLASS_NAME_ENTITY = DDMStructureLinkImpl.class.getName();
076            public static final String FINDER_CLASS_NAME_LIST_WITH_PAGINATION = FINDER_CLASS_NAME_ENTITY +
077                    ".List1";
078            public static final String FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION = FINDER_CLASS_NAME_ENTITY +
079                    ".List2";
080            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_CLASSNAMEID =
081                    new FinderPath(DDMStructureLinkModelImpl.ENTITY_CACHE_ENABLED,
082                            DDMStructureLinkModelImpl.FINDER_CACHE_ENABLED,
083                            DDMStructureLinkImpl.class, FINDER_CLASS_NAME_LIST_WITH_PAGINATION,
084                            "findByClassNameId",
085                            new String[] {
086                                    Long.class.getName(),
087                                    
088                            "java.lang.Integer", "java.lang.Integer",
089                                    "com.liferay.portal.kernel.util.OrderByComparator"
090                            });
091            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_CLASSNAMEID =
092                    new FinderPath(DDMStructureLinkModelImpl.ENTITY_CACHE_ENABLED,
093                            DDMStructureLinkModelImpl.FINDER_CACHE_ENABLED,
094                            DDMStructureLinkImpl.class,
095                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByClassNameId",
096                            new String[] { Long.class.getName() },
097                            DDMStructureLinkModelImpl.CLASSNAMEID_COLUMN_BITMASK);
098            public static final FinderPath FINDER_PATH_COUNT_BY_CLASSNAMEID = new FinderPath(DDMStructureLinkModelImpl.ENTITY_CACHE_ENABLED,
099                            DDMStructureLinkModelImpl.FINDER_CACHE_ENABLED, Long.class,
100                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByClassNameId",
101                            new String[] { Long.class.getName() });
102            public static final FinderPath FINDER_PATH_FETCH_BY_CLASSPK = new FinderPath(DDMStructureLinkModelImpl.ENTITY_CACHE_ENABLED,
103                            DDMStructureLinkModelImpl.FINDER_CACHE_ENABLED,
104                            DDMStructureLinkImpl.class, FINDER_CLASS_NAME_ENTITY,
105                            "fetchByClassPK", new String[] { Long.class.getName() },
106                            DDMStructureLinkModelImpl.CLASSPK_COLUMN_BITMASK);
107            public static final FinderPath FINDER_PATH_COUNT_BY_CLASSPK = new FinderPath(DDMStructureLinkModelImpl.ENTITY_CACHE_ENABLED,
108                            DDMStructureLinkModelImpl.FINDER_CACHE_ENABLED, Long.class,
109                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByClassPK",
110                            new String[] { Long.class.getName() });
111            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_STRUCTUREID =
112                    new FinderPath(DDMStructureLinkModelImpl.ENTITY_CACHE_ENABLED,
113                            DDMStructureLinkModelImpl.FINDER_CACHE_ENABLED,
114                            DDMStructureLinkImpl.class, FINDER_CLASS_NAME_LIST_WITH_PAGINATION,
115                            "findByStructureId",
116                            new String[] {
117                                    Long.class.getName(),
118                                    
119                            "java.lang.Integer", "java.lang.Integer",
120                                    "com.liferay.portal.kernel.util.OrderByComparator"
121                            });
122            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_STRUCTUREID =
123                    new FinderPath(DDMStructureLinkModelImpl.ENTITY_CACHE_ENABLED,
124                            DDMStructureLinkModelImpl.FINDER_CACHE_ENABLED,
125                            DDMStructureLinkImpl.class,
126                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByStructureId",
127                            new String[] { Long.class.getName() },
128                            DDMStructureLinkModelImpl.STRUCTUREID_COLUMN_BITMASK);
129            public static final FinderPath FINDER_PATH_COUNT_BY_STRUCTUREID = new FinderPath(DDMStructureLinkModelImpl.ENTITY_CACHE_ENABLED,
130                            DDMStructureLinkModelImpl.FINDER_CACHE_ENABLED, Long.class,
131                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByStructureId",
132                            new String[] { Long.class.getName() });
133            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_ALL = new FinderPath(DDMStructureLinkModelImpl.ENTITY_CACHE_ENABLED,
134                            DDMStructureLinkModelImpl.FINDER_CACHE_ENABLED,
135                            DDMStructureLinkImpl.class,
136                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findAll", new String[0]);
137            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL = new FinderPath(DDMStructureLinkModelImpl.ENTITY_CACHE_ENABLED,
138                            DDMStructureLinkModelImpl.FINDER_CACHE_ENABLED,
139                            DDMStructureLinkImpl.class, FINDER_CLASS_NAME_LIST_WITH_PAGINATION,
140                            "findAll", new String[0]);
141            public static final FinderPath FINDER_PATH_COUNT_ALL = new FinderPath(DDMStructureLinkModelImpl.ENTITY_CACHE_ENABLED,
142                            DDMStructureLinkModelImpl.FINDER_CACHE_ENABLED, Long.class,
143                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countAll", new String[0]);
144    
145            /**
146             * Caches the d d m structure link in the entity cache if it is enabled.
147             *
148             * @param ddmStructureLink the d d m structure link
149             */
150            public void cacheResult(DDMStructureLink ddmStructureLink) {
151                    EntityCacheUtil.putResult(DDMStructureLinkModelImpl.ENTITY_CACHE_ENABLED,
152                            DDMStructureLinkImpl.class, ddmStructureLink.getPrimaryKey(),
153                            ddmStructureLink);
154    
155                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_CLASSPK,
156                            new Object[] { Long.valueOf(ddmStructureLink.getClassPK()) },
157                            ddmStructureLink);
158    
159                    ddmStructureLink.resetOriginalValues();
160            }
161    
162            /**
163             * Caches the d d m structure links in the entity cache if it is enabled.
164             *
165             * @param ddmStructureLinks the d d m structure links
166             */
167            public void cacheResult(List<DDMStructureLink> ddmStructureLinks) {
168                    for (DDMStructureLink ddmStructureLink : ddmStructureLinks) {
169                            if (EntityCacheUtil.getResult(
170                                                    DDMStructureLinkModelImpl.ENTITY_CACHE_ENABLED,
171                                                    DDMStructureLinkImpl.class,
172                                                    ddmStructureLink.getPrimaryKey()) == null) {
173                                    cacheResult(ddmStructureLink);
174                            }
175                            else {
176                                    ddmStructureLink.resetOriginalValues();
177                            }
178                    }
179            }
180    
181            /**
182             * Clears the cache for all d d m structure links.
183             *
184             * <p>
185             * The {@link com.liferay.portal.kernel.dao.orm.EntityCache} and {@link com.liferay.portal.kernel.dao.orm.FinderCache} are both cleared by this method.
186             * </p>
187             */
188            @Override
189            public void clearCache() {
190                    if (_HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE) {
191                            CacheRegistryUtil.clear(DDMStructureLinkImpl.class.getName());
192                    }
193    
194                    EntityCacheUtil.clearCache(DDMStructureLinkImpl.class.getName());
195    
196                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_ENTITY);
197                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
198                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
199            }
200    
201            /**
202             * Clears the cache for the d d m structure link.
203             *
204             * <p>
205             * The {@link com.liferay.portal.kernel.dao.orm.EntityCache} and {@link com.liferay.portal.kernel.dao.orm.FinderCache} are both cleared by this method.
206             * </p>
207             */
208            @Override
209            public void clearCache(DDMStructureLink ddmStructureLink) {
210                    EntityCacheUtil.removeResult(DDMStructureLinkModelImpl.ENTITY_CACHE_ENABLED,
211                            DDMStructureLinkImpl.class, ddmStructureLink.getPrimaryKey());
212    
213                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
214                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
215    
216                    FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_CLASSPK,
217                            new Object[] { Long.valueOf(ddmStructureLink.getClassPK()) });
218            }
219    
220            /**
221             * Creates a new d d m structure link with the primary key. Does not add the d d m structure link to the database.
222             *
223             * @param structureLinkId the primary key for the new d d m structure link
224             * @return the new d d m structure link
225             */
226            public DDMStructureLink create(long structureLinkId) {
227                    DDMStructureLink ddmStructureLink = new DDMStructureLinkImpl();
228    
229                    ddmStructureLink.setNew(true);
230                    ddmStructureLink.setPrimaryKey(structureLinkId);
231    
232                    return ddmStructureLink;
233            }
234    
235            /**
236             * Removes the d d m structure link with the primary key from the database. Also notifies the appropriate model listeners.
237             *
238             * @param primaryKey the primary key of the d d m structure link
239             * @return the d d m structure link that was removed
240             * @throws com.liferay.portal.NoSuchModelException if a d d m structure link with the primary key could not be found
241             * @throws SystemException if a system exception occurred
242             */
243            @Override
244            public DDMStructureLink remove(Serializable primaryKey)
245                    throws NoSuchModelException, SystemException {
246                    return remove(((Long)primaryKey).longValue());
247            }
248    
249            /**
250             * Removes the d d m structure link with the primary key from the database. Also notifies the appropriate model listeners.
251             *
252             * @param structureLinkId the primary key of the d d m structure link
253             * @return the d d m structure link that was removed
254             * @throws com.liferay.portlet.dynamicdatamapping.NoSuchStructureLinkException if a d d m structure link with the primary key could not be found
255             * @throws SystemException if a system exception occurred
256             */
257            public DDMStructureLink remove(long structureLinkId)
258                    throws NoSuchStructureLinkException, SystemException {
259                    Session session = null;
260    
261                    try {
262                            session = openSession();
263    
264                            DDMStructureLink ddmStructureLink = (DDMStructureLink)session.get(DDMStructureLinkImpl.class,
265                                            Long.valueOf(structureLinkId));
266    
267                            if (ddmStructureLink == null) {
268                                    if (_log.isWarnEnabled()) {
269                                            _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
270                                                    structureLinkId);
271                                    }
272    
273                                    throw new NoSuchStructureLinkException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
274                                            structureLinkId);
275                            }
276    
277                            return ddmStructureLinkPersistence.remove(ddmStructureLink);
278                    }
279                    catch (NoSuchStructureLinkException nsee) {
280                            throw nsee;
281                    }
282                    catch (Exception e) {
283                            throw processException(e);
284                    }
285                    finally {
286                            closeSession(session);
287                    }
288            }
289    
290            /**
291             * Removes the d d m structure link from the database. Also notifies the appropriate model listeners.
292             *
293             * @param ddmStructureLink the d d m structure link
294             * @return the d d m structure link that was removed
295             * @throws SystemException if a system exception occurred
296             */
297            @Override
298            public DDMStructureLink remove(DDMStructureLink ddmStructureLink)
299                    throws SystemException {
300                    return super.remove(ddmStructureLink);
301            }
302    
303            @Override
304            protected DDMStructureLink removeImpl(DDMStructureLink ddmStructureLink)
305                    throws SystemException {
306                    ddmStructureLink = toUnwrappedModel(ddmStructureLink);
307    
308                    Session session = null;
309    
310                    try {
311                            session = openSession();
312    
313                            BatchSessionUtil.delete(session, ddmStructureLink);
314                    }
315                    catch (Exception e) {
316                            throw processException(e);
317                    }
318                    finally {
319                            closeSession(session);
320                    }
321    
322                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
323                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
324    
325                    DDMStructureLinkModelImpl ddmStructureLinkModelImpl = (DDMStructureLinkModelImpl)ddmStructureLink;
326    
327                    FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_CLASSPK,
328                            new Object[] { Long.valueOf(ddmStructureLinkModelImpl.getClassPK()) });
329    
330                    EntityCacheUtil.removeResult(DDMStructureLinkModelImpl.ENTITY_CACHE_ENABLED,
331                            DDMStructureLinkImpl.class, ddmStructureLink.getPrimaryKey());
332    
333                    return ddmStructureLink;
334            }
335    
336            @Override
337            public DDMStructureLink updateImpl(
338                    com.liferay.portlet.dynamicdatamapping.model.DDMStructureLink ddmStructureLink,
339                    boolean merge) throws SystemException {
340                    ddmStructureLink = toUnwrappedModel(ddmStructureLink);
341    
342                    boolean isNew = ddmStructureLink.isNew();
343    
344                    DDMStructureLinkModelImpl ddmStructureLinkModelImpl = (DDMStructureLinkModelImpl)ddmStructureLink;
345    
346                    Session session = null;
347    
348                    try {
349                            session = openSession();
350    
351                            BatchSessionUtil.update(session, ddmStructureLink, merge);
352    
353                            ddmStructureLink.setNew(false);
354                    }
355                    catch (Exception e) {
356                            throw processException(e);
357                    }
358                    finally {
359                            closeSession(session);
360                    }
361    
362                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
363    
364                    if (isNew || !DDMStructureLinkModelImpl.COLUMN_BITMASK_ENABLED) {
365                            FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
366                    }
367    
368                    else {
369                            if ((ddmStructureLinkModelImpl.getColumnBitmask() &
370                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_CLASSNAMEID.getColumnBitmask()) != 0) {
371                                    Object[] args = new Object[] {
372                                                    Long.valueOf(ddmStructureLinkModelImpl.getOriginalClassNameId())
373                                            };
374    
375                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_CLASSNAMEID,
376                                            args);
377                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_CLASSNAMEID,
378                                            args);
379    
380                                    args = new Object[] {
381                                                    Long.valueOf(ddmStructureLinkModelImpl.getClassNameId())
382                                            };
383    
384                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_CLASSNAMEID,
385                                            args);
386                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_CLASSNAMEID,
387                                            args);
388                            }
389    
390                            if ((ddmStructureLinkModelImpl.getColumnBitmask() &
391                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_STRUCTUREID.getColumnBitmask()) != 0) {
392                                    Object[] args = new Object[] {
393                                                    Long.valueOf(ddmStructureLinkModelImpl.getOriginalStructureId())
394                                            };
395    
396                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_STRUCTUREID,
397                                            args);
398                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_STRUCTUREID,
399                                            args);
400    
401                                    args = new Object[] {
402                                                    Long.valueOf(ddmStructureLinkModelImpl.getStructureId())
403                                            };
404    
405                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_STRUCTUREID,
406                                            args);
407                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_STRUCTUREID,
408                                            args);
409                            }
410                    }
411    
412                    EntityCacheUtil.putResult(DDMStructureLinkModelImpl.ENTITY_CACHE_ENABLED,
413                            DDMStructureLinkImpl.class, ddmStructureLink.getPrimaryKey(),
414                            ddmStructureLink);
415    
416                    if (isNew) {
417                            FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_CLASSPK,
418                                    new Object[] { Long.valueOf(ddmStructureLink.getClassPK()) },
419                                    ddmStructureLink);
420                    }
421                    else {
422                            if ((ddmStructureLinkModelImpl.getColumnBitmask() &
423                                            FINDER_PATH_FETCH_BY_CLASSPK.getColumnBitmask()) != 0) {
424                                    Object[] args = new Object[] {
425                                                    Long.valueOf(ddmStructureLinkModelImpl.getOriginalClassPK())
426                                            };
427    
428                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_CLASSPK, args);
429                                    FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_CLASSPK, args);
430    
431                                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_CLASSPK,
432                                            new Object[] { Long.valueOf(ddmStructureLink.getClassPK()) },
433                                            ddmStructureLink);
434                            }
435                    }
436    
437                    return ddmStructureLink;
438            }
439    
440            protected DDMStructureLink toUnwrappedModel(
441                    DDMStructureLink ddmStructureLink) {
442                    if (ddmStructureLink instanceof DDMStructureLinkImpl) {
443                            return ddmStructureLink;
444                    }
445    
446                    DDMStructureLinkImpl ddmStructureLinkImpl = new DDMStructureLinkImpl();
447    
448                    ddmStructureLinkImpl.setNew(ddmStructureLink.isNew());
449                    ddmStructureLinkImpl.setPrimaryKey(ddmStructureLink.getPrimaryKey());
450    
451                    ddmStructureLinkImpl.setStructureLinkId(ddmStructureLink.getStructureLinkId());
452                    ddmStructureLinkImpl.setClassNameId(ddmStructureLink.getClassNameId());
453                    ddmStructureLinkImpl.setClassPK(ddmStructureLink.getClassPK());
454                    ddmStructureLinkImpl.setStructureId(ddmStructureLink.getStructureId());
455    
456                    return ddmStructureLinkImpl;
457            }
458    
459            /**
460             * Returns the d d m structure link with the primary key or throws a {@link com.liferay.portal.NoSuchModelException} if it could not be found.
461             *
462             * @param primaryKey the primary key of the d d m structure link
463             * @return the d d m structure link
464             * @throws com.liferay.portal.NoSuchModelException if a d d m structure link with the primary key could not be found
465             * @throws SystemException if a system exception occurred
466             */
467            @Override
468            public DDMStructureLink findByPrimaryKey(Serializable primaryKey)
469                    throws NoSuchModelException, SystemException {
470                    return findByPrimaryKey(((Long)primaryKey).longValue());
471            }
472    
473            /**
474             * Returns the d d m structure link with the primary key or throws a {@link com.liferay.portlet.dynamicdatamapping.NoSuchStructureLinkException} if it could not be found.
475             *
476             * @param structureLinkId the primary key of the d d m structure link
477             * @return the d d m structure link
478             * @throws com.liferay.portlet.dynamicdatamapping.NoSuchStructureLinkException if a d d m structure link with the primary key could not be found
479             * @throws SystemException if a system exception occurred
480             */
481            public DDMStructureLink findByPrimaryKey(long structureLinkId)
482                    throws NoSuchStructureLinkException, SystemException {
483                    DDMStructureLink ddmStructureLink = fetchByPrimaryKey(structureLinkId);
484    
485                    if (ddmStructureLink == null) {
486                            if (_log.isWarnEnabled()) {
487                                    _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + structureLinkId);
488                            }
489    
490                            throw new NoSuchStructureLinkException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
491                                    structureLinkId);
492                    }
493    
494                    return ddmStructureLink;
495            }
496    
497            /**
498             * Returns the d d m structure link with the primary key or returns <code>null</code> if it could not be found.
499             *
500             * @param primaryKey the primary key of the d d m structure link
501             * @return the d d m structure link, or <code>null</code> if a d d m structure link with the primary key could not be found
502             * @throws SystemException if a system exception occurred
503             */
504            @Override
505            public DDMStructureLink fetchByPrimaryKey(Serializable primaryKey)
506                    throws SystemException {
507                    return fetchByPrimaryKey(((Long)primaryKey).longValue());
508            }
509    
510            /**
511             * Returns the d d m structure link with the primary key or returns <code>null</code> if it could not be found.
512             *
513             * @param structureLinkId the primary key of the d d m structure link
514             * @return the d d m structure link, or <code>null</code> if a d d m structure link with the primary key could not be found
515             * @throws SystemException if a system exception occurred
516             */
517            public DDMStructureLink fetchByPrimaryKey(long structureLinkId)
518                    throws SystemException {
519                    DDMStructureLink ddmStructureLink = (DDMStructureLink)EntityCacheUtil.getResult(DDMStructureLinkModelImpl.ENTITY_CACHE_ENABLED,
520                                    DDMStructureLinkImpl.class, structureLinkId);
521    
522                    if (ddmStructureLink == _nullDDMStructureLink) {
523                            return null;
524                    }
525    
526                    if (ddmStructureLink == null) {
527                            Session session = null;
528    
529                            boolean hasException = false;
530    
531                            try {
532                                    session = openSession();
533    
534                                    ddmStructureLink = (DDMStructureLink)session.get(DDMStructureLinkImpl.class,
535                                                    Long.valueOf(structureLinkId));
536                            }
537                            catch (Exception e) {
538                                    hasException = true;
539    
540                                    throw processException(e);
541                            }
542                            finally {
543                                    if (ddmStructureLink != null) {
544                                            cacheResult(ddmStructureLink);
545                                    }
546                                    else if (!hasException) {
547                                            EntityCacheUtil.putResult(DDMStructureLinkModelImpl.ENTITY_CACHE_ENABLED,
548                                                    DDMStructureLinkImpl.class, structureLinkId,
549                                                    _nullDDMStructureLink);
550                                    }
551    
552                                    closeSession(session);
553                            }
554                    }
555    
556                    return ddmStructureLink;
557            }
558    
559            /**
560             * Returns all the d d m structure links where classNameId = &#63;.
561             *
562             * @param classNameId the class name ID
563             * @return the matching d d m structure links
564             * @throws SystemException if a system exception occurred
565             */
566            public List<DDMStructureLink> findByClassNameId(long classNameId)
567                    throws SystemException {
568                    return findByClassNameId(classNameId, QueryUtil.ALL_POS,
569                            QueryUtil.ALL_POS, null);
570            }
571    
572            /**
573             * Returns a range of all the d d m structure links where classNameId = &#63;.
574             *
575             * <p>
576             * 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.
577             * </p>
578             *
579             * @param classNameId the class name ID
580             * @param start the lower bound of the range of d d m structure links
581             * @param end the upper bound of the range of d d m structure links (not inclusive)
582             * @return the range of matching d d m structure links
583             * @throws SystemException if a system exception occurred
584             */
585            public List<DDMStructureLink> findByClassNameId(long classNameId,
586                    int start, int end) throws SystemException {
587                    return findByClassNameId(classNameId, start, end, null);
588            }
589    
590            /**
591             * Returns an ordered range of all the d d m structure links where classNameId = &#63;.
592             *
593             * <p>
594             * 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.
595             * </p>
596             *
597             * @param classNameId the class name ID
598             * @param start the lower bound of the range of d d m structure links
599             * @param end the upper bound of the range of d d m structure links (not inclusive)
600             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
601             * @return the ordered range of matching d d m structure links
602             * @throws SystemException if a system exception occurred
603             */
604            public List<DDMStructureLink> findByClassNameId(long classNameId,
605                    int start, int end, OrderByComparator orderByComparator)
606                    throws SystemException {
607                    FinderPath finderPath = null;
608                    Object[] finderArgs = null;
609    
610                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
611                                    (orderByComparator == null)) {
612                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_CLASSNAMEID;
613                            finderArgs = new Object[] { classNameId };
614                    }
615                    else {
616                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_CLASSNAMEID;
617                            finderArgs = new Object[] { classNameId, start, end, orderByComparator };
618                    }
619    
620                    List<DDMStructureLink> list = (List<DDMStructureLink>)FinderCacheUtil.getResult(finderPath,
621                                    finderArgs, this);
622    
623                    if (list == null) {
624                            StringBundler query = null;
625    
626                            if (orderByComparator != null) {
627                                    query = new StringBundler(3 +
628                                                    (orderByComparator.getOrderByFields().length * 3));
629                            }
630                            else {
631                                    query = new StringBundler(2);
632                            }
633    
634                            query.append(_SQL_SELECT_DDMSTRUCTURELINK_WHERE);
635    
636                            query.append(_FINDER_COLUMN_CLASSNAMEID_CLASSNAMEID_2);
637    
638                            if (orderByComparator != null) {
639                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
640                                            orderByComparator);
641                            }
642    
643                            String sql = query.toString();
644    
645                            Session session = null;
646    
647                            try {
648                                    session = openSession();
649    
650                                    Query q = session.createQuery(sql);
651    
652                                    QueryPos qPos = QueryPos.getInstance(q);
653    
654                                    qPos.add(classNameId);
655    
656                                    list = (List<DDMStructureLink>)QueryUtil.list(q, getDialect(),
657                                                    start, end);
658                            }
659                            catch (Exception e) {
660                                    throw processException(e);
661                            }
662                            finally {
663                                    if (list == null) {
664                                            FinderCacheUtil.removeResult(finderPath, finderArgs);
665                                    }
666                                    else {
667                                            cacheResult(list);
668    
669                                            FinderCacheUtil.putResult(finderPath, finderArgs, list);
670                                    }
671    
672                                    closeSession(session);
673                            }
674                    }
675    
676                    return list;
677            }
678    
679            /**
680             * Returns the first d d m structure link in the ordered set where classNameId = &#63;.
681             *
682             * <p>
683             * 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.
684             * </p>
685             *
686             * @param classNameId the class name ID
687             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
688             * @return the first matching d d m structure link
689             * @throws com.liferay.portlet.dynamicdatamapping.NoSuchStructureLinkException if a matching d d m structure link could not be found
690             * @throws SystemException if a system exception occurred
691             */
692            public DDMStructureLink findByClassNameId_First(long classNameId,
693                    OrderByComparator orderByComparator)
694                    throws NoSuchStructureLinkException, SystemException {
695                    List<DDMStructureLink> list = findByClassNameId(classNameId, 0, 1,
696                                    orderByComparator);
697    
698                    if (list.isEmpty()) {
699                            StringBundler msg = new StringBundler(4);
700    
701                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
702    
703                            msg.append("classNameId=");
704                            msg.append(classNameId);
705    
706                            msg.append(StringPool.CLOSE_CURLY_BRACE);
707    
708                            throw new NoSuchStructureLinkException(msg.toString());
709                    }
710                    else {
711                            return list.get(0);
712                    }
713            }
714    
715            /**
716             * Returns the last d d m structure link in the ordered set where classNameId = &#63;.
717             *
718             * <p>
719             * 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.
720             * </p>
721             *
722             * @param classNameId the class name ID
723             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
724             * @return the last matching d d m structure link
725             * @throws com.liferay.portlet.dynamicdatamapping.NoSuchStructureLinkException if a matching d d m structure link could not be found
726             * @throws SystemException if a system exception occurred
727             */
728            public DDMStructureLink findByClassNameId_Last(long classNameId,
729                    OrderByComparator orderByComparator)
730                    throws NoSuchStructureLinkException, SystemException {
731                    int count = countByClassNameId(classNameId);
732    
733                    List<DDMStructureLink> list = findByClassNameId(classNameId, count - 1,
734                                    count, orderByComparator);
735    
736                    if (list.isEmpty()) {
737                            StringBundler msg = new StringBundler(4);
738    
739                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
740    
741                            msg.append("classNameId=");
742                            msg.append(classNameId);
743    
744                            msg.append(StringPool.CLOSE_CURLY_BRACE);
745    
746                            throw new NoSuchStructureLinkException(msg.toString());
747                    }
748                    else {
749                            return list.get(0);
750                    }
751            }
752    
753            /**
754             * Returns the d d m structure links before and after the current d d m structure link in the ordered set where classNameId = &#63;.
755             *
756             * <p>
757             * 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.
758             * </p>
759             *
760             * @param structureLinkId the primary key of the current d d m structure link
761             * @param classNameId the class name ID
762             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
763             * @return the previous, current, and next d d m structure link
764             * @throws com.liferay.portlet.dynamicdatamapping.NoSuchStructureLinkException if a d d m structure link with the primary key could not be found
765             * @throws SystemException if a system exception occurred
766             */
767            public DDMStructureLink[] findByClassNameId_PrevAndNext(
768                    long structureLinkId, long classNameId,
769                    OrderByComparator orderByComparator)
770                    throws NoSuchStructureLinkException, SystemException {
771                    DDMStructureLink ddmStructureLink = findByPrimaryKey(structureLinkId);
772    
773                    Session session = null;
774    
775                    try {
776                            session = openSession();
777    
778                            DDMStructureLink[] array = new DDMStructureLinkImpl[3];
779    
780                            array[0] = getByClassNameId_PrevAndNext(session, ddmStructureLink,
781                                            classNameId, orderByComparator, true);
782    
783                            array[1] = ddmStructureLink;
784    
785                            array[2] = getByClassNameId_PrevAndNext(session, ddmStructureLink,
786                                            classNameId, orderByComparator, false);
787    
788                            return array;
789                    }
790                    catch (Exception e) {
791                            throw processException(e);
792                    }
793                    finally {
794                            closeSession(session);
795                    }
796            }
797    
798            protected DDMStructureLink getByClassNameId_PrevAndNext(Session session,
799                    DDMStructureLink ddmStructureLink, long classNameId,
800                    OrderByComparator orderByComparator, boolean previous) {
801                    StringBundler query = null;
802    
803                    if (orderByComparator != null) {
804                            query = new StringBundler(6 +
805                                            (orderByComparator.getOrderByFields().length * 6));
806                    }
807                    else {
808                            query = new StringBundler(3);
809                    }
810    
811                    query.append(_SQL_SELECT_DDMSTRUCTURELINK_WHERE);
812    
813                    query.append(_FINDER_COLUMN_CLASSNAMEID_CLASSNAMEID_2);
814    
815                    if (orderByComparator != null) {
816                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
817    
818                            if (orderByConditionFields.length > 0) {
819                                    query.append(WHERE_AND);
820                            }
821    
822                            for (int i = 0; i < orderByConditionFields.length; i++) {
823                                    query.append(_ORDER_BY_ENTITY_ALIAS);
824                                    query.append(orderByConditionFields[i]);
825    
826                                    if ((i + 1) < orderByConditionFields.length) {
827                                            if (orderByComparator.isAscending() ^ previous) {
828                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
829                                            }
830                                            else {
831                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
832                                            }
833                                    }
834                                    else {
835                                            if (orderByComparator.isAscending() ^ previous) {
836                                                    query.append(WHERE_GREATER_THAN);
837                                            }
838                                            else {
839                                                    query.append(WHERE_LESSER_THAN);
840                                            }
841                                    }
842                            }
843    
844                            query.append(ORDER_BY_CLAUSE);
845    
846                            String[] orderByFields = orderByComparator.getOrderByFields();
847    
848                            for (int i = 0; i < orderByFields.length; i++) {
849                                    query.append(_ORDER_BY_ENTITY_ALIAS);
850                                    query.append(orderByFields[i]);
851    
852                                    if ((i + 1) < orderByFields.length) {
853                                            if (orderByComparator.isAscending() ^ previous) {
854                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
855                                            }
856                                            else {
857                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
858                                            }
859                                    }
860                                    else {
861                                            if (orderByComparator.isAscending() ^ previous) {
862                                                    query.append(ORDER_BY_ASC);
863                                            }
864                                            else {
865                                                    query.append(ORDER_BY_DESC);
866                                            }
867                                    }
868                            }
869                    }
870    
871                    String sql = query.toString();
872    
873                    Query q = session.createQuery(sql);
874    
875                    q.setFirstResult(0);
876                    q.setMaxResults(2);
877    
878                    QueryPos qPos = QueryPos.getInstance(q);
879    
880                    qPos.add(classNameId);
881    
882                    if (orderByComparator != null) {
883                            Object[] values = orderByComparator.getOrderByConditionValues(ddmStructureLink);
884    
885                            for (Object value : values) {
886                                    qPos.add(value);
887                            }
888                    }
889    
890                    List<DDMStructureLink> list = q.list();
891    
892                    if (list.size() == 2) {
893                            return list.get(1);
894                    }
895                    else {
896                            return null;
897                    }
898            }
899    
900            /**
901             * Returns all the d d m structure links that the user has permission to view where classNameId = &#63;.
902             *
903             * @param classNameId the class name ID
904             * @return the matching d d m structure links that the user has permission to view
905             * @throws SystemException if a system exception occurred
906             */
907            public List<DDMStructureLink> filterFindByClassNameId(long classNameId)
908                    throws SystemException {
909                    return filterFindByClassNameId(classNameId, QueryUtil.ALL_POS,
910                            QueryUtil.ALL_POS, null);
911            }
912    
913            /**
914             * Returns a range of all the d d m structure links that the user has permission to view where classNameId = &#63;.
915             *
916             * <p>
917             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
918             * </p>
919             *
920             * @param classNameId the class name ID
921             * @param start the lower bound of the range of d d m structure links
922             * @param end the upper bound of the range of d d m structure links (not inclusive)
923             * @return the range of matching d d m structure links that the user has permission to view
924             * @throws SystemException if a system exception occurred
925             */
926            public List<DDMStructureLink> filterFindByClassNameId(long classNameId,
927                    int start, int end) throws SystemException {
928                    return filterFindByClassNameId(classNameId, start, end, null);
929            }
930    
931            /**
932             * Returns an ordered range of all the d d m structure links that the user has permissions to view where classNameId = &#63;.
933             *
934             * <p>
935             * 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.
936             * </p>
937             *
938             * @param classNameId the class name ID
939             * @param start the lower bound of the range of d d m structure links
940             * @param end the upper bound of the range of d d m structure links (not inclusive)
941             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
942             * @return the ordered range of matching d d m structure links that the user has permission to view
943             * @throws SystemException if a system exception occurred
944             */
945            public List<DDMStructureLink> filterFindByClassNameId(long classNameId,
946                    int start, int end, OrderByComparator orderByComparator)
947                    throws SystemException {
948                    if (!InlineSQLHelperUtil.isEnabled()) {
949                            return findByClassNameId(classNameId, start, end, orderByComparator);
950                    }
951    
952                    StringBundler query = null;
953    
954                    if (orderByComparator != null) {
955                            query = new StringBundler(3 +
956                                            (orderByComparator.getOrderByFields().length * 3));
957                    }
958                    else {
959                            query = new StringBundler(2);
960                    }
961    
962                    if (getDB().isSupportsInlineDistinct()) {
963                            query.append(_FILTER_SQL_SELECT_DDMSTRUCTURELINK_WHERE);
964                    }
965                    else {
966                            query.append(_FILTER_SQL_SELECT_DDMSTRUCTURELINK_NO_INLINE_DISTINCT_WHERE_1);
967                    }
968    
969                    query.append(_FINDER_COLUMN_CLASSNAMEID_CLASSNAMEID_2);
970    
971                    if (!getDB().isSupportsInlineDistinct()) {
972                            query.append(_FILTER_SQL_SELECT_DDMSTRUCTURELINK_NO_INLINE_DISTINCT_WHERE_2);
973                    }
974    
975                    if (orderByComparator != null) {
976                            if (getDB().isSupportsInlineDistinct()) {
977                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
978                                            orderByComparator);
979                            }
980                            else {
981                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_TABLE,
982                                            orderByComparator);
983                            }
984                    }
985    
986                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
987                                    DDMStructureLink.class.getName(),
988                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN);
989    
990                    Session session = null;
991    
992                    try {
993                            session = openSession();
994    
995                            SQLQuery q = session.createSQLQuery(sql);
996    
997                            if (getDB().isSupportsInlineDistinct()) {
998                                    q.addEntity(_FILTER_ENTITY_ALIAS, DDMStructureLinkImpl.class);
999                            }
1000                            else {
1001                                    q.addEntity(_FILTER_ENTITY_TABLE, DDMStructureLinkImpl.class);
1002                            }
1003    
1004                            QueryPos qPos = QueryPos.getInstance(q);
1005    
1006                            qPos.add(classNameId);
1007    
1008                            return (List<DDMStructureLink>)QueryUtil.list(q, getDialect(),
1009                                    start, end);
1010                    }
1011                    catch (Exception e) {
1012                            throw processException(e);
1013                    }
1014                    finally {
1015                            closeSession(session);
1016                    }
1017            }
1018    
1019            /**
1020             * Returns the d d m structure links before and after the current d d m structure link in the ordered set of d d m structure links that the user has permission to view where classNameId = &#63;.
1021             *
1022             * @param structureLinkId the primary key of the current d d m structure link
1023             * @param classNameId the class name ID
1024             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1025             * @return the previous, current, and next d d m structure link
1026             * @throws com.liferay.portlet.dynamicdatamapping.NoSuchStructureLinkException if a d d m structure link with the primary key could not be found
1027             * @throws SystemException if a system exception occurred
1028             */
1029            public DDMStructureLink[] filterFindByClassNameId_PrevAndNext(
1030                    long structureLinkId, long classNameId,
1031                    OrderByComparator orderByComparator)
1032                    throws NoSuchStructureLinkException, SystemException {
1033                    if (!InlineSQLHelperUtil.isEnabled()) {
1034                            return findByClassNameId_PrevAndNext(structureLinkId, classNameId,
1035                                    orderByComparator);
1036                    }
1037    
1038                    DDMStructureLink ddmStructureLink = findByPrimaryKey(structureLinkId);
1039    
1040                    Session session = null;
1041    
1042                    try {
1043                            session = openSession();
1044    
1045                            DDMStructureLink[] array = new DDMStructureLinkImpl[3];
1046    
1047                            array[0] = filterGetByClassNameId_PrevAndNext(session,
1048                                            ddmStructureLink, classNameId, orderByComparator, true);
1049    
1050                            array[1] = ddmStructureLink;
1051    
1052                            array[2] = filterGetByClassNameId_PrevAndNext(session,
1053                                            ddmStructureLink, classNameId, orderByComparator, false);
1054    
1055                            return array;
1056                    }
1057                    catch (Exception e) {
1058                            throw processException(e);
1059                    }
1060                    finally {
1061                            closeSession(session);
1062                    }
1063            }
1064    
1065            protected DDMStructureLink filterGetByClassNameId_PrevAndNext(
1066                    Session session, DDMStructureLink ddmStructureLink, long classNameId,
1067                    OrderByComparator orderByComparator, boolean previous) {
1068                    StringBundler query = null;
1069    
1070                    if (orderByComparator != null) {
1071                            query = new StringBundler(6 +
1072                                            (orderByComparator.getOrderByFields().length * 6));
1073                    }
1074                    else {
1075                            query = new StringBundler(3);
1076                    }
1077    
1078                    if (getDB().isSupportsInlineDistinct()) {
1079                            query.append(_FILTER_SQL_SELECT_DDMSTRUCTURELINK_WHERE);
1080                    }
1081                    else {
1082                            query.append(_FILTER_SQL_SELECT_DDMSTRUCTURELINK_NO_INLINE_DISTINCT_WHERE_1);
1083                    }
1084    
1085                    query.append(_FINDER_COLUMN_CLASSNAMEID_CLASSNAMEID_2);
1086    
1087                    if (!getDB().isSupportsInlineDistinct()) {
1088                            query.append(_FILTER_SQL_SELECT_DDMSTRUCTURELINK_NO_INLINE_DISTINCT_WHERE_2);
1089                    }
1090    
1091                    if (orderByComparator != null) {
1092                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
1093    
1094                            if (orderByConditionFields.length > 0) {
1095                                    query.append(WHERE_AND);
1096                            }
1097    
1098                            for (int i = 0; i < orderByConditionFields.length; i++) {
1099                                    if (getDB().isSupportsInlineDistinct()) {
1100                                            query.append(_ORDER_BY_ENTITY_ALIAS);
1101                                    }
1102                                    else {
1103                                            query.append(_ORDER_BY_ENTITY_TABLE);
1104                                    }
1105    
1106                                    query.append(orderByConditionFields[i]);
1107    
1108                                    if ((i + 1) < orderByConditionFields.length) {
1109                                            if (orderByComparator.isAscending() ^ previous) {
1110                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
1111                                            }
1112                                            else {
1113                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
1114                                            }
1115                                    }
1116                                    else {
1117                                            if (orderByComparator.isAscending() ^ previous) {
1118                                                    query.append(WHERE_GREATER_THAN);
1119                                            }
1120                                            else {
1121                                                    query.append(WHERE_LESSER_THAN);
1122                                            }
1123                                    }
1124                            }
1125    
1126                            query.append(ORDER_BY_CLAUSE);
1127    
1128                            String[] orderByFields = orderByComparator.getOrderByFields();
1129    
1130                            for (int i = 0; i < orderByFields.length; i++) {
1131                                    if (getDB().isSupportsInlineDistinct()) {
1132                                            query.append(_ORDER_BY_ENTITY_ALIAS);
1133                                    }
1134                                    else {
1135                                            query.append(_ORDER_BY_ENTITY_TABLE);
1136                                    }
1137    
1138                                    query.append(orderByFields[i]);
1139    
1140                                    if ((i + 1) < orderByFields.length) {
1141                                            if (orderByComparator.isAscending() ^ previous) {
1142                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
1143                                            }
1144                                            else {
1145                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
1146                                            }
1147                                    }
1148                                    else {
1149                                            if (orderByComparator.isAscending() ^ previous) {
1150                                                    query.append(ORDER_BY_ASC);
1151                                            }
1152                                            else {
1153                                                    query.append(ORDER_BY_DESC);
1154                                            }
1155                                    }
1156                            }
1157                    }
1158    
1159                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
1160                                    DDMStructureLink.class.getName(),
1161                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN);
1162    
1163                    SQLQuery q = session.createSQLQuery(sql);
1164    
1165                    q.setFirstResult(0);
1166                    q.setMaxResults(2);
1167    
1168                    if (getDB().isSupportsInlineDistinct()) {
1169                            q.addEntity(_FILTER_ENTITY_ALIAS, DDMStructureLinkImpl.class);
1170                    }
1171                    else {
1172                            q.addEntity(_FILTER_ENTITY_TABLE, DDMStructureLinkImpl.class);
1173                    }
1174    
1175                    QueryPos qPos = QueryPos.getInstance(q);
1176    
1177                    qPos.add(classNameId);
1178    
1179                    if (orderByComparator != null) {
1180                            Object[] values = orderByComparator.getOrderByConditionValues(ddmStructureLink);
1181    
1182                            for (Object value : values) {
1183                                    qPos.add(value);
1184                            }
1185                    }
1186    
1187                    List<DDMStructureLink> list = q.list();
1188    
1189                    if (list.size() == 2) {
1190                            return list.get(1);
1191                    }
1192                    else {
1193                            return null;
1194                    }
1195            }
1196    
1197            /**
1198             * Returns the d d m structure link where classPK = &#63; or throws a {@link com.liferay.portlet.dynamicdatamapping.NoSuchStructureLinkException} if it could not be found.
1199             *
1200             * @param classPK the class p k
1201             * @return the matching d d m structure link
1202             * @throws com.liferay.portlet.dynamicdatamapping.NoSuchStructureLinkException if a matching d d m structure link could not be found
1203             * @throws SystemException if a system exception occurred
1204             */
1205            public DDMStructureLink findByClassPK(long classPK)
1206                    throws NoSuchStructureLinkException, SystemException {
1207                    DDMStructureLink ddmStructureLink = fetchByClassPK(classPK);
1208    
1209                    if (ddmStructureLink == null) {
1210                            StringBundler msg = new StringBundler(4);
1211    
1212                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1213    
1214                            msg.append("classPK=");
1215                            msg.append(classPK);
1216    
1217                            msg.append(StringPool.CLOSE_CURLY_BRACE);
1218    
1219                            if (_log.isWarnEnabled()) {
1220                                    _log.warn(msg.toString());
1221                            }
1222    
1223                            throw new NoSuchStructureLinkException(msg.toString());
1224                    }
1225    
1226                    return ddmStructureLink;
1227            }
1228    
1229            /**
1230             * Returns the d d m structure link where classPK = &#63; or returns <code>null</code> if it could not be found. Uses the finder cache.
1231             *
1232             * @param classPK the class p k
1233             * @return the matching d d m structure link, or <code>null</code> if a matching d d m structure link could not be found
1234             * @throws SystemException if a system exception occurred
1235             */
1236            public DDMStructureLink fetchByClassPK(long classPK)
1237                    throws SystemException {
1238                    return fetchByClassPK(classPK, true);
1239            }
1240    
1241            /**
1242             * Returns the d d m structure link where classPK = &#63; or returns <code>null</code> if it could not be found, optionally using the finder cache.
1243             *
1244             * @param classPK the class p k
1245             * @param retrieveFromCache whether to use the finder cache
1246             * @return the matching d d m structure link, or <code>null</code> if a matching d d m structure link could not be found
1247             * @throws SystemException if a system exception occurred
1248             */
1249            public DDMStructureLink fetchByClassPK(long classPK,
1250                    boolean retrieveFromCache) throws SystemException {
1251                    Object[] finderArgs = new Object[] { classPK };
1252    
1253                    Object result = null;
1254    
1255                    if (retrieveFromCache) {
1256                            result = FinderCacheUtil.getResult(FINDER_PATH_FETCH_BY_CLASSPK,
1257                                            finderArgs, this);
1258                    }
1259    
1260                    if (result == null) {
1261                            StringBundler query = new StringBundler(2);
1262    
1263                            query.append(_SQL_SELECT_DDMSTRUCTURELINK_WHERE);
1264    
1265                            query.append(_FINDER_COLUMN_CLASSPK_CLASSPK_2);
1266    
1267                            String sql = query.toString();
1268    
1269                            Session session = null;
1270    
1271                            try {
1272                                    session = openSession();
1273    
1274                                    Query q = session.createQuery(sql);
1275    
1276                                    QueryPos qPos = QueryPos.getInstance(q);
1277    
1278                                    qPos.add(classPK);
1279    
1280                                    List<DDMStructureLink> list = q.list();
1281    
1282                                    result = list;
1283    
1284                                    DDMStructureLink ddmStructureLink = null;
1285    
1286                                    if (list.isEmpty()) {
1287                                            FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_CLASSPK,
1288                                                    finderArgs, list);
1289                                    }
1290                                    else {
1291                                            ddmStructureLink = list.get(0);
1292    
1293                                            cacheResult(ddmStructureLink);
1294    
1295                                            if ((ddmStructureLink.getClassPK() != classPK)) {
1296                                                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_CLASSPK,
1297                                                            finderArgs, ddmStructureLink);
1298                                            }
1299                                    }
1300    
1301                                    return ddmStructureLink;
1302                            }
1303                            catch (Exception e) {
1304                                    throw processException(e);
1305                            }
1306                            finally {
1307                                    if (result == null) {
1308                                            FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_CLASSPK,
1309                                                    finderArgs);
1310                                    }
1311    
1312                                    closeSession(session);
1313                            }
1314                    }
1315                    else {
1316                            if (result instanceof List<?>) {
1317                                    return null;
1318                            }
1319                            else {
1320                                    return (DDMStructureLink)result;
1321                            }
1322                    }
1323            }
1324    
1325            /**
1326             * Returns all the d d m structure links where structureId = &#63;.
1327             *
1328             * @param structureId the structure ID
1329             * @return the matching d d m structure links
1330             * @throws SystemException if a system exception occurred
1331             */
1332            public List<DDMStructureLink> findByStructureId(long structureId)
1333                    throws SystemException {
1334                    return findByStructureId(structureId, QueryUtil.ALL_POS,
1335                            QueryUtil.ALL_POS, null);
1336            }
1337    
1338            /**
1339             * Returns a range of all the d d m structure links where structureId = &#63;.
1340             *
1341             * <p>
1342             * 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.
1343             * </p>
1344             *
1345             * @param structureId the structure ID
1346             * @param start the lower bound of the range of d d m structure links
1347             * @param end the upper bound of the range of d d m structure links (not inclusive)
1348             * @return the range of matching d d m structure links
1349             * @throws SystemException if a system exception occurred
1350             */
1351            public List<DDMStructureLink> findByStructureId(long structureId,
1352                    int start, int end) throws SystemException {
1353                    return findByStructureId(structureId, start, end, null);
1354            }
1355    
1356            /**
1357             * Returns an ordered range of all the d d m structure links where structureId = &#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 structureId the structure ID
1364             * @param start the lower bound of the range of d d m structure links
1365             * @param end the upper bound of the range of d d m structure links (not inclusive)
1366             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
1367             * @return the ordered range of matching d d m structure links
1368             * @throws SystemException if a system exception occurred
1369             */
1370            public List<DDMStructureLink> findByStructureId(long structureId,
1371                    int start, int end, OrderByComparator orderByComparator)
1372                    throws SystemException {
1373                    FinderPath finderPath = null;
1374                    Object[] finderArgs = null;
1375    
1376                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
1377                                    (orderByComparator == null)) {
1378                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_STRUCTUREID;
1379                            finderArgs = new Object[] { structureId };
1380                    }
1381                    else {
1382                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_STRUCTUREID;
1383                            finderArgs = new Object[] { structureId, start, end, orderByComparator };
1384                    }
1385    
1386                    List<DDMStructureLink> list = (List<DDMStructureLink>)FinderCacheUtil.getResult(finderPath,
1387                                    finderArgs, this);
1388    
1389                    if (list == null) {
1390                            StringBundler query = null;
1391    
1392                            if (orderByComparator != null) {
1393                                    query = new StringBundler(3 +
1394                                                    (orderByComparator.getOrderByFields().length * 3));
1395                            }
1396                            else {
1397                                    query = new StringBundler(2);
1398                            }
1399    
1400                            query.append(_SQL_SELECT_DDMSTRUCTURELINK_WHERE);
1401    
1402                            query.append(_FINDER_COLUMN_STRUCTUREID_STRUCTUREID_2);
1403    
1404                            if (orderByComparator != null) {
1405                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1406                                            orderByComparator);
1407                            }
1408    
1409                            String sql = query.toString();
1410    
1411                            Session session = null;
1412    
1413                            try {
1414                                    session = openSession();
1415    
1416                                    Query q = session.createQuery(sql);
1417    
1418                                    QueryPos qPos = QueryPos.getInstance(q);
1419    
1420                                    qPos.add(structureId);
1421    
1422                                    list = (List<DDMStructureLink>)QueryUtil.list(q, getDialect(),
1423                                                    start, end);
1424                            }
1425                            catch (Exception e) {
1426                                    throw processException(e);
1427                            }
1428                            finally {
1429                                    if (list == null) {
1430                                            FinderCacheUtil.removeResult(finderPath, finderArgs);
1431                                    }
1432                                    else {
1433                                            cacheResult(list);
1434    
1435                                            FinderCacheUtil.putResult(finderPath, finderArgs, list);
1436                                    }
1437    
1438                                    closeSession(session);
1439                            }
1440                    }
1441    
1442                    return list;
1443            }
1444    
1445            /**
1446             * Returns the first d d m structure link in the ordered set where structureId = &#63;.
1447             *
1448             * <p>
1449             * 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.
1450             * </p>
1451             *
1452             * @param structureId the structure ID
1453             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1454             * @return the first matching d d m structure link
1455             * @throws com.liferay.portlet.dynamicdatamapping.NoSuchStructureLinkException if a matching d d m structure link could not be found
1456             * @throws SystemException if a system exception occurred
1457             */
1458            public DDMStructureLink findByStructureId_First(long structureId,
1459                    OrderByComparator orderByComparator)
1460                    throws NoSuchStructureLinkException, SystemException {
1461                    List<DDMStructureLink> list = findByStructureId(structureId, 0, 1,
1462                                    orderByComparator);
1463    
1464                    if (list.isEmpty()) {
1465                            StringBundler msg = new StringBundler(4);
1466    
1467                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1468    
1469                            msg.append("structureId=");
1470                            msg.append(structureId);
1471    
1472                            msg.append(StringPool.CLOSE_CURLY_BRACE);
1473    
1474                            throw new NoSuchStructureLinkException(msg.toString());
1475                    }
1476                    else {
1477                            return list.get(0);
1478                    }
1479            }
1480    
1481            /**
1482             * Returns the last d d m structure link in the ordered set where structureId = &#63;.
1483             *
1484             * <p>
1485             * 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.
1486             * </p>
1487             *
1488             * @param structureId the structure ID
1489             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1490             * @return the last matching d d m structure link
1491             * @throws com.liferay.portlet.dynamicdatamapping.NoSuchStructureLinkException if a matching d d m structure link could not be found
1492             * @throws SystemException if a system exception occurred
1493             */
1494            public DDMStructureLink findByStructureId_Last(long structureId,
1495                    OrderByComparator orderByComparator)
1496                    throws NoSuchStructureLinkException, SystemException {
1497                    int count = countByStructureId(structureId);
1498    
1499                    List<DDMStructureLink> list = findByStructureId(structureId, count - 1,
1500                                    count, orderByComparator);
1501    
1502                    if (list.isEmpty()) {
1503                            StringBundler msg = new StringBundler(4);
1504    
1505                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1506    
1507                            msg.append("structureId=");
1508                            msg.append(structureId);
1509    
1510                            msg.append(StringPool.CLOSE_CURLY_BRACE);
1511    
1512                            throw new NoSuchStructureLinkException(msg.toString());
1513                    }
1514                    else {
1515                            return list.get(0);
1516                    }
1517            }
1518    
1519            /**
1520             * Returns the d d m structure links before and after the current d d m structure link in the ordered set where structureId = &#63;.
1521             *
1522             * <p>
1523             * 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.
1524             * </p>
1525             *
1526             * @param structureLinkId the primary key of the current d d m structure link
1527             * @param structureId the structure ID
1528             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1529             * @return the previous, current, and next d d m structure link
1530             * @throws com.liferay.portlet.dynamicdatamapping.NoSuchStructureLinkException if a d d m structure link with the primary key could not be found
1531             * @throws SystemException if a system exception occurred
1532             */
1533            public DDMStructureLink[] findByStructureId_PrevAndNext(
1534                    long structureLinkId, long structureId,
1535                    OrderByComparator orderByComparator)
1536                    throws NoSuchStructureLinkException, SystemException {
1537                    DDMStructureLink ddmStructureLink = findByPrimaryKey(structureLinkId);
1538    
1539                    Session session = null;
1540    
1541                    try {
1542                            session = openSession();
1543    
1544                            DDMStructureLink[] array = new DDMStructureLinkImpl[3];
1545    
1546                            array[0] = getByStructureId_PrevAndNext(session, ddmStructureLink,
1547                                            structureId, orderByComparator, true);
1548    
1549                            array[1] = ddmStructureLink;
1550    
1551                            array[2] = getByStructureId_PrevAndNext(session, ddmStructureLink,
1552                                            structureId, orderByComparator, false);
1553    
1554                            return array;
1555                    }
1556                    catch (Exception e) {
1557                            throw processException(e);
1558                    }
1559                    finally {
1560                            closeSession(session);
1561                    }
1562            }
1563    
1564            protected DDMStructureLink getByStructureId_PrevAndNext(Session session,
1565                    DDMStructureLink ddmStructureLink, long structureId,
1566                    OrderByComparator orderByComparator, boolean previous) {
1567                    StringBundler query = null;
1568    
1569                    if (orderByComparator != null) {
1570                            query = new StringBundler(6 +
1571                                            (orderByComparator.getOrderByFields().length * 6));
1572                    }
1573                    else {
1574                            query = new StringBundler(3);
1575                    }
1576    
1577                    query.append(_SQL_SELECT_DDMSTRUCTURELINK_WHERE);
1578    
1579                    query.append(_FINDER_COLUMN_STRUCTUREID_STRUCTUREID_2);
1580    
1581                    if (orderByComparator != null) {
1582                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
1583    
1584                            if (orderByConditionFields.length > 0) {
1585                                    query.append(WHERE_AND);
1586                            }
1587    
1588                            for (int i = 0; i < orderByConditionFields.length; i++) {
1589                                    query.append(_ORDER_BY_ENTITY_ALIAS);
1590                                    query.append(orderByConditionFields[i]);
1591    
1592                                    if ((i + 1) < orderByConditionFields.length) {
1593                                            if (orderByComparator.isAscending() ^ previous) {
1594                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
1595                                            }
1596                                            else {
1597                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
1598                                            }
1599                                    }
1600                                    else {
1601                                            if (orderByComparator.isAscending() ^ previous) {
1602                                                    query.append(WHERE_GREATER_THAN);
1603                                            }
1604                                            else {
1605                                                    query.append(WHERE_LESSER_THAN);
1606                                            }
1607                                    }
1608                            }
1609    
1610                            query.append(ORDER_BY_CLAUSE);
1611    
1612                            String[] orderByFields = orderByComparator.getOrderByFields();
1613    
1614                            for (int i = 0; i < orderByFields.length; i++) {
1615                                    query.append(_ORDER_BY_ENTITY_ALIAS);
1616                                    query.append(orderByFields[i]);
1617    
1618                                    if ((i + 1) < orderByFields.length) {
1619                                            if (orderByComparator.isAscending() ^ previous) {
1620                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
1621                                            }
1622                                            else {
1623                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
1624                                            }
1625                                    }
1626                                    else {
1627                                            if (orderByComparator.isAscending() ^ previous) {
1628                                                    query.append(ORDER_BY_ASC);
1629                                            }
1630                                            else {
1631                                                    query.append(ORDER_BY_DESC);
1632                                            }
1633                                    }
1634                            }
1635                    }
1636    
1637                    String sql = query.toString();
1638    
1639                    Query q = session.createQuery(sql);
1640    
1641                    q.setFirstResult(0);
1642                    q.setMaxResults(2);
1643    
1644                    QueryPos qPos = QueryPos.getInstance(q);
1645    
1646                    qPos.add(structureId);
1647    
1648                    if (orderByComparator != null) {
1649                            Object[] values = orderByComparator.getOrderByConditionValues(ddmStructureLink);
1650    
1651                            for (Object value : values) {
1652                                    qPos.add(value);
1653                            }
1654                    }
1655    
1656                    List<DDMStructureLink> list = q.list();
1657    
1658                    if (list.size() == 2) {
1659                            return list.get(1);
1660                    }
1661                    else {
1662                            return null;
1663                    }
1664            }
1665    
1666            /**
1667             * Returns all the d d m structure links that the user has permission to view where structureId = &#63;.
1668             *
1669             * @param structureId the structure ID
1670             * @return the matching d d m structure links that the user has permission to view
1671             * @throws SystemException if a system exception occurred
1672             */
1673            public List<DDMStructureLink> filterFindByStructureId(long structureId)
1674                    throws SystemException {
1675                    return filterFindByStructureId(structureId, QueryUtil.ALL_POS,
1676                            QueryUtil.ALL_POS, null);
1677            }
1678    
1679            /**
1680             * Returns a range of all the d d m structure links that the user has permission to view where structureId = &#63;.
1681             *
1682             * <p>
1683             * 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.
1684             * </p>
1685             *
1686             * @param structureId the structure ID
1687             * @param start the lower bound of the range of d d m structure links
1688             * @param end the upper bound of the range of d d m structure links (not inclusive)
1689             * @return the range of matching d d m structure links that the user has permission to view
1690             * @throws SystemException if a system exception occurred
1691             */
1692            public List<DDMStructureLink> filterFindByStructureId(long structureId,
1693                    int start, int end) throws SystemException {
1694                    return filterFindByStructureId(structureId, start, end, null);
1695            }
1696    
1697            /**
1698             * Returns an ordered range of all the d d m structure links that the user has permissions to view where structureId = &#63;.
1699             *
1700             * <p>
1701             * 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.
1702             * </p>
1703             *
1704             * @param structureId the structure ID
1705             * @param start the lower bound of the range of d d m structure links
1706             * @param end the upper bound of the range of d d m structure links (not inclusive)
1707             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
1708             * @return the ordered range of matching d d m structure links that the user has permission to view
1709             * @throws SystemException if a system exception occurred
1710             */
1711            public List<DDMStructureLink> filterFindByStructureId(long structureId,
1712                    int start, int end, OrderByComparator orderByComparator)
1713                    throws SystemException {
1714                    if (!InlineSQLHelperUtil.isEnabled()) {
1715                            return findByStructureId(structureId, start, end, orderByComparator);
1716                    }
1717    
1718                    StringBundler query = null;
1719    
1720                    if (orderByComparator != null) {
1721                            query = new StringBundler(3 +
1722                                            (orderByComparator.getOrderByFields().length * 3));
1723                    }
1724                    else {
1725                            query = new StringBundler(2);
1726                    }
1727    
1728                    if (getDB().isSupportsInlineDistinct()) {
1729                            query.append(_FILTER_SQL_SELECT_DDMSTRUCTURELINK_WHERE);
1730                    }
1731                    else {
1732                            query.append(_FILTER_SQL_SELECT_DDMSTRUCTURELINK_NO_INLINE_DISTINCT_WHERE_1);
1733                    }
1734    
1735                    query.append(_FINDER_COLUMN_STRUCTUREID_STRUCTUREID_2);
1736    
1737                    if (!getDB().isSupportsInlineDistinct()) {
1738                            query.append(_FILTER_SQL_SELECT_DDMSTRUCTURELINK_NO_INLINE_DISTINCT_WHERE_2);
1739                    }
1740    
1741                    if (orderByComparator != null) {
1742                            if (getDB().isSupportsInlineDistinct()) {
1743                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1744                                            orderByComparator);
1745                            }
1746                            else {
1747                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_TABLE,
1748                                            orderByComparator);
1749                            }
1750                    }
1751    
1752                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
1753                                    DDMStructureLink.class.getName(),
1754                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN);
1755    
1756                    Session session = null;
1757    
1758                    try {
1759                            session = openSession();
1760    
1761                            SQLQuery q = session.createSQLQuery(sql);
1762    
1763                            if (getDB().isSupportsInlineDistinct()) {
1764                                    q.addEntity(_FILTER_ENTITY_ALIAS, DDMStructureLinkImpl.class);
1765                            }
1766                            else {
1767                                    q.addEntity(_FILTER_ENTITY_TABLE, DDMStructureLinkImpl.class);
1768                            }
1769    
1770                            QueryPos qPos = QueryPos.getInstance(q);
1771    
1772                            qPos.add(structureId);
1773    
1774                            return (List<DDMStructureLink>)QueryUtil.list(q, getDialect(),
1775                                    start, end);
1776                    }
1777                    catch (Exception e) {
1778                            throw processException(e);
1779                    }
1780                    finally {
1781                            closeSession(session);
1782                    }
1783            }
1784    
1785            /**
1786             * Returns the d d m structure links before and after the current d d m structure link in the ordered set of d d m structure links that the user has permission to view where structureId = &#63;.
1787             *
1788             * @param structureLinkId the primary key of the current d d m structure link
1789             * @param structureId the structure ID
1790             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1791             * @return the previous, current, and next d d m structure link
1792             * @throws com.liferay.portlet.dynamicdatamapping.NoSuchStructureLinkException if a d d m structure link with the primary key could not be found
1793             * @throws SystemException if a system exception occurred
1794             */
1795            public DDMStructureLink[] filterFindByStructureId_PrevAndNext(
1796                    long structureLinkId, long structureId,
1797                    OrderByComparator orderByComparator)
1798                    throws NoSuchStructureLinkException, SystemException {
1799                    if (!InlineSQLHelperUtil.isEnabled()) {
1800                            return findByStructureId_PrevAndNext(structureLinkId, structureId,
1801                                    orderByComparator);
1802                    }
1803    
1804                    DDMStructureLink ddmStructureLink = findByPrimaryKey(structureLinkId);
1805    
1806                    Session session = null;
1807    
1808                    try {
1809                            session = openSession();
1810    
1811                            DDMStructureLink[] array = new DDMStructureLinkImpl[3];
1812    
1813                            array[0] = filterGetByStructureId_PrevAndNext(session,
1814                                            ddmStructureLink, structureId, orderByComparator, true);
1815    
1816                            array[1] = ddmStructureLink;
1817    
1818                            array[2] = filterGetByStructureId_PrevAndNext(session,
1819                                            ddmStructureLink, structureId, orderByComparator, false);
1820    
1821                            return array;
1822                    }
1823                    catch (Exception e) {
1824                            throw processException(e);
1825                    }
1826                    finally {
1827                            closeSession(session);
1828                    }
1829            }
1830    
1831            protected DDMStructureLink filterGetByStructureId_PrevAndNext(
1832                    Session session, DDMStructureLink ddmStructureLink, long structureId,
1833                    OrderByComparator orderByComparator, boolean previous) {
1834                    StringBundler query = null;
1835    
1836                    if (orderByComparator != null) {
1837                            query = new StringBundler(6 +
1838                                            (orderByComparator.getOrderByFields().length * 6));
1839                    }
1840                    else {
1841                            query = new StringBundler(3);
1842                    }
1843    
1844                    if (getDB().isSupportsInlineDistinct()) {
1845                            query.append(_FILTER_SQL_SELECT_DDMSTRUCTURELINK_WHERE);
1846                    }
1847                    else {
1848                            query.append(_FILTER_SQL_SELECT_DDMSTRUCTURELINK_NO_INLINE_DISTINCT_WHERE_1);
1849                    }
1850    
1851                    query.append(_FINDER_COLUMN_STRUCTUREID_STRUCTUREID_2);
1852    
1853                    if (!getDB().isSupportsInlineDistinct()) {
1854                            query.append(_FILTER_SQL_SELECT_DDMSTRUCTURELINK_NO_INLINE_DISTINCT_WHERE_2);
1855                    }
1856    
1857                    if (orderByComparator != null) {
1858                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
1859    
1860                            if (orderByConditionFields.length > 0) {
1861                                    query.append(WHERE_AND);
1862                            }
1863    
1864                            for (int i = 0; i < orderByConditionFields.length; i++) {
1865                                    if (getDB().isSupportsInlineDistinct()) {
1866                                            query.append(_ORDER_BY_ENTITY_ALIAS);
1867                                    }
1868                                    else {
1869                                            query.append(_ORDER_BY_ENTITY_TABLE);
1870                                    }
1871    
1872                                    query.append(orderByConditionFields[i]);
1873    
1874                                    if ((i + 1) < orderByConditionFields.length) {
1875                                            if (orderByComparator.isAscending() ^ previous) {
1876                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
1877                                            }
1878                                            else {
1879                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
1880                                            }
1881                                    }
1882                                    else {
1883                                            if (orderByComparator.isAscending() ^ previous) {
1884                                                    query.append(WHERE_GREATER_THAN);
1885                                            }
1886                                            else {
1887                                                    query.append(WHERE_LESSER_THAN);
1888                                            }
1889                                    }
1890                            }
1891    
1892                            query.append(ORDER_BY_CLAUSE);
1893    
1894                            String[] orderByFields = orderByComparator.getOrderByFields();
1895    
1896                            for (int i = 0; i < orderByFields.length; i++) {
1897                                    if (getDB().isSupportsInlineDistinct()) {
1898                                            query.append(_ORDER_BY_ENTITY_ALIAS);
1899                                    }
1900                                    else {
1901                                            query.append(_ORDER_BY_ENTITY_TABLE);
1902                                    }
1903    
1904                                    query.append(orderByFields[i]);
1905    
1906                                    if ((i + 1) < orderByFields.length) {
1907                                            if (orderByComparator.isAscending() ^ previous) {
1908                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
1909                                            }
1910                                            else {
1911                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
1912                                            }
1913                                    }
1914                                    else {
1915                                            if (orderByComparator.isAscending() ^ previous) {
1916                                                    query.append(ORDER_BY_ASC);
1917                                            }
1918                                            else {
1919                                                    query.append(ORDER_BY_DESC);
1920                                            }
1921                                    }
1922                            }
1923                    }
1924    
1925                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
1926                                    DDMStructureLink.class.getName(),
1927                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN);
1928    
1929                    SQLQuery q = session.createSQLQuery(sql);
1930    
1931                    q.setFirstResult(0);
1932                    q.setMaxResults(2);
1933    
1934                    if (getDB().isSupportsInlineDistinct()) {
1935                            q.addEntity(_FILTER_ENTITY_ALIAS, DDMStructureLinkImpl.class);
1936                    }
1937                    else {
1938                            q.addEntity(_FILTER_ENTITY_TABLE, DDMStructureLinkImpl.class);
1939                    }
1940    
1941                    QueryPos qPos = QueryPos.getInstance(q);
1942    
1943                    qPos.add(structureId);
1944    
1945                    if (orderByComparator != null) {
1946                            Object[] values = orderByComparator.getOrderByConditionValues(ddmStructureLink);
1947    
1948                            for (Object value : values) {
1949                                    qPos.add(value);
1950                            }
1951                    }
1952    
1953                    List<DDMStructureLink> list = q.list();
1954    
1955                    if (list.size() == 2) {
1956                            return list.get(1);
1957                    }
1958                    else {
1959                            return null;
1960                    }
1961            }
1962    
1963            /**
1964             * Returns all the d d m structure links.
1965             *
1966             * @return the d d m structure links
1967             * @throws SystemException if a system exception occurred
1968             */
1969            public List<DDMStructureLink> findAll() throws SystemException {
1970                    return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
1971            }
1972    
1973            /**
1974             * Returns a range of all the d d m structure links.
1975             *
1976             * <p>
1977             * 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.
1978             * </p>
1979             *
1980             * @param start the lower bound of the range of d d m structure links
1981             * @param end the upper bound of the range of d d m structure links (not inclusive)
1982             * @return the range of d d m structure links
1983             * @throws SystemException if a system exception occurred
1984             */
1985            public List<DDMStructureLink> findAll(int start, int end)
1986                    throws SystemException {
1987                    return findAll(start, end, null);
1988            }
1989    
1990            /**
1991             * Returns an ordered range of all the d d m structure links.
1992             *
1993             * <p>
1994             * 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.
1995             * </p>
1996             *
1997             * @param start the lower bound of the range of d d m structure links
1998             * @param end the upper bound of the range of d d m structure links (not inclusive)
1999             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
2000             * @return the ordered range of d d m structure links
2001             * @throws SystemException if a system exception occurred
2002             */
2003            public List<DDMStructureLink> findAll(int start, int end,
2004                    OrderByComparator orderByComparator) throws SystemException {
2005                    FinderPath finderPath = null;
2006                    Object[] finderArgs = new Object[] { start, end, orderByComparator };
2007    
2008                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
2009                                    (orderByComparator == null)) {
2010                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_ALL;
2011                            finderArgs = FINDER_ARGS_EMPTY;
2012                    }
2013                    else {
2014                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL;
2015                            finderArgs = new Object[] { start, end, orderByComparator };
2016                    }
2017    
2018                    List<DDMStructureLink> list = (List<DDMStructureLink>)FinderCacheUtil.getResult(finderPath,
2019                                    finderArgs, this);
2020    
2021                    if (list == null) {
2022                            StringBundler query = null;
2023                            String sql = null;
2024    
2025                            if (orderByComparator != null) {
2026                                    query = new StringBundler(2 +
2027                                                    (orderByComparator.getOrderByFields().length * 3));
2028    
2029                                    query.append(_SQL_SELECT_DDMSTRUCTURELINK);
2030    
2031                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
2032                                            orderByComparator);
2033    
2034                                    sql = query.toString();
2035                            }
2036                            else {
2037                                    sql = _SQL_SELECT_DDMSTRUCTURELINK;
2038                            }
2039    
2040                            Session session = null;
2041    
2042                            try {
2043                                    session = openSession();
2044    
2045                                    Query q = session.createQuery(sql);
2046    
2047                                    if (orderByComparator == null) {
2048                                            list = (List<DDMStructureLink>)QueryUtil.list(q,
2049                                                            getDialect(), start, end, false);
2050    
2051                                            Collections.sort(list);
2052                                    }
2053                                    else {
2054                                            list = (List<DDMStructureLink>)QueryUtil.list(q,
2055                                                            getDialect(), start, end);
2056                                    }
2057                            }
2058                            catch (Exception e) {
2059                                    throw processException(e);
2060                            }
2061                            finally {
2062                                    if (list == null) {
2063                                            FinderCacheUtil.removeResult(finderPath, finderArgs);
2064                                    }
2065                                    else {
2066                                            cacheResult(list);
2067    
2068                                            FinderCacheUtil.putResult(finderPath, finderArgs, list);
2069                                    }
2070    
2071                                    closeSession(session);
2072                            }
2073                    }
2074    
2075                    return list;
2076            }
2077    
2078            /**
2079             * Removes all the d d m structure links where classNameId = &#63; from the database.
2080             *
2081             * @param classNameId the class name ID
2082             * @throws SystemException if a system exception occurred
2083             */
2084            public void removeByClassNameId(long classNameId) throws SystemException {
2085                    for (DDMStructureLink ddmStructureLink : findByClassNameId(classNameId)) {
2086                            ddmStructureLinkPersistence.remove(ddmStructureLink);
2087                    }
2088            }
2089    
2090            /**
2091             * Removes the d d m structure link where classPK = &#63; from the database.
2092             *
2093             * @param classPK the class p k
2094             * @throws SystemException if a system exception occurred
2095             */
2096            public void removeByClassPK(long classPK)
2097                    throws NoSuchStructureLinkException, SystemException {
2098                    DDMStructureLink ddmStructureLink = findByClassPK(classPK);
2099    
2100                    ddmStructureLinkPersistence.remove(ddmStructureLink);
2101            }
2102    
2103            /**
2104             * Removes all the d d m structure links where structureId = &#63; from the database.
2105             *
2106             * @param structureId the structure ID
2107             * @throws SystemException if a system exception occurred
2108             */
2109            public void removeByStructureId(long structureId) throws SystemException {
2110                    for (DDMStructureLink ddmStructureLink : findByStructureId(structureId)) {
2111                            ddmStructureLinkPersistence.remove(ddmStructureLink);
2112                    }
2113            }
2114    
2115            /**
2116             * Removes all the d d m structure links from the database.
2117             *
2118             * @throws SystemException if a system exception occurred
2119             */
2120            public void removeAll() throws SystemException {
2121                    for (DDMStructureLink ddmStructureLink : findAll()) {
2122                            ddmStructureLinkPersistence.remove(ddmStructureLink);
2123                    }
2124            }
2125    
2126            /**
2127             * Returns the number of d d m structure links where classNameId = &#63;.
2128             *
2129             * @param classNameId the class name ID
2130             * @return the number of matching d d m structure links
2131             * @throws SystemException if a system exception occurred
2132             */
2133            public int countByClassNameId(long classNameId) throws SystemException {
2134                    Object[] finderArgs = new Object[] { classNameId };
2135    
2136                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_CLASSNAMEID,
2137                                    finderArgs, this);
2138    
2139                    if (count == null) {
2140                            StringBundler query = new StringBundler(2);
2141    
2142                            query.append(_SQL_COUNT_DDMSTRUCTURELINK_WHERE);
2143    
2144                            query.append(_FINDER_COLUMN_CLASSNAMEID_CLASSNAMEID_2);
2145    
2146                            String sql = query.toString();
2147    
2148                            Session session = null;
2149    
2150                            try {
2151                                    session = openSession();
2152    
2153                                    Query q = session.createQuery(sql);
2154    
2155                                    QueryPos qPos = QueryPos.getInstance(q);
2156    
2157                                    qPos.add(classNameId);
2158    
2159                                    count = (Long)q.uniqueResult();
2160                            }
2161                            catch (Exception e) {
2162                                    throw processException(e);
2163                            }
2164                            finally {
2165                                    if (count == null) {
2166                                            count = Long.valueOf(0);
2167                                    }
2168    
2169                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_CLASSNAMEID,
2170                                            finderArgs, count);
2171    
2172                                    closeSession(session);
2173                            }
2174                    }
2175    
2176                    return count.intValue();
2177            }
2178    
2179            /**
2180             * Returns the number of d d m structure links that the user has permission to view where classNameId = &#63;.
2181             *
2182             * @param classNameId the class name ID
2183             * @return the number of matching d d m structure links that the user has permission to view
2184             * @throws SystemException if a system exception occurred
2185             */
2186            public int filterCountByClassNameId(long classNameId)
2187                    throws SystemException {
2188                    if (!InlineSQLHelperUtil.isEnabled()) {
2189                            return countByClassNameId(classNameId);
2190                    }
2191    
2192                    StringBundler query = new StringBundler(2);
2193    
2194                    query.append(_FILTER_SQL_COUNT_DDMSTRUCTURELINK_WHERE);
2195    
2196                    query.append(_FINDER_COLUMN_CLASSNAMEID_CLASSNAMEID_2);
2197    
2198                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
2199                                    DDMStructureLink.class.getName(),
2200                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN);
2201    
2202                    Session session = null;
2203    
2204                    try {
2205                            session = openSession();
2206    
2207                            SQLQuery q = session.createSQLQuery(sql);
2208    
2209                            q.addScalar(COUNT_COLUMN_NAME,
2210                                    com.liferay.portal.kernel.dao.orm.Type.LONG);
2211    
2212                            QueryPos qPos = QueryPos.getInstance(q);
2213    
2214                            qPos.add(classNameId);
2215    
2216                            Long count = (Long)q.uniqueResult();
2217    
2218                            return count.intValue();
2219                    }
2220                    catch (Exception e) {
2221                            throw processException(e);
2222                    }
2223                    finally {
2224                            closeSession(session);
2225                    }
2226            }
2227    
2228            /**
2229             * Returns the number of d d m structure links where classPK = &#63;.
2230             *
2231             * @param classPK the class p k
2232             * @return the number of matching d d m structure links
2233             * @throws SystemException if a system exception occurred
2234             */
2235            public int countByClassPK(long classPK) throws SystemException {
2236                    Object[] finderArgs = new Object[] { classPK };
2237    
2238                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_CLASSPK,
2239                                    finderArgs, this);
2240    
2241                    if (count == null) {
2242                            StringBundler query = new StringBundler(2);
2243    
2244                            query.append(_SQL_COUNT_DDMSTRUCTURELINK_WHERE);
2245    
2246                            query.append(_FINDER_COLUMN_CLASSPK_CLASSPK_2);
2247    
2248                            String sql = query.toString();
2249    
2250                            Session session = null;
2251    
2252                            try {
2253                                    session = openSession();
2254    
2255                                    Query q = session.createQuery(sql);
2256    
2257                                    QueryPos qPos = QueryPos.getInstance(q);
2258    
2259                                    qPos.add(classPK);
2260    
2261                                    count = (Long)q.uniqueResult();
2262                            }
2263                            catch (Exception e) {
2264                                    throw processException(e);
2265                            }
2266                            finally {
2267                                    if (count == null) {
2268                                            count = Long.valueOf(0);
2269                                    }
2270    
2271                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_CLASSPK,
2272                                            finderArgs, count);
2273    
2274                                    closeSession(session);
2275                            }
2276                    }
2277    
2278                    return count.intValue();
2279            }
2280    
2281            /**
2282             * Returns the number of d d m structure links where structureId = &#63;.
2283             *
2284             * @param structureId the structure ID
2285             * @return the number of matching d d m structure links
2286             * @throws SystemException if a system exception occurred
2287             */
2288            public int countByStructureId(long structureId) throws SystemException {
2289                    Object[] finderArgs = new Object[] { structureId };
2290    
2291                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_STRUCTUREID,
2292                                    finderArgs, this);
2293    
2294                    if (count == null) {
2295                            StringBundler query = new StringBundler(2);
2296    
2297                            query.append(_SQL_COUNT_DDMSTRUCTURELINK_WHERE);
2298    
2299                            query.append(_FINDER_COLUMN_STRUCTUREID_STRUCTUREID_2);
2300    
2301                            String sql = query.toString();
2302    
2303                            Session session = null;
2304    
2305                            try {
2306                                    session = openSession();
2307    
2308                                    Query q = session.createQuery(sql);
2309    
2310                                    QueryPos qPos = QueryPos.getInstance(q);
2311    
2312                                    qPos.add(structureId);
2313    
2314                                    count = (Long)q.uniqueResult();
2315                            }
2316                            catch (Exception e) {
2317                                    throw processException(e);
2318                            }
2319                            finally {
2320                                    if (count == null) {
2321                                            count = Long.valueOf(0);
2322                                    }
2323    
2324                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_STRUCTUREID,
2325                                            finderArgs, count);
2326    
2327                                    closeSession(session);
2328                            }
2329                    }
2330    
2331                    return count.intValue();
2332            }
2333    
2334            /**
2335             * Returns the number of d d m structure links that the user has permission to view where structureId = &#63;.
2336             *
2337             * @param structureId the structure ID
2338             * @return the number of matching d d m structure links that the user has permission to view
2339             * @throws SystemException if a system exception occurred
2340             */
2341            public int filterCountByStructureId(long structureId)
2342                    throws SystemException {
2343                    if (!InlineSQLHelperUtil.isEnabled()) {
2344                            return countByStructureId(structureId);
2345                    }
2346    
2347                    StringBundler query = new StringBundler(2);
2348    
2349                    query.append(_FILTER_SQL_COUNT_DDMSTRUCTURELINK_WHERE);
2350    
2351                    query.append(_FINDER_COLUMN_STRUCTUREID_STRUCTUREID_2);
2352    
2353                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
2354                                    DDMStructureLink.class.getName(),
2355                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN);
2356    
2357                    Session session = null;
2358    
2359                    try {
2360                            session = openSession();
2361    
2362                            SQLQuery q = session.createSQLQuery(sql);
2363    
2364                            q.addScalar(COUNT_COLUMN_NAME,
2365                                    com.liferay.portal.kernel.dao.orm.Type.LONG);
2366    
2367                            QueryPos qPos = QueryPos.getInstance(q);
2368    
2369                            qPos.add(structureId);
2370    
2371                            Long count = (Long)q.uniqueResult();
2372    
2373                            return count.intValue();
2374                    }
2375                    catch (Exception e) {
2376                            throw processException(e);
2377                    }
2378                    finally {
2379                            closeSession(session);
2380                    }
2381            }
2382    
2383            /**
2384             * Returns the number of d d m structure links.
2385             *
2386             * @return the number of d d m structure links
2387             * @throws SystemException if a system exception occurred
2388             */
2389            public int countAll() throws SystemException {
2390                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_ALL,
2391                                    FINDER_ARGS_EMPTY, this);
2392    
2393                    if (count == null) {
2394                            Session session = null;
2395    
2396                            try {
2397                                    session = openSession();
2398    
2399                                    Query q = session.createQuery(_SQL_COUNT_DDMSTRUCTURELINK);
2400    
2401                                    count = (Long)q.uniqueResult();
2402                            }
2403                            catch (Exception e) {
2404                                    throw processException(e);
2405                            }
2406                            finally {
2407                                    if (count == null) {
2408                                            count = Long.valueOf(0);
2409                                    }
2410    
2411                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_ALL,
2412                                            FINDER_ARGS_EMPTY, count);
2413    
2414                                    closeSession(session);
2415                            }
2416                    }
2417    
2418                    return count.intValue();
2419            }
2420    
2421            /**
2422             * Initializes the d d m structure link persistence.
2423             */
2424            public void afterPropertiesSet() {
2425                    String[] listenerClassNames = StringUtil.split(GetterUtil.getString(
2426                                            com.liferay.portal.util.PropsUtil.get(
2427                                                    "value.object.listener.com.liferay.portlet.dynamicdatamapping.model.DDMStructureLink")));
2428    
2429                    if (listenerClassNames.length > 0) {
2430                            try {
2431                                    List<ModelListener<DDMStructureLink>> listenersList = new ArrayList<ModelListener<DDMStructureLink>>();
2432    
2433                                    for (String listenerClassName : listenerClassNames) {
2434                                            listenersList.add((ModelListener<DDMStructureLink>)InstanceFactory.newInstance(
2435                                                            listenerClassName));
2436                                    }
2437    
2438                                    listeners = listenersList.toArray(new ModelListener[listenersList.size()]);
2439                            }
2440                            catch (Exception e) {
2441                                    _log.error(e);
2442                            }
2443                    }
2444            }
2445    
2446            public void destroy() {
2447                    EntityCacheUtil.removeCache(DDMStructureLinkImpl.class.getName());
2448                    FinderCacheUtil.removeCache(FINDER_CLASS_NAME_ENTITY);
2449                    FinderCacheUtil.removeCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
2450            }
2451    
2452            @BeanReference(type = DDMContentPersistence.class)
2453            protected DDMContentPersistence ddmContentPersistence;
2454            @BeanReference(type = DDMStorageLinkPersistence.class)
2455            protected DDMStorageLinkPersistence ddmStorageLinkPersistence;
2456            @BeanReference(type = DDMStructurePersistence.class)
2457            protected DDMStructurePersistence ddmStructurePersistence;
2458            @BeanReference(type = DDMStructureLinkPersistence.class)
2459            protected DDMStructureLinkPersistence ddmStructureLinkPersistence;
2460            @BeanReference(type = DDMTemplatePersistence.class)
2461            protected DDMTemplatePersistence ddmTemplatePersistence;
2462            @BeanReference(type = ResourcePersistence.class)
2463            protected ResourcePersistence resourcePersistence;
2464            @BeanReference(type = UserPersistence.class)
2465            protected UserPersistence userPersistence;
2466            private static final String _SQL_SELECT_DDMSTRUCTURELINK = "SELECT ddmStructureLink FROM DDMStructureLink ddmStructureLink";
2467            private static final String _SQL_SELECT_DDMSTRUCTURELINK_WHERE = "SELECT ddmStructureLink FROM DDMStructureLink ddmStructureLink WHERE ";
2468            private static final String _SQL_COUNT_DDMSTRUCTURELINK = "SELECT COUNT(ddmStructureLink) FROM DDMStructureLink ddmStructureLink";
2469            private static final String _SQL_COUNT_DDMSTRUCTURELINK_WHERE = "SELECT COUNT(ddmStructureLink) FROM DDMStructureLink ddmStructureLink WHERE ";
2470            private static final String _FINDER_COLUMN_CLASSNAMEID_CLASSNAMEID_2 = "ddmStructureLink.classNameId = ?";
2471            private static final String _FINDER_COLUMN_CLASSPK_CLASSPK_2 = "ddmStructureLink.classPK = ?";
2472            private static final String _FINDER_COLUMN_STRUCTUREID_STRUCTUREID_2 = "ddmStructureLink.structureId = ?";
2473            private static final String _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN = "ddmStructureLink.structureLinkId";
2474            private static final String _FILTER_SQL_SELECT_DDMSTRUCTURELINK_WHERE = "SELECT DISTINCT {ddmStructureLink.*} FROM DDMStructureLink ddmStructureLink WHERE ";
2475            private static final String _FILTER_SQL_SELECT_DDMSTRUCTURELINK_NO_INLINE_DISTINCT_WHERE_1 =
2476                    "SELECT {DDMStructureLink.*} FROM (SELECT DISTINCT ddmStructureLink.structureLinkId FROM DDMStructureLink ddmStructureLink WHERE ";
2477            private static final String _FILTER_SQL_SELECT_DDMSTRUCTURELINK_NO_INLINE_DISTINCT_WHERE_2 =
2478                    ") TEMP_TABLE INNER JOIN DDMStructureLink ON TEMP_TABLE.structureLinkId = DDMStructureLink.structureLinkId";
2479            private static final String _FILTER_SQL_COUNT_DDMSTRUCTURELINK_WHERE = "SELECT COUNT(DISTINCT ddmStructureLink.structureLinkId) AS COUNT_VALUE FROM DDMStructureLink ddmStructureLink WHERE ";
2480            private static final String _FILTER_ENTITY_ALIAS = "ddmStructureLink";
2481            private static final String _FILTER_ENTITY_TABLE = "DDMStructureLink";
2482            private static final String _ORDER_BY_ENTITY_ALIAS = "ddmStructureLink.";
2483            private static final String _ORDER_BY_ENTITY_TABLE = "DDMStructureLink.";
2484            private static final String _NO_SUCH_ENTITY_WITH_PRIMARY_KEY = "No DDMStructureLink exists with the primary key ";
2485            private static final String _NO_SUCH_ENTITY_WITH_KEY = "No DDMStructureLink exists with the key {";
2486            private static final boolean _HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE = com.liferay.portal.util.PropsValues.HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE;
2487            private static Log _log = LogFactoryUtil.getLog(DDMStructureLinkPersistenceImpl.class);
2488            private static DDMStructureLink _nullDDMStructureLink = new DDMStructureLinkImpl() {
2489                            @Override
2490                            public Object clone() {
2491                                    return this;
2492                            }
2493    
2494                            @Override
2495                            public CacheModel<DDMStructureLink> toCacheModel() {
2496                                    return _nullDDMStructureLinkCacheModel;
2497                            }
2498                    };
2499    
2500            private static CacheModel<DDMStructureLink> _nullDDMStructureLinkCacheModel = new CacheModel<DDMStructureLink>() {
2501                            public DDMStructureLink toEntityModel() {
2502                                    return _nullDDMStructureLink;
2503                            }
2504                    };
2505    }