001: /* ====================================================================
002: * The Jcorporate Apache Style Software License, Version 1.2 05-07-2002
003: *
004: * Copyright (c) 1995-2002 Jcorporate Ltd. All rights reserved.
005: *
006: * Redistribution and use in source and binary forms, with or without
007: * modification, are permitted provided that the following conditions
008: * are met:
009: *
010: * 1. Redistributions of source code must retain the above copyright
011: * notice, this list of conditions and the following disclaimer.
012: *
013: * 2. Redistributions in binary form must reproduce the above copyright
014: * notice, this list of conditions and the following disclaimer in
015: * the documentation and/or other materials provided with the
016: * distribution.
017: *
018: * 3. The end-user documentation included with the redistribution,
019: * if any, must include the following acknowledgment:
020: * "This product includes software developed by Jcorporate Ltd.
021: * (http://www.jcorporate.com/)."
022: * Alternately, this acknowledgment may appear in the software itself,
023: * if and wherever such third-party acknowledgments normally appear.
024: *
025: * 4. "Jcorporate" and product names such as "Expresso" must
026: * not be used to endorse or promote products derived from this
027: * software without prior written permission. For written permission,
028: * please contact info@jcorporate.com.
029: *
030: * 5. Products derived from this software may not be called "Expresso",
031: * or other Jcorporate product names; nor may "Expresso" or other
032: * Jcorporate product names appear in their name, without prior
033: * written permission of Jcorporate Ltd.
034: *
035: * 6. No product derived from this software may compete in the same
036: * market space, i.e. framework, without prior written permission
037: * of Jcorporate Ltd. For written permission, please contact
038: * partners@jcorporate.com.
039: *
040: * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
041: * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
042: * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
043: * DISCLAIMED. IN NO EVENT SHALL JCORPORATE LTD OR ITS CONTRIBUTORS
044: * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
045: * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
046: * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
047: * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
048: * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
049: * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
050: * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
051: * SUCH DAMAGE.
052: * ====================================================================
053: *
054: * This software consists of voluntary contributions made by many
055: * individuals on behalf of the Jcorporate Ltd. Contributions back
056: * to the project(s) are encouraged when you make modifications.
057: * Please send them to support@jcorporate.com. For more information
058: * on Jcorporate Ltd. and its products, please see
059: * <http://www.jcorporate.com/>.
060: *
061: * Portions of this software are based upon other open source
062: * products and are subject to their respective licenses.
063: */
064:
065: package com.jcorporate.expresso.services.dbobj;
066:
067: import com.jcorporate.expresso.core.cache.CacheException;
068: import com.jcorporate.expresso.core.cache.CacheManager;
069: import com.jcorporate.expresso.core.cache.CacheSystem;
070: import com.jcorporate.expresso.core.db.DBException;
071: import com.jcorporate.expresso.core.dbobj.RequestContext;
072: import com.jcorporate.expresso.core.dbobj.Schema;
073: import com.jcorporate.expresso.core.dbobj.SchemaFactory;
074: import com.jcorporate.expresso.core.dbobj.SecuredDBObject;
075: import com.jcorporate.expresso.core.dbobj.ValidValue;
076: import com.jcorporate.expresso.core.misc.StringUtil;
077: import org.apache.log4j.Logger;
078:
079: import java.util.Vector;
080:
081: /**
082: * Schema list
083: * The schema list object lists the individual Schema classes
084: * for each application installed at this site.
085: * These schemas, in turn, contain information about the tables/database object
086: * required for each application.
087: *
088: * @author Michael Nash
089: * @version $Revision: 1.18 $ $Date: 2004/11/17 20:48:18 $
090: */
091: public class SchemaList extends SecuredDBObject {
092:
093: static private final transient Logger log = Logger
094: .getLogger(SchemaList.class);
095:
096: /**
097: * Default TTY of 30 minutes
098: */
099: static private final long CACHE_TTY = 60 * 30 * 1000;
100:
101: /**
102: * Field name for the schema class
103: */
104: static public final String FLD_SCHEMA_CLASS = "SchemaClass";
105:
106: /**
107: * Field name for the schema description
108: */
109: static public final String FLD_DESCRIP = "Descrip";
110:
111: /**
112: * Field name for 'component code'
113: */
114: static public final String FLD_COMPONENT_CODE = "ComponentCode";
115:
116: /**
117: * Field name for virtual field component code.
118: */
119: static public final String FLD_VERSION_NUMBER = "VersionNumber";
120:
121: /**
122: * Constructor
123: */
124: public SchemaList() throws DBException {
125: super ();
126: } /* SchemaList() */
127:
128: /**
129: * Use over (String) constructor. Initializes the object in the context
130: * of the user who's uid belongs to the parameter.
131: *
132: * @param uid the Uid of the user context
133: * @throws DBException if there's an initialization problem
134: */
135: public SchemaList(int uid) throws DBException {
136: super (uid);
137: }
138:
139: /**
140: * For using DBObjects within Controllers. Initializes based upon the current
141: * user and the requested db. [Of course this can be modified later]
142: *
143: * @param request - The controller request handed to you by the framework.
144: * @throws DBException upon construction error
145: */
146: public SchemaList(RequestContext request) throws DBException {
147: super (request);
148: }
149:
150: /**
151: * Get a vector of valid values mapping Schema Classes to Schema Descriptions
152: *
153: * @return Vector of Valid Values objects
154: * @throws DBException upon retrieval error
155: */
156: public Vector getValues() throws DBException {
157:
158: String cacheName = this .getClass().getName() + ".validValues";
159: CacheSystem cs = CacheManager.getCacheSystem(this
160: .getDataContext());
161: boolean cacheError = false;
162: try {
163: if (!cs.existsCache(cacheName)) {
164: cs.createCache(cacheName, true);
165: }
166: } catch (CacheException ex) {
167: log.error("Error getting cached valid values", ex);
168: cacheError = true;
169: }
170:
171: Vector v = null;
172: //
173: // Do not use cache if in Transaction. and a localconnection has been set
174: //
175: if (!cacheError
176: && (localConnection == null || localConnection
177: .getAutoCommit() == false)) {
178: java.util.List temp = cs.getItems(cacheName);
179: if (temp != null) {
180: if (temp instanceof Vector) {
181: v = (Vector) temp;
182: } else {
183: v = new Vector(temp);
184: }
185: }
186: }
187:
188: if (v == null) {
189: v = getValuesDefault("SchemaClass", "Descrip");
190: v.addElement(new ValidValue(
191: "com.jcorporate.expresso.core.ExpressoSchema",
192: "Expresso"));
193:
194: if (!cacheError) {
195: try {
196: cs.setItems(cacheName, v, CACHE_TTY);
197: } catch (CacheException ex) {
198: log.error("Error setting cached valid values", ex);
199: }
200: }
201: }
202:
203: return v;
204: } /* getValues() */
205:
206: /**
207: * Used to deal with the virtual field VersionNumber. For all other fields
208: * it just calls the normal SecuredDBObject.getField()
209: *
210: * @param fieldName The name of the field to retrieve
211: * @return The field value
212: * @throws DBException upon error
213: */
214: public String getField(String fieldName) throws DBException {
215: if (fieldName.equals("VersionNumber")) {
216: String schemaClass = StringUtil
217: .notNull(getField("SchemaClass"));
218:
219: if (!schemaClass.equals("")) {
220: Schema oneSchema = null;
221:
222: oneSchema = SchemaFactory.getInstance().getSchema(
223: schemaClass);
224:
225: if (oneSchema == null) {
226: return "N/A";
227: }
228:
229: return oneSchema.getVersion();
230: }
231:
232: return "";
233: }
234:
235: return super .getField(fieldName);
236: } /* getField(String) */
237:
238: /**
239: * Sets up the Schema List fields
240: */
241: public void setupFields() throws DBException {
242: setTargetTable("SCHEMALIST");
243: setDescription("DBschemaList");
244: setCharset("ISO-8859-1");
245: addField(FLD_SCHEMA_CLASS, "char", 128, false,
246: "schemaClassFile");
247: addField(FLD_DESCRIP, "char", 80, false, "schemaDescription");
248: addField(FLD_COMPONENT_CODE, "char", 80, true, "componentCode");
249: addVirtualField(FLD_VERSION_NUMBER, "char", 10, "version");
250: addKey("SchemaClass");
251: } /* setupFields() */
252:
253: } /* SchemaList */
254:
255: /* SchemaList */
|