All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.couchbase.client.java.repository.CouchbaseRepository Maven / Gradle / Ivy

There is a newer version: 3.7.7
Show newest version
/**
 * Copyright (C) 2015 Couchbase, Inc.
 *
 * Permission is hereby granted, free of charge, to any person obtaining a copy
 * of this software and associated documentation files (the "Software"), to deal
 * in the Software without restriction, including without limitation the rights
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 * copies of the Software, and to permit persons to whom the Software is
 * furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be included in
 * all copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALING
 * IN THE SOFTWARE.
 */
package com.couchbase.client.java.repository;

import com.couchbase.client.core.annotations.InterfaceAudience;
import com.couchbase.client.core.annotations.InterfaceStability;
import com.couchbase.client.java.Bucket;
import com.couchbase.client.java.PersistTo;
import com.couchbase.client.java.ReplicaMode;
import com.couchbase.client.java.ReplicateTo;
import com.couchbase.client.java.document.EntityDocument;
import com.couchbase.client.java.env.CouchbaseEnvironment;
import com.couchbase.client.java.util.Blocking;

import java.util.List;
import java.util.concurrent.TimeUnit;

@InterfaceAudience.Public
@InterfaceStability.Experimental
public class CouchbaseRepository implements Repository {

    private static final TimeUnit TIMEOUT_UNIT = TimeUnit.MILLISECONDS;

    private final AsyncRepository asyncRepository;
    private final long timeout;

    public CouchbaseRepository(Bucket bucket, CouchbaseEnvironment environment) {
        this.timeout = environment.kvTimeout();
        this.asyncRepository = bucket.async().repository().toBlocking().single();
    }

    @Override
    public AsyncRepository async() {
        return asyncRepository;
    }

    @Override
    public  EntityDocument get(String id, Class entityClass) {
        return get(id, entityClass, timeout, TIMEOUT_UNIT);
    }

    @Override
    public  EntityDocument get(String id, Class entityClass, long timeout, TimeUnit timeUnit) {
        return Blocking.blockForSingle(asyncRepository.get(id, entityClass), timeout, timeUnit);
    }

    @Override
    public  EntityDocument upsert(EntityDocument document) {
        return upsert(document, timeout, TIMEOUT_UNIT);
    }

    @Override
    public  EntityDocument upsert(EntityDocument document, long timeout, TimeUnit timeUnit) {
        return Blocking.blockForSingle(asyncRepository.upsert(document), timeout, timeUnit);
    }

    @Override
    public  List> getFromReplica(String id, ReplicaMode type, Class entityClass) {
        return getFromReplica(id, type, entityClass, timeout, TIMEOUT_UNIT);
    }

    @Override
    public  List> getFromReplica(String id, ReplicaMode type, Class entityClass, long timeout, TimeUnit timeUnit) {
        return Blocking.blockForSingle(asyncRepository.getFromReplica(id, type, entityClass).toList(), timeout, timeUnit);
    }

    @Override
    public  EntityDocument getAndLock(String id, int lockTime, Class entityClass) {
        return getAndLock(id, lockTime, entityClass, timeout, TIMEOUT_UNIT);
    }

    @Override
    public  EntityDocument getAndLock(String id, int lockTime, Class entityClass, long timeout, TimeUnit timeUnit) {
        return Blocking.blockForSingle(asyncRepository.getAndLock(id, lockTime, entityClass), timeout, timeUnit);
    }

    @Override
    public  EntityDocument getAndTouch(String id, int expiry, Class entityClass) {
        return getAndTouch(id, expiry, entityClass, timeout, TIMEOUT_UNIT);
    }

    @Override
    public  EntityDocument getAndTouch(String id, int expiry, Class entityClass, long timeout, TimeUnit timeUnit) {
        return Blocking.blockForSingle(asyncRepository.getAndTouch(id, expiry, entityClass), timeout, timeUnit);
    }

    @Override
    public boolean exists(String id) {
        return exists(id, timeout, TIMEOUT_UNIT);
    }

    @Override
    public boolean exists(String id, long timeout, TimeUnit timeUnit) {
        return Blocking.blockForSingle(asyncRepository.exists(id), timeout, timeUnit);
    }

    @Override
    public  boolean exists(EntityDocument document) {
        return exists(document, timeout, TIMEOUT_UNIT);
    }

