本文整理汇总了Java中org.ektorp.CouchDbConnector.create方法的典型用法代码示例。如果您正苦于以下问题:Java CouchDbConnector.create方法的具体用法?Java CouchDbConnector.create怎么用?Java CouchDbConnector.create使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.ektorp.CouchDbConnector
的用法示例。
在下文中一共展示了CouchDbConnector.create方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: createDesign
import org.ektorp.CouchDbConnector; //导入方法依赖的package包/类
public static void createDesign(CouchDbConnector db) {
if (!db.contains("_design/views")) {
DesignDocument dd = new DesignDocument("_design/views");
String mapFullPicturesByCreationDate = "function(doc) {\n if (doc.type == \"FullPicture\") {\n emit(doc.creationDate, doc);\n }\n}";
String mapPortraitsByCreationDate = "function(doc) {\n if (doc.type == \"Portrait\") {\n emit(doc.creationDate, doc);\n }\n}";
DesignDocument.View view = new DesignDocument.View(mapFullPicturesByCreationDate);
dd.addView("fullPicturesByCreationDate", view);
view = new DesignDocument.View(mapPortraitsByCreationDate);
dd.addView("portraitsByCreationDate", view);
db.create(dd);
}
}
示例2: testAttachments
import org.ektorp.CouchDbConnector; //导入方法依赖的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());
}
示例3: addComment
import org.ektorp.CouchDbConnector; //导入方法依赖的package包/类
private void addComment(String itemNumber, String comment){
CouchDbConnector dbc = _db.createConnector(dbname, true);
Map<String, String> doc = new HashMap<String, String>();
doc.put("_id", UUID.randomUUID().toString());
doc.put("itemNumber", itemNumber);
doc.put("comment", comment);
dbc.create(doc);
}
示例4: signUp
import org.ektorp.CouchDbConnector; //导入方法依赖的package包/类
public static boolean signUp(String username, String password, String email)
throws SignUpException {
CouchDbConnector usersDb = getUsersDb();
try {
usersDb.create(getUser(username, password, email));
} catch (Exception e) {
throw new SignUpException("Username not Available");
}
return false;
}
示例5: putDocs
import org.ektorp.CouchDbConnector; //导入方法依赖的package包/类
public void putDocs(CouchDbConnector db) {
TestObject obj2 = new TestObject("22222", "two");
db.create(obj2);
TestObject obj4 = new TestObject("44444", "four");
db.create(obj4);
TestObject obj1 = new TestObject("11111", "one");
db.create(obj1);
TestObject obj3 = new TestObject("33333", "three");
db.create(obj3);
TestObject obj5 = new TestObject("55555", "five");
db.create(obj5);
}
示例6: testPush
import org.ektorp.CouchDbConnector; //导入方法依赖的package包/类
public void testPush() 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);
// create 3 objects
TestObject test1 = new TestObject(1, false, "ektorp-1");
TestObject test2 = new TestObject(2, false, "ektorp-2");
TestObject test3 = new TestObject(3, false, "ektorp-3");
// save these objects in the database
dbConnector.create(test1);
dbConnector.create(test2);
dbConnector.create(test3);
// push this database to the test replication server
ReplicationCommand pushCommand = new ReplicationCommand.Builder()
.source(DEFAULT_TEST_DB)
.target(getReplicationURL().toExternalForm())
.continuous(false)
.createTarget(true)
.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());
}
示例7: testFilteredPush
import org.ektorp.CouchDbConnector; //导入方法依赖的package包/类
public void testFilteredPush() throws IOException {
CountDownLatch doneSignal = new CountDownLatch(1);
// install the filter
database.setFilter("evenFoo", new ReplicationFilter() {
@Override
public boolean filter(SavedRevision revision, Map<String, Object> params) {
Integer foo = (Integer) revision.getProperties().get("foo");
if (foo != null && foo.intValue() % 2 == 0) {
return true;
}
return false;
}
});
HttpClient httpClient = new CBLiteHttpClient(manager);
CouchDbInstance dbInstance = new StdCouchDbInstance(httpClient);
// create a local database
CouchDbConnector dbConnector = dbInstance.createConnector(DEFAULT_TEST_DB, true);
// create 3 objects
TestObject test1 = new TestObject(1, false, "ektorp-1");
TestObject test2 = new TestObject(2, false, "ektorp-2");
TestObject test3 = new TestObject(3, false, "ektorp-3");
// save these objects in the database
dbConnector.create(test1);
dbConnector.create(test2);
dbConnector.create(test3);
// push this database to the test replication server
ReplicationCommand pushCommand = new ReplicationCommand.Builder()
.source(DEFAULT_TEST_DB)
.target(getReplicationURL().toExternalForm())
.continuous(false)
.filter("evenFoo")
.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());
}
示例8: disabledTestPushToLocal
import org.ektorp.CouchDbConnector; //导入方法依赖的package包/类
public void disabledTestPushToLocal() throws Exception, IOException {
Database other = manager.getExistingDatabase(DEFAULT_TEST_DB + "2");
if(other != null) {
other.delete();
}
HttpClient httpClient = new CBLiteHttpClient(manager);
CouchDbInstance dbInstance = new StdCouchDbInstance(httpClient);
// create a local database
CouchDbConnector dbConnector = dbInstance.createConnector(DEFAULT_TEST_DB, true);
// create 3 objects
TestObject test1 = new TestObject(1, false, "ektorp-1");
TestObject test2 = new TestObject(2, false, "ektorp-2");
TestObject test3 = new TestObject(3, false, "ektorp-3");
// save these objects in the database
dbConnector.create(test1);
dbConnector.create(test2);
dbConnector.create(test3);
// push this database to the test replication server
ReplicationCommand pushCommand = new ReplicationCommand.Builder()
.source(DEFAULT_TEST_DB)
.target(DEFAULT_TEST_DB + "2")
.continuous(false)
.createTarget(true)
.build();
ReplicationStatus status = dbInstance.replicate(pushCommand);
try {
Thread.sleep(60*1000);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
Assert.assertNotNull(status.getSessionId());
}