Package io.jsondb
Interface JsonDBOperations
-
- All Known Implementing Classes:
JsonDBTemplate
public interface JsonDBOperationsInterface that defines the methods available in JsonDBTemplate
-
-
Method Summary
All Methods Instance Methods Abstract 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.
-
-
-
Method Detail
-
reLoadDB
void reLoadDB()
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
-
reloadCollection
void reloadCollection(java.lang.String collectionName)
Reloads a particular collection from dblocation directory- Parameters:
collectionName- name of the collection to reload
-
addCollectionFileChangeListener
void addCollectionFileChangeListener(CollectionFileChangeListener listener)
adds 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- Parameters:
listener- actual listener to add
-
removeCollectionFileChangeListener
void removeCollectionFileChangeListener(CollectionFileChangeListener listener)
removes a previously added CollectionFileChangeListener- Parameters:
listener- actual listener to remove
-
hasCollectionFileChangeListener
boolean hasCollectionFileChangeListener()
a method to check if there are any registered CollectionFileChangeListener- Returns:
- true of there are any registered CollectionFileChangeListeners
-
createCollection
<T> void createCollection(java.lang.Class<T> entityClass)
Create an uncapped collection with a name based on the provided entity class.- Type Parameters:
T- Type annotated withDocumentannotation and member of the baseScanPackage- Parameters:
entityClass- class that determines the collection to create
-
createCollection
<T> void createCollection(java.lang.String collectionName)
Create an uncapped collection with the provided name.- Type Parameters:
T- Type annotated withDocumentannotation and member of the baseScanPackage- Parameters:
collectionName- name of the collection
-
dropCollection
<T> void dropCollection(java.lang.Class<T> entityClass)
Drop the collection with the name indicated by the entity class.- Type Parameters:
T- Type annotated withDocumentannotation and member of the baseScanPackage- Parameters:
entityClass- class that determines the collection to drop/delete.
-
dropCollection
void dropCollection(java.lang.String collectionName)
Drop the collection with the given name.- Parameters:
collectionName- name of the collection to drop/delete.
-
updateCollectionSchema
<T> void updateCollectionSchema(CollectionSchemaUpdate update, java.lang.Class<T> entityClass)
-
updateCollectionSchema
<T> void updateCollectionSchema(CollectionSchemaUpdate update, java.lang.String collectionName)
Update a collection as per the specified CollectionUpdate param. This method is only available by collectionName and not by Class.- 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
java.util.Set<java.lang.String> getCollectionNames()
A set of collection names.- Returns:
- list of collection names
-
getCollectionName
java.lang.String getCollectionName(java.lang.Class<?> entityClass)
The collection name used for the specified class by this template.- Parameters:
entityClass- must not be null.- Returns:
- name of the collection
-
getCollection
<T> java.util.List<T> getCollection(java.lang.Class<T> entityClass)
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.- 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
<T> boolean collectionExists(java.lang.Class<T> entityClass)
Check to see if a collection with a name indicated by the entity class exists.- 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
boolean collectionExists(java.lang.String collectionName)
Check to see if a collection with a given name exists.- Parameters:
collectionName- name of the collection- Returns:
- true if a collection with the given name is found, false otherwise.
-
isCollectionReadonly
<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- 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
<T> boolean isCollectionReadonly(java.lang.String collectionName)
-
find
<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.- 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
<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.- 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
<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. 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).- 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
<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. 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).- 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
<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. 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).- 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
<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. 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).- 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
<T> java.util.List<T> findAll(java.lang.Class<T> entityClass)
Query for a list of objects of type T from the specified collection.- 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
<T> java.util.List<T> findAll(java.lang.String collectionName)
Query for a list of objects of type T from the specified collection.- 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
<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.- 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
<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.- 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
<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.- 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
<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.- 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
<T> T findById(java.lang.Object id, java.lang.Class<T> entityClass)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.- 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
<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.- 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
<T> T findOne(java.lang.String jxQuery, java.lang.Class<T> entityClass)
-
findOne
<T> T findOne(java.lang.String jxQuery, java.lang.String collectionName)
-
insert
<T> void insert(java.lang.Object objectToSave)
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.- Type Parameters:
T- Type annotated withDocumentannotation and member of the baseScanPackage- Parameters:
objectToSave- the object to store in the collection
-
insert
<T> void insert(java.lang.Object objectToSave, java.lang.String collectionName)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.- 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
<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.- 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
<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.- 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
<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. This will throw a exception if the object is not already present. This is a not same as MongoDB behaviour- 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
<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. This will throw a exception if the object is not already present. This is a not same as MongoDB behaviour- 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
<T> T remove(java.lang.Object objectToRemove, java.lang.Class<T> entityClass)Remove the given object from the collection by id.- 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
<T> T remove(java.lang.Object objectToRemove, java.lang.String collectionName)Remove the given object from the collection by id.- 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
<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.- 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
<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.- 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
<T> void upsert(java.lang.Object objectToSave)
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- Type Parameters:
T- Type annotated withDocumentannotation and member of the baseScanPackage- Parameters:
objectToSave- the object to update.
-
upsert
<T> void upsert(java.lang.Object objectToSave, java.lang.String collectionName)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- 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
<T> void upsert(java.util.Collection<? extends T> batchToSave, java.lang.Class<T> entityClass)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- 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
<T> void upsert(java.util.Collection<? extends T> batchToSave, java.lang.String collectionName)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- 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
<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. 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- 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
<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. 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- 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
<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. Both the find and remove operation is done atomically- 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
<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. Both the find and remove operation is done atomically- 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
<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. Both the find and remove operation is done atomically- 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
<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. Both the find and remove operation is done atomically- 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
<T> java.util.List<T> findAllAndModify(java.lang.String jxQuery, Update update, java.lang.Class<T> entityClass)
-
findAllAndModify
<T> java.util.List<T> findAllAndModify(java.lang.String jxQuery, Update update, java.lang.String collectionName)
-
changeEncryption
<T> void changeEncryption(ICipher newCipher)
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- 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
void backup(java.lang.String backupPath)
This method backs up JSONDB collections to specified backup path- Parameters:
backupPath- location at which to backup the database contents
-
restore
void restore(java.lang.String restorePath, boolean merge)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- Parameters:
restorePath- path were backup jsondb files are presentmerge- whether to merge data from restore location
-
-