本文整理汇总了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());
}
示例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);
}
}
示例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;
}