Right Java tools for J2EE, Web Service, Grid and more
|Home | Products | Documents | Downloads | Purchase | Support | Company | Partners | Contact |

com.acelet.opensource.globalEnvironment
Class GlobalProperties

java.lang.Object
  extended by com.acelet.opensource.globalEnvironment.GlobalProperties
All Implemented Interfaces:
java.io.Serializable

public class GlobalProperties
extends java.lang.Object
implements java.io.Serializable

The GlobalEnvironment is a set of classes providing persistent key - value pairs across different application and components.
GlobalEnvironment is a global version of java.util.Properties and java.util.Hashtable. Properties and Hashtable are valid within one single Java VM. GlobalEnvironment is valid across the whole network in distributed computing environment.

                        ------------------
                       |GlobalEnvironment |
   EJB <-------------->|                  |<----->Java application
   JSP <-------------->|   ----------     |
   Servlet <---------->|  |          |    |
   Grid computing <--->|  |(Database)|<----->C++ application
   Helper class <----->|  |          |<----->Other application
                       |   ----------     |
                        ------------------
 

In the J2EE world, the environment values are very rigid. They are in deployment descriptors. They can be changed at deploy time only. They are not shareable among different distributed components. Using GlobalEnvironment as static values, you can make your program more flexible. GlobalEnvironment can be used as dynamic values as well.
In Grid computing environment, GlobalEnvironment is very convenient.

There are following classes in this family:

This family stores key - value pairs in the global scope: It uses a SQL database to store key-values, instead of memory. So it is valid across many JVMs, many components and many applications, which may be written in different computer languages.

This family is thread safe.

This is a database application. The transaction behavior is subject to database isolation level and other setting.

GlobalProperties is a global version of java.util.Properties. The data type of key - value pair is String - String.
GlobalHashtable is a global version of java.util.Hashtable. The data type of key - value pair is Object - Object.
GlobalObject fills the gap between GlobalProperties and GlobalHashtable. The data type of key - value pair is String - Object.
GlobalDouble is for real numbers.
GlobalLong is for integer type of numbers.

The methods increase in both GlobalDouble and GlobalLong provide a thread friendly functionality on top of thread safe behavior: a thread will not overwrite changes from other threads. For example, you have an attribute "totalSale". The current value is 10.00. Now you sold something for 2.00 and your coworker sold something for 5.00 at the same time. If you do:

  
    read totalSale and get the value 10.00
    write totalSale as 10.00 + 2.00
 
and your coworker does similaly. Than the result will be either 12.00 or 15.00, not 17.00.
If you use method increase, do not read, do not write, but:
    increase by 2.00
 
and your coworker does similaly. The result will be 17.00, reguardless of who gets the transaction first.

GlobalEnvironment has most of applicable methods from java.util.Properties and java.util.Hashtable. The method signatures are similar, but with a java.sql.Connection as the first parameter.

Please see java.util.Propertes and java.util.Hashtable for method descriptions.

GlobalEnvironment is designed to be vender and platform neutral.

GlobalEnvironment is designed for J2EE (Java 2 Enterprise Edition) and EJB (Enterprise Java Beans). In J2EE/EJB world there is no standard way to set a global environment to share objects across JSP, Servlet and EJB. GlobalEnvironment solves this problem.
GlobalEnvironment can be use outside of J2EE/EJB as well.

Note: Transaction issue: There is no COMMIT or ROLLBACK inside GlobalEnvironment library. We assume that EJB container will take care of it, or you have to explicitly take care of it.

If you want to modify GlobalEnvironment (by calling method clear, put...) and want your modification be a part of a transaction, you should assign Connection parameter using the same instance with other class/method calls within the same transaction to ensure the integraty of the transaction. Or you have to do it in two phase commit.
If you want to modify GlobalEnvironment (by calling method clear, put...) and do NOT want your modification be a part of a transaction, you should not do so within another transaction. Use a different Connection may or may not be good enough. Some J2EE/EJB vendors are "transaction smart". If you modify GlobalEnvironment using a different instance of Connection, but with the same database, the server may treat it the same as if you used the same instance of Connection. So your modification will be subject of COMMIT and ROLLBACK within the transaction. If you want your modification to be independent, do not modify it within other transactions.

Note: The objects in GlobalHashtable and GlobalObject must be serializable. That is: those objects must implement java.io.Serializable. This is the only requirement.

Note: Some databases have limitations on the size of primary keys. This affect GlobalHashtable. You can modify the size of theKey on globalHashtable to make a compromise between fast access and the size limitation for your keys. See SQL script files included in this package for details.

Note: the key must be unique.

Note: The key of java.util.Properties is case sensitive String. GlobalProperties and GlobalObject assume that the SELECT statement on underlying database is case sensitive.

Requirements: SQL database. Please see enclosed script files for setup required tables with some databases.

Contributors:

Version:
1.00, 2001.05.15, 1.10, 2001.12.10 add queryTimeout, 1.12, 2003.02.04 More optimazation., 2.00, 2003.08.01 Change all methods be static while keep it backword compatible., 2.01, 2004.06.18 bug fixed
Author:
Wei Jiang
See Also:
GlobalDouble, GlobalHashtable, GlobalLong, GlobalObject, Serialized Form

Field Summary
 java.lang.String VERSION
           
 
Constructor Summary
GlobalProperties()
           
GlobalProperties(int queryTimeout)
           
 
Method Summary
static void clear(java.sql.Connection connection)
           
static boolean contains(java.sql.Connection connection, java.lang.String value)
           
static boolean containsKey(java.sql.Connection connection, java.lang.String key)
           
static boolean containsValue(java.sql.Connection connection, java.lang.String value)
           
static java.util.Enumeration elements(java.sql.Connection connection)
           
static java.lang.String get(java.sql.Connection connection, java.lang.String key)
           
static java.lang.String getProperty(java.sql.Connection connection, java.lang.String key)
           
static java.lang.String getProperty(java.sql.Connection connection, java.lang.String key, java.lang.String defaultValue)
           
static boolean isEmpty(java.sql.Connection connection)
           
static java.util.Enumeration keys(java.sql.Connection connection)
           
static void main(java.lang.String[] args)
           
static java.util.Enumeration propertyNames(java.sql.Connection connection)
           
static java.lang.String put(java.sql.Connection connection, java.lang.String key, java.lang.String value)
           
static java.lang.String remove(java.sql.Connection connection, java.lang.String key)
           
static java.lang.Object remove(java.sql.Connection connection, java.lang.String key, java.lang.String value)
           
static java.lang.String setProperty(java.sql.Connection connection, java.lang.String key, java.lang.String value)
           
static int size(java.sql.Connection connection)
           
static java.util.Collection values(java.sql.Connection connection)
           
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

VERSION

public final java.lang.String VERSION
See Also:
Constant Field Values
Constructor Detail

GlobalProperties

public GlobalProperties()

GlobalProperties

public GlobalProperties(int queryTimeout)
Method Detail

clear

public static void clear(java.sql.Connection connection)
                  throws java.lang.Exception
Throws:
java.lang.Exception

contains

public static boolean contains(java.sql.Connection connection,
                               java.lang.String value)
                        throws java.lang.Exception
Throws:
java.lang.Exception

containsKey

public static boolean containsKey(java.sql.Connection connection,
                                  java.lang.String key)
                           throws java.lang.Exception
Throws:
java.lang.Exception

containsValue

public static boolean containsValue(java.sql.Connection connection,
                                    java.lang.String value)
                             throws java.lang.Exception
Throws:
java.lang.Exception

elements

public static java.util.Enumeration elements(java.sql.Connection connection)
                                      throws java.lang.Exception
Throws:
java.lang.Exception

get

public static java.lang.String get(java.sql.Connection connection,
                                   java.lang.String key)
                            throws java.lang.Exception
Throws:
java.lang.Exception

getProperty

public static java.lang.String getProperty(java.sql.Connection connection,
                                           java.lang.String key)
                                    throws java.lang.Exception
Throws:
java.lang.Exception

getProperty

public static java.lang.String getProperty(java.sql.Connection connection,
                                           java.lang.String key,
                                           java.lang.String defaultValue)
                                    throws java.lang.Exception
Throws:
java.lang.Exception

isEmpty

public static boolean isEmpty(java.sql.Connection connection)
                       throws java.lang.Exception
Throws:
java.lang.Exception

keys

public static java.util.Enumeration keys(java.sql.Connection connection)
                                  throws java.lang.Exception
Throws:
java.lang.Exception

propertyNames

public static java.util.Enumeration propertyNames(java.sql.Connection connection)
                                           throws java.lang.Exception
Throws:
java.lang.Exception

put

public static java.lang.String put(java.sql.Connection connection,
                                   java.lang.String key,
                                   java.lang.String value)
                            throws java.lang.Exception
Throws:
java.lang.Exception

remove

public static java.lang.String remove(java.sql.Connection connection,
                                      java.lang.String key)
                               throws java.lang.Exception
Throws:
java.lang.Exception

remove

public static java.lang.Object remove(java.sql.Connection connection,
                                      java.lang.String key,
                                      java.lang.String value)
                               throws java.lang.Exception
Throws:
java.lang.Exception

setProperty

public static java.lang.String setProperty(java.sql.Connection connection,
                                           java.lang.String key,
                                           java.lang.String value)
                                    throws java.lang.Exception
Throws:
java.lang.Exception

size

public static int size(java.sql.Connection connection)
                throws java.lang.Exception
Throws:
java.lang.Exception

values

public static java.util.Collection values(java.sql.Connection connection)
                                   throws java.lang.Exception
Throws:
java.lang.Exception

main

public static void main(java.lang.String[] args)
                 throws java.lang.Exception
Throws:
java.lang.Exception

Copyright Acelet Corporation. 2000-2008. All rights reserved.