This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Realm realm = Realm.getInstance(context).executeTransaction(new Realm.Transaction() { | |
@Override | |
public void execute(Realm realm) { | |
realm.copyToRealm(user); | |
} | |
}); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class Email extends RealmObject { | |
@PrimaryKey | |
private String address; | |
..... | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Realm realm = Realm.getInstance(context); | |
realm.beginTransaction(); | |
realm.copyToRealmOrUpdate(user); | |
realm.commitTransaction(); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class User extends RealmObject { | |
private String userName; | |
private String imageUrl; | |
private String status; | |
private RealmList<Email> emailList; | |
//getters and setter | |
..... | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class User extends RealmObject { | |
@PrimaryKey | |
private int userId; | |
private String description; | |
private String sureName; | |
private String name; | |
private RealmList<Address> addresses; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
User user = new User(); | |
user.setName("Justin"); | |
user.setSurname("Timberlake"); | |
Realm realm = Realm.getInstance(getActivity()); | |
realm.beginTransaction(); | |
realm.copyToRealm(user); | |
realm.commitTransaction(); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class User extends RealmObject { | |
@PrimaryKey | |
private int userId; | |
private String description; | |
private String sureName; | |
private String name; | |
public String getDescription() { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
String documentId = userDocument.getId(); | |
Document document = database.getDocument(documentId); | |
List<String> emails = (List<String>) document.getProperty("emails"); | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Document userDocument = database.createDocument(); | |
List<String> emails = new ArrayList<String>() {{ | |
add("[email protected]"); | |
add("[email protected]"); | |
} | |
}; | |
Map<String, Object> userMapper = new HashMap<>(); | |
userMapper.put("name", "Justin"); | |
userMapper.put("sureName", "Timberlake"); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public void initDB(Context context) { | |
try { | |
Manager manager = new Manager(new AndroidContext(context), Manager.DEFAULT_OPTIONS); | |
if (!Manager.isValidDatabaseName(DBName)) { | |
throw new RuntimeException("Bad database name"); | |
} | |
database = manager.getDatabase(DBName); | |
} catch (IOException e) { |