org.ametys.plugins.datainclusion.data.jcr
Class JcrQueryDao

java.lang.Object
  extended by org.apache.avalon.framework.logger.AbstractLogEnabled
      extended by org.ametys.plugins.datainclusion.data.jcr.JcrQueryDao
All Implemented Interfaces:
QueryDao, Component, LogEnabled, Serviceable

public class JcrQueryDao
extends AbstractLogEnabled
implements QueryDao, Serviceable, Component

JCR implementation of the Query DAO. This class manages DataSource and Query objects, storing them in the JCR repository.


Field Summary
protected  DataSourceFactoryExtensionPoint _dataSourceFactoryEP
          The Data Source factory extension point.
protected  javax.jcr.Repository _repository
          The JCR repository.
protected  org.ametys.web.repository.site.SiteManager _siteManager
          The Site manager.
static String DATASOURCES_NODE
          Data sources node name.
static String PLUGIN_NODE
          Plugin root node name.
static String PLUGINS_NODE
          Plugins root node name.
static String PROPERTY_CONF_PREFIX
          Configuration properties prefix.
static String PROPERTY_DESCRIPTION
          "Description" property name.
static String PROPERTY_NAME
          "Name" property name.
static String PROPERTY_TYPE
          "Type" property name.
static String QUERIES_NODE
          Queries node name.
static String QUERY_PROPERTY_DATASOURCE
          Query "dataSource" property name.
static String QUERY_PROPERTY_PARAMETERS
          Query "parameters" property name.
static String QUERY_PROPERTY_QUERYSTRING
          Query "query string" property name.
static String QUERY_PROPERTY_RESULTTYPE
          Query "resultType" property name.
static String ROOT_REPO
          JCR relative path to root node.
 
Fields inherited from interface org.ametys.plugins.datainclusion.data.QueryDao
ROLE
 
Constructor Summary
JcrQueryDao()
           
 
Method Summary
protected  DataSource _extractDataSource(javax.jcr.Node node)
          Create a data source from a node.
protected  Query _extractQuery(javax.jcr.Node node)
          Create a data source from a node.
protected  void _fillDataSourceNode(DataSource dataSource, javax.jcr.Node node)
          Store the data source properties into the JCR node.
protected  void _fillQueryNode(Query query, javax.jcr.Node node)
          Store the query properties into the JCR node.
protected  void _fillQueryNode(Query query, javax.jcr.Node node, javax.jcr.Node dataSourceNode)
          Store the query properties into the JCR node.
protected  void _fillQueryNode(Query query, javax.jcr.Node node, String siteName, String dataSourceId)
          Store the query properties into the JCR node.
protected  Map<String,String> _getAdditionalConf(javax.jcr.Node node)
          Get additional configuration from properties.
protected  javax.jcr.Node _getDataSourcesNode(String siteName)
          Get the data sources root node.
protected  DataSource _getLinkedDataSource(javax.jcr.Node queryNode)
          Get a query's data source from its reference property.
protected  Collection<String> _getMultipleProperty(javax.jcr.Node node, String propertyName)
          Get the values of a string array property.
protected  String _getNotExistingNodeName(javax.jcr.Node container, String baseName)
          Get a name for a node which doesn't already exist in this node.
protected  javax.jcr.Node _getPluginNode(String siteName)
          Get the plugin root node in a site storage space.
protected  javax.jcr.Node _getQueriesNode(String siteName)
          Get the queries root node.
protected  Query.ResultType _getResultType(javax.jcr.Node node, Query.ResultType defaultValue)
          Get a single property value.
