1   /**
2    * Copyright (c) 2000-2010 Liferay, Inc. All rights reserved.
3    *
4    * This library is free software; you can redistribute it and/or modify it under
5    * the terms of the GNU Lesser General Public License as published by the Free
6    * Software Foundation; either version 2.1 of the License, or (at your option)
7    * any later version.
8    *
9    * This library is distributed in the hope that it will be useful, but WITHOUT
10   * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
11   * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
12   * details.
13   */
14  
15  package com.liferay.portal.model.impl;
16  
17  import com.liferay.portal.kernel.bean.ReadOnlyBeanHandler;
18  import com.liferay.portal.kernel.util.GetterUtil;
19  import com.liferay.portal.kernel.util.HtmlUtil;
20  import com.liferay.portal.kernel.util.StringBundler;
21  import com.liferay.portal.kernel.util.StringPool;
22  import com.liferay.portal.model.Shard;
23  import com.liferay.portal.model.ShardSoap;
24  import com.liferay.portal.service.ServiceContext;
25  import com.liferay.portal.util.PortalUtil;
26  
27  import com.liferay.portlet.expando.model.ExpandoBridge;
28  import com.liferay.portlet.expando.util.ExpandoBridgeFactoryUtil;
29  
30  import java.io.Serializable;
31  
32  import java.lang.reflect.Proxy;
33  
34  import java.sql.Types;
35  
36  import java.util.ArrayList;
37  import java.util.List;
38  
39  /**
40   * <a href="ShardModelImpl.java.html"><b><i>View Source</i></b></a>
41   *
42   * <p>
43   * ServiceBuilder generated this class. Modifications in this class will be
44   * overwritten the next time is generated.
45   * </p>
46   *
47   * <p>
48   * This interface is a model that represents the Shard table in the
49   * database.
50   * </p>
51   *
52   * @author    Brian Wing Shun Chan
53   * @see       ShardImpl
54   * @see       com.liferay.portal.model.Shard
55   * @see       com.liferay.portal.model.ShardModel
56   * @generated
57   */
58  public class ShardModelImpl extends BaseModelImpl<Shard> {
59      public static final String TABLE_NAME = "Shard";
60      public static final Object[][] TABLE_COLUMNS = {
61              { "shardId", new Integer(Types.BIGINT) },
62              { "classNameId", new Integer(Types.BIGINT) },
63              { "classPK", new Integer(Types.BIGINT) },
64              { "name", new Integer(Types.VARCHAR) }
65          };
66      public static final String TABLE_SQL_CREATE = "create table Shard (shardId LONG not null primary key,classNameId LONG,classPK LONG,name VARCHAR(75) null)";
67      public static final String TABLE_SQL_DROP = "drop table Shard";
68      public static final String DATA_SOURCE = "liferayDataSource";
69      public static final String SESSION_FACTORY = "liferaySessionFactory";
70      public static final String TX_MANAGER = "liferayTransactionManager";
71      public static final boolean ENTITY_CACHE_ENABLED = GetterUtil.getBoolean(com.liferay.portal.util.PropsUtil.get(
72                  "value.object.entity.cache.enabled.com.liferay.portal.model.Shard"),
73              true);
74      public static final boolean FINDER_CACHE_ENABLED = GetterUtil.getBoolean(com.liferay.portal.util.PropsUtil.get(
75                  "value.object.finder.cache.enabled.com.liferay.portal.model.Shard"),
76              true);
77  
78      public static Shard toModel(ShardSoap soapModel) {
79          Shard model = new ShardImpl();
80  
81          model.setShardId(soapModel.getShardId());
82          model.setClassNameId(soapModel.getClassNameId());
83          model.setClassPK(soapModel.getClassPK());
84          model.setName(soapModel.getName());
85  
86          return model;
87      }
88  
89      public static List<Shard> toModels(ShardSoap[] soapModels) {
90          List<Shard> models = new ArrayList<Shard>(soapModels.length);
91  
92          for (ShardSoap soapModel : soapModels) {
93              models.add(toModel(soapModel));
94          }
95  
96          return models;
97      }
98  
99      public static final long LOCK_EXPIRATION_TIME = GetterUtil.getLong(com.liferay.portal.util.PropsUtil.get(
100                 "lock.expiration.time.com.liferay.portal.model.Shard"));
101 
102     public ShardModelImpl() {
103     }
104 
105     public long getPrimaryKey() {
106         return _shardId;
107     }
108 
109     public void setPrimaryKey(long pk) {
110         setShardId(pk);
111     }
112 
113     public Serializable getPrimaryKeyObj() {
114         return new Long(_shardId);
115     }
116 
117     public long getShardId() {
118         return _shardId;
119     }
120 
121     public void setShardId(long shardId) {
122         _shardId = shardId;
123     }
124 
125     public String getClassName() {
126         if (getClassNameId() <= 0) {
127             return StringPool.BLANK;
128         }
129 
130         return PortalUtil.getClassName(getClassNameId());
131     }
132 
133     public long getClassNameId() {
134         return _classNameId;
135     }
136 
137     public void setClassNameId(long classNameId) {
138         _classNameId = classNameId;
139 
140         if (!_setOriginalClassNameId) {
141             _setOriginalClassNameId = true;
142 
143             _originalClassNameId = classNameId;
144         }
145     }
146 
147     public long getOriginalClassNameId() {
148         return _originalClassNameId;
149     }
150 
151     public long getClassPK() {
152         return _classPK;
153     }
154 
155     public void setClassPK(long classPK) {
156         _classPK = classPK;
157 
158         if (!_setOriginalClassPK) {
159             _setOriginalClassPK = true;
160 
161             _originalClassPK = classPK;
162         }
163     }
164 
165     public long getOriginalClassPK() {
166         return _originalClassPK;
167     }
168 
169     public String getName() {
170         return GetterUtil.getString(_name);
171     }
172 
173     public void setName(String name) {
174         _name = name;
175 
176         if (_originalName == null) {
177             _originalName = name;
178         }
179     }
180 
181     public String getOriginalName() {
182         return GetterUtil.getString(_originalName);
183     }
184 
185     public Shard toEscapedModel() {
186         if (isEscapedModel()) {
187             return (Shard)this;
188         }
189         else {
190             Shard model = new ShardImpl();
191 
192             model.setNew(isNew());
193             model.setEscapedModel(true);
194 
195             model.setShardId(getShardId());
196             model.setClassNameId(getClassNameId());
197             model.setClassPK(getClassPK());
198             model.setName(HtmlUtil.escape(getName()));
199 
200             model = (Shard)Proxy.newProxyInstance(Shard.class.getClassLoader(),
201                     new Class[] { Shard.class }, new ReadOnlyBeanHandler(model));
202 
203             return model;
204         }
205     }
206 
207     public ExpandoBridge getExpandoBridge() {
208         if (_expandoBridge == null) {
209             _expandoBridge = ExpandoBridgeFactoryUtil.getExpandoBridge(0,
210                     Shard.class.getName(), getPrimaryKey());
211         }
212 
213         return _expandoBridge;
214     }
215 
216     public void setExpandoBridgeAttributes(ServiceContext serviceContext) {
217         getExpandoBridge().setAttributes(serviceContext);
218     }
219 
220     public Object clone() {
221         ShardImpl clone = new ShardImpl();
222 
223         clone.setShardId(getShardId());
224         clone.setClassNameId(getClassNameId());
225         clone.setClassPK(getClassPK());
226         clone.setName(getName());
227 
228         return clone;
229     }
230 
231     public int compareTo(Shard shard) {
232         long pk = shard.getPrimaryKey();
233 
234         if (getPrimaryKey() < pk) {
235             return -1;
236         }
237         else if (getPrimaryKey() > pk) {
238             return 1;
239         }
240         else {
241             return 0;
242         }
243     }
244 
245     public boolean equals(Object obj) {
246         if (obj == null) {
247             return false;
248         }
249 
250         Shard shard = null;
251 
252         try {
253             shard = (Shard)obj;
254         }
255         catch (ClassCastException cce) {
256             return false;
257         }
258 
259         long pk = shard.getPrimaryKey();
260 
261         if (getPrimaryKey() == pk) {
262             return true;
263         }
264         else {
265             return false;
266         }
267     }
268 
269     public int hashCode() {
270         return (int)getPrimaryKey();
271     }
272 
273     public String toString() {
274         StringBundler sb = new StringBundler(9);
275 
276         sb.append("{shardId=");
277         sb.append(getShardId());
278         sb.append(", classNameId=");
279         sb.append(getClassNameId());
280         sb.append(", classPK=");
281         sb.append(getClassPK());
282         sb.append(", name=");
283         sb.append(getName());
284         sb.append("}");
285 
286         return sb.toString();
287     }
288 
289     public String toXmlString() {
290         StringBundler sb = new StringBundler(16);
291 
292         sb.append("<model><model-name>");
293         sb.append("com.liferay.portal.model.Shard");
294         sb.append("</model-name>");
295 
296         sb.append(
297             "<column><column-name>shardId</column-name><column-value><![CDATA[");
298         sb.append(getShardId());
299         sb.append("]]></column-value></column>");
300         sb.append(
301             "<column><column-name>classNameId</column-name><column-value><![CDATA[");
302         sb.append(getClassNameId());
303         sb.append("]]></column-value></column>");
304         sb.append(
305             "<column><column-name>classPK</column-name><column-value><![CDATA[");
306         sb.append(getClassPK());
307         sb.append("]]></column-value></column>");
308         sb.append(
309             "<column><column-name>name</column-name><column-value><![CDATA[");
310         sb.append(getName());
311         sb.append("]]></column-value></column>");
312 
313         sb.append("</model>");
314 
315         return sb.toString();
316     }
317 
318     private long _shardId;
319     private long _classNameId;
320     private long _originalClassNameId;
321     private boolean _setOriginalClassNameId;
322     private long _classPK;
323     private long _originalClassPK;
324     private boolean _setOriginalClassPK;
325     private String _name;
326     private String _originalName;
327     private transient ExpandoBridge _expandoBridge;
328 }