|
Nux 1.0 | ||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectnux.xom.pool.XQueryPool
Efficient thread-safe pool/cache of XQuery
objects, creating and
holding at most maxPoolEntries
XQuery objects (each
representing a compiled query). On cache miss, a new XQuery
is created via a factory, cached for future reuse, and then returned.
On cache hit an XQuery is returned instantly.
Pool eviction is based on a LRU (least recently used) policy.
This class helps to avoid the large overhead involved in constructing (i.e. compiling) an XQuery instance, in particul for complex queries over small input XML documents. Most useful in high throughput server container environments (e.g. large-scale Peer-to-Peer messaging network infrastructures over high-bandwidth networks, scalable MOMs, etc).
Note that this class caches queries, not their results or result fragments. In particular, no materialized view maintenance is done. If desired, result caching can be implemented in an application-specific manner on top of this class, in a large variety of ways.
Example usage (in any arbitrary thread and any arbitrary object):
XQuery xquery = XQueryPool.GLOBAL_POOL.getXQuery(new File("samples/xmark/q03.xq")); //XQuery xquery = XQueryPool.GLOBAL_POOL.getXQuery("for $i in /* return $i/headline_text", null); Document doc = BuilderPool.GLOBAL_POOL.getBuilder(false).build(new File(samples/xmark/auction-0.01.xml)); Nodes results = xquery.execute(doc).toNodes(); for (int i=0; i < results.size(); i++) { System.out.println("node "+i+": "+results.get(i).toXML()); }
Note: Internally uses extremely short-lived locks; the resulting potential lock contention is completely negligible.
Field Summary | |
static XQueryPool |
GLOBAL_POOL
A default pool (can be shared freely across threads without harm); global per class loader. |
Constructor Summary | |
XQueryPool()
Creates a new pool with default parameters. |
|
XQueryPool(int maxPoolEntries,
XQueryFactory factory)
Creates a new pool that uses the given factory on cache misses, and that can hold at most maxPoolEntries queries. |
Method Summary | |
XQuery |
getXQuery(File query)
Returns an XQuery for the given input query. |
XQuery |
getXQuery(ResourceResolver resolver,
String resourceName,
URI baseURI)
Returns an XQuery for the input stream obtained from
resolving the given resourceName against the given resolver. |
XQuery |
getXQuery(String query,
URI baseURI)
Returns an XQuery for the given input query, using the
given base URI. |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
public static final XQueryPool GLOBAL_POOL
Constructor Detail |
public XQueryPool()
public XQueryPool(int maxPoolEntries, XQueryFactory factory)
maxPoolEntries
queries.
maxPoolEntries
- the maximum number of queries this pool can hold before
starting to evict old queries. A value of zero effectively
disables pooling.factory
- the factory creating new XQuery instances on cache missesMethod Detail |
public XQuery getXQuery(File query) throws XQueryException, IOException
XQuery
for the given input query.
query
- the query to compile
IOException
- if an I/O error occured while reading the query.
XQueryException
- if the query has a syntax error, or if it references
namespaces, variables, or functions that have not been
declared, or contains other static errors such as type mismatches.public XQuery getXQuery(String query, URI baseURI) throws XQueryException
XQuery
for the given input query, using the
given base URI.
query
- the query to compilebaseURI
- an absolute URI, used when necessary in the resolution of
relative URIs found in the query. Used by the XQuery
doc
function, and hence the resolver. May be
null
in which case it defaults to the current
working directory.
XQueryException
- if the query has a syntax error, or if it references
namespaces, variables, or functions that have not been
declared, or contains other static errors such as type mismatches.public XQuery getXQuery(ResourceResolver resolver, String resourceName, URI baseURI) throws XQueryException, IOException, MissingResourceException
XQuery
for the input stream obtained from
resolving the given resourceName against the given resolver.
resolver
- an object that can produce an input stream for a given
resource name.resourceName
- the resource name (e.g. a path or URL)baseURI
- an absolute URI, used when necessary in the resolution of
relative URIs found in the query. Used by the XQuery
doc
function, and hence the resolver. May be
null
in which case it defaults to the current
working directory.
Need not be the actual URI of the resolver's stream.
MissingResourceException
- if the resolver could not find the resource (unchecked exception)
IOException
- if an I/O error occured while reading the query from the stream
XQueryException
- if the query has a syntax error, or if it references
namespaces, variables, or functions that have not been
declared, or contains other static errors such as type mismatches.
|
Nux 1.0 | ||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |