Package de.caluga.morphium.writer
Class MorphiumWriterImpl
- java.lang.Object
-
- de.caluga.morphium.writer.MorphiumWriterImpl
-
- All Implemented Interfaces:
ShutdownListener,MorphiumWriter
- Direct Known Subclasses:
AsyncWriterImpl
public class MorphiumWriterImpl extends Object implements MorphiumWriter, ShutdownListener
User: Stephan Bösebeck Date: 30.08.12 Time: 14:38default writer implementation - uses a ThreadPoolExecutor for execution of asynchornous calls maximum Threads are limited to 0.9* MaxConnections configured in MorphiumConfig
- See Also:
MorphiumWriter
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description classMorphiumWriterImpl.WT<T>
-
Constructor Summary
Constructors Constructor Description MorphiumWriterImpl()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidclose()information about closing of morphium and all connections<T> voidcreateIndex(Class<T> cls, String collection, IndexDescription idesc, AsyncOperationCallback<T> callback)<T> voiddropCollection(Class<T> cls, String collection, AsyncOperationCallback<T> callback)voidflush()voidflush(Class type)<T> Map<String,Object>inc(Query<T> query, String field, Number amount, boolean upsert, boolean multiple, AsyncOperationCallback<T> callback)<T> Map<String,Object>inc(Query<T> query, Map<String,Number> fieldsToInc, boolean upsert, boolean multiple, AsyncOperationCallback<T> callback)<T> voidinc(T toInc, String collection, String field, Number amount, AsyncOperationCallback<T> callback)Increases a value in an existing mongo collection entry - no reading necessary.<T> voidinsert(List<T> lst, AsyncOperationCallback<T> callback)<T> voidinsert(List<T> lst, String cn, AsyncOperationCallback<T> callback)<T> voidinsert(T obj, String collection, AsyncOperationCallback<T> callback)ObjectmarshallIfNecessary(Object value)voidonShutdown(Morphium m)<T> voidpop(T obj, String collection, String field, boolean first, AsyncOperationCallback<T> callback)<T> Map<String,Object>pushPull(MorphiumStorageListener.UpdateTypes type, Query<T> query, String field, Object value, boolean upsert, boolean multiple, AsyncOperationCallback<T> callback)<T> Map<String,Object>pushPullAll(MorphiumStorageListener.UpdateTypes type, Query<T> query, String f, List<?> v, boolean upsert, boolean multiple, AsyncOperationCallback<T> callback)<T> Map<String,Object>remove(Query<T> q, boolean multiple, AsyncOperationCallback<T> callback)<T> Map<String,Object>remove(Query<T> q, AsyncOperationCallback<T> callback)deletes all objects matching the given query<T> voidremove(List<T> lst, AsyncOperationCallback<T> callback)<T> voidremove(T o, String collection, AsyncOperationCallback<T> callback)<T> Map<String,Object>set(Query<T> query, Map<String,Object> values, boolean upsert, boolean multiple, AsyncOperationCallback<T> callback)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 col, Map<String,Object> values, boolean upsert, AsyncOperationCallback<T> callback)changes an object in DB AND in Memory...voidsetMaximumQueingTries(int n)voidsetMorphium(Morphium m)voidsetPauseBetweenTries(int p)<T> voidstore(List<T> lst, AsyncOperationCallback<T> callback)stores the given list of objects, should be entities or embedded.<T> voidstore(List<T> lst, String cln, AsyncOperationCallback<T> callback)<T> voidstore(T obj, String collection, AsyncOperationCallback<T> callback)Stores the object, should be an entity<T> Map<String,Object>submitAndBlockIfNecessary(AsyncOperationCallback<T> callback, WriterTask<T> r)<T> Map<String,Object>unset(Query<T> query, AsyncOperationCallback<T> callback, boolean multiple, Enum... fields)<T> Map<String,Object>unset(Query<T> query, AsyncOperationCallback<T> callback, boolean multiple, String... fields)<T> Map<String,Object>unset(Query<T> query, String field, boolean multiple, AsyncOperationCallback<T> callback)<T> voidunset(T toSet, String collection, String field, AsyncOperationCallback<T> callback)Un-setting a value in an existing mongo collection entry - no reading necessary.<T> voidupdateUsingFields(T ent, String collection, AsyncOperationCallback<T> callback, String... fields)update an object using fields specifiedintwriteBufferCount()
-
-
-
Method Detail
-
setMaximumQueingTries
public void setMaximumQueingTries(int n)
- Specified by:
setMaximumQueingTriesin interfaceMorphiumWriter
-
setPauseBetweenTries
public void setPauseBetweenTries(int p)
- Specified by:
setPauseBetweenTriesin interfaceMorphiumWriter
-
setMorphium
public void setMorphium(Morphium m)
- Specified by:
setMorphiumin interfaceMorphiumWriter
-
close
public void close()
Description copied from interface:MorphiumWriterinformation about closing of morphium and all connections- Specified by:
closein interfaceMorphiumWriter
-
insert
public <T> void insert(List<T> lst, AsyncOperationCallback<T> callback)
- Specified by:
insertin interfaceMorphiumWriter
-
insert
public <T> void insert(List<T> lst, String cn, AsyncOperationCallback<T> callback)
- Specified by:
insertin interfaceMorphiumWriter
-
insert
public <T> void insert(T obj, String collection, AsyncOperationCallback<T> callback)- Specified by:
insertin interfaceMorphiumWriter
-
store
public <T> void store(T obj, String collection, AsyncOperationCallback<T> callback)Description copied from interface:MorphiumWriterStores the object, should be an entity- Specified by:
storein interfaceMorphiumWriter- Parameters:
obj- - object to store
-
store
public <T> void store(List<T> lst, String cln, AsyncOperationCallback<T> callback)
- Specified by:
storein interfaceMorphiumWriter
-
flush
public void flush()
- Specified by:
flushin interfaceMorphiumWriter
-
flush
public void flush(Class type)
- Specified by:
flushin interfaceMorphiumWriter
-
store
public <T> void store(List<T> lst, AsyncOperationCallback<T> callback)
Description copied from interface:MorphiumWriterstores the given list of objects, should be entities or embedded.- Specified by:
storein interfaceMorphiumWriter- Parameters:
lst- - to store
-
set
public <T> void set(T toSet, String col, 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!
-
submitAndBlockIfNecessary
public <T> Map<String,Object> submitAndBlockIfNecessary(AsyncOperationCallback<T> callback, WriterTask<T> r)
-
updateUsingFields
public <T> void updateUsingFields(T ent, String collection, AsyncOperationCallback<T> callback, String... fields)Description copied from interface:MorphiumWriterupdate an object using fields specified- Specified by:
updateUsingFieldsin interfaceMorphiumWriter- Parameters:
ent- entityfields- - fields
-
remove
public <T> void remove(List<T> lst, AsyncOperationCallback<T> callback)
- Specified by:
removein interfaceMorphiumWriter
-
remove
public <T> Map<String,Object> remove(Query<T> q, AsyncOperationCallback<T> callback)
deletes all objects matching the given query- Specified by:
removein interfaceMorphiumWriter- Parameters:
q- - query
-
remove
public <T> Map<String,Object> remove(Query<T> q, boolean multiple, AsyncOperationCallback<T> callback)
- Specified by:
removein interfaceMorphiumWriter
-
remove
public <T> void remove(T o, String collection, AsyncOperationCallback<T> callback)- Specified by:
removein interfaceMorphiumWriter
-
inc
public <T> void inc(T toInc, String collection, String field, Number amount, AsyncOperationCallback<T> callback)Increases 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:
toInc- : object to set the value in (or better - the corresponding entry in mongo)field- : the field to changeamount- : the value to set
-
inc
public <T> Map<String,Object> inc(Query<T> query, Map<String,Number> fieldsToInc, boolean upsert, boolean multiple, AsyncOperationCallback<T> callback)
- Specified by:
incin interfaceMorphiumWriter
-
inc
public <T> Map<String,Object> inc(Query<T> query, String field, Number amount, boolean upsert, boolean multiple, AsyncOperationCallback<T> callback)
- Specified by:
incin interfaceMorphiumWriter
-
set
public <T> Map<String,Object> set(Query<T> query, Map<String,Object> values, boolean upsert, boolean multiple, AsyncOperationCallback<T> callback)
will 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
-
unset
public <T> Map<String,Object> unset(Query<T> query, AsyncOperationCallback<T> callback, boolean multiple, Enum... fields)
- Specified by:
unsetin interfaceMorphiumWriter
-
unset
public <T> Map<String,Object> unset(Query<T> query, AsyncOperationCallback<T> callback, boolean multiple, String... fields)
- Specified by:
unsetin interfaceMorphiumWriter
-
unset
public <T> void unset(T toSet, String collection, String field, AsyncOperationCallback<T> callback)Un-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:
toSet- : object to set the value in (or better - the corresponding entry in mongo)field- : field to remove from document
-
pop
public <T> void pop(T obj, String collection, String field, boolean first, AsyncOperationCallback<T> callback)- Specified by:
popin interfaceMorphiumWriter
-
unset
public <T> Map<String,Object> unset(Query<T> query, String field, boolean multiple, AsyncOperationCallback<T> callback)
- Specified by:
unsetin interfaceMorphiumWriter
-
pushPull
public <T> Map<String,Object> pushPull(MorphiumStorageListener.UpdateTypes type, Query<T> query, String field, Object value, boolean upsert, boolean multiple, AsyncOperationCallback<T> callback)
- Specified by:
pushPullin interfaceMorphiumWriter
-
pushPullAll
public <T> Map<String,Object> pushPullAll(MorphiumStorageListener.UpdateTypes type, Query<T> query, String f, List<?> v, boolean upsert, boolean multiple, AsyncOperationCallback<T> callback)
- Specified by:
pushPullAllin interfaceMorphiumWriter
-
dropCollection
public <T> void dropCollection(Class<T> cls, String collection, AsyncOperationCallback<T> callback)
- Specified by:
dropCollectionin interfaceMorphiumWriter
-
createIndex
public <T> void createIndex(Class<T> cls, String collection, IndexDescription idesc, AsyncOperationCallback<T> callback)
- Specified by:
createIndexin interfaceMorphiumWriter
-
writeBufferCount
public int writeBufferCount()
- Specified by:
writeBufferCountin interfaceMorphiumWriter
-
onShutdown
public void onShutdown(Morphium m)
- Specified by:
onShutdownin interfaceShutdownListener
-
-