protected  String _getSingleProperty(javax.jcr.Node node, String propertyName, String defaultValue)
          Get a single property value.
 String addDataSource(String siteName, DataSource dataSource)
          Add a data source and return its id.
 String addQuery(String siteName, Query query, String dataSourceId)
          Add a query and set its id.
 DataSource getDataSource(String siteName, String id)
          Get a data source from its id.
 Map<String,Query> getDataSourceQueries(String siteName, String dataSourceId)
          Get all the queries of a site.
 Map<String,DataSource> getDataSources(String siteName)
          Get all the data sources of a site.
 Map<String,DataSource> getDataSources(String siteName, String type)
          Get all the data sources of a site and of the specified type.
 Map<String,Query> getQueries(String siteName)
          Get all the queries of a site.
 Map<String,Query> getQueries(String siteName, String type)
          Get all the queries of a site.
 Query getQuery(String siteName, String id)
          Get a query from its id.
 void removeDataSource(String siteName, String id)
          Remove a data source.
 void removeQuery(String siteName, String id)
          Remove a query.
 void service(ServiceManager serviceManager)
           
 void updateDataSource(String siteName, DataSource dataSource)
          Update a data source.
 void updateQuery(String siteName, Query query, String dataSourceId)
          Update a query.
 
Methods inherited from class org.apache.avalon.framework.logger.AbstractLogEnabled
enableLogging, getLogger, setupLogger, setupLogger, setupLogger
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

ROOT_REPO

public static final String ROOT_REPO
JCR relative path to root node.

See Also:
Constant Field Values

PLUGINS_NODE

public static final String PLUGINS_NODE
Plugins root node name.

See Also:
Constant Field Values

PLUGIN_NODE

public static final String PLUGIN_NODE
Plugin root node name.

See Also:
Constant Field Values

DATASOURCES_NODE

public static final String DATASOURCES_NODE
Data sources node name.

See Also:
Constant Field Values

QUERIES_NODE

public static final String QUERIES_NODE
Queries node name.

See Also:
Constant Field Values

PROPERTY_NAME

public static final String PROPERTY_NAME
"Name" property name.

See Also:
Constant Field Values

PROPERTY_DESCRIPTION

public static final String PROPERTY_DESCRIPTION
"Description" property name.

See Also:
Constant Field Values

PROPERTY_TYPE

public static final String PROPERTY_TYPE
"Type" property name.

See Also:
Constant Field Values

PROPERTY_CONF_PREFIX

public static final String PROPERTY_CONF_PREFIX
Configuration properties prefix.

See Also:
Constant Field Values

QUERY_PROPERTY_QUERYSTRING

public static final String QUERY_PROPERTY_QUERYSTRING
Query "query string" property name.

See Also:
Constant Field Values

QUERY_PROPERTY_PARAMETERS

public static final String QUERY_PROPERTY_PARAMETERS
Query "parameters" property name.

See Also:
Constant Field Values

QUERY_PROPERTY_RESULTTYPE

public static final String QUERY_PROPERTY_RESULTTYPE
Query "resultType" property name.

See Also:
Constant Field Values

QUERY_PROPERTY_DATASOURCE

public static final String QUERY_PROPERTY_DATASOURCE
Query "dataSource" property name.

See Also:
Constant Field Values

_dataSourceFactoryEP

protected DataSourceFactoryExtensionPoint _dataSourceFactoryEP
The Data Source factory extension point.


_repository

protected javax.jcr.Repository _repository
The JCR repository.


_siteManager

protected org.ametys.web.repository.site.SiteManager _siteManager
The Site manager.

Constructor Detail

JcrQueryDao

public JcrQueryDao()
Method Detail

service

public void service(ServiceManager serviceManager)
             throws ServiceException
Specified by:
service in interface Serviceable
Throws:
ServiceException

getDataSources

public Map<String,DataSource> getDataSources(String siteName)
                                      throws DataInclusionException
Description copied from interface: QueryDao
Get all the data sources of a site.

Specified by:
getDataSources in interface QueryDao
Parameters:
siteName - the site name.
Returns:
the data sources as a Map.
Throws:
DataInclusionException

getDataSources

public Map<String,DataSource> getDataSources(String siteName,
                                             String type)
                                      throws DataInclusionException
Description copied from interface: QueryDao
Get all the data sources of a site and of the specified type.

Specified by:
getDataSources in interface QueryDao
Parameters:
siteName - the site name.
type - the type id.
Returns:
the data sources as a Map.
Throws:
DataInclusionException

getDataSource

public DataSource getDataSource(String siteName,
                                String id)
                         throws DataInclusionException
Description copied from interface: QueryDao
Get a data source from its id.

Specified by:
getDataSource in interface QueryDao
Parameters:
siteName - the site name.
id - the data source id.
Returns:
the DataSource.
Throws:
DataInclusionException

