package orz.sorz.lab.smallcloudemoji.daogenerator;

import de.greenrobot.daogenerator.DaoGenerator;
import de.greenrobot.daogenerator.Entity;
import de.greenrobot.daogenerator.Property;
import de.greenrobot.daogenerator.Schema;
import de.greenrobot.daogenerator.ToMany;

public class AppDaoGenerator {

    public static void main(String[] args) throws Exception {
        Schema schema = new Schema(1, "org.sorz.lab.smallcloudemoji.db");

        addEntities(schema);

        new DaoGenerator().generateAll(schema, "app/src-gen");
    }

    private static void addEntities(Schema schema) {
        Entity repository = schema.addEntity("Repository");
        repository.addIdProperty().index();
        repository.addStringProperty("url").notNull().unique().index();
        repository.addStringProperty("alias");
        repository.addBooleanProperty("hidden").index();
        repository.addIntProperty("order");
        repository.addDateProperty("lastUpdateDate");

        Entity category = schema.addEntity("Category");
        category.addIdProperty().index();
        category.addStringProperty("name");
        category.addBooleanProperty("hidden").index();
        category.addDateProperty("lastUpdateDate").index();
        Property repositoryId = category.addLongProperty("repositoryId").index().getProperty();
        category.addToOne(repository, repositoryId);

        ToMany repositoryToCategories = repository.addToMany(category, repositoryId);
        repositoryToCategories.setName("categories");

        Entity entry = schema.addEntity("Entry");
        entry.addIdProperty().index();
        entry.addStringProperty("emoticon").notNull();
        entry.addStringProperty("description");
        entry.addBooleanProperty("star").index();
        Property lastUsed = entry.addDateProperty("lastUsed").indexDesc(null, false).getProperty();
        entry.addDateProperty("lastUpdateDate").index();
        Property categoryId = entry.addLongProperty("categoryId").index().getProperty();
        entry.addToOne(category, categoryId);

        ToMany categoryToEntries = category.addToMany(entry, categoryId);
        categoryToEntries.setName("entries");
        categoryToEntries.orderDesc(lastUsed);
    }

}

@@ -461,16 +461,44 @@
 schema);
+%0A        addSources(schema);
 %0A%0A      
@@ -2250,10 +2250,796 @@
 %0A    %7D%0A%0A
+    private static void addSources(Schema schema) %7B%0A        Entity source = schema.addEntity(%22Source%22);%0A        source.addIdProperty().index();%0A        source.addStringProperty(%22name%22).notNull();%0A        source.addStringProperty(%22iconUrl%22);%0A        source.addDateProperty(%22postDate%22);%0A        source.addStringProperty(%22introduction%22);%0A        source.addStringProperty(%22creator%22);%0A        source.addStringProperty(%22creatorUrl%22);%0A        source.addStringProperty(%22server%22);%0A        source.addStringProperty(%22serverUrl%22);%0A        source.addStringProperty(%22dataFormat%22);%0A        source.addStringProperty(%22installUrl%22);%0A        source.addStringProperty(%22codeUrl%22).index().notNull();%0A        source.addStringProperty(%22storeUrl%22);%0A        source.addBooleanProperty(%22installed%22).index();%0A    %7D%0A
 %7D%0A

Add source entity to database