Class ElasticSearchPersistenceServiceImpl

  • All Implemented Interfaces:
    EventListener, PersistenceService, org.osgi.framework.BundleListener, org.osgi.framework.SynchronousBundleListener

    public class ElasticSearchPersistenceServiceImpl
    extends Object
    implements PersistenceService, org.osgi.framework.SynchronousBundleListener
    • Constructor Detail

      • ElasticSearchPersistenceServiceImpl

        public ElasticSearchPersistenceServiceImpl()
    • Method Detail

      • setBundleContext

        public void setBundleContext​(org.osgi.framework.BundleContext bundleContext)
      • setClusterName

        public void setClusterName​(String clusterName)
      • setElasticSearchAddresses

        public void setElasticSearchAddresses​(String elasticSearchAddresses)
      • setItemTypeToRefreshPolicy

        public void setItemTypeToRefreshPolicy​(String itemTypeToRefreshPolicy)
                                        throws IOException
        Throws:
        IOException
      • setFatalIllegalStateErrors

        public void setFatalIllegalStateErrors​(String fatalIllegalStateErrors)
      • setAggQueryMaxResponseSizeHttp

        public void setAggQueryMaxResponseSizeHttp​(String aggQueryMaxResponseSizeHttp)
      • setIndexPrefix

        public void setIndexPrefix​(String indexPrefix)
      • setMonthlyIndexNumberOfShards

        @Deprecated
        public void setMonthlyIndexNumberOfShards​(String monthlyIndexNumberOfShards)
        Deprecated.
      • setMonthlyIndexNumberOfReplicas

        @Deprecated
        public void setMonthlyIndexNumberOfReplicas​(String monthlyIndexNumberOfReplicas)
        Deprecated.
      • setMonthlyIndexMappingTotalFieldsLimit

        @Deprecated
        public void setMonthlyIndexMappingTotalFieldsLimit​(String monthlyIndexMappingTotalFieldsLimit)
        Deprecated.
      • setMonthlyIndexMaxDocValueFieldsSearch

        @Deprecated
        public void setMonthlyIndexMaxDocValueFieldsSearch​(String monthlyIndexMaxDocValueFieldsSearch)
        Deprecated.
      • setItemsMonthlyIndexedOverride

        @Deprecated
        public void setItemsMonthlyIndexedOverride​(String itemsMonthlyIndexedOverride)
        Deprecated.
      • setNumberOfShards

        public void setNumberOfShards​(String numberOfShards)
      • setNumberOfReplicas

        public void setNumberOfReplicas​(String numberOfReplicas)
      • setIndexMappingTotalFieldsLimit

        public void setIndexMappingTotalFieldsLimit​(String indexMappingTotalFieldsLimit)
      • setIndexMaxDocValueFieldsSearch

        public void setIndexMaxDocValueFieldsSearch​(String indexMaxDocValueFieldsSearch)
      • setDefaultQueryLimit

        public void setDefaultQueryLimit​(Integer defaultQueryLimit)
      • setRoutingByType

        public void setRoutingByType​(Map<String,​String> routingByType)
      • setConditionEvaluatorDispatcher

        public void setConditionEvaluatorDispatcher​(ConditionEvaluatorDispatcher conditionEvaluatorDispatcher)
      • setBulkProcessorConcurrentRequests

        public void setBulkProcessorConcurrentRequests​(String bulkProcessorConcurrentRequests)
      • setBulkProcessorBulkActions

        public void setBulkProcessorBulkActions​(String bulkProcessorBulkActions)
      • setBulkProcessorBulkSize

        public void setBulkProcessorBulkSize​(String bulkProcessorBulkSize)
      • setBulkProcessorFlushInterval

        public void setBulkProcessorFlushInterval​(String bulkProcessorFlushInterval)
      • setBulkProcessorBackoffPolicy

        public void setBulkProcessorBackoffPolicy​(String bulkProcessorBackoffPolicy)
      • setRolloverIndices

        public void setRolloverIndices​(String rolloverIndices)
      • setRolloverMaxSize

        public void setRolloverMaxSize​(String rolloverMaxSize)
      • setRolloverMaxAge

        public void setRolloverMaxAge​(String rolloverMaxAge)
      • setRolloverMaxDocs

        public void setRolloverMaxDocs​(String rolloverMaxDocs)
      • setRolloverIndexNumberOfShards

        public void setRolloverIndexNumberOfShards​(String rolloverIndexNumberOfShards)
      • setRolloverIndexNumberOfReplicas

        public void setRolloverIndexNumberOfReplicas​(String rolloverIndexNumberOfReplicas)
      • setRolloverIndexMappingTotalFieldsLimit

        public void setRolloverIndexMappingTotalFieldsLimit​(String rolloverIndexMappingTotalFieldsLimit)
      • setRolloverIndexMaxDocValueFieldsSearch

        public void setRolloverIndexMaxDocValueFieldsSearch​(String rolloverIndexMaxDocValueFieldsSearch)
      • setMinimalElasticSearchVersion

        public void setMinimalElasticSearchVersion​(String minimalElasticSearchVersion)
      • setMaximalElasticSearchVersion

        public void setMaximalElasticSearchVersion​(String maximalElasticSearchVersion)
      • setAggregateQueryBucketSize

        public void setAggregateQueryBucketSize​(int aggregateQueryBucketSize)
      • setClientSocketTimeout

        public void setClientSocketTimeout​(String clientSocketTimeout)
      • setMetricsService

        public void setMetricsService​(MetricsService metricsService)
      • setUseBatchingForSave

        public void setUseBatchingForSave​(boolean useBatchingForSave)
      • setUseBatchingForUpdate

        public void setUseBatchingForUpdate​(boolean useBatchingForUpdate)
      • setUsername

        public void setUsername​(String username)
      • setPassword

        public void setPassword​(String password)
      • setSslEnable

        public void setSslEnable​(boolean sslEnable)
      • setSslTrustAllCertificates

        public void setSslTrustAllCertificates​(boolean sslTrustAllCertificates)
      • setAggQueryThrowOnMissingDocs

        public void setAggQueryThrowOnMissingDocs​(boolean aggQueryThrowOnMissingDocs)
      • setThrowExceptions

        public void setThrowExceptions​(boolean throwExceptions)
      • setAlwaysOverwrite

        public void setAlwaysOverwrite​(boolean alwaysOverwrite)
      • setLogLevelRestClient

        public void setLogLevelRestClient​(String logLevelRestClient)
      • setTaskWaitingTimeout

        public void setTaskWaitingTimeout​(String taskWaitingTimeout)
      • setTaskWaitingPollingInterval

        public void setTaskWaitingPollingInterval​(String taskWaitingPollingInterval)
      • getBulkProcessor

        public org.elasticsearch.action.bulk.BulkProcessor getBulkProcessor()
      • stop

        public void stop()
      • bindConditionEvaluator

        public void bindConditionEvaluator​(org.osgi.framework.ServiceReference<ConditionEvaluator> conditionEvaluatorServiceReference)
      • unbindConditionEvaluator

        public void unbindConditionEvaluator​(org.osgi.framework.ServiceReference<ConditionEvaluator> conditionEvaluatorServiceReference)
      • bindConditionESQueryBuilder

        public void bindConditionESQueryBuilder​(org.osgi.framework.ServiceReference<ConditionESQueryBuilder> conditionESQueryBuilderServiceReference)
      • unbindConditionESQueryBuilder

        public void unbindConditionESQueryBuilder​(org.osgi.framework.ServiceReference<ConditionESQueryBuilder> conditionESQueryBuilderServiceReference)
      • bundleChanged

        public void bundleChanged​(org.osgi.framework.BundleEvent event)
        Specified by:
        bundleChanged in interface org.osgi.framework.BundleListener
      • getAllItemsCount

        public long getAllItemsCount​(String itemType)
        Description copied from interface: PersistenceService
        Retrieves the number of items with the specified type as defined by the Item subclass public field ITEM_TYPE.
        Specified by:
        getAllItemsCount in interface PersistenceService
        Parameters:
        itemType - the String representation of the item type we want to retrieve the count of, as defined by its class' ITEM_TYPE field
        Returns:
        the number of items of the specified type
        See Also:
        Item for a discussion of
      • getAllItems

        public <T extends ItemPartialList<T> getAllItems​(Class<T> clazz,
                                                           int offset,
                                                           int size,
                                                           String sortBy)
        Description copied from interface: PersistenceService
        Retrieves all known items of the specified class, ordered according to the specified sortBy String and and paged: only size of them are retrieved, starting with the offset-th one.

        TODO: use a Query object instead of distinct parameters?

        Specified by:
        getAllItems in interface PersistenceService
        Type Parameters:
        T - the type of the Items we want to retrieve
        Parameters:
        clazz - the Item subclass of entities we want to retrieve
        offset - zero or a positive integer specifying the position of the first item in the total ordered collection of matching items
        size - a positive integer specifying how many matching items should be retrieved or -1 if all of them should be retrieved
        sortBy - an optional (null if no sorting is required) String of comma (,) separated property names on which ordering should be performed, ordering elements according to the property order in the String, considering each in turn and moving on to the next one in case of equality of all preceding ones. Each property name is optionally followed by a column (:) and an order specifier: asc or desc.
        Returns:
        a PartialList of pages items with the given type
      • getAllItems

        public <T extends ItemPartialList<T> getAllItems​(Class<T> clazz,
                                                           int offset,
                                                           int size,
                                                           String sortBy,
                                                           String scrollTimeValidity)
        Description copied from interface: PersistenceService
        Retrieves all known items of the specified class, ordered according to the specified sortBy String and and paged: only size of them are retrieved, starting with the offset-th one.

        TODO: use a Query object instead of distinct parameters?

        Specified by:
        getAllItems in interface PersistenceService
        Type Parameters:
        T - the type of the Items we want to retrieve
        Parameters:
        clazz - the Item subclass of entities we want to retrieve
        offset - zero or a positive integer specifying the position of the first item in the total ordered collection of matching items
        size - a positive integer specifying how many matching items should be retrieved or -1 if all of them should be retrieved
        sortBy - an optional (null if no sorting is required) String of comma (,) separated property names on which ordering should be performed, ordering elements according to the property order in the String, considering each in turn and moving on to the next one in case of equality of all preceding ones. Each property name is optionally followed by a column (:) and an order specifier: asc or desc.
        scrollTimeValidity - the time the scrolling query should stay valid. This must contain a time unit value such as the ones supported by ElasticSearch, such as * the ones declared here : https://www.elastic.co/guide/en/elasticsearch/reference/current/common-options.html#time-units
        Returns:
        a PartialList of pages items with the given type
      • load

        public <T extends Item> T load​(String itemId,
                                       Class<T> clazz)
        Description copied from interface: PersistenceService
        Retrieves the item identified with the specified identifier and with the specified Item subclass if it exists.
        Specified by:
        load in interface PersistenceService
        Type Parameters:
        T - the type of the Item subclass we want to retrieve
        Parameters:
        itemId - the identifier of the item we want to retrieve
        clazz - the Item subclass of the item we want to retrieve
        Returns:
        the item identified with the specified identifier and with the specified Item subclass if it exists, null otherwise
      • loadCustomItem

        public CustomItem loadCustomItem​(String itemId,
                                         String customItemType)
        Description copied from interface: PersistenceService
        Load a custom item type identified by an identifier, an optional date hint and the identifier of the custom item type
        Specified by:
        loadCustomItem in interface PersistenceService
        Parameters:
        itemId - the identifier of the custom type we want to retrieve
        customItemType - an identifier of the custom item type to load
        Returns:
        the CustomItem instance with the specified identifier and the custom item type if it exists, null otherwise
      • isConsistent

        public boolean isConsistent​(Item item)
        Description copied from interface: PersistenceService
        Return true if the item which is saved in the persistence service is consistent
        Specified by:
        isConsistent in interface PersistenceService
        Parameters:
        item - the item to the check if consistent
        Returns:
        true if the item is consistent, false otherwise
      • save

        public boolean save​(Item item)
        Description copied from interface: PersistenceService
        Persists the specified Item in the context server.
        Specified by:
        save in interface PersistenceService
        Parameters:
        item - the item to persist
        Returns:
        true if the item was properly persisted, false otherwise
      • save

        public boolean save​(Item item,
                            boolean useBatching)
        Description copied from interface: PersistenceService
        Persists the specified Item in the context server.
        Specified by:
        save in interface PersistenceService
        Parameters:
        item - the item to persist
        useBatching - whether to use batching or not for saving the item. If activating there may be a delay between the call to this method and the actual saving in the persistence backend.
        Returns:
        true if the item was properly persisted, false otherwise
      • save

        public boolean save​(Item item,
                            Boolean useBatchingOption,
                            Boolean alwaysOverwriteOption)
        Description copied from interface: PersistenceService
        Persists the specified Item in the context server.
        Specified by:
        save in interface PersistenceService
        Parameters:
        item - the item to persist
        useBatchingOption - whether to use batching or not for saving the item. If activating there may be a delay between the call to this method and the actual saving in the persistence backend
        alwaysOverwriteOption - whether to overwrite a document even if we are holding an old item when saving
        Returns:
        true if the item was properly persisted, false otherwise
      • update

        public boolean update​(Item item,
                              Class clazz,
                              String propertyName,
                              Object propertyValue)
        Description copied from interface: PersistenceService
        Updates the item of the specified class and identified by the specified identifier with a new property value for the specified property name. Same as update(itemId, clazz, Collections.singletonMap(propertyName, propertyValue))
        Specified by:
        update in interface PersistenceService
        Parameters:
        item - the item we want to update
        clazz - the Item subclass of the item to update
        propertyName - the name of the property to update
        propertyValue - the new value of the property
        Returns:
        true if the update was successful, false otherwise
      • update

        public boolean update​(Item item,
                              Class clazz,
                              Map source)
        Description copied from interface: PersistenceService
        Updates the item of the specified class and identified by the specified identifier with new property values provided as name - value pairs in the specified Map.
        Specified by:
        update in interface PersistenceService
        Parameters:
        item - the item we want to update
        clazz - the Item subclass of the item to update
        source - a Map with entries specifying as key the property name to update and as value its new value
        Returns:
        true if the update was successful, false otherwise
      • update

        public boolean update​(Item item,
                              Class clazz,
                              Map source,
                              boolean alwaysOverwrite)
        Description copied from interface: PersistenceService
        Updates the item of the specified class and identified by the specified identifier with new property values provided as name - value pairs in the specified Map.
        Specified by:
        update in interface PersistenceService
        Parameters:
        item - the item we want to update
        clazz - the Item subclass of the item to update
        source - a Map with entries specifying as key the property name to update and as value its new value
        alwaysOverwrite - whether to overwrite a document even if we are holding an old item when saving
        Returns:
        true if the update was successful, false otherwise
      • updateWithQueryAndScript

        public boolean updateWithQueryAndScript​(Class<?> clazz,
                                                String[] scripts,
                                                Map<String,​Object>[] scriptParams,
                                                Condition[] conditions)
        Description copied from interface: PersistenceService
        Updates the items of the specified class by a query with a new property value for the specified property name based on provided scripts and script parameters
        Specified by:
        updateWithQueryAndScript in interface PersistenceService
        Parameters:
        clazz - the Item subclass of the item to update
        scripts - inline scripts array
        scriptParams - script params array
        conditions - conditions array
        Returns:
        true if the update was successful, false otherwise
      • updateWithQueryAndStoredScript

        public boolean updateWithQueryAndStoredScript​(Class<?> clazz,
                                                      String[] scripts,
                                                      Map<String,​Object>[] scriptParams,
                                                      Condition[] conditions)
        Description copied from interface: PersistenceService
        Updates the items of the specified class by a query with a new property value for the specified property name based on provided stored scripts and script parameters
        Specified by:
        updateWithQueryAndStoredScript in interface PersistenceService
        Parameters:
        clazz - the Item subclass of the item to update
        scripts - Stored scripts name
        scriptParams - script params array
        conditions - conditions array
        Returns:
        true if the update was successful, false otherwise
      • updateWithQueryAndStoredScript

        public boolean updateWithQueryAndStoredScript​(Class<?>[] classes,
                                                      String[] scripts,
                                                      Map<String,​Object>[] scriptParams,
                                                      Condition[] conditions,
                                                      boolean waitForComplete)
        Description copied from interface: PersistenceService
        Updates the items of the specified class by a query with a new property value for the specified property name based on provided stored scripts and script parameters, This one is able to perform an update on multiple types in a single run, be careful with your query as it will be performed on all of them.
        Specified by:
        updateWithQueryAndStoredScript in interface PersistenceService
        Parameters:
        classes - classes of items to update, be careful all of them will be submitted to update for all scripts/conditions
        scripts - Stored scripts name
        scriptParams - script params array
        conditions - conditions array
        waitForComplete - if true, wait for the ES execution to be complete
        Returns:
        true if the update was successful, false otherwise
      • storeScripts

        public boolean storeScripts​(Map<String,​String> scripts)
        Description copied from interface: PersistenceService
        Store script in the Database for later usage with updateWithQueryAndStoredScript function for example.
        Specified by:
        storeScripts in interface PersistenceService
        Parameters:
        scripts - inline scripts map indexed by id
        Returns:
        true if the update was successful, false otherwise
      • updateWithScript

        public boolean updateWithScript​(Item item,
                                        Class<?> clazz,
                                        String script,
                                        Map<String,​Object> scriptParams)
        Description copied from interface: PersistenceService
        Updates the item of the specified class and identified by the specified identifier with a new property value for the specified property name. Same as update(itemId, clazz, Collections.singletonMap(propertyName, propertyValue))
        Specified by:
        updateWithScript in interface PersistenceService
        Parameters:
        item - the item we want to update
        clazz - the Item subclass of the item to update
        script - inline script
        scriptParams - script params
        Returns:
        true if the update was successful, false otherwise
      • remove

        public <T extends Item> boolean remove​(String itemId,
                                               Class<T> clazz)
        Description copied from interface: PersistenceService
        Deletes the item identified with the specified identifier and with the specified Item subclass if it exists.
        Specified by:
        remove in interface PersistenceService
        Type Parameters:
        T - the type of the Item subclass we want to delete
        Parameters:
        itemId - the identifier of the item we want to delete
        clazz - the Item subclass of the item we want to delete
        Returns:
        true if the deletion was successful, false otherwise
      • removeCustomItem

        public boolean removeCustomItem​(String itemId,
                                        String customItemType)
        Description copied from interface: PersistenceService
        Remove a custom item identified by the custom item identifier and the custom item type identifier
        Specified by:
        removeCustomItem in interface PersistenceService
        Parameters:
        itemId - the identifier of the custom item to be removed
        customItemType - the name of the custom item type
        Returns:
        true if the deletion was successful, false otherwise
      • removeByQuery

        public <T extends Item> boolean removeByQuery​(Condition query,
                                                      Class<T> clazz)
        Description copied from interface: PersistenceService
        Deletes items with the specified Item subclass matching the specified Condition.
        Specified by:
        removeByQuery in interface PersistenceService
        Type Parameters:
        T - the type of the Item subclass we want to delete
        Parameters:
        query - a Condition identifying which elements we want to delete
        clazz - the Item subclass of the items we want to delete
        Returns:
        true if the deletion was successful, false otherwise
      • removeByQuery

        public <T extends Item> boolean removeByQuery​(org.elasticsearch.index.query.QueryBuilder queryBuilder,
                                                      Class<T> clazz)
                                               throws Exception
        Throws:
        Exception
      • indexTemplateExists

        public boolean indexTemplateExists​(String templateName)
      • removeIndexTemplate

        public boolean removeIndexTemplate​(String templateName)
      • registerRolloverLifecyclePolicy

        public boolean registerRolloverLifecyclePolicy()
      • createIndex

        public boolean createIndex​(String itemType)
        Description copied from interface: PersistenceService
        Creates an index with for the specified item type in the persistence engine.

        TODO: remove from API?

        Specified by:
        createIndex in interface PersistenceService
        Parameters:
        itemType - the item type
        Returns:
        true if the operation was successful, false otherwise
      • removeIndex

        public boolean removeIndex​(String itemType)
        Description copied from interface: PersistenceService
        Removes the index for the specified item type.

        TODO: remove from API?

        Specified by:
        removeIndex in interface PersistenceService
        Parameters:
        itemType - the item type
        Returns:
        true if the operation was successful, false otherwise
      • setPropertyMapping

        public void setPropertyMapping​(PropertyType property,
                                       String itemType)
        Description copied from interface: PersistenceService
        Create the persistence mapping for specific property for a given type.
        Specified by:
        setPropertyMapping in interface PersistenceService
        Parameters:
        property - the PropertyType to create mapping for
        itemType - the itemType we want to retrieve the mappings for
      • getPropertiesMapping

        public Map<String,​Map<String,​Object>> getPropertiesMapping​(String itemType)
        Description copied from interface: PersistenceService
        Retrieve the type mappings for a given itemType. This method queries the persistence service implementation to retrieve any type mappings it may have for the specified itemType.

        This method may not return any results if the implementation doesn't support property type mappings

        Specified by:
        getPropertiesMapping in interface PersistenceService
        Parameters:
        itemType - the itemType we want to retrieve the mappings for
        Returns:
        properties mapping
      • getPropertyMapping

        public Map<String,​Object> getPropertyMapping​(String property,
                                                           String itemType)
        Description copied from interface: PersistenceService
        Retrieve the mapping for one specific property for a given type.
        Specified by:
        getPropertyMapping in interface PersistenceService
        Parameters:
        property - the property name (can use nested dot notation)
        itemType - the itemType we want to retrieve the mappings for
        Returns:
        property mapping
      • saveQuery

        public boolean saveQuery​(String queryName,
                                 String query)
      • saveQuery

        public boolean saveQuery​(String queryName,
                                 Condition query)
        Description copied from interface: PersistenceService
        Persists the specified query under the specified name.
        Specified by:
        saveQuery in interface PersistenceService
        Parameters:
        queryName - the name under which the specified query should be recorded
        query - the query to be recorded
        Returns:
        true if the query was properly saved, false otherwise
      • removeQuery

        public boolean removeQuery​(String queryName)
        Description copied from interface: PersistenceService
        Deletes the query identified by the specified name.
        Specified by:
        removeQuery in interface PersistenceService
        Parameters:
        queryName - the name under which the specified query was recorded
        Returns:
        true if the deletion was successful, false otherwise
      • isValidCondition

        public boolean isValidCondition​(Condition condition,
                                        Item item)
        Description copied from interface: PersistenceService
        validates if a condition throws exception at query build.
        Specified by:
        isValidCondition in interface PersistenceService
        Parameters:
        condition - the condition we're testing the specified item against
        item - the item we're checking against the specified condition
        Returns:
        true if the item satisfies the condition, false otherwise
      • testMatch

        public boolean testMatch​(Condition query,
                                 Item item)
        Description copied from interface: PersistenceService
        Checks whether the specified item satisfies the provided condition.

        TODO: rename to isMatching?

        Specified by:
        testMatch in interface PersistenceService
        Parameters:
        query - the condition we're testing the specified item against
        item - the item we're checking against the specified condition
        Returns:
        true if the item satisfies the condition, false otherwise
      • query

        public <T extends ItemList<T> query​(Condition query,
                                              String sortBy,
                                              Class<T> clazz)
        Description copied from interface: PersistenceService
        Same as query(query, sortBy, clazz, 0, -1).getList()
        Specified by:
        query in interface PersistenceService
        Type Parameters:
        T - the type of the Item subclass we want to retrieve
        Parameters:
        query - the Condition the items must satisfy to be retrieved
        sortBy - an optional (null if no sorting is required) String of comma (,) separated property names on which ordering should be performed, ordering elements according to the property order in the String, considering each in turn and moving on to the next one in case of equality of all preceding ones. Each property name is optionally followed by a column (:) and an order specifier: asc or desc.
        clazz - the Item subclass of the items we want to retrieve
        Returns:
        a PartialList of items matching the specified criteria
        See Also:
        PersistenceService.query(Condition, String, Class, int, int)
      • query

        public <T extends ItemPartialList<T> query​(Condition query,
                                                     String sortBy,
                                                     Class<T> clazz,
                                                     int offset,
                                                     int size)
        Description copied from interface: PersistenceService
        Retrieves a list of items satisfying the specified Condition, ordered according to the specified sortBy String and and paged: only size of them are retrieved, starting with the offset-th one.
        Specified by:
        query in interface PersistenceService
        Type Parameters:
        T - the type of the Item subclass we want to retrieve
        Parameters:
        query - the Condition the items must satisfy to be retrieved
        sortBy - an optional (null if no sorting is required) String of comma (,) separated property names on which ordering should be performed, ordering elements according to the property order in the String, considering each in turn and moving on to the next one in case of equality of all preceding ones. Each property name is optionally followed by a column (:) and an order specifier: asc or desc.
        clazz - the Item subclass of the items we want to retrieve
        offset - zero or a positive integer specifying the position of the first item in the total ordered collection of matching items
        size - a positive integer specifying how many matching items should be retrieved or -1 if all of them should be retrieved
        Returns:
        a PartialList of items matching the specified criteria
      • query

        public <T extends ItemPartialList<T> query​(Condition query,
                                                     String sortBy,
                                                     Class<T> clazz,
                                                     int offset,
                                                     int size,
                                                     String scrollTimeValidity)
        Description copied from interface: PersistenceService
        Retrieves a list of items satisfying the specified Condition, ordered according to the specified sortBy String and and paged: only size of them are retrieved, starting with the offset-th one. If a scroll identifier and time validity are specified, they will be used to perform a scrolling query, meaning that only partial results will be returned, but the scrolling can be continued.
        Specified by:
        query in interface PersistenceService
        Type Parameters:
        T - the type of the Item subclass we want to retrieve
        Parameters:
        query - the Condition the items must satisfy to be retrieved
        sortBy - an optional (null if no sorting is required) String of comma (,) separated property names on which ordering should be performed, ordering elements according to the property order in the String, considering each in turn and moving on to the next one in case of equality of all preceding ones. Each property name is optionally followed by a column (:) and an order specifier: asc or desc.
        clazz - the Item subclass of the items we want to retrieve
        offset - zero or a positive integer specifying the position of the first item in the total ordered collection of matching items
        size - a positive integer specifying how many matching items should be retrieved or -1 if all of them should be retrieved. In the case of a scroll query this will be used as the scrolling window size.
        scrollTimeValidity - the time the scrolling query should stay valid. This must contain a time unit value such as the ones supported by ElasticSearch, such as the ones declared here : https://www.elastic.co/guide/en/elasticsearch/reference/current/common-options.html#time-units
        Returns:
        a PartialList of items matching the specified criteria, with an scroll identifier and the scroll validity used if a scroll query was requested.
      • queryCustomItem

        public PartialList<CustomItem> queryCustomItem​(Condition query,
                                                       String sortBy,
                                                       String customItemType,
                                                       int offset,
                                                       int size,
                                                       String scrollTimeValidity)
        Description copied from interface: PersistenceService
        Retrieves a list of items satisfying the specified Condition, ordered according to the specified sortBy String and paged: only size of them are retrieved, starting with the offset-th one. If a scroll identifier and time validity are specified, they will be used to perform a scrolling query, meaning that only partial results will be returned, but the scrolling can be continued.
        Specified by:
        queryCustomItem in interface PersistenceService
        Parameters:
        query - the Condition the items must satisfy to be retrieved
        sortBy - an optional (null if no sorting is required) String of comma (,) separated property names on which ordering should be performed, ordering elements according to the property order in the String, considering each in turn and moving on to the next one in case of equality of all preceding ones. Each property name is optionally followed by a column (:) and an order specifier: asc or desc.
        customItemType - the identifier of the custom item type we want to query
        offset - zero or a positive integer specifying the position of the first item in the total ordered collection of matching items
        size - a positive integer specifying how many matching items should be retrieved or -1 if all of them should be retrieved. In the case of a scroll query this will be used as the scrolling window size.
        scrollTimeValidity - the time the scrolling query should stay valid. This must contain a time unit value such as the ones supported by ElasticSearch, such as the ones declared here : https://www.elastic.co/guide/en/elasticsearch/reference/current/common-options.html#time-units
        Returns:
        a PartialList of items matching the specified criteria, with an scroll identifier and the scroll validity used if a scroll query was requested.
      • queryFullText

        public <T extends ItemPartialList<T> queryFullText​(String fulltext,
                                                             Condition query,
                                                             String sortBy,
                                                             Class<T> clazz,
                                                             int offset,
                                                             int size)
        Description copied from interface: PersistenceService
        Retrieves the same items as query(query, sortBy, clazz, 0, -1) with the added constraints that the matching elements must also have at least a field matching the specified full text query.
        Specified by:
        queryFullText in interface PersistenceService
        Type Parameters:
        T - the type of the Item subclass we want to retrieve
        Parameters:
        fulltext - the text that the item must have in one of its fields to be considered a match
        query - the Condition the items must satisfy to be retrieved
        sortBy - an optional (null if no sorting is required) String of comma (,) separated property names on which ordering should be performed, ordering elements according to the property order in the String, considering each in turn and moving on to the next one in case of equality of all preceding ones. Each property name is optionally followed by a column (:) and an order specifier: asc or desc.
        clazz - the Item subclass of the items we want to retrieve
        offset - zero or a positive integer specifying the position of the first item in the total ordered collection of matching items
        size - a positive integer specifying how many matching items should be retrieved or -1 if all of them should be retrieved
        Returns:
        a PartialList of items matching the specified criteria
      • query

        public <T extends ItemList<T> query​(String fieldName,
                                              String fieldValue,
                                              String sortBy,
                                              Class<T> clazz)
        Description copied from interface: PersistenceService
        Same as query(fieldName, fieldValue, sortBy, clazz, 0, -1).getList()
        Specified by:
        query in interface PersistenceService
        Type Parameters:
        T - the type of the Item subclass we want to retrieve
        Parameters:
        fieldName - the name of the field which we want items to have the specified values
        fieldValue - the value the items to retrieve should have for the specified field
        sortBy - an optional (null if no sorting is required) String of comma (,) separated property names on which ordering should be performed, ordering elements according to the property order in the String, considering each in turn and moving on to the next one in case of equality of all preceding ones. Each property name is optionally followed by a column (:) and an order specifier: asc or desc.
        clazz - the Item subclass of the items we want to retrieve
        Returns:
        a list of items matching the specified criteria
        See Also:
        PersistenceService.query(Condition, String, Class, int, int)
      • query

        public <T extends ItemList<T> query​(String fieldName,
                                              String[] fieldValues,
                                              String sortBy,
                                              Class<T> clazz)
        Description copied from interface: PersistenceService
        Retrieves a list of items with the specified field having the specified values.
        Specified by:
        query in interface PersistenceService
        Type Parameters:
        T - the type of the Item subclass we want to retrieve
        Parameters:
        fieldName - the name of the field which we want items to have the specified values
        fieldValues - the values the items to retrieve should have for the specified field
        sortBy - an optional (null if no sorting is required) String of comma (,) separated property names on which ordering should be performed, ordering elements according to the property order in the String, considering each in turn and moving on to the next one in case of equality of all preceding ones. Each property name is optionally followed by a column (:) and an order specifier: asc or desc.
        clazz - the Item subclass of the items we want to retrieve
        Returns:
        a list of items matching the specified criteria
      • query

        public <T extends ItemPartialList<T> query​(String fieldName,
                                                     String fieldValue,
                                                     String sortBy,
                                                     Class<T> clazz,
                                                     int offset,
                                                     int size)
        Description copied from interface: PersistenceService
        Retrieves a list of items with the specified field having the specified value.
        Specified by:
        query in interface PersistenceService
        Type Parameters:
        T - the type of the Item subclass we want to retrieve
        Parameters:
        fieldName - the name of the field which we want items to have the specified value
        fieldValue - the value the items to retrieve should have for the specified field
        sortBy - an optional (null if no sorting is required) String of comma (,) separated property names on which ordering should be performed, ordering elements according to the property order in the String, considering each in turn and moving on to the next one in case of equality of all preceding ones. Each property name is optionally followed by a column (:) and an order specifier: asc or desc.
        clazz - the Item subclass of the items we want to retrieve
        offset - zero or a positive integer specifying the position of the first item in the total ordered collection of matching items
        size - a positive integer specifying how many matching items should be retrieved or -1 if all of them should be retrieved
        Returns:
        a PartialList of items matching the specified criteria
      • queryFullText

        public <T extends ItemPartialList<T> queryFullText​(String fieldName,
                                                             String fieldValue,
                                                             String fulltext,
                                                             String sortBy,
                                                             Class<T> clazz,
                                                             int offset,
                                                             int size)
        Description copied from interface: PersistenceService
        Retrieves a list of items with the specified field having the specified value and having at least a field with the specified full text value in it, ordered according to the specified sortBy String and and paged: only size of them are retrieved, starting with the offset-th one.
        Specified by:
        queryFullText in interface PersistenceService
        Type Parameters:
        T - the type of the Item subclass we want to retrieve
        Parameters:
        fieldName - the name of the field which we want items to have the specified value
        fieldValue - the value the items to retrieve should have for the specified field
        fulltext - the text that the item must have in one of its fields to be considered a match
        sortBy - an optional (null if no sorting is required) String of comma (,) separated property names on which ordering should be performed, ordering elements according to the property order in the String, considering each in turn and moving on to the next one in case of equality of all preceding ones. Each property name is optionally followed by a column (:) and an order specifier: asc or desc.
        clazz - the Item subclass of the items we want to retrieve
        offset - zero or a positive integer specifying the position of the first item in the total ordered collection of matching items
        size - a positive integer specifying how many matching items should be retrieved or -1 if all of them should be retrieved
        Returns:
        a PartialList of items matching the specified criteria
      • queryFullText

        public <T extends ItemPartialList<T> queryFullText​(String fulltext,
                                                             String sortBy,
                                                             Class<T> clazz,
                                                             int offset,
                                                             int size)
        Description copied from interface: PersistenceService
        Retrieves a list of items having at least a field with the specified full text value in it, ordered according to the specified sortBy String and and paged: only size of them are retrieved, starting with the offset-th one.
        Specified by:
        queryFullText in interface PersistenceService
        Type Parameters:
        T - the type of the Item subclass we want to retrieve
        Parameters:
        fulltext - the text that the item must have in one of its fields to be considered a match
        sortBy - an optional (null if no sorting is required) String of comma (,) separated property names on which ordering should be performed, ordering elements according to the property order in the String, considering each in turn and moving on to the next one in case of equality of all preceding ones. Each property name is optionally followed by a column (:) and an order specifier: asc or desc.
        clazz - the Item subclass of the items we want to retrieve
        offset - zero or a positive integer specifying the position of the first item in the total ordered collection of matching items
        size - a positive integer specifying how many matching items should be retrieved or -1 if all of them should be retrieved
        Returns:
        a PartialList of items matching the specified criteria
      • rangeQuery

        public <T extends ItemPartialList<T> rangeQuery​(String fieldName,
                                                          String from,
                                                          String to,
                                                          String sortBy,
                                                          Class<T> clazz,
                                                          int offset,
                                                          int size)
        Description copied from interface: PersistenceService
        Retrieves all items of the specified Item subclass which specified ranged property is within the specified bounds, ordered according to the specified sortBy String and and paged: only size of them are retrieved, starting with the offset-th one.
        Specified by:
        rangeQuery in interface PersistenceService
        Type Parameters:
        T - the type of the Item subclass we want to retrieve
        Parameters:
        fieldName - the name of the range property we want items to retrieve to be included between the specified start and end points
        from - the beginning of the range we want to consider
        to - the end of the range we want to consider
        sortBy - an optional (null if no sorting is required) String of comma (,) separated property names on which ordering should be performed, ordering elements according to the property order in the String, considering each in turn and moving on to the next one in case of equality of all preceding ones. Each property name is optionally followed by a column (:) and an order specifier: asc or desc.
        clazz - the Item subclass of the items we want to retrieve
        offset - zero or a positive integer specifying the position of the first item in the total ordered collection of matching items
        size - a positive integer specifying how many matching items should be retrieved or -1 if all of them should be retrieved
        Returns:
        a PartialList of items matching the specified criteria
      • queryCount

        public long queryCount​(Condition query,
                               String itemType)
        Description copied from interface: PersistenceService
        Retrieves the number of items of the specified type as defined by the Item subclass public field ITEM_TYPE and matching the specified Condition.
        Specified by:
        queryCount in interface PersistenceService
        Parameters:
        query - the condition the items must satisfy
        itemType - the String representation of the item type we want to retrieve the count of, as defined by its class' ITEM_TYPE field
        Returns:
        the number of items of the specified type
        See Also:
        Item for a discussion of
      • continueScrollQuery

        public <T extends ItemPartialList<T> continueScrollQuery​(Class<T> clazz,
                                                                   String scrollIdentifier,
                                                                   String scrollTimeValidity)
        Description copied from interface: PersistenceService
        Continues the execution of a scroll query, to retrieve the next results. If there are no more results the scroll query is also cleared.
        Specified by:
        continueScrollQuery in interface PersistenceService
        Type Parameters:
        T - the type of the Item subclass we want to retrieve
        Parameters:
        clazz - the Item subclass of the items we want to retrieve
        scrollIdentifier - a scroll identifier obtained by the execution of a first query and returned in the PartialList object
        scrollTimeValidity - a scroll time validity value for the scroll query to stay valid. This must contain a time unit value such as the ones supported by ElasticSearch, such as the ones declared here : https://www.elastic.co/guide/en/elasticsearch/reference/current/common-options.html#time-units
        Returns:
        a PartialList of items matching the specified criteria, with an scroll identifier and the scroll validity used if a scroll query was requested. Note that if there are no more results the list will be empty but not null.
      • continueCustomItemScrollQuery

        public PartialList<CustomItem> continueCustomItemScrollQuery​(String customItemType,
                                                                     String scrollIdentifier,
                                                                     String scrollTimeValidity)
        Description copied from interface: PersistenceService
        Continues the execution of a scroll query, to retrieve the next results. If there are no more results the scroll query is also cleared.
        Specified by:
        continueCustomItemScrollQuery in interface PersistenceService
        Parameters:
        customItemType - the identifier of the custom item type we want to continue querying
        scrollIdentifier - a scroll identifier obtained by the execution of a first query and returned in the PartialList object
        scrollTimeValidity - a scroll time validity value for the scroll query to stay valid. This must contain a time unit value such as the ones supported by ElasticSearch, such as the ones declared here : https://www.elastic.co/guide/en/elasticsearch/reference/current/common-options.html#time-units
        Returns:
        a PartialList of items matching the specified criteria, with an scroll identifier and the scroll validity used if a scroll query was requested. Note that if there are no more results the list will be empty but not null.
      • aggregateQuery

        @Deprecated
        public Map<String,​Long> aggregateQuery​(Condition filter,
                                                     BaseAggregate aggregate,
                                                     String itemType)
        Deprecated.
        As of version 1.3.0-incubating, use aggregateWithOptimizedQuery(Condition, BaseAggregate, String) instead
        Description copied from interface: PersistenceService
        Retrieves the number of items with the specified type as defined by the Item subclass public field ITEM_TYPE matching the optional specified condition and aggregated according to the specified BaseAggregate. Also return the global count of document matching the ITEM_TYPE
        Specified by:
        aggregateQuery in interface PersistenceService
        Parameters:
        filter - the condition the items must match or null if no filtering is needed
        aggregate - an aggregate specifying how matching items must be bundled
        itemType - the String representation of the item type we want to retrieve the count of, as defined by its class' ITEM_TYPE field
        Returns:
        a Map associating aggregation dimension name as key and cardinality for that dimension as value
      • aggregateWithOptimizedQuery

        public Map<String,​Long> aggregateWithOptimizedQuery​(Condition filter,
                                                                  BaseAggregate aggregate,
                                                                  String itemType)
        Description copied from interface: PersistenceService
        Retrieves the number of items with the specified type as defined by the Item subclass public field ITEM_TYPE matching the optional specified condition and aggregated according to the specified BaseAggregate. This aggregate won't return the global count and should therefore be much faster than PersistenceService.aggregateQuery(Condition, BaseAggregate, String)
        Specified by:
        aggregateWithOptimizedQuery in interface PersistenceService
        Parameters:
        filter - the condition the items must match or null if no filtering is needed
        aggregate - an aggregate specifying how matching items must be bundled
        itemType - the String representation of the item type we want to retrieve the count of, as defined by its class' ITEM_TYPE field
        Returns:
        a Map associating aggregation dimension name as key and cardinality for that dimension as value
      • aggregateWithOptimizedQuery

        public Map<String,​Long> aggregateWithOptimizedQuery​(Condition filter,
                                                                  BaseAggregate aggregate,
                                                                  String itemType,
                                                                  int size)
        Description copied from interface: PersistenceService
        Retrieves the number of items with the specified type as defined by the Item subclass public field ITEM_TYPE matching the optional specified condition and aggregated according to the specified BaseAggregate.
        Specified by:
        aggregateWithOptimizedQuery in interface PersistenceService
        Parameters:
        filter - the condition the items must match or null if no filtering is needed
        aggregate - an aggregate specifying how matching items must be bundled
        itemType - the String representation of the item type we want to retrieve the count of, as defined by its class' ITEM_TYPE field
        size - size of returned buckets in the response
        Returns:
        a Map associating aggregation dimension name as key and cardinality for that dimension as value
      • purgeTimeBasedItems

        public <T extends Item> void purgeTimeBasedItems​(int existsNumberOfDays,
                                                         Class<T> clazz)
        Description copied from interface: PersistenceService
        Purges time based data in the context server up to the specified days number of existence. (This only works for time based data stored in rolling over indices, it have no effect on other types)
        Specified by:
        purgeTimeBasedItems in interface PersistenceService
        Parameters:
        existsNumberOfDays - the number of days
        clazz - the item type to be purged
      • purge

        public void purge​(String scope)
        Description copied from interface: PersistenceService
        Removes all data associated with the provided scope.
        Specified by:
        purge in interface PersistenceService
        Parameters:
        scope - the scope for which we want to remove data
      • getSingleValuesMetrics

        public Map<String,​Double> getSingleValuesMetrics​(Condition condition,
                                                               String[] metrics,
                                                               String field,
                                                               String itemType)
        Description copied from interface: PersistenceService
        Retrieves the specified metrics for the specified field of items of the specified type as defined by the Item subclass public field ITEM_TYPE and matching the specified Condition.
        Specified by:
        getSingleValuesMetrics in interface PersistenceService
        Parameters:
        condition - the condition the items must satisfy
        metrics - a String array which metrics should be computed (possible values: sum for the sum of the values, avg for the average of the values, min for the minimum value and max for the maximum value)
        field - the name of the field for which the metrics should be computed
        itemType - the String representation of the item type we want to retrieve the count of, as defined by its class' ITEM_TYPE field
        Returns:
        a Map associating computed metric name as key to its associated value