001    /**
002     * Copyright (c) 2000-2013 Liferay, Inc. All rights reserved.
003     *
004     * This library is free software; you can redistribute it and/or modify it under
005     * the terms of the GNU Lesser General Public License as published by the Free
006     * Software Foundation; either version 2.1 of the License, or (at your option)
007     * any later version.
008     *
009     * This library is distributed in the hope that it will be useful, but WITHOUT
010     * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
011     * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
012     * details.
013     */
014    
015    package com.liferay.portlet.expando.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.impl.BaseModelImpl;
025    
026    import com.liferay.portlet.expando.model.ExpandoColumn;
027    import com.liferay.portlet.expando.model.ExpandoColumnModel;
028    import com.liferay.portlet.expando.model.ExpandoColumnSoap;
029    
030    import java.io.Serializable;
031    
032    import java.sql.Types;
033    
034    import java.util.ArrayList;
035    import java.util.HashMap;
036    import java.util.List;
037    import java.util.Map;
038    
039    /**
040     * The base model implementation for the ExpandoColumn service. Represents a row in the "ExpandoColumn" database table, with each column mapped to a property of this class.
041     *
042     * <p>
043     * This implementation and its corresponding interface {@link com.liferay.portlet.expando.model.ExpandoColumnModel} exist only as a container for the default property accessors generated by ServiceBuilder. Helper methods and all application logic should be put in {@link ExpandoColumnImpl}.
044     * </p>
045     *
046     * @author Brian Wing Shun Chan
047     * @see ExpandoColumnImpl
048     * @see com.liferay.portlet.expando.model.ExpandoColumn
049     * @see com.liferay.portlet.expando.model.ExpandoColumnModel
050     * @generated
051     */
052    @JSON(strict = true)
053    public class ExpandoColumnModelImpl extends BaseModelImpl<ExpandoColumn>
054            implements ExpandoColumnModel {
055            /*
056             * NOTE FOR DEVELOPERS:
057             *
058             * Never modify or reference this class directly. All methods that expect a expando column model instance should use the {@link com.liferay.portlet.expando.model.ExpandoColumn} interface instead.
059             */
060            public static final String TABLE_NAME = "ExpandoColumn";
061            public static final Object[][] TABLE_COLUMNS = {
062                            { "columnId", Types.BIGINT },
063                            { "companyId", Types.BIGINT },
064                            { "tableId", Types.BIGINT },
065                            { "name", Types.VARCHAR },
066                            { "type_", Types.INTEGER },
067                            { "defaultData", Types.VARCHAR },
068                            { "typeSettings", Types.CLOB }
069                    };
070            public static final String TABLE_SQL_CREATE = "create table ExpandoColumn (columnId LONG not null primary key,companyId LONG,tableId LONG,name VARCHAR(75) null,type_ INTEGER,defaultData STRING null,typeSettings TEXT null)";
071            public static final String TABLE_SQL_DROP = "drop table ExpandoColumn";
072            public static final String ORDER_BY_JPQL = " ORDER BY expandoColumn.name ASC";
073            public static final String ORDER_BY_SQL = " ORDER BY ExpandoColumn.name 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.portlet.expando.model.ExpandoColumn"),
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.portlet.expando.model.ExpandoColumn"),
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.portlet.expando.model.ExpandoColumn"),
085                            true);
086            public static long NAME_COLUMN_BITMASK = 1L;
087            public static long TABLEID_COLUMN_BITMASK = 2L;
088    
089            /**
090             * Converts the soap model instance into a normal model instance.
091             *
092             * @param soapModel the soap model instance to convert
093             * @return the normal model instance
094             */
095            public static ExpandoColumn toModel(ExpandoColumnSoap soapModel) {
096                    if (soapModel == null) {
097                            return null;
098                    }
099    
100                    ExpandoColumn model = new ExpandoColumnImpl();
101    
102                    model.setColumnId(soapModel.getColumnId());
103                    model.setCompanyId(soapModel.getCompanyId());
104                    model.setTableId(soapModel.getTableId());
105                    model.setName(soapModel.getName());
106                    model.setType(soapModel.getType());
107                    model.setDefaultData(soapModel.getDefaultData());
108                    model.setTypeSettings(soapModel.getTypeSettings());
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<ExpandoColumn> toModels(ExpandoColumnSoap[] soapModels) {
120                    if (soapModels == null) {
121                            return null;
122                    }
123    
124                    List<ExpandoColumn> models = new ArrayList<ExpandoColumn>(soapModels.length);
125    
126                    for (ExpandoColumnSoap 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.portlet.expando.model.ExpandoColumn"));
135    
136            public ExpandoColumnModelImpl() {
137            }
138    
139            public long getPrimaryKey() {
140                    return _columnId;
141            }
142    
143            public void setPrimaryKey(long primaryKey) {
144                    setColumnId(primaryKey);
145            }
146    
147            public Serializable getPrimaryKeyObj() {
148                    return new Long(_columnId);
149            }
150    
151            public void setPrimaryKeyObj(Serializable primaryKeyObj) {
152                    setPrimaryKey(((Long)primaryKeyObj).longValue());
153            }
154    
155            public Class<?> getModelClass() {
156                    return ExpandoColumn.class;
157            }
158    
159            public String getModelClassName() {
160                    return ExpandoColumn.class.getName();
161            }
162    
163            @Override
164            public Map<String, Object> getModelAttributes() {
165                    Map<String, Object> attributes = new HashMap<String, Object>();
166    
167                    attributes.put("columnId", getColumnId());
168                    attributes.put("companyId", getCompanyId());
169                    attributes.put("tableId", getTableId());
170                    attributes.put("name", getName());
171                    attributes.put("type", getType());
172                    attributes.put("defaultData", getDefaultData());
173                    attributes.put("typeSettings", getTypeSettings());
174    
175                    return attributes;
176            }
177    
178            @Override
179            public void setModelAttributes(Map<String, Object> attributes) {
180                    Long columnId = (Long)attributes.get("columnId");
181    
182                    if (columnId != null) {
183                            setColumnId(columnId);
184                    }
185    
186                    Long companyId = (Long)attributes.get("companyId");
187    
188                    if (companyId != null) {
189                            setCompanyId(companyId);
190                    }
191    
192                    Long tableId = (Long)attributes.get("tableId");
193    
194                    if (tableId != null) {
195                            setTableId(tableId);
196                    }
197    
198                    String name = (String)attributes.get("name");
199    
200                    if (name != null) {
201                            setName(name);
202                    }
203    
204                    Integer type = (Integer)attributes.get("type");
205    
206                    if (type != null) {
207                            setType(type);
208                    }
209    
210                    String defaultData = (String)attributes.get("defaultData");
211    
212                    if (defaultData != null) {
213                            setDefaultData(defaultData);
214                    }
215    
216                    String typeSettings = (String)attributes.get("typeSettings");
217    
218                    if (typeSettings != null) {
219                            setTypeSettings(typeSettings);
220                    }
221            }
222    
223            @JSON
224            public long getColumnId() {
225                    return _columnId;
226            }
227    
228            public void setColumnId(long columnId) {
229                    _columnId = columnId;
230            }
231    
232            @JSON
233            public long getCompanyId() {
234                    return _companyId;
235            }
236    
237            public void setCompanyId(long companyId) {
238                    _companyId = companyId;
239            }
240    
241            @JSON
242            public long getTableId() {
243                    return _tableId;
244            }
245    
246            public void setTableId(long tableId) {
247                    _columnBitmask |= TABLEID_COLUMN_BITMASK;
248    
249                    if (!_setOriginalTableId) {
250                            _setOriginalTableId = true;
251    
252                            _originalTableId = _tableId;
253                    }
254    
255                    _tableId = tableId;
256            }
257    
258            public long getOriginalTableId() {
259                    return _originalTableId;
260            }
261    
262            @JSON
263            public String getName() {
264                    if (_name == null) {
265                            return StringPool.BLANK;
266                    }
267                    else {
268                            return _name;
269                    }
270            }
271    
272            public void setName(String name) {
273                    _columnBitmask = -1L;
274    
275                    if (_originalName == null) {
276                            _originalName = _name;
277                    }
278    
279                    _name = name;
280            }
281    
282            public String getOriginalName() {
283                    return GetterUtil.getString(_originalName);
284            }
285    
286            @JSON
287            public int getType() {
288                    return _type;
289            }
290    
291            public void setType(int type) {
292                    _type = type;
293            }
294    
295            @JSON
296            public String getDefaultData() {
297                    if (_defaultData == null) {
298                            return StringPool.BLANK;
299                    }
300                    else {
301                            return _defaultData;
302                    }
303            }
304    
305            public void setDefaultData(String defaultData) {
306                    _defaultData = defaultData;
307            }
308    
309            @JSON
310            public String getTypeSettings() {
311                    if (_typeSettings == null) {
312                            return StringPool.BLANK;
313                    }
314                    else {
315                            return _typeSettings;
316                    }
317            }
318    
319            public void setTypeSettings(String typeSettings) {
320                    _typeSettings = typeSettings;
321            }
322    
323            public long getColumnBitmask() {
324                    return _columnBitmask;
325            }
326    
327            @Override
328            public ExpandoColumn toEscapedModel() {
329                    if (_escapedModel == null) {
330                            _escapedModel = (ExpandoColumn)ProxyUtil.newProxyInstance(_classLoader,
331                                            _escapedModelInterfaces, new AutoEscapeBeanHandler(this));
332                    }
333    
334                    return _escapedModel;
335            }
336    
337            public ExpandoColumn toUnescapedModel() {
338                    return (ExpandoColumn)this;
339            }
340    
341            @Override
342            public Object clone() {
343                    ExpandoColumnImpl expandoColumnImpl = new ExpandoColumnImpl();
344    
345                    expandoColumnImpl.setColumnId(getColumnId());
346                    expandoColumnImpl.setCompanyId(getCompanyId());
347                    expandoColumnImpl.setTableId(getTableId());
348                    expandoColumnImpl.setName(getName());
349                    expandoColumnImpl.setType(getType());
350                    expandoColumnImpl.setDefaultData(getDefaultData());
351                    expandoColumnImpl.setTypeSettings(getTypeSettings());
352    
353                    expandoColumnImpl.resetOriginalValues();
354    
355                    return expandoColumnImpl;
356            }
357    
358            public int compareTo(ExpandoColumn expandoColumn) {
359                    int value = 0;
360    
361                    value = getName().compareTo(expandoColumn.getName());
362    
363                    if (value != 0) {
364                            return value;
365                    }
366    
367                    return 0;
368            }
369    
370            @Override
371            public boolean equals(Object obj) {
372                    if (this == obj) {
373                            return true;
374                    }
375    
376                    if (!(obj instanceof ExpandoColumn)) {
377                            return false;
378                    }
379    
380                    ExpandoColumn expandoColumn = (ExpandoColumn)obj;
381    
382                    long primaryKey = expandoColumn.getPrimaryKey();
383    
384                    if (getPrimaryKey() == primaryKey) {
385                            return true;
386                    }
387                    else {
388                            return false;
389                    }
390            }
391    
392            @Override
393            public int hashCode() {
394                    return (int)getPrimaryKey();
395            }
396    
397            @Override
398            public void resetOriginalValues() {
399                    ExpandoColumnModelImpl expandoColumnModelImpl = this;
400    
401                    expandoColumnModelImpl._originalTableId = expandoColumnModelImpl._tableId;
402    
403                    expandoColumnModelImpl._setOriginalTableId = false;
404    
405                    expandoColumnModelImpl._originalName = expandoColumnModelImpl._name;
406    
407                    expandoColumnModelImpl._columnBitmask = 0;
408            }
409    
410            @Override
411            public CacheModel<ExpandoColumn> toCacheModel() {
412                    ExpandoColumnCacheModel expandoColumnCacheModel = new ExpandoColumnCacheModel();
413    
414                    expandoColumnCacheModel.columnId = getColumnId();
415    
416                    expandoColumnCacheModel.companyId = getCompanyId();
417    
418                    expandoColumnCacheModel.tableId = getTableId();
419    
420                    expandoColumnCacheModel.name = getName();
421    
422                    String name = expandoColumnCacheModel.name;
423    
424                    if ((name != null) && (name.length() == 0)) {
425                            expandoColumnCacheModel.name = null;
426                    }
427    
428                    expandoColumnCacheModel.type = getType();
429    
430                    expandoColumnCacheModel.defaultData = getDefaultData();
431    
432                    String defaultData = expandoColumnCacheModel.defaultData;
433    
434                    if ((defaultData != null) && (defaultData.length() == 0)) {
435                            expandoColumnCacheModel.defaultData = null;
436                    }
437    
438                    expandoColumnCacheModel.typeSettings = getTypeSettings();
439    
440                    String typeSettings = expandoColumnCacheModel.typeSettings;
441    
442                    if ((typeSettings != null) && (typeSettings.length() == 0)) {
443                            expandoColumnCacheModel.typeSettings = null;
444                    }
445    
446                    return expandoColumnCacheModel;
447            }
448    
449            @Override
450            public String toString() {
451                    StringBundler sb = new StringBundler(15);
452    
453                    sb.append("{columnId=");
454                    sb.append(getColumnId());
455                    sb.append(", companyId=");
456                    sb.append(getCompanyId());
457                    sb.append(", tableId=");
458                    sb.append(getTableId());
459                    sb.append(", name=");
460                    sb.append(getName());
461                    sb.append(", type=");
462                    sb.append(getType());
463                    sb.append(", defaultData=");
464                    sb.append(getDefaultData());
465                    sb.append(", typeSettings=");
466                    sb.append(getTypeSettings());
467                    sb.append("}");
468    
469                    return sb.toString();
470            }
471    
472            public String toXmlString() {
473                    StringBundler sb = new StringBundler(25);
474    
475                    sb.append("<model><model-name>");
476                    sb.append("com.liferay.portlet.expando.model.ExpandoColumn");
477                    sb.append("</model-name>");
478    
479                    sb.append(
480                            "<column><column-name>columnId</column-name><column-value><![CDATA[");
481                    sb.append(getColumnId());
482                    sb.append("]]></column-value></column>");
483                    sb.append(
484                            "<column><column-name>companyId</column-name><column-value><![CDATA[");
485                    sb.append(getCompanyId());
486                    sb.append("]]></column-value></column>");
487                    sb.append(
488                            "<column><column-name>tableId</column-name><column-value><![CDATA[");
489                    sb.append(getTableId());
490                    sb.append("]]></column-value></column>");
491                    sb.append(
492                            "<column><column-name>name</column-name><column-value><![CDATA[");
493                    sb.append(getName());
494                    sb.append("]]></column-value></column>");
495                    sb.append(
496                            "<column><column-name>type</column-name><column-value><![CDATA[");
497                    sb.append(getType());
498                    sb.append("]]></column-value></column>");
499                    sb.append(
500                            "<column><column-name>defaultData</column-name><column-value><![CDATA[");
501                    sb.append(getDefaultData());
502                    sb.append("]]></column-value></column>");
503                    sb.append(
504                            "<column><column-name>typeSettings</column-name><column-value><![CDATA[");
505                    sb.append(getTypeSettings());
506                    sb.append("]]></column-value></column>");
507    
508                    sb.append("</model>");
509    
510                    return sb.toString();
511            }
512    
513            private static ClassLoader _classLoader = ExpandoColumn.class.getClassLoader();
514            private static Class<?>[] _escapedModelInterfaces = new Class[] {
515                            ExpandoColumn.class
516                    };
517            private long _columnId;
518            private long _companyId;
519            private long _tableId;
520            private long _originalTableId;
521            private boolean _setOriginalTableId;
522            private String _name;
523            private String _originalName;
524            private int _type;
525            private String _defaultData;
526            private String _typeSettings;
527            private long _columnBitmask;
528            private ExpandoColumn _escapedModel;
529    }