org.openxri.store.impl.db
Class DatabaseStore

java.lang.Object
  extended by org.openxri.config.impl.AbstractComponent
      extended by org.openxri.store.impl.AbstractStore
          extended by org.openxri.store.impl.db.DatabaseStore
All Implemented Interfaces:
java.io.Serializable, Component, Store, StoreAttributable, StoreBetterLookup, StoreEditable, StoreLookup, StoreMountable, StoreResettable, StoreStatistics

public class DatabaseStore
extends AbstractStore
implements Store, StoreLookup, StoreBetterLookup, StoreEditable, StoreResettable, StoreAttributable, StoreMountable, StoreStatistics

A class using Hibernate for implementing the basic and several extended store operations. It expects Hibernate parameters in the store arguments which should be present in the OpenXRI server configuration (e.g. in the properties file).

Author:
=peacekeeper
See Also:
Serialized Form

Nested Class Summary
 
Nested classes/interfaces inherited from interface org.openxri.store.StoreAttributable
StoreAttributable.Selector
 
Field Summary
protected  org.hibernate.cfg.Configuration configuration
           
static int MAX_ALIAS_RECURSION
           
protected  org.hibernate.SessionFactory sessionFactory
           
 
Fields inherited from class org.openxri.config.impl.AbstractComponent
properties
 
Constructor Summary
DatabaseStore(java.util.Properties properties)
           
 
Method Summary
 void close()
           
 Authority createAuthority(XRD xrd)
          Creates an authority without associating it with a subsegment.
 SubSegment createRootSubSegment(java.lang.String name, XRD xrd)
          Creates a root subsegment (entry-point namespace to the server).
 void deleteAuthority(Authority authority)
          Deletes an authority and any subsegments registered underneath it.
 void deleteRootSubSegment(java.lang.String name)
          Deletes the root subsegment (namespace) associated with an authority.
 SubSegment findRootSubSegment(java.lang.String namespace)
          Finds a root subsegment with a given name.
 SubSegment findSubSegment(Authority parentAuthority, java.lang.String name)
          Finds a subsegment with a given authority and name.
 java.util.Map<java.lang.String,java.lang.String> getAuthorityAttributes(Authority authority)
          Gets attributes from an authority.
 SubSegment[] getAuthorityChildSubSegments(Authority parent)
          Gets all subsegments that have this authority as parent.
 java.lang.Long getAuthorityCount()
           
 java.lang.String getAuthorityIndex(Authority authority)
          Gets the index of the authority.
 java.lang.String getAuthorityPath(Authority authority)
          Returns the path at which the authority is mounted.
 java.lang.String[] getAuthorityQxris(Authority authority)
          Gets all full XRIs that lead to this authority.
 java.lang.String[] getAuthorityQxris(Authority authority, boolean reassignable, boolean persistent)
          Gets all full XRIs that lead to this authority.
 SubSegment[] getAuthoritySubSegments(Authority authority)
          Gets all subsegments that lead to this authority.
 org.hibernate.SessionFactory getSessionFactory()
          Checks if the database connection is still alive; if not, try to reconnect, then throw exception.
 java.util.Map<java.lang.String,java.lang.String> getStoreAttributes()
          Gets attributes from the store.
 java.util.Map<java.lang.String,java.lang.String> getSubSegmentAttributes(SubSegment subSegment)
          Gets attributes from a subsegment.
 Authority getSubSegmentAuthority(SubSegment subSegment)
          Returns the authority of this subsegment.
 java.lang.Long getSubSegmentCount()
           
 java.lang.String getSubSegmentIndex(SubSegment subSegment)
          Gets the index of the subsegment.
 Authority getSubSegmentParentAuthority(SubSegment subSegment)
          Returns the authority of this subsegment.
 SubSegment[] getSynonymSubSegments(Authority parent, Authority authority)
          Gets all subsegments with a given parent authority and authority.
 void init()
          A server component is constructed by the ComponentRegistry by passing a Properties object to its constructor and then calling this init() method.
 boolean isClosed()
           
 Authority[] listAuthorities()
          Returns all authorities.
 Authority[] listAuthoritiesByAttributes(StoreAttributable.Selector selector)
          Returns all authorities whose attributes satisfy certain conditions.
 Authority[] listAuthoritiesByAttributeValue(java.lang.String key, java.lang.String value)
          Returns all authorities with a certain attribute key/value pair.
 Authority[] listAuthoritiesByIndex(java.lang.String indx)
          Returns all authorities with a certain index.
 Authority[] listAuthoritiesByPath(java.lang.String path)
          Returns all authorities mounted at a given path.
 SubSegment[] listRootSubSegments()
          Lists all of the root subsegments (namespaces) on the server.
 SubSegment[] listSubSegments()
          Returns all subsegments.
 SubSegment[] listSubSegmentsByAttributes(StoreAttributable.Selector selector)
          Returns all subsegments whose attributes satisfy certain conditions.
 SubSegment[] listSubSegmentsByAttributeValue(java.lang.String key, java.lang.String value)
          Returns all subsegments whose attributes satisfy certain conditions.
 SubSegment[] listSubSegmentsByIndex(java.lang.String indx)
          Returns all subsegments with a certain index.
 Authority localLookup(XRIAuthority authorityPath)
          This method iterates through all subsegments of the given authority path and returns its final authority.
 SubSegment registerSubsegment(Authority parentAuthority, java.lang.String subSegmentName, Authority authority)
          Registers a new subsegment using an already existing authority.
 SubSegment registerSubsegment(Authority parentAuthority, java.lang.String subSegmentName, XRD xrd)
          Registers a subsegment with a new authority.
 void releaseSubSegment(SubSegment subSegment)
          Releases the descriptor information associated with a registered subsegment.
 void resetStore()
          Takes a Store implementation back to a known clean state.
 void setAuthorityAttributes(Authority authority, java.util.Map<java.lang.String,java.lang.String> attributes)
          Associates attributes with an authority.
 void setAuthorityIndex(Authority authority, java.lang.String indx)
          Associates an index with an authority.
 void setAuthorityPath(Authority authority, java.lang.String path)
          Mounts an authority at a given path.
 void setSessionFactory(org.hibernate.SessionFactory sessionFactory)
          Allow the connection to be changed externally.
 void setStoreAttributes(java.util.Map<java.lang.String,java.lang.String> attributes)
          Associates attributes with the store.
 void setSubSegmentAttributes(SubSegment subSegment, java.util.Map<java.lang.String,java.lang.String> attributes)
          Associates attributes with a subsegment.
 void setSubSegmentIndex(SubSegment subSegment, java.lang.String indx)
          Associates an index with a subsegment.
 void setXrd(Authority authority, XRD xrd)
          Sets the XRD of an authority.
 
Methods inherited from class org.openxri.config.impl.AbstractComponent
getProperties
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface org.openxri.config.Component
getProperties
 

Field Detail

MAX_ALIAS_RECURSION

public static final int MAX_ALIAS_RECURSION
See Also:
Constant Field Values

configuration

protected org.hibernate.cfg.Configuration configuration

sessionFactory

protected org.hibernate.SessionFactory sessionFactory
Constructor Detail

DatabaseStore

public DatabaseStore(java.util.Properties properties)
Method Detail

init

public void init()
          throws StoreException
Description copied from interface: Component
A server component is constructed by the ComponentRegistry by passing a Properties object to its constructor and then calling this init() method.

Specified by:
init in interface Component
Throws:
StoreException

close

public void close()

isClosed

public boolean isClosed()

getSessionFactory

public org.hibernate.SessionFactory getSessionFactory()
                                               throws StoreException
Checks if the database connection is still alive; if not, try to reconnect, then throw exception.

Returns:
The database connection.
Throws:
StoreException

setSessionFactory

public void setSessionFactory(org.hibernate.SessionFactory sessionFactory)
Allow the connection to be changed externally.

Parameters:
sessionFactory -

listRootSubSegments

public SubSegment[] listRootSubSegments()
                                 throws StoreException
Description copied from interface: Store
Lists all of the root subsegments (namespaces) on the server.

Specified by:
listRootSubSegments in interface Store
Throws:
StoreException

createAuthority

