Android-TriOrm


Source link: https://github.com/HendrixString/Android-TriOrm

Android-TriOrm

a 3d database ORM experiment for Android. (used in two commercial projects). based around small tables concept and JVM Serialization.

How to use

simply fork or download the project, you can also download and create .aar file yourself.

Explanation

TriOrm is a very light, simple and efficient ORM with partial SQL wrapping, with the following theme:

  • every Object ( TriData extension) is serialized and saved in the database.
  • you can only query by three fields: id, time_created and type.
  • familiar no fuss Builder pattern to construct database.
  • easy API to query, save and load typed objects.
  • a very small usage of annotation(Optional).
  • no learning curve whatsoever, no Boiler-plate code.
  • Database is ready to use in less than couple of minutes.
  • everything is typed.
  • most of the presistent is carried by JVM Serialization and minimal small SQL table.

construct your Model/Tables

Simply extend TriData with the following annotations(Optional).

@TriTable(dbName = "myDataBase", tableName = "user") public class User extends TriData {

  public String firstName = "John";
  public String lastName  = "Dow";

public User() {

  
}

public User(String id) {

super(id);

  
}
 
}
  @TriTable(dbName = "myDataBase", tableName = "location") public class Location extends TriData {

  public String city
 = "city";
  public String state
= "state";

public Location() {

  
}

}
 

every TriData has the following indexed/query-able properties with getters/setters:

  • setId(..) - you can set the id or it will be set automatically for you.
  • setType(..) - some auxiliary field.
  • setTimeCreated(..) - also set-up for you by default.

construct your Database

constructing a database takes one line of code

new TriDatabase.Builder(this).addTable(User.class).addTable(Location.class).build();
 

and without annotations:

new TriDatabase.Builder(this).name("myDataBase").addTable("user", User.class).addTable("location", Location.class).build();
 

Saving into your Database

Simply invoke the save() method on your extended TriData object.

User user

 = new User();
  user.setId("theDude");
 user.setType("Java programmer");
  user.firstName  = "Jimi"; user.lastName
= "Hendrix";  user.save();

loading a single object from your Database

Simply use the TriOrm.load(..) Singleton and use your typed object.

User user = TriOrm.load(User.class, "theDude");

querying from your Database

Simply use the TriOrm.query(..) builder Singleton and use your typed object.

ArrayList<User> list_users = TriOrm.query(User.class).timeCreatedFrom(0).timeCreatedTo(100).type("Java programmer").build().query();

you can query anything from the three properties: id, timeCreated and type.

getting an instance of a table

Simply use the TriOrm.table(..) Singleton and use your typed object. With table you can have more options and some sandbox methods.

TriTable<User> table = TriOrm.table(User.class);

Important Notes

The presistent layer is built around JVM Serialization, therefore there are important considerations for when evolving your model/tables like any other database solution, beware of the folowing:

  • TriData is based on JVM Serialization, therefore:
    • adding new fields is compatible.
    • deleting/renaming exiting fields is not compatible, Therefore you will have to implement your writeObject/readObject and be smart about it.
    • adding new methods, altering previous methods is incompatible.
  • look here for more info Durable Java: Serialization
  • I recommend using primitive types as much as possible when designing the model/table.
  • for best performence and compatibility control, you can experiment with Externalizable interface for reflection free.
  • contributions are most welcome with regards to compatiblity/performence.

Dependencies

  • AOSP

Terms

Contact Author

Resources

A tiny library that assists in saving and restoring objects to and from disk using RxJava on Android.

Android 9-patch shadow generator.

A rating toggle for Android which switches between 3 rating levels:

  • positive
  • neutral
  • negative

This library is an extension for android buttons. You can add switchable buttons with cool animations when you press on them.

Neat 2D and 3D load indicators/spinners to use in your app. The library converts pre-made spritesheets to an AnimationDrawable to returns a Loader object than extends from ImageView. A very simple idea that can liven up your app.

Android Developer Icons is a custom icon set, included are:

  • 250 hand-crafted, pixel-perfect icons in 5 sizes and 14 colors
  • an icon font, made from the set
  • all sources: .svg, .ai, .eps, .eot, .ttf, .woff

Topics


2D Engines   3D Engines   9-Patch   Action Bars   Activities   ADB   Advertisements   Analytics   Animations   ANR   AOP   API   APK   APT   Architecture   Audio   Autocomplete   Background Processing   Backward Compatibility   Badges   Bar Codes   Benchmarking   Bitmaps   Bluetooth   Blur Effects   Bread Crumbs   BRMS   Browser Extensions   Build Systems   Bundles   Buttons   Caching   Camera   Canvas   Cards   Carousels   Changelog   Checkboxes   Cloud Storages   Color Analysis   Color Pickers   Colors   Comet/Push   Compass Sensors   Conferences   Content Providers   Continuous Integration   Crash Reports   Credit Cards   Credits   CSV   Curl/Flip   Data Binding   Data Generators   Data Structures   Database   Database Browsers   Date &   Debugging   Decompilers   Deep Links   Dependency Injections   Design   Design Patterns   Dex   Dialogs   Distributed Computing   Distribution Platforms   Download Managers   Drawables   Emoji   Emulators   EPUB   Equalizers &   Event Buses   Exception Handling   Face Recognition   Feedback &   File System   File/Directory   Fingerprint   Floating Action   Fonts   Forms   Fragments   FRP   FSM   Functional Programming   Gamepads   Games   Geocaching   Gestures   GIF   Glow Pad   Gradle Plugins   Graphics   Grid Views   Highlighting   HTML   HTTP Mocking   Icons   IDE   IDE Plugins   Image Croppers   Image Loaders   Image Pickers   Image Processing   Image Views   Instrumentation   Intents   Job Schedulers   JSON   Keyboard   Kotlin   Layouts   Library Demos   List View   List Views   Localization   Location   Lock Patterns   Logcat   Logging   Mails   Maps   Markdown   Mathematics   Maven Plugins   MBaaS   Media   Menus   Messaging   MIME   Mobile Web   Native Image   Navigation   NDK   Networking   NFC   NoSQL   Number Pickers   OAuth   Object Mocking   OCR Engines   OpenGL   ORM   Other Pickers   Parallax List   Parcelables   Particle Systems   Password Inputs   PDF   Permissions   Physics Engines   Platforms   Plugin Frameworks   Preferences   Progress Indicators   ProGuard   Properties   Protocol Buffer   Pull To   Purchases   Push/Pull   QR Codes   Quick Return   Radio Buttons   Range Bars   Ratings   Recycler Views   Resources   REST   Ripple Effects   RSS   Screenshots   Scripting   Scroll Views   SDK   Search Inputs   Security   Sensors   Services   Showcase Views   Signatures   Sliding Panels   Snackbars   SOAP   Social Networks   Spannable   Spinners   Splash Screens   SSH   Static Analysis   Status Bars   Styling   SVG   System   Tags   Task Managers   TDD &   Template Engines   Testing   Testing Tools   Text Formatting   Text Views   Text Watchers   Text-to   Toasts   Toolkits For   Tools   Tooltips   Trainings   TV   Twitter   Updaters   USB   User Stories   Utils   Validation   Video   View Adapters   View Pagers   Views   Watch Face   Wearable Data   Wearables   Weather   Web Tools   Web Views   WebRTC   WebSockets   Wheel Widgets   Wi-Fi   Widgets   Windows   Wizards   XML   XMPP   YAML   ZIP Codes