    @Override
    public  boolean exists(EntityDocument document, long timeout, TimeUnit timeUnit) {
        return Blocking.blockForSingle(asyncRepository.exists(document), timeout, timeUnit);
    }

    @Override
    public  EntityDocument upsert(EntityDocument document, PersistTo persistTo) {
        return upsert(document, persistTo, timeout, TIMEOUT_UNIT);
    }

    @Override
    public  EntityDocument upsert(EntityDocument document, PersistTo persistTo, long timeout, TimeUnit timeUnit) {
        return upsert(document, persistTo, ReplicateTo.NONE, timeout, timeUnit);
    }

    @Override
    public  EntityDocument upsert(EntityDocument document, ReplicateTo replicateTo) {
        return upsert(document, replicateTo, timeout, TIMEOUT_UNIT);
    }

    @Override
    public  EntityDocument upsert(EntityDocument document, ReplicateTo replicateTo, long timeout, TimeUnit timeUnit) {
        return upsert(document, PersistTo.NONE, replicateTo, timeout, timeUnit);
    }

    @Override
    public  EntityDocument upsert(EntityDocument document, PersistTo persistTo, ReplicateTo replicateTo) {
        return upsert(document, persistTo, replicateTo, timeout, TIMEOUT_UNIT);
    }

    @Override
    public  EntityDocument upsert(EntityDocument document, PersistTo persistTo, ReplicateTo replicateTo, long timeout, TimeUnit timeUnit) {
        return Blocking.blockForSingle(asyncRepository.upsert(document, persistTo, replicateTo), timeout, timeUnit);
    }

    @Override
    public  EntityDocument insert(EntityDocument document, PersistTo persistTo) {
        return insert(document, persistTo, timeout, TIMEOUT_UNIT);
    }

    @Override
    public  EntityDocument insert(EntityDocument document, PersistTo persistTo, long timeout, TimeUnit timeUnit) {
        return insert(document, persistTo, ReplicateTo.NONE, timeout, timeUnit);
    }

    @Override
    public  EntityDocument insert(EntityDocument document, ReplicateTo replicateTo) {
        return insert(document, replicateTo, timeout, TIMEOUT_UNIT);
    }

    @Override
    public  EntityDocument insert(EntityDocument document, ReplicateTo replicateTo, long timeout, TimeUnit timeUnit) {
        return insert(document, PersistTo.NONE, replicateTo, timeout, timeUnit);
    }

    @Override
    public  EntityDocument insert(EntityDocument document, PersistTo persistTo, ReplicateTo replicateTo) {
        return insert(document, persistTo, replicateTo, timeout, TIMEOUT_UNIT);
    }

    @Override
    public  EntityDocument insert(EntityDocument document, PersistTo persistTo, ReplicateTo replicateTo, long timeout, TimeUnit timeUnit) {
        return Blocking.blockForSingle(asyncRepository.insert(document, persistTo, replicateTo), timeout, timeUnit);
    }

    @Override
    public  EntityDocument insert(EntityDocument document) {
        return insert(document, timeout, TIMEOUT_UNIT);
    }

    @Override
    public  EntityDocument insert(EntityDocument document, long timeout, TimeUnit timeUnit) {
        return insert(document, PersistTo.NONE, ReplicateTo.NONE, timeout, timeUnit);
    }

    @Override
    public  EntityDocument replace(EntityDocument document) {
        return replace(document, timeout, TIMEOUT_UNIT);
    }

    @Override
    public  EntityDocument replace(EntityDocument document, long timeout, TimeUnit timeUnit) {
        return replace(document, PersistTo.NONE, ReplicateTo.NONE, timeout, timeUnit);
    }

    @Override
    public  EntityDocument replace(EntityDocument document, PersistTo persistTo) {
        return replace(document, persistTo, timeout, TIMEOUT_UNIT);
    }

    @Override
    public  EntityDocument replace(EntityDocument document, PersistTo persistTo, long timeout, TimeUnit timeUnit) {
        return replace(document, persistTo, ReplicateTo.NONE, timeout, timeUnit);
    }

    @Override
    public  EntityDocument replace(EntityDocument document, ReplicateTo replicateTo) {
        return replace(document, replicateTo, timeout, TIMEOUT_UNIT);
    }

