Package gov.nysenate.openleg.qa.model

Source Code of gov.nysenate.openleg.qa.model.CouchInstance

package gov.nysenate.openleg.qa.model;

import org.ektorp.CouchDbConnector;
import org.ektorp.CouchDbInstance;
import org.ektorp.http.HttpClient;
import org.ektorp.impl.NameConventions;
import org.ektorp.impl.StdCouchDbInstance;
import org.ektorp.support.DesignDocument;

public class CouchInstance {
    private static CouchInstance couchInstance = null;

    public static CouchInstance getInstance(String databaseName, boolean createIfNotExist, HttpClient httpClient) {
        if(couchInstance == null) {
            couchInstance = new CouchInstance(databaseName, createIfNotExist, httpClient);
        }
        return couchInstance;
    }

    private CouchDbInstance couchDbInstance = null;
    private CouchDbConnector couchDbConnector = null;

    private CouchInstance(String databaseName, boolean createIfNotExist, HttpClient httpClient) {
        couchDbInstance = new StdCouchDbInstance(httpClient);
        couchDbConnector = couchDbInstance.createConnector(databaseName, createIfNotExist);
    }

    public CouchDbInstance getDbInstance() {
        return couchDbInstance;
    }

    public CouchDbConnector getConnector() {
        return couchDbConnector;
    }

    public static DesignDocument getDesignDocumentForClass(Class<?> clazz, CouchInstance instance) {
        String stdDesignDocumentId = NameConventions.designDocName(clazz);
        DesignDocument dd = instance.getConnector().get(DesignDocument.class, stdDesignDocumentId);
        return dd;
    }
}
TOP

Related Classes of gov.nysenate.openleg.qa.model.CouchInstance

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.