| java.lang.Object de.danet.an.util.EJBUtil
EJBUtil | public class EJBUtil (Code) | | Collection of EJB utilities.
This class adds common utilitites for an EJB environment.
|
createSession | public static Object createSession(Class ejbClass, String jndiName) throws IllegalArgumentException, ResourceNotAvailableException(Code) | | Create a session EJB. This method can be used for the special
— but very common — case when you want to create a
session EJB and the corresponding home interface has a create
method without any paramaters.
The given home interface is looked up using
EJBUtil.retrieveEJBHome retrieveEJBHome or
EJBUtil.retrieveEJBLocalHome retrieveEJBLocalHome (as
appropriate for the given class) and then the create session
method is called.
Parameters: ejbClass - the class of the home interface which must define acreate() method. Parameters: jndiName - the JNDI name of the home interface the new EJBObject . throws: IllegalArgumentException - if no create method without arguments exists. throws: ResourceNotAvailableException - if a problem occurs thatshould be temporary. |
createSession | public static EJBLocalObject createSession(EJBLocalHome home) throws IllegalArgumentException, ResourceNotAvailableException(Code) | | Create a session EJB. This method can be used for the special -
but very common - case when you want to create a session EJB
and the corresponding home interface has a create method
without any paramaters.
Parameters: home - the home interface throws: IllegalArgumentException - if no create method without arguments exists. throws: ResourceNotAvailableException - if a problem occurs thatshould be temporary. the new EJBObject . |
lookupEJBHome | public static EJBHome lookupEJBHome(Class ejbClass, String jndiName) throws NamingException(Code) | | Lookup a home interface using
EJBUtil.lookupJNDIEntrylookupJNDIEntry .
The method provides caching of looked up home interface
if the JNDI name is global (i.e. does not start with
"java:comp/ ").
Parameters: ejbClass - the class of the home interface Parameters: jndiName - the JNDI name of the home interface an EJBHome object throws: NamingException - if the JNDI lookup fails. |
lookupEJBLocalHome | public static EJBLocalHome lookupEJBLocalHome(Class ejbClass, String jndiName) throws NamingException(Code) | | Lookup a local home interface using
EJBUtil.lookupJNDIEntrylookupJNDIEntry .
Parameters: ejbClass - the class of the home interface Parameters: jndiName - the JNDI name of the home interface an EJBHome object throws: NamingException - if the JNDI lookup fails. |
lookupJNDIEntry | public static Object lookupJNDIEntry(String entry) throws NamingException(Code) | | Lookup a JNDI entry. This method implements caching as not all
application servers implement JNDI efficiently. As a
consequence, this method can only be used for read-only entries
that do not change over time.
Parameters: entry - the JNDI name of the entry the object found object throws: NamingException - if the JNDI lookup fails. |
newPrimaryKey | public static long newPrimaryKey(String table, long min) throws ResourceNotAvailableException(Code) | | Gets the next unique primary key for the given database table
observing a minimum value.
This method uses a high/low algorithm. The high values are
obtained from an EJB that maintains a table in a database.
The JNDI name of the ejb used can be set in a properties file
"/de.danet.an.util.jdbcKeyGen.properties with the
entry "generatorEjbJndiName ".
The JNDI name defaults to
"java:comp/env/ejb/JdbcKeyGenLocal ". This reflects the
assumption that this method is usually called from an EJB or
servlet. Of course, the deployment descriptor of the calling
EJB or servlet must include an <ejb-ref>
entry that links to the local home of EJB "KeyGen".
The table used by the EJB can be set with the property
"highKeyTable ". It defaults to
"KeyGeneratorHighs ". This table must be created as:
create table KeyGeneratorHighs (
TabName VARCHAR(50) NOT NULL,
NextKey INTEGER NOT NULL
)/
Another property that can be set is "highFactor ".
It determines the number of low keys used before a new
high key is requested. This value defaults to 64.
Parameters: table - the name of the table. Parameters: min - the minimum value of the returned key. the new primary key. throws: ResourceNotAvailableException - if an error occurs. |
removeSession | public static void removeSession(Object handle)(Code) | | Convenience method to clean up a session connection after
usage. If the given parameter is an instance of
EJBObject it simply calls remove() on
the given object. If the parameter is null
(indicating that the previous session creation propably failed)
nothing happens. If an error occurs when calling
remove() , it will be logged as warning.
Parameters: handle - the — maybe — ejb session object. |
retrieveEJBHome | public static EJBHome retrieveEJBHome(Class ejbClass, String jndiName) throws ResourceNotAvailableException, IllegalStateException(Code) | | Return an EJB's home interface using
EJBUtil.lookupEJBHomelookupEJBHome . This should be called from a
context where the JNDI name of the home interface is expected
to exist. NamingException s should thus only occur
if the service is not available due to dynamic error conditions
(network failure etc.). These exceptions are mapped to a
ResourceNotAvailable exception.
If, nevertheless, the NamingException indicates
that the JNDI entry does not exists, we assume a configuration
error and throw an IllegalStateException .
Parameters: ejbClass - the class of the home interface Parameters: jndiName - the JNDI name of the home interface an EJBHome object throws: ResourceNotAvailableException - if a problem occurs thatshould be temporary. throws: IllegalStateException - if the givenjndiName is not registered. |
retrieveEJBLocalHome | public static EJBLocalHome retrieveEJBLocalHome(Class ejbClass, String jndiName) throws ResourceNotAvailableException, IllegalStateException(Code) | | Return an EJB's local home interface using
EJBUtil.lookupEJBHome lookupEJBLocalHome . This should be
called from a context where the JNDI name of the home interface
is expected to exist. NamingException s should thus
only occur if the service is not available due to dynamic error
conditions (network failure etc.). These exceptions are mapped
to a ResourceNotAvailable exception.
If, nevertheless, the NamingException indicates
that the JNDI entry does not exists, we assume a configuration
error and throw an IllegalStateException .
Parameters: ejbClass - the class of the home interface Parameters: jndiName - the JNDI name of the home interface an EJBHome object throws: ResourceNotAvailableException - if a problem occurs thatshould be temporary. throws: IllegalStateException - if the givenjndiName is not registered. |
retrieveJNDIEntry | public static Object retrieveJNDIEntry(String entry) throws ResourceNotAvailableException, IllegalStateException(Code) | | Lookup a JNDI entry using
EJBUtil.lookupJNDIEntrylookupJNDIEntry . This should be called from a
context where the JNDI name is expected
to exist. NamingException s should thus only occur
if the service is not available due to dynamic error conditions
(network failure etc.). These exceptions are mapped to a
ResourceNotAvailable exception.
If, nevertheless, the NamingException indicates
that the JNDI entry does not exists, we assume a configuration
error and throw an IllegalStateException .
Parameters: entry - the JNDI name an EJBHome object throws: ResourceNotAvailableException - if a problem occurs thatshould be temporary. throws: IllegalStateException - if the givenjndiName is not registered. |
unwrapEJBException | public static Throwable unwrapEJBException(Throwable ex)(Code) | | Unwrap the root cuase of an EJBException . The
EJBException wrappers often hide the root cause of
an exception. This method calls
getCausedByException() until it finds an exception
that is not of type EJBException . This exception
is returned.
Parameters: ex - the exception to be unwrapped. the root cause exception. |
|
|