Skip to content

Instantly share code, notes, and snippets.

@keima
Created November 19, 2014 06:21
Show Gist options
  • Save keima/3c6fd6c3dc8ec6c2e1be to your computer and use it in GitHub Desktop.
Save keima/3c6fd6c3dc8ec6c2e1be to your computer and use it in GitHub Desktop.
package com.example
import de.greenrobot.daogenerator.DaoGenerator
import de.greenrobot.daogenerator.Entity
import de.greenrobot.daogenerator.Schema
public class MyDaoGenerator {
static int SCHEMA_VERSION = 1;
static String SCHEMA_PACKAGE_NAME = "net.pside.android.example.mostpowerfulorminandroid";
public static void main(String[] args) throws Exception {
println "Generating greenDAO Schema and Entities..."
println "> Setup Schema: ${SCHEMA_PACKAGE_NAME} : ${SCHEMA_VERSION}"
Schema schema = new Schema(SCHEMA_VERSION, SCHEMA_PACKAGE_NAME);
println "> Setup Entity: Simple"
Entity simple = schema.addEntity("Simple");
simple.addIdProperty();
simple.addStringProperty("stringValue");
simple.addDateProperty("dateValue");
simple.addBooleanProperty("booleanValue");
simple.addByteArrayProperty("blobValue");
simple.addShortProperty("shortValue");
simple.addIntProperty("intValue");
simple.addLongProperty("longValue");
simple.addFloatProperty("floatValue");
simple.addDoubleProperty("doubleValue");
def entities = new Entity[5];
def entityNames = [
"ChildOne",
"ChildTwo",
"ChildThree",
"ChildFour",
"ChildFive",
]
// addEntityとaddPropertyを分ける(ひとつに纏めることもできるけどここは速度重視でもないし。。。)
entities.eachWithIndex { Entity entity, int i ->
entities[i] = schema.addEntity(entityNames[i])
}
entityNames.eachWithIndex() { String entityName, int i ->
println "> Setup Entity: ${entityName}"
Entity entity = entities[i]
entity.addIdProperty()
if (entityName.equals("ChildFive")) {
entity.addStringProperty("ormName")
} else {
def property = entity.addLongProperty(entityNames[i + 1] + "Id").getProperty()
entity.addToOne(entities[i], property)
}
}
println "> Generating Schema and Entity: ${args[0]}"
new DaoGenerator().generateAll(schema, args[0]);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment