public class UserRepository<U extends User> extends ModelRepository<U>
ModelRepository for the built-in User type.
UserRepository<MyUser> userRepo = new UserRepository<MyUser>("user", MyUser.class);
Most application are extending the built-in User model and adds new properties like address, etc. You should create your own Repository class by extending this base class in such case.
public class Customer extends User {
// your custom properties and prototype (instance) methods
}
public class CustomerRepository extends UserRepository<Customer> {
public interface LoginCallback extends LoginCallback<Customer> {
}
public CustomerRepository() {
super("customer", null, Customer.class);
}
// your custom static methods
}
| Modifier and Type | Class and Description |
|---|---|
static interface |
UserRepository.LoginCallback<U>
Callback passed to loginUser to receive success and newly created
U user instance or thrown error. |
ModelRepository.FindAllCallback<T extends Model>, ModelRepository.FindCallback<T extends Model>| Modifier and Type | Field and Description |
|---|---|
static java.lang.String |
PROPERTY_CURRENT_USER_ID |
static java.lang.String |
SHARED_PREFERENCES_NAME |
| Constructor and Description |
|---|
UserRepository(java.lang.String className,
java.lang.Class<U> userClass)
Creates a new UserRepository, associating it with
the static
U user class and the user class name. |
UserRepository(java.lang.String className,
java.lang.String nameForRestUrl,
java.lang.Class<U> userClass)
Creates a new UserRepository, associating it with
the static
U user class and the user class name. |
| Modifier and Type | Method and Description |
|---|---|
RestContract |
createContract()
Creates a
RestContract representing the user type's custom
routes. |
U |
createUser(java.lang.String email,
java.lang.String password)
Creates a
U user instance given an email and a password. |
U |
createUser(java.lang.String email,
java.lang.String password,
java.util.Map<java.lang.String,? extends java.lang.Object> parameters)
Creates a new
U user given the email, password and optional parameters. |
void |
findCurrentUser(ObjectCallback<U> callback)
Fetch the data of the currently logged in user.
|
U |
getCachedCurrentUser()
Get the cached value of the currently logged in user.
|
java.lang.Object |
getCurrentUserId() |
void |
loginUser(java.lang.String email,
java.lang.String password,
UserRepository.LoginCallback<U> callback)
Login a user given an email and password.
|
void |
logout(VoidCallback callback)
Logs the current user out of the server and removes the access
token from the system.
|
protected void |
setCurrentUserId(java.lang.Object currentUserId) |
createModel, createObject, findAll, findById, getNameForRestUrlgetApplicationContext, getRestAdaptergetAdapter, getClassName, invokeStaticMethod, invokeStaticMethod, setAdapterpublic static final java.lang.String SHARED_PREFERENCES_NAME
public static final java.lang.String PROPERTY_CURRENT_USER_ID
public UserRepository(java.lang.String className,
java.lang.Class<U> userClass)
U user class and the user class name.className - The remote class name.userClass - The User (sub)class. It must have a public no-argument constructor.public UserRepository(java.lang.String className,
java.lang.String nameForRestUrl,
java.lang.Class<U> userClass)
U user class and the user class name.className - The remote class name.nameForRestUrl - The pluralized class name to use in REST transport.
Use null for the default value, which is the plural
form of className.userClass - The User (sub)class. It must have a public no-argument constructor.public java.lang.Object getCurrentUserId()
protected void setCurrentUserId(java.lang.Object currentUserId)
public void findCurrentUser(ObjectCallback<U> callback)
callback.onSuccess(null) when no user is logged in.
The data is cached, see getCachedCurrentUser()callback - success/error callbackpublic U getCachedCurrentUser()
findCurrentUser(ObjectCallback),
loginUser(String, String, LoginCallback) and
logout(VoidCallback)
The typical usage:
findCurrentUser(ObjectCallback) is called to pre-load the data.
getCachedCurrentUser() to access the data
of the currently logged in user.
public U createUser(java.lang.String email, java.lang.String password)
U user instance given an email and a password.email - password - U user instance.public RestContract createContract()
RestContract representing the user type's custom
routes. Used to extend an Adapter to support user. Calls
super ModelRepository createContract first.createContract in class ModelRepository<U extends User>RestContract for this model type.public U createUser(java.lang.String email, java.lang.String password, java.util.Map<java.lang.String,? extends java.lang.Object> parameters)
U user given the email, password and optional parameters.email - - user emailpassword - - user passwordparameters - - optional parametersU user instance.public void loginUser(java.lang.String email,
java.lang.String password,
UserRepository.LoginCallback<U> callback)
AccessToken and U user models if successful.email - - user emailpassword - - user passwordcallback - - success/error callbackpublic void logout(VoidCallback callback)
callback - The callback to be executed when finished.