Package io.ran
Annotation Interface Mapper
@Mapper
indicates the mapping configuration for a class.
This configuration is used to determine the data-space to use for the class, using the implementation of DbType
that is specified in the dbType()
parameter.
Typical usage:
@Mapper(dbType = Valqueries.class)
public class Person {
@PrimaryKey
private String id;
@Key(name = "name")
private String name;
}
If this is used to generate an SQL table, it will generate a table called person
with two columns: id
and name
.
It will also alter the table to add an index on the name
column.
The corresponding SQL code is similar to:
CREATE TABLE `person` (`id` VARCHAR(255), `name` VARCHAR(255), PRIMARY KEY (`id`));
ALTER TABLE `person` ADD INDEX `name` (`name`);
Any fields in a model class that are transient will not be mapped to the database.
A class that is annotated with @Mapper
MUST also have the following:
- A no-args constructor or an @
Inject
annotated constructor where all parameters are injectable - A getter and a setter method for each field that is to be mapped to the database. These will be used to read and write the data from the database and will be wrapped by the generated class.
- No setters that refer to non-existing fields (e.g. no
setFullName(String)
if there is no fullName field)
- See Also:
-
Required Element Summary
Required Elements
-
Element Details
-
dbType
Points to the class to use as the dbType for this class.- Returns:
- The
DbType
to use for this class.
-