001: /**
002: Cache - Load data from source tables (or select statements) and puts them into
003: Hatshtable (cache).
004:
005: Copyright (C) 2002-2003 Together
006:
007: This library is free software; you can redistribute it and/or
008: modify it under the terms of the GNU Lesser General Public
009: License as published by the Free Software Foundation; either
010: version 2.1 of the License, or (at your option) any later version.
011:
012: This library is distributed in the hope that it will be useful,
013: but WITHOUT ANY WARRANTY; without even the implied warranty of
014: MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
015: Lesser General Public License for more details.
016:
017: You should have received a copy of the GNU Lesser General Public
018: License along with this library; if not, write to the Free Software
019: Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
020:
021: Cache.java
022: Date: 23.01.2003.
023: @version 1.0.0
024: @author: Milosevic Sinisa sinisa@prozone.co.yu
025: */package org.webdocwf.util.loader;
026:
027: import java.util.Hashtable;
028: import java.util.Vector;
029: import java.math.BigDecimal;
030:
031: /**
032: Cache - Load data from source tables (or select statements) and puts them into
033: Hatshtable (cache).
034: */
035: public class Cache {
036:
037: private Hashtable hCache = null;
038:
039: /**
040: * Public constructor of cache class.
041: * Constructor create new hashtable
042: */
043: public Cache() {
044: this .hCache = new Hashtable();
045: }
046:
047: /**
048: * Public constructor of cache class.
049: * Constructor set cache table.
050: * @param cache is cache table.
051: */
052: public Cache(Hashtable cache) {
053: this .hCache = cache;
054: }
055:
056: /**
057: * Read current cache table
058: * @return value of parmeter hCache
059: */
060: public Hashtable getCache() {
061: return this .hCache;
062: }
063:
064: /**
065: * Set cache table.
066: * @param cache is cache table
067: */
068: public void setCache(Hashtable cache) {
069: this .hCache = cache;
070: }
071:
072: /**
073: * Put row of source values into cache.
074: * @param row SQL query row
075: * @param sourceValues represents source values
076: */
077: public void setCacheRow(BigDecimal row, Vector sourceValues) {
078: this .hCache.put(row, sourceValues);
079: }
080:
081: /**
082: * Put row of source values into cache.
083: * @param cache is cache table
084: * @param row is SQL query row
085: * @param sourceValues represents source values
086: */
087: public void setCacheRow(Hashtable cache, BigDecimal row,
088: Vector sourceValues) {
089: cache.put(row, sourceValues);
090: }
091:
092: /**
093: * Read row of source values.
094: * @param row is SQL query row.
095: * @return Vector values of source columns.
096: */
097: public Vector getCacheRow(BigDecimal row) {
098: if (this .hCache.isEmpty())
099: return null;
100: else
101: return (Vector) this .hCache.get(row);
102: }
103:
104: /**
105: * Read row of source values.
106: * @param row is SQL query row.
107: * @param cache is cache table
108: * @return Vector values of source columns.
109: */
110: public Vector getCacheRow(Hashtable cache, BigDecimal row) {
111: if (cache.isEmpty())
112: return null;
113: else
114: return (Vector) cache.get(row);
115: }
116:
117: /**
118: * Reset cache.
119: */
120: public void resetCache() {
121: this .hCache.clear();
122: this .hCache = new Hashtable();
123: }
124:
125: }
|