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.ResourceBlock;
025    import com.liferay.portal.model.ResourceBlockModel;
026    import com.liferay.portal.model.ResourceBlockSoap;
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.HashMap;
038    import java.util.List;
039    import java.util.Map;
040    
041    /**
042     * The base model implementation for the ResourceBlock service. Represents a row in the "ResourceBlock" database table, with each column mapped to a property of this class.
043     *
044     * <p>
045     * This implementation and its corresponding interface {@link com.liferay.portal.model.ResourceBlockModel} exist only as a container for the default property accessors generated by ServiceBuilder. Helper methods and all application logic should be put in {@link ResourceBlockImpl}.
046     * </p>
047     *
048     * @author Brian Wing Shun Chan
049     * @see ResourceBlockImpl
050     * @see com.liferay.portal.model.ResourceBlock
051     * @see com.liferay.portal.model.ResourceBlockModel
052     * @generated
053     */
054    @JSON(strict = true)
055    public class ResourceBlockModelImpl extends BaseModelImpl<ResourceBlock>
056            implements ResourceBlockModel {
057            /*
058             * NOTE FOR DEVELOPERS:
059             *
060             * Never modify or reference this class directly. All methods that expect a resource block model instance should use the {@link com.liferay.portal.model.ResourceBlock} interface instead.
061             */
062            public static final String TABLE_NAME = "ResourceBlock";
063            public static final Object[][] TABLE_COLUMNS = {
064                            { "resourceBlockId", Types.BIGINT },
065                            { "companyId", Types.BIGINT },
066                            { "groupId", Types.BIGINT },
067                            { "name", Types.VARCHAR },
068                            { "permissionsHash", Types.VARCHAR },
069                            { "referenceCount", Types.BIGINT }
070                    };
071            public static final String TABLE_SQL_CREATE = "create table ResourceBlock (resourceBlockId LONG not null primary key,companyId LONG,groupId LONG,name VARCHAR(75) null,permissionsHash VARCHAR(75) null,referenceCount LONG)";
072            public static final String TABLE_SQL_DROP = "drop table ResourceBlock";
073            public static final String ORDER_BY_JPQL = " ORDER BY resourceBlock.resourceBlockId ASC";
074            public static final String ORDER_BY_SQL = " ORDER BY ResourceBlock.resourceBlockId 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.ResourceBlock"),
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.ResourceBlock"),
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.ResourceBlock"),
086                            true);
087            public static long COMPANYID_COLUMN_BITMASK = 1L;
088            public static long GROUPID_COLUMN_BITMASK = 2L;
089            public static long NAME_COLUMN_BITMASK = 4L;
090            public static long PERMISSIONSHASH_COLUMN_BITMASK = 8L;
091            public static long RESOURCEBLOCKID_COLUMN_BITMASK = 16L;
092    
093            /**
094             * Converts the soap model instance into a normal model instance.
095             *
096             * @param soapModel the soap model instance to convert
097             * @return the normal model instance
098             */
099            public static ResourceBlock toModel(ResourceBlockSoap soapModel) {
100                    if (soapModel == null) {
101                            return null;
102                    }
103    
104                    ResourceBlock model = new ResourceBlockImpl();
105    
106                    model.setResourceBlockId(soapModel.getResourceBlockId());
107                    model.setCompanyId(soapModel.getCompanyId());
108                    model.setGroupId(soapModel.getGroupId());
109                    model.setName(soapModel.getName());
110                    model.setPermissionsHash(soapModel.getPermissionsHash());
111                    model.setReferenceCount(soapModel.getReferenceCount());
112    
113                    return model;
114            }
115    
116            /**
117             * Converts the soap model instances into normal model instances.
118             *
119             * @param soapModels the soap model instances to convert
120             * @return the normal model instances
121             */
122            public static List<ResourceBlock> toModels(ResourceBlockSoap[] soapModels) {
123                    if (soapModels == null) {
124                            return null;
125                    }
126    
127                    List<ResourceBlock> models = new ArrayList<ResourceBlock>(soapModels.length);
128    
129                    for (ResourceBlockSoap soapModel : soapModels) {
130                            models.add(toModel(soapModel));
131                    }
132    
133                    return models;
134            }
135    
136            public static final long LOCK_EXPIRATION_TIME = GetterUtil.getLong(com.liferay.portal.util.PropsUtil.get(
137                                    "lock.expiration.time.com.liferay.portal.model.ResourceBlock"));
138    
139            public ResourceBlockModelImpl() {
140            }
141    
142            @Override
143            public long getPrimaryKey() {
144                    return _resourceBlockId;
145            }
146    
147            @Override
148            public void setPrimaryKey(long primaryKey) {
149                    setResourceBlockId(primaryKey);
150            }
151    
152            @Override
153            public Serializable getPrimaryKeyObj() {
154                    return _resourceBlockId;
155            }
156    
157            @Override
158            public void setPrimaryKeyObj(Serializable primaryKeyObj) {
159                    setPrimaryKey(((Long)primaryKeyObj).longValue());
160            }
161    
162            @Override
163            public Class<?> getModelClass() {
164                    return ResourceBlock.class;
165            }
166    
167            @Override
168            public String getModelClassName() {
169                    return ResourceBlock.class.getName();
170            }
171    
172            @Override
173            public Map<String, Object> getModelAttributes() {
174                    Map<String, Object> attributes = new HashMap<String, Object>();
175    
176                    attributes.put("resourceBlockId", getResourceBlockId());
177                    attributes.put("companyId", getCompanyId());
178                    attributes.put("groupId", getGroupId());
179                    attributes.put("name", getName());
180                    attributes.put("permissionsHash", getPermissionsHash());
181                    attributes.put("referenceCount", getReferenceCount());
182    
183                    return attributes;
184            }
185    
186            @Override
187            public void setModelAttributes(Map<String, Object> attributes) {
188                    Long resourceBlockId = (Long)attributes.get("resourceBlockId");
189    
190                    if (resourceBlockId != null) {
191                            setResourceBlockId(resourceBlockId);
192                    }
193    
194                    Long companyId = (Long)attributes.get("companyId");
195    
196                    if (companyId != null) {
197                            setCompanyId(companyId);
198                    }
199    
200                    Long groupId = (Long)attributes.get("groupId");
201    
202                    if (groupId != null) {
203                            setGroupId(groupId);
204                    }
205    
206                    String name = (String)attributes.get("name");
207    
208                    if (name != null) {
209                            setName(name);
210                    }
211    
212                    String permissionsHash = (String)attributes.get("permissionsHash");
213    
214                    if (permissionsHash != null) {
215                            setPermissionsHash(permissionsHash);
216                    }
217    
218                    Long referenceCount = (Long)attributes.get("referenceCount");
219    
220                    if (referenceCount != null) {
221                            setReferenceCount(referenceCount);
222                    }
223            }
224    
225            @JSON
226            @Override
227            public long getResourceBlockId() {
228                    return _resourceBlockId;
229            }
230    
231            @Override
232            public void setResourceBlockId(long resourceBlockId) {
233                    _resourceBlockId = resourceBlockId;
234            }
235    
236            @JSON
237            @Override
238            public long getCompanyId() {
239                    return _companyId;
240            }
241    
242            @Override
243            public void setCompanyId(long companyId) {
244                    _columnBitmask |= COMPANYID_COLUMN_BITMASK;
245    
246                    if (!_setOriginalCompanyId) {
247                            _setOriginalCompanyId = true;
248    
249                            _originalCompanyId = _companyId;
250                    }
251    
252                    _companyId = companyId;
253            }
254    
255            public long getOriginalCompanyId() {
256                    return _originalCompanyId;
257            }
258    
259            @JSON
260            @Override
261            public long getGroupId() {
262                    return _groupId;
263            }
264    
265            @Override
266            public void setGroupId(long groupId) {
267                    _columnBitmask |= GROUPID_COLUMN_BITMASK;
268    
269                    if (!_setOriginalGroupId) {
270                            _setOriginalGroupId = true;
271    
272                            _originalGroupId = _groupId;
273                    }
274    
275                    _groupId = groupId;
276            }
277    
278            public long getOriginalGroupId() {
279                    return _originalGroupId;
280            }
281    
282            @JSON
283            @Override
284            public String getName() {
285                    if (_name == null) {
286                            return StringPool.BLANK;
287                    }
288                    else {
289                            return _name;
290                    }
291            }
292    
293            @Override
294            public void setName(String name) {
295                    _columnBitmask |= NAME_COLUMN_BITMASK;
296    
297                    if (_originalName == null) {
298                            _originalName = _name;
299                    }
300    
301                    _name = name;
302            }
303    
304            public String getOriginalName() {
305                    return GetterUtil.getString(_originalName);
306            }
307    
308            @JSON
309            @Override
310            public String getPermissionsHash() {
311                    if (_permissionsHash == null) {
312                            return StringPool.BLANK;
313                    }
314                    else {
315                            return _permissionsHash;
316                    }
317            }
318    
319            @Override
320            public void setPermissionsHash(String permissionsHash) {
321                    _columnBitmask |= PERMISSIONSHASH_COLUMN_BITMASK;
322    
323                    if (_originalPermissionsHash == null) {
324                            _originalPermissionsHash = _permissionsHash;
325                    }
326    
327                    _permissionsHash = permissionsHash;
328            }
329    
330            public String getOriginalPermissionsHash() {
331                    return GetterUtil.getString(_originalPermissionsHash);
332            }
333    
334            @JSON
335            @Override
336            public long getReferenceCount() {
337                    return _referenceCount;
338            }
339    
340            @Override
341            public void setReferenceCount(long referenceCount) {
342                    _referenceCount = referenceCount;
343            }
344    
345            public long getColumnBitmask() {
346                    return _columnBitmask;
347            }
348    
349            @Override
350            public ExpandoBridge getExpandoBridge() {
351                    return ExpandoBridgeFactoryUtil.getExpandoBridge(getCompanyId(),
352                            ResourceBlock.class.getName(), getPrimaryKey());
353            }
354    
355            @Override
356            public void setExpandoBridgeAttributes(ServiceContext serviceContext) {
357                    ExpandoBridge expandoBridge = getExpandoBridge();
358    
359                    expandoBridge.setAttributes(serviceContext);
360            }
361    
362            @Override
363            public ResourceBlock toEscapedModel() {
364                    if (_escapedModel == null) {
365                            _escapedModel = (ResourceBlock)ProxyUtil.newProxyInstance(_classLoader,
366                                            _escapedModelInterfaces, new AutoEscapeBeanHandler(this));
367                    }
368    
369                    return _escapedModel;
370            }
371    
372            @Override
373            public Object clone() {
374                    ResourceBlockImpl resourceBlockImpl = new ResourceBlockImpl();
375    
376                    resourceBlockImpl.setResourceBlockId(getResourceBlockId());
377                    resourceBlockImpl.setCompanyId(getCompanyId());
378                    resourceBlockImpl.setGroupId(getGroupId());
379                    resourceBlockImpl.setName(getName());
380                    resourceBlockImpl.setPermissionsHash(getPermissionsHash());
381                    resourceBlockImpl.setReferenceCount(getReferenceCount());
382    
383                    resourceBlockImpl.resetOriginalValues();
384    
385                    return resourceBlockImpl;
386            }
387    
388            @Override
389            public int compareTo(ResourceBlock resourceBlock) {
390                    long primaryKey = resourceBlock.getPrimaryKey();
391    
392                    if (getPrimaryKey() < primaryKey) {
393                            return -1;
394                    }
395                    else if (getPrimaryKey() > primaryKey) {
396                            return 1;
397                    }
398                    else {
399                            return 0;
400                    }
401            }
402    
403            @Override
404            public boolean equals(Object obj) {
405                    if (this == obj) {
406                            return true;
407                    }
408    
409                    if (!(obj instanceof ResourceBlock)) {
410                            return false;
411                    }
412    
413                    ResourceBlock resourceBlock = (ResourceBlock)obj;
414    
415                    long primaryKey = resourceBlock.getPrimaryKey();
416    
417                    if (getPrimaryKey() == primaryKey) {
418                            return true;
419                    }
420                    else {
421                            return false;
422                    }
423            }
424    
425            @Override
426            public int hashCode() {
427                    return (int)getPrimaryKey();
428            }
429    
430            @Override
431            public void resetOriginalValues() {
432                    ResourceBlockModelImpl resourceBlockModelImpl = this;
433    
434                    resourceBlockModelImpl._originalCompanyId = resourceBlockModelImpl._companyId;
435    
436                    resourceBlockModelImpl._setOriginalCompanyId = false;
437    
438                    resourceBlockModelImpl._originalGroupId = resourceBlockModelImpl._groupId;
439    
440                    resourceBlockModelImpl._setOriginalGroupId = false;
441    
442                    resourceBlockModelImpl._originalName = resourceBlockModelImpl._name;
443    
444                    resourceBlockModelImpl._originalPermissionsHash = resourceBlockModelImpl._permissionsHash;
445    
446                    resourceBlockModelImpl._columnBitmask = 0;
447            }
448    
449            @Override
450            public CacheModel<ResourceBlock> toCacheModel() {
451                    ResourceBlockCacheModel resourceBlockCacheModel = new ResourceBlockCacheModel();
452    
453                    resourceBlockCacheModel.resourceBlockId = getResourceBlockId();
454    
455                    resourceBlockCacheModel.companyId = getCompanyId();
456    
457                    resourceBlockCacheModel.groupId = getGroupId();
458    
459                    resourceBlockCacheModel.name = getName();
460    
461                    String name = resourceBlockCacheModel.name;
462    
463                    if ((name != null) && (name.length() == 0)) {
464                            resourceBlockCacheModel.name = null;
465                    }
466    
467                    resourceBlockCacheModel.permissionsHash = getPermissionsHash();
468    
469                    String permissionsHash = resourceBlockCacheModel.permissionsHash;
470    
471                    if ((permissionsHash != null) && (permissionsHash.length() == 0)) {
472                            resourceBlockCacheModel.permissionsHash = null;
473                    }
474    
475                    resourceBlockCacheModel.referenceCount = getReferenceCount();
476    
477                    return resourceBlockCacheModel;
478            }
479    
480            @Override
481            public String toString() {
482                    StringBundler sb = new StringBundler(13);
483    
484                    sb.append("{resourceBlockId=");
485                    sb.append(getResourceBlockId());
486                    sb.append(", companyId=");
487                    sb.append(getCompanyId());
488                    sb.append(", groupId=");
489                    sb.append(getGroupId());
490                    sb.append(", name=");
491                    sb.append(getName());
492                    sb.append(", permissionsHash=");
493                    sb.append(getPermissionsHash());
494                    sb.append(", referenceCount=");
495                    sb.append(getReferenceCount());
496                    sb.append("}");
497    
498                    return sb.toString();
499            }
500    
501            @Override
502            public String toXmlString() {
503                    StringBundler sb = new StringBundler(22);
504    
505                    sb.append("<model><model-name>");
506                    sb.append("com.liferay.portal.model.ResourceBlock");
507                    sb.append("</model-name>");
508    
509                    sb.append(
510                            "<column><column-name>resourceBlockId</column-name><column-value><![CDATA[");
511                    sb.append(getResourceBlockId());
512                    sb.append("]]></column-value></column>");
513                    sb.append(
514                            "<column><column-name>companyId</column-name><column-value><![CDATA[");
515                    sb.append(getCompanyId());
516                    sb.append("]]></column-value></column>");
517                    sb.append(
518                            "<column><column-name>groupId</column-name><column-value><![CDATA[");
519                    sb.append(getGroupId());
520                    sb.append("]]></column-value></column>");
521                    sb.append(
522                            "<column><column-name>name</column-name><column-value><![CDATA[");
523                    sb.append(getName());
524                    sb.append("]]></column-value></column>");
525                    sb.append(
526                            "<column><column-name>permissionsHash</column-name><column-value><![CDATA[");
527                    sb.append(getPermissionsHash());
528                    sb.append("]]></column-value></column>");
529                    sb.append(
530                            "<column><column-name>referenceCount</column-name><column-value><![CDATA[");
531                    sb.append(getReferenceCount());
532                    sb.append("]]></column-value></column>");
533    
534                    sb.append("</model>");
535    
536                    return sb.toString();
537            }
538    
539            private static ClassLoader _classLoader = ResourceBlock.class.getClassLoader();
540            private static Class<?>[] _escapedModelInterfaces = new Class[] {
541                            ResourceBlock.class
542                    };
543            private long _resourceBlockId;
544            private long _companyId;
545            private long _originalCompanyId;
546            private boolean _setOriginalCompanyId;
547            private long _groupId;
548            private long _originalGroupId;
549            private boolean _setOriginalGroupId;
550            private String _name;
551            private String _originalName;
552            private String _permissionsHash;
553            private String _originalPermissionsHash;
554            private long _referenceCount;
555            private long _columnBitmask;
556            private ResourceBlock _escapedModel;
557    }