|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectcom.j256.ormlite.android.apptools.OrmLiteConfigUtil
public class OrmLiteConfigUtil
Database configuration file helper class that is used to write a configuration file into the raw resource sub-directory to speed up DAO creation.
With help from the user list and especially Ian Dees, we discovered that calls to annotation methods in Android are _very_ expensive because Method.equals() was doing a huge toString(). This was causing folks to see 2-3 seconds startup time when configuring 10-15 DAOs because of 1000s of calls to @DatabaseField methods. See this Android bug report.
I added this utility class which writes a configuration file into the raw resource "res/raw" directory inside of your
project containing the table and field names and associated details. This file can then be loaded into the
DaoManager
with the help of the
OrmLiteSqliteOpenHelper.OrmLiteSqliteOpenHelper(android.content.Context, String, android.database.sqlite.SQLiteDatabase.CursorFactory, int, int)
constructor. This means that you can configure your classes _without_ any runtime calls to annotations. It seems
significantly faster.
WARNING: Although this is fast, the big problem is that you have to remember to regenerate the config file whenever you edit one of your database classes. There is no way that I know of to do this automagically.
Field Summary | |
---|---|
protected static int |
maxFindSourceLevel
Maximum recursion level while we are looking for source files. |
protected static String |
RAW_DIR_NAME
Raw directory name that we are looking for. |
protected static String |
RESOURCE_DIR_NAME
Resource directory name that we are looking for. |
Constructor Summary | |
---|---|
OrmLiteConfigUtil()
|
Method Summary | |
---|---|
protected static File |
findRawDir(File dir)
Look for the resource-directory in the current directory or the directories above. |
static void |
main(String[] args)
A call through to writeConfigFile(String) taking the file name from the single command line argument. |
static void |
writeConfigFile(File configFile)
Finds the annotated classes in the current directory or below and writes a configuration file. |
static void |
writeConfigFile(File configFile,
Class<?>[] classes)
Write a configuration file with the configuration for classes. |
static void |
writeConfigFile(File configFile,
File searchDir)
Finds the annotated classes in the specified search directory or below and writes a configuration file. |
static void |
writeConfigFile(OutputStream outputStream,
Class<?>[] classes)
Write a configuration file to an output stream with the configuration for classes. |
static void |
writeConfigFile(OutputStream outputStream,
File searchDir)
Write a configuration file to an output stream with the configuration for classes. |
static void |
writeConfigFile(String fileName)
Finds the annotated classes in the current directory or below and writes a configuration file to the file-name in the raw folder. |
static void |
writeConfigFile(String fileName,
Class<?>[] classes)
Writes a configuration fileName in the raw directory with the configuration for classes. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
protected static final String RESOURCE_DIR_NAME
protected static final String RAW_DIR_NAME
protected static int maxFindSourceLevel
Constructor Detail |
---|
public OrmLiteConfigUtil()
Method Detail |
---|
public static void main(String[] args) throws Exception
writeConfigFile(String)
taking the file name from the single command line argument.
Exception
public static void writeConfigFile(String fileName) throws SQLException, IOException
SQLException
IOException
public static void writeConfigFile(String fileName, Class<?>[] classes) throws SQLException, IOException
SQLException
IOException
public static void writeConfigFile(File configFile) throws SQLException, IOException
SQLException
IOException
public static void writeConfigFile(File configFile, File searchDir) throws SQLException, IOException
SQLException
IOException
public static void writeConfigFile(File configFile, Class<?>[] classes) throws SQLException, IOException
SQLException
IOException
public static void writeConfigFile(OutputStream outputStream, File searchDir) throws SQLException, IOException
SQLException
IOException
public static void writeConfigFile(OutputStream outputStream, Class<?>[] classes) throws SQLException, IOException
SQLException
IOException
protected static File findRawDir(File dir)
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |