Package io.jsondb

Class JsonDBTemplate

    • Constructor Summary

      Constructors 
      Constructor Description
      JsonDBTemplate​(java.lang.String dbFilesLocationString, java.lang.String baseScanPackage)  
      JsonDBTemplate​(java.lang.String dbFilesLocationString, java.lang.String baseScanPackage, boolean compatibilityMode, java.util.Comparator<java.lang.String> schemaComparator)  
      JsonDBTemplate​(java.lang.String dbFilesLocationString, java.lang.String baseScanPackage, ICipher cipher)  
      JsonDBTemplate​(java.lang.String dbFilesLocationString, java.lang.String baseScanPackage, ICipher cipher, boolean compatibilityMode, java.util.Comparator<java.lang.String> schemaComparator)  
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void addCollectionFileChangeListener​(CollectionFileChangeListener listener)
      adds a CollectionFileChangeListener to db.
      void backup​(java.lang.String backupPath)
      This method backs up JSONDB collections to specified backup path
      <T> void changeEncryption​(ICipher newCipher)
      A method that allows changing the encryption algorithm and or encryption key used.
      <T> boolean collectionExists​(java.lang.Class<T> entityClass)
      Check to see if a collection with a name indicated by the entity class exists.
      boolean collectionExists​(java.lang.String collectionName)
      Check to see if a collection with a given name exists.
      <T> void createCollection​(java.lang.Class<T> entityClass)
      Create an uncapped collection with a name based on the provided entity class.
      <T> void createCollection​(java.lang.String collectionName)
      Create an uncapped collection with the provided name.
      <T> void dropCollection​(java.lang.Class<T> entityClass)
      Drop the collection with the name indicated by the entity class.
      void dropCollection​(java.lang.String collectionName)
      Drop the collection with the given name.
      <T> java.util.List<T> find​(java.lang.String jxQuery, java.lang.Class<T> entityClass)
      Map the results of an ad-hoc query on the collection for the entity class to a List of the specified type.
      <T> java.util.List<T> find​(java.lang.String jxQuery, java.lang.Class<T> entityClass, java.util.Comparator<? super T> comparator)
      Map the results of an ad-hoc query on the collection for the entity class to a List of the specified type.
      <T> java.util.List<T> find​(java.lang.String jxQuery, java.lang.Class<T> entityClass, java.util.Comparator<? super T> comparator, java.lang.String slice)
      Map the results of an ad-hoc query on the specified collection to a List of the specified type.
      <T> java.util.List<T> find​(java.lang.String jxQuery, java.lang.String collectionName)
      Map the results of an ad-hoc query on the specified collection to a List of the specified type.
      <T> java.util.List<T> find​(java.lang.String jxQuery, java.lang.String collectionName, java.util.Comparator<? super T> comparator)
      Map the results of an ad-hoc query on the specified collection to a List of the specified type.
      <T> java.util.List<T> find​(java.lang.String jxQuery, java.lang.String collectionName, java.util.Comparator<? super T> comparator, java.lang.String slice)
      Map the results of an ad-hoc query on the specified collection to a List of the specified type.
      <T> java.util.List<T> findAll​(java.lang.Class<T> entityClass)
      Query for a list of objects of type T from the specified collection.
      <T> java.util.List<T> findAll​(java.lang.Class<T> entityClass, java.util.Comparator<? super T> comparator)
      Query for a list of objects of type T from the specified collection.
      <T> java.util.List<T> findAll​(java.lang.Class<T> entityClass, java.util.Comparator<? super T> comparator, java.lang.String slice)
      Query for a list of objects of type T from the specified collection.
      <T> java.util.List<T> findAll​(java.lang.String collectionName)
      Query for a list of objects of type T from the specified collection.
      <T> java.util.List<T> findAll​(java.lang.String collectionName, java.util.Comparator<? super T> comparator)
      Query for a list of objects of type T from the specified collection.
      <T> java.util.List<T> findAll​(java.lang.String collectionName, java.util.Comparator<? super T> comparator, java.lang.String slice)
      Query for a list of objects of type T from the specified collection.
      <T> java.util.List<T> findAllAndModify​(java.lang.String jxQuery, Update update, java.lang.Class<T> entityClass)  
      <T> java.util.List<T> findAllAndModify​(java.lang.String jxQuery, Update update, java.lang.String collectionName)  
      <T> java.util.List<T> findAllAndRemove​(java.lang.String jxQuery, java.lang.Class<T> entityClass)
      Returns and removes all documents matching the given query form the collection used to store the entityClass.
      <T> java.util.List<T> findAllAndRemove​(java.lang.String jxQuery, java.lang.String collectionName)
      Returns and removes all documents matching the given query form the collection used to store the entityClass.
      <T> T findAndModify​(java.lang.String jxQuery, Update update, java.lang.Class<T> entityClass)
      Triggers findAndModify to apply provided Update on the first document matching Criteria of given Query.
      <T> T findAndModify​(java.lang.String jxQuery, Update update, java.lang.String collectionName)
      Triggers findAndModify to apply provided Update on the first document matching Criteria of given Query.
      <T> T findAndRemove​(java.lang.String jxQuery, java.lang.Class<T> entityClass)
      Map the results of the jxQuery on the collection for the entity type to a single instance of an object of the specified type.
      <T> T findAndRemove​(java.lang.String jxQuery, java.lang.String collectionName)
      Map the results of the jxQuery on the collection for the entity type to a single instance of an object of the specified type.
      <T> T findById​(java.lang.Object id, java.lang.Class<T> entityClass)
      Returns a document with the given id mapped onto the given class.
      <T> T findById​(java.lang.Object id, java.lang.String collectionName)
      Returns the document with the given id from the given collection mapped onto the given target class.
      <T> T findOne​(java.lang.String jxQuery, java.lang.Class<T> entityClass)  
      <T> T findOne​(java.lang.String jxQuery, java.lang.String collectionName)  
      <T> java.util.List<T> getCollection​(java.lang.Class<T> entityClass)
      Get a collection by name, creating it if it doesn't exist.
      java.lang.String getCollectionName​(java.lang.Class<?> entityClass)
      The collection name used for the specified class by this template.
      java.util.Set<java.lang.String> getCollectionNames()
      A set of collection names.
      boolean hasCollectionFileChangeListener()
      a method to check if there are any registered CollectionFileChangeListener
      <T> void insert​(java.lang.Object objectToSave)
      Insert the object into correct collection.
      <T> void insert​(java.lang.Object objectToSave, java.lang.String collectionName)
      Insert the object into the specified collection.
      <T> void insert​(java.util.Collection<? extends T> batchToSave, java.lang.Class<T> entityClass)
      Insert a Collection of objects into a collection in a single batch write to the database.
      <T> void insert​(java.util.Collection<? extends T> batchToSave, java.lang.String collectionName)
      Insert a Collection of objects into a collection in a single batch write to the database.
      <T> boolean isCollectionReadonly​(java.lang.Class<T> entityClass)
      is a collection readonly, A collection can be readonly if its schema version does not match the actualSchema version
      <T> boolean isCollectionReadonly​(java.lang.String collectionName)  
      void reloadCollection​(java.lang.String collectionName)
      Reloads a particular collection from dblocation directory
      void reLoadDB()
      Re-load the collections from dblocation folder.
      <T> T remove​(java.lang.Object objectToRemove, java.lang.Class<T> entityClass)
      Remove the given object from the collection by id.
      <T> T remove​(java.lang.Object objectToRemove, java.lang.String collectionName)
      Remove the given object from the collection by id.
      <T> java.util.List<T> remove​(java.util.Collection<? extends T> batchToRemove, java.lang.Class<T> entityClass)
      Remove a Collection of objects from a collection in a single batch write to the database.
      <T> java.util.List<T> remove​(java.util.Collection<? extends T> batchToRemove, java.lang.String collectionName)
      Remove a Collection of objects from a collection in a single batch write to the database.
      void removeCollectionFileChangeListener​(CollectionFileChangeListener listener)
      removes a previously added CollectionFileChangeListener
      void restore​(java.lang.String restorePath, boolean merge)
      This method restores JSONDB collections from specified restore path.
      <T> void save​(java.lang.Object objectToSave, java.lang.Class<T> entityClass)
      Save the object to the collection for the entity type of the object to save.
      <T> void save​(java.lang.Object objectToSave, java.lang.String collectionName)
      Save the object to the collection for the entity type of the object to save.
      <T> void updateCollectionSchema​(CollectionSchemaUpdate update, java.lang.Class<T> entityClass)  
      <T> void updateCollectionSchema​(CollectionSchemaUpdate update, java.lang.String collectionName)
      Update a collection as per the specified CollectionUpdate param.
      <T> void upsert​(java.lang.Object objectToSave)
      Performs an upsert.
      <T> void upsert​(java.lang.Object objectToSave, java.lang.String collectionName)
      Performs an upsert.
      <T> void upsert​(java.util.Collection<? extends T> batchToSave, java.lang.Class<T> entityClass)
      Performs an upsert.
      <T> void upsert​(java.util.Collection<? extends T> batchToSave, java.lang.String collectionName)
      Performs an upsert.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • JsonDBTemplate

        public JsonDBTemplate​(java.lang.String dbFilesLocationString,
                              java.lang.String baseScanPackage)
      • JsonDBTemplate

        public JsonDBTemplate​(java.lang.String dbFilesLocationString,
                              java.lang.String baseScanPackage,
                              boolean compatibilityMode,
                              java.util.Comparator<java.lang.String> schemaComparator)
      • JsonDBTemplate

        public JsonDBTemplate​(java.lang.String dbFilesLocationString,
                              java.lang.String baseScanPackage,
                              ICipher cipher)
      • JsonDBTemplate

        public JsonDBTemplate​(java.lang.String dbFilesLocationString,
                              java.lang.String baseScanPackage,
                              ICipher cipher,
                              boolean compatibilityMode,
                              java.util.Comparator<java.lang.String> schemaComparator)
    • Method Detail

      • reLoadDB

        public void reLoadDB()
        Description copied from interface: JsonDBOperations
        Re-load the collections from dblocation folder. This functionality is useful if you some other process is going to directly update the collection files in dblocation
        Specified by:
        reLoadDB in interface JsonDBOperations
      • reloadCollection

        public void reloadCollection​(java.lang.String collectionName)
        Description copied from interface: JsonDBOperations
        Reloads a particular collection from dblocation directory
        Specified by:
        reloadCollection in interface JsonDBOperations
        Parameters:
        collectionName - name of the collection to reload
      • hasCollectionFileChangeListener

        public boolean hasCollectionFileChangeListener()
        Description copied from interface: JsonDBOperations
        a method to check if there are any registered CollectionFileChangeListener
        Specified by:
        hasCollectionFileChangeListener in interface JsonDBOperations
        Returns:
        true of there are any registered CollectionFileChangeListeners
      • createCollection

        public <T> void createCollection​(java.lang.Class<T> entityClass)
        Description copied from interface: JsonDBOperations
        Create an uncapped collection with a name based on the provided entity class.
        Specified by:
        createCollection in interface JsonDBOperations
        Type Parameters:
        T - Type annotated with Document annotation and member of the baseScanPackage
        Parameters:
        entityClass - class that determines the collection to create
      • createCollection

        public <T> void createCollection​(java.lang.String collectionName)
        Description copied from interface: JsonDBOperations
        Create an uncapped collection with the provided name.
        Specified by:
        createCollection in interface JsonDBOperations
        Type Parameters:
        T - Type annotated with Document annotation and member of the baseScanPackage
        Parameters:
        collectionName - name of the collection
      • dropCollection

        public <T> void dropCollection​(java.lang.Class<T> entityClass)
        Description copied from interface: JsonDBOperations
        Drop the collection with the name indicated by the entity class.
        Specified by:
        dropCollection in interface JsonDBOperations
        Type Parameters:
        T - Type annotated with Document annotation and member of the baseScanPackage
        Parameters:
        entityClass - class that determines the collection to drop/delete.
      • dropCollection

        public void dropCollection​(java.lang.String collectionName)
        Description copied from interface: JsonDBOperations
        Drop the collection with the given name.
        Specified by:
        dropCollection in interface JsonDBOperations
        Parameters:
        collectionName - name of the collection to drop/delete.
      • updateCollectionSchema

        public <T> void updateCollectionSchema​(CollectionSchemaUpdate update,
                                               java.lang.String collectionName)
        Description copied from interface: JsonDBOperations
        Update a collection as per the specified CollectionUpdate param. This method is only available by collectionName and not by Class.
        Specified by:
        updateCollectionSchema in interface JsonDBOperations
        Type Parameters:
        T - Type annotated with Document annotation and member of the baseScanPackage
        Parameters:
        update - how to update the Collection
        collectionName - name of the collection to update schema for
      • getCollectionNames

        public java.util.Set<java.lang.String> getCollectionNames()
        Description copied from interface: JsonDBOperations
        A set of collection names.
        Specified by:
        getCollectionNames in interface JsonDBOperations
        Returns:
        list of collection names
      • getCollectionName

        public java.lang.String getCollectionName​(java.lang.Class<?> entityClass)
        Description copied from interface: JsonDBOperations
        The collection name used for the specified class by this template.
        Specified by:
        getCollectionName in interface JsonDBOperations
        Parameters:
        entityClass - must not be null.
        Returns:
        name of the collection
      • getCollection

        public <T> java.util.List<T> getCollection​(java.lang.Class<T> entityClass)
        Description copied from interface: JsonDBOperations
        Get a collection by name, creating it if it doesn't exist. The returned collection will be a new copy of the existing collection Modifying its contents will not modify the contents of collection in JsonDB memory.
        Specified by:
        getCollection in interface JsonDBOperations
        Type Parameters:
        T - Type annotated with Document annotation and member of the baseScanPackage
        Parameters:
        entityClass - class that determines the name of the collection
        Returns:
        A copy of the existing collection or a newly created one.
      • collectionExists

        public <T> boolean collectionExists​(java.lang.Class<T> entityClass)
        Description copied from interface: JsonDBOperations
        Check to see if a collection with a name indicated by the entity class exists.
        Specified by:
        collectionExists in interface JsonDBOperations
        Type Parameters:
        T - Type annotated with Document annotation and member of the baseScanPackage
        Parameters:
        entityClass - class that determines the name of the collection
        Returns:
        true if a collection with the given name is found, false otherwise.
      • collectionExists

        public boolean collectionExists​(java.lang.String collectionName)
        Description copied from interface: JsonDBOperations
        Check to see if a collection with a given name exists.
        Specified by:
        collectionExists in interface JsonDBOperations
        Parameters:
        collectionName - name of the collection
        Returns:
        true if a collection with the given name is found, false otherwise.
      • isCollectionReadonly

        public <T> boolean isCollectionReadonly​(java.lang.Class<T> entityClass)
        Description copied from interface: JsonDBOperations
        is a collection readonly, A collection can be readonly if its schema version does not match the actualSchema version
        Specified by:
        isCollectionReadonly in interface JsonDBOperations
        Type Parameters:
        T - Type annotated with Document annotation and member of the baseScanPackage
        Parameters:
        entityClass - class that determines the collection
        Returns:
        true if collection is readonly
      • find

        public <T> java.util.List<T> find​(java.lang.String jxQuery,
                                          java.lang.Class<T> entityClass)
        Description copied from interface: JsonDBOperations
        Map the results of an ad-hoc query on the collection for the entity class to a List of the specified type.
        Specified by:
        find in interface JsonDBOperations
        Type Parameters:
        T - Type annotated with Document annotation and member of the baseScanPackage
        Parameters:
        jxQuery - a XPATH query expression
        entityClass - the parameterized type of the returned list.
        Returns:
        the list of found objects
      • find

        public <T> java.util.List<T> find​(java.lang.String jxQuery,
                                          java.lang.String collectionName)
        Description copied from interface: JsonDBOperations
        Map the results of an ad-hoc query on the specified collection to a List of the specified type.
        Specified by:
        find in interface JsonDBOperations
        Type Parameters:
        T - Type annotated with Document annotation and member of the baseScanPackage
        Parameters:
        jxQuery - a XPATH query expression
        collectionName - name of the collection to retrieve the objects from
        Returns:
        the list of found objects
      • find

        public <T> java.util.List<T> find​(java.lang.String jxQuery,
                                          java.lang.Class<T> entityClass,
                                          java.util.Comparator<? super T> comparator)
        Description copied from interface: JsonDBOperations
        Map the results of an ad-hoc query on the collection for the entity class to a List of the specified type. The objects in result are sorted according to the order induced by the specified comparator. All elements in the array must be mutually comparable by the specified comparator (that is, c.compare(e1, e2) must not throw a ClassCastException for any elements e1 and e2 in the array).
        Specified by:
        find in interface JsonDBOperations
        Type Parameters:
        T - Type annotated with Document annotation and member of the baseScanPackage
        Parameters:
        jxQuery - a XPATH query expression
        entityClass - the parameterized type of the returned list.
        comparator - Comparator to use for sorting the objects
        Returns:
        the list of found objects
      • find

        public <T> java.util.List<T> find​(java.lang.String jxQuery,
                                          java.lang.String collectionName,
                                          java.util.Comparator<? super T> comparator)
        Description copied from interface: JsonDBOperations
        Map the results of an ad-hoc query on the specified collection to a List of the specified type. The objects in result are sorted according to the order induced by the specified comparator. All elements in the array must be mutually comparable by the specified comparator (that is, c.compare(e1, e2) must not throw a ClassCastException for any elements e1 and e2 in the array).
        Specified by:
        find in interface JsonDBOperations
        Type Parameters:
        T - Type annotated with Document annotation and member of the baseScanPackage
        Parameters:
        jxQuery - a XPATH query expression
        collectionName - name of the collection to retrieve the objects from
        comparator - Comparator to use for sorting the objects
        Returns:
        the list of found objects
      • find

        public <T> java.util.List<T> find​(java.lang.String jxQuery,
                                          java.lang.Class<T> entityClass,
                                          java.util.Comparator<? super T> comparator,
                                          java.lang.String slice)
        Description copied from interface: JsonDBOperations
        Map the results of an ad-hoc query on the specified collection to a List of the specified type. The objects in result are sorted according to the order induced by the specified comparator. All elements in the array must be mutually comparable by the specified comparator (that is, c.compare(e1, e2) must not throw a ClassCastException for any elements e1 and e2 in the array).
        Specified by:
        find in interface JsonDBOperations
        Type Parameters:
        T - Type annotated with Document annotation and member of the baseScanPackage
        Parameters:
        jxQuery - a XPATH query expression
        entityClass - the parameterized type of the returned list.
        comparator - Comparator to use for sorting the objects Note: If sorting along with slicing is used then sorting over fields with the 'secret' anotation will actually sort the raw encrypted field value, which will be undesirable and probably useless, this limitation is for efficiency reasons, when slicing is enabled we defer the deep copy and decryption of secret fields until a later stage (which happens after sorting), assuming quite some objects may not be selected due to slicing However if slicing is not used then the sorting will sort over unencrypted field value.
        slice - select the indices to return from the find_result. The behaviour of this slicing feature is similar to the slicing feature in python or numpy, as much as possible https://docs.scipy.org/doc/numpy-1.13.0/reference/arrays.indexing.html A slice is a string notation and the basic slice syntax is i:j:k, where i is the starting index, j is the stopping index, and k is the step (k != 0). In other words it is start:stop:step Example find_result = [T0, T1, T2, T3, T4, T5, T6, T7, T8, T9] slice = "1:7:2" returns [T1, T3, T5] i is inclusive, j is exclusive Negative i and j are interpreted as n + i and n + j where n is the number of elements found. Negative k makes stepping go towards smaller indices. Example find_result = [T0, T1, T2, T3, T4, T5, T6, T7, T8, T9] slice = "-2:10" returns [T8, T9] slice = "-3:3:-1" returns [T7, T6, T5, T4] Assume n is the number of elements in find_result. Then, if i is not given it defaults to 0 for k>0 and n - 1 for k<0 . If j is not given it defaults to n for k>0 and -n-1 for k<0 If k is not given it defaults to 1. Note that :: is the same as : and means select all indices from find_result. Example find_result = [T0, T1, T2, T3, T4, T5, T6, T7, T8, T9] slice = "5:" returns [T5, T6, T7, T8, T9] Assume n is the number of elements in find_result. Then, if j>n then it is considered as n, in case of negative j it is considered -n.
        Returns:
        the list of found objects
      • find

        public <T> java.util.List<T> find​(java.lang.String jxQuery,
                                          java.lang.String collectionName,
                                          java.util.Comparator<? super T> comparator,
                                          java.lang.String slice)
        Description copied from interface: JsonDBOperations
        Map the results of an ad-hoc query on the specified collection to a List of the specified type. The objects in result are sorted according to the order induced by the specified comparator. All elements in the array must be mutually comparable by the specified comparator (that is, c.compare(e1, e2) must not throw a ClassCastException for any elements e1 and e2 in the array).
        Specified by:
        find in interface JsonDBOperations
        Type Parameters:
        T - Type annotated with Document annotation and member of the baseScanPackage
        Parameters:
        jxQuery - a XPATH query expression
        collectionName - name of the collection to retrieve the objects from
        comparator - Comparator to use for sorting the objects Note: If sorting along with slicing is used then sorting over fields with the 'secret' anotation will actually sort the raw encrypted field value, which will be undesirable and probably useless, this limitation is for efficiency reasons, when slicing is enabled we defer the deep copy and decryption of secret fields until a later stage (which happens after sorting), assuming quite some objects may not be selected due to slicing However if slicing is not used then the sorting will sort over unencrypted field value.
        slice - select the indices to return from the find_result. The behaviour of this slicing feature is similar to the slicing feature in python or numpy, as much as possible https://docs.scipy.org/doc/numpy-1.13.0/reference/arrays.indexing.html A slice is a string notation and the basic slice syntax is i:j:k, where i is the starting index, j is the stopping index, and k is the step (k != 0). In other words it is start:stop:step Example find_result = [T0, T1, T2, T3, T4, T5, T6, T7, T8, T9] slice = "1:7:2" returns [T1, T3, T5] i is inclusive, j is exclusive Negative i and j are interpreted as n + i and n + j where n is the number of elements found. Negative k makes stepping go towards smaller indices. Example find_result = [T0, T1, T2, T3, T4, T5, T6, T7, T8, T9] slice = "-2:10" returns [T8, T9] slice = "-3:3:-1" returns [T7, T6, T5, T4] Assume n is the number of elements in find_result. Then, if i is not given it defaults to 0 for k>0 and n - 1 for k<0 . If j is not given it defaults to n for k>0 and -n-1 for k<0 If k is not given it defaults to 1. Note that :: is the same as : and means select all indices from find_result. Example find_result = [T0, T1, T2, T3, T4, T5, T6, T7, T8, T9] slice = "5:" returns [T5, T6, T7, T8, T9] Assume n is the number of elements in find_result. Then, if j>n then it is considered as n, in case of negative j it is considered -n.
        Returns:
        the list of found objects
      • findAll

        public <T> java.util.List<T> findAll​(java.lang.Class<T> entityClass)
        Description copied from interface: JsonDBOperations
        Query for a list of objects of type T from the specified collection.
        Specified by:
        findAll in interface JsonDBOperations
        Type Parameters:
        T - Type annotated with Document annotation and member of the baseScanPackage
        Parameters:
        entityClass - the parameterized type of the returned list.
        Returns:
        the found collection
      • findAll

        public <T> java.util.List<T> findAll​(java.lang.String collectionName)
        Description copied from interface: JsonDBOperations
        Query for a list of objects of type T from the specified collection.
        Specified by:
        findAll in interface JsonDBOperations
        Type Parameters:
        T - Type annotated with Document annotation and member of the baseScanPackage
        Parameters:
        collectionName - name of the collection to retrieve the objects from
        Returns:
        the found collection
      • findAll

        public <T> java.util.List<T> findAll​(java.lang.Class<T> entityClass,
                                             java.util.Comparator<? super T> comparator)
        Description copied from interface: JsonDBOperations
        Query for a list of objects of type T from the specified collection.
        Specified by:
        findAll in interface JsonDBOperations
        Type Parameters:
        T - Type annotated with Document annotation and member of the baseScanPackage
        Parameters:
        entityClass - the parameterized type of the returned list.
        comparator - Comparator to use for sorting the objects
        Returns:
        the found collection
      • findAll

        public <T> java.util.List<T> findAll​(java.lang.String collectionName,
                                             java.util.Comparator<? super T> comparator)
        Description copied from interface: JsonDBOperations
        Query for a list of objects of type T from the specified collection.
        Specified by:
        findAll in interface JsonDBOperations
        Type Parameters:
        T - Type annotated with Document annotation and member of the baseScanPackage
        Parameters:
        collectionName - name of the collection to retrieve the objects from
        comparator - Comparator to use for sorting the objects
        Returns:
        the found collection
      • findAll

        public <T> java.util.List<T> findAll​(java.lang.Class<T> entityClass,
                                             java.util.Comparator<? super T> comparator,
                                             java.lang.String slice)
        Description copied from interface: JsonDBOperations
        Query for a list of objects of type T from the specified collection.
        Specified by:
        findAll in interface JsonDBOperations
        Type Parameters:
        T - Type annotated with Document annotation and member of the baseScanPackage
        Parameters:
        entityClass - the parameterized type of the returned list.
        comparator - Comparator to use for sorting the objects Note: If sorting along with slicing is used then sorting over fields with the 'secret' anotation will actually sort the raw encrypted field value, which will be undesirable and probably useless, this limitation is for efficiency reasons, when slicing is enabled we defer the deep copy and decryption of secret fields until a later stage (which happens after sorting), assuming quite some objects may not be selected due to slicing However if slicing is not used then the sorting will sort over unencrypted field value.
        slice - select the indices to return from the find_result. The behaviour of this slicing feature is similar to the slicing feature in python or numpy, as much as possible https://docs.scipy.org/doc/numpy-1.13.0/reference/arrays.indexing.html A slice is a string notation and the basic slice syntax is i:j:k, where i is the starting index, j is the stopping index, and k is the step (k != 0). In other words it is start:stop:step Example find_result = [T0, T1, T2, T3, T4, T5, T6, T7, T8, T9] slice = "1:7:2" returns [T1, T3, T5] i is inclusive, j is exclusive Negative i and j are interpreted as n + i and n + j where n is the number of elements found. Negative k makes stepping go towards smaller indices. Example find_result = [T0, T1, T2, T3, T4, T5, T6, T7, T8, T9] slice = "-2:10" returns [T8, T9] slice = "-3:3:-1" returns [T7, T6, T5, T4] Assume n is the number of elements in find_result. Then, if i is not given it defaults to 0 for k>0 and n - 1 for k<0 . If j is not given it defaults to n for k>0 and -n-1 for k<0 If k is not given it defaults to 1. Note that :: is the same as : and means select all indices from find_result. Example find_result = [T0, T1, T2, T3, T4, T5, T6, T7, T8, T9] slice = "5:" returns [T5, T6, T7, T8, T9] Assume n is the number of elements in find_result. Then, if j>n then it is considered as n, in case of negative j it is considered -n.
        Returns:
        the found collection
      • findAll

        public <T> java.util.List<T> findAll​(java.lang.String collectionName,
                                             java.util.Comparator<? super T> comparator,
                                             java.lang.String slice)
        Description copied from interface: JsonDBOperations
        Query for a list of objects of type T from the specified collection.
        Specified by:
        findAll in interface JsonDBOperations
        Type Parameters:
        T - Type annotated with Document annotation and member of the baseScanPackage
        Parameters:
        collectionName - name of the collection to retrieve the objects from
        comparator - Comparator to use for sorting the objects Note: If sorting along with slicing is used then sorting over fields with the 'secret' anotation will actually sort the raw encrypted field value, which will be undesirable and probably useless, this limitation is for efficiency reasons, when slicing is enabled we defer the deep copy and decryption of secret fields until a later stage (which happens after sorting), assuming quite some objects may not be selected due to slicing However if slicing is not used then the sorting will sort over unencrypted field value.
        slice - select the indices to return from the find_result. The behaviour of this slicing feature is similar to the slicing feature in python or numpy, as much as possible https://docs.scipy.org/doc/numpy-1.13.0/reference/arrays.indexing.html A slice is a string notation and the basic slice syntax is i:j:k, where i is the starting index, j is the stopping index, and k is the step (k != 0). In other words it is start:stop:step Example find_result = [T0, T1, T2, T3, T4, T5, T6, T7, T8, T9] slice = "1:7:2" returns [T1, T3, T5] i is inclusive, j is exclusive Negative i and j are interpreted as n + i and n + j where n is the number of elements found. Negative k makes stepping go towards smaller indices. Example find_result = [T0, T1, T2, T3, T4, T5, T6, T7, T8, T9] slice = "-2:10" returns [T8, T9] slice = "-3:3:-1" returns [T7, T6, T5, T4] Assume n is the number of elements in find_result. Then, if i is not given it defaults to 0 for k>0 and n - 1 for k<0 . If j is not given it defaults to n for k>0 and -n-1 for k<0 If k is not given it defaults to 1. Note that :: is the same as : and means select all indices from find_result. Example find_result = [T0, T1, T2, T3, T4, T5, T6, T7, T8, T9] slice = "5:" returns [T5, T6, T7, T8, T9] Assume n is the number of elements in find_result. Then, if j>n then it is considered as n, in case of negative j it is considered -n.
        Returns:
        the found collection
      • findById

        public <T> T findById​(java.lang.Object id,
                              java.lang.Class<T> entityClass)
        Description copied from interface: JsonDBOperations
        Returns a document with the given id mapped onto the given class. The collection the query is ran against will be derived from the given target class as well.
        Specified by:
        findById in interface JsonDBOperations
        Type Parameters:
        T - Type annotated with Document annotation and member of the baseScanPackage
        Parameters:
        id - the id of the document to return.
        entityClass - the type the document shall be converted into.
        Returns:
        the document with the given id mapped onto the given target class.
      • findById

        public <T> T findById​(java.lang.Object id,
                              java.lang.String collectionName)
        Description copied from interface: JsonDBOperations
        Returns the document with the given id from the given collection mapped onto the given target class.
        Specified by:
        findById in interface JsonDBOperations
        Type Parameters:
        T - Type annotated with Document annotation and member of the baseScanPackage
        Parameters:
        id - the id of the document to return
        collectionName - the collection to query for the document
        Returns:
        object searched within the collection
      • findOne

        public <T> T findOne​(java.lang.String jxQuery,
                             java.lang.Class<T> entityClass)
        Specified by:
        findOne in interface JsonDBOperations
      • findOne

        public <T> T findOne​(java.lang.String jxQuery,
                             java.lang.String collectionName)
        Specified by:
        findOne in interface JsonDBOperations
      • insert

        public <T> void insert​(java.lang.Object objectToSave)
        Description copied from interface: JsonDBOperations
        Insert the object into correct collection. The collection type of the object is automatically determined. Insert is used to initially store the object into the database. To update an existing object use the save method.
        Specified by:
        insert in interface JsonDBOperations
        Type Parameters:
        T - Type annotated with Document annotation and member of the baseScanPackage
        Parameters:
        objectToSave - the object to store in the collection
      • insert

        public <T> void insert​(java.lang.Object objectToSave,
                               java.lang.String collectionName)
        Description copied from interface: JsonDBOperations
        Insert the object into the specified collection. Insert is used to initially store the object into the database. To update an existing object use the save method.
        Specified by:
        insert in interface JsonDBOperations
        Type Parameters:
        T - Type annotated with Document annotation and member of the baseScanPackage
        Parameters:
        objectToSave - the object to store in the collection
        collectionName - name of the collection to store the object in
      • insert

        public <T> void insert​(java.util.Collection<? extends T> batchToSave,
                               java.lang.Class<T> entityClass)
        Description copied from interface: JsonDBOperations
        Insert a Collection of objects into a collection in a single batch write to the database.
        Specified by:
        insert in interface JsonDBOperations
        Type Parameters:
        T - Type annotated with Document annotation and member of the baseScanPackage
        Parameters:
        batchToSave - the list of objects to save.
        entityClass - class that determines the collection to use
      • insert

        public <T> void insert​(java.util.Collection<? extends T> batchToSave,
                               java.lang.String collectionName)
        Description copied from interface: JsonDBOperations
        Insert a Collection of objects into a collection in a single batch write to the database.
        Specified by:
        insert in interface JsonDBOperations
        Type Parameters:
        T - Type annotated with Document annotation and member of the baseScanPackage
        Parameters:
        batchToSave - the list of objects to save.
        collectionName - name of the collection to store the object in
      • save

        public <T> void save​(java.lang.Object objectToSave,
                             java.lang.Class<T> entityClass)
        Description copied from interface: JsonDBOperations
        Save the object to the collection for the entity type of the object to save. This will throw a exception if the object is not already present. This is a not same as MongoDB behaviour
        Specified by:
        save in interface JsonDBOperations
        Type Parameters:
        T - Type annotated with Document annotation and member of the baseScanPackage
        Parameters:
        objectToSave - the object to store in the collection
        entityClass - class that determines the collection to use
      • save

        public <T> void save​(java.lang.Object objectToSave,
                             java.lang.String collectionName)
        Description copied from interface: JsonDBOperations
        Save the object to the collection for the entity type of the object to save. This will throw a exception if the object is not already present. This is a not same as MongoDB behaviour
        Specified by:
        save in interface JsonDBOperations
        Type Parameters:
        T - Type annotated with Document annotation and member of the baseScanPackage
        Parameters:
        objectToSave - the object to store in the collection
        collectionName - name of the collection to store the object in
      • remove

        public <T> T remove​(java.lang.Object objectToRemove,
                            java.lang.Class<T> entityClass)
        Description copied from interface: JsonDBOperations
        Remove the given object from the collection by id.
        Specified by:
        remove in interface JsonDBOperations
        Type Parameters:
        T - Type annotated with Document annotation and member of the baseScanPackage
        Parameters:
        objectToRemove - the object to remove from the collection
        entityClass - class that determines the collection to use
        Returns:
        the object that was actually removed or null
      • remove

        public <T> T remove​(java.lang.Object objectToRemove,
                            java.lang.String collectionName)
        Description copied from interface: JsonDBOperations
        Remove the given object from the collection by id.
        Specified by:
        remove in interface JsonDBOperations
        Type Parameters:
        T - Type annotated with Document annotation and member of the baseScanPackage
        Parameters:
        objectToRemove - the object to remove from the collection
        collectionName - name of the collection to remove the object from
        Returns:
        the object that was actually removed or null
      • remove

        public <T> java.util.List<T> remove​(java.util.Collection<? extends T> batchToRemove,
                                            java.lang.Class<T> entityClass)
        Description copied from interface: JsonDBOperations
        Remove a Collection of objects from a collection in a single batch write to the database.
        Specified by:
        remove in interface JsonDBOperations
        Type Parameters:
        T - Type annotated with Document annotation and member of the baseScanPackage
        Parameters:
        batchToRemove - the list of objects to remove.
        entityClass - class that determines the collection to use
        Returns:
        List of objects actually removed or null
      • remove

        public <T> java.util.List<T> remove​(java.util.Collection<? extends T> batchToRemove,
                                            java.lang.String collectionName)
        Description copied from interface: JsonDBOperations
        Remove a Collection of objects from a collection in a single batch write to the database.
        Specified by:
        remove in interface JsonDBOperations
        Type Parameters:
        T - Type annotated with Document annotation and member of the baseScanPackage
        Parameters:
        batchToRemove - the list of objects to remove.
        collectionName - name of the collection to remove the objects from
        Returns:
        List of objects actually removed or null
      • upsert

        public <T> void upsert​(java.lang.Object objectToSave)
        Description copied from interface: JsonDBOperations
        Performs an upsert. If no document is found that matches the query, a new document is created and inserted, else the found document is updated with contents of object
        Specified by:
        upsert in interface JsonDBOperations
        Type Parameters:
        T - Type annotated with Document annotation and member of the baseScanPackage
        Parameters:
        objectToSave - the object to update.
      • upsert

        public <T> void upsert​(java.lang.Object objectToSave,
                               java.lang.String collectionName)
        Description copied from interface: JsonDBOperations
        Performs an upsert. If no document is found that matches the query, a new document is created and inserted, else the found document is updated with contents of object
        Specified by:
        upsert in interface JsonDBOperations
        Type Parameters:
        T - Type annotated with Document annotation and member of the baseScanPackage
        Parameters:
        objectToSave - the object to update.
        collectionName - name of the collection to update the objects from
      • upsert

        public <T> void upsert​(java.util.Collection<? extends T> batchToSave,
                               java.lang.Class<T> entityClass)
        Description copied from interface: JsonDBOperations
        Performs an upsert. If no document is found that matches the input, new documents are created and inserted, else the found document is updated with contents of object
        Specified by:
        upsert in interface JsonDBOperations
        Type Parameters:
        T - Type annotated with Document annotation and member of the baseScanPackage
        Parameters:
        batchToSave - the list of objects to update.
        entityClass - class that determines the collection to use
      • upsert

        public <T> void upsert​(java.util.Collection<? extends T> batchToSave,
                               java.lang.String collectionName)
        Description copied from interface: JsonDBOperations
        Performs an upsert. If no document is found that matches the input, new documents are created and inserted, else the found document is updated with contents of object
        Specified by:
        upsert in interface JsonDBOperations
        Type Parameters:
        T - Type annotated with Document annotation and member of the baseScanPackage
        Parameters:
        batchToSave - the list of objects to update.
        collectionName - name of the collection to update the objects from
      • findAndRemove

        public <T> T findAndRemove​(java.lang.String jxQuery,
                                   java.lang.Class<T> entityClass)
        Description copied from interface: JsonDBOperations
        Map the results of the jxQuery on the collection for the entity type to a single instance of an object of the specified type. The first document that matches the query is returned and also removed from the collection in the database. Both the find and remove operation is done atomically
        Specified by:
        findAndRemove in interface JsonDBOperations
        Type Parameters:
        T - Type annotated with Document annotation and member of the baseScanPackage
        Parameters:
        jxQuery - JxPath query string
        entityClass - class that determines the collection to use
        Returns:
        the removed object or null
      • findAndRemove

        public <T> T findAndRemove​(java.lang.String jxQuery,
                                   java.lang.String collectionName)
        Description copied from interface: JsonDBOperations
        Map the results of the jxQuery on the collection for the entity type to a single instance of an object of the specified type. The first document that matches the query is returned and also removed from the collection in the database. Both the find and remove operation is done atomically
        Specified by:
        findAndRemove in interface JsonDBOperations
        Type Parameters:
        T - Type annotated with Document annotation and member of the baseScanPackage
        Parameters:
        jxQuery - JxPath query string
        collectionName - name of the collection to update the objects from
        Returns:
        the removed object or null
      • findAllAndRemove

        public <T> java.util.List<T> findAllAndRemove​(java.lang.String jxQuery,
                                                      java.lang.Class<T> entityClass)
        Description copied from interface: JsonDBOperations
        Returns and removes all documents matching the given query form the collection used to store the entityClass. Both the find and remove operation is done atomically
        Specified by:
        findAllAndRemove in interface JsonDBOperations
        Type Parameters:
        T - Type annotated with Document annotation and member of the baseScanPackage
        Parameters:
        jxQuery - JxPath query string
        entityClass - class that determines the collection to use
        Returns:
        the list of removed objects or null
      • findAllAndRemove

        public <T> java.util.List<T> findAllAndRemove​(java.lang.String jxQuery,
                                                      java.lang.String collectionName)
        Description copied from interface: JsonDBOperations
        Returns and removes all documents matching the given query form the collection used to store the entityClass. Both the find and remove operation is done atomically
        Specified by:
        findAllAndRemove in interface JsonDBOperations
        Type Parameters:
        T - Type annotated with Document annotation and member of the baseScanPackage
        Parameters:
        jxQuery - JxPath query string
        collectionName - name of the collection to update the objects from
        Returns:
        the list of removed objects or null
      • findAndModify

        public <T> T findAndModify​(java.lang.String jxQuery,
                                   Update update,
                                   java.lang.Class<T> entityClass)
        Description copied from interface: JsonDBOperations
        Triggers findAndModify to apply provided Update on the first document matching Criteria of given Query. Both the find and remove operation is done atomically
        Specified by:
        findAndModify in interface JsonDBOperations
        Type Parameters:
        T - Type annotated with Document annotation and member of the baseScanPackage
        Parameters:
        jxQuery - JxPath query string
        update - The Update operation to perform
        entityClass - class that determines the collection to use
        Returns:
        first object that was modified or null
      • findAndModify

        public <T> T findAndModify​(java.lang.String jxQuery,
                                   Update update,
                                   java.lang.String collectionName)
        Description copied from interface: JsonDBOperations
        Triggers findAndModify to apply provided Update on the first document matching Criteria of given Query. Both the find and remove operation is done atomically
        Specified by:
        findAndModify in interface JsonDBOperations
        Type Parameters:
        T - Type annotated with Document annotation and member of the baseScanPackage
        Parameters:
        jxQuery - JxPath query string
        update - The Update operation to perform
        collectionName - name of the collection to update the objects from
        Returns:
        first object that was modified or null
      • findAllAndModify

        public <T> java.util.List<T> findAllAndModify​(java.lang.String jxQuery,
                                                      Update update,
                                                      java.lang.Class<T> entityClass)
        Specified by:
        findAllAndModify in interface JsonDBOperations
      • findAllAndModify

        public <T> java.util.List<T> findAllAndModify​(java.lang.String jxQuery,
                                                      Update update,
                                                      java.lang.String collectionName)
        Specified by:
        findAllAndModify in interface JsonDBOperations
      • changeEncryption

        public <T> void changeEncryption​(ICipher newCipher)
        Description copied from interface: JsonDBOperations
        A method that allows changing the encryption algorithm and or encryption key used. This operation could take time. If for some reason the operation crashes in between the database will be left in a inconsistent state, So it would be better to back up the database before you carry out this operation It will change all the json files that have any keys that are secret
        Specified by:
        changeEncryption in interface JsonDBOperations
        Type Parameters:
        T - Type annotated with Document annotation and member of the baseScanPackage
        Parameters:
        newCipher - a new cipher to use, the algorithm may be same and just the key may be new
      • backup

        public void backup​(java.lang.String backupPath)
        Description copied from interface: JsonDBOperations
        This method backs up JSONDB collections to specified backup path
        Specified by:
        backup in interface JsonDBOperations
        Parameters:
        backupPath - location at which to backup the database contents
      • restore

        public void restore​(java.lang.String restorePath,
                            boolean merge)
        Description copied from interface: JsonDBOperations
        This method restores JSONDB collections from specified restore path. if merge flag is set to true restore operation will merge collections from restore location and if it is set to false it will replace existing collections with collections being restored
        Specified by:
        restore in interface JsonDBOperations
        Parameters:
        restorePath - path were backup jsondb files are present
        merge - whether to merge data from restore location