• This repository has been archived on 08/Feb/2022
  • Stars
    star
    328
  • Rank 128,352 (Top 3 %)
  • Language
    Java
  • License
    Apache License 2.0
  • Created almost 9 years ago
  • Updated almost 7 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

A simple & fluent Android ORM, how can it be easier ? RxJava2 compatible

Freezer

Android Arsenal CircleCI

Android app on Google Play

A simple & fluent Android ORM, how can it be easier ? And it's compatible with RxJava2 !

UserEntityManager userEntityManager = new UserEntityManager();

userEntityManager.add(new User("Florent", 6));
userEntityManager.add(new User("Florian", 3));
userEntityManager.add(new User("Bastien", 3));

List<User> allUsers = userEntityManager.select()
                             .name().startsWith("Flo")
                             .asList();

userEntityManager.select()
       .age().equals(3)
       .asObservable()

       .subscribeOn(Schedulers.newThread())
       .observeOn(AndroidSchedulers.mainThread())
       .subscribe(users ->
          //display the users
       );

First, initialize !

Don't forget to initialise Freezer in your application:

public class MyApplication extends Application {

    @Override public void onCreate() {
        super.onCreate();
        Freezer.onCreate(this);
    }

}

Second, annotate your models

Use Annotations to mark classes to be persisted:

@Model
public class User {
    int age;
    String name;
    Cat cat;
    List<Cat> pets;
}
@Model
public class Cat {
    @Id long id;
    String name;
}

Now, play with the managers !

Persist datas

Persist your data easily:

UserEntityManager userEntityManager = new UserEntityManager();

User user = ... // Create a new object
userEntityManager.add(user);

Querying

Freezer query engine uses a fluent interface to construct multi-clause queries.

Simple

To find all users:

List<User> allUsers = userEntityManager.select()
                             .asList();

To find the first user who is 3 years old:

User user3 = userEntityManager.select()
                    .age().equalsTo(3)
                    .first();

Complex

To find all users

  • with name "Florent"
  • or who own a pet with named "Java"

you would write:

List<User> allUsers = userEntityManager.select()
                                .name().equalsTo("Florent")
                             .or()
                                .cat(CatEntityManager.where().name().equalsTo("Java"))
                             .or()
                                .pets(CatEntityManager.where().name().equalsTo("Sasha"))
                             .asList();

Selectors

//strings
     .name().equalsTo("florent")
     .name().notEqualsTo("kevin")
     .name().contains("flo")
     .name().in("flo","alex","logan")
//numbers
     .age().equalsTo(10)
     .age().notEqualsTo(30)
     .age().greatherThan(5)
     .age().between(10,20)
     .age().in(10,13,16)
//booleans
     .hacker().equalsTo(true)
     .hacker().isTrue()
     .hacker().isFalse()
//dates
     .myDate().equalsTo(OTHER_DATE)
     .myDate().notEqualsTo(OTHER_DATE)
     .myDate().before(OTHER_DATE)
     .myDate().after(OTHER_DATE)

Aggregation

The QueryBuilder offers various aggregation methods:

float agesSum      = userEntityManager.select().sum(UserColumns.age);
float agesAverage  = userEntityManager.select().average(UserColumns.age);
float ageMin       = userEntityManager.select().min(UserColumns.age);
float ageMax       = userEntityManager.select().max(UserColumns.age);
int count          = userEntityManager.select().count();

Limit

The QueryBuilder offers a limitation method, for example, getting 10 users, starting from the 5th:

List<User> someUsers = userEntityManager.select()
                                .limit(5, 10) //start, count
                                .asList();

Asynchronous

Freezer offers various asynchronous methods:

Add / Delete / Update

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

                    }
                });

Querying

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

                    }
                });

Observables

With RxJava

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:

@Model
public class MyEntity {

    // primitives
    [ int / float / boolean / String / long / double ] field;
    
    //dates
    Date myDate;

    // arrays
    [ int[] / float[] / boolean[] / String[] / long[] / double ] array; 
    
    // collections
    [ List<Integer> / List<Float> / List<Boolean> / List<String> / List<Long> / List<Double> ] collection;
    
