Back to project page Abstract-Model.
The source code is released under:
Apache License
If you think the Android project Abstract-Model listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.
package com.logician.abstractModel.examples; //from ww w . ja v a 2s . c o m import java.util.EnumSet; import com.logician.abstractModel.AsyncModelFactory; import com.logician.abstractModel.Column; import com.logician.abstractModel.Column.Flag; import com.logician.abstractModel.Model; import com.logician.abstractModel.Column.Type; public class User extends Model { public static final String TABLE_NAME = "user"; public static final String INDEX = "index"; public static final String USERNAME = "username"; public static final String PASSWORD = "password"; public static final Column[] COLUMNS = { new Column(USERNAME, Type.STRING, EnumSet.of(Flag.NOT_NULL)), new Column(PASSWORD, Type.STRING, EnumSet.of(Flag.NOT_NULL)) }; public int index; public String username; public String password; @Override public String getTableName() { return TABLE_NAME; } @Override public Column[] getColumns() { return COLUMNS; } @Override public void fromRow(Row row) { username = row.getString(USERNAME); password = row.getString(PASSWORD); } @Override public void toRow(Row row) { row.put(USERNAME, username); row.put(PASSWORD, password); } @Override // equals(Model model) in Model public boolean equals(Model model){ if(model instanceof User){ return equals((User) model); } else return false; } // Since passwords can change, we're only comparing username. public boolean equals(User user){ return user.username.equals(username); } // A standard Model.Factory implementation. public static final Factory<User> FACTORY = new Factory<User>(){ @Override public User getModel() { return new User(); }}; // All you have to do to instantiate your Models on a background thread! public static final AsyncModelFactory<User> ASYNC_FACTORY = new AsyncModelFactory<User>(){ @Override public Factory<User> getFactory() { return FACTORY; }}; }