XBRLAPI

A Java API for XBRL


org.xbrlapi.data.exist
Class StoreImpl

java.lang.Object
  extended by org.xbrlapi.data.BaseStoreImpl
      extended by org.xbrlapi.data.exist.StoreImpl
All Implemented Interfaces:
Serializable, Store

public class StoreImpl
extends BaseStoreImpl
implements Store

Implementation of the XBRL data store using eXist as the underlying database.

Author:
Geoffrey Shuetrim (geoff@galexy.net)
See Also:
Serialized Form

Field Summary
protected static String configurationRoot
           
 
Fields inherited from class org.xbrlapi.data.BaseStoreImpl
domImplementation, matcher, namespaceBindings, storeDOM
 
Constructor Summary
StoreImpl(String host, String port, String database, String username, String password, String storeParentPath, String dataCollectionName)
          Initialise the database connection.
 
Method Summary
 void close()
          Close the data store.
 void delete()
          Close and then delete the data store.
 DBConnection getConnection()
           
 int getSize()
           
<F extends XML>
F
getXMLResource(String index)
          Retrieves a fragment from an XBRL API data store.
 boolean hasXMLResource(String index)
          Test if a store contains a specific fragment, as identified by its index.
 void persist(XML xml)
          Add a fragment to the DTS.
 long queryCount(String query)
          This method must be synchronised
 Set<String> queryForIndices(String query)
          Run a query against the collection of all fragments in the store.
 Set<String> queryForStrings(String query)
          Run a query that is required to return a sequence of strings.
<F extends XML>
List<F>
queryForXMLResources(String query)
          Run a query against the collection of all fragments in the store.
 void remove(String index)
          Remove a fragment from the DTS.
 void remove(XML xml)
          Remove a XML resource from the underlying data structure.
 String toString()
           
 
Methods inherited from class org.xbrlapi.data.BaseStoreImpl
augmentNetworkForFragment, augmentNetworksForFragment, clearFilteringURIs, deleteDocument, deleteRelatedDocuments, DOM2String, equals, finalize, getAllFactIndices, getAllFacts, getAllFacts, getAnalyser, getArcIndices, getArcIndices, getArcroles, getArcroles, getArcroleTypes, getArcroleTypes, getArcs, getArcs, getChildFragments, getChildFragments, getCompositeDocument, getConcept, getDocumentAsDOM, getDocumentsToDiscover, getDocumentURIs, getExtendedLinkIndices, getExtendedLinks, getFactIndices, getFacts, getFacts, getFacts, getFacts, getFilteringURIs, getFollowingSibling, getFragmentIndices, getFragmentIndicesFromDocument, getFragmentIndicesFromDocument, getFragmentsFromDocument, getFragmentsFromDocument, getGlobalDeclaration, getId, getItems, getItems, getLabels, getLabels, getLabels, getLabels, getLabels, getLanguage, getLanguageMap, getLanguages, getLinkRoles, getLinkRoles, getMatcher, getMinimalNetwork, getMinimalNetworksWithArcrole, getMinimalNetworksWithArcrole, getMinimumDocumentSet, getMinimumDocumentSet, getMissingDocumentURIs, getNetworkRoots, getNetworks, getNetworks, getNetworks, getNetworksFrom, getNetworksFrom, getNetworksFrom, getNetworksTo, getNetworksTo, getNetworksTo, getNumberOfXMLResources, getReferencedDocuments, getReferences, getReferences, getReferences, getReferences, getReferences, getReferencingDocuments, getReferencingFragments, getRelationshipsFrom, getRelationshipsTo, getResourceRoles, getRoleTypes, getRoleTypes, getRootFragmentForDocument, getRootFragmentIndices, getRootFragments, getRootFragments, getSchema, getSchemaContent, getSourceIndices, getSources, getStoreAsDOM, getStubs, getStubs, getSubtree, getTargets, getTuples, getTuples, getURIFilteringPredicate, getXMLResources, getXMLResources, hasAllRelationships, hasDocument, hashCode, isFilteringByURIs, isLoading, isPersistingRelationships, persistLoaderState, persistStub, queryForString, recindLoadingRightsFor, removeStub, requestLoadingRightsFor, saveDocuments, saveDocuments, saveStoreAsSingleDocument, serialize, serialize, serialize, setAnalyser, setFilteringURIs, setMatcher, setNamespaceBinding, startLoading, stopLoading, sync
 
