Package de.caluga.morphium.driver.inmem
Class InMemoryDriver
- java.lang.Object
-
- de.caluga.morphium.driver.inmem.InMemoryDriver
-
- All Implemented Interfaces:
MorphiumDriver,MongoConnection,Closeable,AutoCloseable
public class InMemoryDriver extends Object implements MorphiumDriver, MongoConnection
User: Stephan Bösebeck Date: 28.11.15 Time: 23:25InMemory implementation of the MorphiumDriver interface. can be used for testing or caching. Does not cover all functionality yet.
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from interface de.caluga.morphium.driver.MorphiumDriver
MorphiumDriver.DriverStatsKey
-
-
Field Summary
Fields Modifier and Type Field Description static StringdriverName
-
Constructor Summary
Constructors Constructor Description InMemoryDriver()
-
Method Summary
-
-
-
Field Detail
-
driverName
public static final String driverName
- See Also:
- Constant Field Values
-
-
Method Detail
-
createAggregator
public <T,R> Aggregator<T,R> createAggregator(Morphium morphium, Class<? extends T> type, Class<? extends R> resultType)
- Specified by:
createAggregatorin interfaceMorphiumDriver
-
restore
public void restore(InputStream in) throws IOException, org.json.simple.parser.ParseException
- Throws:
IOExceptionorg.json.simple.parser.ParseException
-
restoreFromFile
public void restoreFromFile(File f) throws IOException, org.json.simple.parser.ParseException
- Throws:
IOExceptionorg.json.simple.parser.ParseException
-
dumpToFile
public void dumpToFile(Morphium m, String db, File f) throws IOException
- Throws:
IOException
-
dump
public void dump(Morphium m, String db, OutputStream out) throws IOException
- Throws:
IOException
-
listDatabases
public List<String> listDatabases()
- Specified by:
listDatabasesin interfaceMorphiumDriver
-
listCollections
public List<String> listCollections(String db, String pattern)
- Specified by:
listCollectionsin interfaceMorphiumDriver
-
getReplicaSetName
public String getReplicaSetName()
- Specified by:
getReplicaSetNamein interfaceMorphiumDriver
-
setReplicaSetName
public void setReplicaSetName(String replicaSetName)
- Specified by:
setReplicaSetNamein interfaceMorphiumDriver
-
resetData
public void resetData()
-
watch
public void watch(WatchCommand settings) throws MorphiumDriverException
- Specified by:
watchin interfaceMongoConnection- Specified by:
watchin interfaceMorphiumDriver- Throws:
MorphiumDriverException
-
readAnswerFor
public List<Map<String,Object>> readAnswerFor(int queryId) throws MorphiumDriverException
- Specified by:
readAnswerForin interfaceMongoConnection- Throws:
MorphiumDriverException
-
getAnswerFor
public MorphiumCursor getAnswerFor(int queryId, int batchsize) throws MorphiumDriverException
- Specified by:
getAnswerForin interfaceMongoConnection- Throws:
MorphiumDriverException
-
readAnswerFor
public List<Map<String,Object>> readAnswerFor(MorphiumCursor crs) throws MorphiumDriverException
- Specified by:
readAnswerForin interfaceMongoConnection- Throws:
MorphiumDriverException
-
sendCommand
public int sendCommand(MongoCommand cmd) throws MorphiumDriverException
- Specified by:
sendCommandin interfaceMongoConnection- Throws:
MorphiumDriverException
-
runCommand
public int runCommand(CreateUserAdminCommand cmd)
-
runCommand
public int runCommand(CreateRoleAdminCommand cmd)
-
runCommand
public int runCommand(SaslAuthCommand cmd)
-
runCommand
public int runCommand(GenericCommand cmd)
-
getReadConnection
public MongoConnection getReadConnection(ReadPreference rp)
- Specified by:
getReadConnectionin interfaceMorphiumDriver
-
getPrimaryConnection
public MongoConnection getPrimaryConnection(WriteConcern wc)
- Specified by:
getPrimaryConnectionin interfaceMorphiumDriver
-
releaseConnection
public void releaseConnection(MongoConnection con)
- Specified by:
releaseConnectionin interfaceMorphiumDriver
-
getName
public String getName()
- Specified by:
getNamein interfaceMorphiumDriver
-
getMaxBsonObjectSize
public int getMaxBsonObjectSize()
- Specified by:
getMaxBsonObjectSizein interfaceMorphiumDriver
-
setMaxBsonObjectSize
public void setMaxBsonObjectSize(int maxBsonObjectSize)
- Specified by:
setMaxBsonObjectSizein interfaceMorphiumDriver
-
getMaxMessageSize
public int getMaxMessageSize()
- Specified by:
getMaxMessageSizein interfaceMorphiumDriver
-
setMaxMessageSize
public void setMaxMessageSize(int maxMessageSize)
- Specified by:
setMaxMessageSizein interfaceMorphiumDriver
-
getMaxWriteBatchSize
public int getMaxWriteBatchSize()
- Specified by:
getMaxWriteBatchSizein interfaceMorphiumDriver
-
setMaxWriteBatchSize
public void setMaxWriteBatchSize(int maxWriteBatchSize)
- Specified by:
setMaxWriteBatchSizein interfaceMorphiumDriver
-
isReplicaSet
public boolean isReplicaSet()
- Specified by:
isReplicaSetin interfaceMorphiumDriver
-
setReplicaSet
public void setReplicaSet(boolean replicaSet)
- Specified by:
setReplicaSetin interfaceMorphiumDriver
-
getDefaultJ
public boolean getDefaultJ()
- Specified by:
getDefaultJin interfaceMorphiumDriver
-
getDefaultWriteTimeout
public int getDefaultWriteTimeout()
- Specified by:
getDefaultWriteTimeoutin interfaceMorphiumDriver
-
setDefaultWriteTimeout
public void setDefaultWriteTimeout(int wt)
- Specified by:
setDefaultWriteTimeoutin interfaceMorphiumDriver
-
setHostSeed
public void setHostSeed(String... host)
- Specified by:
setHostSeedin interfaceMorphiumDriver
-
setConnectionUrl
public void setConnectionUrl(String connectionUrl)
- Specified by:
setConnectionUrlin interfaceMorphiumDriver
-
connect
public void connect()
- Specified by:
connectin interfaceMorphiumDriver
-
getExpireCheck
public int getExpireCheck()
-
setExpireCheck
public InMemoryDriver setExpireCheck(int expireCheck)
-
connect
public void connect(String replicasetName)
- Specified by:
connectin interfaceMorphiumDriver
-
isConnected
public boolean isConnected()
- Specified by:
isConnectedin interfaceMongoConnection- Specified by:
isConnectedin interfaceMorphiumDriver
-
getConnectedTo
public String getConnectedTo()
- Specified by:
getConnectedToin interfaceMongoConnection
-
getConnectedToHost
public String getConnectedToHost()
- Specified by:
getConnectedToHostin interfaceMongoConnection
-
getConnectedToPort
public int getConnectedToPort()
- Specified by:
getConnectedToPortin interfaceMongoConnection
-
getRetriesOnNetworkError
public int getRetriesOnNetworkError()
- Specified by:
getRetriesOnNetworkErrorin interfaceMorphiumDriver
-
setRetriesOnNetworkError
public MorphiumDriver setRetriesOnNetworkError(int r)
- Specified by:
setRetriesOnNetworkErrorin interfaceMorphiumDriver
-
getSleepBetweenErrorRetries
public int getSleepBetweenErrorRetries()
- Specified by:
getSleepBetweenErrorRetriesin interfaceMorphiumDriver
-
setSleepBetweenErrorRetries
public MorphiumDriver setSleepBetweenErrorRetries(int s)
- Specified by:
setSleepBetweenErrorRetriesin interfaceMorphiumDriver
-
getMaxConnections
public int getMaxConnections()
- Specified by:
getMaxConnectionsin interfaceMorphiumDriver
-
setMaxConnections
public MorphiumDriver setMaxConnections(int maxConnections)
- Specified by:
setMaxConnectionsin interfaceMorphiumDriver
-
getMinConnections
public int getMinConnections()
- Specified by:
getMinConnectionsin interfaceMorphiumDriver
-
setMinConnections
public MorphiumDriver setMinConnections(int minConnections)
- Specified by:
setMinConnectionsin interfaceMorphiumDriver
-
isRetryReads
public boolean isRetryReads()
- Specified by:
isRetryReadsin interfaceMorphiumDriver
-
setRetryReads
public MorphiumDriver setRetryReads(boolean retryReads)
- Specified by:
setRetryReadsin interfaceMorphiumDriver
-
isRetryWrites
public boolean isRetryWrites()
- Specified by:
isRetryWritesin interfaceMorphiumDriver
-
setRetryWrites
public MorphiumDriver setRetryWrites(boolean retryWrites)
- Specified by:
setRetryWritesin interfaceMorphiumDriver
-
getReadTimeout
public int getReadTimeout()
- Specified by:
getReadTimeoutin interfaceMorphiumDriver
-
setReadTimeout
public void setReadTimeout(int readTimeout)
- Specified by:
setReadTimeoutin interfaceMorphiumDriver
-
getMinConnectionsPerHost
public int getMinConnectionsPerHost()
- Specified by:
getMinConnectionsPerHostin interfaceMorphiumDriver
-
setMinConnectionsPerHost
public void setMinConnectionsPerHost(int minConnectionsPerHost)
- Specified by:
setMinConnectionsPerHostin interfaceMorphiumDriver
-
getMaxConnectionsPerHost
public int getMaxConnectionsPerHost()
- Specified by:
getMaxConnectionsPerHostin interfaceMorphiumDriver
-
setMaxConnectionsPerHost
public void setMaxConnectionsPerHost(int maxConnectionsPerHost)
- Specified by:
setMaxConnectionsPerHostin interfaceMorphiumDriver
-
setCredentials
public void setCredentials(String db, String login, String pwd)
- Specified by:
setCredentialsin interfaceMongoConnection- Specified by:
setCredentialsin interfaceMorphiumDriver
-
startTransaction
public MorphiumTransactionContext startTransaction(boolean autoCommit)
- Specified by:
startTransactionin interfaceMorphiumDriver
-
isTransactionInProgress
public boolean isTransactionInProgress()
- Specified by:
isTransactionInProgressin interfaceMorphiumDriver
-
getTransactionContext
public MorphiumTransactionContext getTransactionContext()
- Specified by:
getTransactionContextin interfaceMorphiumDriver
-
connect
public HelloResult connect(MorphiumDriver drv, String host, int port) throws IOException, MorphiumDriverException
- Specified by:
connectin interfaceMongoConnection- Throws:
IOExceptionMorphiumDriverException
-
getDriver
public MorphiumDriver getDriver()
- Specified by:
getDriverin interfaceMongoConnection
-
getSourcePort
public int getSourcePort()
- Specified by:
getSourcePortin interfaceMongoConnection
-
close
public void close()
- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceCloseable- Specified by:
closein interfaceMongoConnection
-
release
public void release()
- Specified by:
releasein interfaceMongoConnection
-
isReplicaset
public boolean isReplicaset()
- Specified by:
isReplicasetin interfaceMorphiumDriver
-
getReplsetStatus
public Map<String,Object> getReplsetStatus()
- Specified by:
getReplsetStatusin interfaceMorphiumDriver
-
getDBStats
public Map<String,Object> getDBStats(String db)
- Specified by:
getDBStatsin interfaceMorphiumDriver
-
getCollStats
public Map<String,Object> getCollStats(String db, String coll) throws MorphiumDriverException
- Specified by:
getCollStatsin interfaceMorphiumDriver- Throws:
MorphiumDriverException
-
initIteration
public MorphiumCursor initIteration(String db, String collection, Map<String,Object> query, Map<String,Object> sort, Map<String,Object> projection, int skip, int limit, int batchSize, ReadPreference readPreference, Collation coll, Map<String,Object> findMetaData) throws MorphiumDriverException
- Throws:
MorphiumDriverException
-
watch
public void watch(String db, String collection, int timeout, boolean fullDocumentOnUpdate, List<Map<String,Object>> pipeline, DriverTailableIterationCallback cb) throws MorphiumDriverException
- Throws:
MorphiumDriverException
-
nextIteration
public MorphiumCursor nextIteration(MorphiumCursor crs) throws MorphiumDriverException
- Throws:
MorphiumDriverException
-
find
public List<Map<String,Object>> find(String db, String collection, Map<String,Object> query, Map<String,Object> sort, Map<String,Object> projection, int skip, int limit) throws MorphiumDriverException
- Throws:
MorphiumDriverException
-
count
public long count(String db, String collection, Map<String,Object> query, Collation collation, ReadPreference rp) throws MorphiumDriverException
- Throws:
MorphiumDriverException
-
estimatedDocumentCount
public long estimatedDocumentCount(String db, String collection, ReadPreference rp) throws MorphiumDriverException
- Throws:
MorphiumDriverException
-
findByFieldValue
public List<Map<String,Object>> findByFieldValue(String db, String coll, String field, Object value) throws MorphiumDriverException
- Throws:
MorphiumDriverException
-
getIndexDataForCollection
public Map<Integer,List<Map<String,Object>>> getIndexDataForCollection(String db, String collection, String fields)
-
insert
public List<Map<String,Object>> insert(String db, String collection, List<Map<String,Object>> objs, Map<String,Object> wc) throws MorphiumDriverException
- Throws:
MorphiumDriverException
-
store
public Map<String,Integer> store(String db, String collection, List<Map<String,Object>> objs, Map<String,Object> wc) throws MorphiumDriverException
- Throws:
MorphiumDriverException
-
closeIteration
public void closeIteration(MorphiumCursor crs)
- Specified by:
closeIterationin interfaceMongoConnection
-
killCursors
public Map<String,Object> killCursors(String db, String coll, long... ids) throws MorphiumDriverException
- Specified by:
killCursorsin interfaceMongoConnection- Throws:
MorphiumDriverException
-
replyAvailableFor
public boolean replyAvailableFor(int msgId)
- Specified by:
replyAvailableForin interfaceMongoConnection
-
getReplyFor
public OpMsg getReplyFor(int msgid, long timeout) throws MorphiumDriverException
- Specified by:
getReplyForin interfaceMongoConnection- Throws:
MorphiumDriverException
-
readSingleAnswer
public Map<String,Object> readSingleAnswer(int id) throws MorphiumDriverException
- Specified by:
readSingleAnswerin interfaceMongoConnection- Throws:
MorphiumDriverException
-
update
public Map<String,Object> update(String db, String collection, Map<String,Object> query, Map<String,Object> sort, Map<String,Object> op, boolean multiple, boolean upsert, Map<String,Object> collation, Map<String,Object> wc) throws MorphiumDriverException
- Throws:
MorphiumDriverException
-
delete
public Map<String,Object> delete(String db, String collection, Map<String,Object> query, Map<String,Object> sort, boolean multiple, Map<String,Object> collation, WriteConcern wc) throws MorphiumDriverException
- Throws:
MorphiumDriverException
-
drop
public void drop(String db, String collection, WriteConcern wc)
-
drop
public void drop(String db, WriteConcern wc)
-
exists
public boolean exists(String db)
- Specified by:
existsin interfaceMorphiumDriver
-
getMaxConnectionLifetime
public int getMaxConnectionLifetime()
- Specified by:
getMaxConnectionLifetimein interfaceMorphiumDriver
-
setMaxConnectionLifetime
public void setMaxConnectionLifetime(int timeout)
- Specified by:
setMaxConnectionLifetimein interfaceMorphiumDriver
-
getMaxConnectionIdleTime
public int getMaxConnectionIdleTime()
- Specified by:
getMaxConnectionIdleTimein interfaceMorphiumDriver
-
setMaxConnectionIdleTime
public void setMaxConnectionIdleTime(int time)
- Specified by:
setMaxConnectionIdleTimein interfaceMorphiumDriver
-
getConnectionTimeout
public int getConnectionTimeout()
- Specified by:
getConnectionTimeoutin interfaceMorphiumDriver
-
setConnectionTimeout
public void setConnectionTimeout(int timeout)
- Specified by:
setConnectionTimeoutin interfaceMorphiumDriver
-
getDefaultW
public int getDefaultW()
- Specified by:
getDefaultWin interfaceMorphiumDriver
-
setDefaultW
public void setDefaultW(int w)
- Specified by:
setDefaultWin interfaceMorphiumDriver
-
getHeartbeatFrequency
public int getHeartbeatFrequency()
- Specified by:
getHeartbeatFrequencyin interfaceMorphiumDriver
-
setHeartbeatFrequency
public void setHeartbeatFrequency(int heartbeatFrequency)
- Specified by:
setHeartbeatFrequencyin interfaceMorphiumDriver
-
getDefaultReadPreference
public ReadPreference getDefaultReadPreference()
- Specified by:
getDefaultReadPreferencein interfaceMorphiumDriver
-
setDefaultReadPreference
public void setDefaultReadPreference(ReadPreference rp)
- Specified by:
setDefaultReadPreferencein interfaceMorphiumDriver
-
getDefaultBatchSize
public int getDefaultBatchSize()
- Specified by:
getDefaultBatchSizein interfaceMorphiumDriver
-
setDefaultBatchSize
public void setDefaultBatchSize(int defaultBatchSize)
- Specified by:
setDefaultBatchSizein interfaceMorphiumDriver
-
isUseSSL
public boolean isUseSSL()
- Specified by:
isUseSSLin interfaceMorphiumDriver
-
setUseSSL
public void setUseSSL(boolean useSSL)
- Specified by:
setUseSSLin interfaceMorphiumDriver
-
isDefaultJ
public boolean isDefaultJ()
- Specified by:
isDefaultJin interfaceMorphiumDriver
-
setDefaultJ
public void setDefaultJ(boolean j)
- Specified by:
setDefaultJin interfaceMorphiumDriver
-
distinct
public List<Object> distinct(String db, String collection, String field, Map<String,Object> filter, Map<String,Object> collation) throws MorphiumDriverException
- Throws:
MorphiumDriverException
-
exists
public boolean exists(String db, String collection)
- Specified by:
existsin interfaceMorphiumDriver
-
findAndOneAndDelete
public Map<String,Object> findAndOneAndDelete(String db, String col, Map<String,Object> query, Map<String,Object> sort, Map<String,Object> collation) throws MorphiumDriverException
- Throws:
MorphiumDriverException
-
findAndOneAndUpdate
public Map<String,Object> findAndOneAndUpdate(String db, String col, Map<String,Object> query, Map<String,Object> update, Map<String,Object> sort, Map<String,Object> collation) throws MorphiumDriverException
- Throws:
MorphiumDriverException
-
findAndOneAndReplace
public Map<String,Object> findAndOneAndReplace(String db, String col, Map<String,Object> query, Map<String,Object> replacement, Map<String,Object> sort, Map<String,Object> collation) throws MorphiumDriverException
- Throws:
MorphiumDriverException
-
tailableIteration
public void tailableIteration(String db, String collection, Map<String,Object> query, Map<String,Object> sort, Map<String,Object> projection, int skip, int limit, int batchSize, ReadPreference readPreference, int timeout, DriverTailableIterationCallback cb) throws MorphiumDriverException
- Throws:
MorphiumDriverException
-
getMaxWaitTime
public int getMaxWaitTime()
- Specified by:
getMaxWaitTimein interfaceMorphiumDriver
-
setMaxWaitTime
public void setMaxWaitTime(int maxWaitTime)
- Specified by:
setMaxWaitTimein interfaceMorphiumDriver
-
getCredentials
public String[] getCredentials(String db)
- Specified by:
getCredentialsin interfaceMorphiumDriver
-
getHostSeed
public List<String> getHostSeed()
- Specified by:
getHostSeedin interfaceMorphiumDriver
-
setHostSeed
public void setHostSeed(List<String> hosts)
- Specified by:
setHostSeedin interfaceMorphiumDriver
-
getServerSelectionTimeout
public int getServerSelectionTimeout()
-
setServerSelectionTimeout
public void setServerSelectionTimeout(int serverSelectionTimeout)
-
isCapped
public boolean isCapped(String db, String coll)
- Specified by:
isCappedin interfaceMorphiumDriver
-
getNumConnectionsByHost
public Map<String,Integer> getNumConnectionsByHost()
- Specified by:
getNumConnectionsByHostin interfaceMorphiumDriver
-
createBulkContext
public BulkRequestContext createBulkContext(Morphium m, String db, String collection, boolean ordered, WriteConcern wc)
- Specified by:
createBulkContextin interfaceMorphiumDriver
-
getDriverStats
public Map<MorphiumDriver.DriverStatsKey,Double> getDriverStats()
- Specified by:
getDriverStatsin interfaceMorphiumDriver
-
createIndex
public void createIndex(String db, String collection, Map<String,Object> indexDef, Map<String,Object> options) throws MorphiumDriverException
- Throws:
MorphiumDriverException
-
mapReduce
public List<Map<String,Object>> mapReduce(String db, String collection, String mapping, String reducing) throws MorphiumDriverException
- Throws:
MorphiumDriverException
-
mapReduce
public List<Map<String,Object>> mapReduce(String db, String collection, String mapping, String reducing, Map<String,Object> query) throws MorphiumDriverException
- Throws:
MorphiumDriverException
-
mapReduce
public List<Map<String,Object>> mapReduce(String db, String collection, String mapping, String reducing, Map<String,Object> query, Map<String,Object> sorting, Collation collation) throws MorphiumDriverException
- Throws:
MorphiumDriverException
-
commitTransaction
public void commitTransaction()
- Specified by:
commitTransactionin interfaceMorphiumDriver
-
abortTransaction
public void abortTransaction()
- Specified by:
abortTransactionin interfaceMorphiumDriver
-
setTransactionContext
public void setTransactionContext(MorphiumTransactionContext ctx)
- Specified by:
setTransactionContextin interfaceMorphiumDriver
-
writeDump
public void writeDump(File f)
-
getSslContext
public SSLContext getSslContext()
-
setSslContext
public void setSslContext(SSLContext sslContext)
-
isSslInvalidHostNameAllowed
public boolean isSslInvalidHostNameAllowed()
-
setSslInvalidHostNameAllowed
public void setSslInvalidHostNameAllowed(boolean sslInvalidHostNameAllowed)
-
-