    // One To One
    MySecondEntity child;
    
    // One To Many
    List<MySecondEntity> childs;
}

Update

You can update a model:

user.setName("laurent");
userEntityManager.update(user);

Id

You can optionnaly set a field as an identifier:

@Model
public class MyEntity {
    @Id long id;
}

The identifier must be a long

Ignore

You can ignore a field:

@Model
public class MyEntity {
    @Ignore
    int field;    
}

Logging

You can log all SQL queries from entities managers:

userEntityManager.logQueries((query, datas) -> Log.d(TAG, query) }

Migration

To handle schema migration, just add @Migration(newVersion) in a static method, then describe the modifications:

public class DatabaseMigration {

    @Migration(2)
    public static void migrateTo2(Migrator migrator) {
        migrator.update("User")
                .removeField("age")
                .renameTo("Man");
    }

    @Migration(3)
    public static void migrateTo3(Migrator migrator) {
        migrator.update("Man")
                .addField("birth", ColumnType.Primitive.Int);
    }
    
    @Migration(4)
    public static void migrateTo4(Migrator migrator) {
        migrator.addTable(migrator.createModel("Woman")
                .field("name", ColumnType.Primitive.String)
                .build());
    }
}

Migration isn't yet capable of:

  • changing type of field
  • adding/modifying One To One
  • adding/modifying One To Many
  • handling collections/arrays

Download

Android app on Google Play

Buy Me a Coffee at ko-fi.com

Download

buildscript {
  dependencies {
    classpath 'com.neenbedankt.gradle.plugins:android-apt:1.8'
  }
}

apply plugin: 'com.neenbedankt.android-apt'

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

Changelog

1.0.1

Introduced Migration Engine.

1.0.2

  • Support long & double
  • Support arrays
  • Improved QueryBuilder
  • Refactored cursors helpers

1.0.3

  • Support dates
  • Added unit tests
  • Fixed one to many

1.0.4

  • Added @Id & @Ignore

1.0.5

  • Model update

2.0.0

  • Async API
  • Support Observables
  • Added @DatabaseName

2.0.1

  • Limit

2.0.2

  • Added query.in(...values...)

2.0.3

  • Freezer.onCreate is no longer dynamic

2.0.5

  • Improved performace for batch add & update (thanks to graphee-gabriel)

