KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > jcorporate > expresso > services > dbobj > SchemaList


1 /* ====================================================================
2  * The Jcorporate Apache Style Software License, Version 1.2 05-07-2002
3  *
4  * Copyright (c) 1995-2002 Jcorporate Ltd. All rights reserved.
5  *
6  * Redistribution and use in source and binary forms, with or without
7  * modification, are permitted provided that the following conditions
8  * are met:
9  *
10  * 1. Redistributions of source code must retain the above copyright
11  * notice, this list of conditions and the following disclaimer.
12  *
13  * 2. Redistributions in binary form must reproduce the above copyright
14  * notice, this list of conditions and the following disclaimer in
15  * the documentation and/or other materials provided with the
16  * distribution.
17  *
18  * 3. The end-user documentation included with the redistribution,
19  * if any, must include the following acknowledgment:
20  * "This product includes software developed by Jcorporate Ltd.
21  * (http://www.jcorporate.com/)."
22  * Alternately, this acknowledgment may appear in the software itself,
23  * if and wherever such third-party acknowledgments normally appear.
24  *
25  * 4. "Jcorporate" and product names such as "Expresso" must
26  * not be used to endorse or promote products derived from this
27  * software without prior written permission. For written permission,
28  * please contact info@jcorporate.com.
29  *
30  * 5. Products derived from this software may not be called "Expresso",
31  * or other Jcorporate product names; nor may "Expresso" or other
32  * Jcorporate product names appear in their name, without prior
33  * written permission of Jcorporate Ltd.
34  *
35  * 6. No product derived from this software may compete in the same
36  * market space, i.e. framework, without prior written permission
37  * of Jcorporate Ltd. For written permission, please contact
38  * partners@jcorporate.com.
39  *
40  * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
41  * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
42  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
43  * DISCLAIMED. IN NO EVENT SHALL JCORPORATE LTD OR ITS CONTRIBUTORS
44  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
45  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
46  * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
47  * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
48  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
49  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
50  * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
51  * SUCH DAMAGE.
52  * ====================================================================
53  *
54  * This software consists of voluntary contributions made by many
55  * individuals on behalf of the Jcorporate Ltd. Contributions back
56  * to the project(s) are encouraged when you make modifications.
57  * Please send them to support@jcorporate.com. For more information
58  * on Jcorporate Ltd. and its products, please see
59  * <http://www.jcorporate.com/>.
60  *
61  * Portions of this software are based upon other open source
62  * products and are subject to their respective licenses.
63  */

64
65 package com.jcorporate.expresso.services.dbobj;
66
67 import com.jcorporate.expresso.core.cache.CacheException;
68 import com.jcorporate.expresso.core.cache.CacheManager;
69 import com.jcorporate.expresso.core.cache.CacheSystem;
70 import com.jcorporate.expresso.core.db.DBException;
71 import com.jcorporate.expresso.core.dbobj.RequestContext;
72 import com.jcorporate.expresso.core.dbobj.Schema;
73 import com.jcorporate.expresso.core.dbobj.SchemaFactory;
74 import com.jcorporate.expresso.core.dbobj.SecuredDBObject;
75 import com.jcorporate.expresso.core.dbobj.ValidValue;
76 import com.jcorporate.expresso.core.misc.StringUtil;
77 import org.apache.log4j.Logger;
78
79 import java.util.Vector JavaDoc;
80
81
82 /**
83  * Schema list
84  * The schema list object lists the individual Schema classes
85  * for each application installed at this site.
86  * These schemas, in turn, contain information about the tables/database object
87  * required for each application.
88  *
89  * @author Michael Nash
90  * @version $Revision: 1.18 $ $Date: 2004/11/17 20:48:18 $
91  */

