예제 #1
0
 /**
  * 创建DBLibrary
  *
  * @param context
  * @param dbName 数据库名称
  */
 public static KJDB create(Context context, String targetDirectory, String dbName) {
   DaoConfig config = new DaoConfig();
   config.setContext(context);
   config.setDbName(dbName);
   config.setTargetDirectory(targetDirectory);
   return create(config);
 }
예제 #2
0
 /**
  * 创建 DBLibrary
  *
  * @param context
  * @param dbName 数据库名称
  * @param isDebug 是否为debug模式(debug模式进行数据库操作的时候将会打印sql语句)
  */
 public static KJDB create(Context context, String dbName, boolean isDebug) {
   DaoConfig config = new DaoConfig();
   config.setContext(context);
   config.setDbName(dbName);
   config.setDebug(isDebug);
   return create(config);
 }
예제 #3
0
 private static synchronized KJDB getInstance(DaoConfig daoConfig) {
   KJDB dao = daoMap.get(daoConfig.getDbName());
   if (dao == null) {
     dao = new KJDB(daoConfig);
     daoMap.put(daoConfig.getDbName(), dao);
   }
   return dao;
 }
예제 #4
0
 private KJDB(DaoConfig config) {
   if (config == null) {
     throw new RuntimeException("daoConfig is null");
   }
   if (config.getContext() == null) {
     throw new RuntimeException("android context is null");
   }
   if (config.getTargetDirectory() != null && config.getTargetDirectory().trim().length() > 0) {
     this.db = createDbFileOnSDCard(config.getTargetDirectory(), config.getDbName());
   } else {
     this.db =
         new SqliteDbHelper(
                 config.getContext().getApplicationContext(),
                 config.getDbName(),
                 config.getDbVersion(),
                 config.getDbUpdateListener())
             .getWritableDatabase();
   }
   this.config = config;
 }
예제 #5
0
 /**
  * 标准创建器,创建DBLibrary
  *
  * @param context 上下文
  * @param targetDirectory db文件路径,可以配置为sdcard的路径
  * @param dbName 数据库名字
  * @param isDebug 是否是调试模式,调试模式会log出sql信息
  * @param dbVersion 数据库版本信息
  * @param dbUpdateListener 数据库升级监听器,如果监听器为null,升级的时候将会清空所所有的数据
  * @return
  */
 public static KJDB create(
     Context context,
     String targetDirectory,
     String dbName,
     boolean isDebug,
     int dbVersion,
     DbUpdateListener dbUpdateListener) {
   DaoConfig config = new DaoConfig();
   config.setContext(context);
   config.setTargetDirectory(targetDirectory);
   config.setDbName(dbName);
   config.setDebug(isDebug);
   config.setDbVersion(dbVersion);
   config.setDbUpdateListener(dbUpdateListener);
   return create(config);
 }
예제 #6
0
 private void debugSql(String sql) {
   if (config != null && config.isDebug()) android.util.Log.d("Debug SQL", ">>>>>>  " + sql);
 }
예제 #7
0
 /**
  * 创建DBLibrary
  *
  * @param context
  */
 public static KJDB create(Context context) {
   DaoConfig config = new DaoConfig();
   config.setContext(context);
   return create(config);
 }