|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectcom.bea.dsp.das.HelperContextCache
public final class HelperContextCache
ALDSP maintains a global cache of SDO HelperContexts. (See footnote below about how this may not be truly "global" in all cases.) This cache is keyed by a String "name", which is one of two things:
DataAccessServiceFactory.newDataAccessService(Context, String,
String)
or DataAccessServiceFactory.prepareExpression(Context, String,
String)
.
DataAccessServiceFactory.newDataAccessService(Context,
String)
.
DataAccessService.getHelperContext()
. or PreparedExpression.getHelperContext()
. However, if you need to
perform some actions with the HelperContext prior to creating any
DataAccessService/PreparedExpression instances, you may inquire the
HelperContext from this class. This class also contains methods to
let you manipulate this cache.
One of the most important things contained in an SDO HelperContext
is the XSDHelper, which contains all XML schemas known to the
HelperContext. When the mediator APIs construct DataObjects, these
DataObjects will be untyped unless the XSDHelper knows the schema
for the data returned from the ALDSP server. In general, untyped
DataObjects perform more slowly; they also will not behave
correctly when enabled for change-logging (see SDOUtil.enableChanges(commonj.sdo.DataObject)
),
and so cannot be passed to update procedure on the ALDSP server.
Therefore, it is important to ensure that the schemas are loaded whenever possible. There are several ways to accomplish this:
When using the dynamic mediator API, if you wish you can override
the default automatic download behaviour using DataAccessServiceFactory.newDataAccessService(Context, String,
String, boolean)
(for the EJB transport) or DataAccessServiceFactory.newDataAccessService(Context, String,
boolean)
(for the WS transport), and manage the HelperContext
yourself using the methods on this class. This is perhaps useful if
the dataspace has a large number of schemas and you wish to
download only a subset.
However, for ad-hoc queries (see PreparedExpression
), the mediator cannot know which
schemas are necessary, nor is it always the case that the
appropriate schemas for DataObjects returned from ad-hoc queries
exist on the ALDSP server. Therefore it is up to the user to ensure
that the schemas are loaded into the HelperContext prior to
executing any ad-hoc queries. You may use any of methods (1) - (4)
to accomplish this, depending on your query and where the schemas
are located.
Footnote: For internal reasons, the "global" cache represented by this class is not necessarily truly global, although this likely will affect only a very small number of customers. In an application where multiple threads exist with different context ClassLoaders, such as a web application, the cache will be different for each context ClassLoader. The most important result of this is that schemas manually loaded in one thread (using methods 2, 3, or 4 above) will not be known on other threads. To ensure consistent behavior, such applications should arrange to have the schema-loading code executed in each thread.
If you are not using multiple threads with different context ClassLoaders, or you are using DSP's default behaviors for loading schemas, this should not affect you.
Footnote 2: The cache is not infinitely persistent. If no mediator
client code is holding a reference to a particular HelperContext,
it may fall out of the cache with the next garbage collection in
the JVM. If this happens, a subsequent call to get(String)
will return a new HelperContext. If the previous HelperContext for
a given name was modified (say by manually loading schemas into
it), this information will be lost. This is to prevent the cache
from consuming an ever-increasing amount of memory. To prevent this
from occurring, client code should keep a reference to the
HelperContext returned from get(String)
.
Constructor Summary | |
---|---|
HelperContextCache()
|
Method Summary | |
---|---|
static boolean |
flush(java.lang.String name)
Flush the SDO HelperContext associated with a particular dataspace or WSDL URL. |
static commonj.sdo.helper.HelperContext |
get(java.lang.String name)
Obtain the SDO HelperContext associated with a particular dataspace or WSDL URL. |
static boolean |
loadSchemasForDataspace(javax.naming.Context context,
java.lang.String dataspace,
java.lang.String dsname)
Populates the HelperContext for a given dataspace name with schemas by downloading them from the ALDSP server. |
static boolean |
loadSchemasForWsdl(java.lang.String wsdl_url)
Populates the HelperContext for a given WSDL URL with all schemas from the WSDL. |
static boolean |
setClassLoader(java.lang.String name,
java.lang.ClassLoader classloader)
Deprecated. - use thread context classloader |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
public HelperContextCache()
Method Detail |
---|
public static commonj.sdo.helper.HelperContext get(java.lang.String name)
name
- Either a dataspace name, or a WSDL URL.
public static boolean flush(java.lang.String name)
get(String)
must be discarded by the client. It is the
client's responsibility to manage obtaining a correct
HelperContext at any point in time.
name
- Either a dataspace name, or a WSDL URL.
public static boolean setClassLoader(java.lang.String name, java.lang.ClassLoader classloader)
public static boolean loadSchemasForDataspace(javax.naming.Context context, java.lang.String dataspace, java.lang.String dsname) throws DASException
This method will attempt not to repeat downloads; if it is
called twice with the same arguments without an intervening
call to flush(String)
, the second invocation will
return with no effect. In particular, passing a null
dsname a second time for a particular dataspace will never
result in any schemas being downloaded, even if new schemas
have been added to the dataspace in the meantime.
context
- Context to use when connecting to ALDSP server
(same as that passed to DataAccessServiceFactory.newDataAccessService(Context, String,
String)
).dataspace
- the dataspace name.dsname
- the data service name (an "ld:" URI). All schemas
describing XML types referred to by any input parameter or
return type of any operations on the named data service will be
downloaded. If the data service name is null, schemas will be
downloaded for ALL data services in the dataspace. Warning -
This could be a large number of schemas and hence be quite
slow!
DASException
public static boolean loadSchemasForWsdl(java.lang.String wsdl_url) throws DASException
flush(String)
has not been
called in the meantime), this method will return with no
effect.
wsdl_url
- URL of the WSDL.
DASException
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |