本文整理汇总了Java中com.couchbase.lite.CouchbaseLiteException类的典型用法代码示例。如果您正苦于以下问题:Java CouchbaseLiteException类的具体用法?Java CouchbaseLiteException怎么用?Java CouchbaseLiteException使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
CouchbaseLiteException类属于com.couchbase.lite包,在下文中一共展示了CouchbaseLiteException类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: create
import com.couchbase.lite.CouchbaseLiteException; //导入依赖的package包/类
private ListEntity create(String title) throws CouchbaseLiteException {
String currentTimeString = mDateFormatter.format(new Date());
ListEntity mList = ListEntity.create().
setCreatedAt(currentTimeString).
setMembers(new ArrayList<String>()).setTitle(title);
mList.setSub(SubEntity.create().setTest("test"));
ArrayList<SubEntity> sub = new ArrayList<>();
sub.add(SubEntity.create().setTest("rs"));
mList.setListSub(sub);
Application application = (Application) getApplication();
String userId = application.getCurrentUserId();
if (userId != null)
mList.setOwner("p:" + userId);
mList.save();
return mList;
}
示例2: loginAsFacebookUser
import com.couchbase.lite.CouchbaseLiteException; //导入依赖的package包/类
public void loginAsFacebookUser(Activity activity, String token, String userId, String name) {
setCurrentUserId(userId);
setDatabase(getUserDatabase(userId));
String profileDocID = "p:" + userId;
Document profile = mDatabase.getExistingDocument(profileDocID);
if (profile == null) {
try {
Map<String, Object> properties = new HashMap<String, Object>();
properties.put("type", "profile");
properties.put("user_id", userId);
properties.put("name", name);
profile = mDatabase.getDocument(profileDocID);
profile.putProperties(properties);
// Migrate guest data to user:
UserProfile.migrateGuestData(getUserDatabase(GUEST_DATABASE_NAME), profile);
} catch (CouchbaseLiteException e) {
Log.e(TAG, "Cannot create a new user profile", e);
}
}
startReplication(AuthenticatorFactory.createFacebookAuthenticator(token));
login(activity);
}
示例3: addMember
import com.couchbase.lite.CouchbaseLiteException; //导入依赖的package包/类
private void addMember(Document user) {
Map<String, Object> properties = new HashMap<>();
properties.putAll(mList.getProperties());
List<String> members = (List<String>) properties.get("members");
if (members == null) {
members = new ArrayList<String>();
properties.put("members", members);
}
members.add(user.getId());
try {
mList.putProperties(properties);
} catch (CouchbaseLiteException e) {
Log.e(Application.TAG, "Cannot add member to the list", e);
}
}
示例4: createTask
import com.couchbase.lite.CouchbaseLiteException; //导入依赖的package包/类
private void createTask(String title, Bitmap image, String listId) {
String currentTimeString = mDateFormatter.format(new Date());
TaskEntity task = TaskEntity.create()
.setType("task")
.setCreatedAt(currentTimeString)
.setTitle(title)
.setChecked(Boolean.FALSE)
.setListId(listId);
if (image != null) {
ByteArrayOutputStream out = new ByteArrayOutputStream();
image.compress(Bitmap.CompressFormat.JPEG, 50, out);
ByteArrayInputStream in = new ByteArrayInputStream(out.toByteArray());
task.setImage(in);
}
try {
task.save();
} catch (CouchbaseLiteException e) {
Log.e(Application.TAG, "Cannot create new task", e);
}
}
示例5: attachImage
import com.couchbase.lite.CouchbaseLiteException; //导入依赖的package包/类
private void attachImage(TaskEntity task, Bitmap image) {
if (task == null || image == null) return;
ByteArrayOutputStream out = new ByteArrayOutputStream();
image.compress(Bitmap.CompressFormat.JPEG, 50, out);
ByteArrayInputStream in = new ByteArrayInputStream(out.toByteArray());
task.setImage(in);
try {
task.save();
} catch (CouchbaseLiteException e) {
Log.e(Application.TAG, "Cannot attach image", e);
}
}
示例6: searchAllPostsOrderByDate
import com.couchbase.lite.CouchbaseLiteException; //导入依赖的package包/类
@Override
protected List<Post> searchAllPostsOrderByDate() {
List<Post> postList = new ArrayList<>();
try {
Query query = couchDbPost.createAllDocumentsQuery();
query.setAllDocsMode(Query.AllDocsMode.ONLY_CONFLICTS);
QueryEnumerator result = query.run();
for (Iterator<QueryRow> it = result; it.hasNext();) {
QueryRow row = it.next();
postList.add(fillPost(row.getDocument(), row.getDocumentId()));
}
} catch (CouchbaseLiteException e) {
e.printStackTrace();
}
Collections.sort(postList, new PostComparator());
return postList;
}
示例7: loadInBackground
import com.couchbase.lite.CouchbaseLiteException; //导入依赖的package包/类
@Override
public List<QueryRow> loadInBackground() {
try {
List<QueryRow> ret = new ArrayList<QueryRow>();
QueryEnumerator enumerator = query.run();
if (enumerator != null) {
while (enumerator.hasNext()) {
QueryRow row = enumerator.next();
ret.add(row);
}
}
return ret;
} catch (CouchbaseLiteException e) {
throw new RuntimeException(e);
}
}
示例8: getContactDocumentByEmail
import com.couchbase.lite.CouchbaseLiteException; //导入依赖的package包/类
public Document getContactDocumentByEmail(String email) {
Query query = contactView.createQuery();
query.setStartKey(email);
query.setEndKey(email);
QueryEnumerator enumerator;
try {
enumerator = query.run();
} catch (CouchbaseLiteException e) {
throw new RuntimeException(e);
}
Document ret = null;
if (enumerator.hasNext()) {
QueryRow row = enumerator.next();
ret = row.getDocument();
}
return ret;
}
示例9: getMessagesByGame
import com.couchbase.lite.CouchbaseLiteException; //导入依赖的package包/类
public List<Document> getMessagesByGame(String modelId) {
Query query = messageByGameView.createQuery();
query.setStartKey(modelId);
query.setEndKey(modelId);
QueryEnumerator enumerator;
try {
enumerator = query.run();
} catch (CouchbaseLiteException e) {
throw new RuntimeException(e);
}
List<Document> ret = new ArrayList<>();
while (enumerator.hasNext()) {
QueryRow row = enumerator.next();
ret.add(row.getDocument());
}
Collections.sort(ret, new Comparator<Document>() {
@Override
public int compare(Document left, Document right) {
return ((String) left.getProperty("id")).compareTo((String) right.getProperty("id"));
}
});
return ret;
}
示例10: getGameDocumentByModelId
import com.couchbase.lite.CouchbaseLiteException; //导入依赖的package包/类
public Document getGameDocumentByModelId(String id) {
Query query = gameView.createQuery();
query.setStartKey(id);
query.setEndKey(id);
query.setEndKey(id);
QueryEnumerator enumerator;
try {
enumerator = query.run();
} catch (CouchbaseLiteException e) {
throw new RuntimeException(e);
}
Document ret = null;
if (enumerator.hasNext()) {
QueryRow row = enumerator.next();
ret = row.getDocument();
}
return ret;
}
示例11: getGamesByContactQuery
import com.couchbase.lite.CouchbaseLiteException; //导入依赖的package包/类
public Query getGamesByContactQuery(String email) {
final Query gameQueryByContact = gameIdsByContactView.createQuery();
gameQueryByContact.setStartKey(email);
gameQueryByContact.setEndKey(email);
gameQueryByContact.setDescending(true);
gameQueryByContact.setGroupLevel(1);
Query gameQuery = gameView.createQuery();
try {
List<Object> keys = Collections.emptyList();
if (gameQueryByContact != null) {
QueryEnumerator run = gameQueryByContact.run();
if (run != null) {
QueryRow next = run.next();
if (next != null) {
keys = (List<Object>) next.getValue();
}
}
}
gameQuery.setKeys(keys);
} catch (CouchbaseLiteException e) {
throw new RuntimeException(e);
}
return gameQuery;
}
示例12: addObjects
import com.couchbase.lite.CouchbaseLiteException; //导入依赖的package包/类
private void addObjects() {
for (int row = 0; row < numberOfObjects; row++) {
final int testRow = row;
database.runInTransaction(new TransactionalTask() {
@Override
public boolean run() {
Document document = database.createDocument();
Map<String, Object> docContent = new HashMap<String, Object>();
docContent.put("id", testRow);
docContent.put("name", dataGenerator.getEmployeeName(testRow));
docContent.put("age", dataGenerator.getEmployeeAge(testRow));
docContent.put("hired", dataGenerator.getHiredBool(testRow));
try {
document.putProperties(docContent);
} catch (CouchbaseLiteException e) {
throw new RuntimeException("Cannot add object to CouchBase Lite.");
}
return true;
}
});
}
}
示例13: saveContactInfo
import com.couchbase.lite.CouchbaseLiteException; //导入依赖的package包/类
private boolean saveContactInfo(String firstName, String lastName, String phoneNumber) {
Document document = mDatabase.getDocument(CONTACT_INFO_DOCUMENT_ID);
Map<String, Object> properties = new HashMap();
properties.put(FIELD_FIRST_NAME, firstName);
properties.put(FIELD_LAST_NAME, lastName);
properties.put(FIELD_PHONE_NUMBER, phoneNumber);
try {
document.putProperties(properties);
return true;
} catch (CouchbaseLiteException e) {
Log.e(TAG, "Cannot save document", e);
return false;
}
}
示例14: updateContactInfo
import com.couchbase.lite.CouchbaseLiteException; //导入依赖的package包/类
private boolean updateContactInfo(String firstName, String lastName, String phoneNumber) {
Document document = mDatabase.getDocument(CONTACT_INFO_DOCUMENT_ID);
Map<String, Object> properties = new HashMap();
properties.putAll(document.getProperties());
properties.put(FIELD_FIRST_NAME, firstName);
properties.put(FIELD_LAST_NAME, lastName);
properties.put(FIELD_PHONE_NUMBER, phoneNumber);
try {
document.putProperties(properties);
return true;
} catch (CouchbaseLiteException e) {
Log.e(TAG, "Cannot save document", e);
return false;
}
}
示例15: saveAvatar
import com.couchbase.lite.CouchbaseLiteException; //导入依赖的package包/类
private void saveAvatar() {
Document doc = mDatabase.getDocument(CONTACT_INFO_DOCUMENT_ID);
ByteArrayOutputStream bos = new ByteArrayOutputStream();
Bitmap bitmap = ((BitmapDrawable) mImgAvatar.getDrawable()).getBitmap();
bitmap.compress(Bitmap.CompressFormat.PNG, 0 /*ignored for PNG*/, bos);
byte[] bitmapdata = bos.toByteArray();
ByteArrayInputStream bs = new ByteArrayInputStream(bitmapdata);
try {
UnsavedRevision newRev = doc.getCurrentRevision().createRevision();
newRev.setAttachment("avatar.jpg", "image/jpeg", bs);
newRev.save();
} catch (CouchbaseLiteException e) {
Log.e(TAG, "Cannot save attachment", e);
}
}