本文整理汇总了Java中com.couchbase.lite.Document类的典型用法代码示例。如果您正苦于以下问题:Java Document类的具体用法?Java Document怎么用?Java Document使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
Document类属于com.couchbase.lite包,在下文中一共展示了Document类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: loginAsFacebookUser
import com.couchbase.lite.Document; //导入依赖的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);
}
示例2: addMember
import com.couchbase.lite.Document; //导入依赖的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);
}
}
示例3: onItemSelected
import com.couchbase.lite.Document; //导入依赖的package包/类
@Override
public void onItemSelected(String id) {
this.id = id;
Document document = dataService.loadDocument(id);
if (isWaitingForMe(document)) {
Bundle args = new Bundle();
args.putString("id", document.getId());
JoinGameDialogFragment fragment = new JoinGameDialogFragment();
fragment.setArguments(args);
fragment.show(getSupportFragmentManager(), "dialog");
} else {
super.onItemSelected(id);
}
// if (itemListActivity != null) {
// itemListActivity.onItemSelected(list.get(position).getDocumentId());
// }
}
示例4: registerBroadcastReceiver
import com.couchbase.lite.Document; //导入依赖的package包/类
private void registerBroadcastReceiver() {
gameBroadcastReceiver = new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
Bundle extras = intent.getExtras();
String destModelId = extras.getString("modelId");
if (modelId != null && modelId.equals(destModelId)) {
//gotta handle this message
Document messageDocument = dataService.loadDocument(extras.getString("id"));
ObjectMapper mapper = JSONUtils.createObjectMapper();
final GameMessage message = mapper.convertValue(messageDocument.getProperties(), GameMessage.class);
intent.putExtra(Intent.EXTRA_DATA_REMOVED, true);
getActivity().runOnUiThread(new Runnable() {
@Override
public void run() {
controllerFragment.processMessage(message);
}
});
}
}
};
LocalBroadcastManager.getInstance(getActivity()).registerReceiver(
gameBroadcastReceiver,
new IntentFilter(GameBoardApplication.INTENT_ACTION_GAME_MSG));
}
示例5: onItemSelected
import com.couchbase.lite.Document; //导入依赖的package包/类
@Override
public void onItemSelected(String id) {
Document document = dataService.getDocument(id);
Boolean accepted = (Boolean) document.getProperty("accepted");
Boolean reverseAccepted = (Boolean) document.getProperty("reverseAccepted");
accepted = accepted != null ? accepted : false;
reverseAccepted = reverseAccepted != null ? reverseAccepted : false;
if (accepted && !reverseAccepted) {
SnackbarManager.show(Snackbar.with(this).position(Snackbar.SnackbarPosition.TOP).text("This buddy did not accept you yet!").color(Color.YELLOW).textColor(Color.BLACK));
} else if (!accepted && reverseAccepted) {
this.id = id;
showDialog();
} else if (reverseAccepted && accepted) {
Intent intent = new Intent(ContactListActivity.this, GameListActivity.class);
intent.putExtra(Intent.EXTRA_EMAIL, (String) document.getProperties().get("email"));
startActivity(intent);
}
}
示例6: mapItemView
import com.couchbase.lite.Document; //导入依赖的package包/类
@Override
protected void mapItemView(final Document document, final View view) {
// if (document != null) {
// final TextView localView = (TextView) view.findViewById(R.id.item_detail);
// localView.setText("...");
// getActivity().runOnUiThread(new Runnable() {
// @Override
// public void run() {
// GameBoardApplication app = ((GameBoardApplication) getActivity().getApplication());
//// int count = app.getCountGames(document.getProperties().get("email").toString());
//// localView.setText(document.getProperties().get("login").toString() + " " + count);
// localView.setText(document.getProperties().get("login").toString());
// }
// });
// }
}
示例7: getContactDocumentByEmail
import com.couchbase.lite.Document; //导入依赖的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;
}
示例8: getMessagesByGame
import com.couchbase.lite.Document; //导入依赖的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;
}
示例9: getGameDocumentByModelId
import com.couchbase.lite.Document; //导入依赖的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;
}
示例10: fromDocument
import com.couchbase.lite.Document; //导入依赖的package包/类
public <T extends CBLDocument> T fromDocument(@Nullable ReadOnlyDictionary dictionary, @NonNull Class<T> typeOfT) throws CBLMapperClassException {
if (dictionary == null) {
return null;
}
T object = null;
object = decode(dictionary.toMap(), typeOfT, true, null);
// Attach ID & Document to object
if (object != null && dictionary instanceof Document) {
Document document = (Document) dictionary;
object.setDocument(document);
setCBLDocumentID(object, document.getId());
}
return object;
}
示例11: testUnserializedInheritedClass
import com.couchbase.lite.Document; //导入依赖的package包/类
@Test
public void testUnserializedInheritedClass() throws Exception {
final String id = "testID";
final String name = "Julie";
final int age = 27;
Document document = new Document(id);
document.setString(ChildClass.FIELD_NAME, name);
document.setInt(ChildClass.FIELD_AGE, age);
CBLMapper documentMapper = new CBLMapper();
ChildClass simpleModelWithID = documentMapper.fromDocument(document, ChildClass.class);
assertNotNull(simpleModelWithID);
assertEquals(id, simpleModelWithID.getID());
assertEquals(name, simpleModelWithID.getName());
assertEquals(age, simpleModelWithID.getAge());
}
示例12: testEnumList
import com.couchbase.lite.Document; //导入依赖的package包/类
@Test
public void testEnumList() throws Exception {
Box box = new Box();
box.addSpecy(Species.Cat);
box.addSpecy(Species.Dog);
CBLMapper mapper = new CBLMapper();
Document doc = mapper.toDocument(box);
Box unserializedBox = mapper.fromDocument(doc, Box.class);
assertEquals(2, unserializedBox.getSpecies().size());
assertEquals(Species.Cat, unserializedBox.getSpecies().get(0));
assertEquals(Species.Dog, unserializedBox.getSpecies().get(1));
}
示例13: testSerializeForeignDoc
import com.couchbase.lite.Document; //导入依赖的package包/类
@Test
public void testSerializeForeignDoc() throws Exception {
Song firstSong = new Song("aaa", "First song");
Song secondSong = new Song("bbb", "Second song");
List<Song> songList = new ArrayList<>();
songList.add(firstSong);
songList.add(secondSong);
Album album = new Album("xxx", songList);
CBLMapper mapper = new CBLMapper();
Document doc = mapper.toDocument(album);
assertNotNull(doc.getArray(Album.FIELD_SONG_LIST));
assertEquals("aaa", doc.getArray(Album.FIELD_SONG_LIST).getString(0));
assertEquals("bbb", doc.getArray(Album.FIELD_SONG_LIST).getString(1));
album = mapper.fromDocument(doc, Album.class);
assertNotNull(album);
assertEquals("xxx", album.ID);
}
示例14: testUnserializeForeignDoc
import com.couchbase.lite.Document; //导入依赖的package包/类
@Test
public void testUnserializeForeignDoc() throws Exception {
List<Object> songIDs = new ArrayList<>();
songIDs.add("aaa");
songIDs.add("bbb");
Document doc = new Document();
doc.setArray(Album.FIELD_SONG_LIST, new Array(songIDs));
CBLMapper mapper = new CBLMapper();
Album album = mapper.fromDocument(doc, Album.class);
assertNotNull(album.SongList);
assertEquals("aaa", album.SongList.get(0).getDocumentID());
assertEquals("bbb", album.SongList.get(1).getDocumentID());
}
示例15: initializeCouchbase
import com.couchbase.lite.Document; //导入依赖的package包/类
private void initializeCouchbase(Context context) {
final Map<String, Object> s = new HashMap<>();
s.put("key1", "value1");
s.put("key2", "value2");
s.put("key3", "value3");
s.put("key4", "value4");
s.put("key5", "value5");
s.put("key6", "value6");
s.put("key7", "value7");
s.put("key8", "value8");
s.put("key9", "value9");
s.put("key10", "value10");
try {
mManager = new Manager(new AndroidContext(context), Manager.DEFAULT_OPTIONS);
mDatabase = mManager.getDatabase("stetho-couchbase-sample");
Document doc = mDatabase.getDocument("id:123456");
doc.putProperties(s);
doc = mDatabase.getDocument("p::abcdefg");
doc.putProperties(s);
doc = mDatabase.getDocument("p::123abc");
doc.putProperties(s);
} catch (Exception ignored) {
}
}