Package io.jsondb
Class JsonDBTemplate
- java.lang.Object
-
- io.jsondb.JsonDBTemplate
-
- All Implemented Interfaces:
JsonDBOperations
public class JsonDBTemplate extends java.lang.Object implements JsonDBOperations
-
-
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 voidaddCollectionFileChangeListener(CollectionFileChangeListener listener)adds a CollectionFileChangeListener to db.voidbackup(java.lang.String backupPath)This method backs up JSONDB collections to specified backup path<T> voidchangeEncryption(ICipher newCipher)A method that allows changing the encryption algorithm and or encryption key used.<T> booleancollectionExists(java.lang.Class<T> entityClass)Check to see if a collection with a name indicated by the entity class exists.booleancollectionExists(java.lang.String collectionName)Check to see if a collection with a given name exists.<T> voidcreateCollection(java.lang.Class<T> entityClass)Create an uncapped collection with a name based on the provided entity class.<T> voidcreateCollection(java.lang.String collectionName)Create an uncapped collection with the provided name.<T> voiddropCollection(java.lang.Class<T> entityClass)Drop the collection with the name indicated by the entity class.voiddropCollection(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> TfindAndModify(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> TfindAndModify(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> TfindAndRemove(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> TfindAndRemove(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> TfindById(java.lang.Object id, java.lang.Class<T> entityClass)Returns a document with the given id mapped onto the given class.<T> TfindById(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> TfindOne(java.lang.String jxQuery, java.lang.Class<T> entityClass)<T> TfindOne(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.StringgetCollectionName(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.booleanhasCollectionFileChangeListener()a method to check if there are any registered CollectionFileChangeListener<T> voidinsert(java.lang.Object objectToSave)Insert the object into correct collection.<T> voidinsert(java.lang.Object objectToSave, java.lang.String collectionName)Insert the object into the specified collection.<T> voidinsert(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> voidinsert(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> booleanisCollectionReadonly(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> booleanisCollectionReadonly(java.lang.String collectionName)voidreloadCollection(java.lang.String collectionName)Reloads a particular collection from dblocation directoryvoidreLoadDB()Re-load the collections from dblocation folder.<T> Tremove(java.lang.Object objectToRemove, java.lang.Class<T> entityClass)Remove the given object from the collection by id.<T> Tremove(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.voidremoveCollectionFileChangeListener(CollectionFileChangeListener listener)removes a previously added CollectionFileChangeListenervoidrestore(java.lang.String restorePath, boolean merge)This method restores JSONDB collections from specified restore path.<T> voidsave(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> voidsave(java.lang.Object objectToSave, java.lang.String collectionName)Save the object to the collection for the entity type of the object to save.<T> voidupdateCollectionSchema(CollectionSchemaUpdate update, java.lang.Class<T> entityClass)<T> voidupdateCollectionSchema(CollectionSchemaUpdate update, java.lang.String collectionName)Update a collection as per the specified CollectionUpdate param.<T> voidupsert(java.lang.Object objectToSave)Performs an upsert.<T> voidupsert(java.lang.Object objectToSave, java.lang.String collectionName)Performs an upsert.<T> voidupsert(java.util.Collection<? extends T> batchToSave, java.lang.Class<T> entityClass)Performs an upsert.<T> voidupsert(java.util.Collection<? extends T> batchToSave, java.lang.String collectionName)Performs an upsert.
-
-
-
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:JsonDBOperationsRe-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:
reLoadDBin interfaceJsonDBOperations
-
reloadCollection
public void reloadCollection(java.lang.String collectionName)
Description copied from interface:JsonDBOperationsReloads a particular collection from dblocation directory- Specified by:
reloadCollectionin interfaceJsonDBOperations- Parameters:
collectionName- name of the collection to reload
-
addCollectionFileChangeListener
public void addCollectionFileChangeListener(CollectionFileChangeListener listener)
Description copied from interface:JsonDBOperationsadds a CollectionFileChangeListener to db. NOTE: This method uses FileWatchers and on MAC we get now events for file changes so this does not work on Mac- Specified by:
addCollectionFileChangeListenerin interfaceJsonDBOperations- Parameters:
listener- actual listener to add
-
removeCollectionFileChangeListener
public void removeCollectionFileChangeListener(CollectionFileChangeListener listener)
Description copied from interface:JsonDBOperationsremoves a previously added CollectionFileChangeListener- Specified by:
removeCollectionFileChangeListenerin interfaceJsonDBOperations- Parameters:
listener- actual listener to remove
-
hasCollectionFileChangeListener
public boolean hasCollectionFileChangeListener()
Description copied from interface:JsonDBOperationsa method to check if there are any registered CollectionFileChangeListener- Specified by:
hasCollectionFileChangeListenerin interfaceJsonDBOperations- Returns:
- true of there are any registered CollectionFileChangeListeners
-
createCollection
public <T> void createCollection(java.lang.Class<T> entityClass)
Description copied from interface:JsonDBOperationsCreate an uncapped collection with a name based on the provided entity class.- Specified by:
createCollectionin interfaceJsonDBOperations- Type Parameters:
T- Type annotated withDocumentannotation 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:JsonDBOperationsCreate an uncapped collection with the provided name.- Specified by:
createCollectionin interfaceJsonDBOperations- Type Parameters:
T- Type annotated withDocumentannotation 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:JsonDBOperationsDrop the collection with the name indicated by the entity class.- Specified by:
dropCollectionin interfaceJsonDBOperations- Type Parameters:
T- Type annotated withDocumentannotation 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:JsonDBOperationsDrop the collection with the given name.- Specified by:
dropCollectionin interfaceJsonDBOperations- Parameters:
collectionName- name of the collection to drop/delete.
-
updateCollectionSchema
public <T> void updateCollectionSchema(CollectionSchemaUpdate update, java.lang.Class<T> entityClass)
- Specified by:
updateCollectionSchemain interfaceJsonDBOperations
-
updateCollectionSchema
public <T> void updateCollectionSchema(CollectionSchemaUpdate update, java.lang.String collectionName)
Description copied from interface:JsonDBOperationsUpdate a collection as per the specified CollectionUpdate param. This method is only available by collectionName and not by Class.- Specified by:
updateCollectionSchemain interfaceJsonDBOperations- Type Parameters:
T- Type annotated withDocumentannotation and member of the baseScanPackage- Parameters:
update- how to update the CollectioncollectionName- name of the collection to update schema for
-
getCollectionNames
public java.util.Set<java.lang.String> getCollectionNames()
Description copied from interface:JsonDBOperationsA set of collection names.- Specified by:
getCollectionNamesin interfaceJsonDBOperations- Returns:
- list of collection names
-
getCollectionName
public java.lang.String getCollectionName(java.lang.Class<?> entityClass)
Description copied from interface:JsonDBOperationsThe collection name used for the specified class by this template.- Specified by:
getCollectionNamein interfaceJsonDBOperations- 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:JsonDBOperationsGet 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:
getCollectionin interfaceJsonDBOperations- Type Parameters:
T- Type annotated withDocumentannotation 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:JsonDBOperationsCheck to see if a collection with a name indicated by the entity class exists.- Specified by:
collectionExistsin interfaceJsonDBOperations- Type Parameters:
T- Type annotated withDocumentannotation 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:JsonDBOperationsCheck to see if a collection with a given name exists.- Specified by:
collectionExistsin interfaceJsonDBOperations- 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:JsonDBOperationsis a collection readonly, A collection can be readonly if its schema version does not match the actualSchema version- Specified by:
isCollectionReadonlyin interfaceJsonDBOperations- Type Parameters:
T- Type annotated withDocumentannotation and member of the baseScanPackage- Parameters:
entityClass- class that determines the collection- Returns:
- true if collection is readonly
-
isCollectionReadonly
public <T> boolean isCollectionReadonly(java.lang.String collectionName)
- Specified by:
isCollectionReadonlyin interfaceJsonDBOperations
-
find
public <T> java.util.List<T> find(java.lang.String jxQuery, java.lang.Class<T> entityClass)Description copied from interface:JsonDBOperationsMap the results of an ad-hoc query on the collection for the entity class to a List of the specified type.- Specified by:
findin interfaceJsonDBOperations- Type Parameters:
T- Type annotated withDocumentannotation and member of the baseScanPackage- Parameters:
jxQuery- a XPATH query expressionentityClass- 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:JsonDBOperationsMap the results of an ad-hoc query on the specified collection to a List of the specified type.- Specified by:
findin interfaceJsonDBOperations- Type Parameters:
T- Type annotated withDocumentannotation and member of the baseScanPackage- Parameters:
jxQuery- a XPATH query expressioncollectionName- 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:JsonDBOperationsMap 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:
findin interfaceJsonDBOperations- Type Parameters:
T- Type annotated withDocumentannotation and member of the baseScanPackage- Parameters:
jxQuery- a XPATH query expressionentityClass- 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:JsonDBOperationsMap 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:
findin interfaceJsonDBOperations- Type Parameters:
T- Type annotated withDocumentannotation and member of the baseScanPackage- Parameters:
jxQuery- a XPATH query expressioncollectionName- name of the collection to retrieve the objects fromcomparator- 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:JsonDBOperationsMap 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:
findin interfaceJsonDBOperations- Type Parameters:
T- Type annotated withDocumentannotation and member of the baseScanPackage- Parameters:
jxQuery- a XPATH query expressionentityClass- 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:JsonDBOperationsMap 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:
findin interfaceJsonDBOperations- Type Parameters:
T- Type annotated withDocumentannotation and member of the baseScanPackage- Parameters:
jxQuery- a XPATH query expressioncollectionName- name of the collection to retrieve the objects fromcomparator- 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:JsonDBOperationsQuery for a list of objects of type T from the specified collection.- Specified by:
findAllin interfaceJsonDBOperations- Type Parameters:
T- Type annotated withDocumentannotation 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:JsonDBOperationsQuery for a list of objects of type T from the specified collection.- Specified by:
findAllin interfaceJsonDBOperations- Type Parameters:
T- Type annotated withDocumentannotation 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:JsonDBOperationsQuery for a list of objects of type T from the specified collection.- Specified by:
findAllin interfaceJsonDBOperations- Type Parameters:
T- Type annotated withDocumentannotation 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:JsonDBOperationsQuery for a list of objects of type T from the specified collection.- Specified by:
findAllin interfaceJsonDBOperations- Type Parameters:
T- Type annotated withDocumentannotation and member of the baseScanPackage- Parameters:
collectionName- name of the collection to retrieve the objects fromcomparator- 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:JsonDBOperationsQuery for a list of objects of type T from the specified collection.- Specified by:
findAllin interfaceJsonDBOperations- Type Parameters:
T- Type annotated withDocumentannotation 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:JsonDBOperationsQuery for a list of objects of type T from the specified collection.- Specified by:
findAllin interfaceJsonDBOperations- Type Parameters:
T- Type annotated withDocumentannotation and member of the baseScanPackage- Parameters:
collectionName- name of the collection to retrieve the objects fromcomparator- 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:JsonDBOperationsReturns 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:
findByIdin interfaceJsonDBOperations- Type Parameters:
T- Type annotated withDocumentannotation 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:JsonDBOperationsReturns the document with the given id from the given collection mapped onto the given target class.- Specified by:
findByIdin interfaceJsonDBOperations- Type Parameters:
T- Type annotated withDocumentannotation and member of the baseScanPackage- Parameters:
id- the id of the document to returncollectionName- 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:
findOnein interfaceJsonDBOperations
-
findOne
public <T> T findOne(java.lang.String jxQuery, java.lang.String collectionName)- Specified by:
findOnein interfaceJsonDBOperations
-
insert
public <T> void insert(java.lang.Object objectToSave)
Description copied from interface:JsonDBOperationsInsert 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:
insertin interfaceJsonDBOperations- Type Parameters:
T- Type annotated withDocumentannotation 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:JsonDBOperationsInsert 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:
insertin interfaceJsonDBOperations- Type Parameters:
T- Type annotated withDocumentannotation and member of the baseScanPackage- Parameters:
objectToSave- the object to store in the collectioncollectionName- 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:JsonDBOperationsInsert a Collection of objects into a collection in a single batch write to the database.- Specified by:
insertin interfaceJsonDBOperations- Type Parameters:
T- Type annotated withDocumentannotation 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:JsonDBOperationsInsert a Collection of objects into a collection in a single batch write to the database.- Specified by:
insertin interfaceJsonDBOperations- Type Parameters:
T- Type annotated withDocumentannotation 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:JsonDBOperationsSave 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:
savein interfaceJsonDBOperations- Type Parameters:
T- Type annotated withDocumentannotation and member of the baseScanPackage- Parameters:
objectToSave- the object to store in the collectionentityClass- class that determines the collection to use
-
save
public <T> void save(java.lang.Object objectToSave, java.lang.String collectionName)Description copied from interface:JsonDBOperationsSave 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:
savein interfaceJsonDBOperations- Type Parameters:
T- Type annotated withDocumentannotation and member of the baseScanPackage- Parameters:
objectToSave- the object to store in the collectioncollectionName- 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:JsonDBOperationsRemove the given object from the collection by id.- Specified by:
removein interfaceJsonDBOperations- Type Parameters:
T- Type annotated withDocumentannotation and member of the baseScanPackage- Parameters:
objectToRemove- the object to remove from the collectionentityClass- 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:JsonDBOperationsRemove the given object from the collection by id.- Specified by:
removein interfaceJsonDBOperations- Type Parameters:
T- Type annotated withDocumentannotation and member of the baseScanPackage- Parameters:
objectToRemove- the object to remove from the collectioncollectionName- 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:JsonDBOperationsRemove a Collection of objects from a collection in a single batch write to the database.- Specified by:
removein interfaceJsonDBOperations- Type Parameters:
T- Type annotated withDocumentannotation 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:JsonDBOperationsRemove a Collection of objects from a collection in a single batch write to the database.- Specified by:
removein interfaceJsonDBOperations- Type Parameters:
T- Type annotated withDocumentannotation 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:JsonDBOperationsPerforms 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:
upsertin interfaceJsonDBOperations- Type Parameters:
T- Type annotated withDocumentannotation 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:JsonDBOperationsPerforms 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:
upsertin interfaceJsonDBOperations- Type Parameters:
T- Type annotated withDocumentannotation 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:JsonDBOperationsPerforms 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:
upsertin interfaceJsonDBOperations- Type Parameters:
T- Type annotated withDocumentannotation 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:JsonDBOperationsPerforms 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:
upsertin interfaceJsonDBOperations- Type Parameters:
T- Type annotated withDocumentannotation 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:JsonDBOperationsMap 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:
findAndRemovein interfaceJsonDBOperations- Type Parameters:
T- Type annotated withDocumentannotation and member of the baseScanPackage- Parameters:
jxQuery- JxPath query stringentityClass- 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:JsonDBOperationsMap 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:
findAndRemovein interfaceJsonDBOperations- Type Parameters:
T- Type annotated withDocumentannotation and member of the baseScanPackage- Parameters:
jxQuery- JxPath query stringcollectionName- 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:JsonDBOperationsReturns 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:
findAllAndRemovein interfaceJsonDBOperations- Type Parameters:
T- Type annotated withDocumentannotation and member of the baseScanPackage- Parameters:
jxQuery- JxPath query stringentityClass- 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:JsonDBOperationsReturns 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:
findAllAndRemovein interfaceJsonDBOperations- Type Parameters:
T- Type annotated withDocumentannotation and member of the baseScanPackage- Parameters:
jxQuery- JxPath query stringcollectionName- 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:JsonDBOperationsTriggers 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:
findAndModifyin interfaceJsonDBOperations- Type Parameters:
T- Type annotated withDocumentannotation and member of the baseScanPackage- Parameters:
jxQuery- JxPath query stringupdate- The Update operation to performentityClass- 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:JsonDBOperationsTriggers 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:
findAndModifyin interfaceJsonDBOperations- Type Parameters:
T- Type annotated withDocumentannotation and member of the baseScanPackage- Parameters:
jxQuery- JxPath query stringupdate- The Update operation to performcollectionName- 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:
findAllAndModifyin interfaceJsonDBOperations
-
findAllAndModify
public <T> java.util.List<T> findAllAndModify(java.lang.String jxQuery, Update update, java.lang.String collectionName)- Specified by:
findAllAndModifyin interfaceJsonDBOperations
-
changeEncryption
public <T> void changeEncryption(ICipher newCipher)
Description copied from interface:JsonDBOperationsA 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:
changeEncryptionin interfaceJsonDBOperations- Type Parameters:
T- Type annotated withDocumentannotation 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:JsonDBOperationsThis method backs up JSONDB collections to specified backup path- Specified by:
backupin interfaceJsonDBOperations- Parameters:
backupPath- location at which to backup the database contents
-
restore
public void restore(java.lang.String restorePath, boolean merge)Description copied from interface:JsonDBOperationsThis 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:
restorein interfaceJsonDBOperations- Parameters:
restorePath- path were backup jsondb files are presentmerge- whether to merge data from restore location
-
-