Methods inherited from class java.lang.Object
clone, getClass, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface org.xbrlapi.data.Store
augmentNetworkForFragment, augmentNetworksForFragment, clearFilteringURIs, deleteDocument, deleteRelatedDocuments, getAllFactIndices, getAllFacts, getAllFacts, getAnalyser, getArcIndices, getArcIndices, getArcroles, getArcroles, getArcroleTypes, getArcroleTypes, getArcs, getArcs, getChildFragments, getChildFragments, getCompositeDocument, getConcept, getDocumentAsDOM, getDocumentsToDiscover, getDocumentURIs, getExtendedLinkIndices, getExtendedLinks, getFactIndices, getFacts, getFacts, getFacts, getFacts, getFilteringURIs, getFragmentIndices, getFragmentIndicesFromDocument, getFragmentIndicesFromDocument, getFragmentsFromDocument, getFragmentsFromDocument, getGlobalDeclaration, getId, getItems, getItems, getLabels, getLabels, getLabels, getLabels, getLabels, getLanguage, getLanguageMap, getLanguages, getLinkRoles, getLinkRoles, getMatcher, getMinimalNetwork, getMinimalNetworksWithArcrole, getMinimalNetworksWithArcrole, getMinimumDocumentSet, getMinimumDocumentSet, getMissingDocumentURIs, getNetworkRoots, getNetworks, getNetworks, getNetworks, getNetworksFrom, getNetworksFrom, getNetworksFrom, getNetworksTo, getNetworksTo, getNetworksTo, getNumberOfXMLResources, getReferencedDocuments, getReferences, getReferences, getReferences, getReferences, getReferences, getReferencingDocuments, getReferencingFragments, getRelationshipsFrom, getRelationshipsTo, getResourceRoles, getRoleTypes, getRoleTypes, getRootFragmentForDocument, getRootFragmentIndices, getRootFragments, getRootFragments, getSchema, getSchemaContent, getSourceIndices, getSources, getStoreAsDOM, getStubs, getStubs, getSubtree, getTargets, getTuples, getTuples, getXMLResources, getXMLResources, hasAllRelationships, hasDocument, isFilteringByURIs, isLoading, isPersistingRelationships, persistLoaderState, persistStub, queryForString, recindLoadingRightsFor, removeStub, requestLoadingRightsFor, saveDocuments, saveDocuments, saveStoreAsSingleDocument, serialize, serialize, serialize, setAnalyser, setFilteringURIs, setMatcher, setNamespaceBinding, startLoading, stopLoading, sync
 

Field Detail

configurationRoot

protected static final String configurationRoot
See Also:
Constant Field Values
Constructor Detail

StoreImpl

public StoreImpl(String host,
                 String port,
                 String database,
                 String username,
                 String password,
                 String storeParentPath,
                 String dataCollectionName)
          throws XBRLException
Initialise the database connection.

Parameters:
host - Host DB server IP address or domain name
port - Host DB server port
database - Database name
username - Username of the database user
password - Password of the database user
storeParentPath - The full path to the container collection, which is the collection that will hold the data collection when it are created.
dataCollectionName - The name of the data collection.
Throws:
XBRLException
Method Detail

getConnection

public DBConnection getConnection()
Returns:
the database connection or null if there is none.

close

public void close()
           throws XBRLException
Close the data store. Throws XBRLException if the data store cannot be closed.

Specified by:
close in interface Store
Overrides:
close in class BaseStoreImpl
Throws:
XBRLException
See Also:
Store.close()

delete

public void delete()
            throws XBRLException
Description copied from interface: Store
Close and then delete the data store. This method must be synchronized.

Specified by:
delete in interface Store
Throws:
XBRLException - if the data store cannot be deleted.
See Also:
Store.delete()

getSize

public int getSize()
            throws XBRLException
Specified by:
getSize in interface Store
Returns:
the number of fragments in the data store.
Throws:
XBRLException - if the number of fragments cannot be determined.
See Also:
Store.persist(XML)

persist

public void persist(XML xml)
             throws XBRLException
Add a fragment to the DTS. Sets the fragment builder to null because it is no longer required, stores the fragment data and metadata in the data store, sets the store property in the fragment.

Specified by:
persist in interface Store
Parameters:
xml - The fragment to be added to the DTS store.
Throws:
XBRLException - if the fragment cannot be added to the store (eg: because one with the same index is already in the store).

