1   // 
2   //Copyright (c) 2003, Caltha - Gajda, Krzewski, Mach, Potempski Sp.J. 
3   //All rights reserved. 
4   //   
5   //Redistribution and use in source and binary forms, with or without modification,  
6   //are permitted provided that the following conditions are met: 
7   //   
8   //* Redistributions of source code must retain the above copyright notice,  
9   //this list of conditions and the following disclaimer. 
10  //* Redistributions in binary form must reproduce the above copyright notice,  
11  //this list of conditions and the following disclaimer in the documentation  
12  //and/or other materials provided with the distribution. 
13  //* Neither the name of the Caltha - Gajda, Krzewski, Mach, Potempski Sp.J.  
14  //nor the names of its contributors may be used to endorse or promote products  
15  //derived from this software without specific prior written permission. 
16  // 
17  //THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"  
18  //AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED  
19  //WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 
20  //IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,  
21  //INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,  
22  //BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, 
23  //OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,  
24  //WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)  
25  //ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE  
26  //POSSIBILITY OF SUCH DAMAGE. 
27  //
28  
29  package org.objectledge.database.persistence;
30  
31  import java.math.BigDecimal;
32  import java.util.Date;
33  
34  /**
35   * @author <a href="mailto:pablo@caltha.pl">Pawel Potempski</a>
36   *
37   * To change the template for this generated type comment go to
38   * Window&gt;Preferences&gt;Java&gt;Code Generation&gt;Code and Comments
39   */
40  public class TestObject implements Persistent
41  {
42      private long id;
43      
44      private String value;
45      
46      private Date date;
47  
48      private boolean valueBoolean;
49      
50      private float valueFloat;
51      
52      private BigDecimal valueDecimal;
53      
54      private Date valueTime;
55      
56      private Date valueTimestamp;
57      
58      private short valueShort;
59      
60      private byte valueByte;
61      
62      public TestObject()
63      {
64          this("",null);
65      }
66  
67      public TestObject(String value, Date date)
68      {
69          id = -1;
70          this.date = date;
71          this.value = value;
72      }
73      
74  
75      /***
76       * {@inheritDoc}
77       */
78      public String getTable()
79      {
80          return "test_object";
81      }
82  
83      /***
84       * {@inheritDoc}
85       */
86      public String[] getKeyColumns()
87      {
88          return new String[]{"id"};
89      }
90  
91      /***
92       * {@inheritDoc}
93       */
94      public void getData(OutputRecord record) throws PersistenceException
95      {
96          record.setLong("id", id);
97          record.setString("value", value);
98          record.setDate("date",date);
99          record.setBoolean("value_boolean",valueBoolean);
100         record.setFloat("value_float",valueFloat);
101         record.setBigDecimal("value_decimal",valueDecimal);
102         record.setTime("value_time",valueTime);
103         record.setTimestamp("value_timestamp",valueTimestamp);
104         record.setShort("value_short",valueShort);
105         record.setByte("value_byte",valueByte);
106     }
107 
108     /***
109      * {@inheritDoc}
110      */
111     public void setData(InputRecord record) throws PersistenceException
112     {
113         id = record.getLong("id");
114         value = record.getString("value");
115         date = record.getDate("date");
116         valueBoolean = record.getBoolean("value_boolean");
117         valueFloat = record.getFloat("value_float");
118         valueDecimal = record.getBigDecimal("value_decimal");
119         valueTime = record.getDate("value_time");
120         valueTimestamp = record.getDate("value_timestamp");
121         valueShort = record.getShort("value_short");
122         valueByte = record.getByte("value_byte");
123     }
124 
125     /***
126      * {@inheritDoc}
127      */
128     public boolean getSaved()
129     {
130         return (id != -1);
131     }
132 
133     /***
134      * {@inheritDoc}
135      */
136     public void setSaved(long id)
137     {
138         this.id = id;
139     }
140 
141     public long getId()
142     {
143         return id;
144     }
145     
146     public String getValue()
147     {
148         return value;
149     }
150     
151     public Date getDate()
152     {
153         return date;
154     }
155     
156     public void setDate(Date date)
157     {
158         this.date = date;
159     }
160     
161     public void setValue(String value)
162     {
163         this.value = value;
164     }
165 }