Package de.caluga.morphium.writer
Class BufferedMorphiumWriterImpl
java.lang.Object
de.caluga.morphium.writer.BufferedMorphiumWriterImpl
- All Implemented Interfaces:
ShutdownListener,MorphiumWriter
User: Stephan Bösebeck
Date: 11.03.13
Time: 11:41
Buffered Writer buffers all write requests (store, update, remove...) to mongo for a certain time. After that time the requests are issued en block to mongo. Attention: this is not using BULK-Requests yet!
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidaddToWriteQueue(Class<?> type, String collectionName, de.caluga.morphium.writer.BufferedMorphiumWriterImpl.BufferedBulkOp r, AsyncOperationCallback c, AsyncOperationType t) voidclose()information about closing of morphium and all connections<T> voidcreateIndex(Class<T> cls, String collection, IndexDescription index, AsyncOperationCallback<T> c) <T> voiddropCollection(Class<T> cls, String collection, AsyncOperationCallback<T> c) <T> voidensureIndex(Class<T> cls, String collection, Map<String, Object> index, AsyncOperationCallback<T> c) voidflush()void<T> voidinc(Query<T> query, String field, Number amount, boolean upsert, boolean multiple, AsyncOperationCallback<T> c) <T> voidinc(Query<T> query, Map<String, Number> fieldsToInc, boolean upsert, boolean multiple, AsyncOperationCallback<T> c) <T> voidinc(T obj, String collection, String field, Number amount, AsyncOperationCallback<T> c) Increases a value in an existing mongo collection entry - no reading necessary.<T> voidinsert(List<T> o, AsyncOperationCallback<T> callback) <T> voidinsert(List<T> lst, String collectionName, AsyncOperationCallback<T> c) <T> voidinsert(T o, String collection, AsyncOperationCallback<T> c) booleanvoid<T> voidpop(T obj, String collection, String field, boolean first, AsyncOperationCallback<T> c) <T> voidpushPull(boolean push, Query<T> q, String field, Object value, boolean upsert, boolean multiple, AsyncOperationCallback<T> c) <T> voidpushPullAll(boolean push, Query<T> q, String field, List<?> value, boolean upsert, boolean multiple, AsyncOperationCallback<T> c) <T> voidremove(Query<T> q, boolean multiple, AsyncOperationCallback<T> c) <T> voidremove(Query<T> q, AsyncOperationCallback<T> c) deletes all objects matching the given query<T> voidremove(List<T> lst, AsyncOperationCallback<T> c) <T> voidremove(T o, String collection, AsyncOperationCallback<T> c) <T> voidset(Query<T> query, Map<String, Object> values, boolean upsert, boolean multiple, AsyncOperationCallback<T> c) will change an entry in mongodb-collection corresponding to given class object if query is too complex, upsert might not work!<T> voidset(T toSet, String collection, Map<String, Object> values, boolean upsert, AsyncOperationCallback<T> callback) changes an object in DB AND in Memory...voidsetMaximumQueingTries(int n) voidvoidsetOrderedExecution(boolean orderedExecution) voidsetPauseBetweenTries(int p) <T> voidstore(List<T> lst, AsyncOperationCallback<T> c) stores the given list of objects, should be entities or embedded.<T> voidstore(List<T> lst, String collectionName, AsyncOperationCallback<T> c) <T> voidstore(T o, String collection, AsyncOperationCallback<T> c) Stores the object, should be an entity<T> voidunset(Query<T> query, AsyncOperationCallback<T> c, boolean multiple, Enum... fields) <T> voidunset(Query<T> query, AsyncOperationCallback<T> c, boolean multiple, String... fields) <T> voidunset(Query<T> query, String field, boolean multiple, AsyncOperationCallback<T> c) <T> voidunset(T obj, String collection, String field, AsyncOperationCallback<T> c) Un-setting a value in an existing mongo collection entry - no reading necessary.<T> voidupdateUsingFields(T ent, String collection, AsyncOperationCallback<T> c, String... fields) update an object using fields specifiedint
-
Constructor Details
-
BufferedMorphiumWriterImpl
public BufferedMorphiumWriterImpl()
-
-
Method Details
-
close
public void close()Description copied from interface:MorphiumWriterinformation about closing of morphium and all connections- Specified by:
closein interfaceMorphiumWriter
-
isOrderedExecution
public boolean isOrderedExecution() -
setOrderedExecution
public void setOrderedExecution(boolean orderedExecution) -
addToWriteQueue
public void addToWriteQueue(Class<?> type, String collectionName, de.caluga.morphium.writer.BufferedMorphiumWriterImpl.BufferedBulkOp r, AsyncOperationCallback c, AsyncOperationType t) -
insert
- Specified by:
insertin interfaceMorphiumWriter
-
insert
- Specified by:
insertin interfaceMorphiumWriter
-
insert
- Specified by:
insertin interfaceMorphiumWriter
-
store
Description copied from interface:MorphiumWriterStores the object, should be an entity- Specified by:
storein interfaceMorphiumWriter- Parameters:
o- - entity
-
store
- Specified by:
storein interfaceMorphiumWriter
-
updateUsingFields
public <T> void updateUsingFields(T ent, String collection, AsyncOperationCallback<T> c, String... fields) Description copied from interface:MorphiumWriterupdate an object using fields specified- Specified by:
updateUsingFieldsin interfaceMorphiumWriter- Parameters:
ent- entityfields- - fields
-
set
public <T> void set(Query<T> query, Map<String, Object> values, boolean upsert, boolean multiple, AsyncOperationCallback<T> c) Description copied from interface:MorphiumWriterwill change an entry in mongodb-collection corresponding to given class object if query is too complex, upsert might not work! Upsert should consist of single and-queries, which will be used to generate the object to create, unless it already exists. look at Mongodb-query documentation as well- Specified by:
setin interfaceMorphiumWriter- Parameters:
query- - query to specify which objects should be setvalues- - map fieldName->Value, which values are to be set!upsert- - insert, if it does not exist (query needs to be simple!)multiple- - update several documents, if false, only first hit will be updated
-
inc
public <T> void inc(Query<T> query, Map<String, Number> fieldsToInc, boolean upsert, boolean multiple, AsyncOperationCallback<T> c) - Specified by:
incin interfaceMorphiumWriter
-
inc
public <T> void inc(Query<T> query, String field, Number amount, boolean upsert, boolean multiple, AsyncOperationCallback<T> c) - Specified by:
incin interfaceMorphiumWriter
-
inc
public <T> void inc(T obj, String collection, String field, Number amount, AsyncOperationCallback<T> c) Description copied from interface:MorphiumWriterIncreases a value in an existing mongo collection entry - no reading necessary. Object is altered in place db.collection.update({"_id":toInc.id},{$inc:{field:amount}} attention: this alteres the given object toSet in a similar way- Specified by:
incin interfaceMorphiumWriter- Parameters:
obj- : object to set the value in (or better - the corresponding entry in mongo)field- : the field to changeamount- : the value to set
-
pop
public <T> void pop(T obj, String collection, String field, boolean first, AsyncOperationCallback<T> c) - Specified by:
popin interfaceMorphiumWriter
-
setMorphium
- Specified by:
setMorphiumin interfaceMorphiumWriter
-
remove
- Specified by:
removein interfaceMorphiumWriter
-
remove
- Specified by:
removein interfaceMorphiumWriter
-
remove
- Specified by:
removein interfaceMorphiumWriter
-
remove
Description copied from interface:MorphiumWriterdeletes all objects matching the given query- Specified by:
removein interfaceMorphiumWriter- Parameters:
q- the query
-
pushPull
public <T> void pushPull(boolean push, Query<T> q, String field, Object value, boolean upsert, boolean multiple, AsyncOperationCallback<T> c) - Specified by:
pushPullin interfaceMorphiumWriter
-
pushPullAll
public <T> void pushPullAll(boolean push, Query<T> q, String field, List<?> value, boolean upsert, boolean multiple, AsyncOperationCallback<T> c) - Specified by:
pushPullAllin interfaceMorphiumWriter
-
unset
Description copied from interface:MorphiumWriterUn-setting a value in an existing mongo collection entry - no reading necessary. Object is altered in place db.collection.update({"_id":toSet.id},{$unset:{field:1}} attention: this alteres the given object toSet in a similar way- Specified by:
unsetin interfaceMorphiumWriter- Parameters:
obj- : object to set the value in (or better - the corresponding entry in mongo)field- : field to remove from document
-
unset
- Specified by:
unsetin interfaceMorphiumWriter
-
unset
public <T> void unset(Query<T> query, AsyncOperationCallback<T> c, boolean multiple, String... fields) - Specified by:
unsetin interfaceMorphiumWriter
-
unset
public <T> void unset(Query<T> query, AsyncOperationCallback<T> c, boolean multiple, Enum... fields) - Specified by:
unsetin interfaceMorphiumWriter
-
dropCollection
- Specified by:
dropCollectionin interfaceMorphiumWriter
-
ensureIndex
-
createIndex
public <T> void createIndex(Class<T> cls, String collection, IndexDescription index, AsyncOperationCallback<T> c) - Specified by:
createIndexin interfaceMorphiumWriter
-
writeBufferCount
public int writeBufferCount()- Specified by:
writeBufferCountin interfaceMorphiumWriter
-
store
Description copied from interface:MorphiumWriterstores the given list of objects, should be entities or embedded.- Specified by:
storein interfaceMorphiumWriter- Parameters:
lst- - to store
-
flush
public void flush()- Specified by:
flushin interfaceMorphiumWriter
-
flush
- Specified by:
flushin interfaceMorphiumWriter
-
onShutdown
- Specified by:
onShutdownin interfaceShutdownListener
-
setMaximumQueingTries
public void setMaximumQueingTries(int n) - Specified by:
setMaximumQueingTriesin interfaceMorphiumWriter
-
setPauseBetweenTries
public void setPauseBetweenTries(int p) - Specified by:
setPauseBetweenTriesin interfaceMorphiumWriter
-
set
public <T> void set(T toSet, String collection, Map<String, Object> values, boolean upsert, AsyncOperationCallback<T> callback) Description copied from interface:MorphiumWriterchanges an object in DB AND in Memory... the Object toSet WILL be modified!- Specified by:
setin interfaceMorphiumWriter- Parameters:
toSet- entity to set values in both in mongo and in memoryvalues- : contains name/values to set to the given object!
-