KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > webdocwf > util > loader > Cache


1 /**
2   Cache - Load data from source tables (or select statements) and puts them into
3   Hatshtable (cache).
4
5     Copyright (C) 2002-2003 Together
6
7     This library is free software; you can redistribute it and/or
8     modify it under the terms of the GNU Lesser General Public
9     License as published by the Free Software Foundation; either
10     version 2.1 of the License, or (at your option) any later version.
11
12     This library is distributed in the hope that it will be useful,
13     but WITHOUT ANY WARRANTY; without even the implied warranty of
14     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15     Lesser General Public License for more details.
16
17     You should have received a copy of the GNU Lesser General Public
18     License along with this library; if not, write to the Free Software
19     Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20
21  Cache.java
22  Date: 23.01.2003.
23  @version 1.0.0
24  @author: Milosevic Sinisa sinisa@prozone.co.yu
25  */

26
27 package org.webdocwf.util.loader;
28
29
30 import java.util.Hashtable JavaDoc;
31 import java.util.Vector JavaDoc;
32 import java.math.BigDecimal JavaDoc;
33
34 /**
35   Cache - Load data from source tables (or select statements) and puts them into
36   Hatshtable (cache).
37 */

38 public class Cache {
39
40   private Hashtable JavaDoc hCache=null;
41
42   /**
43    * Public constructor of cache class.
44    * Constructor create new hashtable
45    */

46   public Cache() {
47     this.hCache=new Hashtable JavaDoc();
48   }
49
50   /**
51    * Public constructor of cache class.
52    * Constructor set cache table.
53    * @param cache is cache table.
54    */

55   public Cache(Hashtable JavaDoc cache) {
56     this.hCache=cache;
57   }
58
59   /**
60    * Read current cache table
61    * @return value of parmeter hCache
62    */

63   public Hashtable JavaDoc getCache() {
64     return this.hCache;
65   }
66
67   /**
68    * Set cache table.
69    * @param cache is cache table
70    */

71   public void setCache(Hashtable JavaDoc cache) {
72     this.hCache=cache;
73   }
74
75   /**
76    * Put row of source values into cache.
77    * @param row SQL query row
78    * @param sourceValues represents source values
79    */

80   public void setCacheRow(BigDecimal JavaDoc row, Vector JavaDoc sourceValues) {
81     this.hCache.put(row,sourceValues);
82   }
83
84   /**
85    * Put row of source values into cache.
86    * @param cache is cache table
87    * @param row is SQL query row
88    * @param sourceValues represents source values
89    */

90   public void setCacheRow(Hashtable JavaDoc cache, BigDecimal JavaDoc row, Vector JavaDoc sourceValues) {
91     cache.put(row,sourceValues);
92   }
93
94   /**
95    * Read row of source values.
96    * @param row is SQL query row.
97    * @return Vector values of source columns.
98    */

99   public Vector JavaDoc getCacheRow(BigDecimal JavaDoc row) {
100     if(this.hCache.isEmpty())
101       return null;
102     else
103       return (Vector JavaDoc)this.hCache.get(row);
104   }
105
106   /**
107    * Read row of source values.
108    * @param row is SQL query row.
109    * @param cache is cache table
110    * @return Vector values of source columns.
111    */

112   public Vector JavaDoc getCacheRow(Hashtable JavaDoc cache, BigDecimal JavaDoc row) {
113     if(cache.isEmpty())
114       return null;
115     else
116       return (Vector JavaDoc)cache.get(row);
117   }
118
119   /**
120    * Reset cache.
121    */

122   public void resetCache() {
123     this.hCache.clear();
124     this.hCache=new Hashtable JavaDoc();
125   }
126
127 }
Popular Tags