addDataSource

public String addDataSource(String siteName,
                            DataSource dataSource)
                     throws DataInclusionException
Description copied from interface: QueryDao
Add a data source and return its id.

Specified by:
addDataSource in interface QueryDao
Parameters:
siteName - the site name
dataSource - the data source to add. The id member doesn't need to be specified.
Returns:
id of the newly created data source.
Throws:
DataInclusionException

updateDataSource

public void updateDataSource(String siteName,
                             DataSource dataSource)
                      throws DataInclusionException
Description copied from interface: QueryDao
Update a data source. Update the data source specified by its id member with all the data.

Specified by:
updateDataSource in interface QueryDao
Parameters:
siteName - the site name
dataSource - the data source to update.
Throws:
DataInclusionException

removeDataSource

public void removeDataSource(String siteName,
                             String id)
                      throws DataInclusionException
Description copied from interface: QueryDao
Remove a data source.

Specified by:
removeDataSource in interface QueryDao
Parameters:
siteName - the site name
id - the data source id.
Throws:
DataInclusionException

getQueries

public Map<String,Query> getQueries(String siteName)
                             throws DataInclusionException
Description copied from interface: QueryDao
Get all the queries of a site.

Specified by:
getQueries in interface QueryDao
Parameters:
siteName - the site name.
Returns:
the queries as a Map.
Throws:
DataInclusionException

getQueries

public Map<String,Query> getQueries(String siteName,
                                    String type)
                             throws DataInclusionException
Description copied from interface: QueryDao
Get all the queries of a site.

Specified by:
getQueries in interface QueryDao
Parameters:
siteName - the site name.
Returns:
the queries as a Map.
Throws:
DataInclusionException

getDataSourceQueries

public Map<String,Query> getDataSourceQueries(String siteName,
                                              String dataSourceId)
                                       throws DataInclusionException
Description copied from interface: QueryDao
Get all the queries of a site.

Specified by:
getDataSourceQueries in interface QueryDao
Parameters:
siteName - the site name.
Returns:
the queries as a Map.
Throws:
DataInclusionException

getQuery

public Query getQuery(String siteName,
                      String id)
               throws DataInclusionException
Description copied from interface: QueryDao
Get a query from its id.

Specified by:
getQuery in interface QueryDao
Parameters:
siteName - the site name.
id - the query id.
Returns:
the Query.
Throws:
DataInclusionException

addQuery

public String addQuery(String siteName,
                       Query query,
                       String dataSourceId)
                throws DataInclusionException
Description copied from interface: QueryDao
Add a query and set its id.

Specified by:
addQuery in interface QueryDao
Parameters:
siteName - the site name
query - the query to add. The id member doesn't need to be specified.
Returns:
id of the newly created data source.
Throws:
DataInclusionException

updateQuery

public void updateQuery(String siteName,
                        Query query,
                        String dataSourceId)
                 throws DataInclusionException
Description copied from interface: QueryDao
Update a query. Update the query specified by its id member with all the data.

Specified by:
updateQuery in interface QueryDao
Parameters:
siteName - the site name
query - the query to update.
Throws:
DataInclusionException

removeQuery

public void removeQuery(String siteName,
                        String id)
                 throws DataInclusionException
Description copied from interface: QueryDao
Remove a query.

Specified by:
removeQuery in interface QueryDao
Parameters:
siteName - the site name
id - the query id.
Throws:
DataInclusionException

_extractDataSource

protected DataSource _extractDataSource(javax.jcr.Node node)
                                 throws javax.jcr.RepositoryException,
                                        DataInclusionException
Create a data source from a node.

Parameters:
node - the data source node.
Returns:
the data source.
Throws:
javax.jcr.RepositoryException
DataInclusionException

_extractQuery

protected Query _extractQuery(javax.jcr.Node node)
                       throws javax.jcr.RepositoryException,
                              DataInclusionException
Create a data source from a node.

Parameters:
node - the data source node.
Returns:
the data source.
Throws:
javax.jcr.RepositoryException
DataInclusionException

_getSingleProperty

