Storm


Source link: https://github.com/supaldubey/storm

A small and FAST Java ORM solution for Android SQLite database. Currently being used across projects from Enterprise to Open Source

Storm was created with intention to be easy to use ORM solution for Android platform. While working for a corporate client we realised that the available tools either expect too much to be done manually, or are super-complicated or just want entities to extend their own.

The target was to have something which is easy to use, super-fast,convenient and does not asks you to write all queries, updates, creates or even to extend their models.

Cubestack Apps using Storm

[More details here] ( http://cubestacklabs.com/category/storm/)

Adding to Project

To add storm to your Android project, please use below for Gradle in your project specific Gradle file. This would add Cubestack bitray Mave repository to your project

maven {
 url "http://dl.bintray.com/cubestack/maven" 
}

Once Maven repository is added, you may import Storm to your project with current version (1.0g) or any other

dependencies {

  compile 'in.cubestack.android.lib:storm:1.0g' 
}

Getting Started

Storm needs to know the basic database details and the tables it needs to manage.

Three basic steps:

Step One (Define the Table)

Tables can be defined easily with marking your entities with annotations similar to most ORMs

@Table(name = "DEMO_ENTITY") class Entity {

 @PrimaryKey
 @Column(name="ID", type = FieldType.INTEGER)
 private int id;  
}

Once you have tables defined as above, the next step is to bind them to a database.

Step Two (Define the Database)

Database also have their annotation which can be applied, there can be multiple databases defined.

@Database(name="MY_DB", tables = {
Entity.class, AnotherEntity.class
}
, version = 2) class Database {

}

Step Three (Start Using)

With database ready for us, we may start using it as below:

Retrival

StormService service = new BaseService(getContext(), Database.class);
 List<Entity> savedEntities  = service.findAll(Entity.class);

Save

StormService service = new BaseService(getContext(), Database.class);
 Entity entity = new Entity ();
  // Set all values service.save(entity);
  Assert.assertTrue(entity.id > 0 );
 

Not only storm would save the entity for you, it would also auto increment the ID (You may override this behaviour with @PrimaryKey annotation), it would also update the new ID value generated to your entity.

Find and Fetch

There is a handy Criteria API to help you fetch the data from your tables:

Creating the restrictions:

  restrictions = StormRestrictions.restrictionsFor(TestEntity.class);

Restriction idRes = restrictions.equals("id", 7);
 

Multiple Restrictions:

  Restriction name = restrictions.likeIgnoreCase("name", "Bruce Wayne");

Restriction combo = restrictions.and(idRes, name);
 

Using restrictions:

List<TestEntity> responseList = stormService.find(TestEntity.class, combo);
 

There is also an Async API with callbacks to help avoid writing the AsyncTasks

Example: [Word List Project] ( https://github.com/supaldubey/gre/blob/master/app/src/main/java/in/cubestack/material/androidmaterial/fragment/MainFragment.java)

 //

  WordList is mapped Table, Restirctions can be paged, order on multiple Properties and callback stormService.find(WordList.class, restriction.page(pageNo), Order.orderFor(WordList.class, new String[]{
"word"
}
, SortOrder.ASC),

 new StormCallBack<WordList>() {

  @Override

  public void onResults(final List<WordList> results) {

  // Do something with results on Main UI Thread

  
}

@Override

  public void onError(Throwable throwable) {

 // Handle Error, on UI Thread

  
}

 
}
);
 

That's it

No other configurations, no create tables, nothing required. We donot want an entry in AndroidManifest, or any String to be declared in the XML.

We would read the entities defined as per the @Database annotation and make sure we make everything ready.

View demo application: link to Google Play Store!, [source code] ( https://github.com/supaldubey/gre) and [Entity Mappings] ( https://github.com/supaldubey/gre/tree/master/app/src/main/java/in/cubestack/material/androidmaterial/model)

Features

  • Manage Relations (one to One and One to Many Supported)
  • Save entire object graph in one transaction (In case of relational database and collections)
  • Fetch entire object graph with conditions
  • Limit and Order support (Paging)
  • Supports cascading (Delete Orphans and Save Child relations)
  • Bulk Insert (Works in Transaction)
  • Auto create tables on Create
  • Auto update tables on update of application versions
  • Version Audit history via Annotations
  • Utilizes Where / Restrictions / Limits / Orders constraints (Without a line of SQL code)
  • All list options are Transnational for performance
  • Handy callback options
  • Sync and Async calling suppport
  • Performance (Almost similar to Raw SQL)
  • No Constraints, your entities need not extend any classes
  • Non Invasive Framework.
  • Less that 100 KB Footprint, no additional dependency

Resources

CameraView aims to help Android developers easily integrate Camera features.

Delta offers your android app the hot fix and incremental upgrade powers.

If you want pick image from gallery or take picture, this library can help easily.

Reactive layer (similar to the pattern repository) for the Realm.

AndroidYouTubePlayer is a simple View that can be easily integrated in every Activity/Fragment. The interaction with YouTube is based on the IFrame Player API, therefore the YouTube app is not required to use the player.

ElasticListView extends android ListView and allows you pull down from the top of ListView to update data and pull up from the bottom of ListView to load data.

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