[cvs]
expresso/expresso-web/WEB-INF/src/com/jcorporate/expresso/services/dbobj
Setup.java
Larry Hamel
lhamel at jcorp2.servlets.net
Wed May 5 00:18:42 PDT 2004
Update of /home/javacorp/.cvs/expresso/expresso/expresso-web/WEB-INF/src/com/jcorporate/expresso/services/dbobj
In directory jcorp2.servlets.net:/tmp/cvs-serv10444/expresso-web/WEB-INF/src/com/jcorporate/expresso/services/dbobj
Modified Files:
Setup.java
Log Message:
add convenience methods & reformat
Index: Setup.java
===================================================================
RCS file: /home/javacorp/.cvs/expresso/expresso/expresso-web/WEB-INF/src/com/jcorporate/expresso/services/dbobj/Setup.java,v
retrieving revision 1.23
retrieving revision 1.24
diff -C2 -d -r1.23 -r1.24
*** Setup.java 8 Apr 2004 23:16:14 -0000 1.23
--- Setup.java 5 May 2004 07:18:40 -0000 1.24
***************
*** 91,107 ****
* schema is initialized. The user can then customize these values.</p>
*
! * @author Michael Nash
*/
public class Setup
extends SecuredDBObject {
! /** Is the setup cache initialized? */
private static boolean cacheInitialized = false;
! /** Name of the setup cache file. */
! public static final String CACHE_NAME = "com.jcorporate.expresso.services"
! + ".dbobj.Setup.setupCache";
! /** The Log4J Logger Instance */
private static Logger log = Logger.getLogger(Setup.class);
--- 91,112 ----
* schema is initialized. The user can then customize these values.</p>
*
! * @author Michael Nash
*/
public class Setup
extends SecuredDBObject {
! /**
! * Is the setup cache initialized?
! */
private static boolean cacheInitialized = false;
! /**
! * Name of the setup cache file.
! */
! public static final String CACHE_NAME = Setup.class.getName() + ".setupCache";
! /**
! * The Log4J Logger Instance
! */
private static Logger log = Logger.getLogger(Setup.class);
***************
*** 112,116 ****
private static HashSet tableNotExists = new HashSet();
public static final String SETUP_CODE = "SetupCode";
! public static final String DESCRIP = "Descrip";
public static final String SETUP_VALUE = "SetupValue";
public static final String SCHEMA_CLASS = "SchemaClass";
--- 117,121 ----
private static HashSet tableNotExists = new HashSet();
public static final String SETUP_CODE = "SetupCode";
! public static final String SETUP_DESCRIP = "Descrip";
public static final String SETUP_VALUE = "SetupValue";
public static final String SCHEMA_CLASS = "SchemaClass";
***************
*** 119,123 ****
* Constructor
*
! * @throws DBException upon error
*/
public Setup()
--- 124,128 ----
* Constructor
*
! * @throws DBException upon error
*/
public Setup()
***************
*** 129,132 ****
--- 134,138 ----
/**
* Initializes Setup with proper user context
+ *
* @param uid the Owning user's uid
* @throws DBException upon error
***************
*** 152,156 ****
* Extend add to call updatepool
*
! * @throws DBException upon error
*/
public synchronized void add()
--- 158,162 ----
* Extend add to call updatepool
*
! * @throws DBException upon error
*/
public synchronized void add()
***************
*** 164,168 ****
* Extend update to call updatepool
*
! * @throws DBException upon error
*/
public synchronized void delete()
--- 170,174 ----
* Extend update to call updatepool
*
! * @throws DBException upon error
*/
public synchronized void delete()
***************
*** 174,181 ****
/**
! *
! *
! * @return boolean true if something was indeed found.
! * @throws DBException upon error
*/
public boolean find()
--- 180,185 ----
/**
! * @return boolean true if something was indeed found.
! * @throws DBException upon error
*/
public boolean find()
***************
*** 197,204 ****
* you will want to call the getValue that names your Schema
*
! * @param dbName The data context to get the value for
! * @param setupCode The code string of the setup code required
! * @return String value stored in the given config value
! * @throws DBException If the value cannot be retrieved
*/
public static String getValue(String dbName, String setupCode)
--- 201,208 ----
* you will want to call the getValue that names your Schema
*
! * @param dbName The data context to get the value for
! * @param setupCode The code string of the setup code required
! * @return String value stored in the given config value
! * @throws DBException If the value cannot be retrieved
*/
public static String getValue(String dbName, String setupCode)
***************
*** 224,232 ****
* accessing these values from the connection pool
*
! * @param dbName The data context name
! * @param schemaName The name of the schema
! * @param setupCode The code string of the setup code required
! * @return String value stored in the given config value
! * @throws DBException If the value cannot be retrieved
*/
public static String getValue(String dbName, String schemaName,
--- 228,236 ----
* accessing these values from the connection pool
*
! * @param dbName The data context name
! * @param schemaName The name of the schema
! * @param setupCode The code string of the setup code required
! * @return String value stored in the given config value
! * @throws DBException If the value cannot be retrieved
*/
public static String getValue(String dbName, String schemaName,
***************
*** 253,263 ****
sl.retrieve();
! return ConfigManager.expandValue(StringUtil.notNull(
! sl.getField(SETUP_VALUE)));
}
// handle case where caching is on
! CacheManager cm = CacheManager.getInstance();
if (tableNotExists.contains(dbName)) {
--- 257,266 ----
sl.retrieve();
! return ConfigManager.expandValue(StringUtil.notNull(sl.getField(SETUP_VALUE)));
}
// handle case where caching is on
! CacheManager.getInstance(); // must precede access
if (tableNotExists.contains(dbName)) {
***************
*** 275,279 ****
}
! if (!cm.existsCache(dbName, CACHE_NAME) && isCaching) {
log.info("Setup cache did not exist - reading setup values");
readSetups();
--- 278,282 ----
}
! if (!CacheManager.existsCache(dbName, CACHE_NAME) && isCaching) {
log.info("Setup cache did not exist - reading setup values");
readSetups();
***************
*** 284,288 ****
* (as it probably got cleared by the cache manager)
*/
! int itemCount = cm.getItemCount(dbName, CACHE_NAME);
if (itemCount == 0) {
--- 287,291 ----
* (as it probably got cleared by the cache manager)
*/
! int itemCount = CacheManager.getItemCount(dbName, CACHE_NAME);
if (itemCount == 0) {
***************
*** 293,297 ****
}
! itemCount = cm.getItemCount(dbName, CACHE_NAME);
if (itemCount == 0) {
--- 296,300 ----
}
! itemCount = CacheManager.getItemCount(dbName, CACHE_NAME);
if (itemCount == 0) {
***************
*** 300,304 ****
}
! ValidValue oneItem = (ValidValue) cm.getItem(dbName,
CACHE_NAME,
schemaName + "|" + setupCode);
--- 303,307 ----
}
! ValidValue oneItem = (ValidValue) CacheManager.getItem(dbName,
CACHE_NAME,
schemaName + "|" + setupCode);
***************
*** 308,313 ****
}
! return ConfigManager.expandValue(StringUtil.notNull(
! oneItem.getDescription()));
} /* getValue(String, String, String) */
--- 311,315 ----
}
! return ConfigManager.expandValue(StringUtil.notNull(oneItem.getDescription()));
} /* getValue(String, String, String) */
***************
*** 317,324 ****
* valid (not null) or the method throws an exception
*
! * @param dbName The datacontext name
! * @param setupCode Code of the required setup value
! * @return java.lang.String
! * @throws DBException if the value does not exist or is null
*/
public static String getValueRequired(String dbName, String setupCode)
--- 319,326 ----
* valid (not null) or the method throws an exception
*
! * @param dbName The datacontext name
! * @param setupCode Code of the required setup value
! * @return java.lang.String
! * @throws DBException if the value does not exist or is null
*/
public static String getValueRequired(String dbName, String setupCode)
***************
*** 347,355 ****
* Get a value from the configuration values. Return null (no exception) if value doesn't exist
*
! * @param dbName The datacontext name
! * @param setupCode Code of the required setup value
! * @return java.lang.String of value, or null if not found
*/
! public static String getValueUnrequired(String dbName, String setupCode) {
String setupValue = null;
--- 349,357 ----
* Get a value from the configuration values. Return null (no exception) if value doesn't exist
*
! * @param dbName The datacontext name
! * @param setupCode Code of the required setup value
! * @return java.lang.String of value, or null if not found
*/
! public static String getValueUnrequired(String dbName, String setupCode) {
String setupValue = null;
***************
*** 368,377 ****
* Get a value from the configuration values. Return null (no exception) if value doesn't exist
*
! * @param dbName The datacontext name
! * @param setupCode Code of the required setup value
! * @param schema name of schema
! * @return java.lang.String of value, or null if not found
*/
! public static String getValueUnrequired(String dbName, String schema, String setupCode) {
String setupValue = null;
--- 370,379 ----
* Get a value from the configuration values. Return null (no exception) if value doesn't exist
*
! * @param dbName The datacontext name
! * @param setupCode Code of the required setup value
! * @param schema name of schema
! * @return java.lang.String of value, or null if not found
*/
! public static String getValueUnrequired(String dbName, String schema, String setupCode) {
String setupValue = null;
***************
*** 379,383 ****
setupValue = getValue(dbName, schema, setupCode);
// getvalue can return "" for some error cases
! if ( "".equals(setupValue) ) setupValue = null;
} catch (DBException e) {
// no problem
--- 381,385 ----
setupValue = getValue(dbName, schema, setupCode);
// getvalue can return "" for some error cases
! if ("".equals(setupValue)) setupValue = null;
} catch (DBException e) {
// no problem
***************
*** 392,400 ****
* valid or the method throws an exception
*
! * @param dbName The data context for the value
! * @param schema The schema class for this setup code
! * @param setupCode Code of the required setup value
! * @return String
! * @throws DBException if the value does not exist or is null
*/
public static String getValueRequired(String dbName, String schema,
--- 394,402 ----
* valid or the method throws an exception
*
! * @param dbName The data context for the value
! * @param schema The schema class for this setup code
! * @param setupCode Code of the required setup value
! * @return String
! * @throws DBException if the value does not exist or is null
*/
public static String getValueRequired(String dbName, String schema,
***************
*** 429,433 ****
* Check if this setup value is a directory
*
! * @throws DBException upon error
*/
private void isDirectory()
--- 431,435 ----
* Check if this setup value is a directory
*
! * @throws DBException upon error
*/
private void isDirectory()
***************
*** 442,446 ****
throw new DBException("Setup value '" + getField(SETUP_VALUE) +
"' for code '" + getField(SETUP_CODE) +
! "' (" + getField(DESCRIP) +
") is not a valid directory name. Must use '/' as " +
"path seperator and end with '/'");
--- 444,448 ----
throw new DBException("Setup value '" + getField(SETUP_VALUE) +
"' for code '" + getField(SETUP_CODE) +
! "' (" + getField(SETUP_DESCRIP) +
") is not a valid directory name. Must use '/' as " +
"path seperator and end with '/'");
***************
*** 451,455 ****
/**
* @param forceRead - Tries to reread the setup values even if the db tables
! * don't exist yet.
* @throws DBException if there's an error reading the setups
*/
--- 453,457 ----
/**
* @param forceRead - Tries to reread the setup values even if the db tables
! * don't exist yet.
* @throws DBException if there's an error reading the setups
*/
***************
*** 464,471 ****
log.info("Reading setup values for all databases/contexts");
int keyCount = 0;
String oneConfigKey = null;
- CacheManager cm = CacheManager.getInstance();
-
for (Enumeration e = ConfigManager.getAllConfigKeys();
e.hasMoreElements();) {
--- 466,472 ----
log.info("Reading setup values for all databases/contexts");
+ CacheManager.getInstance(); // must precede accesses
int keyCount = 0;
String oneConfigKey = null;
for (Enumeration e = ConfigManager.getAllConfigKeys();
e.hasMoreElements();) {
***************
*** 473,477 ****
/* We do an inner try here so that if we can't read
! setup values for one */
/* database, we continue & try to */
/* read values for the rest of the databases */
--- 474,478 ----
/* We do an inner try here so that if we can't read
! setup values for one */
/* database, we continue & try to */
/* read values for the rest of the databases */
***************
*** 492,499 ****
}
/* If we're specifically told in the expresso-config.xml file
! * that a particular context is NOT an "expresso"
! * context - e.g. doesn't contain Expresso tables, then don't
! * try to read setup values from it.
! */
try {
if (!ConfigManager.getContext(oneConfigKey)
--- 493,500 ----
}
/* If we're specifically told in the expresso-config.xml file
! * that a particular context is NOT an "expresso"
! * context - e.g. doesn't contain Expresso tables, then don't
! * try to read setup values from it.
! */
try {
if (!ConfigManager.getContext(oneConfigKey)
***************
*** 505,509 ****
}
if (!skipThisContext) {
! CacheSystem cs = cm.getCacheSystem(oneConfigKey);
if (log.isInfoEnabled()) {
log.info("Reading setup values for '" + oneConfigKey +
--- 506,510 ----
}
if (!skipThisContext) {
! CacheSystem cs = CacheManager.getCacheSystem(oneConfigKey);
if (log.isInfoEnabled()) {
log.info("Reading setup values for '" + oneConfigKey +
***************
*** 526,537 ****
setupCount++;
oneSetup = (Setup) ek.next();
! cm.addItem(oneConfigKey, CACHE_NAME,
! new ValidValue(
! oneSetup.getField(
! SCHEMA_CLASS) + "|" +
! oneSetup.getField(
! SETUP_CODE),
! oneSetup.getField(
! SETUP_VALUE)));
}
if (setupCount == 0) {
--- 527,534 ----
setupCount++;
oneSetup = (Setup) ek.next();
! CacheManager.addItem(oneConfigKey, CACHE_NAME,
! new ValidValue(oneSetup.getField(SCHEMA_CLASS) + "|" +
! oneSetup.getField(SETUP_CODE),
! oneSetup.getField(SETUP_VALUE)));
}
if (setupCount == 0) {
***************
*** 545,553 ****
}
! DBConnectionPool onePool = DBConnectionPool.getInstance(
! oneConfigKey);
! String maxConnect = StringUtil.notNull(
! getValue(oneConfigKey, "MaxConnections"));
if (!maxConnect.equals("")) {
--- 542,548 ----
}
! DBConnectionPool onePool = DBConnectionPool.getInstance(oneConfigKey);
! String maxConnect = StringUtil.notNull(getValue(oneConfigKey, "MaxConnections"));
if (!maxConnect.equals("")) {
***************
*** 561,567 ****
}
try {
! String timeOut = StringUtil.notNull(
! getValue(oneConfigKey,
! "ConnTimeOut"));
int interval = 30;
--- 556,561 ----
}
try {
! String timeOut = StringUtil.notNull(getValue(oneConfigKey,
! "ConnTimeOut"));
int interval = 30;
***************
*** 603,607 ****
* Read the setup/config values into a hashtable for cached access
*
! * @throws DBException upon error
*/
public static synchronized void readSetups()
--- 597,601 ----
* Read the setup/config values into a hashtable for cached access
*
! * @throws DBException upon error
*/
public static synchronized void readSetups()
***************
*** 614,618 ****
* Extend retrieve to supply a defeult for the schemaclass field
*
! * @throws DBException If the retrieve fails
*/
public synchronized void retrieve()
--- 608,612 ----
* Extend retrieve to supply a defeult for the schemaclass field
*
! * @throws DBException If the retrieve fails
*/
public synchronized void retrieve()
***************
*** 629,632 ****
--- 623,627 ----
* DB Tool calls this when the Expresso Setup Values are finally able to be
* read
+ *
* @param dbName the data context that setup tables now exist for
*/
***************
*** 639,644 ****
/**
* @see com.jcorporate.expresso.core.dbobj.SecuredDBObject#setupFields
- *
- * @throws DBException
*/
protected synchronized void setupFields()
--- 634,637 ----
***************
*** 649,657 ****
addField(SCHEMA_CLASS, "char", 128, false, "schema");
addField(SETUP_CODE, "char", 30, false, SETUP_CODE);
! addField(DESCRIP, "char", 80, false, "description");
addField(SETUP_VALUE, "varchar", 255, true, SETUP_VALUE);
setStringFilter(SCHEMA_CLASS, "stripFilter");
setStringFilter(SETUP_CODE, "stripFilter");
! setStringFilter(DESCRIP, "stripFilter");
setStringFilter(SETUP_VALUE, "rawFilter");
addKey(SCHEMA_CLASS);
--- 642,650 ----
addField(SCHEMA_CLASS, "char", 128, false, "schema");
addField(SETUP_CODE, "char", 30, false, SETUP_CODE);
! addField(SETUP_DESCRIP, "char", 80, false, "description");
addField(SETUP_VALUE, "varchar", 255, true, SETUP_VALUE);
setStringFilter(SCHEMA_CLASS, "stripFilter");
setStringFilter(SETUP_CODE, "stripFilter");
! setStringFilter(SETUP_DESCRIP, "stripFilter");
setStringFilter(SETUP_VALUE, "rawFilter");
addKey(SCHEMA_CLASS);
***************
*** 665,669 ****
* Extend update to validate some setup values
*
! * @throws DBException upon error
*/
public synchronized void update()
--- 658,662 ----
* Extend update to validate some setup values
*
! * @throws DBException upon error
*/
public synchronized void update()
***************
*** 687,694 ****
/**
! * updateCache is calle when we've updated setup values,
* so they must be read into the cache again
*
! * @throws DBException upon error
*/
private void updateCache()
--- 680,687 ----
/**
! * updateCache is called when we've updated setup values,
* so they must be read into the cache again
*
! * @throws DBException upon error
*/
private void updateCache()
***************
*** 700,703 ****
--- 693,723 ----
}
} /* updateCache() */
+
+ /**
+ * convenience setter for code
+ *
+ * @param code new code to set
+ */
+ public void setCode(String code) throws DBException {
+ setField(SETUP_CODE, code);
+ }
+
+ /**
+ * convenience setter for value
+ *
+ * @param value new value to set
+ */
+ public void setValue(String value) throws DBException {
+ setField(SETUP_VALUE, value);
+ }
+
+ /**
+ * convenience setter for description of Setup item
+ *
+ * @param descrip new description to set
+ */
+ public void setDescrip(String descrip) throws DBException {
+ setField(SETUP_DESCRIP, descrip);
+ }
}
More information about the cvs
mailing list