protected String _getSingleProperty(javax.jcr.Node node,
                                    String propertyName,
                                    String defaultValue)
                             throws javax.jcr.RepositoryException
Get a single property value.

Parameters:
node -
propertyName -
defaultValue -
Returns:
the single property value.
Throws:
javax.jcr.RepositoryException

_getResultType

protected Query.ResultType _getResultType(javax.jcr.Node node,
                                          Query.ResultType defaultValue)
                                   throws javax.jcr.RepositoryException
Get a single property value.

Parameters:
node -
defaultValue -
Returns:
the single property value.
Throws:
javax.jcr.RepositoryException

_getMultipleProperty

protected Collection<String> _getMultipleProperty(javax.jcr.Node node,
                                                  String propertyName)
                                           throws javax.jcr.RepositoryException
Get the values of a string array property.

Parameters:
node -
propertyName -
Returns:
the values.
Throws:
javax.jcr.RepositoryException

_getAdditionalConf

protected Map<String,String> _getAdditionalConf(javax.jcr.Node node)
                                         throws javax.jcr.RepositoryException
Get additional configuration from properties.

Parameters:
node -
Returns:
the additional configuration as a Map.
Throws:
javax.jcr.RepositoryException

_getLinkedDataSource

protected DataSource _getLinkedDataSource(javax.jcr.Node queryNode)
                                   throws javax.jcr.RepositoryException,
                                          DataInclusionException
Get a query's data source from its reference property.

Parameters:
queryNode - the query Node.
Returns:
the Data Source if found, null otherwise.
Throws:
javax.jcr.RepositoryException
DataInclusionException

_fillDataSourceNode

protected void _fillDataSourceNode(DataSource dataSource,
                                   javax.jcr.Node node)
                            throws javax.jcr.RepositoryException
Store the data source properties into the JCR node.

Parameters:
dataSource -
node -
Throws:
javax.jcr.RepositoryException

_fillQueryNode

protected void _fillQueryNode(Query query,
                              javax.jcr.Node node)
                       throws javax.jcr.RepositoryException,
                              DataInclusionException
Store the query properties into the JCR node.

Parameters:
query -
node -
Throws:
javax.jcr.RepositoryException
DataInclusionException

_fillQueryNode

protected void _fillQueryNode(Query query,
                              javax.jcr.Node node,
                              String siteName,
                              String dataSourceId)
                       throws javax.jcr.RepositoryException,
                              DataInclusionException
Store the query properties into the JCR node.

Parameters:
query -
node -
siteName -
dataSourceId -
Throws:
javax.jcr.RepositoryException
DataInclusionException

_fillQueryNode

protected void _fillQueryNode(Query query,
                              javax.jcr.Node node,
                              javax.jcr.Node dataSourceNode)
                       throws javax.jcr.RepositoryException
Store the query properties into the JCR node.

Parameters:
query -
node -
dataSourceNode -
Throws:
javax.jcr.RepositoryException

_getNotExistingNodeName

protected String _getNotExistingNodeName(javax.jcr.Node container,
                                         String baseName)
                                  throws javax.jcr.RepositoryException
Get a name for a node which doesn't already exist in this node.

Parameters:
container - the container node.
baseName - the base wanted node name.
Returns:
the name, free to be taken.
Throws:
javax.jcr.RepositoryException

_getPluginNode

protected javax.jcr.Node _getPluginNode(String siteName)
                                 throws javax.jcr.RepositoryException
Get the plugin root node in a site storage space.

Parameters:
siteName - the site name.
Returns:
the plugin root node.
Throws:
javax.jcr.RepositoryException

_getDataSourcesNode

protected javax.jcr.Node _getDataSourcesNode(String siteName)
                                      throws javax.jcr.RepositoryException
Get the data sources root node.

Parameters:
siteName -
Returns:
the data sources root node.
Throws:
javax.jcr.RepositoryException

_getQueriesNode

protected javax.jcr.Node _getQueriesNode(String siteName)
                                  throws javax.jcr.RepositoryException
Get the queries root node.

Parameters:
siteName -
Returns:
the queries root node.
Throws:
javax.jcr.RepositoryException


Copyright © 2010 Anyware Services. All Rights Reserved.