001    /**
002     * Copyright (c) 2000-2011 Liferay, Inc. All rights reserved.
003     *
004     * The contents of this file are subject to the terms of the Liferay Enterprise
005     * Subscription License ("License"). You may not use this file except in
006     * compliance with the License. You can obtain a copy of the License by
007     * contacting Liferay, Inc. See the License for the specific language governing
008     * permissions and limitations under the License, including but not limited to
009     * distribution rights of the Software.
010     *
011     *
012     *
013     */
014    
015    package com.liferay.portal.service.persistence;
016    
017    import com.liferay.portal.NoSuchImageException;
018    import com.liferay.portal.NoSuchModelException;
019    import com.liferay.portal.kernel.bean.BeanReference;
020    import com.liferay.portal.kernel.cache.CacheRegistryUtil;
021    import com.liferay.portal.kernel.dao.orm.EntityCacheUtil;
022    import com.liferay.portal.kernel.dao.orm.FinderCacheUtil;
023    import com.liferay.portal.kernel.dao.orm.FinderPath;
024    import com.liferay.portal.kernel.dao.orm.Query;
025    import com.liferay.portal.kernel.dao.orm.QueryPos;
026    import com.liferay.portal.kernel.dao.orm.QueryUtil;
027    import com.liferay.portal.kernel.dao.orm.Session;
028    import com.liferay.portal.kernel.exception.SystemException;
029    import com.liferay.portal.kernel.log.Log;
030    import com.liferay.portal.kernel.log.LogFactoryUtil;
031    import com.liferay.portal.kernel.util.GetterUtil;
032    import com.liferay.portal.kernel.util.InstanceFactory;
033    import com.liferay.portal.kernel.util.OrderByComparator;
034    import com.liferay.portal.kernel.util.StringBundler;
035    import com.liferay.portal.kernel.util.StringPool;
036    import com.liferay.portal.kernel.util.StringUtil;
037    import com.liferay.portal.model.CacheModel;
038    import com.liferay.portal.model.Image;
039    import com.liferay.portal.model.ModelListener;
040    import com.liferay.portal.model.impl.ImageImpl;
041    import com.liferay.portal.model.impl.ImageModelImpl;
042    import com.liferay.portal.service.persistence.impl.BasePersistenceImpl;
043    
044    import com.liferay.portlet.documentlibrary.service.persistence.DLFileEntryPersistence;
045    
046    import java.io.Serializable;
047    
048    import java.util.ArrayList;
049    import java.util.Collections;
050    import java.util.List;
051    
052    /**
053     * The persistence implementation for the image service.
054     *
055     * <p>
056     * Caching information and settings can be found in <code>portal.properties</code>
057     * </p>
058     *
059     * @author Brian Wing Shun Chan
060     * @see ImagePersistence
061     * @see ImageUtil
062     * @generated
063     */
064    public class ImagePersistenceImpl extends BasePersistenceImpl<Image>
065            implements ImagePersistence {
066            /*
067             * NOTE FOR DEVELOPERS:
068             *
069             * Never modify or reference this class directly. Always use {@link ImageUtil} to access the image persistence. Modify <code>service.xml</code> and rerun ServiceBuilder to regenerate this class.
070             */
071            public static final String FINDER_CLASS_NAME_ENTITY = ImageImpl.class.getName();
072            public static final String FINDER_CLASS_NAME_LIST_WITH_PAGINATION = FINDER_CLASS_NAME_ENTITY +
073                    ".List1";
074            public static final String FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION = FINDER_CLASS_NAME_ENTITY +
075                    ".List2";
076            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_LTSIZE = new FinderPath(ImageModelImpl.ENTITY_CACHE_ENABLED,
077                            ImageModelImpl.FINDER_CACHE_ENABLED, ImageImpl.class,
078                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByLtSize",
079                            new String[] {
080                                    Integer.class.getName(),
081                                    
082                            "java.lang.Integer", "java.lang.Integer",
083                                    "com.liferay.portal.kernel.util.OrderByComparator"
084                            });
085            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_LTSIZE =
086                    new FinderPath(ImageModelImpl.ENTITY_CACHE_ENABLED,
087                            ImageModelImpl.FINDER_CACHE_ENABLED, ImageImpl.class,
088                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByLtSize",
089                            new String[] { Integer.class.getName() },
090                            ImageModelImpl.SIZE_COLUMN_BITMASK);
091            public static final FinderPath FINDER_PATH_COUNT_BY_LTSIZE = new FinderPath(ImageModelImpl.ENTITY_CACHE_ENABLED,
092                            ImageModelImpl.FINDER_CACHE_ENABLED, Long.class,
093                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByLtSize",
094                            new String[] { Integer.class.getName() });
095            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_ALL = new FinderPath(ImageModelImpl.ENTITY_CACHE_ENABLED,
096                            ImageModelImpl.FINDER_CACHE_ENABLED, ImageImpl.class,
097                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findAll", new String[0]);
098            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL = new FinderPath(ImageModelImpl.ENTITY_CACHE_ENABLED,
099                            ImageModelImpl.FINDER_CACHE_ENABLED, ImageImpl.class,
100                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findAll", new String[0]);
101            public static final FinderPath FINDER_PATH_COUNT_ALL = new FinderPath(ImageModelImpl.ENTITY_CACHE_ENABLED,
102                            ImageModelImpl.FINDER_CACHE_ENABLED, Long.class,
103                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countAll", new String[0]);
104    
105            /**
106             * Caches the image in the entity cache if it is enabled.
107             *
108             * @param image the image
109             */
110            public void cacheResult(Image image) {
111                    EntityCacheUtil.putResult(ImageModelImpl.ENTITY_CACHE_ENABLED,
112                            ImageImpl.class, image.getPrimaryKey(), image);
113    
114                    image.resetOriginalValues();
115            }
116    
117            /**
118             * Caches the images in the entity cache if it is enabled.
119             *
120             * @param images the images
121             */
122            public void cacheResult(List<Image> images) {
123                    for (Image image : images) {
124                            if (EntityCacheUtil.getResult(ImageModelImpl.ENTITY_CACHE_ENABLED,
125                                                    ImageImpl.class, image.getPrimaryKey()) == null) {
126                                    cacheResult(image);
127                            }
128                            else {
129                                    image.resetOriginalValues();
130                            }
131                    }
132            }
133    
134            /**
135             * Clears the cache for all images.
136             *
137             * <p>
138             * The {@link com.liferay.portal.kernel.dao.orm.EntityCache} and {@link com.liferay.portal.kernel.dao.orm.FinderCache} are both cleared by this method.
139             * </p>
140             */
141            @Override
142            public void clearCache() {
143                    if (_HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE) {
144                            CacheRegistryUtil.clear(ImageImpl.class.getName());
145                    }
146    
147                    EntityCacheUtil.clearCache(ImageImpl.class.getName());
148    
149                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_ENTITY);
150                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
151                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
152            }
153    
154            /**
155             * Clears the cache for the image.
156             *
157             * <p>
158             * The {@link com.liferay.portal.kernel.dao.orm.EntityCache} and {@link com.liferay.portal.kernel.dao.orm.FinderCache} are both cleared by this method.
159             * </p>
160             */
161            @Override
162            public void clearCache(Image image) {
163                    EntityCacheUtil.removeResult(ImageModelImpl.ENTITY_CACHE_ENABLED,
164                            ImageImpl.class, image.getPrimaryKey());
165    
166                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
167                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
168            }
169    
170            /**
171             * Creates a new image with the primary key. Does not add the image to the database.
172             *
173             * @param imageId the primary key for the new image
174             * @return the new image
175             */
176            public Image create(long imageId) {
177                    Image image = new ImageImpl();
178    
179                    image.setNew(true);
180                    image.setPrimaryKey(imageId);
181    
182                    return image;
183            }
184    
185            /**
186             * Removes the image with the primary key from the database. Also notifies the appropriate model listeners.
187             *
188             * @param primaryKey the primary key of the image
189             * @return the image that was removed
190             * @throws com.liferay.portal.NoSuchModelException if a image with the primary key could not be found
191             * @throws SystemException if a system exception occurred
192             */
193            @Override
194            public Image remove(Serializable primaryKey)
195                    throws NoSuchModelException, SystemException {
196                    return remove(((Long)primaryKey).longValue());
197            }
198    
199            /**
200             * Removes the image with the primary key from the database. Also notifies the appropriate model listeners.
201             *
202             * @param imageId the primary key of the image
203             * @return the image that was removed
204             * @throws com.liferay.portal.NoSuchImageException if a image with the primary key could not be found
205             * @throws SystemException if a system exception occurred
206             */
207            public Image remove(long imageId)
208                    throws NoSuchImageException, SystemException {
209                    Session session = null;
210    
211                    try {
212                            session = openSession();
213    
214                            Image image = (Image)session.get(ImageImpl.class,
215                                            Long.valueOf(imageId));
216    
217                            if (image == null) {
218                                    if (_log.isWarnEnabled()) {
219                                            _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + imageId);
220                                    }
221    
222                                    throw new NoSuchImageException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
223                                            imageId);
224                            }
225    
226                            return imagePersistence.remove(image);
227                    }
228                    catch (NoSuchImageException nsee) {
229                            throw nsee;
230                    }
231                    catch (Exception e) {
232                            throw processException(e);
233                    }
234                    finally {
235                            closeSession(session);
236                    }
237            }
238    
239            /**
240             * Removes the image from the database. Also notifies the appropriate model listeners.
241             *
242             * @param image the image
243             * @return the image that was removed
244             * @throws SystemException if a system exception occurred
245             */
246            @Override
247            public Image remove(Image image) throws SystemException {
248                    return super.remove(image);
249            }
250    
251            @Override
252            protected Image removeImpl(Image image) throws SystemException {
253                    image = toUnwrappedModel(image);
254    
255                    Session session = null;
256    
257                    try {
258                            session = openSession();
259    
260                            BatchSessionUtil.delete(session, image);
261                    }
262                    catch (Exception e) {
263                            throw processException(e);
264                    }
265                    finally {
266                            closeSession(session);
267                    }
268    
269                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
270                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
271    
272                    EntityCacheUtil.removeResult(ImageModelImpl.ENTITY_CACHE_ENABLED,
273                            ImageImpl.class, image.getPrimaryKey());
274    
275                    return image;
276            }
277    
278            @Override
279            public Image updateImpl(com.liferay.portal.model.Image image, boolean merge)
280                    throws SystemException {
281                    image = toUnwrappedModel(image);
282    
283                    boolean isNew = image.isNew();
284    
285                    ImageModelImpl imageModelImpl = (ImageModelImpl)image;
286    
287                    Session session = null;
288    
289                    try {
290                            session = openSession();
291    
292                            BatchSessionUtil.update(session, image, merge);
293    
294                            image.setNew(false);
295                    }
296                    catch (Exception e) {
297                            throw processException(e);
298                    }
299                    finally {
300                            closeSession(session);
301                    }
302    
303                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
304    
305                    if (isNew || !ImageModelImpl.COLUMN_BITMASK_ENABLED) {
306                            FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
307                    }
308    
309                    else {
310                            if ((imageModelImpl.getColumnBitmask() &
311                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_LTSIZE.getColumnBitmask()) != 0) {
312                                    Object[] args = new Object[] {
313                                                    Integer.valueOf(imageModelImpl.getOriginalSize())
314                                            };
315    
316                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_LTSIZE, args);
317                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_LTSIZE,
318                                            args);
319    
320                                    args = new Object[] { Integer.valueOf(imageModelImpl.getSize()) };
321    
322                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_LTSIZE, args);
323                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_LTSIZE,
324                                            args);
325                            }
326                    }
327    
328                    EntityCacheUtil.putResult(ImageModelImpl.ENTITY_CACHE_ENABLED,
329                            ImageImpl.class, image.getPrimaryKey(), image);
330    
331                    return image;
332            }
333    
334            protected Image toUnwrappedModel(Image image) {
335                    if (image instanceof ImageImpl) {
336                            return image;
337                    }
338    
339                    ImageImpl imageImpl = new ImageImpl();
340    
341                    imageImpl.setNew(image.isNew());
342                    imageImpl.setPrimaryKey(image.getPrimaryKey());
343    
344                    imageImpl.setImageId(image.getImageId());
345                    imageImpl.setModifiedDate(image.getModifiedDate());
346                    imageImpl.setText(image.getText());
347                    imageImpl.setType(image.getType());
348                    imageImpl.setHeight(image.getHeight());
349                    imageImpl.setWidth(image.getWidth());
350                    imageImpl.setSize(image.getSize());
351    
352                    return imageImpl;
353            }
354    
355            /**
356             * Returns the image with the primary key or throws a {@link com.liferay.portal.NoSuchModelException} if it could not be found.
357             *
358             * @param primaryKey the primary key of the image
359             * @return the image
360             * @throws com.liferay.portal.NoSuchModelException if a image with the primary key could not be found
361             * @throws SystemException if a system exception occurred
362             */
363            @Override
364            public Image findByPrimaryKey(Serializable primaryKey)
365                    throws NoSuchModelException, SystemException {
366                    return findByPrimaryKey(((Long)primaryKey).longValue());
367            }
368    
369            /**
370             * Returns the image with the primary key or throws a {@link com.liferay.portal.NoSuchImageException} if it could not be found.
371             *
372             * @param imageId the primary key of the image
373             * @return the image
374             * @throws com.liferay.portal.NoSuchImageException if a image with the primary key could not be found
375             * @throws SystemException if a system exception occurred
376             */
377            public Image findByPrimaryKey(long imageId)
378                    throws NoSuchImageException, SystemException {
379                    Image image = fetchByPrimaryKey(imageId);
380    
381                    if (image == null) {
382                            if (_log.isWarnEnabled()) {
383                                    _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + imageId);
384                            }
385    
386                            throw new NoSuchImageException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
387                                    imageId);
388                    }
389    
390                    return image;
391            }
392    
393            /**
394             * Returns the image with the primary key or returns <code>null</code> if it could not be found.
395             *
396             * @param primaryKey the primary key of the image
397             * @return the image, or <code>null</code> if a image with the primary key could not be found
398             * @throws SystemException if a system exception occurred
399             */
400            @Override
401            public Image fetchByPrimaryKey(Serializable primaryKey)
402                    throws SystemException {
403                    return fetchByPrimaryKey(((Long)primaryKey).longValue());
404            }
405    
406            /**
407             * Returns the image with the primary key or returns <code>null</code> if it could not be found.
408             *
409             * @param imageId the primary key of the image
410             * @return the image, or <code>null</code> if a image with the primary key could not be found
411             * @throws SystemException if a system exception occurred
412             */
413            public Image fetchByPrimaryKey(long imageId) throws SystemException {
414                    Image image = (Image)EntityCacheUtil.getResult(ImageModelImpl.ENTITY_CACHE_ENABLED,
415                                    ImageImpl.class, imageId);
416    
417                    if (image == _nullImage) {
418                            return null;
419                    }
420    
421                    if (image == null) {
422                            Session session = null;
423    
424                            boolean hasException = false;
425    
426                            try {
427                                    session = openSession();
428    
429                                    image = (Image)session.get(ImageImpl.class,
430                                                    Long.valueOf(imageId));
431                            }
432                            catch (Exception e) {
433                                    hasException = true;
434    
435                                    throw processException(e);
436                            }
437                            finally {
438                                    if (image != null) {
439                                            cacheResult(image);
440                                    }
441                                    else if (!hasException) {
442                                            EntityCacheUtil.putResult(ImageModelImpl.ENTITY_CACHE_ENABLED,
443                                                    ImageImpl.class, imageId, _nullImage);
444                                    }
445    
446                                    closeSession(session);
447                            }
448                    }
449    
450                    return image;
451            }
452    
453            /**
454             * Returns all the images where size &lt; &#63;.
455             *
456             * @param size the size
457             * @return the matching images
458             * @throws SystemException if a system exception occurred
459             */
460            public List<Image> findByLtSize(int size) throws SystemException {
461                    return findByLtSize(size, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
462            }
463    
464            /**
465             * Returns a range of all the images where size &lt; &#63;.
466             *
467             * <p>
468             * 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.
469             * </p>
470             *
471             * @param size the size
472             * @param start the lower bound of the range of images
473             * @param end the upper bound of the range of images (not inclusive)
474             * @return the range of matching images
475             * @throws SystemException if a system exception occurred
476             */
477            public List<Image> findByLtSize(int size, int start, int end)
478                    throws SystemException {
479                    return findByLtSize(size, start, end, null);
480            }
481    
482            /**
483             * Returns an ordered range of all the images where size &lt; &#63;.
484             *
485             * <p>
486             * 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.
487             * </p>
488             *
489             * @param size the size
490             * @param start the lower bound of the range of images
491             * @param end the upper bound of the range of images (not inclusive)
492             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
493             * @return the ordered range of matching images
494             * @throws SystemException if a system exception occurred
495             */
496            public List<Image> findByLtSize(int size, int start, int end,
497                    OrderByComparator orderByComparator) throws SystemException {
498                    FinderPath finderPath = null;
499                    Object[] finderArgs = null;
500    
501                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
502                                    (orderByComparator == null)) {
503                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_LTSIZE;
504                            finderArgs = new Object[] { size };
505                    }
506                    else {
507                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_LTSIZE;
508                            finderArgs = new Object[] { size, start, end, orderByComparator };
509                    }
510    
511                    List<Image> list = (List<Image>)FinderCacheUtil.getResult(finderPath,
512                                    finderArgs, this);
513    
514                    if (list == null) {
515                            StringBundler query = null;
516    
517                            if (orderByComparator != null) {
518                                    query = new StringBundler(3 +
519                                                    (orderByComparator.getOrderByFields().length * 3));
520                            }
521                            else {
522                                    query = new StringBundler(3);
523                            }
524    
525                            query.append(_SQL_SELECT_IMAGE_WHERE);
526    
527                            query.append(_FINDER_COLUMN_LTSIZE_SIZE_2);
528    
529                            if (orderByComparator != null) {
530                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
531                                            orderByComparator);
532                            }
533    
534                            else {
535                                    query.append(ImageModelImpl.ORDER_BY_JPQL);
536                            }
537    
538                            String sql = query.toString();
539    
540                            Session session = null;
541    
542                            try {
543                                    session = openSession();
544    
545                                    Query q = session.createQuery(sql);
546    
547                                    QueryPos qPos = QueryPos.getInstance(q);
548    
549                                    qPos.add(size);
550    
551                                    list = (List<Image>)QueryUtil.list(q, getDialect(), start, end);
552                            }
553                            catch (Exception e) {
554                                    throw processException(e);
555                            }
556                            finally {
557                                    if (list == null) {
558                                            FinderCacheUtil.removeResult(finderPath, finderArgs);
559                                    }
560                                    else {
561                                            cacheResult(list);
562    
563                                            FinderCacheUtil.putResult(finderPath, finderArgs, list);
564                                    }
565    
566                                    closeSession(session);
567                            }
568                    }
569    
570                    return list;
571            }
572    
573            /**
574             * Returns the first image in the ordered set where size &lt; &#63;.
575             *
576             * <p>
577             * 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.
578             * </p>
579             *
580             * @param size the size
581             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
582             * @return the first matching image
583             * @throws com.liferay.portal.NoSuchImageException if a matching image could not be found
584             * @throws SystemException if a system exception occurred
585             */
586            public Image findByLtSize_First(int size,
587                    OrderByComparator orderByComparator)
588                    throws NoSuchImageException, SystemException {
589                    List<Image> list = findByLtSize(size, 0, 1, orderByComparator);
590    
591                    if (list.isEmpty()) {
592                            StringBundler msg = new StringBundler(4);
593    
594                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
595    
596                            msg.append("size=");
597                            msg.append(size);
598    
599                            msg.append(StringPool.CLOSE_CURLY_BRACE);
600    
601                            throw new NoSuchImageException(msg.toString());
602                    }
603                    else {
604                            return list.get(0);
605                    }
606            }
607    
608            /**
609             * Returns the last image in the ordered set where size &lt; &#63;.
610             *
611             * <p>
612             * 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.
613             * </p>
614             *
615             * @param size the size
616             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
617             * @return the last matching image
618             * @throws com.liferay.portal.NoSuchImageException if a matching image could not be found
619             * @throws SystemException if a system exception occurred
620             */
621            public Image findByLtSize_Last(int size, OrderByComparator orderByComparator)
622                    throws NoSuchImageException, SystemException {
623                    int count = countByLtSize(size);
624    
625                    List<Image> list = findByLtSize(size, count - 1, count,
626                                    orderByComparator);
627    
628                    if (list.isEmpty()) {
629                            StringBundler msg = new StringBundler(4);
630    
631                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
632    
633                            msg.append("size=");
634                            msg.append(size);
635    
636                            msg.append(StringPool.CLOSE_CURLY_BRACE);
637    
638                            throw new NoSuchImageException(msg.toString());
639                    }
640                    else {
641                            return list.get(0);
642                    }
643            }
644    
645            /**
646             * Returns the images before and after the current image in the ordered set where size &lt; &#63;.
647             *
648             * <p>
649             * 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.
650             * </p>
651             *
652             * @param imageId the primary key of the current image
653             * @param size the size
654             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
655             * @return the previous, current, and next image
656             * @throws com.liferay.portal.NoSuchImageException if a image with the primary key could not be found
657             * @throws SystemException if a system exception occurred
658             */
659            public Image[] findByLtSize_PrevAndNext(long imageId, int size,
660                    OrderByComparator orderByComparator)
661                    throws NoSuchImageException, SystemException {
662                    Image image = findByPrimaryKey(imageId);
663    
664                    Session session = null;
665    
666                    try {
667                            session = openSession();
668    
669                            Image[] array = new ImageImpl[3];
670    
671                            array[0] = getByLtSize_PrevAndNext(session, image, size,
672                                            orderByComparator, true);
673    
674                            array[1] = image;
675    
676                            array[2] = getByLtSize_PrevAndNext(session, image, size,
677                                            orderByComparator, false);
678    
679                            return array;
680                    }
681                    catch (Exception e) {
682                            throw processException(e);
683                    }
684                    finally {
685                            closeSession(session);
686                    }
687            }
688    
689            protected Image getByLtSize_PrevAndNext(Session session, Image image,
690                    int size, OrderByComparator orderByComparator, boolean previous) {
691                    StringBundler query = null;
692    
693                    if (orderByComparator != null) {
694                            query = new StringBundler(6 +
695                                            (orderByComparator.getOrderByFields().length * 6));
696                    }
697                    else {
698                            query = new StringBundler(3);
699                    }
700    
701                    query.append(_SQL_SELECT_IMAGE_WHERE);
702    
703                    query.append(_FINDER_COLUMN_LTSIZE_SIZE_2);
704    
705                    if (orderByComparator != null) {
706                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
707    
708                            if (orderByConditionFields.length > 0) {
709                                    query.append(WHERE_AND);
710                            }
711    
712                            for (int i = 0; i < orderByConditionFields.length; i++) {
713                                    query.append(_ORDER_BY_ENTITY_ALIAS);
714                                    query.append(orderByConditionFields[i]);
715    
716                                    if ((i + 1) < orderByConditionFields.length) {
717                                            if (orderByComparator.isAscending() ^ previous) {
718                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
719                                            }
720                                            else {
721                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
722                                            }
723                                    }
724                                    else {
725                                            if (orderByComparator.isAscending() ^ previous) {
726                                                    query.append(WHERE_GREATER_THAN);
727                                            }
728                                            else {
729                                                    query.append(WHERE_LESSER_THAN);
730                                            }
731                                    }
732                            }
733    
734                            query.append(ORDER_BY_CLAUSE);
735    
736                            String[] orderByFields = orderByComparator.getOrderByFields();
737    
738                            for (int i = 0; i < orderByFields.length; i++) {
739                                    query.append(_ORDER_BY_ENTITY_ALIAS);
740                                    query.append(orderByFields[i]);
741    
742                                    if ((i + 1) < orderByFields.length) {
743                                            if (orderByComparator.isAscending() ^ previous) {
744                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
745                                            }
746                                            else {
747                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
748                                            }
749                                    }
750                                    else {
751                                            if (orderByComparator.isAscending() ^ previous) {
752                                                    query.append(ORDER_BY_ASC);
753                                            }
754                                            else {
755                                                    query.append(ORDER_BY_DESC);
756                                            }
757                                    }
758                            }
759                    }
760    
761                    else {
762                            query.append(ImageModelImpl.ORDER_BY_JPQL);
763                    }
764    
765                    String sql = query.toString();
766    
767                    Query q = session.createQuery(sql);
768    
769                    q.setFirstResult(0);
770                    q.setMaxResults(2);
771    
772                    QueryPos qPos = QueryPos.getInstance(q);
773    
774                    qPos.add(size);
775    
776                    if (orderByComparator != null) {
777                            Object[] values = orderByComparator.getOrderByConditionValues(image);
778    
779                            for (Object value : values) {
780                                    qPos.add(value);
781                            }
782                    }
783    
784                    List<Image> list = q.list();
785    
786                    if (list.size() == 2) {
787                            return list.get(1);
788                    }
789                    else {
790                            return null;
791                    }
792            }
793    
794            /**
795             * Returns all the images.
796             *
797             * @return the images
798             * @throws SystemException if a system exception occurred
799             */
800            public List<Image> findAll() throws SystemException {
801                    return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
802            }
803    
804            /**
805             * Returns a range of all the images.
806             *
807             * <p>
808             * 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.
809             * </p>
810             *
811             * @param start the lower bound of the range of images
812             * @param end the upper bound of the range of images (not inclusive)
813             * @return the range of images
814             * @throws SystemException if a system exception occurred
815             */
816            public List<Image> findAll(int start, int end) throws SystemException {
817                    return findAll(start, end, null);
818            }
819    
820            /**
821             * Returns an ordered range of all the images.
822             *
823             * <p>
824             * 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.
825             * </p>
826             *
827             * @param start the lower bound of the range of images
828             * @param end the upper bound of the range of images (not inclusive)
829             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
830             * @return the ordered range of images
831             * @throws SystemException if a system exception occurred
832             */
833            public List<Image> findAll(int start, int end,
834                    OrderByComparator orderByComparator) throws SystemException {
835                    FinderPath finderPath = null;
836                    Object[] finderArgs = new Object[] { start, end, orderByComparator };
837    
838                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
839                                    (orderByComparator == null)) {
840                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_ALL;
841                            finderArgs = FINDER_ARGS_EMPTY;
842                    }
843                    else {
844                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL;
845                            finderArgs = new Object[] { start, end, orderByComparator };
846                    }
847    
848                    List<Image> list = (List<Image>)FinderCacheUtil.getResult(finderPath,
849                                    finderArgs, this);
850    
851                    if (list == null) {
852                            StringBundler query = null;
853                            String sql = null;
854    
855                            if (orderByComparator != null) {
856                                    query = new StringBundler(2 +
857                                                    (orderByComparator.getOrderByFields().length * 3));
858    
859                                    query.append(_SQL_SELECT_IMAGE);
860    
861                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
862                                            orderByComparator);
863    
864                                    sql = query.toString();
865                            }
866                            else {
867                                    sql = _SQL_SELECT_IMAGE.concat(ImageModelImpl.ORDER_BY_JPQL);
868                            }
869    
870                            Session session = null;
871    
872                            try {
873                                    session = openSession();
874    
875                                    Query q = session.createQuery(sql);
876    
877                                    if (orderByComparator == null) {
878                                            list = (List<Image>)QueryUtil.list(q, getDialect(), start,
879                                                            end, false);
880    
881                                            Collections.sort(list);
882                                    }
883                                    else {
884                                            list = (List<Image>)QueryUtil.list(q, getDialect(), start,
885                                                            end);
886                                    }
887                            }
888                            catch (Exception e) {
889                                    throw processException(e);
890                            }
891                            finally {
892                                    if (list == null) {
893                                            FinderCacheUtil.removeResult(finderPath, finderArgs);
894                                    }
895                                    else {
896                                            cacheResult(list);
897    
898                                            FinderCacheUtil.putResult(finderPath, finderArgs, list);
899                                    }
900    
901                                    closeSession(session);
902                            }
903                    }
904    
905                    return list;
906            }
907    
908            /**
909             * Removes all the images where size &lt; &#63; from the database.
910             *
911             * @param size the size
912             * @throws SystemException if a system exception occurred
913             */
914            public void removeByLtSize(int size) throws SystemException {
915                    for (Image image : findByLtSize(size)) {
916                            imagePersistence.remove(image);
917                    }
918            }
919    
920            /**
921             * Removes all the images from the database.
922             *
923             * @throws SystemException if a system exception occurred
924             */
925            public void removeAll() throws SystemException {
926                    for (Image image : findAll()) {
927                            imagePersistence.remove(image);
928                    }
929            }
930    
931            /**
932             * Returns the number of images where size &lt; &#63;.
933             *
934             * @param size the size
935             * @return the number of matching images
936             * @throws SystemException if a system exception occurred
937             */
938            public int countByLtSize(int size) throws SystemException {
939                    Object[] finderArgs = new Object[] { size };
940    
941                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_LTSIZE,
942                                    finderArgs, this);
943    
944                    if (count == null) {
945                            StringBundler query = new StringBundler(2);
946    
947                            query.append(_SQL_COUNT_IMAGE_WHERE);
948    
949                            query.append(_FINDER_COLUMN_LTSIZE_SIZE_2);
950    
951                            String sql = query.toString();
952    
953                            Session session = null;
954    
955                            try {
956                                    session = openSession();
957    
958                                    Query q = session.createQuery(sql);
959    
960                                    QueryPos qPos = QueryPos.getInstance(q);
961    
962                                    qPos.add(size);
963    
964                                    count = (Long)q.uniqueResult();
965                            }
966                            catch (Exception e) {
967                                    throw processException(e);
968                            }
969                            finally {
970                                    if (count == null) {
971                                            count = Long.valueOf(0);
972                                    }
973    
974                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_LTSIZE,
975                                            finderArgs, count);
976    
977                                    closeSession(session);
978                            }
979                    }
980    
981                    return count.intValue();
982            }
983    
984            /**
985             * Returns the number of images.
986             *
987             * @return the number of images
988             * @throws SystemException if a system exception occurred
989             */
990            public int countAll() throws SystemException {
991                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_ALL,
992                                    FINDER_ARGS_EMPTY, this);
993    
994                    if (count == null) {
995                            Session session = null;
996    
997                            try {
998                                    session = openSession();
999    
1000                                    Query q = session.createQuery(_SQL_COUNT_IMAGE);
1001    
1002                                    count = (Long)q.uniqueResult();
1003                            }
1004                            catch (Exception e) {
1005                                    throw processException(e);
1006                            }
1007                            finally {
1008                                    if (count == null) {
1009                                            count = Long.valueOf(0);
1010                                    }
1011    
1012                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_ALL,
1013                                            FINDER_ARGS_EMPTY, count);
1014    
1015                                    closeSession(session);
1016                            }
1017                    }
1018    
1019                    return count.intValue();
1020            }
1021    
1022            /**
1023             * Initializes the image persistence.
1024             */
1025            public void afterPropertiesSet() {
1026                    String[] listenerClassNames = StringUtil.split(GetterUtil.getString(
1027                                            com.liferay.portal.util.PropsUtil.get(
1028                                                    "value.object.listener.com.liferay.portal.model.Image")));
1029    
1030                    if (listenerClassNames.length > 0) {
1031                            try {
1032                                    List<ModelListener<Image>> listenersList = new ArrayList<ModelListener<Image>>();
1033    
1034                                    for (String listenerClassName : listenerClassNames) {
1035                                            listenersList.add((ModelListener<Image>)InstanceFactory.newInstance(
1036                                                            listenerClassName));
1037                                    }
1038    
1039                                    listeners = listenersList.toArray(new ModelListener[listenersList.size()]);
1040                            }
1041                            catch (Exception e) {
1042                                    _log.error(e);
1043                            }
1044                    }
1045            }
1046    
1047            public void destroy() {
1048                    EntityCacheUtil.removeCache(ImageImpl.class.getName());
1049                    FinderCacheUtil.removeCache(FINDER_CLASS_NAME_ENTITY);
1050                    FinderCacheUtil.removeCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
1051            }
1052    
1053            @BeanReference(type = AccountPersistence.class)
1054            protected AccountPersistence accountPersistence;
1055            @BeanReference(type = AddressPersistence.class)
1056            protected AddressPersistence addressPersistence;
1057            @BeanReference(type = BrowserTrackerPersistence.class)
1058            protected BrowserTrackerPersistence browserTrackerPersistence;
1059            @BeanReference(type = ClassNamePersistence.class)
1060            protected ClassNamePersistence classNamePersistence;
1061            @BeanReference(type = ClusterGroupPersistence.class)
1062            protected ClusterGroupPersistence clusterGroupPersistence;
1063            @BeanReference(type = CompanyPersistence.class)
1064            protected CompanyPersistence companyPersistence;
1065            @BeanReference(type = ContactPersistence.class)
1066            protected ContactPersistence contactPersistence;
1067            @BeanReference(type = CountryPersistence.class)
1068            protected CountryPersistence countryPersistence;
1069            @BeanReference(type = EmailAddressPersistence.class)
1070            protected EmailAddressPersistence emailAddressPersistence;
1071            @BeanReference(type = GroupPersistence.class)
1072            protected GroupPersistence groupPersistence;
1073            @BeanReference(type = ImagePersistence.class)
1074            protected ImagePersistence imagePersistence;
1075            @BeanReference(type = LayoutPersistence.class)
1076            protected LayoutPersistence layoutPersistence;
1077            @BeanReference(type = LayoutBranchPersistence.class)
1078            protected LayoutBranchPersistence layoutBranchPersistence;
1079            @BeanReference(type = LayoutPrototypePersistence.class)
1080            protected LayoutPrototypePersistence layoutPrototypePersistence;
1081            @BeanReference(type = LayoutRevisionPersistence.class)
1082            protected LayoutRevisionPersistence layoutRevisionPersistence;
1083            @BeanReference(type = LayoutSetPersistence.class)
1084            protected LayoutSetPersistence layoutSetPersistence;
1085            @BeanReference(type = LayoutSetBranchPersistence.class)
1086            protected LayoutSetBranchPersistence layoutSetBranchPersistence;
1087            @BeanReference(type = LayoutSetPrototypePersistence.class)
1088            protected LayoutSetPrototypePersistence layoutSetPrototypePersistence;
1089            @BeanReference(type = ListTypePersistence.class)
1090            protected ListTypePersistence listTypePersistence;
1091            @BeanReference(type = LockPersistence.class)
1092            protected LockPersistence lockPersistence;
1093            @BeanReference(type = MembershipRequestPersistence.class)
1094            protected MembershipRequestPersistence membershipRequestPersistence;
1095            @BeanReference(type = OrganizationPersistence.class)
1096            protected OrganizationPersistence organizationPersistence;
1097            @BeanReference(type = OrgGroupPermissionPersistence.class)
1098            protected OrgGroupPermissionPersistence orgGroupPermissionPersistence;
1099            @BeanReference(type = OrgGroupRolePersistence.class)
1100            protected OrgGroupRolePersistence orgGroupRolePersistence;
1101            @BeanReference(type = OrgLaborPersistence.class)
1102            protected OrgLaborPersistence orgLaborPersistence;
1103            @BeanReference(type = PasswordPolicyPersistence.class)
1104            protected PasswordPolicyPersistence passwordPolicyPersistence;
1105            @BeanReference(type = PasswordPolicyRelPersistence.class)
1106            protected PasswordPolicyRelPersistence passwordPolicyRelPersistence;
1107            @BeanReference(type = PasswordTrackerPersistence.class)
1108            protected PasswordTrackerPersistence passwordTrackerPersistence;
1109            @BeanReference(type = PermissionPersistence.class)
1110            protected PermissionPersistence permissionPersistence;
1111            @BeanReference(type = PhonePersistence.class)
1112            protected PhonePersistence phonePersistence;
1113            @BeanReference(type = PluginSettingPersistence.class)
1114            protected PluginSettingPersistence pluginSettingPersistence;
1115            @BeanReference(type = PortalPreferencesPersistence.class)
1116            protected PortalPreferencesPersistence portalPreferencesPersistence;
1117            @BeanReference(type = PortletPersistence.class)
1118            protected PortletPersistence portletPersistence;
1119            @BeanReference(type = PortletItemPersistence.class)
1120            protected PortletItemPersistence portletItemPersistence;
1121            @BeanReference(type = PortletPreferencesPersistence.class)
1122            protected PortletPreferencesPersistence portletPreferencesPersistence;
1123            @BeanReference(type = RegionPersistence.class)
1124            protected RegionPersistence regionPersistence;
1125            @BeanReference(type = ReleasePersistence.class)
1126            protected ReleasePersistence releasePersistence;
1127            @BeanReference(type = RepositoryPersistence.class)
1128            protected RepositoryPersistence repositoryPersistence;
1129            @BeanReference(type = RepositoryEntryPersistence.class)
1130            protected RepositoryEntryPersistence repositoryEntryPersistence;
1131            @BeanReference(type = ResourcePersistence.class)
1132            protected ResourcePersistence resourcePersistence;
1133            @BeanReference(type = ResourceActionPersistence.class)
1134            protected ResourceActionPersistence resourceActionPersistence;
1135            @BeanReference(type = ResourceBlockPersistence.class)
1136            protected ResourceBlockPersistence resourceBlockPersistence;
1137            @BeanReference(type = ResourceBlockPermissionPersistence.class)
1138            protected ResourceBlockPermissionPersistence resourceBlockPermissionPersistence;
1139            @BeanReference(type = ResourceCodePersistence.class)
1140            protected ResourceCodePersistence resourceCodePersistence;
1141            @BeanReference(type = ResourcePermissionPersistence.class)
1142            protected ResourcePermissionPersistence resourcePermissionPersistence;
1143            @BeanReference(type = ResourceTypePermissionPersistence.class)
1144            protected ResourceTypePermissionPersistence resourceTypePermissionPersistence;
1145            @BeanReference(type = RolePersistence.class)
1146            protected RolePersistence rolePersistence;
1147            @BeanReference(type = ServiceComponentPersistence.class)
1148            protected ServiceComponentPersistence serviceComponentPersistence;
1149            @BeanReference(type = ShardPersistence.class)
1150            protected ShardPersistence shardPersistence;
1151            @BeanReference(type = SubscriptionPersistence.class)
1152            protected SubscriptionPersistence subscriptionPersistence;
1153            @BeanReference(type = TeamPersistence.class)
1154            protected TeamPersistence teamPersistence;
1155            @BeanReference(type = TicketPersistence.class)
1156            protected TicketPersistence ticketPersistence;
1157            @BeanReference(type = UserPersistence.class)
1158            protected UserPersistence userPersistence;
1159            @BeanReference(type = UserGroupPersistence.class)
1160            protected UserGroupPersistence userGroupPersistence;
1161            @BeanReference(type = UserGroupGroupRolePersistence.class)
1162            protected UserGroupGroupRolePersistence userGroupGroupRolePersistence;
1163            @BeanReference(type = UserGroupRolePersistence.class)
1164            protected UserGroupRolePersistence userGroupRolePersistence;
1165            @BeanReference(type = UserIdMapperPersistence.class)
1166            protected UserIdMapperPersistence userIdMapperPersistence;
1167            @BeanReference(type = UserNotificationEventPersistence.class)
1168            protected UserNotificationEventPersistence userNotificationEventPersistence;
1169            @BeanReference(type = UserTrackerPersistence.class)
1170            protected UserTrackerPersistence userTrackerPersistence;
1171            @BeanReference(type = UserTrackerPathPersistence.class)
1172            protected UserTrackerPathPersistence userTrackerPathPersistence;
1173            @BeanReference(type = VirtualHostPersistence.class)
1174            protected VirtualHostPersistence virtualHostPersistence;
1175            @BeanReference(type = WebDAVPropsPersistence.class)
1176            protected WebDAVPropsPersistence webDAVPropsPersistence;
1177            @BeanReference(type = WebsitePersistence.class)
1178            protected WebsitePersistence websitePersistence;
1179            @BeanReference(type = WorkflowDefinitionLinkPersistence.class)
1180            protected WorkflowDefinitionLinkPersistence workflowDefinitionLinkPersistence;
1181            @BeanReference(type = WorkflowInstanceLinkPersistence.class)
1182            protected WorkflowInstanceLinkPersistence workflowInstanceLinkPersistence;
1183            @BeanReference(type = DLFileEntryPersistence.class)
1184            protected DLFileEntryPersistence dlFileEntryPersistence;
1185            private static final String _SQL_SELECT_IMAGE = "SELECT image FROM Image image";
1186            private static final String _SQL_SELECT_IMAGE_WHERE = "SELECT image FROM Image image WHERE ";
1187            private static final String _SQL_COUNT_IMAGE = "SELECT COUNT(image) FROM Image image";
1188            private static final String _SQL_COUNT_IMAGE_WHERE = "SELECT COUNT(image) FROM Image image WHERE ";
1189            private static final String _FINDER_COLUMN_LTSIZE_SIZE_2 = "image.size < ?";
1190            private static final String _ORDER_BY_ENTITY_ALIAS = "image.";
1191            private static final String _NO_SUCH_ENTITY_WITH_PRIMARY_KEY = "No Image exists with the primary key ";
1192            private static final String _NO_SUCH_ENTITY_WITH_KEY = "No Image exists with the key {";
1193            private static final boolean _HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE = com.liferay.portal.util.PropsValues.HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE;
1194            private static Log _log = LogFactoryUtil.getLog(ImagePersistenceImpl.class);
1195            private static Image _nullImage = new ImageImpl() {
1196                            @Override
1197                            public Object clone() {
1198                                    return this;
1199                            }
1200    
1201                            @Override
1202                            public CacheModel<Image> toCacheModel() {
1203                                    return _nullImageCacheModel;
1204                            }
1205                    };
1206    
1207            private static CacheModel<Image> _nullImageCacheModel = new CacheModel<Image>() {
1208                            public Image toEntityModel() {
1209                                    return _nullImage;
1210                            }
1211                    };
1212    }