io.realm.exceptions.RealmException Java Examples

The following examples show how to use io.realm.exceptions.RealmException. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: TokensRealmSource.java    From alpha-wallet-android with MIT License 4 votes vote down vote up
private void saveERC721Assets(Realm realm, Token token) throws RealmException
{
    ERC721Token e;
    if (token instanceof ERC721Token)
    {
        e = (ERC721Token) token;
    }
    else
    {
        return; //no storage here
    }

    String dbKey = databaseKey(token);

    deleteAssets(realm, dbKey);

    //now create the assets inside this
    for (Asset asset : e.getTokenAssets())
    {
        RealmERC721Asset realmAsset = realm.where(RealmERC721Asset.class)
                .equalTo("tokenIdAddr", RealmERC721Asset.tokenIdAddrName(asset.getTokenId(), dbKey))
                .findFirst();

        if (realmAsset == null)
        {
            realmAsset = realm.createObject(RealmERC721Asset.class,
                                            RealmERC721Asset.tokenIdAddrName(asset.getTokenId(), dbKey));

            realmAsset.setName(asset.getName());
            realmAsset.setDescription(asset.getDescription());
            realmAsset.setExternalLink(asset.getExternalLink());
            realmAsset.setImagePreviewUrl(asset.getImagePreviewUrl());
            realmAsset.setBackgroundColor(asset.getBackgroundColor());
            realmAsset.setTraits(asset.getTraits());
        }
        else
        {
            //see if traits have changed
            List<Trait> traits = realmAsset.getTraits();
            if (traits.size() != asset.getTraits().size() || traitsDifferent(traits, asset.getTraits()))
            {
                realmAsset.setImagePreviewUrl(asset.getImagePreviewUrl());
                realmAsset.setTraits(asset.getTraits());
            }
        }
    }
}