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                            { "text_", Types.CLOB },
067                            { "type_", Types.VARCHAR },
068                            { "height", Types.INTEGER },
069                            { "width", Types.INTEGER },
070                            { "size_", Types.INTEGER }
071                    };
072            public static final String TABLE_SQL_CREATE = "create table Image (imageId LONG not null primary key,modifiedDate DATE null,text_ TEXT null,type_ VARCHAR(75) null,height INTEGER,width INTEGER,size_ INTEGER)";
073            public static final String TABLE_SQL_DROP = "drop table Image";
074            public static final String ORDER_BY_JPQL = " ORDER BY image.imageId ASC";
075            public static final String ORDER_BY_SQL = " ORDER BY Image.imageId ASC";
076            public static final String DATA_SOURCE = "liferayDataSource";
077            public static final String SESSION_FACTORY = "liferaySessionFactory";
078            public static final String TX_MANAGER = "liferayTransactionManager";
079            public static final boolean ENTITY_CACHE_ENABLED = GetterUtil.getBoolean(com.liferay.portal.util.PropsUtil.get(
080                                    "value.object.entity.cache.enabled.com.liferay.portal.model.Image"),
081                            true);
082            public static final boolean FINDER_CACHE_ENABLED = GetterUtil.getBoolean(com.liferay.portal.util.PropsUtil.get(
083                                    "value.object.finder.cache.enabled.com.liferay.portal.model.Image"),
084                            true);
085            public static final boolean COLUMN_BITMASK_ENABLED = GetterUtil.getBoolean(com.liferay.portal.util.PropsUtil.get(
086                                    "value.object.column.bitmask.enabled.com.liferay.portal.model.Image"),
087                            true);
088            public static long SIZE_COLUMN_BITMASK = 1L;
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.setText(soapModel.getText());
106                    model.setType(soapModel.getType());
107                    model.setHeight(soapModel.getHeight());
108                    model.setWidth(soapModel.getWidth());
109                    model.setSize(soapModel.getSize());
110    
111                    return model;
112            }
113    
114            /**
115             * Converts the soap model instances into normal model instances.
116             *
117             * @param soapModels the soap model instances to convert
118             * @return the normal model instances
119             */
120            public static List<Image> toModels(ImageSoap[] soapModels) {
121                    if (soapModels == null) {
122                            return null;
123                    }
124    
125                    List<Image> models = new ArrayList<Image>(soapModels.length);
126    
127                    for (ImageSoap soapModel : soapModels) {
128                            models.add(toModel(soapModel));
129                    }
130    
131                    return models;
132            }
133    
134            public static final long LOCK_EXPIRATION_TIME = GetterUtil.getLong(com.liferay.portal.util.PropsUtil.get(
135                                    "lock.expiration.time.com.liferay.portal.model.Image"));
136    
137            public ImageModelImpl() {
138            }
139    
140            public long getPrimaryKey() {
141                    return _imageId;
142            }
143    
144            public void setPrimaryKey(long primaryKey) {
145                    setImageId(primaryKey);
146            }
147    
148            public Serializable getPrimaryKeyObj() {
149                    return new Long(_imageId);
150            }
151    
152            public void setPrimaryKeyObj(Serializable primaryKeyObj) {
153                    setPrimaryKey(((Long)primaryKeyObj).longValue());
154            }
155    
156            public Class<?> getModelClass() {
157                    return Image.class;
158            }
159    
160            public String getModelClassName() {
161                    return Image.class.getName();
162            }
163    
164            @Override
165            public Map<String, Object> getModelAttributes() {
166                    Map<String, Object> attributes = new HashMap<String, Object>();
167    
168                    attributes.put("imageId", getImageId());
169                    attributes.put("modifiedDate", getModifiedDate());
170                    attributes.put("text", getText());
171                    attributes.put("type", getType());
172                    attributes.put("height", getHeight());
173                    attributes.put("width", getWidth());
174                    attributes.put("size", getSize());
175    
176                    return attributes;
177            }
178    
179            @Override
180            public void setModelAttributes(Map<String, Object> attributes) {
181                    Long imageId = (Long)attributes.get("imageId");
182    
183                    if (imageId != null) {
184                            setImageId(imageId);
185                    }
186    
187                    Date modifiedDate = (Date)attributes.get("modifiedDate");
188    
189                    if (modifiedDate != null) {
190                            setModifiedDate(modifiedDate);
191                    }
192    
193                    String text = (String)attributes.get("text");
194    
195                    if (text != null) {
196                            setText(text);
197                    }
198    
199                    String type = (String)attributes.get("type");
200    
201                    if (type != null) {
202                            setType(type);
203                    }
204    
205                    Integer height = (Integer)attributes.get("height");
206    
207                    if (height != null) {
208                            setHeight(height);
209                    }
210    
211                    Integer width = (Integer)attributes.get("width");
212    
213                    if (width != null) {
214                            setWidth(width);
215                    }
216    
217                    Integer size = (Integer)attributes.get("size");
218    
219                    if (size != null) {
220                            setSize(size);
221                    }
222            }
223    
224            @JSON
225            public long getImageId() {
226                    return _imageId;
227            }
228    
229            public void setImageId(long imageId) {
230                    _columnBitmask = -1L;
231    
232                    _imageId = imageId;
233            }
234    
235            @JSON
236            public Date getModifiedDate() {
237                    return _modifiedDate;
238            }
239    
240            public void setModifiedDate(Date modifiedDate) {
241                    _modifiedDate = modifiedDate;
242            }
243    
244            @JSON
245            public String getText() {
246                    if (_text == null) {
247                            return StringPool.BLANK;
248                    }
249                    else {
250                            return _text;
251                    }
252            }
253    
254            public void setText(String text) {
255                    _text = text;
256            }
257    
258            @JSON
259            public String getType() {
260                    if (_type == null) {
261                            return StringPool.BLANK;
262                    }
263                    else {
264                            return _type;
265                    }
266            }
267    
268            public void setType(String type) {
269                    _type = type;
270            }
271    
272            @JSON
273            public int getHeight() {
274                    return _height;
275            }
276    
277            public void setHeight(int height) {
278                    _height = height;
279            }
280    
281            @JSON
282            public int getWidth() {
283                    return _width;
284            }
285    
286            public void setWidth(int width) {
287                    _width = width;
288            }
289    
290            @JSON
291            public int getSize() {
292                    return _size;
293            }
294    
295            public void setSize(int size) {
296                    _columnBitmask |= SIZE_COLUMN_BITMASK;
297    
298                    if (!_setOriginalSize) {
299                            _setOriginalSize = true;
300    
301                            _originalSize = _size;
302                    }
303    
304                    _size = size;
305            }
306    
307            public int getOriginalSize() {
308                    return _originalSize;
309            }
310    
311            public long getColumnBitmask() {
312                    return _columnBitmask;
313            }
314    
315            @Override
316            public ExpandoBridge getExpandoBridge() {
317                    return ExpandoBridgeFactoryUtil.getExpandoBridge(0,
318                            Image.class.getName(), getPrimaryKey());
319            }
320    
321            @Override
322            public void setExpandoBridgeAttributes(ServiceContext serviceContext) {
323                    ExpandoBridge expandoBridge = getExpandoBridge();
324    
325                    expandoBridge.setAttributes(serviceContext);
326            }
327    
328            @Override
329            public Image toEscapedModel() {
330                    if (_escapedModel == null) {
331                            _escapedModel = (Image)ProxyUtil.newProxyInstance(_classLoader,
332                                            _escapedModelInterfaces, new AutoEscapeBeanHandler(this));
333                    }
334    
335                    return _escapedModel;
336            }
337    
338            public Image toUnescapedModel() {
339                    return (Image)this;
340            }
341    
342            @Override
343            public Object clone() {
344                    ImageImpl imageImpl = new ImageImpl();
345    
346                    imageImpl.setImageId(getImageId());
347                    imageImpl.setModifiedDate(getModifiedDate());
348                    imageImpl.setText(getText());
349                    imageImpl.setType(getType());
350                    imageImpl.setHeight(getHeight());
351                    imageImpl.setWidth(getWidth());
352                    imageImpl.setSize(getSize());
353    
354                    imageImpl.resetOriginalValues();
355    
356                    return imageImpl;
357            }
358    
359            public int compareTo(Image image) {
360                    int value = 0;
361    
362                    if (getImageId() < image.getImageId()) {
363                            value = -1;
364                    }
365                    else if (getImageId() > image.getImageId()) {
366                            value = 1;
367                    }
368                    else {
369                            value = 0;
370                    }
371    
372                    if (value != 0) {
373                            return value;
374                    }
375    
376                    return 0;
377            }
378    
379            @Override
380            public boolean equals(Object obj) {
381                    if (this == obj) {
382                            return true;
383                    }
384    
385                    if (!(obj instanceof Image)) {
386                            return false;
387                    }
388    
389                    Image image = (Image)obj;
390    
391                    long primaryKey = image.getPrimaryKey();
392    
393                    if (getPrimaryKey() == primaryKey) {
394                            return true;
395                    }
396                    else {
397                            return false;
398                    }
399            }
400    
401            @Override
402            public int hashCode() {
403                    return (int)getPrimaryKey();
404            }
405    
406            @Override
407            public void resetOriginalValues() {
408                    ImageModelImpl imageModelImpl = this;
409    
410                    imageModelImpl._originalSize = imageModelImpl._size;
411    
412                    imageModelImpl._setOriginalSize = false;
413    
414                    imageModelImpl._columnBitmask = 0;
415            }
416    
417            @Override
418            public CacheModel<Image> toCacheModel() {
419                    ImageCacheModel imageCacheModel = new ImageCacheModel();
420    
421                    imageCacheModel.imageId = getImageId();
422    
423                    Date modifiedDate = getModifiedDate();
424    
425                    if (modifiedDate != null) {
426                            imageCacheModel.modifiedDate = modifiedDate.getTime();
427                    }
428                    else {
429                            imageCacheModel.modifiedDate = Long.MIN_VALUE;
430                    }
431    
432                    imageCacheModel.text = getText();
433    
434                    String text = imageCacheModel.text;
435    
436                    if ((text != null) && (text.length() == 0)) {
437                            imageCacheModel.text = null;
438                    }
439    
440                    imageCacheModel.type = getType();
441    
442                    String type = imageCacheModel.type;
443    
444                    if ((type != null) && (type.length() == 0)) {
445                            imageCacheModel.type = null;
446                    }
447    
448                    imageCacheModel.height = getHeight();
449    
450                    imageCacheModel.width = getWidth();
451    
452                    imageCacheModel.size = getSize();
453    
454                    return imageCacheModel;
455            }
456    
457            @Override
458            public String toString() {
459                    StringBundler sb = new StringBundler(15);
460    
461                    sb.append("{imageId=");
462                    sb.append(getImageId());
463                    sb.append(", modifiedDate=");
464                    sb.append(getModifiedDate());
465                    sb.append(", text=");
466                    sb.append(getText());
467                    sb.append(", type=");
468                    sb.append(getType());
469                    sb.append(", height=");
470                    sb.append(getHeight());
471                    sb.append(", width=");
472                    sb.append(getWidth());
473                    sb.append(", size=");
474                    sb.append(getSize());
475                    sb.append("}");
476    
477                    return sb.toString();
478            }
479    
480            public String toXmlString() {
481                    StringBundler sb = new StringBundler(25);
482    
483                    sb.append("<model><model-name>");
484                    sb.append("com.liferay.portal.model.Image");
485                    sb.append("</model-name>");
486    
487                    sb.append(
488                            "<column><column-name>imageId</column-name><column-value><![CDATA[");
489                    sb.append(getImageId());
490                    sb.append("]]></column-value></column>");
491                    sb.append(
492                            "<column><column-name>modifiedDate</column-name><column-value><![CDATA[");
493                    sb.append(getModifiedDate());
494                    sb.append("]]></column-value></column>");
495                    sb.append(
496                            "<column><column-name>text</column-name><column-value><![CDATA[");
497                    sb.append(getText());
498                    sb.append("]]></column-value></column>");
499                    sb.append(
500                            "<column><column-name>type</column-name><column-value><![CDATA[");
501                    sb.append(getType());
502                    sb.append("]]></column-value></column>");
503                    sb.append(
504                            "<column><column-name>height</column-name><column-value><![CDATA[");
505                    sb.append(getHeight());
506                    sb.append("]]></column-value></column>");
507                    sb.append(
508                            "<column><column-name>width</column-name><column-value><![CDATA[");
509                    sb.append(getWidth());
510                    sb.append("]]></column-value></column>");
511                    sb.append(
512                            "<column><column-name>size</column-name><column-value><![CDATA[");
513                    sb.append(getSize());
514                    sb.append("]]></column-value></column>");
515    
516                    sb.append("</model>");
517    
518                    return sb.toString();
519            }
520    
521            private static ClassLoader _classLoader = Image.class.getClassLoader();
522            private static Class<?>[] _escapedModelInterfaces = new Class[] { Image.class };
523            private long _imageId;
524            private Date _modifiedDate;
525            private String _text;
526            private String _type;
527            private int _height;
528            private int _width;
529            private int _size;
530            private int _originalSize;
531            private boolean _setOriginalSize;
532            private long _columnBitmask;
533            private Image _escapedModel;
534    }