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