001    /**
002     * Copyright (c) 2000-2013 Liferay, Inc. All rights reserved.
003     *
004     * This library is free software; you can redistribute it and/or modify it under
005     * the terms of the GNU Lesser General Public License as published by the Free
006     * Software Foundation; either version 2.1 of the License, or (at your option)
007     * any later version.
008     *
009     * This library is distributed in the hope that it will be useful, but WITHOUT
010     * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
011     * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
012     * details.
013     */
014    
015    package com.liferay.portlet.dynamicdatamapping.service.persistence;
016    
017    import com.liferay.portal.NoSuchModelException;
018    import com.liferay.portal.kernel.bean.BeanReference;
019    import com.liferay.portal.kernel.cache.CacheRegistryUtil;
020    import com.liferay.portal.kernel.dao.orm.EntityCacheUtil;
021    import com.liferay.portal.kernel.dao.orm.FinderCacheUtil;
022    import com.liferay.portal.kernel.dao.orm.FinderPath;
023    import com.liferay.portal.kernel.dao.orm.Query;
024    import com.liferay.portal.kernel.dao.orm.QueryPos;
025    import com.liferay.portal.kernel.dao.orm.QueryUtil;
026    import com.liferay.portal.kernel.dao.orm.Session;
027    import com.liferay.portal.kernel.exception.SystemException;
028    import com.liferay.portal.kernel.log.Log;
029    import com.liferay.portal.kernel.log.LogFactoryUtil;
030    import com.liferay.portal.kernel.util.GetterUtil;
031    import com.liferay.portal.kernel.util.InstanceFactory;
032    import com.liferay.portal.kernel.util.OrderByComparator;
033    import com.liferay.portal.kernel.util.StringBundler;
034    import com.liferay.portal.kernel.util.StringPool;
035    import com.liferay.portal.kernel.util.StringUtil;
036    import com.liferay.portal.kernel.util.Validator;
037    import com.liferay.portal.kernel.uuid.PortalUUIDUtil;
038    import com.liferay.portal.model.CacheModel;
039    import com.liferay.portal.model.ModelListener;
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.NoSuchStorageLinkException;
046    import com.liferay.portlet.dynamicdatamapping.model.DDMStorageLink;
047    import com.liferay.portlet.dynamicdatamapping.model.impl.DDMStorageLinkImpl;
048    import com.liferay.portlet.dynamicdatamapping.model.impl.DDMStorageLinkModelImpl;
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 storage 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 DDMStorageLinkPersistence
065     * @see DDMStorageLinkUtil
066     * @generated
067     */
068    public class DDMStorageLinkPersistenceImpl extends BasePersistenceImpl<DDMStorageLink>
069            implements DDMStorageLinkPersistence {
070            /*
071             * NOTE FOR DEVELOPERS:
072             *
073             * Never modify or reference this class directly. Always use {@link DDMStorageLinkUtil} to access the d d m storage link persistence. Modify <code>service.xml</code> and rerun ServiceBuilder to regenerate this class.
074             */
075            public static final String FINDER_CLASS_NAME_ENTITY = DDMStorageLinkImpl.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_UUID = new FinderPath(DDMStorageLinkModelImpl.ENTITY_CACHE_ENABLED,
081                            DDMStorageLinkModelImpl.FINDER_CACHE_ENABLED,
082                            DDMStorageLinkImpl.class, FINDER_CLASS_NAME_LIST_WITH_PAGINATION,
083                            "findByUuid",
084                            new String[] {
085                                    String.class.getName(),
086                                    
087                            "java.lang.Integer", "java.lang.Integer",
088                                    "com.liferay.portal.kernel.util.OrderByComparator"
089                            });
090            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID = new FinderPath(DDMStorageLinkModelImpl.ENTITY_CACHE_ENABLED,
091                            DDMStorageLinkModelImpl.FINDER_CACHE_ENABLED,
092                            DDMStorageLinkImpl.class,
093                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByUuid",
094                            new String[] { String.class.getName() },
095                            DDMStorageLinkModelImpl.UUID_COLUMN_BITMASK);
096            public static final FinderPath FINDER_PATH_COUNT_BY_UUID = new FinderPath(DDMStorageLinkModelImpl.ENTITY_CACHE_ENABLED,
097                            DDMStorageLinkModelImpl.FINDER_CACHE_ENABLED, Long.class,
098                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByUuid",
099                            new String[] { String.class.getName() });
100            public static final FinderPath FINDER_PATH_FETCH_BY_CLASSPK = new FinderPath(DDMStorageLinkModelImpl.ENTITY_CACHE_ENABLED,
101                            DDMStorageLinkModelImpl.FINDER_CACHE_ENABLED,
102                            DDMStorageLinkImpl.class, FINDER_CLASS_NAME_ENTITY,
103                            "fetchByClassPK", new String[] { Long.class.getName() },
104                            DDMStorageLinkModelImpl.CLASSPK_COLUMN_BITMASK);
105            public static final FinderPath FINDER_PATH_COUNT_BY_CLASSPK = new FinderPath(DDMStorageLinkModelImpl.ENTITY_CACHE_ENABLED,
106                            DDMStorageLinkModelImpl.FINDER_CACHE_ENABLED, Long.class,
107                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByClassPK",
108                            new String[] { Long.class.getName() });
109            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_STRUCTUREID =
110                    new FinderPath(DDMStorageLinkModelImpl.ENTITY_CACHE_ENABLED,
111                            DDMStorageLinkModelImpl.FINDER_CACHE_ENABLED,
112                            DDMStorageLinkImpl.class, FINDER_CLASS_NAME_LIST_WITH_PAGINATION,
113                            "findByStructureId",
114                            new String[] {
115                                    Long.class.getName(),
116                                    
117                            "java.lang.Integer", "java.lang.Integer",
118                                    "com.liferay.portal.kernel.util.OrderByComparator"
119                            });
120            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_STRUCTUREID =
121                    new FinderPath(DDMStorageLinkModelImpl.ENTITY_CACHE_ENABLED,
122                            DDMStorageLinkModelImpl.FINDER_CACHE_ENABLED,
123                            DDMStorageLinkImpl.class,
124                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByStructureId",
125                            new String[] { Long.class.getName() },
126                            DDMStorageLinkModelImpl.STRUCTUREID_COLUMN_BITMASK);
127            public static final FinderPath FINDER_PATH_COUNT_BY_STRUCTUREID = new FinderPath(DDMStorageLinkModelImpl.ENTITY_CACHE_ENABLED,
128                            DDMStorageLinkModelImpl.FINDER_CACHE_ENABLED, Long.class,
129                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByStructureId",
130                            new String[] { Long.class.getName() });
131            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_ALL = new FinderPath(DDMStorageLinkModelImpl.ENTITY_CACHE_ENABLED,
132                            DDMStorageLinkModelImpl.FINDER_CACHE_ENABLED,
133                            DDMStorageLinkImpl.class, FINDER_CLASS_NAME_LIST_WITH_PAGINATION,
134                            "findAll", new String[0]);
135            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL = new FinderPath(DDMStorageLinkModelImpl.ENTITY_CACHE_ENABLED,
136                            DDMStorageLinkModelImpl.FINDER_CACHE_ENABLED,
137                            DDMStorageLinkImpl.class,
138                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findAll", new String[0]);
139            public static final FinderPath FINDER_PATH_COUNT_ALL = new FinderPath(DDMStorageLinkModelImpl.ENTITY_CACHE_ENABLED,
140                            DDMStorageLinkModelImpl.FINDER_CACHE_ENABLED, Long.class,
141                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countAll", new String[0]);
142    
143            /**
144             * Caches the d d m storage link in the entity cache if it is enabled.
145             *
146             * @param ddmStorageLink the d d m storage link
147             */
148            public void cacheResult(DDMStorageLink ddmStorageLink) {
149                    EntityCacheUtil.putResult(DDMStorageLinkModelImpl.ENTITY_CACHE_ENABLED,
150                            DDMStorageLinkImpl.class, ddmStorageLink.getPrimaryKey(),
151                            ddmStorageLink);
152    
153                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_CLASSPK,
154                            new Object[] { Long.valueOf(ddmStorageLink.getClassPK()) },
155                            ddmStorageLink);
156    
157                    ddmStorageLink.resetOriginalValues();
158            }
159    
160            /**
161             * Caches the d d m storage links in the entity cache if it is enabled.
162             *
163             * @param ddmStorageLinks the d d m storage links
164             */
165            public void cacheResult(List<DDMStorageLink> ddmStorageLinks) {
166                    for (DDMStorageLink ddmStorageLink : ddmStorageLinks) {
167                            if (EntityCacheUtil.getResult(
168                                                    DDMStorageLinkModelImpl.ENTITY_CACHE_ENABLED,
169                                                    DDMStorageLinkImpl.class, ddmStorageLink.getPrimaryKey()) == null) {
170                                    cacheResult(ddmStorageLink);
171                            }
172                            else {
173                                    ddmStorageLink.resetOriginalValues();
174                            }
175                    }
176            }
177    
178            /**
179             * Clears the cache for all d d m storage links.
180             *
181             * <p>
182             * The {@link com.liferay.portal.kernel.dao.orm.EntityCache} and {@link com.liferay.portal.kernel.dao.orm.FinderCache} are both cleared by this method.
183             * </p>
184             */
185            @Override
186            public void clearCache() {
187                    if (_HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE) {
188                            CacheRegistryUtil.clear(DDMStorageLinkImpl.class.getName());
189                    }
190    
191                    EntityCacheUtil.clearCache(DDMStorageLinkImpl.class.getName());
192    
193                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_ENTITY);
194                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
195                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
196            }
197    
198            /**
199             * Clears the cache for the d d m storage link.
200             *
201             * <p>
202             * The {@link com.liferay.portal.kernel.dao.orm.EntityCache} and {@link com.liferay.portal.kernel.dao.orm.FinderCache} are both cleared by this method.
203             * </p>
204             */
205            @Override
206            public void clearCache(DDMStorageLink ddmStorageLink) {
207                    EntityCacheUtil.removeResult(DDMStorageLinkModelImpl.ENTITY_CACHE_ENABLED,
208                            DDMStorageLinkImpl.class, ddmStorageLink.getPrimaryKey());
209    
210                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
211                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
212    
213                    clearUniqueFindersCache(ddmStorageLink);
214            }
215    
216            @Override
217            public void clearCache(List<DDMStorageLink> ddmStorageLinks) {
218                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
219                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
220    
221                    for (DDMStorageLink ddmStorageLink : ddmStorageLinks) {
222                            EntityCacheUtil.removeResult(DDMStorageLinkModelImpl.ENTITY_CACHE_ENABLED,
223                                    DDMStorageLinkImpl.class, ddmStorageLink.getPrimaryKey());
224    
225                            clearUniqueFindersCache(ddmStorageLink);
226                    }
227            }
228    
229            protected void cacheUniqueFindersCache(DDMStorageLink ddmStorageLink) {
230                    if (ddmStorageLink.isNew()) {
231                            Object[] args = new Object[] {
232                                            Long.valueOf(ddmStorageLink.getClassPK())
233                                    };
234    
235                            FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_CLASSPK, args,
236                                    Long.valueOf(1));
237                            FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_CLASSPK, args,
238                                    ddmStorageLink);
239                    }
240                    else {
241                            DDMStorageLinkModelImpl ddmStorageLinkModelImpl = (DDMStorageLinkModelImpl)ddmStorageLink;
242    
243                            if ((ddmStorageLinkModelImpl.getColumnBitmask() &
244                                            FINDER_PATH_FETCH_BY_CLASSPK.getColumnBitmask()) != 0) {
245                                    Object[] args = new Object[] {
246                                                    Long.valueOf(ddmStorageLink.getClassPK())
247                                            };
248    
249                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_CLASSPK, args,
250                                            Long.valueOf(1));
251                                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_CLASSPK, args,
252                                            ddmStorageLink);
253                            }
254                    }
255            }
256    
257            protected void clearUniqueFindersCache(DDMStorageLink ddmStorageLink) {
258                    DDMStorageLinkModelImpl ddmStorageLinkModelImpl = (DDMStorageLinkModelImpl)ddmStorageLink;
259    
260                    Object[] args = new Object[] { Long.valueOf(ddmStorageLink.getClassPK()) };
261    
262                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_CLASSPK, args);
263                    FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_CLASSPK, args);
264    
265                    if ((ddmStorageLinkModelImpl.getColumnBitmask() &
266                                    FINDER_PATH_FETCH_BY_CLASSPK.getColumnBitmask()) != 0) {
267                            args = new Object[] {
268                                            Long.valueOf(ddmStorageLinkModelImpl.getOriginalClassPK())
269                                    };
270    
271                            FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_CLASSPK, args);
272                            FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_CLASSPK, args);
273                    }
274            }
275    
276            /**
277             * Creates a new d d m storage link with the primary key. Does not add the d d m storage link to the database.
278             *
279             * @param storageLinkId the primary key for the new d d m storage link
280             * @return the new d d m storage link
281             */
282            public DDMStorageLink create(long storageLinkId) {
283                    DDMStorageLink ddmStorageLink = new DDMStorageLinkImpl();
284    
285                    ddmStorageLink.setNew(true);
286                    ddmStorageLink.setPrimaryKey(storageLinkId);
287    
288                    String uuid = PortalUUIDUtil.generate();
289    
290                    ddmStorageLink.setUuid(uuid);
291    
292                    return ddmStorageLink;
293            }
294    
295            /**
296             * Removes the d d m storage link with the primary key from the database. Also notifies the appropriate model listeners.
297             *
298             * @param storageLinkId the primary key of the d d m storage link
299             * @return the d d m storage link that was removed
300             * @throws com.liferay.portlet.dynamicdatamapping.NoSuchStorageLinkException if a d d m storage link with the primary key could not be found
301             * @throws SystemException if a system exception occurred
302             */
303            public DDMStorageLink remove(long storageLinkId)
304                    throws NoSuchStorageLinkException, SystemException {
305                    return remove(Long.valueOf(storageLinkId));
306            }
307    
308            /**
309             * Removes the d d m storage link with the primary key from the database. Also notifies the appropriate model listeners.
310             *
311             * @param primaryKey the primary key of the d d m storage link
312             * @return the d d m storage link that was removed
313             * @throws com.liferay.portlet.dynamicdatamapping.NoSuchStorageLinkException if a d d m storage link with the primary key could not be found
314             * @throws SystemException if a system exception occurred
315             */
316            @Override
317            public DDMStorageLink remove(Serializable primaryKey)
318                    throws NoSuchStorageLinkException, SystemException {
319                    Session session = null;
320    
321                    try {
322                            session = openSession();
323    
324                            DDMStorageLink ddmStorageLink = (DDMStorageLink)session.get(DDMStorageLinkImpl.class,
325                                            primaryKey);
326    
327                            if (ddmStorageLink == null) {
328                                    if (_log.isWarnEnabled()) {
329                                            _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + primaryKey);
330                                    }
331    
332                                    throw new NoSuchStorageLinkException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
333                                            primaryKey);
334                            }
335    
336                            return remove(ddmStorageLink);
337                    }
338                    catch (NoSuchStorageLinkException nsee) {
339                            throw nsee;
340                    }
341                    catch (Exception e) {
342                            throw processException(e);
343                    }
344                    finally {
345                            closeSession(session);
346                    }
347            }
348    
349            @Override
350            protected DDMStorageLink removeImpl(DDMStorageLink ddmStorageLink)
351                    throws SystemException {
352                    ddmStorageLink = toUnwrappedModel(ddmStorageLink);
353    
354                    Session session = null;
355    
356                    try {
357                            session = openSession();
358    
359                            BatchSessionUtil.delete(session, ddmStorageLink);
360                    }
361                    catch (Exception e) {
362                            throw processException(e);
363                    }
364                    finally {
365                            closeSession(session);
366                    }
367    
368                    clearCache(ddmStorageLink);
369    
370                    return ddmStorageLink;
371            }
372    
373            @Override
374            public DDMStorageLink updateImpl(
375                    com.liferay.portlet.dynamicdatamapping.model.DDMStorageLink ddmStorageLink,
376                    boolean merge) throws SystemException {
377                    ddmStorageLink = toUnwrappedModel(ddmStorageLink);
378    
379                    boolean isNew = ddmStorageLink.isNew();
380    
381                    DDMStorageLinkModelImpl ddmStorageLinkModelImpl = (DDMStorageLinkModelImpl)ddmStorageLink;
382    
383                    if (Validator.isNull(ddmStorageLink.getUuid())) {
384                            String uuid = PortalUUIDUtil.generate();
385    
386                            ddmStorageLink.setUuid(uuid);
387                    }
388    
389                    Session session = null;
390    
391                    try {
392                            session = openSession();
393    
394                            BatchSessionUtil.update(session, ddmStorageLink, merge);
395    
396                            ddmStorageLink.setNew(false);
397                    }
398                    catch (Exception e) {
399                            throw processException(e);
400                    }
401                    finally {
402                            closeSession(session);
403                    }
404    
405                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
406    
407                    if (isNew || !DDMStorageLinkModelImpl.COLUMN_BITMASK_ENABLED) {
408                            FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
409                    }
410    
411                    else {
412                            if ((ddmStorageLinkModelImpl.getColumnBitmask() &
413                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID.getColumnBitmask()) != 0) {
414                                    Object[] args = new Object[] {
415                                                    ddmStorageLinkModelImpl.getOriginalUuid()
416                                            };
417    
418                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_UUID, args);
419                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID,
420                                            args);
421    
422                                    args = new Object[] { ddmStorageLinkModelImpl.getUuid() };
423    
424                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_UUID, args);
425                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID,
426                                            args);
427                            }
428    
429                            if ((ddmStorageLinkModelImpl.getColumnBitmask() &
430                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_STRUCTUREID.getColumnBitmask()) != 0) {
431                                    Object[] args = new Object[] {
432                                                    Long.valueOf(ddmStorageLinkModelImpl.getOriginalStructureId())
433                                            };
434    
435                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_STRUCTUREID,
436                                            args);
437                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_STRUCTUREID,
438                                            args);
439    
440                                    args = new Object[] {
441                                                    Long.valueOf(ddmStorageLinkModelImpl.getStructureId())
442                                            };
443    
444                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_STRUCTUREID,
445                                            args);
446                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_STRUCTUREID,
447                                            args);
448                            }
449                    }
450    
451                    EntityCacheUtil.putResult(DDMStorageLinkModelImpl.ENTITY_CACHE_ENABLED,
452                            DDMStorageLinkImpl.class, ddmStorageLink.getPrimaryKey(),
453                            ddmStorageLink);
454    
455                    clearUniqueFindersCache(ddmStorageLink);
456                    cacheUniqueFindersCache(ddmStorageLink);
457    
458                    return ddmStorageLink;
459            }
460    
461            protected DDMStorageLink toUnwrappedModel(DDMStorageLink ddmStorageLink) {
462                    if (ddmStorageLink instanceof DDMStorageLinkImpl) {
463                            return ddmStorageLink;
464                    }
465    
466                    DDMStorageLinkImpl ddmStorageLinkImpl = new DDMStorageLinkImpl();
467    
468                    ddmStorageLinkImpl.setNew(ddmStorageLink.isNew());
469                    ddmStorageLinkImpl.setPrimaryKey(ddmStorageLink.getPrimaryKey());
470    
471                    ddmStorageLinkImpl.setUuid(ddmStorageLink.getUuid());
472                    ddmStorageLinkImpl.setStorageLinkId(ddmStorageLink.getStorageLinkId());
473                    ddmStorageLinkImpl.setClassNameId(ddmStorageLink.getClassNameId());
474                    ddmStorageLinkImpl.setClassPK(ddmStorageLink.getClassPK());
475                    ddmStorageLinkImpl.setStructureId(ddmStorageLink.getStructureId());
476    
477                    return ddmStorageLinkImpl;
478            }
479    
480            /**
481             * Returns the d d m storage link with the primary key or throws a {@link com.liferay.portal.NoSuchModelException} if it could not be found.
482             *
483             * @param primaryKey the primary key of the d d m storage link
484             * @return the d d m storage link
485             * @throws com.liferay.portal.NoSuchModelException if a d d m storage link with the primary key could not be found
486             * @throws SystemException if a system exception occurred
487             */
488            @Override
489            public DDMStorageLink findByPrimaryKey(Serializable primaryKey)
490                    throws NoSuchModelException, SystemException {
491                    return findByPrimaryKey(((Long)primaryKey).longValue());
492            }
493    
494            /**
495             * Returns the d d m storage link with the primary key or throws a {@link com.liferay.portlet.dynamicdatamapping.NoSuchStorageLinkException} if it could not be found.
496             *
497             * @param storageLinkId the primary key of the d d m storage link
498             * @return the d d m storage link
499             * @throws com.liferay.portlet.dynamicdatamapping.NoSuchStorageLinkException if a d d m storage link with the primary key could not be found
500             * @throws SystemException if a system exception occurred
501             */
502            public DDMStorageLink findByPrimaryKey(long storageLinkId)
503                    throws NoSuchStorageLinkException, SystemException {
504                    DDMStorageLink ddmStorageLink = fetchByPrimaryKey(storageLinkId);
505    
506                    if (ddmStorageLink == null) {
507                            if (_log.isWarnEnabled()) {
508                                    _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + storageLinkId);
509                            }
510    
511                            throw new NoSuchStorageLinkException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
512                                    storageLinkId);
513                    }
514    
515                    return ddmStorageLink;
516            }
517    
518            /**
519             * Returns the d d m storage link with the primary key or returns <code>null</code> if it could not be found.
520             *
521             * @param primaryKey the primary key of the d d m storage link
522             * @return the d d m storage link, or <code>null</code> if a d d m storage link with the primary key could not be found
523             * @throws SystemException if a system exception occurred
524             */
525            @Override
526            public DDMStorageLink fetchByPrimaryKey(Serializable primaryKey)
527                    throws SystemException {
528                    return fetchByPrimaryKey(((Long)primaryKey).longValue());
529            }
530    
531            /**
532             * Returns the d d m storage link with the primary key or returns <code>null</code> if it could not be found.
533             *
534             * @param storageLinkId the primary key of the d d m storage link
535             * @return the d d m storage link, or <code>null</code> if a d d m storage link with the primary key could not be found
536             * @throws SystemException if a system exception occurred
537             */
538            public DDMStorageLink fetchByPrimaryKey(long storageLinkId)
539                    throws SystemException {
540                    DDMStorageLink ddmStorageLink = (DDMStorageLink)EntityCacheUtil.getResult(DDMStorageLinkModelImpl.ENTITY_CACHE_ENABLED,
541                                    DDMStorageLinkImpl.class, storageLinkId);
542    
543                    if (ddmStorageLink == _nullDDMStorageLink) {
544                            return null;
545                    }
546    
547                    if (ddmStorageLink == null) {
548                            Session session = null;
549    
550                            boolean hasException = false;
551    
552                            try {
553                                    session = openSession();
554    
555                                    ddmStorageLink = (DDMStorageLink)session.get(DDMStorageLinkImpl.class,
556                                                    Long.valueOf(storageLinkId));
557                            }
558                            catch (Exception e) {
559                                    hasException = true;
560    
561                                    throw processException(e);
562                            }
563                            finally {
564                                    if (ddmStorageLink != null) {
565                                            cacheResult(ddmStorageLink);
566                                    }
567                                    else if (!hasException) {
568                                            EntityCacheUtil.putResult(DDMStorageLinkModelImpl.ENTITY_CACHE_ENABLED,
569                                                    DDMStorageLinkImpl.class, storageLinkId,
570                                                    _nullDDMStorageLink);
571                                    }
572    
573                                    closeSession(session);
574                            }
575                    }
576    
577                    return ddmStorageLink;
578            }
579    
580            /**
581             * Returns all the d d m storage links where uuid = &#63;.
582             *
583             * @param uuid the uuid
584             * @return the matching d d m storage links
585             * @throws SystemException if a system exception occurred
586             */
587            public List<DDMStorageLink> findByUuid(String uuid)
588                    throws SystemException {
589                    return findByUuid(uuid, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
590            }
591    
592            /**
593             * Returns a range of all the d d m storage links where uuid = &#63;.
594             *
595             * <p>
596             * 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.
597             * </p>
598             *
599             * @param uuid the uuid
600             * @param start the lower bound of the range of d d m storage links
601             * @param end the upper bound of the range of d d m storage links (not inclusive)
602             * @return the range of matching d d m storage links
603             * @throws SystemException if a system exception occurred
604             */
605            public List<DDMStorageLink> findByUuid(String uuid, int start, int end)
606                    throws SystemException {
607                    return findByUuid(uuid, start, end, null);
608            }
609    
610            /**
611             * Returns an ordered range of all the d d m storage links where uuid = &#63;.
612             *
613             * <p>
614             * 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.
615             * </p>
616             *
617             * @param uuid the uuid
618             * @param start the lower bound of the range of d d m storage links
619             * @param end the upper bound of the range of d d m storage links (not inclusive)
620             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
621             * @return the ordered range of matching d d m storage links
622             * @throws SystemException if a system exception occurred
623             */
624            public List<DDMStorageLink> findByUuid(String uuid, int start, int end,
625                    OrderByComparator orderByComparator) throws SystemException {
626                    FinderPath finderPath = null;
627                    Object[] finderArgs = null;
628    
629                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
630                                    (orderByComparator == null)) {
631                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID;
632                            finderArgs = new Object[] { uuid };
633                    }
634                    else {
635                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_UUID;
636                            finderArgs = new Object[] { uuid, start, end, orderByComparator };
637                    }
638    
639                    List<DDMStorageLink> list = (List<DDMStorageLink>)FinderCacheUtil.getResult(finderPath,
640                                    finderArgs, this);
641    
642                    if ((list != null) && !list.isEmpty()) {
643                            for (DDMStorageLink ddmStorageLink : list) {
644                                    if (!Validator.equals(uuid, ddmStorageLink.getUuid())) {
645                                            list = null;
646    
647                                            break;
648                                    }
649                            }
650                    }
651    
652                    if (list == null) {
653                            StringBundler query = null;
654    
655                            if (orderByComparator != null) {
656                                    query = new StringBundler(3 +
657                                                    (orderByComparator.getOrderByFields().length * 3));
658                            }
659                            else {
660                                    query = new StringBundler(2);
661                            }
662    
663                            query.append(_SQL_SELECT_DDMSTORAGELINK_WHERE);
664    
665                            if (uuid == null) {
666                                    query.append(_FINDER_COLUMN_UUID_UUID_1);
667                            }
668                            else {
669                                    if (uuid.equals(StringPool.BLANK)) {
670                                            query.append(_FINDER_COLUMN_UUID_UUID_3);
671                                    }
672                                    else {
673                                            query.append(_FINDER_COLUMN_UUID_UUID_2);
674                                    }
675                            }
676    
677                            if (orderByComparator != null) {
678                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
679                                            orderByComparator);
680                            }
681    
682                            String sql = query.toString();
683    
684                            Session session = null;
685    
686                            try {
687                                    session = openSession();
688    
689                                    Query q = session.createQuery(sql);
690    
691                                    QueryPos qPos = QueryPos.getInstance(q);
692    
693                                    if (uuid != null) {
694                                            qPos.add(uuid);
695                                    }
696    
697                                    list = (List<DDMStorageLink>)QueryUtil.list(q, getDialect(),
698                                                    start, end);
699                            }
700                            catch (Exception e) {
701                                    throw processException(e);
702                            }
703                            finally {
704                                    if (list == null) {
705                                            FinderCacheUtil.removeResult(finderPath, finderArgs);
706                                    }
707                                    else {
708                                            cacheResult(list);
709    
710                                            FinderCacheUtil.putResult(finderPath, finderArgs, list);
711                                    }
712    
713                                    closeSession(session);
714                            }
715                    }
716    
717                    return list;
718            }
719    
720            /**
721             * Returns the first d d m storage link in the ordered set where uuid = &#63;.
722             *
723             * @param uuid the uuid
724             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
725             * @return the first matching d d m storage link
726             * @throws com.liferay.portlet.dynamicdatamapping.NoSuchStorageLinkException if a matching d d m storage link could not be found
727             * @throws SystemException if a system exception occurred
728             */
729            public DDMStorageLink findByUuid_First(String uuid,
730                    OrderByComparator orderByComparator)
731                    throws NoSuchStorageLinkException, SystemException {
732                    DDMStorageLink ddmStorageLink = fetchByUuid_First(uuid,
733                                    orderByComparator);
734    
735                    if (ddmStorageLink != null) {
736                            return ddmStorageLink;
737                    }
738    
739                    StringBundler msg = new StringBundler(4);
740    
741                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
742    
743                    msg.append("uuid=");
744                    msg.append(uuid);
745    
746                    msg.append(StringPool.CLOSE_CURLY_BRACE);
747    
748                    throw new NoSuchStorageLinkException(msg.toString());
749            }
750    
751            /**
752             * Returns the first d d m storage link in the ordered set where uuid = &#63;.
753             *
754             * @param uuid the uuid
755             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
756             * @return the first matching d d m storage link, or <code>null</code> if a matching d d m storage link could not be found
757             * @throws SystemException if a system exception occurred
758             */
759            public DDMStorageLink fetchByUuid_First(String uuid,
760                    OrderByComparator orderByComparator) throws SystemException {
761                    List<DDMStorageLink> list = findByUuid(uuid, 0, 1, orderByComparator);
762    
763                    if (!list.isEmpty()) {
764                            return list.get(0);
765                    }
766    
767                    return null;
768            }
769    
770            /**
771             * Returns the last d d m storage link in the ordered set where uuid = &#63;.
772             *
773             * @param uuid the uuid
774             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
775             * @return the last matching d d m storage link
776             * @throws com.liferay.portlet.dynamicdatamapping.NoSuchStorageLinkException if a matching d d m storage link could not be found
777             * @throws SystemException if a system exception occurred
778             */
779            public DDMStorageLink findByUuid_Last(String uuid,
780                    OrderByComparator orderByComparator)
781                    throws NoSuchStorageLinkException, SystemException {
782                    DDMStorageLink ddmStorageLink = fetchByUuid_Last(uuid, orderByComparator);
783    
784                    if (ddmStorageLink != null) {
785                            return ddmStorageLink;
786                    }
787    
788                    StringBundler msg = new StringBundler(4);
789    
790                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
791    
792                    msg.append("uuid=");
793                    msg.append(uuid);
794    
795                    msg.append(StringPool.CLOSE_CURLY_BRACE);
796    
797                    throw new NoSuchStorageLinkException(msg.toString());
798            }
799    
800            /**
801             * Returns the last d d m storage link in the ordered set where uuid = &#63;.
802             *
803             * @param uuid the uuid
804             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
805             * @return the last matching d d m storage link, or <code>null</code> if a matching d d m storage link could not be found
806             * @throws SystemException if a system exception occurred
807             */
808            public DDMStorageLink fetchByUuid_Last(String uuid,
809                    OrderByComparator orderByComparator) throws SystemException {
810                    int count = countByUuid(uuid);
811    
812                    List<DDMStorageLink> list = findByUuid(uuid, count - 1, count,
813                                    orderByComparator);
814    
815                    if (!list.isEmpty()) {
816                            return list.get(0);
817                    }
818    
819                    return null;
820            }
821    
822            /**
823             * Returns the d d m storage links before and after the current d d m storage link in the ordered set where uuid = &#63;.
824             *
825             * @param storageLinkId the primary key of the current d d m storage link
826             * @param uuid the uuid
827             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
828             * @return the previous, current, and next d d m storage link
829             * @throws com.liferay.portlet.dynamicdatamapping.NoSuchStorageLinkException if a d d m storage link with the primary key could not be found
830             * @throws SystemException if a system exception occurred
831             */
832            public DDMStorageLink[] findByUuid_PrevAndNext(long storageLinkId,
833                    String uuid, OrderByComparator orderByComparator)
834                    throws NoSuchStorageLinkException, SystemException {
835                    DDMStorageLink ddmStorageLink = findByPrimaryKey(storageLinkId);
836    
837                    Session session = null;
838    
839                    try {
840                            session = openSession();
841    
842                            DDMStorageLink[] array = new DDMStorageLinkImpl[3];
843    
844                            array[0] = getByUuid_PrevAndNext(session, ddmStorageLink, uuid,
845                                            orderByComparator, true);
846    
847                            array[1] = ddmStorageLink;
848    
849                            array[2] = getByUuid_PrevAndNext(session, ddmStorageLink, uuid,
850                                            orderByComparator, false);
851    
852                            return array;
853                    }
854                    catch (Exception e) {
855                            throw processException(e);
856                    }
857                    finally {
858                            closeSession(session);
859                    }
860            }
861    
862            protected DDMStorageLink getByUuid_PrevAndNext(Session session,
863                    DDMStorageLink ddmStorageLink, String uuid,
864                    OrderByComparator orderByComparator, boolean previous) {
865                    StringBundler query = null;
866    
867                    if (orderByComparator != null) {
868                            query = new StringBundler(6 +
869                                            (orderByComparator.getOrderByFields().length * 6));
870                    }
871                    else {
872                            query = new StringBundler(3);
873                    }
874    
875                    query.append(_SQL_SELECT_DDMSTORAGELINK_WHERE);
876    
877                    if (uuid == null) {
878                            query.append(_FINDER_COLUMN_UUID_UUID_1);
879                    }
880                    else {
881                            if (uuid.equals(StringPool.BLANK)) {
882                                    query.append(_FINDER_COLUMN_UUID_UUID_3);
883                            }
884                            else {
885                                    query.append(_FINDER_COLUMN_UUID_UUID_2);
886                            }
887                    }
888    
889                    if (orderByComparator != null) {
890                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
891    
892                            if (orderByConditionFields.length > 0) {
893                                    query.append(WHERE_AND);
894                            }
895    
896                            for (int i = 0; i < orderByConditionFields.length; i++) {
897                                    query.append(_ORDER_BY_ENTITY_ALIAS);
898                                    query.append(orderByConditionFields[i]);
899    
900                                    if ((i + 1) < orderByConditionFields.length) {
901                                            if (orderByComparator.isAscending() ^ previous) {
902                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
903                                            }
904                                            else {
905                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
906                                            }
907                                    }
908                                    else {
909                                            if (orderByComparator.isAscending() ^ previous) {
910                                                    query.append(WHERE_GREATER_THAN);
911                                            }
912                                            else {
913                                                    query.append(WHERE_LESSER_THAN);
914                                            }
915                                    }
916                            }
917    
918                            query.append(ORDER_BY_CLAUSE);
919    
920                            String[] orderByFields = orderByComparator.getOrderByFields();
921    
922                            for (int i = 0; i < orderByFields.length; i++) {
923                                    query.append(_ORDER_BY_ENTITY_ALIAS);
924                                    query.append(orderByFields[i]);
925    
926                                    if ((i + 1) < orderByFields.length) {
927                                            if (orderByComparator.isAscending() ^ previous) {
928                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
929                                            }
930                                            else {
931                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
932                                            }
933                                    }
934                                    else {
935                                            if (orderByComparator.isAscending() ^ previous) {
936                                                    query.append(ORDER_BY_ASC);
937                                            }
938                                            else {
939                                                    query.append(ORDER_BY_DESC);
940                                            }
941                                    }
942                            }
943                    }
944    
945                    String sql = query.toString();
946    
947                    Query q = session.createQuery(sql);
948    
949                    q.setFirstResult(0);
950                    q.setMaxResults(2);
951    
952                    QueryPos qPos = QueryPos.getInstance(q);
953    
954                    if (uuid != null) {
955                            qPos.add(uuid);
956                    }
957    
958                    if (orderByComparator != null) {
959                            Object[] values = orderByComparator.getOrderByConditionValues(ddmStorageLink);
960    
961                            for (Object value : values) {
962                                    qPos.add(value);
963                            }
964                    }
965    
966                    List<DDMStorageLink> list = q.list();
967    
968                    if (list.size() == 2) {
969                            return list.get(1);
970                    }
971                    else {
972                            return null;
973                    }
974            }
975    
976            /**
977             * Returns the d d m storage link where classPK = &#63; or throws a {@link com.liferay.portlet.dynamicdatamapping.NoSuchStorageLinkException} if it could not be found.
978             *
979             * @param classPK the class p k
980             * @return the matching d d m storage link
981             * @throws com.liferay.portlet.dynamicdatamapping.NoSuchStorageLinkException if a matching d d m storage link could not be found
982             * @throws SystemException if a system exception occurred
983             */
984            public DDMStorageLink findByClassPK(long classPK)
985                    throws NoSuchStorageLinkException, SystemException {
986                    DDMStorageLink ddmStorageLink = fetchByClassPK(classPK);
987    
988                    if (ddmStorageLink == null) {
989                            StringBundler msg = new StringBundler(4);
990    
991                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
992    
993                            msg.append("classPK=");
994                            msg.append(classPK);
995    
996                            msg.append(StringPool.CLOSE_CURLY_BRACE);
997    
998                            if (_log.isWarnEnabled()) {
999                                    _log.warn(msg.toString());
1000                            }
1001    
1002                            throw new NoSuchStorageLinkException(msg.toString());
1003                    }
1004    
1005                    return ddmStorageLink;
1006            }
1007    
1008            /**
1009             * Returns the d d m storage link where classPK = &#63; or returns <code>null</code> if it could not be found. Uses the finder cache.
1010             *
1011             * @param classPK the class p k
1012             * @return the matching d d m storage link, or <code>null</code> if a matching d d m storage link could not be found
1013             * @throws SystemException if a system exception occurred
1014             */
1015            public DDMStorageLink fetchByClassPK(long classPK)
1016                    throws SystemException {
1017                    return fetchByClassPK(classPK, true);
1018            }
1019    
1020            /**
1021             * Returns the d d m storage link where classPK = &#63; or returns <code>null</code> if it could not be found, optionally using the finder cache.
1022             *
1023             * @param classPK the class p k
1024             * @param retrieveFromCache whether to use the finder cache
1025             * @return the matching d d m storage link, or <code>null</code> if a matching d d m storage link could not be found
1026             * @throws SystemException if a system exception occurred
1027             */
1028            public DDMStorageLink fetchByClassPK(long classPK, boolean retrieveFromCache)
1029                    throws SystemException {
1030                    Object[] finderArgs = new Object[] { classPK };
1031    
1032                    Object result = null;
1033    
1034                    if (retrieveFromCache) {
1035                            result = FinderCacheUtil.getResult(FINDER_PATH_FETCH_BY_CLASSPK,
1036                                            finderArgs, this);
1037                    }
1038    
1039                    if (result instanceof DDMStorageLink) {
1040                            DDMStorageLink ddmStorageLink = (DDMStorageLink)result;
1041    
1042                            if ((classPK != ddmStorageLink.getClassPK())) {
1043                                    result = null;
1044                            }
1045                    }
1046    
1047                    if (result == null) {
1048                            StringBundler query = new StringBundler(2);
1049    
1050                            query.append(_SQL_SELECT_DDMSTORAGELINK_WHERE);
1051    
1052                            query.append(_FINDER_COLUMN_CLASSPK_CLASSPK_2);
1053    
1054                            String sql = query.toString();
1055    
1056                            Session session = null;
1057    
1058                            try {
1059                                    session = openSession();
1060    
1061                                    Query q = session.createQuery(sql);
1062    
1063                                    QueryPos qPos = QueryPos.getInstance(q);
1064    
1065                                    qPos.add(classPK);
1066    
1067                                    List<DDMStorageLink> list = q.list();
1068    
1069                                    result = list;
1070    
1071                                    DDMStorageLink ddmStorageLink = null;
1072    
1073                                    if (list.isEmpty()) {
1074                                            FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_CLASSPK,
1075                                                    finderArgs, list);
1076                                    }
1077                                    else {
1078                                            ddmStorageLink = list.get(0);
1079    
1080                                            cacheResult(ddmStorageLink);
1081    
1082                                            if ((ddmStorageLink.getClassPK() != classPK)) {
1083                                                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_CLASSPK,
1084                                                            finderArgs, ddmStorageLink);
1085                                            }
1086                                    }
1087    
1088                                    return ddmStorageLink;
1089                            }
1090                            catch (Exception e) {
1091                                    throw processException(e);
1092                            }
1093                            finally {
1094                                    if (result == null) {
1095                                            FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_CLASSPK,
1096                                                    finderArgs);
1097                                    }
1098    
1099                                    closeSession(session);
1100                            }
1101                    }
1102                    else {
1103                            if (result instanceof List<?>) {
1104                                    return null;
1105                            }
1106                            else {
1107                                    return (DDMStorageLink)result;
1108                            }
1109                    }
1110            }
1111    
1112            /**
1113             * Returns all the d d m storage links where structureId = &#63;.
1114             *
1115             * @param structureId the structure ID
1116             * @return the matching d d m storage links
1117             * @throws SystemException if a system exception occurred
1118             */
1119            public List<DDMStorageLink> findByStructureId(long structureId)
1120                    throws SystemException {
1121                    return findByStructureId(structureId, QueryUtil.ALL_POS,
1122                            QueryUtil.ALL_POS, null);
1123            }
1124    
1125            /**
1126             * Returns a range of all the d d m storage links where structureId = &#63;.
1127             *
1128             * <p>
1129             * 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.
1130             * </p>
1131             *
1132             * @param structureId the structure ID
1133             * @param start the lower bound of the range of d d m storage links
1134             * @param end the upper bound of the range of d d m storage links (not inclusive)
1135             * @return the range of matching d d m storage links
1136             * @throws SystemException if a system exception occurred
1137             */
1138            public List<DDMStorageLink> findByStructureId(long structureId, int start,
1139                    int end) throws SystemException {
1140                    return findByStructureId(structureId, start, end, null);
1141            }
1142    
1143            /**
1144             * Returns an ordered range of all the d d m storage links where structureId = &#63;.
1145             *
1146             * <p>
1147             * 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.
1148             * </p>
1149             *
1150             * @param structureId the structure ID
1151             * @param start the lower bound of the range of d d m storage links
1152             * @param end the upper bound of the range of d d m storage links (not inclusive)
1153             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
1154             * @return the ordered range of matching d d m storage links
1155             * @throws SystemException if a system exception occurred
1156             */
1157            public List<DDMStorageLink> findByStructureId(long structureId, int start,
1158                    int end, OrderByComparator orderByComparator) throws SystemException {
1159                    FinderPath finderPath = null;
1160                    Object[] finderArgs = null;
1161    
1162                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
1163                                    (orderByComparator == null)) {
1164                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_STRUCTUREID;
1165                            finderArgs = new Object[] { structureId };
1166                    }
1167                    else {
1168                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_STRUCTUREID;
1169                            finderArgs = new Object[] { structureId, start, end, orderByComparator };
1170                    }
1171    
1172                    List<DDMStorageLink> list = (List<DDMStorageLink>)FinderCacheUtil.getResult(finderPath,
1173                                    finderArgs, this);
1174    
1175                    if ((list != null) && !list.isEmpty()) {
1176                            for (DDMStorageLink ddmStorageLink : list) {
1177                                    if ((structureId != ddmStorageLink.getStructureId())) {
1178                                            list = null;
1179    
1180                                            break;
1181                                    }
1182                            }
1183                    }
1184    
1185                    if (list == null) {
1186                            StringBundler query = null;
1187    
1188                            if (orderByComparator != null) {
1189                                    query = new StringBundler(3 +
1190                                                    (orderByComparator.getOrderByFields().length * 3));
1191                            }
1192                            else {
1193                                    query = new StringBundler(2);
1194                            }
1195    
1196                            query.append(_SQL_SELECT_DDMSTORAGELINK_WHERE);
1197    
1198                            query.append(_FINDER_COLUMN_STRUCTUREID_STRUCTUREID_2);
1199    
1200                            if (orderByComparator != null) {
1201                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1202                                            orderByComparator);
1203                            }
1204    
1205                            String sql = query.toString();
1206    
1207                            Session session = null;
1208    
1209                            try {
1210                                    session = openSession();
1211    
1212                                    Query q = session.createQuery(sql);
1213    
1214                                    QueryPos qPos = QueryPos.getInstance(q);
1215    
1216                                    qPos.add(structureId);
1217    
1218                                    list = (List<DDMStorageLink>)QueryUtil.list(q, getDialect(),
1219                                                    start, end);
1220                            }
1221                            catch (Exception e) {
1222                                    throw processException(e);
1223                            }
1224                            finally {
1225                                    if (list == null) {
1226                                            FinderCacheUtil.removeResult(finderPath, finderArgs);
1227                                    }
1228                                    else {
1229                                            cacheResult(list);
1230    
1231                                            FinderCacheUtil.putResult(finderPath, finderArgs, list);
1232                                    }
1233    
1234                                    closeSession(session);
1235                            }
1236                    }
1237    
1238                    return list;
1239            }
1240    
1241            /**
1242             * Returns the first d d m storage link in the ordered set where structureId = &#63;.
1243             *
1244             * @param structureId the structure ID
1245             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1246             * @return the first matching d d m storage link
1247             * @throws com.liferay.portlet.dynamicdatamapping.NoSuchStorageLinkException if a matching d d m storage link could not be found
1248             * @throws SystemException if a system exception occurred
1249             */
1250            public DDMStorageLink findByStructureId_First(long structureId,
1251                    OrderByComparator orderByComparator)
1252                    throws NoSuchStorageLinkException, SystemException {
1253                    DDMStorageLink ddmStorageLink = fetchByStructureId_First(structureId,
1254                                    orderByComparator);
1255    
1256                    if (ddmStorageLink != null) {
1257                            return ddmStorageLink;
1258                    }
1259    
1260                    StringBundler msg = new StringBundler(4);
1261    
1262                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1263    
1264                    msg.append("structureId=");
1265                    msg.append(structureId);
1266    
1267                    msg.append(StringPool.CLOSE_CURLY_BRACE);
1268    
1269                    throw new NoSuchStorageLinkException(msg.toString());
1270            }
1271    
1272            /**
1273             * Returns the first d d m storage link in the ordered set where structureId = &#63;.
1274             *
1275             * @param structureId the structure ID
1276             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1277             * @return the first matching d d m storage link, or <code>null</code> if a matching d d m storage link could not be found
1278             * @throws SystemException if a system exception occurred
1279             */
1280            public DDMStorageLink fetchByStructureId_First(long structureId,
1281                    OrderByComparator orderByComparator) throws SystemException {
1282                    List<DDMStorageLink> list = findByStructureId(structureId, 0, 1,
1283                                    orderByComparator);
1284    
1285                    if (!list.isEmpty()) {
1286                            return list.get(0);
1287                    }
1288    
1289                    return null;
1290            }
1291    
1292            /**
1293             * Returns the last d d m storage link in the ordered set where structureId = &#63;.
1294             *
1295             * @param structureId the structure ID
1296             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1297             * @return the last matching d d m storage link
1298             * @throws com.liferay.portlet.dynamicdatamapping.NoSuchStorageLinkException if a matching d d m storage link could not be found
1299             * @throws SystemException if a system exception occurred
1300             */
1301            public DDMStorageLink findByStructureId_Last(long structureId,
1302                    OrderByComparator orderByComparator)
1303                    throws NoSuchStorageLinkException, SystemException {
1304                    DDMStorageLink ddmStorageLink = fetchByStructureId_Last(structureId,
1305                                    orderByComparator);
1306    
1307                    if (ddmStorageLink != null) {
1308                            return ddmStorageLink;
1309                    }
1310    
1311                    StringBundler msg = new StringBundler(4);
1312    
1313                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1314    
1315                    msg.append("structureId=");
1316                    msg.append(structureId);
1317    
1318                    msg.append(StringPool.CLOSE_CURLY_BRACE);
1319    
1320                    throw new NoSuchStorageLinkException(msg.toString());
1321            }
1322    
1323            /**
1324             * Returns the last d d m storage link in the ordered set where structureId = &#63;.
1325             *
1326             * @param structureId the structure ID
1327             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1328             * @return the last matching d d m storage link, or <code>null</code> if a matching d d m storage link could not be found
1329             * @throws SystemException if a system exception occurred
1330             */
1331            public DDMStorageLink fetchByStructureId_Last(long structureId,
1332                    OrderByComparator orderByComparator) throws SystemException {
1333                    int count = countByStructureId(structureId);
1334    
1335                    List<DDMStorageLink> list = findByStructureId(structureId, count - 1,
1336                                    count, orderByComparator);
1337    
1338                    if (!list.isEmpty()) {
1339                            return list.get(0);
1340                    }
1341    
1342                    return null;
1343            }
1344    
1345            /**
1346             * Returns the d d m storage links before and after the current d d m storage link in the ordered set where structureId = &#63;.
1347             *
1348             * @param storageLinkId the primary key of the current d d m storage link
1349             * @param structureId the structure ID
1350             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1351             * @return the previous, current, and next d d m storage link
1352             * @throws com.liferay.portlet.dynamicdatamapping.NoSuchStorageLinkException if a d d m storage link with the primary key could not be found
1353             * @throws SystemException if a system exception occurred
1354             */
1355            public DDMStorageLink[] findByStructureId_PrevAndNext(long storageLinkId,
1356                    long structureId, OrderByComparator orderByComparator)
1357                    throws NoSuchStorageLinkException, SystemException {
1358                    DDMStorageLink ddmStorageLink = findByPrimaryKey(storageLinkId);
1359    
1360                    Session session = null;
1361    
1362                    try {
1363                            session = openSession();
1364    
1365                            DDMStorageLink[] array = new DDMStorageLinkImpl[3];
1366    
1367                            array[0] = getByStructureId_PrevAndNext(session, ddmStorageLink,
1368                                            structureId, orderByComparator, true);
1369    
1370                            array[1] = ddmStorageLink;
1371    
1372                            array[2] = getByStructureId_PrevAndNext(session, ddmStorageLink,
1373                                            structureId, orderByComparator, false);
1374    
1375                            return array;
1376                    }
1377                    catch (Exception e) {
1378                            throw processException(e);
1379                    }
1380                    finally {
1381                            closeSession(session);
1382                    }
1383            }
1384    
1385            protected DDMStorageLink getByStructureId_PrevAndNext(Session session,
1386                    DDMStorageLink ddmStorageLink, long structureId,
1387                    OrderByComparator orderByComparator, boolean previous) {
1388                    StringBundler query = null;
1389    
1390                    if (orderByComparator != null) {
1391                            query = new StringBundler(6 +
1392                                            (orderByComparator.getOrderByFields().length * 6));
1393                    }
1394                    else {
1395                            query = new StringBundler(3);
1396                    }
1397    
1398                    query.append(_SQL_SELECT_DDMSTORAGELINK_WHERE);
1399    
1400                    query.append(_FINDER_COLUMN_STRUCTUREID_STRUCTUREID_2);
1401    
1402                    if (orderByComparator != null) {
1403                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
1404    
1405                            if (orderByConditionFields.length > 0) {
1406                                    query.append(WHERE_AND);
1407                            }
1408    
1409                            for (int i = 0; i < orderByConditionFields.length; i++) {
1410                                    query.append(_ORDER_BY_ENTITY_ALIAS);
1411                                    query.append(orderByConditionFields[i]);
1412    
1413                                    if ((i + 1) < orderByConditionFields.length) {
1414                                            if (orderByComparator.isAscending() ^ previous) {
1415                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
1416                                            }
1417                                            else {
1418                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
1419                                            }
1420                                    }
1421                                    else {
1422                                            if (orderByComparator.isAscending() ^ previous) {
1423                                                    query.append(WHERE_GREATER_THAN);
1424                                            }
1425                                            else {
1426                                                    query.append(WHERE_LESSER_THAN);
1427                                            }
1428                                    }
1429                            }
1430    
1431                            query.append(ORDER_BY_CLAUSE);
1432    
1433                            String[] orderByFields = orderByComparator.getOrderByFields();
1434    
1435                            for (int i = 0; i < orderByFields.length; i++) {
1436                                    query.append(_ORDER_BY_ENTITY_ALIAS);
1437                                    query.append(orderByFields[i]);
1438    
1439                                    if ((i + 1) < orderByFields.length) {
1440                                            if (orderByComparator.isAscending() ^ previous) {
1441                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
1442                                            }
1443                                            else {
1444                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
1445                                            }
1446                                    }
1447                                    else {
1448                                            if (orderByComparator.isAscending() ^ previous) {
1449                                                    query.append(ORDER_BY_ASC);
1450                                            }
1451                                            else {
1452                                                    query.append(ORDER_BY_DESC);
1453                                            }
1454                                    }
1455                            }
1456                    }
1457    
1458                    String sql = query.toString();
1459    
1460                    Query q = session.createQuery(sql);
1461    
1462                    q.setFirstResult(0);
1463                    q.setMaxResults(2);
1464    
1465                    QueryPos qPos = QueryPos.getInstance(q);
1466    
1467                    qPos.add(structureId);
1468    
1469                    if (orderByComparator != null) {
1470                            Object[] values = orderByComparator.getOrderByConditionValues(ddmStorageLink);
1471    
1472                            for (Object value : values) {
1473                                    qPos.add(value);
1474                            }
1475                    }
1476    
1477                    List<DDMStorageLink> list = q.list();
1478    
1479                    if (list.size() == 2) {
1480                            return list.get(1);
1481                    }
1482                    else {
1483                            return null;
1484                    }
1485            }
1486    
1487            /**
1488             * Returns all the d d m storage links.
1489             *
1490             * @return the d d m storage links
1491             * @throws SystemException if a system exception occurred
1492             */
1493            public List<DDMStorageLink> findAll() throws SystemException {
1494                    return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
1495            }
1496    
1497            /**
1498             * Returns a range of all the d d m storage links.
1499             *
1500             * <p>
1501             * 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.
1502             * </p>
1503             *
1504             * @param start the lower bound of the range of d d m storage links
1505             * @param end the upper bound of the range of d d m storage links (not inclusive)
1506             * @return the range of d d m storage links
1507             * @throws SystemException if a system exception occurred
1508             */
1509            public List<DDMStorageLink> findAll(int start, int end)
1510                    throws SystemException {
1511                    return findAll(start, end, null);
1512            }
1513    
1514            /**
1515             * Returns an ordered range of all the d d m storage links.
1516             *
1517             * <p>
1518             * 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.
1519             * </p>
1520             *
1521             * @param start the lower bound of the range of d d m storage links
1522             * @param end the upper bound of the range of d d m storage links (not inclusive)
1523             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
1524             * @return the ordered range of d d m storage links
1525             * @throws SystemException if a system exception occurred
1526             */
1527            public List<DDMStorageLink> findAll(int start, int end,
1528                    OrderByComparator orderByComparator) throws SystemException {
1529                    FinderPath finderPath = null;
1530                    Object[] finderArgs = new Object[] { start, end, orderByComparator };
1531    
1532                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
1533                                    (orderByComparator == null)) {
1534                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL;
1535                            finderArgs = FINDER_ARGS_EMPTY;
1536                    }
1537                    else {
1538                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_ALL;
1539                            finderArgs = new Object[] { start, end, orderByComparator };
1540                    }
1541    
1542                    List<DDMStorageLink> list = (List<DDMStorageLink>)FinderCacheUtil.getResult(finderPath,
1543                                    finderArgs, this);
1544    
1545                    if (list == null) {
1546                            StringBundler query = null;
1547                            String sql = null;
1548    
1549                            if (orderByComparator != null) {
1550                                    query = new StringBundler(2 +
1551                                                    (orderByComparator.getOrderByFields().length * 3));
1552    
1553                                    query.append(_SQL_SELECT_DDMSTORAGELINK);
1554    
1555                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1556                                            orderByComparator);
1557    
1558                                    sql = query.toString();
1559                            }
1560                            else {
1561                                    sql = _SQL_SELECT_DDMSTORAGELINK;
1562                            }
1563    
1564                            Session session = null;
1565    
1566                            try {
1567                                    session = openSession();
1568    
1569                                    Query q = session.createQuery(sql);
1570    
1571                                    if (orderByComparator == null) {
1572                                            list = (List<DDMStorageLink>)QueryUtil.list(q,
1573                                                            getDialect(), start, end, false);
1574    
1575                                            Collections.sort(list);
1576                                    }
1577                                    else {
1578                                            list = (List<DDMStorageLink>)QueryUtil.list(q,
1579                                                            getDialect(), start, end);
1580                                    }
1581                            }
1582                            catch (Exception e) {
1583                                    throw processException(e);
1584                            }
1585                            finally {
1586                                    if (list == null) {
1587                                            FinderCacheUtil.removeResult(finderPath, finderArgs);
1588                                    }
1589                                    else {
1590                                            cacheResult(list);
1591    
1592                                            FinderCacheUtil.putResult(finderPath, finderArgs, list);
1593                                    }
1594    
1595                                    closeSession(session);
1596                            }
1597                    }
1598    
1599                    return list;
1600            }
1601    
1602            /**
1603             * Removes all the d d m storage links where uuid = &#63; from the database.
1604             *
1605             * @param uuid the uuid
1606             * @throws SystemException if a system exception occurred
1607             */
1608            public void removeByUuid(String uuid) throws SystemException {
1609                    for (DDMStorageLink ddmStorageLink : findByUuid(uuid)) {
1610                            remove(ddmStorageLink);
1611                    }
1612            }
1613    
1614            /**
1615             * Removes the d d m storage link where classPK = &#63; from the database.
1616             *
1617             * @param classPK the class p k
1618             * @return the d d m storage link that was removed
1619             * @throws SystemException if a system exception occurred
1620             */
1621            public DDMStorageLink removeByClassPK(long classPK)
1622                    throws NoSuchStorageLinkException, SystemException {
1623                    DDMStorageLink ddmStorageLink = findByClassPK(classPK);
1624    
1625                    return remove(ddmStorageLink);
1626            }
1627    
1628            /**
1629             * Removes all the d d m storage links where structureId = &#63; from the database.
1630             *
1631             * @param structureId the structure ID
1632             * @throws SystemException if a system exception occurred
1633             */
1634            public void removeByStructureId(long structureId) throws SystemException {
1635                    for (DDMStorageLink ddmStorageLink : findByStructureId(structureId)) {
1636                            remove(ddmStorageLink);
1637                    }
1638            }
1639    
1640            /**
1641             * Removes all the d d m storage links from the database.
1642             *
1643             * @throws SystemException if a system exception occurred
1644             */
1645            public void removeAll() throws SystemException {
1646                    for (DDMStorageLink ddmStorageLink : findAll()) {
1647                            remove(ddmStorageLink);
1648                    }
1649            }
1650    
1651            /**
1652             * Returns the number of d d m storage links where uuid = &#63;.
1653             *
1654             * @param uuid the uuid
1655             * @return the number of matching d d m storage links
1656             * @throws SystemException if a system exception occurred
1657             */
1658            public int countByUuid(String uuid) throws SystemException {
1659                    Object[] finderArgs = new Object[] { uuid };
1660    
1661                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_UUID,
1662                                    finderArgs, this);
1663    
1664                    if (count == null) {
1665                            StringBundler query = new StringBundler(2);
1666    
1667                            query.append(_SQL_COUNT_DDMSTORAGELINK_WHERE);
1668    
1669                            if (uuid == null) {
1670                                    query.append(_FINDER_COLUMN_UUID_UUID_1);
1671                            }
1672                            else {
1673                                    if (uuid.equals(StringPool.BLANK)) {
1674                                            query.append(_FINDER_COLUMN_UUID_UUID_3);
1675                                    }
1676                                    else {
1677                                            query.append(_FINDER_COLUMN_UUID_UUID_2);
1678                                    }
1679                            }
1680    
1681                            String sql = query.toString();
1682    
1683                            Session session = null;
1684    
1685                            try {
1686                                    session = openSession();
1687    
1688                                    Query q = session.createQuery(sql);
1689    
1690                                    QueryPos qPos = QueryPos.getInstance(q);
1691    
1692                                    if (uuid != null) {
1693                                            qPos.add(uuid);
1694                                    }
1695    
1696                                    count = (Long)q.uniqueResult();
1697                            }
1698                            catch (Exception e) {
1699                                    throw processException(e);
1700                            }
1701                            finally {
1702                                    if (count == null) {
1703                                            count = Long.valueOf(0);
1704                                    }
1705    
1706                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_UUID,
1707                                            finderArgs, count);
1708    
1709                                    closeSession(session);
1710                            }
1711                    }
1712    
1713                    return count.intValue();
1714            }
1715    
1716            /**
1717             * Returns the number of d d m storage links where classPK = &#63;.
1718             *
1719             * @param classPK the class p k
1720             * @return the number of matching d d m storage links
1721             * @throws SystemException if a system exception occurred
1722             */
1723            public int countByClassPK(long classPK) throws SystemException {
1724                    Object[] finderArgs = new Object[] { classPK };
1725    
1726                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_CLASSPK,
1727                                    finderArgs, this);
1728    
1729                    if (count == null) {
1730                            StringBundler query = new StringBundler(2);
1731    
1732                            query.append(_SQL_COUNT_DDMSTORAGELINK_WHERE);
1733    
1734                            query.append(_FINDER_COLUMN_CLASSPK_CLASSPK_2);
1735    
1736                            String sql = query.toString();
1737    
1738                            Session session = null;
1739    
1740                            try {
1741                                    session = openSession();
1742    
1743                                    Query q = session.createQuery(sql);
1744    
1745                                    QueryPos qPos = QueryPos.getInstance(q);
1746    
1747                                    qPos.add(classPK);
1748    
1749                                    count = (Long)q.uniqueResult();
1750                            }
1751                            catch (Exception e) {
1752                                    throw processException(e);
1753                            }
1754                            finally {
1755                                    if (count == null) {
1756                                            count = Long.valueOf(0);
1757                                    }
1758    
1759                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_CLASSPK,
1760                                            finderArgs, count);
1761    
1762                                    closeSession(session);
1763                            }
1764                    }
1765    
1766                    return count.intValue();
1767            }
1768    
1769            /**
1770             * Returns the number of d d m storage links where structureId = &#63;.
1771             *
1772             * @param structureId the structure ID
1773             * @return the number of matching d d m storage links
1774             * @throws SystemException if a system exception occurred
1775             */
1776            public int countByStructureId(long structureId) throws SystemException {
1777                    Object[] finderArgs = new Object[] { structureId };
1778    
1779                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_STRUCTUREID,
1780                                    finderArgs, this);
1781    
1782                    if (count == null) {
1783                            StringBundler query = new StringBundler(2);
1784    
1785                            query.append(_SQL_COUNT_DDMSTORAGELINK_WHERE);
1786    
1787                            query.append(_FINDER_COLUMN_STRUCTUREID_STRUCTUREID_2);
1788    
1789                            String sql = query.toString();
1790    
1791                            Session session = null;
1792    
1793                            try {
1794                                    session = openSession();
1795    
1796                                    Query q = session.createQuery(sql);
1797    
1798                                    QueryPos qPos = QueryPos.getInstance(q);
1799    
1800                                    qPos.add(structureId);
1801    
1802                                    count = (Long)q.uniqueResult();
1803                            }
1804                            catch (Exception e) {
1805                                    throw processException(e);
1806                            }
1807                            finally {
1808                                    if (count == null) {
1809                                            count = Long.valueOf(0);
1810                                    }
1811    
1812                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_STRUCTUREID,
1813                                            finderArgs, count);
1814    
1815                                    closeSession(session);
1816                            }
1817                    }
1818    
1819                    return count.intValue();
1820            }
1821    
1822            /**
1823             * Returns the number of d d m storage links.
1824             *
1825             * @return the number of d d m storage links
1826             * @throws SystemException if a system exception occurred
1827             */
1828            public int countAll() throws SystemException {
1829                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_ALL,
1830                                    FINDER_ARGS_EMPTY, this);
1831    
1832                    if (count == null) {
1833                            Session session = null;
1834    
1835                            try {
1836                                    session = openSession();
1837    
1838                                    Query q = session.createQuery(_SQL_COUNT_DDMSTORAGELINK);
1839    
1840                                    count = (Long)q.uniqueResult();
1841                            }
1842                            catch (Exception e) {
1843                                    throw processException(e);
1844                            }
1845                            finally {
1846                                    if (count == null) {
1847                                            count = Long.valueOf(0);
1848                                    }
1849    
1850                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_ALL,
1851                                            FINDER_ARGS_EMPTY, count);
1852    
1853                                    closeSession(session);
1854                            }
1855                    }
1856    
1857                    return count.intValue();
1858            }
1859    
1860            /**
1861             * Initializes the d d m storage link persistence.
1862             */
1863            public void afterPropertiesSet() {
1864                    String[] listenerClassNames = StringUtil.split(GetterUtil.getString(
1865                                            com.liferay.portal.util.PropsUtil.get(
1866                                                    "value.object.listener.com.liferay.portlet.dynamicdatamapping.model.DDMStorageLink")));
1867    
1868                    if (listenerClassNames.length > 0) {
1869                            try {
1870                                    List<ModelListener<DDMStorageLink>> listenersList = new ArrayList<ModelListener<DDMStorageLink>>();
1871    
1872                                    for (String listenerClassName : listenerClassNames) {
1873                                            Class<?> clazz = getClass();
1874    
1875                                            listenersList.add((ModelListener<DDMStorageLink>)InstanceFactory.newInstance(
1876                                                            clazz.getClassLoader(), listenerClassName));
1877                                    }
1878    
1879                                    listeners = listenersList.toArray(new ModelListener[listenersList.size()]);
1880                            }
1881                            catch (Exception e) {
1882                                    _log.error(e);
1883                            }
1884                    }
1885            }
1886    
1887            public void destroy() {
1888                    EntityCacheUtil.removeCache(DDMStorageLinkImpl.class.getName());
1889                    FinderCacheUtil.removeCache(FINDER_CLASS_NAME_ENTITY);
1890                    FinderCacheUtil.removeCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
1891            }
1892    
1893            @BeanReference(type = DDMContentPersistence.class)
1894            protected DDMContentPersistence ddmContentPersistence;
1895            @BeanReference(type = DDMStorageLinkPersistence.class)
1896            protected DDMStorageLinkPersistence ddmStorageLinkPersistence;
1897            @BeanReference(type = DDMStructurePersistence.class)
1898            protected DDMStructurePersistence ddmStructurePersistence;
1899            @BeanReference(type = DDMStructureLinkPersistence.class)
1900            protected DDMStructureLinkPersistence ddmStructureLinkPersistence;
1901            @BeanReference(type = DDMTemplatePersistence.class)
1902            protected DDMTemplatePersistence ddmTemplatePersistence;
1903            @BeanReference(type = ResourcePersistence.class)
1904            protected ResourcePersistence resourcePersistence;
1905            @BeanReference(type = UserPersistence.class)
1906            protected UserPersistence userPersistence;
1907            private static final String _SQL_SELECT_DDMSTORAGELINK = "SELECT ddmStorageLink FROM DDMStorageLink ddmStorageLink";
1908            private static final String _SQL_SELECT_DDMSTORAGELINK_WHERE = "SELECT ddmStorageLink FROM DDMStorageLink ddmStorageLink WHERE ";
1909            private static final String _SQL_COUNT_DDMSTORAGELINK = "SELECT COUNT(ddmStorageLink) FROM DDMStorageLink ddmStorageLink";
1910            private static final String _SQL_COUNT_DDMSTORAGELINK_WHERE = "SELECT COUNT(ddmStorageLink) FROM DDMStorageLink ddmStorageLink WHERE ";
1911            private static final String _FINDER_COLUMN_UUID_UUID_1 = "ddmStorageLink.uuid IS NULL";
1912            private static final String _FINDER_COLUMN_UUID_UUID_2 = "ddmStorageLink.uuid = ?";
1913            private static final String _FINDER_COLUMN_UUID_UUID_3 = "(ddmStorageLink.uuid IS NULL OR ddmStorageLink.uuid = ?)";
1914            private static final String _FINDER_COLUMN_CLASSPK_CLASSPK_2 = "ddmStorageLink.classPK = ?";
1915            private static final String _FINDER_COLUMN_STRUCTUREID_STRUCTUREID_2 = "ddmStorageLink.structureId = ?";
1916            private static final String _ORDER_BY_ENTITY_ALIAS = "ddmStorageLink.";
1917            private static final String _NO_SUCH_ENTITY_WITH_PRIMARY_KEY = "No DDMStorageLink exists with the primary key ";
1918            private static final String _NO_SUCH_ENTITY_WITH_KEY = "No DDMStorageLink exists with the key {";
1919            private static final boolean _HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE = com.liferay.portal.util.PropsValues.HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE;
1920            private static Log _log = LogFactoryUtil.getLog(DDMStorageLinkPersistenceImpl.class);
1921            private static DDMStorageLink _nullDDMStorageLink = new DDMStorageLinkImpl() {
1922                            @Override
1923                            public Object clone() {
1924                                    return this;
1925                            }
1926    
1927                            @Override
1928                            public CacheModel<DDMStorageLink> toCacheModel() {
1929                                    return _nullDDMStorageLinkCacheModel;
1930                            }
1931                    };
1932    
1933            private static CacheModel<DDMStorageLink> _nullDDMStorageLinkCacheModel = new CacheModel<DDMStorageLink>() {
1934                            public DDMStorageLink toEntityModel() {
1935                                    return _nullDDMStorageLink;
1936                            }
1937                    };
1938    }