Skip to content

Instantly share code, notes, and snippets.

@rafayali
Last active January 6, 2016 12:15
Show Gist options
  • Save rafayali/cffe6412bb0c683d8c39 to your computer and use it in GitHub Desktop.
Save rafayali/cffe6412bb0c683d8c39 to your computer and use it in GitHub Desktop.
A standalone java app to create configuration of OrmLite for android
public class OrmLiteConfigurationApp extends OrmLiteConfigUtil{
/**
* classes represents the models to use for generating the ormlite_config.txt file
*/
private static final Class<?>[] classes = new Class[] {TimeEntries.class};
/**
* Given that this is a separate program from the android app, we have to use
* a static main java method to create the configuration file.
* @param args
* @throws IOException
* @throws SQLException
*/
public static void main(String[] args) throws IOException, SQLException {
String currDirectory = "user.dir";
String configPath = "/app/src/main/res/raw/ormlite_config.txt";
/**
* Gets the project root directory
*/
String projectRoot = System.getProperty(currDirectory);
/**
* Full configuration path includes the project root path, and the location
* of the ormlite_config.txt file appended to it
*/
String fullConfigPath = projectRoot + configPath;
File configFile = new File(fullConfigPath);
/**
* In the a scenario where we run this program serveral times, it will recreate the
* configuration file each time with the updated configurations.
*/
if(configFile.exists()) {
configFile.delete();
configFile = new File(fullConfigPath);
}
/**
* writeConfigFile is a util method used to write the necessary configurations
* to the ormlite_config.txt file.
*/
writeConfigFile(configFile, classes);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment