de.folt.models.datamodel
Class DataSourceInstance

java.lang.Object
  extended by de.folt.models.datamodel.DataSourceInstance

public class DataSourceInstance
extends java.lang.Object

This class maintains a list of active data sources (instances of data sources). Data source are added by using createInstance. The class itself cannot be instantiated.
The main idea is to have only one active instance for each named data source . This e.g. avoids loading the same data sources several times (in different threads).
This implements a (enhanced) singleton pattern; not in its classical meaning where one has really only one instance. In contrasts it pools several instances of data sources in one hash table. Each data source is stored in the hash table with a key which identifies a given dat source. As a singleton there is no method to create a DataSourceInstance. The method getInstace returns a named data source. getInstance creates one if it does not exist otherwise returns the one found. getAllDataSourceInstanceNames returns all active instances. The data sources themselves are stores in @see de.folt.models.datamodel.DataSourceStorage, which basically is a class consisting of the data source and a counter indicating how often the createInstance method was called. createInstance increase the counter, removeInsance decreases the counter. The data source is removed from the list when the counter decrements to zero. The data source remove method is only called if the removeIfCounterZero boolean of DataSourceStorage is set to true (which it is per default).

Author:
klemens

Method Summary
static DataSource createInstance(java.lang.String name)
          createInstance create an instance of a data source based on its name.
static DataSource createInstance(java.lang.String name, DataSourceProperties dataModelProperties)
          createInstance create an instance of a data source based on its name and model a parameters.
static DataSource createInstance(java.lang.String name, java.util.Observer observer)
          createInstance creates an instance of a data source with and attaches an observer
static DataSource createInstance(java.lang.String name, java.lang.String configfile)
          createInstance create an instance of a data source based on its name.
static java.lang.String[] getAllDataSourceInstanceNames()
          getAllDataSourceInstanceNames returns all data source instances
static int getCounter(java.lang.String name)
          getCounter get the counter (usage) value for the data source
static DataSourceStorage getDataSourceStorageInstance(java.lang.String name)
          getDataSourceStorageInstance get the data storage instance
static java.util.Vector<java.lang.String[]> getDataSourcesWithType()
           
static java.lang.String[] getDataSourcesWithType(java.lang.String type)
           
static DataSource getInstance(java.lang.String name)
          getInstance
static java.util.Vector<java.lang.String> getKnownDataSourceModels()
          getKnownDataSourceModels return all the known data source model classes
static java.util.Vector<java.lang.String> getOpenTMSDatabases()
          getOpenTMSDatabases get a vector of the openTMS Data Sources
static void main(java.lang.String[] args)
          main
static DataSource removeInstance(java.lang.String name)
          removeInstance
static void test()
          test simple test method for generating DataModelInstances
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

createInstance

public static DataSource createInstance(java.lang.String name)
                                 throws OpenTMSException
createInstance create an instance of a data source based on its name. Method requires that it can determine the parameters of the data source for an existing data source some how.

Parameters:
name - of the data source
Returns:
the data source or null in case of not found or when an Exception occurred
Throws:
OpenTMSException

createInstance

public static DataSource createInstance(java.lang.String name,
                                        DataSourceProperties dataModelProperties)
                                 throws OpenTMSException
createInstance create an instance of a data source based on its name and model a parameters.

Parameters:
name - the name for the new instance
dataModelProperties - the properties associated with the new instance
Returns:
the instance generated
Throws:
OpenTMSException

createInstance

public static DataSource createInstance(java.lang.String name,
                                        java.util.Observer observer)
                                 throws OpenTMSException
createInstance creates an instance of a data source with and attaches an observer

Parameters:
name - the data source to create
observer - an observer for the data source
Returns:
the data source
Throws:
OpenTMSException

createInstance

public static DataSource createInstance(java.lang.String name,
                                        java.lang.String configfile)
                                 throws OpenTMSException
createInstance create an instance of a data source based on its name. Method requires that it can determine the parameters of the data source for an existing data source some how.

Parameters:
name - of the data source
Returns:
the data source or null in case of not found or when an Exception occured
Throws:
OpenTMSException

getAllDataSourceInstanceNames

public static java.lang.String[] getAllDataSourceInstanceNames()
getAllDataSourceInstanceNames returns all data source instances

Returns:
the names of the data source instances

getCounter

public static int getCounter(java.lang.String name)
getCounter get the counter (usage) value for the data source

Parameters:
name - the data source name
Returns:
the counter associated with the instance or -1 in case of error

getDataSourceStorageInstance

public static DataSourceStorage getDataSourceStorageInstance(java.lang.String name)
getDataSourceStorageInstance get the data storage instance

Parameters:
name - the name of the instance
Returns:
the DataSourceStorage associated with the instance

getInstance

public static DataSource getInstance(java.lang.String name)
getInstance

Parameters:
name - the name of the data source instance to be retrieved
Returns:
a data source based on name

getKnownDataSourceModels

public static java.util.Vector<java.lang.String> getKnownDataSourceModels()
getKnownDataSourceModels return all the known data source model classes

Returns:
a vector with the names of the know data source model class names

getOpenTMSDatabases

public static java.util.Vector<java.lang.String> getOpenTMSDatabases()
getOpenTMSDatabases get a vector of the openTMS Data Sources

Returns:
a Vector containing the openTMS Data Sources

getDataSourcesWithType

public static java.util.Vector<java.lang.String[]> getDataSourcesWithType()

getDataSourcesWithType

public static java.lang.String[] getDataSourcesWithType(java.lang.String type)

main

public static void main(java.lang.String[] args)
main

Parameters:
args -

removeInstance

public static DataSource removeInstance(java.lang.String name)
                                 throws OpenTMSException
removeInstance

Parameters:
name - the name of the data model to remove; usually the data model then closes connections etc.
Returns:
the removed data model
Throws:
OpenTMSException

test

public static void test()
test simple test method for generating DataModelInstances