KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > daffodilwoods > daffodildb > utils > field > FieldDateLiteral


1 package com.daffodilwoods.daffodildb.utils.field;
2
3 import com.daffodilwoods.database.resource.DException;
4 import com.daffodilwoods.daffodildb.utils.GetByteComparator;
5 import com.daffodilwoods.daffodildb.server.datasystem.interfaces.Datatype;
6 import com.daffodilwoods.daffodildb.utils.BufferRange;
7 import java.sql.Date JavaDoc;
8
9 public class FieldDateLiteral extends FieldBase implements Comparable JavaDoc{
10
11   public FieldDateLiteral(Object JavaDoc object0){
12     object = object0;
13     datatype = Datatype.DATE;
14   }
15
16   public Object JavaDoc getObject() throws DException{
17     return object;
18   }
19
20   public FieldDateLiteral(BufferRange bufferRange0) {
21       super(bufferRange0,Datatype.DATE);
22   }
23
24   public BufferRange getBufferRange() {
25     if(bufferRange == null)
26       bufferRange = new BufferRange(getBytes((Date JavaDoc)object));
27     return bufferRange;
28   }
29
30   public boolean isNull() {
31       return object == null;
32   }
33   private byte[] getBytes(java.util.Date JavaDoc date)
34   {
35       if( date == null)
36           return null;
37
38       byte b[] = new byte[8];
39       long a1 = date.getTime();
40       for(int i = 56 , j=0 ; i >= 0 ; i-= 8)
41           b[j++]=(byte)((a1 >> i) & 0xFF);
42       return b;
43   }
44
45   public boolean equals(Object JavaDoc fieldBase){
46       try {
47           return (getDatatype() != ((FieldBase)fieldBase).getDatatype()) ? false :
48                   GetByteComparator.sameComparator.compare(this,fieldBase) == 0;
49       }
50       catch (DException ex) {
51           return false;
52       }
53   }
54
55   public int compareTo(Object JavaDoc fieldBase){
56       try {
57           return (GetByteComparator.sameComparator.compare(this,fieldBase) );
58       }
59       catch (DException ex) {
60           return -1;
61       }
62   }
63
64
65   public boolean getNull() {
66       return object == null;
67   }
68   public void setDatatype(int type) throws DException{
69   }
70   public void setBufferRange(BufferRange range) {
71    throw new RuntimeException JavaDoc("Create new instance of FieldDateLiteral instead of setting the bufferrange. Discuss with Neeraj or Parveen Sir ");
72 }
73
74
75 }
76
Popular Tags