92 public class SchemaList
93         extends SecuredDBObject {
94
95     static private final transient Logger log = Logger.getLogger(SchemaList.class);
96
97     /**
98      * Default TTY of 30 minutes
99      */

100     static private final long CACHE_TTY = 60 * 30 * 1000;
101
102     /**
103      * Field name for the schema class
104      */

105     static public final String JavaDoc FLD_SCHEMA_CLASS = "SchemaClass";
106
107     /**
108      * Field name for the schema description
109      */

110     static public final String JavaDoc FLD_DESCRIP = "Descrip";
111
112     /**
113      * Field name for 'component code'
114      */

115     static public final String JavaDoc FLD_COMPONENT_CODE = "ComponentCode";
116
117     /**
118      * Field name for virtual field component code.
119      */

120     static public final String JavaDoc FLD_VERSION_NUMBER = "VersionNumber";
121
122
123     /**
124      * Constructor
125      */

126     public SchemaList()
127             throws DBException {
128         super();
129     } /* SchemaList() */
130
131
132     /**
133      * Use over (String) constructor. Initializes the object in the context
134      * of the user who's uid belongs to the parameter.
135      *
136      * @param uid the Uid of the user context
137      * @throws DBException if there's an initialization problem
138      */

139     public SchemaList(int uid)
140             throws DBException {
141         super(uid);
142     }
143
144     /**
145      * For using DBObjects within Controllers. Initializes based upon the current
146      * user and the requested db. [Of course this can be modified later]
147      *
148      * @param request - The controller request handed to you by the framework.
149      * @throws DBException upon construction error
150      */

151     public SchemaList(RequestContext request)
152             throws DBException {
153         super(request);
154     }
155
156
157     /**
158      * Get a vector of valid values mapping Schema Classes to Schema Descriptions
159      *
160      * @return Vector of Valid Values objects
161      * @throws DBException upon retrieval error
162      */

163     public Vector JavaDoc getValues()
164             throws DBException {
165
166         String JavaDoc cacheName = this.getClass().getName() + ".validValues";
167         CacheSystem cs = CacheManager.getCacheSystem(this.getDataContext());
168         boolean cacheError = false;
169         try {
170             if (!cs.existsCache(cacheName)) {
171                 cs.createCache(cacheName, true);
172             }
173         } catch (CacheException ex) {
174             log.error("Error getting cached valid values", ex);
175             cacheError = true;
176         }
177
178         Vector JavaDoc v = null;
179         //
180
// Do not use cache if in Transaction. and a localconnection has been set
181
//
182
if (!cacheError && (localConnection == null || localConnection.getAutoCommit() == false)) {
183             java.util.List JavaDoc temp = cs.getItems(cacheName);
184             if (temp != null) {
185                 if (temp instanceof Vector JavaDoc) {
186                     v = (Vector JavaDoc) temp;
187                 } else {
188                     v = new Vector JavaDoc(temp);
189                 }
190             }
191         }
192
193         if (v == null) {
194             v = getValuesDefault("SchemaClass", "Descrip");
195             v.addElement(new ValidValue("com.jcorporate.expresso.core.ExpressoSchema",
196                     "Expresso"));
197
198             if (!cacheError) {
199                 try {
200                     cs.setItems(cacheName, v, CACHE_TTY);
201                 } catch (CacheException ex) {
202                     log.error("Error setting cached valid values", ex);
203                 }
204             }
205         }
206
207
208         return v;
209     } /* getValues() */
210
211
212     /**
213      * Used to deal with the virtual field VersionNumber. For all other fields
214      * it just calls the normal SecuredDBObject.getField()
215      *
216      * @param fieldName The name of the field to retrieve
217      * @return The field value
218      * @throws DBException upon error
219      */

220     public String JavaDoc getField(String JavaDoc fieldName)
221             throws DBException {
222         if (fieldName.equals("VersionNumber")) {
223             String JavaDoc schemaClass = StringUtil.notNull(getField("SchemaClass"));
224
225             if (!schemaClass.equals("")) {
226                 Schema oneSchema = null;
227
228                 oneSchema = SchemaFactory.getInstance().getSchema(schemaClass);
229
230                 if (oneSchema == null) {
231                     return "N/A";
232                 }
233
234
235                 return oneSchema.getVersion();
236             }
237
238             return "";
239         }
240
241         return super.getField(fieldName);
242     } /* getField(String) */
243
244
245     /**
246      * Sets up the Schema List fields
247      */

248     public void setupFields()
249             throws DBException {
250         setTargetTable("SCHEMALIST");
251         setDescription("DBschemaList");
252         setCharset("ISO-8859-1");
253         addField(FLD_SCHEMA_CLASS, "char", 128, false, "schemaClassFile");
254         addField(FLD_DESCRIP, "char", 80, false, "schemaDescription");
255         addField(FLD_COMPONENT_CODE, "char", 80, true, "componentCode");
256         addVirtualField(FLD_VERSION_NUMBER, "char", 10, "version");
257         addKey("SchemaClass");
258     } /* setupFields() */
259
260
261 } /* SchemaList */
262
263 /* SchemaList */
Popular Tags