本文整理汇总了Java中org.ektorp.CouchDbInstance类的典型用法代码示例。如果您正苦于以下问题:Java CouchDbInstance类的具体用法?Java CouchDbInstance怎么用?Java CouchDbInstance使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
CouchDbInstance类属于org.ektorp包,在下文中一共展示了CouchDbInstance类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testCreate
import org.ektorp.CouchDbInstance; //导入依赖的package包/类
@Test
public void testCreate() {
final CloudantServiceInfo badUrlServiceInfo = new CloudantServiceInfo(
"id",
"username",
"password",
"hostname",
443,
"url"
);
assertNull(creator.create(badUrlServiceInfo, new ServiceConnectorConfig() {
}));
final CloudantServiceInfo serviceInfo = new CloudantServiceInfo(
"testId",
"username",
"password",
"username.cloudant.com",
443,
"https://username:[email protected]"
);
assertTrue(creator.create(serviceInfo, new ServiceConnectorConfig() {
}) instanceof CouchDbInstance);
}
示例2: connector
import org.ektorp.CouchDbInstance; //导入依赖的package包/类
@Bean
public StdCouchDbConnector connector() throws Exception {
String url = "http://localhost:5984/";
String databaseName = "ektorp-integration-tests";
Properties properties = new Properties();
properties.setProperty("autoUpdateViewOnChange", "true");
HttpClientFactoryBean factory = new HttpClientFactoryBean();
factory.setUrl(url);
factory.setProperties(properties);
factory.afterPropertiesSet();
HttpClient client = factory.getObject();
CouchDbInstance dbInstance = new StdCouchDbInstance(client);
return new StdCouchDbConnector(databaseName, dbInstance);
}
示例3: testAttachments
import org.ektorp.CouchDbInstance; //导入依赖的package包/类
public void testAttachments() throws IOException {
HttpClient httpClient = new CBLiteHttpClient(manager);
CouchDbInstance dbInstance = new StdCouchDbInstance(httpClient);
CouchDbConnector dbConnector = dbInstance.createConnector(DEFAULT_TEST_DB, true);
TestObject test = new TestObject(1, false, "ektorp");
//create a document
dbConnector.create(test);
//attach file to it
byte[] attach1 = "This is the body of attach1".getBytes();
ByteArrayInputStream b = new ByteArrayInputStream(attach1);
AttachmentInputStream a = new AttachmentInputStream("attach", b, "text/plain");
dbConnector.createAttachment(test.getId(), test.getRevision(), a);
AttachmentInputStream readAttachment = dbConnector.getAttachment(test.getId(), "attach");
Assert.assertEquals("text/plain", readAttachment.getContentType());
Assert.assertEquals("attach", readAttachment.getId());
BufferedReader br = new BufferedReader(new InputStreamReader(readAttachment));
Assert.assertEquals("This is the body of attach1", br.readLine());
}
示例4: instance
import org.ektorp.CouchDbInstance; //导入依赖的package包/类
public static CouchDbConnector instance() {
if (db != null) {
return db;
}
synchronized (Database.class) {
try {
CouchDbInstance db_lookup = (CouchDbInstance) new InitialContext().lookup(DATABASE_JNDI);
db = db_lookup.createConnector(DATABASE_NAME, true);
return db;
} catch (Exception e) {
throw new RuntimeException(e);
}
}
}
示例5: initConnection
import org.ektorp.CouchDbInstance; //导入依赖的package包/类
private CouchDbConnector initConnection() throws MalformedURLException, ProxyInitilizedFailedException {
String username = ConfigManager.get("couchdbUsername");
String password = ConfigManager.get("couchdbPassword");
String host = ConfigManager.get("couchdbHost");
int port = ConfigManager.getInt("couchdbPort");
int timeout = ConfigManager.getInt("couchdbTimeout");
boolean enableSSL = ConfigManager.getBoolean("couchdbEnableSSL", false);
String dbName = ConfigManager.get("couchdbDBName");
Builder builder = new StdHttpClient.Builder();
builder = builder
.host(host)
.port(port)
.connectionTimeout(timeout)
.enableSSL(enableSSL);
if (username != null && !username.isEmpty() && password != null && !password.isEmpty() ) {
builder = builder.username(username).password(password);
}
CouchDbInstance dbInstance = new StdCouchDbInstance(builder.build());
if (!dbInstance.checkIfDbExists(dbName))
dbInstance.createDatabase(dbName);
CouchDbConnector couchDB = dbInstance.createConnector(dbName, true);
return couchDB;
}
示例6: init
import org.ektorp.CouchDbInstance; //导入依赖的package包/类
/**
* Inits the.
*/
@PostConstruct
public void init() {
LOGGER.trace("Initializing version: " + WifKeys.WIF_KEY_VERSION);
// TODO do it more elegant,enable the rewriting of reviews, only for
// development
System.setProperty("org.ektorp.support.AutoUpdateViewOnChange", "true");
repoURL = couchDBConfig.getRepoURL();
wifDB = couchDBConfig.getWifDB();
loginRequired = couchDBConfig.isLoginRequired();
LOGGER.info("Using CouchDB URL {}, with What If database: {} ", repoURL,
wifDB);
try {
if (loginRequired) {
LOGGER.info("using the login name {} ", couchDBConfig.getLogin());
httpClient = new StdHttpClient.Builder().url(repoURL)
.username(couchDBConfig.getLogin())
.password(couchDBConfig.getPassword()).build();
} else {
LOGGER.info("authentication not required, not using credentials");
httpClient = new StdHttpClient.Builder().url(repoURL).build();
}
} catch (MalformedURLException e) {
LOGGER.error(
"MalformedURLException: Using CouchDB URL {} , with What If database: {} "
+ repoURL, wifDB);
}
CouchDbInstance dbInstance = new StdCouchDbInstance(httpClient);
// TODO There should be one for each repository
db = new StdCouchDbConnector(wifDB, dbInstance);
}
示例7: create
import org.ektorp.CouchDbInstance; //导入依赖的package包/类
@Override
public CouchDbInstance create(CloudantServiceInfo serviceInfo,
ServiceConnectorConfig serviceConnectorConfig) {
HttpClient httpClient;
try {
httpClient = new StdHttpClient.Builder()
.url(serviceInfo.getUrl())
.build();
return new StdCouchDbInstance(httpClient);
} catch (MalformedURLException e) {
LOG.logp(Level.WARNING, CloudantInstanceCreator.class.getName(), "create", "Error parsing URL", e);
return null;
}
}
示例8: init
import org.ektorp.CouchDbInstance; //导入依赖的package包/类
@PostConstruct
private void init() {
HttpClient httpClient;
httpClient = new StdHttpClient.Builder()
.host("127.0.0.1")
.port(5984)
.username("admin")
.password("password")
.build();
CouchDbInstance dbInstance = new StdCouchDbInstance(httpClient);
couchDBConnector = dbInstance.createConnector("relax-dms", false);
restTemplate = new RestTemplate(httpClient);
}
示例9: configure
import org.ektorp.CouchDbInstance; //导入依赖的package包/类
@Override
protected void configure() {
try {
CouchDbInstance couchDbInstance = new StdCouchDbInstance(new StdHttpClient.Builder()
.url(couchDbConfig.getUrl())
.username(couchDbConfig.getAdmin().getUsername())
.password(couchDbConfig.getAdmin().getPassword())
.maxConnections(couchDbConfig.getMaxConnections())
.build());
DbConnectorFactory connectorFactory = new DbConnectorFactory(couchDbInstance, couchDbConfig.getDbPrefix());
CouchDbConnector dataSourceConnector = connectorFactory.createConnector(OdsRegistrationRepository.DATABASE_NAME, true);
bind(CouchDbConnector.class).annotatedWith(Names.named(OdsRegistrationRepository.DATABASE_NAME)).toInstance(dataSourceConnector);
CouchDbConnector clientConnector = connectorFactory.createConnector(ClientRepository.DATABASE_NAME, true);
bind(CouchDbConnector.class).annotatedWith(Names.named(ClientRepository.DATABASE_NAME)).toInstance(clientConnector);
CouchDbConnector eplAdapterConnector = connectorFactory.createConnector(EplAdapterRepository.DATABASE_NAME, true);
bind(CouchDbConnector.class).annotatedWith(Names.named(EplAdapterRepository.DATABASE_NAME)).toInstance(eplAdapterConnector);
CouchDbConnector userConnector = connectorFactory.createConnector(UserRepository.DATABASE_NAME, true);
bind(CouchDbConnector.class).annotatedWith(Names.named(UserRepository.DATABASE_NAME)).toInstance(userConnector);
} catch (MalformedURLException mue) {
throw new RuntimeException(mue);
}
}
示例10: createConnector
import org.ektorp.CouchDbInstance; //导入依赖的package包/类
public CouchDbConnector createConnector(String couchUrl, String dbName,
int maxConnections, String username, String password) {
HttpClient httpClient;
try {
StdHttpClient.Builder builder = new StdHttpClient.Builder().url(
couchUrl).maxConnections(maxConnections);
if (username != null) {
builder.username(username);
}
if (password != null) {
builder.password(password);
}
httpClient = builder.build();
} catch (MalformedURLException e) {
throw new IllegalStateException(e);
}
CouchDbInstance dbInstance = new StdCouchDbInstance(httpClient);
StdCouchDbConnector connector = new StdCouchDbConnector(dbName,
dbInstance) {
final StreamingJsonSerializer customSerializer = new StreamingJsonSerializer(
mapper);
@Override
protected String serializeToJson(Object o) {
return customSerializer.toJson(o);
}
};
return connector;
}
示例11: doTest
import org.ektorp.CouchDbInstance; //导入依赖的package包/类
@Test
public void doTest() {
Item item = new Item();
item.setItemField("test" + System.currentTimeMillis());
CouchDbInstance dbInstance = new StdCouchDbInstance(httpClient);
db = new StdCouchDbConnector("mydatabase", dbInstance);
db.createDatabaseIfNotExists();
db.create(item);
Assert.assertEquals(item.getItemField(), db.get(Item.class, item.getId()).getItemField());
}
示例12: configure
import org.ektorp.CouchDbInstance; //导入依赖的package包/类
@Override
protected void configure() {
try {
CouchDbInstance couchDbInstance = new StdCouchDbInstance(new StdHttpClient.Builder()
.url(couchDbConfig.getUrl())
.username(couchDbConfig.getAdmin().getUsername())
.password(couchDbConfig.getAdmin().getPassword())
.maxConnections(couchDbConfig.getMaxConnections())
.build());
DbConnectorFactory connectorFactory = new DbConnectorFactory(couchDbInstance, couchDbConfig.getDbPrefix());
CouchDbConnector dataSourceConnector = connectorFactory.createConnector(DataSourceRepository.DATABASE_NAME, true);
bind(CouchDbConnector.class).annotatedWith(Names.named(DataSourceRepository.DATABASE_NAME)).toInstance(dataSourceConnector);
CouchDbConnector userConnector = connectorFactory.createConnector(UserRepository.DATABASE_NAME, true);
bind(CouchDbConnector.class).annotatedWith(Names.named(UserRepository.DATABASE_NAME)).toInstance(userConnector);
bind(DbConnectorFactory.class).toInstance(connectorFactory);
install(new FactoryModuleBuilder().build(RepositoryFactory.class));
bind(DataSourceRepository.class).in(Singleton.class);
bind(new TypeLiteral<Cache<DataViewRepository>>() { }).in(Singleton.class);
bind(new TypeLiteral<Cache<ProcessorChainReferenceRepository>>() { }).in(Singleton.class);
bind(new TypeLiteral<Cache<NotificationClientRepository>>() { }).in(Singleton.class);
bind(new TypeLiteral<Cache<PluginMetaDataRepository>>() { }).in(Singleton.class);
bind(new TypeLiteral<Cache<DataRepository>>() { }).in(Singleton.class);
} catch (MalformedURLException mue) {
throw new RuntimeException(mue);
}
}
示例13: createConnectors
import org.ektorp.CouchDbInstance; //导入依赖的package包/类
private List<CouchDbConnector> createConnectors(List<URL> urlsForConnectors, String databaseName){
List<CouchDbConnector> result = new ArrayList<CouchDbConnector>();
for(URL url : urlsForConnectors){
HttpClient httpClient = new StdHttpClient.Builder().url(url).build();
CouchDbInstance dbInstance = new StdCouchDbInstance(httpClient);
// 2nd paramter true => Create database if not exists
CouchDbConnector dbConnector = dbInstance.createConnector(databaseName, true);
result.add(dbConnector);
}
return result;
}
示例14: testViewQueryFromWeb
import org.ektorp.CouchDbInstance; //导入依赖的package包/类
public void testViewQueryFromWeb() throws IOException {
HttpClient httpClient = new CBLiteHttpClient(manager);
CouchDbInstance dbInstance = new StdCouchDbInstance(httpClient);
CouchDbConnector couchDbConnector = dbInstance.createConnector(DEFAULT_TEST_DB, true);
String dDocName = "ddoc";
String viewName = "people";
View view = database.getView(String.format("%s/%s", dDocName, viewName));
view.setMapReduce(new Mapper() {
@Override
public void map(Map<String, Object> document, Emitter emitter) {
String type = (String) document.get("type");
if ("person".equals(type)) {
emitter.emit(null, document.get("_id"));
}
}
}, new Reducer() {
@Override
public Object reduce(List<Object> keys, List<Object> values, boolean rereduce) {
return null;
}
}, "1"
);
ViewQuery viewQuery = new ViewQuery().designDocId("_design/" + dDocName).viewName(viewName);
//viewQuery.descending(true); //use this to reverse the sorting order of the view
ViewResult viewResult = couchDbConnector.queryView(viewQuery);
Assert.assertEquals(0, viewResult.getTotalRows());
}
示例15: testPull
import org.ektorp.CouchDbInstance; //导入依赖的package包/类
public void testPull() throws IOException {
CountDownLatch doneSignal = new CountDownLatch(1);
HttpClient httpClient = new CBLiteHttpClient(manager);
CouchDbInstance dbInstance = new StdCouchDbInstance(httpClient);
// create a local database
CouchDbConnector dbConnector = dbInstance.createConnector(DEFAULT_TEST_DB, true);
// push this database to the test replication server
ReplicationCommand pushCommand = new ReplicationCommand.Builder()
.source(getReplicationURL().toExternalForm())
.target(DEFAULT_TEST_DB)
.continuous(false)
.build();
ReplicationStatus status = dbInstance.replicate(pushCommand);
Replication repl = database.getReplicator(status.getSessionId());
ReplicationChangeListener replicationObserver = new ReplicationChangeListener(doneSignal);
repl.addChangeListener(replicationObserver);
try {
boolean success = doneSignal.await(30, TimeUnit.SECONDS);
assertTrue(success);
} catch (InterruptedException e) {
e.printStackTrace();
}
Assert.assertNotNull(status.getSessionId());
}