2.0.6

  • Add or update object if same @Id on add, addAll`

2.1.0

  • Added RxJava2 support

A project initiated by Xebia

This project was first developed by Xebia and has been open-sourced since. We will continue working on it. We encourage the community to contribute to the project by opening tickets and/or pull requests.

logo xebia

Android app on Google Play Android app on Google Play

License

Copyright 2015 Xebia, Inc.

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

   http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

More Repositories

1

MaterialViewPager

A Material Design ViewPager easy to use library
Java
8,130
star
2

ShapeOfView

Give a custom shape to any android view, Material Design 2 ready
Java
3,132
star
3

ExpectAnim

Describe your animation and run !
Java
2,788
star
4

ViewAnimator

A fluent Android animation library
Java
2,712
star
5

DiagonalLayout

With Diagonal Layout explore new styles and approaches on material design
Java
2,562
star
6

CameraFragment

A simple easy-to-integrate Camera Fragment for Android
Java
2,290
star
7

ExpansionPanel

Android - Expansion panels contain creation flows and allow lightweight editing of an element.
Java
1,976
star
8

GlidePalette

Android Lollipop Palette is now easy to use with Glide
Java
1,677
star
9

ArcLayout

With Arc Layout explore new styles and approaches on material design
Java
1,638
star
10

MaterialTextField

A different beautiful Floating Edit Text
Java
1,488
star
11

HollyViewPager

A different beautiful ViewPager, with quick swipe controls
Java
1,131
star
12

FiftyShadesOf

An elegant context-care loading placeholder for Android
Java
1,107
star
13

ViewTooltip

A fluent tooltip for Android
Java
1,080
star
14

SingleDateAndTimePicker

You can now select a date and a time with only one widget !
Java
1,020
star
15

MyLittleCanvas

🎨Need to create a custom view ? You don't know how to use Canvas, use MyLittleCanvas instead !
Java
927
star
16

AwesomeBar

Just beautiful
Java
869
star
17

RuntimePermission

Simpliest way to ask runtime permissions on Android, no need to extend class or override permissionResult method, choose your way : Kotlin / Coroutines / RxJava / Java7 / Java8
Java
865
star
18

Depth

Add some Depth to your fragments
Java
779
star
19

Flutter-AssetsAudioPlayer

Play simultaneously music/audio from assets/network/file directly from Flutter, compatible with android / ios / web / macos, displays notifications
Dart
755
star
20

MaterialLeanBack

A beautiful leanback port for Smartphones and Tablets
Java
731
star
21

KotlinPleaseAnimate

Kotlin, please, can you animate my views ?
Kotlin
558
star
22

LongShadow

Add a long shadow on any Android View
Java
557
star
23

BubbleTab

Put some bubble in your tabs and give your apps a supa fresh style !
Java
533
star
24

TutoShowcase

A simple and Elegant Showcase view for Android
Java
509
star
25

RxRetroJsoup

A simple API-like from html website (scrapper) for Android, RxJava2 ready !
Java
485
star
26

Carpaccio

Data Mapping & Smarter Views framework for android
Java
414
star
27

BeautifulParallax

Beautify your RecyclerViews with a great parallax effect !
Java
410
star
28

MaterialImageLoading

Material image loading implementation
Java
390
star
29

PicassoPalette

Android Lollipop Palette is now easy to use with Picasso !
Java
365
star
30

android-slidr

Another android slider / seekbar, but different :-)
Java
346
star
31

RxGps

Finding current location cannot be easier on Android !
Java
300
star
32

WearMenu

An Android Wear Menu implementation
Java
289
star
33

Android-NoSql

Lightweight, simple structured NoSQL database for Android
Java
288
star
34

InlineActivityResult

Receive the activity result directly after the startActivityForResult with InlineActivityResult
Java
273
star
35

Motion-ShapeOfView

Explain how to use MotionLayout with ShapeOfView
Kotlin
241
star
36

Android-3D-Layout

Wow effect, transform your layout into 3D views
Java
231
star
37

OCiney-iOS

Objective-C
227
star
38

NewAndroidArchitecture-Component-Github

Sample project based on the new Android Component Architecture
Java
222
star
39

DaVinci

DaVinci is an image downloading and caching library for Android Wear
Java
219
star
40

Flutter-ShapeOfView

Give a custom shape to any flutter widget, Material Design 2 ready
Dart
216
star
41

Shrine-MaterialDesign2

implementation of Material Design 2 Shrine project
Kotlin
216
star
42

AndroidUnitTest

Save time & clear your unit tests on Android !
Java
205
star
43

AndroidParallax

Parallax on Android in the simplest way
Java
173
star
44

ApplicationProvider

Retrieve the android application and the current activity from anywhere
Kotlin
165
star
45

Navigator

Android Multi-module navigator, trying to find a way to navigate into a modularized android project
Kotlin
142
star
46

Android-YoutubeMp3

Download videos as mp3 directly from Youtube Android App
Java
136
star
47

KotlinNativeSample

Kotlin Native app working on Android & iPhone
Kotlin
120
star
48

EnhancedNavigationView

A different BottomNavigationView that you could find in all android apps
Kotlin
114
star
49

AnimatedWidgets

Easily add animations on your screen with AnimatedWidgets. Made for Bloc pattern
Dart
113
star
50

OCiney

OCiney is a sample app implementing several UI and UX patterns. I was firstly built to test a few different implementations of a details page.
Java
110
star
51

Kanvas

Make canvas easier to use in Kotlin 😊
Kotlin
98
star
52

Multiplatform-LiveData

Multiplatorm implementation of LiveDatas / MVVM in kotlin android & native ios
Kotlin
94
star
53

movie_android_flutter

A sample movie app, developed on flutter, then on android
Dart
87
star
54

Multiplatform-Preferences

Kotlin Multi Platform Preferences, for android an ios : SharedPreferences & NSUserDefault
Kotlin
86
star
55

Flutter-KenBurns

Kenburns effect on flutter
Dart
84
star
56

RxAnimator

An RxJava2 binding for android Animator
Java
79
star
57

WearViewStub

Display different layout on Android Wear Square / Round / Moto 360
Java
79
star
58

RxBus

Android reactive event bus that simplifies communication between Presenters, Activities, Fragments, Threads, Services, etc.
Java
77
star
59

TutosAndroidFrance

Java
75
star
60

Google-ARCore-Playground

Exploring Augmented Reality with google's sdk ARCore
Java
72
star
61

KotlinAnim

Create fluent animations in a kotlin way
Kotlin
70
star
62

Android-OkGraphQl

Reactive GraphQl client for Android
Java
64
star
63

AnimatedPencil

Animated Pencil Action view for Android
Java
60
star
64

RxComponentLifecycle

Rx binding of new Android Architecture Component Lifecycle
Java
56
star
65

Multiplatform-Log

Kotlin Multi Platform Logger, for android an ios : Logcat & print
Kotlin
51
star
66

DaggerAutoInject

Inject automatically your Activities & Fragments, just with a simple annotation
Java
49
star
67

EasyFirebase

Java
48
star
68

fonts

Define the fonts of your Android project directly from the build.gradle
Groovy
46
star
69

Multiplatform-Bus

Kotlin event-bus compatible with Android & native iOS
Kotlin
44
star
70

flutter_web_import_js_library

Import & use javascript libraries in your flutter web projects
JavaScript
42
star
71

Wear-Emmet

Emmet is an protocol based data-transfer for Android Wear
Java
41
star
72

AndroidAnalytics

Analytics dispatcher for Android Applications
Java
39
star
73

RxAndroidOrm

An reactive simple & fluent Android ORM, how can it be easier ? RxJava2 ready
Java
36
star
74

Flutter-Anim

Fluent Flutter Animation library. Describe Sequences & Parallel animation's workflow, setup startDelay, duration and curve, then run !
Dart
36
star
75

WormHole

WormHole allows to share classes between Flutter and Native Platform (android / ios)
Dart
34
star
76

Github

Sample project using Dagger2, RxJAva, RetroLambda and Carpaccio
Java
31
star
77

Coroutines-Animations

Use the power of kotlin coroutines to execute your android animations
Kotlin
30
star
78

Potier

Java
29
star
79

RxBeacon

Rx binding for AltBeacon (Android-Beacon-Library)
Java
29
star
80

Open-Mam

Open Source Mobile Application Management (WORK IN PROGRESS)
Java
28
star
81

HolyFragment

Fragment NewInstance generator
Java
16
star
82

Flutter_audio_widget

Play an audio on flutter can be as simple as display an image ! Just add a widget into the tree
Dart
14
star
83

Asyncterractor

Transform any object into an async object (can be useful for VIPER)
Java
14
star
84

WearKit

Wearkit is an Android Wear implementation of WatchKit
Java
13
star
85

JsonSerializable-Plugin

Intellij Plugin for Dart and Flutter projects. Generates the code that JsonSerializable need to generate the .g.dart files
Java
12
star
86

Missing_Kotlin

"Flutter is **** because it does not use Kotlin" Already heard it ? Prove them you can do the same thing as Kotlin using Flutter/Dart !
Dart
11
star
87

Baguette

Baguette is an Android Toast implementation adapted for Android Wear
Java
10
star
88

AdsManager

Java
9
star
89

StickyHeader

Cannot have a simplest android recycler sticky header implementation
8
star
90

AndroidMVPresenter

Java
6
star
91

WatchFaceSample

Java
5
star
92

GCM-Sample-Android-PHP

Java
4
star
93

OSSRH-67799

3
star
94

flutter_web_howl

JavaScript
2
star
95

MeetupWear_EmmetDavinci

Java
2
star
96

OpenMam-PHP

JavaScript
1
star
97

OpenMam-Android

Java
1
star
98

MyYoutube

1
star
99

UnitTestWithDagger

Java
1
star