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

nl.vpro.ektorp.Support Maven / Gradle / Ivy

There is a newer version: 2.8.1
Show newest version
package nl.vpro.ektorp;

import lombok.extern.slf4j.Slf4j;

import org.ektorp.CouchDbConnector;
import org.ektorp.DbAccessException;
import org.ektorp.impl.NameConventions;
import org.ektorp.support.CouchDbRepositorySupport;

/**
 * @author Michiel Meeuwissen
 * @since 3.6
 */
@Slf4j
public class Support extends CouchDbRepositorySupport {

    public static  Support getInstance(String logInfo, Class type, CouchDbConnector db, boolean createIfNotExists) {
        try {
            return new Support<>(type, db, createIfNotExists);
        } catch (DbAccessException dbe) {
            log.error(logInfo + " " + db.getDatabaseName() + ": " + dbe.getClass().getName() + " " + dbe.getMessage());
            log.info("Will create a connector to couchdb without trying to check and create the database (supposing it is temporary down now");
            return new Support<>(type, db, false);
        }
    }

    public static  Support getInstance(String logInfo, Class type, CouchDbConnector db) {
        return getInstance(logInfo, type, db, true);
    }


    protected Support(Class type, CouchDbConnector db) {
        super(type, db);
    }

    protected Support(Class type, CouchDbConnector db, boolean createIfNotExists) {
        super(type, db, createIfNotExists);
    }

    public CouchDbConnector getConnector() {
        return db;
    }

    public String getPath() {
        return getConnector().path();
    }

    public String getDesignDocumentId() {
        return NameConventions.designDocName(type);
    }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy