Giter Club home page Giter Club logo

greendaoforandroidstudio's Introduction

GreenDao Module for Android Studio

This project aims to provide a reusable instrument for easy and fast implementation of GreenDao database in every Android project. It consists of Java module - GreenDao database universal generator which is ready to be put in any project. By editing single line of code, point a path to your project where ready to use database files will be created. Usage of module is presented on exemplary project that is also included in the package.

Quick Setup

1. Download module

Pull the package with exemplary project and generator from GitHub.

2. Add module to project

Place MyDaoGenerator anywhere you like in your project tree.

3. Connect generator with project

By editing ONLY `outputDir` parameter in gradle.build file point the direction where database files should be created:
project(':MyDaoGenerator') {
    apply plugin: 'application'
    apply plugin: 'java'

    mainClassName = "pl.surecase.eu.MyDaoGenerator"
    // edit output direction
    outputDir = "../DaoExample/src/main/java-gen"

    dependencies {
        compile fileTree(dir: 'libs', include: ['*.jar'])
        compile('de.greenrobot:DaoGenerator:1.3.0')
    }

    task createDocs {
        def docs = file(outputDir)
        docs.mkdirs()
    }

    run {
        args outputDir
    }
}

Module provide DaoGenerator library on its own via Maven software tool. This library is necessary for creating GreenDao database files. Directory entered by user will be created if it doesn't exist and sent do java code as console argument.

4. Create database

MyDaoGenerator contains only one java class. It is a place where you can create your database accordingly to your needs. Example presented below is a creation of single object named Box that contains fields such as ID, Name, Slots and Description. You can learn how to modify this file by using [GreenDao documentation](http://greendao-orm.com/documentation/).
public class MyDaoGenerator {

    public static void main(String args[]) throws Exception {
        Schema schema = new Schema(3, "greendao");
        Entity box = schema.addEntity("Box");
        box.addIdProperty();
        box.addStringProperty("name");
        box.addIntProperty("slots");
        box.addStringProperty("description");
        new DaoGenerator().generateAll(schema, args[0]);
    }
} 

5. Run module

After pointing output path of your database files and creating your database code, you can run the module to generate files. Module isn't a part of your project. It is only a tool that you use to generate files - it isn't compiled during build of your project.
  • To run MyDaoGenerator go to Gradle task section in Android Studio.
  • Pick MyDaoGenerator from the Gradle project tree.
  • Chose run task.

gradleRun

  • Module has created files accordingly to content of MyDaoGenerator.class and in directory specified in outputDir parameter.

6. Make project aware of GreenDao files

To use GreenDao objects, project needs GreenDao library to be included.

or:

  • Add Maven code to gradle.build file.

      dependencies {
           compile 'de.greenrobot:greendao:1.3.7'
      }
    

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.