hasXMLResource

public boolean hasXMLResource(String index)
                       throws XBRLException
Test if a store contains a specific fragment, as identified by its index.

Specified by:
hasXMLResource in interface Store
Parameters:
index - The index of the fragment to test for.
Returns:
true iff the store contains a fragment with the specified fragment index.
Throws:
XBRLException - If the test cannot be conducted.

getXMLResource

public <F extends XML> F getXMLResource(String index)
                             throws XBRLException
Retrieves a fragment from an XBRL API data store. The fragment will be created as a fragment of the original fragment type but will be returned as a straight fragment.

Specified by:
getXMLResource in interface Store
Parameters:
index - The index of the fragment.
Returns:
The fragment corresponding to the specified index or null if the fragment is not in the store.
Throws:
XBRLException - if the fragment cannot be retrieved.

remove

public void remove(String index)
            throws XBRLException
Remove a fragment from the DTS. If a fragment with the same ID does not already exist in the DTs then no action is required.

Specified by:
remove in interface Store
Parameters:
index - The index of the fragment to be removed from the DTS store.
Throws:
XBRLException - if the fragment cannot be removed from the store.

remove

public void remove(XML xml)
            throws XBRLException
Description copied from interface: Store
Remove a XML resource from the underlying data structure. If a XML resource with the same ID does not already exist in the data store then no action is required.

Specified by:
remove in interface Store
Overrides:
remove in class BaseStoreImpl
Parameters:
xml - The XML resource to remove.
Throws:
XBRLException - if the XML resource cannot be removed from the store.
See Also:
Store.remove(XML)

queryForXMLResources

public <F extends XML> List<F> queryForXMLResources(String query)
                                         throws XBRLException
Description copied from interface: Store
Run a query against the collection of all fragments in the store. Implementations of this method must be synchronized.

Specified by:
queryForXMLResources in interface Store
Parameters:
query - The XQuery query to run against the set of fragments. Any occurrences of the string #roots# in a query will be deemed to be a marker for the root elements of the fragments in an XML database collection and it will be substituted with the necessary expression to identify those roots in the data store.
Returns:
a list of matching fragments or the empty list if no matching fragments exist.
Throws:
XBRLException - if the query cannot be executed.
See Also:
Store.queryForXMLResources(String)

queryCount

public long queryCount(String query)
                throws XBRLException
Description copied from interface: Store
This method must be synchronised

Specified by:
queryCount in interface Store
Parameters:
query - The XQuery to run. Any occurrences of the string #roots# in a query will be deemed to be a marker for the root elements of the fragments in an XML database collection and it will be substituted with the necessary expression to identify those roots in the data store.
Returns:
a count of the number of results returned by the query.
Throws:
XBRLException - if the query cannot be executed.
See Also:
Store.queryCount(String)

queryForIndices

public Set<String> queryForIndices(String query)
                            throws XBRLException
Description copied from interface: Store
Run a query against the collection of all fragments in the store. Implementations of this method must be synchronized.

Specified by:
queryForIndices in interface Store
Parameters:
query - The XQuery query to run against the set of fragments. Any occurrences of the string #roots# in a query will be deemed to be a marker for the root elements of the fragments in an XML database collection and it will be substituted with the necessary expression to identify those roots in the data store. The query MUST return a sequence of XML resource metadata root elements matching the query. Otherwise, results from the query will be unpredictable.
Returns:
a set of the indices of XML resources matching the query.
Throws:
XBRLException - if the query cannot be executed.
See Also:
Store.queryForIndices(String)

queryForStrings

public Set<String> queryForStrings(String query)
                            throws XBRLException
Description copied from interface: Store
Run a query that is required to return a sequence of strings. Implementations of this method must be synchronized.

Specified by:
queryForStrings in interface Store
Parameters:
query - The XQuery query to run against the set of fragments. Any occurrences of the string #roots# in a query will be deemed to be a marker for the root elements of the fragments in an XML database collection and it will be substituted with the necessary expression to identify those roots in the data store.
Returns:
a list of strings, each of which is a query result.
Throws:
XBRLException - if the query cannot be executed or if the query results are not strings.
See Also:
Store.queryForStrings(String)

toString

public String toString()
Overrides:
toString in class Object

Get Java XBRL API implementation at SourceForge.net.