public Authority createAuthority(XRD xrd)
                          throws StoreException
Description copied from interface: Store
Creates an authority without associating it with a subsegment. You probably want to use registerSubsegment() instead, which creates both and authority and an associated subsegment.

Specified by:
createAuthority in interface Store
Parameters:
xrd - An initial XRD that will be run through the default create pipeline and then associated with the new authority.
Throws:
StoreException

createRootSubSegment

public SubSegment createRootSubSegment(java.lang.String name,
                                       XRD xrd)
                                throws StoreException
Description copied from interface: Store
Creates a root subsegment (entry-point namespace to the server).

Specified by:
createRootSubSegment in interface Store
Parameters:
name - The name of the new root subsegment.
xrd - The XRD of the authority associated with the root subsegment.
Throws:
StoreException

deleteRootSubSegment

public void deleteRootSubSegment(java.lang.String name)
                          throws StoreException
Description copied from interface: Store
Deletes the root subsegment (namespace) associated with an authority. Does not delete the authority itself.

Specified by:
deleteRootSubSegment in interface Store
Parameters:
name - The root subsegment (namespace) to delete.
Throws:
StoreException

deleteAuthority

public void deleteAuthority(Authority authority)
                     throws StoreException
Description copied from interface: Store
Deletes an authority and any subsegments registered underneath it. It does not delete any authorities registered for those subsegments.

Specified by:
deleteAuthority in interface Store
Parameters:
authority - The authority to delete
Throws:
StoreException

registerSubsegment

public SubSegment registerSubsegment(Authority parentAuthority,
                                     java.lang.String subSegmentName,
                                     XRD xrd)
                              throws StoreException
Description copied from interface: Store
Registers a subsegment with a new authority.

Specified by:
registerSubsegment in interface Store
Parameters:
parentAuthority - The authority to register under.
subSegmentName - The name of the subsegment to register.
xrd - An initial XRD that will be run through the default create pipeline and then associated with the new authority.
Throws:
StoreException

registerSubsegment

public SubSegment registerSubsegment(Authority parentAuthority,
                                     java.lang.String subSegmentName,
                                     Authority authority)
                              throws StoreException
Description copied from interface: Store
Registers a new subsegment using an already existing authority.

Specified by:
registerSubsegment in interface Store
Parameters:
parentAuthority - The authority id to register under.
subSegmentName - The name of the subsegment to register.
authority - The existing authority for the subsegment.
Throws:
StoreException

releaseSubSegment

public void releaseSubSegment(SubSegment subSegment)
                       throws StoreException
Description copied from interface: Store
Releases the descriptor information associated with a registered subsegment.

Specified by:
releaseSubSegment in interface Store
Parameters:
subSegment - The subsegment to release.
Throws:
StoreException

findRootSubSegment

public SubSegment findRootSubSegment(java.lang.String namespace)
                              throws StoreException
Description copied from interface: StoreLookup
Finds a root subsegment with a given name.

Specified by:
findRootSubSegment in interface StoreLookup
Parameters:
namespace - The namespace (root subsegment) to look for.
Returns:
The found root subsegment, or null if it could not be found.
Throws:
StoreException

findSubSegment

public SubSegment findSubSegment(Authority parentAuthority,
                                 java.lang.String name)
                          throws StoreException
Description copied from interface: StoreLookup
Finds a subsegment with a given authority and name.

Specified by:
findSubSegment in interface StoreLookup
Parameters:
parentAuthority - The authority to look for.
name - The subsegment name to look for.
Returns:
The found subsegment, or null if it could not be found.
Throws:
StoreException

getSubSegmentParentAuthority

public Authority getSubSegmentParentAuthority(SubSegment subSegment)
                                       throws StoreException
Description copied from interface: StoreLookup
Returns the authority of this subsegment.

Specified by:
getSubSegmentParentAuthority in interface StoreLookup
Parameters:
subSegment - subsegment
Returns:
The authority for this subsegment; null if this store has no authority for the subsegment
Throws:
StoreException

getSubSegmentAuthority

public Authority getSubSegmentAuthority(SubSegment subSegment)
                                 throws StoreException
Description copied from interface: StoreLookup
Returns the authority of this subsegment.

