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.portal.model.impl;
016    
017    import com.liferay.portal.kernel.bean.AutoEscapeBeanHandler;
018    import com.liferay.portal.kernel.json.JSON;
019    import com.liferay.portal.kernel.util.GetterUtil;
020    import com.liferay.portal.kernel.util.ProxyUtil;
021    import com.liferay.portal.kernel.util.StringBundler;
022    import com.liferay.portal.kernel.util.StringPool;
023    import com.liferay.portal.model.CacheModel;
024    import com.liferay.portal.model.Image;
025    import com.liferay.portal.model.ImageModel;
026    import com.liferay.portal.model.ImageSoap;
027    import com.liferay.portal.service.ServiceContext;
028    
029    import com.liferay.portlet.expando.model.ExpandoBridge;
030    import com.liferay.portlet.expando.util.ExpandoBridgeFactoryUtil;
031    
032    import java.io.Serializable;
033    
034    import java.sql.Types;
035    
036    import java.util.ArrayList;
037    import java.util.Date;
038    import java.util.HashMap;
039    import java.util.List;
040    import java.util.Map;
041    
042    /**
043     * The base model implementation for the Image service. Represents a row in the "Image" database table, with each column mapped to a property of this class.
044     *
045     * <p>
046     * This implementation and its corresponding interface {@link com.liferay.portal.model.ImageModel} exist only as a container for the default property accessors generated by ServiceBuilder. Helper methods and all application logic should be put in {@link ImageImpl}.
047     * </p>
048     *
049     * @author Brian Wing Shun Chan
050     * @see ImageImpl
051     * @see com.liferay.portal.model.Image
052     * @see com.liferay.portal.model.ImageModel
053     * @generated
054     */
055    @JSON(strict = true)
056    public class ImageModelImpl extends BaseModelImpl<Image> implements ImageModel {
057            /*
058             * NOTE FOR DEVELOPERS:
059             *
060             * Never modify or reference this class directly. All methods that expect a image model instance should use the {@link com.liferay.portal.model.Image} interface instead.
061             */
062            public static final String TABLE_NAME = "Image";
063            public static final Object[][] TABLE_COLUMNS = {
064                            { "imageId", Types.BIGINT },
065                            { "modifiedDate", Types.TIMESTAMP },
066                            { "type_", Types.VARCHAR },
067                            { "height", Types.INTEGER },
068                            { "width", Types.INTEGER },
069                            { "size_", Types.INTEGER }
070                    };
071            public static final String TABLE_SQL_CREATE = "create table Image (imageId LONG not null primary key,modifiedDate DATE null,type_ VARCHAR(75) null,height INTEGER,width INTEGER,size_ INTEGER)";
072            public static final String TABLE_SQL_DROP = "drop table Image";
073            public static final String ORDER_BY_JPQL = " ORDER BY image.imageId ASC";
074            public static final String ORDER_BY_SQL = " ORDER BY Image.imageId ASC";
075            public static final String DATA_SOURCE = "liferayDataSource";
076            public static final String SESSION_FACTORY = "liferaySessionFactory";
077            public static final String TX_MANAGER = "liferayTransactionManager";
078            public static final boolean ENTITY_CACHE_ENABLED = GetterUtil.getBoolean(com.liferay.portal.util.PropsUtil.get(
079                                    "value.object.entity.cache.enabled.com.liferay.portal.model.Image"),
080                            true);
081            public static final boolean FINDER_CACHE_ENABLED = GetterUtil.getBoolean(com.liferay.portal.util.PropsUtil.get(
082                                    "value.object.finder.cache.enabled.com.liferay.portal.model.Image"),
083                            true);
084            public static final boolean COLUMN_BITMASK_ENABLED = GetterUtil.getBoolean(com.liferay.portal.util.PropsUtil.get(
085                                    "value.object.column.bitmask.enabled.com.liferay.portal.model.Image"),
086                            true);
087            public static long SIZE_COLUMN_BITMASK = 1L;
088            public static long IMAGEID_COLUMN_BITMASK = 2L;
089    
090            /**
091             * Converts the soap model instance into a normal model instance.
092             *
093             * @param soapModel the soap model instance to convert
094             * @return the normal model instance
095             */
096            public static Image toModel(ImageSoap soapModel) {
097                    if (soapModel == null) {
098                            return null;
099                    }
100    
101                    Image model = new ImageImpl();
102    
103                    model.setImageId(soapModel.getImageId());
104                    model.setModifiedDate(soapModel.getModifiedDate());
105                    model.setType(soapModel.getType());
106                    model.setHeight(soapModel.getHeight());
107                    model.setWidth(soapModel.getWidth());
108                    model.setSize(soapModel.getSize());
109    
110                    return model;
111            }
112    
113            /**
114             * Converts the soap model instances into normal model instances.
115             *
116             * @param soapModels the soap model instances to convert
117             * @return the normal model instances
118             */
119            public static List<Image> toModels(ImageSoap[] soapModels) {
120                    if (soapModels == null) {
121                            return null;
122                    }
123    
124                    List<Image> models = new ArrayList<Image>(soapModels.length);
125    
126                    for (ImageSoap soapModel : soapModels) {
127                            models.add(toModel(soapModel));
128                    }
129    
130                    return models;
131            }
132    
133            public static final long LOCK_EXPIRATION_TIME = GetterUtil.getLong(com.liferay.portal.util.PropsUtil.get(
134                                    "lock.expiration.time.com.liferay.portal.model.Image"));
135    
136            public ImageModelImpl() {
137            }
138    
139            @Override
140            public long getPrimaryKey() {
141                    return _imageId;
142            }
143    
144            @Override
145            public void setPrimaryKey(long primaryKey) {
146                    setImageId(primaryKey);
147            }
148    
149            @Override
150            public Serializable getPrimaryKeyObj() {
151                    return _imageId;
152            }
153    
154            @Override
155            public void setPrimaryKeyObj(Serializable primaryKeyObj) {
156                    setPrimaryKey(((Long)primaryKeyObj).longValue());
157            }
158    
159            @Override
160            public Class<?> getModelClass() {
161                    return Image.class;
162            }
163    
164            @Override
165            public String getModelClassName() {
166                    return Image.class.getName();
167            }
168    
169            @Override
170            public Map<String, Object> getModelAttributes() {
171                    Map<String, Object> attributes = new HashMap<String, Object>();
172    
173                    attributes.put("imageId", getImageId());
174                    attributes.put("modifiedDate", getModifiedDate());
175                    attributes.put("type", getType());
176                    attributes.put("height", getHeight());
177                    attributes.put("width", getWidth());
178                    attributes.put("size", getSize());
179    
180                    return attributes;
181            }
182    
183            @Override
184            public void setModelAttributes(Map<String, Object> attributes) {
185                    Long imageId = (Long)attributes.get("imageId");
186    
187                    if (imageId != null) {
188                            setImageId(imageId);
189                    }
190    
191                    Date modifiedDate = (Date)attributes.get("modifiedDate");
192    
193                    if (modifiedDate != null) {
194                            setModifiedDate(modifiedDate);
195                    }
196    
197                    String type = (String)attributes.get("type");
198    
199                    if (type != null) {
200                            setType(type);
201                    }
202    
203                    Integer height = (Integer)attributes.get("height");
204    
205                    if (height != null) {
206                            setHeight(height);
207                    }
208    
209                    Integer width = (Integer)attributes.get("width");
210    
211                    if (width != null) {
212                            setWidth(width);
213                    }
214    
215                    Integer size = (Integer)attributes.get("size");
216    
217                    if (size != null) {
218                            setSize(size);
219                    }
220            }
221    
222            @JSON
223            @Override
224            public long getImageId() {
225                    return _imageId;
226            }
227    
228            @Override
229            public void setImageId(long imageId) {
230                    _columnBitmask = -1L;
231    
232                    _imageId = imageId;
233            }
234    
235            @JSON
236            @Override
237            public Date getModifiedDate() {
238                    return _modifiedDate;
239            }
240    
241            @Override
242            public void setModifiedDate(Date modifiedDate) {
243                    _modifiedDate = modifiedDate;
244            }
245    
246            @JSON
247            @Override
248            public String getType() {
249                    if (_type == null) {
250                            return StringPool.BLANK;
251                    }
252                    else {
253                            return _type;
254                    }
255            }
256    
257            @Override
258            public void setType(String type) {
259                    _type = type;
260            }
261    
262            @JSON
263            @Override
264            public int getHeight() {
265                    return _height;
266            }
267    
268            @Override
269            public void setHeight(int height) {
270                    _height = height;
271            }
272    
273            @JSON
274            @Override
275            public int getWidth() {
276                    return _width;
277            }
278    
279            @Override
280            public void setWidth(int width) {
281                    _width = width;
282            }
283    
284            @JSON
285            @Override
286            public int getSize() {
287                    return _size;
288            }
289    
290            @Override
291            public void setSize(int size) {
292                    _columnBitmask |= SIZE_COLUMN_BITMASK;
293    
294                    if (!_setOriginalSize) {
295                            _setOriginalSize = true;
296    
297                            _originalSize = _size;
298                    }
299    
300                    _size = size;
301            }
302    
303            public int getOriginalSize() {
304                    return _originalSize;
305            }
306    
307            public long getColumnBitmask() {
308                    return _columnBitmask;
309            }
310    
311            @Override
312            public ExpandoBridge getExpandoBridge() {
313                    return ExpandoBridgeFactoryUtil.getExpandoBridge(0,
314                            Image.class.getName(), getPrimaryKey());
315            }
316    
317            @Override
318            public void setExpandoBridgeAttributes(ServiceContext serviceContext) {
319                    ExpandoBridge expandoBridge = getExpandoBridge();
320    
321                    expandoBridge.setAttributes(serviceContext);
322            }
323    
324            @Override
325            public Image toEscapedModel() {
326                    if (_escapedModel == null) {
327                            _escapedModel = (Image)ProxyUtil.newProxyInstance(_classLoader,
328                                            _escapedModelInterfaces, new AutoEscapeBeanHandler(this));
329                    }
330    
331                    return _escapedModel;
332            }
333    
334            @Override
335            public Object clone() {
336                    ImageImpl imageImpl = new ImageImpl();
337    
338                    imageImpl.setImageId(getImageId());
339                    imageImpl.setModifiedDate(getModifiedDate());
340                    imageImpl.setType(getType());
341                    imageImpl.setHeight(getHeight());
342                    imageImpl.setWidth(getWidth());
343                    imageImpl.setSize(getSize());
344    
345                    imageImpl.resetOriginalValues();
346    
347                    return imageImpl;
348            }
349    
350            @Override
351            public int compareTo(Image image) {
352                    int value = 0;
353    
354                    if (getImageId() < image.getImageId()) {
355                            value = -1;
356                    }
357                    else if (getImageId() > image.getImageId()) {
358                            value = 1;
359                    }
360                    else {
361                            value = 0;
362                    }
363    
364                    if (value != 0) {
365                            return value;
366                    }
367    
368                    return 0;
369            }
370    
371            @Override
372            public boolean equals(Object obj) {
373                    if (this == obj) {
374                            return true;
375                    }
376    
377                    if (!(obj instanceof Image)) {
378                            return false;
379                    }
380    
381                    Image image = (Image)obj;
382    
383                    long primaryKey = image.getPrimaryKey();
384    
385                    if (getPrimaryKey() == primaryKey) {
386                            return true;
387                    }
388                    else {
389                            return false;
390                    }
391            }
392    
393            @Override
394            public int hashCode() {
395                    return (int)getPrimaryKey();
396            }
397    
398            @Override
399            public void resetOriginalValues() {
400                    ImageModelImpl imageModelImpl = this;
401    
402                    imageModelImpl._originalSize = imageModelImpl._size;
403    
404                    imageModelImpl._setOriginalSize = false;
405    
406                    imageModelImpl._columnBitmask = 0;
407            }
408    
409            @Override
410            public CacheModel<Image> toCacheModel() {
411                    ImageCacheModel imageCacheModel = new ImageCacheModel();
412    
413                    imageCacheModel.imageId = getImageId();
414    
415                    Date modifiedDate = getModifiedDate();
416    
417                    if (modifiedDate != null) {
418                            imageCacheModel.modifiedDate = modifiedDate.getTime();
419                    }
420                    else {
421                            imageCacheModel.modifiedDate = Long.MIN_VALUE;
422                    }
423    
424                    imageCacheModel.type = getType();
425    
426                    String type = imageCacheModel.type;
427    
428                    if ((type != null) && (type.length() == 0)) {
429                            imageCacheModel.type = null;
430                    }
431    
432                    imageCacheModel.height = getHeight();
433    
434                    imageCacheModel.width = getWidth();
435    
436                    imageCacheModel.size = getSize();
437    
438                    return imageCacheModel;
439            }
440    
441            @Override
442            public String toString() {
443                    StringBundler sb = new StringBundler(13);
444    
445                    sb.append("{imageId=");
446                    sb.append(getImageId());
447                    sb.append(", modifiedDate=");
448                    sb.append(getModifiedDate());
449                    sb.append(", type=");
450                    sb.append(getType());
451                    sb.append(", height=");
452                    sb.append(getHeight());
453                    sb.append(", width=");
454                    sb.append(getWidth());
455                    sb.append(", size=");
456                    sb.append(getSize());
457                    sb.append("}");
458    
459                    return sb.toString();
460            }
461    
462            @Override
463            public String toXmlString() {
464                    StringBundler sb = new StringBundler(22);
465    
466                    sb.append("<model><model-name>");
467                    sb.append("com.liferay.portal.model.Image");
468                    sb.append("</model-name>");
469    
470                    sb.append(
471                            "<column><column-name>imageId</column-name><column-value><![CDATA[");
472                    sb.append(getImageId());
473                    sb.append("]]></column-value></column>");
474                    sb.append(
475                            "<column><column-name>modifiedDate</column-name><column-value><![CDATA[");
476                    sb.append(getModifiedDate());
477                    sb.append("]]></column-value></column>");
478                    sb.append(
479                            "<column><column-name>type</column-name><column-value><![CDATA[");
480                    sb.append(getType());
481                    sb.append("]]></column-value></column>");
482                    sb.append(
483                            "<column><column-name>height</column-name><column-value><![CDATA[");
484                    sb.append(getHeight());
485                    sb.append("]]></column-value></column>");
486                    sb.append(
487                            "<column><column-name>width</column-name><column-value><![CDATA[");
488                    sb.append(getWidth());
489                    sb.append("]]></column-value></column>");
490                    sb.append(
491                            "<column><column-name>size</column-name><column-value><![CDATA[");
492                    sb.append(getSize());
493                    sb.append("]]></column-value></column>");
494    
495                    sb.append("</model>");
496    
497                    return sb.toString();
498            }
499    
500            private static ClassLoader _classLoader = Image.class.getClassLoader();
501            private static Class<?>[] _escapedModelInterfaces = new Class[] { Image.class };
502            private long _imageId;
503            private Date _modifiedDate;
504            private String _type;
505            private int _height;
506            private int _width;
507            private int _size;
508            private int _originalSize;
509            private boolean _setOriginalSize;
510            private long _columnBitmask;
511            private Image _escapedModel;
512    }