本文整理汇总了Java中org.lightcouch.CouchDbClient类的典型用法代码示例。如果您正苦于以下问题:Java CouchDbClient类的具体用法?Java CouchDbClient怎么用?Java CouchDbClient使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
CouchDbClient类属于org.lightcouch包,在下文中一共展示了CouchDbClient类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: loadDocsFromView
import org.lightcouch.CouchDbClient; //导入依赖的package包/类
protected List<String> loadDocsFromView(String viewId, String path,
String sourcePath, String startKey, String endKey) {
View view;
List<String> allDocs = new Vector<String>();
CouchDbClient dbClient = connectionProvider.getDBClient(CouchDbClient.class, path);
try
{
view = dbClient.view(viewId);
allDocs = view.includeDocs(false).startKey(startKey).endKey(endKey).query();
} catch (NoDocumentException e)
{
e.printStackTrace();
System.out.println("create view, view id: " + viewId);
createView(path, sourcePath, viewId);
view = dbClient.view(viewId);
allDocs = view.includeDocs(false).startKey(startKey).endKey(endKey).query();
}
return allDocs;
}
示例2: loadViewIntoInputStream
import org.lightcouch.CouchDbClient; //导入依赖的package包/类
protected InputStream loadViewIntoInputStream(String viewId, String path, String sourcePath) {
View view;
CouchDbClient dbClient = connectionProvider.getDBClient(CouchDbClient.class, path);
InputStream inStream = null;
try
{
view = dbClient.view(viewId);
} catch (NoDocumentException e)
{
e.printStackTrace();
System.out.println("create view, view id: " + viewId);
createView(path, sourcePath, viewId);
view = dbClient.view(viewId);
}
inStream = view.includeDocs(false).queryForStream();
return inStream;
}
示例3: loadDocsFromView
import org.lightcouch.CouchDbClient; //导入依赖的package包/类
protected List<String> loadDocsFromView(String viewId, String path, String sourcePath) {
View view;
List<String> allDocs = new Vector<String>();
CouchDbClient dbClient = connectionProvider.getDBClient(CouchDbClient.class, path);
try
{
view = dbClient.view(viewId);
allDocs = view.includeDocs(true).query();
} catch (NoDocumentException e)
{
e.printStackTrace();
createView(path, sourcePath, viewId);
view = dbClient.view(viewId);
allDocs = view.includeDocs(true).query();
}
return allDocs;
}
示例4: getSocialToken
import org.lightcouch.CouchDbClient; //导入依赖的package包/类
/**
* Returns all OAuth tokens available in the database.
*
* @param req the http request
* @return all OAuth tokens available in the database
* @throws IOException if configuration cannot be accessed
*/
public static Map<String, String> getSocialToken(HttpServletRequest req) throws IOException {
//noinspection ConstantConditions
CouchDbClient dbClient = new CouchDbClient(CrawcialWebUtils.getCouchDbProperties(req.getServletContext(), Constants.CONFIGDB));
Map<String, String> values = new HashMap<>();
try {
JsonObject o = dbClient.find(JsonObject.class, Constants.SOCIAL_KEYS);
for (String k : Constants.keys) {
if (o.has(k)) {
values.put(k, o.get(k).getAsString());
}
}
} catch (NoDocumentException | NullPointerException e) {
System.out.println("No social config found");
}
return values;
}
示例5: init
import org.lightcouch.CouchDbClient; //导入依赖的package包/类
/**
* Configures the DatabaseService singleton, must be called before the crawling process starts.
*
* @param downloadMedia true, if media downloader enabled, false to disable media downloads
* @param dbProperties CouchDB properties for the Crawcial Twitter Database
* @param imgSize requested image size (thumb, small, medium, large)
* @param mediaHttps true if https should be used for media downloads
*/
public synchronized void init(boolean downloadMedia, CouchDbProperties dbProperties, String imgSize, boolean mediaHttps) {
DatabaseService.downloadMedia = downloadMedia;
this.mediaHttps = mediaHttps;
this.imgSize = imgSize;
warningCnt = 0;
this.dbProperties = dbProperties;
CouchDbClient dbClient = new CouchDbCloneClient(dbProperties);
DesignDocument designDoc = dbClient.design().getFromDesk("crawcial");
dbClient.design().synchronizeWithDb(designDoc);
dbClient.shutdown();
attachmentExecutors = new LinkedBlockingQueue<>();
if (downloadMedia) {
es = new ThreadPoolExecutor(Runtime.getRuntime().availableProcessors(),
Runtime.getRuntime().availableProcessors() * 2, 30, TimeUnit.SECONDS, attachmentExecutors);
}
writeExecutor = new WriteExecutor(jsonObjectVector, bufferLimit);
writeExecutorThread = new Thread(writeExecutor);
writeExecutorThread.setName("writer-executor-thread-0");
writeExecutorThread.start();
}
示例6: bench
import org.lightcouch.CouchDbClient; //导入依赖的package包/类
/**
* Inserts defined amount of fake Tweets.
*
* @param amount amount of fake Tweets
* @return duration in milliseconds
*/
long bench(int amount) {
// Open database connection and take a timestamp
CouchDbClient dbClient = new CouchDbCloneClient(properties);
long startTime = System.currentTimeMillis();
// Send generated JSON samples in bulk to database
dbClient.bulk(generateSampleData(amount), true);
// Take a second timestamp and perform some cleanup
long duration = System.currentTimeMillis() - startTime;
dbClient.context().ensureFullCommit();
dbClient.context().deleteDB(properties.getDbName(), "delete database");
dbClient.shutdown();
return duration;
}
示例7: performMapReduce
import org.lightcouch.CouchDbClient; //导入依赖的package包/类
private Stream<JsonObject> performMapReduce(String dbIP, String tableName, String mapRedDir)
{
MapReduceSources mrs = MapReduceSources.fromDir(mapRedDir);
CouchDbProperties properties = new CouchDbProperties(tableName.toLowerCase(), true, "http", dbIP, 5984, null, null);
CouchDbClient dbClient = new CouchDbClient(properties);
MapReduce mapRedObj = new MapReduce();
mapRedObj.setMap(mrs.getMapJSCode());
mapRedObj.setReduce(mrs.getReduceJSCode());
List<JsonObject> list = dbClient.view("_temp_view").tempView(mapRedObj).group(true)
.includeDocs(false).reduce(true).query(JsonObject.class);
// This step will apply some custom rules to the elements...
return adapter.adaptStream(list);
}
示例8: remove
import org.lightcouch.CouchDbClient; //导入依赖的package包/类
public boolean remove(E entity, String path, String revision) {
if (entity == null)
return false;
CouchDbClient dbClient = connectionProvider.getDBClient(
CouchDbClient.class, path);
Response resp = dbClient.remove(entity.get_id(), revision);
resp = dbClient.purge(path, entity.get_id(), new String[]{revision});
System.out.println("remove object revision: " + entity.get_id() + ", repsonse: " + resp);
return true;
}
示例9: list
import org.lightcouch.CouchDbClient; //导入依赖的package包/类
@Override
public List<E> list(String path, String staticQueryId,
String objectState) {
List<String> allDocs = connectionProvider.getDBClient(CouchDbClient.class, path).view(staticQueryId)
.includeDocs(true).query();
ArrayList<BTSDBBaseObject> results = new ArrayList<BTSDBBaseObject>();
Resource.Factory.Registry.INSTANCE.getExtensionToFactoryMap().put("json", new JsResourceFactoryImpl());
connectionProvider.getEmfResourceSet().getURIConverter().getURIHandlers().add(0, new CouchDBHandler());
for (String jo : allDocs)
{
String id = extractIdFromObjectString(jo);
logger.info(id);
if (!id.startsWith("_"))
{
URI uri = URI.createURI(getLocalDBURL() + path + id);
Resource resource = connectionProvider.getEmfResourceSet().getResource(uri, true);
fillResource(resource, jo);
E o = (E) resource.getContents().get(0);
if (o instanceof BTSDBBaseObject)
{
checkForConflicts((E) o, path);
}
results.add(o);
}
}
if (!results.isEmpty())
{
registerQueryIdWithInternalRegistry(BTSConstants.VIEW_ALL_DOCS, path);
}
return (List<E>) results;
}
示例10: listAvailableRevisions
import org.lightcouch.CouchDbClient; //导入依赖的package包/类
@Override
public List<DBRevision> listAvailableRevisions(K key, String path) {
CouchDbClient dbClient = connectionProvider.getDBClient(
CouchDbClient.class, path);
Params params = new Params();
params.addParam("revs_info", "true");
List<DBRevision> revisions = new Vector<DBRevision>();
JsonObject jsonObject = dbClient.find(JsonObject.class, (String) key,
params);
for (JsonElement rev : jsonObject.getAsJsonArray("_revs_info")) {
JsonElement rev_info = rev.getAsJsonObject().get("rev");
String docRev = rev_info.getAsString();
JsonElement rev_av = rev.getAsJsonObject().get("status");
String rev_av_str = rev_av.getAsString();
DBRevision r = new DBRevision();
r.setRevision(docRev);
if ("available".equals(rev_av_str))
{
r.setLocation(DBRevision.LOCAL);
}
else
{
r.setLocation(DBRevision.NOT_AVAILABLE);
}
revisions.add(r);
}
return revisions;
}
示例11: checkForConflicts
import org.lightcouch.CouchDbClient; //导入依赖的package包/类
@Override
public void checkForConflicts(E object, String path) {
if (object == null) return;
CouchDbClient dbClient = connectionProvider.getDBClient(
CouchDbClient.class, path != null ? path : object.getDBCollectionKey());
List<String> conflicts = dbClient.listConflictingRevs(path, object.get_id());
object.getConflictingRevs().addAll(conflicts);
}
示例12: createView
import org.lightcouch.CouchDbClient; //导入依赖的package包/类
public void createView(String path, String sourcePath, String viewName)
{
logger.info("path " + path + " viewName " + viewName);
CouchDbClient dbClient = connectionProvider.getDBClient(CouchDbClient.class, path);
// design documents stored on local .js files
DesignDocument designDoc = dbClient.design().getFromDesk(sourcePath);
// designDoc.new DesignDocument();//
dbClient.design().synchronizeWithDb(designDoc); // sync with db
// dbClient.syncDesignDocsWithDb(); // sync all
}
示例13: removeDBLease
import org.lightcouch.CouchDbClient; //导入依赖的package包/类
@Override
public boolean removeDBLease(DBLease lease, String path)
{
CouchDbClient dbClient = connectionProvider.getDBClient(
CouchDbClient.class, path);
Response resp = null;
if (lease.get_rev() != null)
{
try {
resp = dbClient.remove(lease.get_id(), lease.get_rev());
} catch (Exception e) {
DBLease entity2 = reload(lease.get_id(), path);
if (entity2 != null)
{
lease = entity2;
resp = dbClient.remove(lease.get_id(), lease.get_rev());
}
}
}
String rev = null;
if (resp != null)
{
rev = resp.getRev();
}
else
{
rev = lease.get_rev();
}
dbClient.purge(path, lease.get_id(), new String[]{rev});
return true;
}
示例14: removeDatabaseUser
import org.lightcouch.CouchDbClient; //导入依赖的package包/类
@Override
public boolean removeDatabaseUser(BTSUser user) {
CouchDbClient dbClient = connectionProvider.getDBClient(
CouchDbClient.class, _USERS);
try {
dbClient.remove(COUCHDB_USERS_PREFIX + user.getUserName());
return true;
} catch (Exception e) {
e.printStackTrace();
return false;
}
}
示例15: purgeDBConnectionPool
import org.lightcouch.CouchDbClient; //导入依赖的package包/类
@Override
public void purgeDBConnectionPool() {
Map<String, CouchDbClient> clients = (Map<String, CouchDbClient>) context.get(DaoConstants.DB_CLIENT_POOL_MAP);
if (clients == null)
{
return;
}
clients.clear();
}