aivarsda / GreenDAOGenerator

Android Green DAO Generator example

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Green DAO Generator Example

This is a simple yet flexible framework for the Green DAO Generator:

  • All entities have Serializable implementation.
  • Ability to generate several schemas to the project.
  • Ability to generate for several projects. (Handling different projects from one place)

How To Use

  • 1. Generator class :
    In the Generator class, add the default output project path.
private final static String DEFAULT_PROJ_OUTPUT_PATH = "../../_fwGreenDAO/src";
  • 2. Adding the schemas:
/**
 * Here is the ERD for the Store schema:
 *	 ----------        ----------
 *	| Customer | ---< | Purchase |
 *	 ----------        ----------
 *	                       |
 *						   |
 *						  / \
 *				     --------------
 *				    | ProductOrder |
 *				     --------------
 *						  \ /
 *						   |
 *						   |
 *				       ---------
 *				      | Product |
 *				       ---------	
 */

Providing the "output_package" in the destination project.
By default DAO files will be placed in "output_package.dao" package.
If needed, you can change it by overriding the initSchema() method in the concrete schema class.

private List <Schema> getSchemas()
	{
		List <Schema> schemaList = new ArrayList<Schema>();
		schemaList.add(new StoreSchema(1, "com.aivarsda.greendao_fw.orm.store",DEFAULT_PROJ_OUTPUT_PATH));
		schemaList.add(new TreeSchema(1, "com.aivarsda.greendao_fw.orm.tree",DEFAULT_PROJ_OUTPUT_PATH));
		
		// You may generate for several projects.
		// Pass another project output path via constructor.
		schemaList.add(new StoreSchema(1,"com.aivarsda.anotherproj.orm.store","../../_anotherproj/src"));
		
		return schemaList;
	}
  • 3. Generating the schemas:
public void generate()
{
	List <Schema> schemaList = getSchemas();
try 
{
	for (int i=0; i<schemaList.size(); i++)
	{
		Schema schema = schemaList.get(i);
		new DaoGenerator().generateAll(schema, ((AGenSchema)schema).getOutRelativePath());
	}
} 
catch (Exception e) {
    e.printStackTrace();
}
}

Contact Developer

Aivars Dalderis

About

Android Green DAO Generator example


Languages

Language:Java 100.0%