Skip to content
This repository has been archived by the owner on Feb 8, 2022. It is now read-only.

Commit

Permalink
Merge pull request #15 from florent37/dev
Browse files Browse the repository at this point in the history
Dev
  • Loading branch information
florent37 committed Feb 26, 2016
2 parents 3dc363d + c0d8207 commit 73be389
Show file tree
Hide file tree
Showing 17 changed files with 1,057 additions and 369 deletions.
78 changes: 61 additions & 17 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@ buildscript {
apply plugin: 'com.neenbedankt.android-apt'

dependencies {
compile 'fr.xebia.android.freezer:freezer:1.0.5'
provided 'fr.xebia.android.freezer:freezer-annotations:1.0.5'
apt 'fr.xebia.android.freezer:freezer-compiler:1.0.5'
compile 'fr.xebia.android.freezer:freezer:1.0.6'
provided 'fr.xebia.android.freezer:freezer-annotations:1.0.6'
apt 'fr.xebia.android.freezer:freezer-compiler:1.0.6'
}
```

Expand All @@ -33,22 +33,15 @@ public class User {
int age;
String name;
Cat cat;
List<Dog> dogs;
}
```

```java
@Model
public class Dog {
String name;
List<Cat> pets;
}
```

```java
@Model
public class Cat {
@Id long id;
String shortName;
String name;
}
```

Expand Down Expand Up @@ -86,17 +79,16 @@ User user3 = userEntityManager.select()

To find all users
- with `name` "Florent"
- or who own a cat with `shortNamed` "Java"
- or who own a dog `named` "Sasha"
- or who own a pet with `named` "Java"

you would write:
```java
List<User> allUsers = userEntityManager.select()
.name().equalsTo("Florent")
.or()
.cat(CatEntityManager.where().shortName().equalsTo("Java"))
.cat(CatEntityManager.where().name().equalsTo("Java"))
.or()
.dogs(DogEntityManager.where().name().equalsTo("Sasha"))
.pets(CatEntityManager.where().name().equalsTo("Sasha"))
.asList();
```

Expand Down Expand Up @@ -135,6 +127,53 @@ float ageMax = userEntityManager.select().max(UserColumns.age);
int count = userEntityManager.select().count();
```

#Asynchronous

Freezer offers various asynchronous methods:

##Add / Delete / Update

```java
userEntityManager
.addAsync(users)
.async(new SimpleCallback<List<User>>() {
@Override
public void onSuccess(List<User> data) {

}
});
```

##Querying

```java
userEntityManager
.select()
...
.async(new SimpleCallback<List<User>>() {
@Override
public void onSuccess(List<User> data) {

}
});
```

##Observables

```java
userEntityManager
.select()
...
.asObservable()
... //rx operations
.subscribe(new Action1<List<User>>() {
@Override
public void call(List<User> users) {

}
});
```

#Entities

Freezer makes it possible, yes you can design your entities as your wish:
Expand Down Expand Up @@ -260,7 +299,6 @@ Migration isn't yet capable of:
- Improve migration
- Add Observable support
- Provide an Asynchronous API
#Changelog
Expand Down Expand Up @@ -289,6 +327,12 @@ Introduced Migration Engine.
- Model update
##1.0.6
- Async API
- Support Observables
- Added @DatabaseName
#A project initiated by Xebia
This project was first developed by Xebia and has been open-sourced since. We will continue working on it.
Expand Down
3 changes: 2 additions & 1 deletion app/src/main/java/com/github/florent37/orm/MainActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,13 @@
import com.github.florent37.orm.model.CatEntityManager;
import com.github.florent37.orm.model.Dog;
import com.github.florent37.orm.model.User;
import com.github.florent37.orm.model.UserColumns;
import com.github.florent37.orm.model.UserEntityManager;

import fr.xebia.android.freezer.QueryLogger;

import java.util.Arrays;
import java.util.List;

public class MainActivity extends AppCompatActivity {

Expand Down Expand Up @@ -52,6 +54,5 @@ protected void queries(){

.asList()
.toString());

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -179,4 +179,36 @@ public void testUpdateCat_onlyFields() throws Exception{
assertThat(catFromBase.getShortName()).isEqualTo("mimi");
}

@Test
public void testDeleteCat() throws Exception{
//given
Cat cat1 = new Cat("toto");
catEntityManager.add(cat1);
assertThat(catEntityManager.count()).isEqualTo(1);
assertThat(cat1.getId()).isAtLeast(1l);

//when
catEntityManager.delete(cat1);

//then
assertThat(catEntityManager.count()).isEqualTo(0);
}

@Test
public void testDeleteCats() throws Exception{
//given
Cat cat1 = new Cat("toto");
Cat cat2 = new Cat("tata");
catEntityManager.add(Arrays.asList(cat1, cat2));
assertThat(catEntityManager.count()).isEqualTo(2);
assertThat(cat1.getId()).isAtLeast(1l);
assertThat(cat2.getId()).isAtLeast(1l);

//when
catEntityManager.delete(Arrays.asList(cat1,cat2));

//then
assertThat(catEntityManager.count()).isEqualTo(0);
}

}
Loading

0 comments on commit 73be389

Please sign in to comment.