当前位置: 首页>>代码示例>>Java>>正文


Java Database类代码示例

本文整理汇总了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());
}
 
开发者ID:IBM-Cloud,项目名称:java-cloudant,代码行数:27,代码来源:AttachServlet.java

示例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();
}
 
开发者ID:IBM-Cloud,项目名称:java-cloudant,代码行数:20,代码来源:ResourceServlet.java

示例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();
	}
}
 
开发者ID:IBM-Cloud,项目名称:java-cloudant,代码行数:25,代码来源:ResourceServlet.java

示例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)
        );
    }
}
 
开发者ID:dbpedia,项目名称:chatbot,代码行数:12,代码来源:RequestRouter.java

示例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())
        );
    }
}
 
开发者ID:dbpedia,项目名称:chatbot,代码行数:13,代码来源:RequestRouter.java

示例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);
}
 
开发者ID:cloudant-labs,项目名称:cloudant-spring,代码行数:14,代码来源:AutoConfigurationTest.java

示例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;
}
 
开发者ID:IBM-Cloud,项目名称:java-cloudant,代码行数:15,代码来源:CloudantClientMgr.java

示例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();
	}
}
 
开发者ID:IBM-Cloud,项目名称:java-cloudant,代码行数:29,代码来源:ResourceServlet.java

示例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();
		}
	}
}
 
开发者ID:IBM-Cloud,项目名称:java-cloudant,代码行数:12,代码来源:ResourceServlet.java

示例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);

	}
 
开发者ID:IBM-Cloud,项目名称:java-cloudant,代码行数:33,代码来源:ResourceServlet.java

示例11: getDB

import com.cloudant.client.api.Database; //导入依赖的package包/类
public Database getDB(){
	return db;
}
 
开发者ID:IBM,项目名称:liberty-outage-reporter,代码行数:4,代码来源:CloudantLocationStore.java

示例12: hrsDb

import com.cloudant.client.api.Database; //导入依赖的package包/类
@Bean
public Database hrsDb(CloudantClient cloudant) {
	return cloudant.database("hrs", true);
}
 
开发者ID:PacktPublishing,项目名称:Spring-5.0-Cookbook,代码行数:5,代码来源:CouchDbConfig.java

示例13: getChatDB

import com.cloudant.client.api.Database; //导入依赖的package包/类
public Database getChatDB() {
    return chatDB;
}
 
开发者ID:dbpedia,项目名称:chatbot,代码行数:4,代码来源:Application.java

示例14: getFeedbackDB

import com.cloudant.client.api.Database; //导入依赖的package包/类
public Database getFeedbackDB() {
    return feedbackDB;
}
 
开发者ID:dbpedia,项目名称:chatbot,代码行数:4,代码来源:Application.java

示例15: getExplorerDB

import com.cloudant.client.api.Database; //导入依赖的package包/类
public Database getExplorerDB() {
    return explorerDB;
}
 
开发者ID:dbpedia,项目名称:chatbot,代码行数:4,代码来源:Application.java


注:本文中的com.cloudant.client.api.Database类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。