Specified by:
getSubSegmentAuthority in interface StoreLookup
Parameters:
subSegment - subsegment
Returns:
The authority for this subsegment; null if this store has no authority for the subsegment
Throws:
StoreException

resetStore

public void resetStore()
                throws StoreException
Description copied from interface: StoreResettable
Takes a Store implementation back to a known clean state. Stores should implement this interface if possible, but are not required to do so.

Specified by:
resetStore in interface StoreResettable
Throws:
StoreException

listAuthorities

public Authority[] listAuthorities()
                            throws StoreException
Description copied from interface: StoreBetterLookup
Returns all authorities.

Specified by:
listAuthorities in interface StoreBetterLookup
Returns:
A list of authorities
Throws:
StoreException

listSubSegments

public SubSegment[] listSubSegments()
                             throws StoreException
Description copied from interface: StoreBetterLookup
Returns all subsegments.

Specified by:
listSubSegments in interface StoreBetterLookup
Returns:
A list of subsegments
Throws:
StoreException

getAuthoritySubSegments

public SubSegment[] getAuthoritySubSegments(Authority authority)
                                     throws StoreException
Description copied from interface: StoreBetterLookup
Gets all subsegments that lead to this authority.

Specified by:
getAuthoritySubSegments in interface StoreBetterLookup
Parameters:
authority - authority for which subsegments should be found
Returns:
An array of subsegments.
Throws:
StoreException

getAuthorityChildSubSegments

public SubSegment[] getAuthorityChildSubSegments(Authority parent)
                                          throws StoreException
Description copied from interface: StoreBetterLookup
Gets all subsegments that have this authority as parent.

Specified by:
getAuthorityChildSubSegments in interface StoreBetterLookup
Parameters:
parent - authority for which child subsegments should be found
Returns:
An array of subsegments.
Throws:
StoreException

getSynonymSubSegments

public SubSegment[] getSynonymSubSegments(Authority parent,
                                          Authority authority)
                                   throws StoreException
Description copied from interface: StoreBetterLookup
Gets all subsegments with a given parent authority and authority. All returned subsegments have the same parent authority and authority, and are therefore local synonyms.

Specified by:
getSynonymSubSegments in interface StoreBetterLookup
Parameters:
parent - authority for which child subsegments should be found
authority - authority for which subsegments should be found
Returns:
An array of subsegments.
Throws:
StoreException

getAuthorityQxris

public java.lang.String[] getAuthorityQxris(Authority authority)
                                     throws StoreException
Description copied from interface: StoreBetterLookup
Gets all full XRIs that lead to this authority. If it is a root authority, this is just the namespace, otherwise it's the namespace of the root authority plus names of subsegments. Usually just one result, unless there are aliases in the subsegment chain.

Specified by:
getAuthorityQxris in interface StoreBetterLookup
Parameters:
authority - Authority for which all full names should be found
Returns:
An array of QXRIs.
Throws:
StoreException

getAuthorityQxris

public java.lang.String[] getAuthorityQxris(Authority authority,
                                            boolean reassignable,
                                            boolean persistent)
                                     throws StoreException
Description copied from interface: StoreBetterLookup
Gets all full XRIs that lead to this authority. If it is a root authority, this is just the namespace, otherwise it's the namespace of the root authority plus names of subsegments. Usually just one result, unless there are aliases in the subsegment chain. The reassignable and persistent parameters can be used to only read i-names or i-numbers from the store.

Specified by:
getAuthorityQxris in interface StoreBetterLookup
Parameters:
authority - Authority for which all full names should be found
reassignable - Whether to consider reassignable subsegments when constructing XRIs.
persistent - Whether to consider persistent subsegments when constructing XRIs.
Returns:
An array of QXRIs.
Throws:
StoreException

localLookup

public Authority localLookup(XRIAuthority authorityPath)
                      throws StoreException
Description copied from interface: StoreLookup
This method iterates through all subsegments of the given authority path and returns its final authority. This only works if all subsegments are part of this store and if the whole authority path is in one of its root namespaces.

Specified by:
localLookup in interface StoreLookup
Parameters:
authorityPath - The XRI authority path to resolve
Returns:
The matching authority or null
Throws:
StoreException

