greenDao 支持 枚举类型
Note.class
@Entity(indexes = {
@Index(value = "text, date DESC", unique = true)
})
public class Note {
@Id(autoincrement = true)
private Long id;
@NotNull
private String text;
private String comment;
private java.util.Date date;
@Convert(converter = NoteTypeConverter.class, columnType = String.class)
private NoteType type;
}
NoteType.class
public enum NoteType {
TEXT, LIST, PICTURE
}
NoteTypeConverter.class
public class NoteTypeConverter implements PropertyConverter<NoteType, String> {
@Override
public NoteType convertToEntityProperty(String databaseValue) {
return NoteType.valueOf(databaseValue);
}
@Override
public String convertToDatabaseValue(NoteType entityProperty) {
return entityProperty.name();
}
}
查询
高级查询
查询条件:
First name is "Joe"
AND(
year of birth is greater than 1970
OR(
year of birth is 1970 AND month of birth is equal to or greater than 10)
)
『firstname 等于Joe,而且(此人1970年后出生或者1970年10月以后出生)』
QueryBuilder<User> qb = userDao.queryBuilder();
qb.where(Properties.FirstName.eq("Joe"),
qb.or(Properties.YearOfBirth.gt(1970),
qb.and(Properties.YearOfBirth.eq(1970), Properties.MonthOfBirth.ge(10))));
List<User> youngJoes = qb.list();
自定义类型查询
**greenDao 支持的默认类型**
boolean, Boolean
int, Integer
short, Short
long, Long
float, Float
double, Double
byte, Byte
byte[]
String
Date
其他类型参考枚举类型 greenDao枚举类型