public class OrmLiteConfigUtil extends Object
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.
Modifier and Type | Field and Description |
---|---|
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 and Description |
---|
OrmLiteConfigUtil() |
Modifier and Type | Method and Description |
---|---|
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(File, boolean) . |
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,
boolean sortClasses)
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,
Class<?>[] classes,
boolean sortClasses)
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(File configFile,
File searchDir,
boolean sortClasses)
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,
Class<?>[] classes,
boolean sortClasses)
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(OutputStream outputStream,
File searchDir,
boolean sortClasses)
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,
boolean sortClasses)
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.
|
static void |
writeConfigFile(String fileName,
Class<?>[] classes,
boolean sortClasses)
Writes a configuration fileName in the raw directory with the configuration for classes.
|
protected static final String RESOURCE_DIR_NAME
protected static final String RAW_DIR_NAME
protected static int maxFindSourceLevel
public static void main(String[] args) throws Exception
writeConfigFile(File, boolean)
. It takes an optional "-s" argument which turns on
sorting of classes by name to produce more deterministic output followed by the name of the output config file.Exception
public static void writeConfigFile(String fileName) throws SQLException, IOException
SQLException
IOException
public static void writeConfigFile(String fileName, boolean sortClasses) throws SQLException, IOException
sortClasses
- Set to true to sort the classes by name before the file is generated.SQLException
IOException
public static void writeConfigFile(String fileName, Class<?>[] classes) throws SQLException, IOException
SQLException
IOException
public static void writeConfigFile(String fileName, Class<?>[] classes, boolean sortClasses) throws SQLException, IOException
sortClasses
- Set to true to sort the classes by name before the file is generated.SQLException
IOException
public static void writeConfigFile(File configFile) throws SQLException, IOException
SQLException
IOException
public static void writeConfigFile(File configFile, boolean sortClasses) throws SQLException, IOException
sortClasses
- Set to true to sort the classes by name before the file is generated.SQLException
IOException
public static void writeConfigFile(File configFile, File searchDir) throws SQLException, IOException
SQLException
IOException
public static void writeConfigFile(File configFile, File searchDir, boolean sortClasses) throws SQLException, IOException
sortClasses
- Set to true to sort the classes by name before the file is generated.SQLException
IOException
public static void writeConfigFile(File configFile, Class<?>[] classes) throws SQLException, IOException
SQLException
IOException
public static void writeConfigFile(File configFile, Class<?>[] classes, boolean sortClasses) throws SQLException, IOException
sortClasses
- Set to true to sort the classes by name before the file is generated.SQLException
IOException
public static void writeConfigFile(OutputStream outputStream, File searchDir) throws SQLException, IOException
SQLException
IOException
public static void writeConfigFile(OutputStream outputStream, File searchDir, boolean sortClasses) throws SQLException, IOException
sortClasses
- Set to true to sort the classes by name before the file is generated.SQLException
IOException
public static void writeConfigFile(OutputStream outputStream, Class<?>[] classes) throws SQLException, IOException
SQLException
IOException
public static void writeConfigFile(OutputStream outputStream, Class<?>[] classes, boolean sortClasses) throws SQLException, IOException
sortClasses
- Set to true to sort the classes and fields by name before the file is generated.SQLException
IOException
This documentation is licensed by Gray Watson under the Creative Commons Attribution-Share Alike 3.0 License.