    @Override
    public  EntityDocument replace(EntityDocument document, ReplicateTo replicateTo, long timeout, TimeUnit timeUnit) {
        return replace(document, PersistTo.NONE, replicateTo, timeout, timeUnit);
    }

    @Override
    public  EntityDocument replace(EntityDocument document, PersistTo persistTo, ReplicateTo replicateTo) {
        return replace(document, persistTo, replicateTo, timeout, TIMEOUT_UNIT);
    }

    @Override
    public  EntityDocument replace(EntityDocument document, PersistTo persistTo, ReplicateTo replicateTo, long timeout, TimeUnit timeUnit) {
        return Blocking.blockForSingle(asyncRepository.replace(document, persistTo, replicateTo), timeout, timeUnit);
    }

    @Override
    public  EntityDocument remove(EntityDocument document) {
        return remove(document, timeout, TIMEOUT_UNIT);
    }

    @Override
    public  EntityDocument remove(EntityDocument document, long timeout, TimeUnit timeUnit) {
        return remove(document, PersistTo.NONE, ReplicateTo.NONE, timeout, timeUnit);
    }

    @Override
    public  EntityDocument remove(EntityDocument document, PersistTo persistTo) {
        return remove(document, persistTo, ReplicateTo.NONE, timeout, TIMEOUT_UNIT);
    }

    @Override
    public  EntityDocument remove(EntityDocument document, PersistTo persistTo, long timeout, TimeUnit timeUnit) {
        return remove(document, persistTo, ReplicateTo.NONE, timeout, timeUnit);
    }

    @Override
    public  EntityDocument remove(EntityDocument document, ReplicateTo replicateTo) {
        return remove(document, PersistTo.NONE, replicateTo, timeout, TIMEOUT_UNIT);
    }

    @Override
    public  EntityDocument remove(EntityDocument document, ReplicateTo replicateTo, long timeout, TimeUnit timeUnit) {
        return remove(document, PersistTo.NONE, replicateTo, timeout, timeUnit);
    }

    @Override
    public  EntityDocument remove(EntityDocument document, PersistTo persistTo, ReplicateTo replicateTo) {
        return remove(document, persistTo, replicateTo, timeout, TIMEOUT_UNIT);
    }

    @Override
    public  EntityDocument remove(EntityDocument document, PersistTo persistTo, ReplicateTo replicateTo, long timeout, TimeUnit timeUnit) {
        return Blocking.blockForSingle(asyncRepository.remove(document, persistTo, replicateTo), timeout, timeUnit);
    }

    @Override
    public  EntityDocument remove(String id, Class entityClass) {
        return remove(id, entityClass, timeout, TIMEOUT_UNIT);
    }

    @Override
    public  EntityDocument remove(String id, Class entityClass, long timeout, TimeUnit timeUnit) {
        return remove(id, PersistTo.NONE, ReplicateTo.NONE, entityClass, timeout, timeUnit);
    }

    @Override
    public  EntityDocument remove(String id, PersistTo persistTo, Class entityClass) {
        return remove(id, persistTo, ReplicateTo.NONE, entityClass, timeout, TIMEOUT_UNIT);
    }

    @Override
    public  EntityDocument remove(String id, PersistTo persistTo, Class entityClass, long timeout, TimeUnit timeUnit) {
        return remove(id, persistTo, ReplicateTo.NONE, entityClass, timeout, timeUnit);
    }

    @Override
    public  EntityDocument remove(String id, ReplicateTo replicateTo, Class entityClass) {
        return remove(id, PersistTo.NONE, replicateTo, entityClass, timeout, TIMEOUT_UNIT);
    }

    @Override
    public  EntityDocument remove(String id, ReplicateTo replicateTo, Class entityClass, long timeout, TimeUnit timeUnit) {
        return remove(id, PersistTo.NONE, replicateTo, entityClass, timeout, timeUnit);
    }

    @Override
    public  EntityDocument remove(String id, PersistTo persistTo, ReplicateTo replicateTo, Class entityClass) {
        return remove(id, persistTo, replicateTo, entityClass, timeout, TIMEOUT_UNIT);
    }

    @Override
    public  EntityDocument remove(String id, PersistTo persistTo, ReplicateTo replicateTo, Class entityClass, long timeout, TimeUnit timeUnit) {
        return Blocking.blockForSingle(asyncRepository.remove(id, persistTo, replicateTo, entityClass), timeout, timeUnit);
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy