org.bsf.listOfValues
Class LovBean

java.lang.Object
  extended byorg.bsf.commons.ejb.GenericAdapterBean
      extended byorg.bsf.commons.ejb.EntityAdapterBean
          extended byorg.bsf.listOfValues.LovBean
All Implemented Interfaces:
javax.ejb.EnterpriseBean, javax.ejb.EntityBean, LovBusinessInterface, java.io.Serializable

public class LovBean
extends org.bsf.commons.ejb.EntityAdapterBean
implements LovBusinessInterface

The LovBean is a BMP EJB that enables the retrieval of a List of Values (LOV). It uses two tables to retrieve the informations needed to build the LOV.

Description of the two tables used by this BMP: 1) BSF_LOV : The definition of the LOV itself (what to retrieve) => OID : The oid of the LOV (ex: 1) => LOV_NAME : The name of the LOV, only for information (ex: LOV_COUNTRIES) => LOV_REQUEST : The request to execute to retrieve the list of values. : The first returned column will define the PK of the : LovValue(cf. S_LOV_DEFINITON below). : (ex: select oid, short_name, long_name from countries) => TABLE_NAME : The name of the Table used in this LOV (could be usefull : when we need to notify that the LOV has to be retrieved : again since the underlying table has changed). If a LOV : is based on more than one table set the "most important" : one (or the one that changes the most... it is up to you). 2) BSF_LOV_DEFINITION : The definition of the fields contained in the LovValues : returned from the execution of the SQL statement cor- : responding to the selected LOV (cf. BSF_LOV). : Enables to use the expected data type and to label the : fields. => LOV_OID : The OID of the LOV (cf. BSF_LOV) for which we define : a field. => FIELD_NAME : The String used to place and access the column matching : the given field_position of the the LOV_REQUEST in the : returned LovValue. Keep the name simple... => FIELD_TYPE : The type of the field (ie. java.lang.Long, java.lang.String, : java.lang.Double, ...). => FIELD_POSITION : The position of this field in the SQL statement defined : in the LOV_REQUEST column of the BSF_LOV table. The first : column defined will be used as the PK for the LovValues.

See Also:
LovServiceBean, LovBusinessInterface, LovValue, Serialized Form

Field Summary
private  java.util.HashMap _lov
          Stores the lovValues in their "mapped" (OID, LovValue) form (a HashMap) to prevent remapping each time the map is requested.
private  java.util.List _metaData
          Stores the metadata (field name, position...) for this list of values.
private  java.util.Vector _sortedLov
          Used as a cache to store the results of the executed SQL to prevent the reexecution of the SQL statement each time the same LOV is requested).
private  java.lang.String JNDI_DATABASE_NAME
          The JNDI name used to retrieve a connection to the database.
static java.lang.String LOV_OID_FOR_TABLE_NAME_STATEMENT
           
private static java.lang.String METADATA_FOR_OID_STATEMENT
           
private static java.lang.String NAME_AND_REQUEST_FOR_OID_STATEMENT
           
 
Fields inherited from class org.bsf.commons.ejb.EntityAdapterBean
ejbContext
 
Fields inherited from class org.bsf.commons.ejb.GenericAdapterBean
 
Constructor Summary
LovBean()
           
 
Method Summary
 java.util.Collection ejbFindByPhysicalTable(java.lang.String p_tableName)
          Finds the LOVs that are working on a given physical table.
 java.lang.Long ejbFindByPrimaryKey(java.lang.Long p_OID)
          Checks if the the Lov exist in the S_LOV_REQUESTS table.
 void ejbLoad()
          Loads all the values from the DB using the request defined in the LOV_REQUESTS table.
 java.util.List getListOfValues()
          Gets the LovValues in the order of their retrieval (for example if we retrieve them by using a EJB BMP and the LOV_REQUESTS table we will get them in the order of the result of the executed SQL).
 LovValue getLovValue(java.lang.Long p_lovValueOID)
          Returns the LovValue corresponding to the given OID in the List Of Values held in the implementing Object.
 java.util.HashMap getLovValuesPerOID()
          Gets the LOV mapped by OID.
 java.util.List getMetaData()
           
 
Methods inherited from class org.bsf.commons.ejb.EntityAdapterBean
ejbActivate, ejbPassivate, ejbRemove, ejbStore, getEJBContext, getUserName, setEntityContext, unsetEntityContext
 
Methods inherited from class org.bsf.commons.ejb.GenericAdapterBean
getConnection, getEJBClassName, getEJBToolBox, getHome, handleCreateSessionException, handleExceptionAsSystemException, handleFinderException, handleRemoteException, handleSQLException, logDebug, logError, logError, logFatal, logFatal, logGraphBegin, logGraphEnd, logInfo, logWarn
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

NAME_AND_REQUEST_FOR_OID_STATEMENT

private static final java.lang.String NAME_AND_REQUEST_FOR_OID_STATEMENT
See Also:
Constant Field Values

METADATA_FOR_OID_STATEMENT

private static final java.lang.String METADATA_FOR_OID_STATEMENT
See Also:
Constant Field Values

LOV_OID_FOR_TABLE_NAME_STATEMENT

public static final java.lang.String LOV_OID_FOR_TABLE_NAME_STATEMENT
See Also:
Constant Field Values

JNDI_DATABASE_NAME

private final java.lang.String JNDI_DATABASE_NAME
The JNDI name used to retrieve a connection to the database.

See Also:
Constant Field Values

_sortedLov

private java.util.Vector _sortedLov
Used as a cache to store the results of the executed SQL to prevent the reexecution of the SQL statement each time the same LOV is requested).


_lov

private java.util.HashMap _lov
Stores the lovValues in their "mapped" (OID, LovValue) form (a HashMap) to prevent remapping each time the map is requested.


_metaData

private java.util.List _metaData
Stores the metadata (field name, position...) for this list of values.

Constructor Detail

LovBean

public LovBean()
Method Detail

ejbLoad

public void ejbLoad()
Loads all the values from the DB using the request defined in the LOV_REQUESTS table. For each row of the resultSet uses the LOV_DEFINITION_NAME and LOV_DEFINITION_TYPE from table LOV_DEFINITION to create the lovValue. This method should be called once per LOV

Specified by:
ejbLoad in interface javax.ejb.EntityBean

ejbFindByPrimaryKey

public java.lang.Long ejbFindByPrimaryKey(java.lang.Long p_OID)
                                   throws javax.ejb.ObjectNotFoundException
Checks if the the Lov exist in the S_LOV_REQUESTS table. Used to test for the LOV existence.

Returns:
The list of values having the given OID.
Throws:
javax.ejb.ObjectNotFoundException - if the corresponding LOV doesn't exist.
java.lang.IllegalArgumentException - if the given OID is null.

ejbFindByPhysicalTable

public java.util.Collection ejbFindByPhysicalTable(java.lang.String p_tableName)
                                            throws javax.ejb.FinderException
Finds the LOVs that are working on a given physical table. In other words it enables us to get a Collection of LOVs that are related to a given DB Table.

Is useful, for example, if the data in the DB are modified (a country is added or removed) and we want to update the LOVs working on those data (on the COUNTRIES table) for them to reflect the changes. First we need to know what LOVs are working on those data and that's what this finder retrieve for us.

You can check the Class description to have more informations about the DB structure.

Parameters:
p_tableName - The name of the DB table that we want to match.
Returns:
The OIDs of the LOVs that refer to the given table name in their TABLE_NAME field (cf. TABLE description).
Throws:
java.lang.IllegalArgumentException - if the given table name is null.
javax.ejb.ObjectNotFoundException - if none is found matching the given table name.
javax.ejb.FinderException

getLovValue

public LovValue getLovValue(java.lang.Long p_lovValueOID)
                     throws NoSuchLovValueException
Returns the LovValue corresponding to the given OID in the List Of Values held in the implementing Object.

Specified by:
getLovValue in interface LovBusinessInterface
Parameters:
p_lovValueOID - The OID, in the List Of Values held in the implementing Object, of the LovValue desired.
Returns:
the LovValue corresponding to the given oid or null if the LovValue isn't present.
Throws:
NoSuchLovValueException - if the requested LovValue isn't found in the LOV.

getLovValuesPerOID

public java.util.HashMap getLovValuesPerOID()
Gets the LOV mapped by OID.

Specified by:
getLovValuesPerOID in interface LovBusinessInterface
Returns:
a HashMap of (key=OID, object=LovValue).

getListOfValues

public java.util.List getListOfValues()
Gets the LovValues in the order of their retrieval (for example if we retrieve them by using a EJB BMP and the LOV_REQUESTS table we will get them in the order of the result of the executed SQL).

Specified by:
getListOfValues in interface LovBusinessInterface
Returns:
A list containing the LovValues.

getMetaData

public java.util.List getMetaData()
Returns:
The LovMetaDataItems in a List.