001    /**
002     * Copyright (c) 2000-2012 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.List;
039    
040    /**
041     * 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.
042     *
043     * <p>
044     * 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}.
045     * </p>
046     *
047     * @author Brian Wing Shun Chan
048     * @see ImageImpl
049     * @see com.liferay.portal.model.Image
050     * @see com.liferay.portal.model.ImageModel
051     * @generated
052     */
053    @JSON(strict = true)
054    public class ImageModelImpl extends BaseModelImpl<Image> implements ImageModel {
055            /*
056             * NOTE FOR DEVELOPERS:
057             *
058             * 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.
059             */
060            public static final String TABLE_NAME = "Image";
061            public static final Object[][] TABLE_COLUMNS = {
062                            { "imageId", Types.BIGINT },
063                            { "modifiedDate", Types.TIMESTAMP },
064                            { "text_", Types.CLOB },
065                            { "type_", Types.VARCHAR },
066                            { "height", Types.INTEGER },
067                            { "width", Types.INTEGER },
068                            { "size_", Types.INTEGER }
069                    };
070            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)";
071            public static final String TABLE_SQL_DROP = "drop table Image";
072            public static final String ORDER_BY_JPQL = " ORDER BY image.imageId ASC";
073            public static final String ORDER_BY_SQL = " ORDER BY Image.imageId ASC";
074            public static final String DATA_SOURCE = "liferayDataSource";
075            public static final String SESSION_FACTORY = "liferaySessionFactory";
076            public static final String TX_MANAGER = "liferayTransactionManager";
077            public static final boolean ENTITY_CACHE_ENABLED = GetterUtil.getBoolean(com.liferay.portal.util.PropsUtil.get(
078                                    "value.object.entity.cache.enabled.com.liferay.portal.model.Image"),
079                            true);
080            public static final boolean FINDER_CACHE_ENABLED = GetterUtil.getBoolean(com.liferay.portal.util.PropsUtil.get(
081                                    "value.object.finder.cache.enabled.com.liferay.portal.model.Image"),
082                            true);
083            public static final boolean COLUMN_BITMASK_ENABLED = GetterUtil.getBoolean(com.liferay.portal.util.PropsUtil.get(
084                                    "value.object.column.bitmask.enabled.com.liferay.portal.model.Image"),
085                            true);
086            public static long SIZE_COLUMN_BITMASK = 1L;
087    
088            /**
089             * Converts the soap model instance into a normal model instance.
090             *
091             * @param soapModel the soap model instance to convert
092             * @return the normal model instance
093             */
094            public static Image toModel(ImageSoap soapModel) {
095                    Image model = new ImageImpl();
096    
097                    model.setImageId(soapModel.getImageId());
098                    model.setModifiedDate(soapModel.getModifiedDate());
099                    model.setText(soapModel.getText());
100                    model.setType(soapModel.getType());
101                    model.setHeight(soapModel.getHeight());
102                    model.setWidth(soapModel.getWidth());
103                    model.setSize(soapModel.getSize());
104    
105                    return model;
106            }
107    
108            /**
109             * Converts the soap model instances into normal model instances.
110             *
111             * @param soapModels the soap model instances to convert
112             * @return the normal model instances
113             */
114            public static List<Image> toModels(ImageSoap[] soapModels) {
115                    List<Image> models = new ArrayList<Image>(soapModels.length);
116    
117                    for (ImageSoap soapModel : soapModels) {
118                            models.add(toModel(soapModel));
119                    }
120    
121                    return models;
122            }
123    
124            public static final long LOCK_EXPIRATION_TIME = GetterUtil.getLong(com.liferay.portal.util.PropsUtil.get(
125                                    "lock.expiration.time.com.liferay.portal.model.Image"));
126    
127            public ImageModelImpl() {
128            }
129    
130            public long getPrimaryKey() {
131                    return _imageId;
132            }
133    
134            public void setPrimaryKey(long primaryKey) {
135                    setImageId(primaryKey);
136            }
137    
138            public Serializable getPrimaryKeyObj() {
139                    return new Long(_imageId);
140            }
141    
142            public void setPrimaryKeyObj(Serializable primaryKeyObj) {
143                    setPrimaryKey(((Long)primaryKeyObj).longValue());
144            }
145    
146            public Class<?> getModelClass() {
147                    return Image.class;
148            }
149    
150            public String getModelClassName() {
151                    return Image.class.getName();
152            }
153    
154            @JSON
155            public long getImageId() {
156                    return _imageId;
157            }
158    
159            public void setImageId(long imageId) {
160                    _columnBitmask = -1L;
161    
162                    _imageId = imageId;
163            }
164    
165            @JSON
166            public Date getModifiedDate() {
167                    return _modifiedDate;
168            }
169    
170            public void setModifiedDate(Date modifiedDate) {
171                    _modifiedDate = modifiedDate;
172            }
173    
174            @JSON
175            public String getText() {
176                    if (_text == null) {
177                            return StringPool.BLANK;
178                    }
179                    else {
180                            return _text;
181                    }
182            }
183    
184            public void setText(String text) {
185                    _text = text;
186            }
187    
188            @JSON
189            public String getType() {
190                    if (_type == null) {
191                            return StringPool.BLANK;
192                    }
193                    else {
194                            return _type;
195                    }
196            }
197    
198            public void setType(String type) {
199                    _type = type;
200            }
201    
202            @JSON
203            public int getHeight() {
204                    return _height;
205            }
206    
207            public void setHeight(int height) {
208                    _height = height;
209            }
210    
211            @JSON
212            public int getWidth() {
213                    return _width;
214            }
215    
216            public void setWidth(int width) {
217                    _width = width;
218            }
219    
220            @JSON
221            public int getSize() {
222                    return _size;
223            }
224    
225            public void setSize(int size) {
226                    _columnBitmask |= SIZE_COLUMN_BITMASK;
227    
228                    if (!_setOriginalSize) {
229                            _setOriginalSize = true;
230    
231                            _originalSize = _size;
232                    }
233    
234                    _size = size;
235            }
236    
237            public int getOriginalSize() {
238                    return _originalSize;
239            }
240    
241            public long getColumnBitmask() {
242                    return _columnBitmask;
243            }
244    
245            @Override
246            public Image toEscapedModel() {
247                    if (_escapedModelProxy == null) {
248                            _escapedModelProxy = (Image)ProxyUtil.newProxyInstance(_classLoader,
249                                            _escapedModelProxyInterfaces,
250                                            new AutoEscapeBeanHandler(this));
251                    }
252    
253                    return _escapedModelProxy;
254            }
255    
256            @Override
257            public ExpandoBridge getExpandoBridge() {
258                    if (_expandoBridge == null) {
259                            _expandoBridge = ExpandoBridgeFactoryUtil.getExpandoBridge(0,
260                                            Image.class.getName(), getPrimaryKey());
261                    }
262    
263                    return _expandoBridge;
264            }
265    
266            @Override
267            public void setExpandoBridgeAttributes(ServiceContext serviceContext) {
268                    getExpandoBridge().setAttributes(serviceContext);
269            }
270    
271            @Override
272            public Object clone() {
273                    ImageImpl imageImpl = new ImageImpl();
274    
275                    imageImpl.setImageId(getImageId());
276                    imageImpl.setModifiedDate(getModifiedDate());
277                    imageImpl.setText(getText());
278                    imageImpl.setType(getType());
279                    imageImpl.setHeight(getHeight());
280                    imageImpl.setWidth(getWidth());
281                    imageImpl.setSize(getSize());
282    
283                    imageImpl.resetOriginalValues();
284    
285                    return imageImpl;
286            }
287    
288            public int compareTo(Image image) {
289                    int value = 0;
290    
291                    if (getImageId() < image.getImageId()) {
292                            value = -1;
293                    }
294                    else if (getImageId() > image.getImageId()) {
295                            value = 1;
296                    }
297                    else {
298                            value = 0;
299                    }
300    
301                    if (value != 0) {
302                            return value;
303                    }
304    
305                    return 0;
306            }
307    
308            @Override
309            public boolean equals(Object obj) {
310                    if (obj == null) {
311                            return false;
312                    }
313    
314                    Image image = null;
315    
316                    try {
317                            image = (Image)obj;
318                    }
319                    catch (ClassCastException cce) {
320                            return false;
321                    }
322    
323                    long primaryKey = image.getPrimaryKey();
324    
325                    if (getPrimaryKey() == primaryKey) {
326                            return true;
327                    }
328                    else {
329                            return false;
330                    }
331            }
332    
333            @Override
334            public int hashCode() {
335                    return (int)getPrimaryKey();
336            }
337    
338            @Override
339            public void resetOriginalValues() {
340                    ImageModelImpl imageModelImpl = this;
341    
342                    imageModelImpl._originalSize = imageModelImpl._size;
343    
344                    imageModelImpl._setOriginalSize = false;
345    
346                    imageModelImpl._columnBitmask = 0;
347            }
348    
349            @Override
350            public CacheModel<Image> toCacheModel() {
351                    ImageCacheModel imageCacheModel = new ImageCacheModel();
352    
353                    imageCacheModel.imageId = getImageId();
354    
355                    Date modifiedDate = getModifiedDate();
356    
357                    if (modifiedDate != null) {
358                            imageCacheModel.modifiedDate = modifiedDate.getTime();
359                    }
360                    else {
361                            imageCacheModel.modifiedDate = Long.MIN_VALUE;
362                    }
363    
364                    imageCacheModel.text = getText();
365    
366                    String text = imageCacheModel.text;
367    
368                    if ((text != null) && (text.length() == 0)) {
369                            imageCacheModel.text = null;
370                    }
371    
372                    imageCacheModel.type = getType();
373    
374                    String type = imageCacheModel.type;
375    
376                    if ((type != null) && (type.length() == 0)) {
377                            imageCacheModel.type = null;
378                    }
379    
380                    imageCacheModel.height = getHeight();
381    
382                    imageCacheModel.width = getWidth();
383    
384                    imageCacheModel.size = getSize();
385    
386                    return imageCacheModel;
387            }
388    
389            @Override
390            public String toString() {
391                    StringBundler sb = new StringBundler(15);
392    
393                    sb.append("{imageId=");
394                    sb.append(getImageId());
395                    sb.append(", modifiedDate=");
396                    sb.append(getModifiedDate());
397                    sb.append(", text=");
398                    sb.append(getText());
399                    sb.append(", type=");
400                    sb.append(getType());
401                    sb.append(", height=");
402                    sb.append(getHeight());
403                    sb.append(", width=");
404                    sb.append(getWidth());
405                    sb.append(", size=");
406                    sb.append(getSize());
407                    sb.append("}");
408    
409                    return sb.toString();
410            }
411    
412            public String toXmlString() {
413                    StringBundler sb = new StringBundler(25);
414    
415                    sb.append("<model><model-name>");
416                    sb.append("com.liferay.portal.model.Image");
417                    sb.append("</model-name>");
418    
419                    sb.append(
420                            "<column><column-name>imageId</column-name><column-value><![CDATA[");
421                    sb.append(getImageId());
422                    sb.append("]]></column-value></column>");
423                    sb.append(
424                            "<column><column-name>modifiedDate</column-name><column-value><![CDATA[");
425                    sb.append(getModifiedDate());
426                    sb.append("]]></column-value></column>");
427                    sb.append(
428                            "<column><column-name>text</column-name><column-value><![CDATA[");
429                    sb.append(getText());
430                    sb.append("]]></column-value></column>");
431                    sb.append(
432                            "<column><column-name>type</column-name><column-value><![CDATA[");
433                    sb.append(getType());
434                    sb.append("]]></column-value></column>");
435                    sb.append(
436                            "<column><column-name>height</column-name><column-value><![CDATA[");
437                    sb.append(getHeight());
438                    sb.append("]]></column-value></column>");
439                    sb.append(
440                            "<column><column-name>width</column-name><column-value><![CDATA[");
441                    sb.append(getWidth());
442                    sb.append("]]></column-value></column>");
443                    sb.append(
444                            "<column><column-name>size</column-name><column-value><![CDATA[");
445                    sb.append(getSize());
446                    sb.append("]]></column-value></column>");
447    
448                    sb.append("</model>");
449    
450                    return sb.toString();
451            }
452    
453            private static ClassLoader _classLoader = Image.class.getClassLoader();
454            private static Class<?>[] _escapedModelProxyInterfaces = new Class[] {
455                            Image.class
456                    };
457            private long _imageId;
458            private Date _modifiedDate;
459            private String _text;
460            private String _type;
461            private int _height;
462            private int _width;
463            private int _size;
464            private int _originalSize;
465            private boolean _setOriginalSize;
466            private transient ExpandoBridge _expandoBridge;
467            private long _columnBitmask;
468            private Image _escapedModelProxy;
469    }