ntroduction to Datarobot for Android - SDJUGExample setup for Android Studio w/ Gradle...

28
Intr oduction to Datarobot f or Andr oid SD JUG 2014 A lightweight per sis tence framework © arconsis IT-Solutions GmbH, 2014 1

Transcript of ntroduction to Datarobot for Android - SDJUGExample setup for Android Studio w/ Gradle...

Page 1: ntroduction to Datarobot for Android - SDJUGExample setup for Android Studio w/ Gradle (build.gradle) buildscript {repositories {mavenCentral() mavenLocal()// Only if you want to use

Introduction to Datarobot for Android

SDJUG 2014

A lightweight persistence framework© arconsis IT-Solutions GmbH, 2014 1

Page 2: ntroduction to Datarobot for Android - SDJUGExample setup for Android Studio w/ Gradle (build.gradle) buildscript {repositories {mavenCentral() mavenLocal()// Only if you want to use

At a glance4 Open Source lightweight persistence framework

=> "Non-invasive"

4 No dealing with Android SQLite database => But you can!

4 Annotation based approach

© arconsis IT-Solutions GmbH, 2014 2

Page 3: ntroduction to Datarobot for Android - SDJUGExample setup for Android Studio w/ Gradle (build.gradle) buildscript {repositories {mavenCentral() mavenLocal()// Only if you want to use

Find it on github:

https://github.com/arconsis/datarobot

© arconsis IT-Solutions GmbH, 2014 3

Page 4: ntroduction to Datarobot for Android - SDJUGExample setup for Android Studio w/ Gradle (build.gradle) buildscript {repositories {mavenCentral() mavenLocal()// Only if you want to use

Main Features4 Annotation based implementation

4 No hardcoded Strings in your code

4 Code generation for the repeating tasks

4 Compile time protection when renaming fields or tables

4 Fall back to Android default API is always possible

© arconsis IT-Solutions GmbH, 2014 4

Page 5: ntroduction to Datarobot for Android - SDJUGExample setup for Android Studio w/ Gradle (build.gradle) buildscript {repositories {mavenCentral() mavenLocal()// Only if you want to use

Simple to setup for ...4 Eclipse

4 IntelliJ IDEA

4 Maven / Gradle

4 Android Studio with Gradle

© arconsis IT-Solutions GmbH, 2014 5

Page 6: ntroduction to Datarobot for Android - SDJUGExample setup for Android Studio w/ Gradle (build.gradle) buildscript {repositories {mavenCentral() mavenLocal()// Only if you want to use

Example setup for Android Studio w/ Gradle (build.gradle)

buildscript { repositories { mavenCentral() mavenLocal()// Only if you want to use your local maven repo } dependencies { // Add annotation processor and android tools dependencies classpath 'com.android.tools.build:gradle:0.13.3' classpath 'com.neenbedankt.gradle.plugins:android-apt:1.4' }}allprojects { ...}

© arconsis IT-Solutions GmbH, 2014 6

Page 7: ntroduction to Datarobot for Android - SDJUGExample setup for Android Studio w/ Gradle (build.gradle) buildscript {repositories {mavenCentral() mavenLocal()// Only if you want to use

Configure the annotation processing (app/build.gradle)

apply plugin: 'android' //add the apt pluginapply plugin: 'android-apt' // the normal android sectionandroid { ... }

// configuration for the annotation prossecorapt { arguments { manifest '/path/to/AndroidManifest.xml' }}dependencies { // add datarobot dependencies apt 'com.arconsis:datarobot.processor:0.1.3-SNAPSHOT' compile 'com.arconsis:datarobot.api:0.1.3-SNAPSHOT' // ... more dependencies}

© arconsis IT-Solutions GmbH, 2014 7

Page 8: ntroduction to Datarobot for Android - SDJUGExample setup for Android Studio w/ Gradle (build.gradle) buildscript {repositories {mavenCentral() mavenLocal()// Only if you want to use

Generated sources are under:/app/build/source/apt/debug/your/package/generated/

© arconsis IT-Solutions GmbH, 2014 8

Page 9: ntroduction to Datarobot for Android - SDJUGExample setup for Android Studio w/ Gradle (build.gradle) buildscript {repositories {mavenCentral() mavenLocal()// Only if you want to use

First steps...

© arconsis IT-Solutions GmbH, 2014 9

Page 10: ntroduction to Datarobot for Android - SDJUGExample setup for Android Studio w/ Gradle (build.gradle) buildscript {repositories {mavenCentral() mavenLocal()// Only if you want to use

Creating a database@Create@Update@Persistence(dbName = "sdjug.db", dbVersion = 1)public class PersistenceConfig implements DbCreate, DbUpdate {

@Override public void onCreate(SQLiteDatabase db) { }

@Override public void onUpdate(SQLiteDatabase db, int oldVersion, int newVersion) { }}

© arconsis IT-Solutions GmbH, 2014 10

Page 11: ntroduction to Datarobot for Android - SDJUGExample setup for Android Studio w/ Gradle (build.gradle) buildscript {repositories {mavenCentral() mavenLocal()// Only if you want to use

Creating an entity@Entitypublic class Event { @PrimaryKey @AutoIncrement @Column private Integer _id; @Column private String name;

public Event() { }

...}

© arconsis IT-Solutions GmbH, 2014 11

Page 12: ntroduction to Datarobot for Android - SDJUGExample setup for Android Studio w/ Gradle (build.gradle) buildscript {repositories {mavenCentral() mavenLocal()// Only if you want to use

Creating an entity@Entity (authority = "com.arconsis.datarobotsdjug.event.provider", contentProvider = true, exported = false)public class Event { @PrimaryKey @AutoIncrement @Column private Integer _id; @Column private String name;

public Event() { }

...}

© arconsis IT-Solutions GmbH, 2014 12

Page 13: ntroduction to Datarobot for Android - SDJUGExample setup for Android Studio w/ Gradle (build.gradle) buildscript {repositories {mavenCentral() mavenLocal()// Only if you want to use

Storing an entity// Create an event POJOEvent event = new Event();event.setName("Event #1");

// Use EntityService to store event POJOEntityService<Event> entityService = new EntityService<Event>(this, Event.class);entityService.save(event);

© arconsis IT-Solutions GmbH, 2014 13

Page 14: ntroduction to Datarobot for Android - SDJUGExample setup for Android Studio w/ Gradle (build.gradle) buildscript {repositories {mavenCentral() mavenLocal()// Only if you want to use

Loading all entities// Use EntityService to load all eventsEntityService<Event> entityService = new EntityService<Event>(this, Event.class);List<Event> events = entityService.get();

© arconsis IT-Solutions GmbH, 2014 14

Page 15: ntroduction to Datarobot for Android - SDJUGExample setup for Android Studio w/ Gradle (build.gradle) buildscript {repositories {mavenCentral() mavenLocal()// Only if you want to use

Query entities4 Use standard Android ContentResolver

Cursor cursor = contentResolver.query( BaseContentProvider.uri(DB.EventTable.TABLE_NAME), null, DB.EventTable.NAME + "= ?", new String[]{"Event #1"}, null);

© arconsis IT-Solutions GmbH, 2014 15

Page 16: ntroduction to Datarobot for Android - SDJUGExample setup for Android Studio w/ Gradle (build.gradle) buildscript {repositories {mavenCentral() mavenLocal()// Only if you want to use

Convert to ObjectCursor4 Use CursorUtil to map cursor to POJO

Cursor cursor = contentResolver.query( ... );ObjectCursor<Event> objects = CursorUtil.getObjectCursor(cursor);

objects.moveToLast();objects.moveToPrevious();

Event event = objects.getCurrent();

© arconsis IT-Solutions GmbH, 2014 16

Page 17: ntroduction to Datarobot for Android - SDJUGExample setup for Android Studio w/ Gradle (build.gradle) buildscript {repositories {mavenCentral() mavenLocal()// Only if you want to use

Convert to collectionCursor cursor = contentResolver.query( ... );ObjectCursor<Event> objects = CursorUtil.getObjectCursor(cursor);

Collection<Event> events = objects.getAll();

© arconsis IT-Solutions GmbH, 2014 17

Page 18: ntroduction to Datarobot for Android - SDJUGExample setup for Android Studio w/ Gradle (build.gradle) buildscript {repositories {mavenCentral() mavenLocal()// Only if you want to use

Resolve Associations 1:1// Add relationship to Event

@Relationship private Place place;

© arconsis IT-Solutions GmbH, 2014 18

Page 19: ntroduction to Datarobot for Android - SDJUGExample setup for Android Studio w/ Gradle (build.gradle) buildscript {repositories {mavenCentral() mavenLocal()// Only if you want to use

Resolve Associations 1:1Event event = new Event();event.setName("SDJUG Meeting");

Place place = new Place();place.setPlaceName("Mira Mesa");event.setPlace(place);

EntityService<Event> entityService = new EntityService<Event>(this, Event.class);entityService.save(event);

for (Event e : entityService.get()) { entityService.resolveAssociations(e, 2); String placeName = e.getPlace().getPlaceName();}

© arconsis IT-Solutions GmbH, 2014 19

Page 20: ntroduction to Datarobot for Android - SDJUGExample setup for Android Studio w/ Gradle (build.gradle) buildscript {repositories {mavenCentral() mavenLocal()// Only if you want to use

Resolve Associations n:m// Add 1:n relationship to Event

@Relationship private Collection<Participant> participants = new LinkedList<Participant>();

© arconsis IT-Solutions GmbH, 2014 20

Page 21: ntroduction to Datarobot for Android - SDJUGExample setup for Android Studio w/ Gradle (build.gradle) buildscript {repositories {mavenCentral() mavenLocal()// Only if you want to use

Resolve Associations n:mEvent event = new Event(); event.setName("SDJUG Meeting");

Participant p1 = new Participant(); p1.setName("Paul");Participant p2 = new Participant(); p2.setName("Steve");

event.addParticipant(p1);event.addParticipant(p2);

(new EntityService<Event>(this, Event.class)).save(event);

for (Event e : entityService.get()) { entityService.resolveAssociations(e); int numberOfParticipants = e.getParticipants().size();}

© arconsis IT-Solutions GmbH, 2014 21

Page 22: ntroduction to Datarobot for Android - SDJUGExample setup for Android Studio w/ Gradle (build.gradle) buildscript {repositories {mavenCentral() mavenLocal()// Only if you want to use

Let's see how using Datarobot impacts

existing apps?!

© arconsis IT-Solutions GmbH, 2014 22

Page 23: ntroduction to Datarobot for Android - SDJUGExample setup for Android Studio w/ Gradle (build.gradle) buildscript {repositories {mavenCentral() mavenLocal()// Only if you want to use

Live-Demo the steps to transform the Notes app to Datarobot...

© arconsis IT-Solutions GmbH, 2014 23

Page 24: ntroduction to Datarobot for Android - SDJUGExample setup for Android Studio w/ Gradle (build.gradle) buildscript {repositories {mavenCentral() mavenLocal()// Only if you want to use

Roadmap4 Named relations

4 Bidirectional association

4 Fluent query api

4 Constraints for @Columns (e.g. not-null, unique)

4 Broadcast intents

4 Projection Support© arconsis IT-Solutions GmbH, 2014 24

Page 25: ntroduction to Datarobot for Android - SDJUGExample setup for Android Studio w/ Gradle (build.gradle) buildscript {repositories {mavenCentral() mavenLocal()// Only if you want to use

Thank you!github.com/arconsis/datarobot

[email protected]

@wolfgangfrank

© arconsis IT-Solutions GmbH, 2014 25

Page 26: ntroduction to Datarobot for Android - SDJUGExample setup for Android Studio w/ Gradle (build.gradle) buildscript {repositories {mavenCentral() mavenLocal()// Only if you want to use

arconsis?

© arconsis IT-Solutions GmbH, 2014 26

Page 27: ntroduction to Datarobot for Android - SDJUGExample setup for Android Studio w/ Gradle (build.gradle) buildscript {repositories {mavenCentral() mavenLocal()// Only if you want to use

www.arconsis.comMobile Enterprise

&Adaptive Enterprise

© arconsis IT-Solutions GmbH, 2014 27

Page 28: ntroduction to Datarobot for Android - SDJUGExample setup for Android Studio w/ Gradle (build.gradle) buildscript {repositories {mavenCentral() mavenLocal()// Only if you want to use

arconsis - services4 iOS & Android trainings (arconsis academy)

4 Mobile development (native + mobile web)

4 Mobile strategy & mobile UX

4 Agile coaching (Scrum, Lean, TDD, ...)

4 Software architecture (mainly Java/JEE)

© arconsis IT-Solutions GmbH, 2014 28