setStoreAttributes

public void setStoreAttributes(java.util.Map<java.lang.String,java.lang.String> attributes)
                        throws StoreException
Description copied from interface: StoreAttributable
Associates attributes with the store.

Specified by:
setStoreAttributes in interface StoreAttributable
Parameters:
attributes - The attributes.
Throws:
StoreException

getStoreAttributes

public java.util.Map<java.lang.String,java.lang.String> getStoreAttributes()
                                                                    throws StoreException
Description copied from interface: StoreAttributable
Gets attributes from the store.

Specified by:
getStoreAttributes in interface StoreAttributable
Returns:
The attributes, or null.
Throws:
StoreException

setAuthorityAttributes

public void setAuthorityAttributes(Authority authority,
                                   java.util.Map<java.lang.String,java.lang.String> attributes)
                            throws StoreException
Description copied from interface: StoreAttributable
Associates attributes with an authority.

Specified by:
setAuthorityAttributes in interface StoreAttributable
Parameters:
authority - The authority.
attributes - The attributes.
Throws:
StoreException

getAuthorityAttributes

public java.util.Map<java.lang.String,java.lang.String> getAuthorityAttributes(Authority authority)
                                                                        throws StoreException
Description copied from interface: StoreAttributable
Gets attributes from an authority.

Specified by:
getAuthorityAttributes in interface StoreAttributable
Parameters:
authority - The authority.
Returns:
The attributes, or null.
Throws:
StoreException

setAuthorityIndex

public void setAuthorityIndex(Authority authority,
                              java.lang.String indx)
                       throws StoreException
Description copied from interface: StoreAttributable
Associates an index with an authority.

Specified by:
setAuthorityIndex in interface StoreAttributable
Parameters:
authority - The authority.
indx - The index for the authority.
Throws:
StoreException

getAuthorityIndex

public java.lang.String getAuthorityIndex(Authority authority)
                                   throws StoreException
Description copied from interface: StoreAttributable
Gets the index of the authority.

Specified by:
getAuthorityIndex in interface StoreAttributable
Throws:
StoreException

setSubSegmentAttributes

public void setSubSegmentAttributes(SubSegment subSegment,
                                    java.util.Map<java.lang.String,java.lang.String> attributes)
                             throws StoreException
Description copied from interface: StoreAttributable
Associates attributes with a subsegment.

Specified by:
setSubSegmentAttributes in interface StoreAttributable
Parameters:
subSegment - The subsegment.
attributes - The attributes.
Throws:
StoreException

getSubSegmentAttributes

public java.util.Map<java.lang.String,java.lang.String> getSubSegmentAttributes(SubSegment subSegment)
                                                                         throws StoreException
Description copied from interface: StoreAttributable
Gets attributes from a subsegment.

Specified by:
getSubSegmentAttributes in interface StoreAttributable
Parameters:
subSegment - The subsegment.
Returns:
The attributes, or null.
Throws:
StoreException

setSubSegmentIndex

public void setSubSegmentIndex(SubSegment subSegment,
                               java.lang.String indx)
                        throws StoreException
Description copied from interface: StoreAttributable
Associates an index with a subsegment.

Specified by:
setSubSegmentIndex in interface StoreAttributable
Parameters:
subSegment - The subsegment.
indx - The index for the subsegment.
Throws:
StoreException

getSubSegmentIndex

public java.lang.String getSubSegmentIndex(SubSegment subSegment)
                                    throws StoreException
Description copied from interface: StoreAttributable
Gets the index of the subsegment.

Specified by:
getSubSegmentIndex in interface StoreAttributable
Parameters:
subSegment - The subsegment.
Throws:
StoreException

listAuthoritiesByAttributes

public Authority[] listAuthoritiesByAttributes(StoreAttributable.Selector selector)
                                        throws StoreException
Description copied from interface: StoreAttributable
Returns all authorities whose attributes satisfy certain conditions.

Specified by:
listAuthoritiesByAttributes in interface StoreAttributable
Parameters:
selector - An object that can select authorities based on their attributes.
Returns:
An array of authorities.
Throws:
StoreException

