本文整理汇总了Java中com.couchbase.lite.DatabaseOptions类的典型用法代码示例。如果您正苦于以下问题:Java DatabaseOptions类的具体用法?Java DatabaseOptions怎么用?Java DatabaseOptions使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
DatabaseOptions类属于com.couchbase.lite包,在下文中一共展示了DatabaseOptions类的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getUserDatabase
import com.couchbase.lite.DatabaseOptions; //导入依赖的package包/类
private Database getUserDatabase(String name) {
try {
String dbName = "db" + StringUtil.MD5(name);
DatabaseOptions options = new DatabaseOptions();
options.setCreate(true);
options.setStorageType(STORAGE_TYPE);
options.setEncryptionKey(ENCRYPTION_ENABLED ? ENCRYPTION_KEY : null);
return getManager().openDatabase(dbName, options);
} catch (CouchbaseLiteException e) {
Log.e(TAG, "Cannot create database for name: " + name, e);
}
return null;
}
示例2: getAllDocumentIds
import com.couchbase.lite.DatabaseOptions; //导入依赖的package包/类
List<String> getAllDocumentIds(String databaseId) {
Timber.d("getAllDocumentIds: %s", databaseId);
ManagerOptions managerOptions = new ManagerOptions();
managerOptions.setReadOnly(true);
DatabaseOptions databaseOptions = new DatabaseOptions();
databaseOptions.setReadOnly(true);
com.couchbase.lite.Database database = null;
try {
// TODO: Create LiveQuery on this?
// TODO: Open manager/database and cache result - could be expensive operation
Manager manager = new Manager(new AndroidContext(mContext), managerOptions);
database = manager.openDatabase(databaseId, databaseOptions);
List<String> docIds = new ArrayList<>();
QueryEnumerator result = database.createAllDocumentsQuery().run();
while (result.hasNext()) {
QueryRow row = result.next();
docIds.add(row.getDocumentId());
}
return docIds;
} catch (Exception e) {
return Collections.emptyList();
} finally {
if (database != null) {
database.close();
}
}
}
示例3: getDocument
import com.couchbase.lite.DatabaseOptions; //导入依赖的package包/类
private Map<String, String> getDocument(String databaseId, String docId) {
Timber.d("getDocument: %s, %s", databaseId, docId);
DatabaseOptions databaseOptions = new DatabaseOptions();
databaseOptions.setReadOnly(true);
com.couchbase.lite.Database database = null;
try {
database = mManager.openDatabase(databaseId, databaseOptions);
Document doc = database.getExistingDocument(docId);
if (doc == null) {
return new TreeMap<>();
}
Map<String, String> returnedMap = new TreeMap<>();
for (Map.Entry<String, Object> entry : doc.getProperties().entrySet()) {
returnedMap.put(entry.getKey(), String.valueOf(entry.getValue()));
}
return returnedMap;
} catch (Exception e) {
Timber.e(e.toString());
return new TreeMap<>();
} finally {
if (database != null) {
database.close();
}
}
}
示例4: CouchbaseInstance
import com.couchbase.lite.DatabaseOptions; //导入依赖的package包/类
private CouchbaseInstance(Context context) throws CouchbaseLiteException, IOException {
mContext = context.getApplicationContext();
DatabaseOptions options = new DatabaseOptions();
options.setCreate(true);
options.setStorageType(Manager.FORESTDB_STORAGE);
Manager manager = new Manager(new AndroidContext(mContext), Manager.DEFAULT_OPTIONS);
mDatabase = manager.openDatabase(DB_SOLVES, options);
initApiClient();
}