View Javadoc

1   /*
2    * Copyright (c) 2004-2005, University Health Network.  All rights reserved. Distributed under the BSD 
3    * license (see http://opensource.org/licenses/bsd-license.php).
4    *  
5    * DateWParamField.java
6    *
7    * Created on 15-Dec-2004 at 1:41:29 PM
8    */
9   package ca.uhn.cache.internal.hibernate.impl;
10  
11  import java.sql.Timestamp;
12  import java.util.Map;
13  
14  import org.apache.commons.lang.builder.EqualsBuilder;
15  import org.apache.commons.lang.builder.HashCodeBuilder;
16  import org.apache.commons.lang.builder.ToStringBuilder;
17  
18  import ca.uhn.cache.IDimension;
19  import ca.uhn.cache.IQueryParam;
20  import ca.uhn.cache.impl.DateParam;
21  import ca.uhn.cache.internal.util.TimestampUtils;
22  
23  /***
24   * Hibernate persistable object with xdoclet annotations for <code>DateParam</code>. 
25   * 
26   * @author <a href="mailto:alexei.guevara@uhn.on.ca">Alexei Guevara</a>
27   * @version $Revision: 1.1 $ updated on $Date: 2005/01/24 22:52:40 $ by $Author: bryan_tripp $
28   * 
29   * @hibernate.joined-subclass table="date_param_field"
30   * @hibernate.joined-subclass-key column="date_param_field_id"
31   */
32  public class DateParamField extends Field {
33      
34      private Timestamp myValue;
35      
36      /***
37       * Constructs a <code>DateParamField</code> from a source <code>DateParam</code>.
38       * 
39       * @param theRecord The record this field belongs to.
40       * @param theParam The source <code>DateParam</code>.
41       */
42      public DateParamField( Record theRecord, DateParam theParam ) {
43          super( theRecord, theParam.getDimension().getName() );
44          setValue( TimestampUtils.dateToTimestamp( theParam.getValue() ) );
45      }
46      
47      /***
48       */
49      public DateParamField() {
50          super( null, null );
51      }
52  
53      /***
54       * @return Returns the value.
55       * 
56       * @hibernate.property not-null="true" type="timestamp"
57       */
58      public Timestamp getValue() {
59          return myValue;
60      }
61      /***
62       * @param theValue The value to set.
63       */
64      public void setValue( Timestamp theValue ) {
65          myValue = theValue;
66      }
67  
68      /***
69       * {@inheritDoc}
70       */
71      public IQueryParam toQueryParam( Map theDimensionNameToDimensionMap ) {
72          return new DateParam( 
73                  (IDimension) theDimensionNameToDimensionMap.get( getDimensionName() ), 
74                  TimestampUtils.timestampToDate( getValue() ) );
75      }
76      
77      /***
78       * {@inheritDoc}
79       */
80      public int hashCode() {
81          return new HashCodeBuilder()
82                      .appendSuper( super.hashCode() )
83                      .append( getValue() ).toHashCode();
84      }
85      
86      
87      /***
88       * {@inheritDoc}
89       */
90      public boolean equals( Object theObj ) {
91          boolean retVal = false;
92          if (theObj instanceof DateParamField) {
93              DateParamField otherField = (DateParamField) theObj;
94              retVal = new EqualsBuilder()
95                  .appendSuper( super.equals(theObj) )
96                  .append( getValue(), otherField.getValue() ).isEquals();
97          }
98          return retVal;
99      }
100     
101     
102     /***
103      * {@inheritDoc}
104      */
105     public String toString() {
106         return new ToStringBuilder( this )
107                     .appendSuper( super.toString() )
108                     .append( getValue() ).toString();
109     }
110     
111 }