本文整理汇总了Java中com.couchbase.lite.Document.putProperties方法的典型用法代码示例。如果您正苦于以下问题:Java Document.putProperties方法的具体用法?Java Document.putProperties怎么用?Java Document.putProperties使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.couchbase.lite.Document
的用法示例。
在下文中一共展示了Document.putProperties方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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: 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) {
}
}
示例3: saveContactInfo
import com.couchbase.lite.Document; //导入方法依赖的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;
}
}
示例4: updateContactInfo
import com.couchbase.lite.Document; //导入方法依赖的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;
}
}
示例5: saveContactInfo
import com.couchbase.lite.Document; //导入方法依赖的package包/类
private boolean saveContactInfo(String firstName, String lastName, String phoneNumber) {
Document document = mDatabase.createDocument();
Map<String, Object> properties = new HashMap();
properties.put(FirstDemoActivity.FIELD_FIRST_NAME, firstName);
properties.put(FirstDemoActivity.FIELD_LAST_NAME, lastName);
properties.put(FirstDemoActivity.FIELD_PHONE_NUMBER, phoneNumber);
try {
document.putProperties(properties);
return true;
} catch (CouchbaseLiteException e) {
e.printStackTrace();
return false;
}
}
示例6: updateData
import com.couchbase.lite.Document; //导入方法依赖的package包/类
@Override
public void updateData() {
openDb();
Iterator it = cachedData.iterator();
while(it.hasNext()) {
DbTestRecordModel recordModel = (DbTestRecordModel)it.next();
Document record = database.getDocument(recordModel.getNewId());
Map<String, Object> properties = new HashMap<>();
properties.putAll(record.getProperties());
properties.put("name", "na");
properties.put("age", 0);
properties.put("address", "na");
try {
record.putProperties(properties);
} catch (CouchbaseLiteException e) {
e.printStackTrace();
}
}
closeDb();
}
示例7: createListItem
import com.couchbase.lite.Document; //导入方法依赖的package包/类
private Document createListItem(String text) throws Exception {
SimpleDateFormat dateFormatter = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS'Z'");
UUID uuid = UUID.randomUUID();
Calendar calendar = GregorianCalendar.getInstance();
long currentTime = calendar.getTimeInMillis();
String currentTimeString = dateFormatter.format(calendar.getTime());
String id = currentTime + "-" + uuid.toString();
// Step 7 - Create document from text box's field entry. code replaces this
Document document = database.getDocument(id); // creates a document with the given id
Map<String, Object> properties = new HashMap<String, Object>();
properties.put("_id", id);
properties.put("text", text);
properties.put("check", Boolean.FALSE);
properties.put("created_at", currentTimeString);
document.putProperties(properties);
return document;
}
示例8: onItemClick
import com.couchbase.lite.Document; //导入方法依赖的package包/类
/**
* Handle click on item in list
*/
public void onItemClick(AdapterView<?> adapterView, View view, int position, long id) {
// Step 10 code goes here
// This code handles checkbox touches. Couchbase Lite documents are like versioned-maps.
// To change a Document, add a new Revision.
QueryRow row = (QueryRow) adapterView.getItemAtPosition(position);
Document document = row.getDocument();
Map<String, Object> newProperties = new HashMap<String, Object>(document.getProperties());
boolean checked = ((Boolean) newProperties.get("check")).booleanValue();
newProperties.put("check", !checked);
try {
document.putProperties(newProperties);
kitchenSyncArrayAdapter.notifyDataSetChanged();
} catch (Exception e) {
Toast.makeText(getApplicationContext(), "Error updating database, see logs for details", Toast.LENGTH_LONG).show();
Log.e(TAG, "Error updating database", e);
}
}
示例9: insertData
import com.couchbase.lite.Document; //导入方法依赖的package包/类
private void insertData(Database database, String documentName, String key, Object object) {
try {
Map<String, Object> docContent = new HashMap<>();
docContent.put(documentName+key, object);
Document document = new Document(database, documentName+key);
document.putProperties(docContent);
} catch (CouchbaseLiteException e) {
e.printStackTrace();
}
}
示例10: insert
import com.couchbase.lite.Document; //导入方法依赖的package包/类
@Override
public Map<String, Object> insert(Map<String, Object> map) throws PersistenceException {
try {
// Create a new document
Document doc = database.createDocument();
doc.putProperties(map);
return doc.getProperties();
} catch (Exception e) {
throw new PersistenceException("Ouch. couldn't store that document.", e);
}
}
开发者ID:benwilcock,项目名称:android-couchbase-dagger-robolectric,代码行数:13,代码来源:CouchbasePersistenceAdapter.java
示例11: insertData
import com.couchbase.lite.Document; //导入方法依赖的package包/类
@Override
public void insertData(List<DbTestRecordModel> modelList) {
openDb();
String KEY_HEADER = "couchHeader";
Iterator it = modelList.iterator();
int count = 0;
while(it.hasNext()) {
Document document = database.createDocument();
Map<String,Object> record = new HashMap<>();
String KEY = KEY_HEADER + count;
count++;
DbTestRecordModel recordModel = (DbTestRecordModel)it.next();
record.put("name",recordModel.getName());
record.put("address",recordModel.getAddress());
record.put("age",recordModel.getAge());
record.put("stringId",KEY);
try {
document.putProperties(record);
} catch (CouchbaseLiteException e) {
e.printStackTrace();
}
}
closeDb();
}
示例12: indexedStringEntityQueriesRun
import com.couchbase.lite.Document; //导入方法依赖的package包/类
private void indexedStringEntityQueriesRun(View indexedStringView, int count)
throws CouchbaseLiteException {
// create entities
String[] fixedRandomStrings = StringGenerator.createFixedRandomStrings(count);
database.beginTransaction();
for (int i = 0; i < count; i++) {
Document entity = database.getDocument(String.valueOf(i));
Map<String, Object> properties = new HashMap<>();
properties.put("indexedString", fixedRandomStrings[i]);
entity.putProperties(properties);
}
database.endTransaction(true);
log("Built and inserted entities.");
// query for entities by indexed string at random
int[] randomIndices = StringGenerator.getFixedRandomIndices(getQueryCount(), count - 1);
// clear the document cache to force loading properties from the database
database.clearDocumentCache();
startClock();
for (int i = 0; i < getQueryCount(); i++) {
int nextIndex = randomIndices[i];
List<Object> keyToQuery = new ArrayList<>(1);
keyToQuery.add(fixedRandomStrings[nextIndex]);
Query query = indexedStringView.createQuery();
query.setKeys(keyToQuery);
QueryEnumerator result = query.run();
while (result.hasNext()) {
QueryRow row = result.next();
//noinspection unused
Document document = row.getDocument();
}
}
stopClock(Benchmark.Type.QUERY_INDEXED);
// delete all entities
deleteAll();
log("Deleted all entities.");
}
示例13: toDocument
import com.couchbase.lite.Document; //导入方法依赖的package包/类
public <T> Document toDocument(T object, Document document) throws CouchbaseLiteException {
Map<String, Object> properties = toProperties(object);
document.putProperties(properties);
return document;
}