Package io.jsondb.io
Class JsonWriter
- java.lang.Object
-
- io.jsondb.io.JsonWriter
-
public class JsonWriter extends java.lang.ObjectA special File Writer to write to the .json DB files that ensures proper character encoding is used and the necessary File Locks are created.
-
-
Constructor Summary
Constructors Constructor Description JsonWriter(JsonDBConfig dbConfig, CollectionMetaData cmd, java.lang.String collectionName, java.io.File collectionFile)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description <T> booleanappendToJsonFile(java.util.Collection<T> collection, java.lang.Object objectToSave)A utility method that appends the provided object to the end of collection file in a atomic way<T> booleanappendToJsonFile(java.util.Collection<T> collection, java.util.Collection<? extends T> batchToSave)A utility method that appends the provided collection of objects to the end of collection file in a atomic way<T> booleanremoveFromJsonFile(java.util.Map<java.lang.Object,T> collection, java.lang.Object id)A utility method that substracts the provided Ids and writes rest of the collection to file in a atomic way<T> booleanremoveFromJsonFile(java.util.Map<java.lang.Object,T> collection, java.util.Set<java.lang.Object> removeIds)A utility method that subtracts the provided Ids and writes rest of the collection to file in a atomic way<T> booleanrenameKeyInJsonFile(java.util.Collection<T> collection, boolean ignoreReadonly, java.lang.String oldKey, java.lang.String newKey)A utility method renames a particular key for the entire contents of .json in a atomic way<T> booleanreWriteJsonFile(java.util.Collection<T> collection, boolean ignoreReadonly)A utility method that completely replaces the contents of .json with the provided collection in a atomic way<T> booleanupdateInJsonFile(java.util.Map<java.lang.Object,T> collection, java.lang.Object id, T objectToSave)A utility method that updates the provided collection of objects into the existing collection file in a atomic way<T> booleanupdateInJsonFile(java.util.Map<java.lang.Object,T> collection, java.util.Map<java.lang.Object,T> modifiedObjects)A utility method that updates the provided collection of objects into the existing collection file in a atomic way
-
-
-
Constructor Detail
-
JsonWriter
public JsonWriter(JsonDBConfig dbConfig, CollectionMetaData cmd, java.lang.String collectionName, java.io.File collectionFile) throws java.io.IOException
- Throws:
java.io.IOException
-
-
Method Detail
-
appendToJsonFile
public <T> boolean appendToJsonFile(java.util.Collection<T> collection, java.lang.Object objectToSave)A utility method that appends the provided object to the end of collection file in a atomic way- Type Parameters:
T- Type annotated withDocumentannotation and member of the baseScanPackage- Parameters:
collection- existing collectionobjectToSave- new Object that is being inserted or updated.- Returns:
- true if success
-
appendToJsonFile
public <T> boolean appendToJsonFile(java.util.Collection<T> collection, java.util.Collection<? extends T> batchToSave)A utility method that appends the provided collection of objects to the end of collection file in a atomic way- Type Parameters:
T- Type annotated withDocumentannotation and member of the baseScanPackage- Parameters:
collection- existing collectionbatchToSave- collection of objects to append.- Returns:
- true if success
-
removeFromJsonFile
public <T> boolean removeFromJsonFile(java.util.Map<java.lang.Object,T> collection, java.lang.Object id)A utility method that substracts the provided Ids and writes rest of the collection to file in a atomic way- Type Parameters:
T- Type annotated withDocumentannotation and member of the baseScanPackage- Parameters:
collection- existing collectionid- id of objects to be removed.- Returns:
- true if success
-
removeFromJsonFile
public <T> boolean removeFromJsonFile(java.util.Map<java.lang.Object,T> collection, java.util.Set<java.lang.Object> removeIds)A utility method that subtracts the provided Ids and writes rest of the collection to file in a atomic way- Type Parameters:
T- Type annotated withDocumentannotation and member of the baseScanPackage- Parameters:
collection- existing collectionremoveIds- ids of objects to be removed.- Returns:
- true if success
-
updateInJsonFile
public <T> boolean updateInJsonFile(java.util.Map<java.lang.Object,T> collection, java.lang.Object id, T objectToSave)A utility method that updates the provided collection of objects into the existing collection file in a atomic way- Type Parameters:
T- Type annotated withDocumentannotation and member of the baseScanPackage- Parameters:
collection- existing collectionid- the id of object to saveobjectToSave- the actual object to save.- Returns:
- true if success
-
updateInJsonFile
public <T> boolean updateInJsonFile(java.util.Map<java.lang.Object,T> collection, java.util.Map<java.lang.Object,T> modifiedObjects)A utility method that updates the provided collection of objects into the existing collection file in a atomic way- Type Parameters:
T- Type annotated withDocumentannotation and member of the baseScanPackage- Parameters:
collection- existing collectionmodifiedObjects- objects to update.- Returns:
- true if success
-
reWriteJsonFile
public <T> boolean reWriteJsonFile(java.util.Collection<T> collection, boolean ignoreReadonly)A utility method that completely replaces the contents of .json with the provided collection in a atomic way- Type Parameters:
T- Type annotated withDocumentannotation and member of the baseScanPackage- Parameters:
collection- existing collectionignoreReadonly- force rewrite even if the collection is marked readonly this is necessary for schemaupdate.- Returns:
- true if success
-
renameKeyInJsonFile
public <T> boolean renameKeyInJsonFile(java.util.Collection<T> collection, boolean ignoreReadonly, java.lang.String oldKey, java.lang.String newKey)A utility method renames a particular key for the entire contents of .json in a atomic way- Type Parameters:
T- Type annotated withDocumentannotation and member of the baseScanPackage- Parameters:
collection- existing collectionignoreReadonly- force rewrite even if the collection is marked readonly this is necessary for schemaupdate.oldKey- String representing the old key/fieldnewKey- String representing the new key/field- Returns:
- true if success
-
-