KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > cofax > DataStore


1 /*
2  * DataStore is part of the Cofax content management system library.
3  *
4  * This library is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU Lesser General Public
6  * License as published by the Free Software Foundation; either
7  * version 2.1 of the License, or (at your option) any later version.
8  *
9  * This library is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12  * Lesser General Public License for more details.
13  *
14  * You should have received a copy of the GNU Lesser General Public
15  * License along with this library; if not, write to the Free Software
16  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17  *
18  * Please see http://www.cofax.org for contact information and other related informaion.
19  *
20  * $Header: /cvsroot/cofax/cofax/src/org/cofax/DataStore.java,v 1.8.2.1 2006/12/11 16:28:43 fxrobin Exp $
21  */

22
23 package org.cofax;
24
25 import java.util.*;
26
27 /**
28  * Cofax's top level data store class. Cofax compatible handlers for data store
29  * implement this API. One example of such a handler is
30  * <code>SqlDataStore</code>. It uses an SQL compatible database as the data
31  * store for Cofax.
32  *
33  * <code>SqlDataStore</code> is flexible since it is not tied to a given table
34  * or field naming structure.
35  *
36  * Other data stores classes like <code>OdiDataStore</code> can be used to
37  * allow Cofax to use an ODI object database as the data store. Other data
38  * stores like <code>XMLDataStore</code> can be used for
39  * <code>PersonalCofax</code> to power small sites for those who do not wish
40  * to use an SQL database.
41  *
42  * Future data stores can be used for distributed content and storage over the
43  * internet. For example, a company that owns several newspapers can use a
44  * <code>DistributedDataStore</code> along with a
45  * <code>DistributedDataCache</code> to serve multiple newspapers from remote
46  * locations.
47  *
48  * <code>DataStore</code> classes are listed in the configuration and loaded
49  * dynamically.
50  *
51  * @author Rajiv Pant
52  * @author Karl Martino
53  */

