Java – check whether the new domain object has not been saved

Does anyone know how I check that domain objects have not been saved to the database? I want to implement the logic in the following example:

protected boolean prepareToSave(Product product, Realm realm) {
    // are we have enought space at storage?
    int productLimit = getLimit();
    if(
       /* product.isStoredInDB() && */ 
       realm.where(Product.class).count() >= productLimit)
       Toast.makeText(this, "Not enought space at storage", Toast.LENGTH_LONG).show();
    else
       // do another stuff
}

Edit:

where?

public class Product extends RealmObject {

    @PrimaryKey private long id;
    @required private String title;
    private String note;
    private byte[] image;
    private byte[] thumbnail;

    private double count = Double.NaN;
    private double minimumCount = Double.NaN;

    // getters and setters
}

The and methods getlimit() only return the syntax limit of storage, not the actual SD card or internal storage capacity. This limit is used to provide in app purchase

resolvent:

You can use

Product p = getProduct()
if (!p.isManaged()) {
  // Object isn't saved in Realm 
}

But your code snippet seems to indicate that you want to check whether the device has enough space to store your changes. There is really no way to determine this, because it will largely depend on the type of data you want to store

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>