public class OpenHelperManager extends Object
OrmLiteSqliteOpenHelperclass that is used to manage the database connection. The helper instance will be kept in a static field and only released once its internal usage count goes to 0. The
SQLiteOpenHelperand database classes maintain one connection under the hood, and prevent locks in the java code. Creating multiple connections can potentially be a source of trouble. This class shares the same connection instance between multiple clients, which will allow multiple activities and services to run at the same time. Every time you use the helper, you should call
getHelper(Context, Class). When you are done with the helper you should call
|Constructor and Description|
|Modifier and Type||Method and Description|
Create a static instance of our open helper from the helper class.
Set the helper for the manager.
If you are _not_ using the
public static void setOpenHelperClass(Class<? extends OrmLiteSqliteOpenHelper> openHelperClass)
OrmLiteBaseActivitytype classes then you will need to call this in a static method in your code.
public static void setHelper(OrmLiteSqliteOpenHelper helper)
public static <T extends OrmLiteSqliteOpenHelper> T getHelper(android.content.Context context, Class<T> openHelperClass)
releaseHelper(). This should be called during an onCreate() type of method when the application or service is starting. The caller should then keep the helper around until it is shutting down when
releaseHelper()should be called.
@Deprecated public static OrmLiteSqliteOpenHelper getHelper(android.content.Context context)
getHelper(Context, Class) (which is recommended) except we have to find the helper class
through other means. This method requires that the Context be a class that extends one of ORMLite's Android base
classes such as
OrmLiteBaseActivity. Either that or the helper class needs to be set in the strings.xml.
To find the helper class, this does the following:
setOpenHelperClass(Class), it will be used to construct a helper.
OrmLiteBaseActivityand other base classes.
public static void releaseHelper()
getHelper(Context, Class). This will decrement the usage counter and close the helper if the counter is 0.
WARNING: This should be called in an onDestroy() type of method when your application or service is
terminating or if your code is no longer going to use the helper or derived DAOs in any way. _Don't_ call this
method if you expect to call
getHelper(Context) again before the application terminates.
This documentation is licensed by Gray Watson under the Creative Commons Attribution-Share Alike 3.0 License.