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


Java StdCouchDbConnector.createDatabaseIfNotExists方法代码示例

本文整理汇总了Java中org.ektorp.impl.StdCouchDbConnector.createDatabaseIfNotExists方法的典型用法代码示例。如果您正苦于以下问题:Java StdCouchDbConnector.createDatabaseIfNotExists方法的具体用法?Java StdCouchDbConnector.createDatabaseIfNotExists怎么用?Java StdCouchDbConnector.createDatabaseIfNotExists使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.ektorp.impl.StdCouchDbConnector的用法示例。


在下文中一共展示了StdCouchDbConnector.createDatabaseIfNotExists方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: doTest

import org.ektorp.impl.StdCouchDbConnector; //导入方法依赖的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());
}
 
开发者ID:Apereo-Learning-Analytics-Initiative,项目名称:Larissa,代码行数:12,代码来源:ITCouchDB.java

示例2: initialize

import org.ektorp.impl.StdCouchDbConnector; //导入方法依赖的package包/类
/**
 * Initialize the data store by reading the credentials, setting the client's properties up and
 * reading the mapping file. Initialize is called when then the call to
 * {@link org.apache.gora.store.DataStoreFactory#createDataStore} is made.
 *
 * @param keyClass
 * @param persistentClass
 * @param properties
 */
@Override
public void initialize(Class<K> keyClass, Class<T> persistentClass, Properties properties) {
  LOG.debug("Initializing CouchDB store");
  super.initialize(keyClass, persistentClass, properties);

  final CouchDBParameters params = CouchDBParameters.load(properties);

  try {
    final String mappingFile = DataStoreFactory.getMappingFile(properties, this, DEFAULT_MAPPING_FILE);
    final HttpClient httpClient = new StdHttpClient.Builder()
        .url("http://" + params.getServer() + ":" + params.getPort())
        .build();

    dbInstance = new StdCouchDbInstance(httpClient);

    final CouchDBMappingBuilder<K, T> builder = new CouchDBMappingBuilder<>(this);
    LOG.debug("Initializing CouchDB store with mapping {}.", new Object[] { mappingFile });
    builder.readMapping(mappingFile);
    mapping = builder.build();

    final ObjectMapperFactory myObjectMapperFactory = new CouchDBObjectMapperFactory();
    myObjectMapperFactory.createObjectMapper().addMixInAnnotations(persistentClass, CouchDbDocument.class);

    db = new StdCouchDbConnector(mapping.getDatabaseName(), dbInstance, myObjectMapperFactory);
    db.createDatabaseIfNotExists();

  } catch (IOException e) {
    LOG.error("Error while initializing CouchDB store: {}", new Object[] { e.getMessage() });
    throw new RuntimeException(e);
  }
}
 
开发者ID:apache,项目名称:gora,代码行数:41,代码来源:CouchDBStore.java

示例3: setupCouchDb

import org.ektorp.impl.StdCouchDbConnector; //导入方法依赖的package包/类
/**
 * This function setups up the CouchDB connection, creates the database and associated views.
 * @param server The server to connect to.
 * @param dbName The name of the database.
 * @return The connection.
 * @throws MalformedURLException If the server string cannot be understood.
 */
public static CouchDbConnector setupCouchDb(String server, String dbName) throws MalformedURLException {
	HttpClient httpClient = new StdHttpClient.Builder().url(server).build();

	CouchDbInstance dbInstance = new StdCouchDbInstance(httpClient);
	StdCouchDbConnector db = new StdCouchDbConnector(dbName, dbInstance);
	db.createDatabaseIfNotExists();
	LOG.info("Connected to CouchDB. Relax.");

	try {
		db.getDesignDocInfo("pepperscore");
	} catch (DocumentNotFoundException e) {
		Map<String, Object> doc = new HashMap<String, Object>();
		doc.put("language", "javascript");

		Map<String, Object> views = new HashMap<String, Object>();
		doc.put("views", views);

		HashMap<String, String> bysessionidView = new HashMap<String, String>();
		bysessionidView.put("map",
				"function(doc) {\n" +
						"  emit(doc.sessionId, doc);\n" +
						"}");
		views.put("bysessionid", bysessionidView);

		HashMap<String, String> inprogressroundView = new HashMap<String, String>();
		inprogressroundView.put("map",
				"function(doc) {\n" +
						"  if (doc.round) {\n" +
						"    if ((doc.round.start) && (!doc.round.end)) {\n" +
						"      emit(doc.sessionId, doc.round.start);\n" +
						"    }\n" +
						"  }" +
						"\n}");
		views.put("inprogressround", inprogressroundView);

		db.create("_design/pepperscore", doc);
	}

	return db;
}
 
开发者ID:SiphonSquirrel,项目名称:jepperscore,代码行数:48,代码来源:CouchDbUtils.java


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