在线时间:8:00-16:00
迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
开源软件名称(OpenSource Name):requery/requery开源软件地址(OpenSource Url):https://github.com/requery/requery开源编程语言(OpenSource Language):Java 86.1%开源软件介绍(OpenSource Introduction):A light but powerful object mapping and SQL generator for Java/Kotlin/Android with RxJava and Java 8 support. Easily map to or create databases, perform queries and updates from any platform that uses Java. ExamplesDefine entities from an abstract class: @Entity
abstract class AbstractPerson {
@Key @Generated
int id;
@Index("name_index") // table specification
String name;
@OneToMany // relationships 1:1, 1:many, many to many
Set<Phone> phoneNumbers;
@Converter(EmailToStringConverter.class) // custom type conversion
Email email;
@PostLoad // lifecycle callbacks
void afterLoad() {
updatePeopleList();
}
// getter, setters, equals & hashCode automatically generated into Person.java
} or from an interface: @Entity
public interface Person {
@Key @Generated
int getId();
String getName();
@OneToMany
Set<Phone> getPhoneNumbers();
String getEmail();
} or use immutable types such as those generated by @AutoValue: @AutoValue
@Entity
abstract class Person {
@AutoValue.Builder
static abstract class Builder {
abstract Builder setId(int id);
abstract Builder setName(String name);
abstract Builder setEmail(String email);
abstract Person build();
}
static Builder builder() {
return new AutoValue_Person.Builder();
}
@Key
abstract int getId();
abstract String getName();
abstract String getEmail();
} (Note some features will not be available when using immutable types, see here) Queries: dsl based query that maps to SQL Result<Person> query = data
.select(Person.class)
.where(Person.NAME.lower().like("b%")).and(Person.AGE.gt(20))
.orderBy(Person.AGE.desc())
.limit(5)
.get(); Relationships: represent relations more efficiently with Java 8 Streams, RxJava Observables or plain iterables. (sets and lists are supported to) @Entity
abstract class AbstractPerson {
@Key @Generated
int id;
@ManyToMany
Result<Group> groups;
// equivalent to:
// data.select(Group.class)
// .join(Group_Person.class).on(Group_ID.equal(Group_Person.GROUP_ID))
// .join(Person.class).on(Group_Person.PERSON_ID.equal(Person.ID))
// .where(Person.ID.equal(id))
} Kotlin specific support using property references and infix functions: data {
val result = select(Person::class) where (Person::age gt 21) and (Person::name eq "Bob") limit 10
} Java 8 streams: data.select(Person.class)
.orderBy(Person.AGE.desc())
.get()
.stream().forEach(System.out::println); Java 8 optional and time support: public interface Person {
@Key @Generated
int getId();
String getName();
Optional<String> getEmail();
ZonedDateTime getBirthday();
} Observable<Person> observable = data
.select(Person.class)
.orderBy(Person.AGE.desc())
.get()
.observable(); RxJava observe query on table changes: Observable<Person> observable = data
.select(Person.class)
.orderBy(Person.AGE.desc())
.get()
.observableResult().subscribe(::updateFromResult); Read/write separation Along with immutable types optionally separate queries (reading) and updates (writing): int rows = data.update(Person.class)
.set(Person.ABOUT, "student")
.where(Person.AGE.lt(21)).get().value(); Features
Reflection freerequery uses compile time annotation processing to generate entity model classes and mapping attributes. On Android this means you get about the same performance reading objects from a query as if it was populated using the standard Cursor and ContentValues API. Query with JavaThe compiled classes work with the query API to take advantage of compile time generated attributes. Create type safe queries and avoid hard to maintain, error prone string concatenated queries. RelationshipsYou can define One-to-One, One-to-Many, Many-to-One, and Many-to-Many relations in your models using annotations. Relationships can be navigated in both directions. Of many type relations can be loaded into standard java collection objects or into a more efficient Result type. From a Result easily create a Stream, RxJava Observable, Iterator, List or Map. Many-to-Many junction tables can be generated automatically. Additionally the relation model is validated at compile time eliminating runtime errors. vs JPArequery provides a modern set of interfaces for persisting and performing queries. Some key differences between requery and JPA providers like Hibernate or EclipseLink:
AndroidDesigned specifically with Android support in mind. See requery-android/example for an example Android project using databinding and interface based entities. For more information see the Android page. Supported DatabasesTested on some of the most popular databases:
JPA AnnotationsA subset of the JPA annotations that map onto the requery annotations are supported. See here for more information. UpsertsUpserts are generated with the appropriate database specific query statements:
Using itVersions are available on bintray jcenter / maven central. repositories {
jcenter()
}
dependencies {
compile 'io.requery:requery:1.6.1'
compile 'io.requery:requery-android:1.6.1' // for android
annotationProcessor 'io.requery:requery-processor:1.6.1'
} For information on gradle and annotation processing & gradle see the wiki. License
|
2023-10-27
2022-08-15
2022-08-17
2022-09-23
2022-08-13
请发表评论