本文整理汇总了Java中com.cloudant.client.api.Database类的典型用法代码示例。如果您正苦于以下问题:Java Database类的具体用法?Java Database怎么用?Java Database使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
Database类属于com.cloudant.client.api包,在下文中一共展示了Database类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: doPost
import com.cloudant.client.api.Database; //导入依赖的package包/类
protected void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
Part part = request.getPart("file");
String id = request.getParameter("id");
String name = request.getParameter("name");
String value = request.getParameter("value");
String fileName = request.getParameter("filename");
Database db = null;
try {
db = CloudantClientMgr.getDB();
} catch (Exception re) {
re.printStackTrace();
response.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
return;
}
ResourceServlet servlet = new ResourceServlet();
JsonObject resultObject = servlet.create(db, id, name, value, part, fileName);
System.out.println("Upload completed.");
response.getWriter().println(resultObject.toString());
}
示例2: create
import com.cloudant.client.api.Database; //导入依赖的package包/类
@POST
public Response create(@QueryParam("id") Long id, @FormParam("name") String name, @FormParam("value") String value)
throws Exception {
Database db = null;
try {
db = getDB();
} catch (Exception re) {
re.printStackTrace();
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).build();
}
String idString = id == null ? null : id.toString();
JsonObject resultObject = create(db, idString, name, value, null, null);
System.out.println("Create Successful.");
return Response.ok(resultObject.toString()).build();
}
示例3: delete
import com.cloudant.client.api.Database; //导入依赖的package包/类
@DELETE
public Response delete(@QueryParam("id") long id) {
Database db = null;
try {
db = getDB();
} catch (Exception re) {
re.printStackTrace();
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).build();
}
// check if document exist
HashMap<String, Object> obj = db.find(HashMap.class, id + "");
if (obj == null) {
return Response.status(Response.Status.NOT_FOUND).build();
} else {
db.remove(obj);
System.out.println("Delete Successful.");
return Response.ok("OK").build();
}
}
示例4: addRequestChatHistory
import com.cloudant.client.api.Database; //导入依赖的package包/类
private void addRequestChatHistory() {
Database chatDB = helper.getChatDB();
if(chatDB != null) {
chatDB.save(new ChatModel()
.setId(msgId + ChatModel.ID_SEPARATOR + "request")
.setUserId(request.getUserId())
.setRequest(request)
.setTimestamp(timestamp)
);
}
}
示例5: addResponseChatHistory
import com.cloudant.client.api.Database; //导入依赖的package包/类
private void addResponseChatHistory(List<Response> responseList) {
Database chatDB = helper.getChatDB();
if(chatDB != null) {
chatDB.save(new ChatModel()
.setId(msgId + ChatModel.ID_SEPARATOR + "response")
.setUserId(request.getUserId())
.setFromBot(true)
.setResponse(responseList)
.setTimestamp(new Date().getTime())
);
}
}
示例6: databaseBeanCreation
import com.cloudant.client.api.Database; //导入依赖的package包/类
@Test
public void databaseBeanCreation() {
Database mockDb = mock(Database.class);
when(mockBuilder.build()).thenReturn(mockClient);
when(mockClient.database("testName", true)).thenReturn(mockDb);
this.context.register(MockCloudantClientConfig.class, MockClientBuilderConfig.class,
CloudantAutoConfiguration.class);
EnvironmentTestUtils.addEnvironment(this.context, "cloudant.db=testName");
this.context.refresh();
Database db = this.context.getBean(Database.class);
assertEquals(mockDb, db);
}
示例7: getDB
import com.cloudant.client.api.Database; //导入依赖的package包/类
public static Database getDB() {
if (cloudant == null) {
initClient();
}
if (db == null) {
try {
db = cloudant.database(databaseName, true);
} catch (Exception e) {
throw new RuntimeException("DB Not found", e);
}
}
return db;
}
示例8: update
import com.cloudant.client.api.Database; //导入依赖的package包/类
@PUT
public Response update(@QueryParam("id") long id, @QueryParam("name") String name,
@QueryParam("value") String value) {
Database db = null;
try {
db = getDB();
} catch (Exception re) {
re.printStackTrace();
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).build();
}
// check if document exist
HashMap<String, Object> obj = db.find(HashMap.class, id + "");
if (obj == null) {
return Response.status(Response.Status.NOT_FOUND).build();
} else {
obj.put("name", name);
obj.put("value", value);
db.update(obj);
System.out.println("Update Successful.");
return Response.ok("OK").build();
}
}
示例9: saveAttachment
import com.cloudant.client.api.Database; //导入依赖的package包/类
private void saveAttachment(Database db, String id, Part part, String fileName, HashMap<String, Object> obj)
throws IOException {
if (part != null) {
InputStream inputStream = part.getInputStream();
try {
db.saveAttachment(inputStream, URLEncoder.encode(fileName,"UTF-8"), part.getContentType(), id, (String) obj.get("_rev"));
} finally {
inputStream.close();
}
}
}
示例10: initializeSampleData
import com.cloudant.client.api.Database; //导入依赖的package包/类
private List<HashMap> initializeSampleData(Database db) throws Exception {
long id = System.currentTimeMillis();
String name = "Sample category";
String value = "List of sample files";
// create a new document
System.out.println("Creating new document with id : " + id);
Map<String, Object> data = new HashMap<String, Object>();
data.put("name", name);
data.put("_id", id + "");
data.put("value", value);
data.put("creation_date", new Date().toString());
db.save(data);
// attach the object
HashMap<String, Object> obj = db.find(HashMap.class, id + "");
// attachment#1
File file = new File("Sample.txt");
file.createNewFile();
PrintWriter writer = new PrintWriter(file);
writer.write("This is a sample file...");
writer.flush();
writer.close();
FileInputStream fileInputStream = new FileInputStream(file);
db.saveAttachment(fileInputStream, file.getName(), "text/plain", id + "", (String) obj.get("_rev"));
fileInputStream.close();
return db.getAllDocsRequestBuilder().includeDocs(true).build().getResponse().getDocsAs(HashMap.class);
}
示例11: getDB
import com.cloudant.client.api.Database; //导入依赖的package包/类
public Database getDB(){
return db;
}
示例12: hrsDb
import com.cloudant.client.api.Database; //导入依赖的package包/类
@Bean
public Database hrsDb(CloudantClient cloudant) {
return cloudant.database("hrs", true);
}
示例13: getChatDB
import com.cloudant.client.api.Database; //导入依赖的package包/类
public Database getChatDB() {
return chatDB;
}
示例14: getFeedbackDB
import com.cloudant.client.api.Database; //导入依赖的package包/类
public Database getFeedbackDB() {
return feedbackDB;
}
示例15: getExplorerDB
import com.cloudant.client.api.Database; //导入依赖的package包/类
public Database getExplorerDB() {
return explorerDB;
}