listSubSegmentsByAttributes

public SubSegment[] listSubSegmentsByAttributes(StoreAttributable.Selector selector)
                                         throws StoreException
Description copied from interface: StoreAttributable
Returns all subsegments whose attributes satisfy certain conditions.

Specified by:
listSubSegmentsByAttributes in interface StoreAttributable
Parameters:
selector - An object that can select authorities based on their attributes.
Returns:
An array of subsegments.
Throws:
StoreException

listAuthoritiesByAttributeValue

public Authority[] listAuthoritiesByAttributeValue(java.lang.String key,
                                                   java.lang.String value)
                                            throws StoreException
Description copied from interface: StoreAttributable
Returns all authorities with a certain attribute key/value pair.

Specified by:
listAuthoritiesByAttributeValue in interface StoreAttributable
Parameters:
key - An attribute key.
value - An attribute value.
Returns:
An array of authorities.
Throws:
StoreException

listSubSegmentsByAttributeValue

public SubSegment[] listSubSegmentsByAttributeValue(java.lang.String key,
                                                    java.lang.String value)
                                             throws StoreException
Description copied from interface: StoreAttributable
Returns all subsegments whose attributes satisfy certain conditions.

Specified by:
listSubSegmentsByAttributeValue in interface StoreAttributable
Parameters:
key - An attribute key.
value - An attribute value.
Returns:
An array of subsegments.
Throws:
StoreException

listAuthoritiesByIndex

public Authority[] listAuthoritiesByIndex(java.lang.String indx)
                                   throws StoreException
Description copied from interface: StoreAttributable
Returns all authorities with a certain index.

Specified by:
listAuthoritiesByIndex in interface StoreAttributable
Parameters:
indx - The index to look for.
Returns:
An array of authorities.
Throws:
StoreException

listSubSegmentsByIndex

public SubSegment[] listSubSegmentsByIndex(java.lang.String indx)
                                    throws StoreException
Description copied from interface: StoreAttributable
Returns all subsegments with a certain index.

Specified by:
listSubSegmentsByIndex in interface StoreAttributable
Parameters:
indx - The index to look for.
Returns:
An array of subsegments.
Throws:
StoreException

setXrd

public void setXrd(Authority authority,
                   XRD xrd)
            throws StoreException
Description copied from interface: StoreEditable
Sets the XRD of an authority.

Specified by:
setXrd in interface StoreEditable
Parameters:
authority - The authority.
xrd - The XRD to set for the authority.
Throws:
StoreException

setAuthorityPath

public void setAuthorityPath(Authority authority,
                             java.lang.String path)
                      throws StoreException
Description copied from interface: StoreMountable
Mounts an authority at a given path.

Specified by:
setAuthorityPath in interface StoreMountable
Parameters:
authority - The authority to mount.
path - The path at which to mount the authority (null to unmount it).
Throws:
StoreException

getAuthorityPath

public java.lang.String getAuthorityPath(Authority authority)
                                  throws StoreException
Description copied from interface: StoreMountable
Returns the path at which the authority is mounted.

Specified by:
getAuthorityPath in interface StoreMountable
Parameters:
authority - The authority to check.
Returns:
The mount path of the authority, or null if the authority is not mounted.
Throws:
StoreException

listAuthoritiesByPath

public Authority[] listAuthoritiesByPath(java.lang.String path)
                                  throws StoreException
Description copied from interface: StoreMountable
Returns all authorities mounted at a given path.

Specified by:
listAuthoritiesByPath in interface StoreMountable
Parameters:
path - The mount path to look for.
Returns:
An array of authorities.
Throws:
StoreException

getAuthorityCount

public java.lang.Long getAuthorityCount()
                                 throws StoreException
Specified by:
getAuthorityCount in interface StoreStatistics
Returns:
The number of authorities in the store
Throws:
StoreException

getSubSegmentCount

public java.lang.Long getSubSegmentCount()
                                  throws StoreException
Specified by:
getSubSegmentCount in interface StoreStatistics
Returns:
The number of subsegments in the store
Throws:
StoreException


Copyright © 2005-2012. All Rights Reserved.