54
55 public abstract class DataStore {
56
57     private String JavaDoc lastError;
58
59     private boolean error;
60
61     private boolean connected;
62
63     private static String JavaDoc dataStoreName;
64
65     public final static int PACKAGE_TAG_CACHE = 1;
66
67     public final static int PACKAGE_TAG_PROCESSED = 2;
68
69     public final static int PACKAGE_TAG_RESULTS = 3;
70
71     public final static int CLOB_COLUMNS = 4;
72
73     public final static int PACKAGE_TAG_CACHE_COMMAND = 5;
74
75     /**
76      * Whether to print logs or not
77      */

78     public static String JavaDoc dataLog = "0";
79
80     /**
81      * Whether to print logs to a file location (named) or System.out(empty)
82      */

83     public static String JavaDoc dataLogLocation = "";
84
85     /**
86      * Max size (in bits) of the log
87      */

88     public static long dataLogMaxSize = 0;
89
90     /**
91      * To be ran once before using the data store. With a config file.
92      */

93
94     public abstract void init(String JavaDoc configFile);
95
96     /**
97      * To be ran once before using the data store. With a pre-loaded Properties
98      * object.
99      */

100     public abstract void init(Properties dbProps);
101
102     /**
103      * To be ran once before using the data store. With a pre-loaded Properties
104      * object.
105      */

106     public abstract void initPool();
107
108     /**
109      * Set's the cache indicated with whichCache
110      */

111     public abstract void setCache(Object JavaDoc cache, int whichCache);
112
113     /**
114      * Clears the cache indicated with whichCache
115      */

116     public abstract void clearCache(int whichCache);
117
118     /**
119      * Gets a single value from a cache object
120      */

121     public abstract Object JavaDoc getCacheValue(Object JavaDoc key, int whichCache);
122
123     public abstract String JavaDoc getPoolConnectionStats(String JavaDoc name);
124
125     public abstract String JavaDoc getURL();
126
127     public abstract String JavaDoc getUser();
128
129     public abstract String JavaDoc getPassword();
130
131     public abstract int getMaxConns();
132
133     public abstract int getInitConns();
134
135     public abstract int getTimeOut();
136
137     public abstract int getConUsageLimit();
138
139     public abstract long getKillTime();
140
141     public abstract void setURL(String JavaDoc in);
142
143     public abstract void setUser(String JavaDoc in);
144
145     public abstract void setPassword(String JavaDoc in);
146
147     public abstract void setMaxConns(int in);
148
149     public abstract void setInitConns(int in);
150
151     public abstract void setTimeOut(int in);
152
153     public abstract void setConUsageLimit(int in);
154
155     public abstract void setKillTime(long in);
156
157     /**
158      * Sets the error message to be returned to the caller
159      */

160     protected void setError(boolean error) {
161         this.error = error;
162     }
163
164     /**
165      * Gets the error set with setError()
166      */

167     public boolean getError() {
168         return error;
169     }
170
171     /**
172      * To be ran once after using the data store. Do clean up here.
173      */

174     public abstract void destroy();
175
176     /**
177      * Returns the last error recorded.
178      */

179     public String JavaDoc getLastError() {
180
181         return lastError + "";
182
183     }
184
185     /**
186      * Sets an error message.
187      */

188     public void setLastError(String JavaDoc lastError) {
189
190         this.lastError = lastError;
191
192     }
193
194     /**
195      * Returns the Data Store name
196      */

197     public String JavaDoc getDataStoreName() {
198         return dataStoreName;
199     }
200
201     /**
202      * Sets the Data Store Name
203      */

204     public void setDataStoreName(String JavaDoc name) {
205         dataStoreName = name;
206     }
207
208     /**
209      * Establishes a connection to the datastore.
210      */

211     public abstract boolean connect();
212
213     /**
214      * Establishes a connection to the datastore.
215      */

216     public abstract boolean connectFromPool();
217
218     /**
219      * Looks up the package tag definition and does variable substitution with
220      * the params HashMap.
221      *
222      * @param tag
223      * The tag name. The Data Store must have a lookup table of names
224      * and definitions. the command.
225      *
226      */

227     public abstract String JavaDoc getPackageTag(String JavaDoc tag, HashMap params, String JavaDoc servPage, String JavaDoc servAddr);
228
229     /**
230      * Executes the tag definition and prefixes the name of returned values with
231      * the tag name. Requires getting a tagStatement with getPackageTag()
232      *
233      *
234      */

235     public abstract List getPackageData(String JavaDoc tag, String JavaDoc tagStatement, String JavaDoc servPage, String JavaDoc servAddr);
236
237     /**
238      * Overload for getPackageData that handles tag data and clobs additionally.
239      */

240     public abstract List getPackageData(HashMap data, String JavaDoc tagName, String JavaDoc tagData, boolean init);
241
242     /**
243      * Disconnects from the data store.
244      */

245     public abstract boolean disConnect();
246
247     /**
248      * Returns whether this datastore is connected.
249      */

250     public boolean isConnected() {
251         return connected;
252     }
253
254     /**
255      * Sets the connected flag
256      */

257     public void setConnected(boolean connected) {
258         this.connected = connected;
259     }
260
261     /**
262      * Inserts an article to the datastore. TO DO: KILL ME PLEASE!!!
263      */

264     public abstract boolean insertArticle(HashMap article, String JavaDoc approvedBy, String JavaDoc xmlFileType, ArrayList mappings, ArrayList relatedLinks);
265
266     /**
267      * Outputs configuration of this Data Store.
268      */

269     public String JavaDoc toString() {
270         return "Instance Of: " + getClass().getName() + "\n" + "dataStoreName: " + dataStoreName;
271     }
272
273     /**
274      * Calculate the query for the search of articles
275      */

276     public abstract HashMap searchArticles(HashMap htParams);
277
278     /**
279      * Returns the queries to get the packageTags
280      */

281     public abstract String JavaDoc selectPackagetags();
282
283     public abstract String JavaDoc selectPackagetagsCache();
284 }
285
Popular Tags