http://my.oschina.net/u/1052509/blog/312635
package pl.surecase.eu;
/**
* Created by Nijugon on 2015/2/19.
*/
import de.greenrobot.daogenerator.DaoGenerator;
import de.greenrobot.daogenerator.Entity;
import de.greenrobot.daogenerator.Property;
import de.greenrobot.daogenerator.PropertyType;
import de.greenrobot.daogenerator.Schema;
import de.greenrobot.daogenerator.ToMany;
public class MyDaoGenerator {
public static void main(String[] args) throws Exception {
//Schema schema = new Schema(version, defaultJavaPackageme);
Schema schema = new Schema(1, "greendao");
setNews(schema);
setUserHistory(schema);
setCategoryAndProduct(schema);
new DaoGenerator().generateAll(schema,"../app/src/main/java-gen");
}
private static void setCategoryAndProduct(Schema schema) {
Entity category = schema.addEntity("Category");
category.addIdProperty().primaryKey().autoincrement();
category.addIntProperty("pcId");//http://www.suntone.com.tw/ProdClass.aspx?PC_ID=1
category.addStringProperty("name");
category.addStringProperty("topBannerUrl");
category.addStringProperty("topBannerName");
category.addStringProperty("sourceUrl");
Entity product = schema.addEntity("Product");
product.addIdProperty().primaryKey().autoincrement();
product.addIntProperty("pNo");
product.addStringProperty("name");
product.addStringProperty("price");
product.addStringProperty("url");
product.addStringProperty("sheifLife");
product.addStringProperty("matertial");
product.addStringProperty("imgUrl");
product.addStringProperty("imgName");
product.addStringProperty("buyAmount");
Property productProperty = product.addLongProperty("categoryId")
.notNull().getProperty();
category.addToMany(product,productProperty,"productsInCategory");//這個one to many關係的名稱
}
private static Entity setNews(Schema schema) {
Entity entity = schema.addEntity("News");
entity.addIdProperty().primaryKey().autoincrement();
entity.addStringProperty("pageId");
entity.addStringProperty("title");
entity.addStringProperty("annosDate");
entity.addStringProperty("content");
return entity;
}
private static Entity setUserHistory(Schema schema) {
Entity entity = schema.addEntity("UserHistory");
entity.addIdProperty().primaryKey().autoincrement();
entity.addStringProperty("type");
entity.addStringProperty("methodName");
entity.addDateProperty("time");
return entity;
}
}
沒有留言:
張貼留言