Class CouchbaseConnector

java.lang.Object
edu.ie3.datamodel.io.connectors.CouchbaseConnector
All Implemented Interfaces:
DataConnector

public class CouchbaseConnector extends Object implements DataConnector
Implements a DataConnector for Couchbase. Couchbase is a JSON document based database.
Entities will be persisted in documents which are then mapped by a key.
  • Constructor Details

    • CouchbaseConnector

      public CouchbaseConnector(String url, String bucketName, String username, String password)
      Initializes a new CouchbaseConnector
      Parameters:
      url - the url to the cluster
      bucketName - the name of the bucket to connect to
      username - the user name
      password - the user password
  • Method Details

    • getSession

      public com.couchbase.client.java.Collection getSession()
      Return the couchbase java sdk equivalent of a session - a collection - to the previously set bucket
      Returns:
      a couchbase collection
    • getAsyncSession

      public com.couchbase.client.java.AsyncCollection getAsyncSession()
      Return the couchbase java sdk equivalent of an asynchronous session - an async collection - to the previously set bucket
      Returns:
      an asynchronous couchbase collection
    • isConnectionValid

      public Boolean isConnectionValid()
      Checks if the database connection is valid
      Returns:
      true, if the cluster responds to an application based ping
    • shutdown

      public void shutdown()
      Specified by:
      shutdown in interface DataConnector
    • getBucketName

      public String getBucketName()
      Returns:
      the bucket name
    • query

      public CompletableFuture<com.couchbase.client.java.query.QueryResult> query(String query)
      Returns a future for the result of the given query, will be executed asynchronously
      Parameters:
      query - the query string
      Returns:
      a future of the query result
    • bulkGet

      public List<CompletableFuture<com.couchbase.client.java.kv.GetResult>> bulkGet(List<String> keys)
      Returns futures for every key search result, will be executed asychnchronously
      Parameters:
      keys - the keys to get the documents for
      Returns:
      list of futures for every key search result
    • get

      public CompletableFuture<com.couchbase.client.java.kv.GetResult> get(String key)
      Returns a future for search result of the given key
      Parameters:
      key - the key to get the document for
      Returns:
      future of the search result
    • persist

      public CompletableFuture<com.couchbase.client.java.kv.MutationResult> persist(String key, Object content)
      Persist the document to the database and map it to the key
      Parameters:
      key - the key for the document
      content - the document content
      Returns:
      future of the persisting result