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.counter.model.impl;
16  
17  import com.liferay.counter.model.Counter;
18  import com.liferay.counter.model.CounterSoap;
19  
20  import com.liferay.portal.kernel.bean.AutoEscapeBeanHandler;
21  import com.liferay.portal.kernel.util.GetterUtil;
22  import com.liferay.portal.kernel.util.StringBundler;
23  import com.liferay.portal.kernel.util.StringPool;
24  import com.liferay.portal.model.impl.BaseModelImpl;
25  
26  import java.io.Serializable;
27  
28  import java.lang.reflect.Proxy;
29  
30  import java.sql.Types;
31  
32  import java.util.ArrayList;
33  import java.util.List;
34  
35  /**
36   * <a href="CounterModelImpl.java.html"><b><i>View Source</i></b></a>
37   *
38   * <p>
39   * ServiceBuilder generated this class. Modifications in this class will be
40   * overwritten the next time is generated.
41   * </p>
42   *
43   * <p>
44   * This interface is a model that represents the Counter table in the
45   * database.
46   * </p>
47   *
48   * @author    Brian Wing Shun Chan
49   * @see       CounterImpl
50   * @see       com.liferay.counter.model.Counter
51   * @see       com.liferay.counter.model.CounterModel
52   * @generated
53   */
54  public class CounterModelImpl extends BaseModelImpl<Counter> {
55      public static final String TABLE_NAME = "Counter";
56      public static final Object[][] TABLE_COLUMNS = {
57              { "name", new Integer(Types.VARCHAR) },
58              { "currentId", new Integer(Types.BIGINT) }
59          };
60      public static final String TABLE_SQL_CREATE = "create table Counter (name VARCHAR(75) not null primary key,currentId LONG)";
61      public static final String TABLE_SQL_DROP = "drop table Counter";
62      public static final String DATA_SOURCE = "liferayDataSource";
63      public static final String SESSION_FACTORY = "liferaySessionFactory";
64      public static final String TX_MANAGER = "liferayTransactionManager";
65      public static final boolean ENTITY_CACHE_ENABLED = GetterUtil.getBoolean(com.liferay.portal.util.PropsUtil.get(
66                  "value.object.entity.cache.enabled.com.liferay.counter.model.Counter"),
67              false);
68      public static final boolean FINDER_CACHE_ENABLED = GetterUtil.getBoolean(com.liferay.portal.util.PropsUtil.get(
69                  "value.object.finder.cache.enabled.com.liferay.counter.model.Counter"),
70              false);
71  
72      public static Counter toModel(CounterSoap soapModel) {
73          Counter model = new CounterImpl();
74  
75          model.setName(soapModel.getName());
76          model.setCurrentId(soapModel.getCurrentId());
77  
78          return model;
79      }
80  
81      public static List<Counter> toModels(CounterSoap[] soapModels) {
82          List<Counter> models = new ArrayList<Counter>(soapModels.length);
83  
84          for (CounterSoap soapModel : soapModels) {
85              models.add(toModel(soapModel));
86          }
87  
88          return models;
89      }
90  
91      public static final long LOCK_EXPIRATION_TIME = GetterUtil.getLong(com.liferay.portal.util.PropsUtil.get(
92                  "lock.expiration.time.com.liferay.counter.model.Counter"));
93  
94      public CounterModelImpl() {
95      }
96  
97      public String getPrimaryKey() {
98          return _name;
99      }
100 
101     public void setPrimaryKey(String pk) {
102         setName(pk);
103     }
104 
105     public Serializable getPrimaryKeyObj() {
106         return _name;
107     }
108 
109     public String getName() {
110         if (_name == null) {
111             return StringPool.BLANK;
112         }
113         else {
114             return _name;
115         }
116     }
117 
118     public void setName(String name) {
119         _name = name;
120     }
121 
122     public long getCurrentId() {
123         return _currentId;
124     }
125 
126     public void setCurrentId(long currentId) {
127         _currentId = currentId;
128     }
129 
130     public Counter toEscapedModel() {
131         if (isEscapedModel()) {
132             return (Counter)this;
133         }
134         else {
135             return (Counter)Proxy.newProxyInstance(Counter.class.getClassLoader(),
136                 new Class[] { Counter.class }, new AutoEscapeBeanHandler(this));
137         }
138     }
139 
140     public Object clone() {
141         CounterImpl clone = new CounterImpl();
142 
143         clone.setName(getName());
144         clone.setCurrentId(getCurrentId());
145 
146         return clone;
147     }
148 
149     public int compareTo(Counter counter) {
150         String pk = counter.getPrimaryKey();
151 
152         return getPrimaryKey().compareTo(pk);
153     }
154 
155     public boolean equals(Object obj) {
156         if (obj == null) {
157             return false;
158         }
159 
160         Counter counter = null;
161 
162         try {
163             counter = (Counter)obj;
164         }
165         catch (ClassCastException cce) {
166             return false;
167         }
168 
169         String pk = counter.getPrimaryKey();
170 
171         if (getPrimaryKey().equals(pk)) {
172             return true;
173         }
174         else {
175             return false;
176         }
177     }
178 
179     public int hashCode() {
180         return getPrimaryKey().hashCode();
181     }
182 
183     public String toString() {
184         StringBundler sb = new StringBundler(5);
185 
186         sb.append("{name=");
187         sb.append(getName());
188         sb.append(", currentId=");
189         sb.append(getCurrentId());
190         sb.append("}");
191 
192         return sb.toString();
193     }
194 
195     public String toXmlString() {
196         StringBundler sb = new StringBundler(10);
197 
198         sb.append("<model><model-name>");
199         sb.append("com.liferay.counter.model.Counter");
200         sb.append("</model-name>");
201 
202         sb.append(
203             "<column><column-name>name</column-name><column-value><![CDATA[");
204         sb.append(getName());
205         sb.append("]]></column-value></column>");
206         sb.append(
207             "<column><column-name>currentId</column-name><column-value><![CDATA[");
208         sb.append(getCurrentId());
209         sb.append("]]></column-value></column>");
210 
211         sb.append("</model>");
212 
213         return sb.toString();
214     }
215 
216     private String _name;
217     private long _currentId;
218 }