001    /**
002     * Copyright (c) 2000-2010 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.util.GetterUtil;
019    import com.liferay.portal.kernel.util.StringBundler;
020    import com.liferay.portal.kernel.util.StringPool;
021    import com.liferay.portal.model.Resource;
022    import com.liferay.portal.model.ResourceModel;
023    import com.liferay.portal.model.ResourceSoap;
024    import com.liferay.portal.service.ServiceContext;
025    
026    import com.liferay.portlet.expando.model.ExpandoBridge;
027    import com.liferay.portlet.expando.util.ExpandoBridgeFactoryUtil;
028    
029    import java.io.Serializable;
030    
031    import java.lang.reflect.Proxy;
032    
033    import java.sql.Types;
034    
035    import java.util.ArrayList;
036    import java.util.List;
037    
038    /**
039     * The base model implementation for the Resource service. Represents a row in the "Resource_" database table, with each column mapped to a property of this class.
040     *
041     * <p>
042     * This implementation and its corresponding interface {@link com.liferay.portal.model.ResourceModel} exist only as a container for the default property accessors generated by ServiceBuilder. Helper methods and all application logic should be put in {@link ResourceImpl}.
043     * </p>
044     *
045     * <p>
046     * Never modify or reference this class directly. All methods that expect a resource model instance should use the {@link com.liferay.portal.model.Resource} interface instead.
047     * </p>
048     *
049     * @author Brian Wing Shun Chan
050     * @see ResourceImpl
051     * @see com.liferay.portal.model.Resource
052     * @see com.liferay.portal.model.ResourceModel
053     * @generated
054     */
055    public class ResourceModelImpl extends BaseModelImpl<Resource>
056            implements ResourceModel {
057            public static final String TABLE_NAME = "Resource_";
058            public static final Object[][] TABLE_COLUMNS = {
059                            { "resourceId", new Integer(Types.BIGINT) },
060                            { "codeId", new Integer(Types.BIGINT) },
061                            { "primKey", new Integer(Types.VARCHAR) }
062                    };
063            public static final String TABLE_SQL_CREATE = "create table Resource_ (resourceId LONG not null primary key,codeId LONG,primKey VARCHAR(255) null)";
064            public static final String TABLE_SQL_DROP = "drop table Resource_";
065            public static final String DATA_SOURCE = "liferayDataSource";
066            public static final String SESSION_FACTORY = "liferaySessionFactory";
067            public static final String TX_MANAGER = "liferayTransactionManager";
068            public static final boolean ENTITY_CACHE_ENABLED = GetterUtil.getBoolean(com.liferay.portal.util.PropsUtil.get(
069                                    "value.object.entity.cache.enabled.com.liferay.portal.model.Resource"),
070                            true);
071            public static final boolean FINDER_CACHE_ENABLED = GetterUtil.getBoolean(com.liferay.portal.util.PropsUtil.get(
072                                    "value.object.finder.cache.enabled.com.liferay.portal.model.Resource"),
073                            true);
074    
075            /**
076             * Converts the soap model instance into a normal model instance.
077             *
078             * @param soapModel the soap model instance to convert
079             * @return the normal model instance
080             */
081            public static Resource toModel(ResourceSoap soapModel) {
082                    Resource model = new ResourceImpl();
083    
084                    model.setResourceId(soapModel.getResourceId());
085                    model.setCodeId(soapModel.getCodeId());
086                    model.setPrimKey(soapModel.getPrimKey());
087    
088                    return model;
089            }
090    
091            /**
092             * Converts the soap model instances into normal model instances.
093             *
094             * @param soapModels the soap model instances to convert
095             * @return the normal model instances
096             */
097            public static List<Resource> toModels(ResourceSoap[] soapModels) {
098                    List<Resource> models = new ArrayList<Resource>(soapModels.length);
099    
100                    for (ResourceSoap soapModel : soapModels) {
101                            models.add(toModel(soapModel));
102                    }
103    
104                    return models;
105            }
106    
107            public static final long LOCK_EXPIRATION_TIME = GetterUtil.getLong(com.liferay.portal.util.PropsUtil.get(
108                                    "lock.expiration.time.com.liferay.portal.model.Resource"));
109    
110            public ResourceModelImpl() {
111            }
112    
113            public long getPrimaryKey() {
114                    return _resourceId;
115            }
116    
117            public void setPrimaryKey(long pk) {
118                    setResourceId(pk);
119            }
120    
121            public Serializable getPrimaryKeyObj() {
122                    return new Long(_resourceId);
123            }
124    
125            public long getResourceId() {
126                    return _resourceId;
127            }
128    
129            public void setResourceId(long resourceId) {
130                    _resourceId = resourceId;
131            }
132    
133            public long getCodeId() {
134                    return _codeId;
135            }
136    
137            public void setCodeId(long codeId) {
138                    _codeId = codeId;
139    
140                    if (!_setOriginalCodeId) {
141                            _setOriginalCodeId = true;
142    
143                            _originalCodeId = codeId;
144                    }
145            }
146    
147            public long getOriginalCodeId() {
148                    return _originalCodeId;
149            }
150    
151            public String getPrimKey() {
152                    if (_primKey == null) {
153                            return StringPool.BLANK;
154                    }
155                    else {
156                            return _primKey;
157                    }
158            }
159    
160            public void setPrimKey(String primKey) {
161                    _primKey = primKey;
162    
163                    if (_originalPrimKey == null) {
164                            _originalPrimKey = primKey;
165                    }
166            }
167    
168            public String getOriginalPrimKey() {
169                    return GetterUtil.getString(_originalPrimKey);
170            }
171    
172            public Resource toEscapedModel() {
173                    if (isEscapedModel()) {
174                            return (Resource)this;
175                    }
176                    else {
177                            return (Resource)Proxy.newProxyInstance(Resource.class.getClassLoader(),
178                                    new Class[] { Resource.class }, new AutoEscapeBeanHandler(this));
179                    }
180            }
181    
182            public ExpandoBridge getExpandoBridge() {
183                    if (_expandoBridge == null) {
184                            _expandoBridge = ExpandoBridgeFactoryUtil.getExpandoBridge(0,
185                                            Resource.class.getName(), getPrimaryKey());
186                    }
187    
188                    return _expandoBridge;
189            }
190    
191            public void setExpandoBridgeAttributes(ServiceContext serviceContext) {
192                    getExpandoBridge().setAttributes(serviceContext);
193            }
194    
195            public Object clone() {
196                    ResourceImpl clone = new ResourceImpl();
197    
198                    clone.setResourceId(getResourceId());
199                    clone.setCodeId(getCodeId());
200                    clone.setPrimKey(getPrimKey());
201    
202                    return clone;
203            }
204    
205            public int compareTo(Resource resource) {
206                    long pk = resource.getPrimaryKey();
207    
208                    if (getPrimaryKey() < pk) {
209                            return -1;
210                    }
211                    else if (getPrimaryKey() > pk) {
212                            return 1;
213                    }
214                    else {
215                            return 0;
216                    }
217            }
218    
219            public boolean equals(Object obj) {
220                    if (obj == null) {
221                            return false;
222                    }
223    
224                    Resource resource = null;
225    
226                    try {
227                            resource = (Resource)obj;
228                    }
229                    catch (ClassCastException cce) {
230                            return false;
231                    }
232    
233                    long pk = resource.getPrimaryKey();
234    
235                    if (getPrimaryKey() == pk) {
236                            return true;
237                    }
238                    else {
239                            return false;
240                    }
241            }
242    
243            public int hashCode() {
244                    return (int)getPrimaryKey();
245            }
246    
247            public String toString() {
248                    StringBundler sb = new StringBundler(7);
249    
250                    sb.append("{resourceId=");
251                    sb.append(getResourceId());
252                    sb.append(", codeId=");
253                    sb.append(getCodeId());
254                    sb.append(", primKey=");
255                    sb.append(getPrimKey());
256                    sb.append("}");
257    
258                    return sb.toString();
259            }
260    
261            public String toXmlString() {
262                    StringBundler sb = new StringBundler(13);
263    
264                    sb.append("<model><model-name>");
265                    sb.append("com.liferay.portal.model.Resource");
266                    sb.append("</model-name>");
267    
268                    sb.append(
269                            "<column><column-name>resourceId</column-name><column-value><![CDATA[");
270                    sb.append(getResourceId());
271                    sb.append("]]></column-value></column>");
272                    sb.append(
273                            "<column><column-name>codeId</column-name><column-value><![CDATA[");
274                    sb.append(getCodeId());
275                    sb.append("]]></column-value></column>");
276                    sb.append(
277                            "<column><column-name>primKey</column-name><column-value><![CDATA[");
278                    sb.append(getPrimKey());
279                    sb.append("]]></column-value></column>");
280    
281                    sb.append("</model>");
282    
283                    return sb.toString();
284            }
285    
286            private long _resourceId;
287            private long _codeId;
288            private long _originalCodeId;
289            private boolean _setOriginalCodeId;
290            private String _primKey;
291            private String _originalPrimKey;
292            private transient ExpandoBridge _expandoBridge;
293    }