001: /*
002: * Copyright 2001-2007 Geert Bevin <gbevin[remove] at uwyn dot com>
003: * Distributed under the terms of either:
004: * - the common development and distribution license (CDDL), v1.0; or
005: * - the GNU Lesser General Public License, v2.1 or later
006: * $Id: BeanImplConstrained.java 3634 2007-01-08 21:42:24Z gbevin $
007: */
008: package com.uwyn.rife.database;
009:
010: import com.uwyn.rife.site.ConstrainedBean;
011: import com.uwyn.rife.site.ConstrainedProperty;
012: import com.uwyn.rife.site.Validation;
013: import java.math.BigDecimal;
014: import java.sql.Time;
015: import java.sql.Timestamp;
016: import java.util.Calendar;
017:
018: public class BeanImplConstrained extends Validation {
019: private String mPropertyString = null;
020: private StringBuffer mPropertyStringbuffer = null;
021: private java.util.Date mPropertyDate = null;
022: private java.util.Calendar mPropertyCalendar = null;
023: private java.sql.Date mPropertySqlDate = null;
024: private java.sql.Time mPropertyTime = null;
025: private java.sql.Timestamp mPropertyTimestamp = null;
026: private char mPropertyChar = 0;
027: private Character mPropertyCharacterObject = null;
028: private boolean mPropertyBoolean = false;
029: private Boolean mPropertyBooleanObject = null;
030: private byte mPropertyByte = 0;
031: private Byte mPropertyByteObject = null;
032: private double mPropertyDouble = 0.0d;
033: private Double mPropertyDoubleObject = null;
034: private float mPropertyFloat = 0.0f;
035: private Float mPropertyFloatObject = null;
036: private int mPropertyInt = 0;
037: private Integer mPropertyIntegerObject = null;
038: private long mPropertyLong = 0;
039: private Long mPropertyLongObject = null;
040: private short mPropertyShort = 0;
041: private Short mPropertyShortObject = null;
042: private BigDecimal mPropertyBigDecimal = null;
043:
044: public BeanImplConstrained() {
045: }
046:
047: protected void activateValidation() {
048: addConstraint(new ConstrainedBean().unique(
049: "propertyStringbuffer", "propertyByteObject")
050: .defaultOrder("propertyString").defaultOrder(
051: "propertyInt", ConstrainedBean.DESC));
052:
053: addConstraint(new ConstrainedProperty("propertyString")
054: .identifier(true).maxLength(30).inList(
055: new String[] { "one", "tw''o",
056: "someotherstring" })
057: .defaultValue("one"));
058: addConstraint(new ConstrainedProperty("propertyStringbuffer")
059: .maxLength(20).unique(true).notEmpty(true)
060: .notNull(true).notEqual("some'blurp"));
061: addConstraint(new ConstrainedProperty("propertyInt").notEmpty(
062: true).defaultValue(23));
063: addConstraint(new ConstrainedProperty("propertyByteObject")
064: .notEqual(-1).notNull(true));
065: addConstraint(new ConstrainedProperty("propertyLongObject")
066: .inList(new String[] { "89", "1221", "66875", "878" }));
067: addConstraint(new ConstrainedProperty("propertyBigDecimal")
068: .precision(17).scale(6));
069: addConstraint(new ConstrainedProperty("propertyShortObject")
070: .sameAs("propertyShort"));
071: addConstraint(new ConstrainedProperty("propertyByte")
072: .saved(false));
073: addConstraint(new ConstrainedProperty("propertyLong")
074: .persistent(false));
075: }
076:
077: public String getPropertyString() {
078: return mPropertyString;
079: }
080:
081: public void setPropertyString(String propertyString) {
082: mPropertyString = propertyString;
083: }
084:
085: public StringBuffer getPropertyStringbuffer() {
086: return mPropertyStringbuffer;
087: }
088:
089: public void setPropertyStringbuffer(
090: StringBuffer propertyStringbuffer) {
091: mPropertyStringbuffer = propertyStringbuffer;
092: }
093:
094: public java.util.Date getPropertyDate() {
095: return mPropertyDate;
096: }
097:
098: public void setPropertyDate(java.util.Date propertyDate) {
099: mPropertyDate = propertyDate;
100: }
101:
102: public java.util.Calendar getPropertyCalendar() {
103: return mPropertyCalendar;
104: }
105:
106: public void setPropertyCalendar(java.util.Calendar propertyCalendar) {
107: mPropertyCalendar = propertyCalendar;
108: }
109:
110: public java.sql.Date getPropertySqlDate() {
111: return mPropertySqlDate;
112: }
113:
114: public void setPropertySqlDate(java.sql.Date propertySqlDate) {
115: mPropertySqlDate = propertySqlDate;
116: }
117:
118: public java.sql.Time getPropertyTime() {
119: return mPropertyTime;
120: }
121:
122: public void setPropertyTime(java.sql.Time propertyTime) {
123: mPropertyTime = propertyTime;
124: }
125:
126: public java.sql.Timestamp getPropertyTimestamp() {
127: return mPropertyTimestamp;
128: }
129:
130: public void setPropertyTimestamp(
131: java.sql.Timestamp propertyTimestamp) {
132: mPropertyTimestamp = propertyTimestamp;
133: }
134:
135: public boolean isPropertyBoolean() {
136: return mPropertyBoolean;
137: }
138:
139: public void setPropertyBoolean(boolean propertyBoolean) {
140: mPropertyBoolean = propertyBoolean;
141: }
142:
143: public Boolean getPropertyBooleanObject() {
144: return mPropertyBooleanObject;
145: }
146:
147: public void setPropertyBooleanObject(Boolean propertyBooleanObject) {
148: mPropertyBooleanObject = propertyBooleanObject;
149: }
150:
151: public byte getPropertyByte() {
152: return mPropertyByte;
153: }
154:
155: public Byte getPropertyByteObject() {
156: return mPropertyByteObject;
157: }
158:
159: public void setPropertyByte(byte propertyByte) {
160: mPropertyByte = propertyByte;
161: }
162:
163: public void setPropertyByteObject(Byte propertyByteObject) {
164: mPropertyByteObject = propertyByteObject;
165: }
166:
167: public double getPropertyDouble() {
168: return mPropertyDouble;
169: }
170:
171: public void setPropertyDouble(double propertyDouble) {
172: mPropertyDouble = propertyDouble;
173: }
174:
175: public void setPropertyDoubleObject(Double propertyDoubleObject) {
176: mPropertyDoubleObject = propertyDoubleObject;
177: }
178:
179: public Double getPropertyDoubleObject() {
180: return mPropertyDoubleObject;
181: }
182:
183: public float getPropertyFloat() {
184: return mPropertyFloat;
185: }
186:
187: public void setPropertyFloat(float propertyFloat) {
188: mPropertyFloat = propertyFloat;
189: }
190:
191: public void setPropertyFloatObject(Float propertyFloatObject) {
192: mPropertyFloatObject = propertyFloatObject;
193: }
194:
195: public Float getPropertyFloatObject() {
196: return mPropertyFloatObject;
197: }
198:
199: public int getPropertyInt() {
200: return mPropertyInt;
201: }
202:
203: public void setPropertyInt(int propertyInt) {
204: mPropertyInt = propertyInt;
205: }
206:
207: public Integer getPropertyIntegerObject() {
208: return mPropertyIntegerObject;
209: }
210:
211: public void setPropertyIntegerObject(Integer propertyIntegerObject) {
212: mPropertyIntegerObject = propertyIntegerObject;
213: }
214:
215: public long getPropertyLong() {
216: return mPropertyLong;
217: }
218:
219: public void setPropertyLong(long propertyLong) {
220: mPropertyLong = propertyLong;
221: }
222:
223: public Long getPropertyLongObject() {
224: return mPropertyLongObject;
225: }
226:
227: public void setPropertyLongObject(Long propertyLongObject) {
228: mPropertyLongObject = propertyLongObject;
229: }
230:
231: public short getPropertyShort() {
232: return mPropertyShort;
233: }
234:
235: public void setPropertyShort(short propertyShort) {
236: mPropertyShort = propertyShort;
237: }
238:
239: public Short getPropertyShortObject() {
240: return mPropertyShortObject;
241: }
242:
243: public void setPropertyShortObject(Short propertyShortObject) {
244: mPropertyShortObject = propertyShortObject;
245: }
246:
247: public char getPropertyChar() {
248: return mPropertyChar;
249: }
250:
251: public void setPropertyChar(char propertyChar) {
252: mPropertyChar = propertyChar;
253: }
254:
255: public Character getPropertyCharacterObject() {
256: return mPropertyCharacterObject;
257: }
258:
259: public void setPropertyCharacterObject(
260: Character propertyCharacterObject) {
261: mPropertyCharacterObject = propertyCharacterObject;
262: }
263:
264: public BigDecimal getPropertyBigDecimal() {
265: return mPropertyBigDecimal;
266: }
267:
268: public void setPropertyBigDecimal(BigDecimal propertyBigDecimal) {
269: mPropertyBigDecimal = propertyBigDecimal;
270: }
271:
272: public static BeanImplConstrained getPopulatedBean() {
273: BeanImplConstrained bean = new BeanImplConstrained();
274: Calendar cal = Calendar.getInstance();
275: cal.set(2002, 5, 18, 15, 26, 14);
276: cal.set(Calendar.MILLISECOND, 764);
277: bean.setPropertyBigDecimal(new BigDecimal("219038743.392874"));
278: bean.setPropertyBoolean(true);
279: bean.setPropertyBooleanObject(false);
280: bean.setPropertyByte((byte) 89);
281: bean.setPropertyByteObject((byte) 34);
282: bean.setPropertyCalendar(cal);
283: bean.setPropertyChar('v');
284: bean.setPropertyCharacterObject('r');
285: bean.setPropertyDate(cal.getTime());
286: bean.setPropertyDouble(53348.34d);
287: bean.setPropertyDoubleObject(143298.692d);
288: bean.setPropertyFloat(98634.2f);
289: bean.setPropertyFloatObject(8734.7f);
290: bean.setPropertyInt(545);
291: bean.setPropertyIntegerObject(968);
292: bean.setPropertyLong(34563L);
293: bean.setPropertyLongObject(66875L);
294: bean.setPropertyShort((short) 43);
295: bean.setPropertyShortObject((short) 68);
296: bean.setPropertySqlDate(new java.sql.Date(cal.getTime()
297: .getTime()));
298: bean.setPropertyString("someotherstring");
299: bean.setPropertyStringbuffer(new StringBuffer(
300: "someotherstringbuff"));
301: bean.setPropertyTime(new Time(cal.getTime().getTime()));
302: bean
303: .setPropertyTimestamp(new Timestamp(cal.getTime()
304: .getTime()));
305:
306: return bean;
307: }
308:
309: public static BeanImplConstrained getNullBean() {
310: BeanImplConstrained bean = new BeanImplConstrained();
311: bean.setPropertyBigDecimal(null);
312: bean.setPropertyBoolean(false);
313: bean.setPropertyBooleanObject(false);
314: bean.setPropertyByte((byte) 0);
315: bean.setPropertyByteObject((byte) 0);
316: bean.setPropertyDate(null);
317: bean.setPropertyCalendar(null);
318: bean.setPropertyChar((char) 0);
319: bean.setPropertyCharacterObject(null);
320: bean.setPropertyDouble(0d);
321: bean.setPropertyDoubleObject(0d);
322: bean.setPropertyFloat(0f);
323: bean.setPropertyFloatObject(0f);
324: bean.setPropertyInt(0);
325: bean.setPropertyIntegerObject(0);
326: bean.setPropertyLong(0L);
327: bean.setPropertyLongObject(0L);
328: bean.setPropertyShort((short) 0);
329: bean.setPropertyShortObject((short) 0);
330: bean.setPropertySqlDate(null);
331: bean.setPropertyString(null);
332: bean.setPropertyStringbuffer(null);
333: bean.setPropertyTime(null);
334: bean.setPropertyTimestamp(null);
335:
336: return bean;
337: }
338: }
|