Beispiel #1
0
  private static synchronized DbUtils getInstance(DaoConfig daoConfig) {
    DbUtils dao = daoMap.get(daoConfig.getDbName());
    if (dao == null) {
      dao = new DbUtils(daoConfig);
      daoMap.put(daoConfig.getDbName(), dao);
    } else {
      dao.daoConfig = daoConfig;
    }

    // update the database if needed
    SQLiteDatabase database = dao.database;
    int oldVersion = database.getVersion();
    int newVersion = daoConfig.getDbVersion();
    if (oldVersion != newVersion) {
      if (oldVersion != 0) {
        DbUpgradeListener upgradeListener = daoConfig.getDbUpgradeListener();
        if (upgradeListener != null) {
          upgradeListener.onUpgrade(dao, oldVersion, newVersion);
        } else {
          try {
            dao.dropDb();
          } catch (DbException e) {
            LogUtils.e(e.getMessage(), e);
          }
        }
      }
      database.setVersion(newVersion);
    }

    return dao;
  }
 public static void saveHotel(Context context, List<Hotel> hotelList) {
   DbUtils db = DbUtils.create(context);
   try {
     db.saveOrUpdateAll(hotelList);
   } catch (DbException e) {
     e.printStackTrace();
   }
 }
 public static List<Banquet> getBanquetsByHotelId(Context context, String hotelId) {
   DbUtils db = DbUtils.create(context);
   try {
     return db.findAll(Selector.from(Banquet.class).where("hotelId", "=", hotelId));
   } catch (DbException e) {
     e.printStackTrace();
     return null;
   }
 }
Beispiel #4
0
 private void saveDoc(DocInfoBean docInfoBean) {
   // TODO Auto-generated method stub
   // DbUtils dbUtils = new DbUtils(null);
   DbUtils db = DBUtilsHelper.getInstance().getDb();
   try {
     db.createTableIfNotExist(DocInfoBean.class);
     db.save(docInfoBean);
   } catch (DbException e) {
     // TODO Auto-generated catch block
     e.printStackTrace();
   }
 }
 /*package*/ DownloadManager(Context appContext) {
   ColumnConverterFactory.registerColumnConverter(
       HttpHandler.State.class, new HttpHandlerStateConverter());
   mContext = appContext;
   db = DbUtils.create(mContext);
   try {
     downloadInfoList = db.findAll(Selector.from(DownloadInfo.class));
   } catch (DbException e) {
     LogUtils.e(e.getMessage(), e);
   }
   if (downloadInfoList == null) {
     downloadInfoList = new ArrayList<DownloadInfo>();
   }
 }
 /**
  * 以一天缓存一次策略,判断当天是否缓存过
  *
  * @param context
  * @param tag 页面名称
  * @return true:已经缓存过, 不需要再缓存 false:未缓存过,需要缓存操作
  */
 public static boolean todayChecked(Context context, String tag) {
   DbUtils db = DbUtils.create(context);
   try {
     Cache cache = db.findFirst(Selector.from(Cache.class).where("pageName", "=", tag));
     if (cache == null) return false;
     String todayStr = getToday();
     if (todayStr.equals(cache.getDate())) {
       return true;
     } else {
       return false;
     }
   } catch (DbException e) {
     e.printStackTrace();
     return false;
   }
 }
 public void removeDownload(DownloadInfo downloadInfo) throws DbException {
   HttpHandler<File> handler = downloadInfo.getHandler();
   if (handler != null && !handler.isCancelled()) {
     handler.cancel();
   }
   downloadInfoList.remove(downloadInfo);
   db.delete(downloadInfo);
 }
 public void backupDownloadInfoList() throws DbException {
   for (DownloadInfo downloadInfo : downloadInfoList) {
     HttpHandler<File> handler = downloadInfo.getHandler();
     if (handler != null) {
       downloadInfo.setState(handler.getState());
     }
   }
   db.saveOrUpdateAll(downloadInfoList);
 }
 public void stopDownload(DownloadInfo downloadInfo) throws DbException {
   HttpHandler<File> handler = downloadInfo.getHandler();
   if (handler != null && !handler.isCancelled()) {
     handler.cancel();
   } else {
     downloadInfo.setState(HttpHandler.State.CANCELLED);
   }
   db.saveOrUpdate(downloadInfo);
 }
 public void insert(List<Comment> list) {
   try {
     for (int i = 0; i < list.size(); i++) {
       Comment commentItem = list.get(i);
       Comment findItem =
           db.findFirst(
               Selector.from(Comment.class).where("commentId", "=", commentItem.getCommentId()));
       if (findItem != null) {
         db.update(commentItem, WhereBuilder.b("commentId", "=", commentItem.getCommentId()));
       } else {
         db.save(commentItem);
       }
     }
   } catch (DbException e) {
     // TODO Auto-generated catch block
     e.printStackTrace();
   }
 }
 public void stopDownload(DownloadInfo downloadInfo) throws DbException {
   HttpHandler<File> handler = downloadInfo.getHandler();
   if (handler != null && !handler.isStopped()) {
     handler.stop();
   } else {
     downloadInfo.setState(HttpHandler.State.STOPPED);
   }
   db.saveOrUpdate(downloadInfo);
 }
  public List<Comment> query(int page) {
    try {
      List<Comment> list = db.findAll(Selector.from(Comment.class).limit(20 * page));
      return list;
    } catch (DbException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
    }

    return null;
  }
 // Quit Unity
 @Override
 protected void onDestroy() {
   System.out.println("---UnityonDestroy");
   DbUtils dbUtils = DbUtils.create(this);
   LocalPlay localPlay = new LocalPlay();
   localPlay.setNowplayUrl("");
   localPlay.setQingxidu("");
   localPlay.setSdurl("");
   localPlay.setHdrul("");
   localPlay.setUhdrul("");
   localPlay.setType("");
   localPlay.setUnityJump(true);
   try {
     dbUtils.saveOrUpdate(localPlay);
   } catch (DbException e) {
     e.printStackTrace();
   }
   mUnityPlayer.quit();
   super.onDestroy();
 }
Beispiel #14
0
 public void resumeDownload(DownloadInfo downloadInfo, final RequestCallBack<File> callback)
     throws DbException {
   HttpUtils http = new HttpUtils();
   http.configRequestThreadPoolSize(maxDownloadThread);
   HttpHandler<File> handler =
       http.download(
           downloadInfo.getDownloadUrl(),
           downloadInfo.getFileSavePath(),
           downloadInfo.isAutoResume(),
           downloadInfo.isAutoRename(),
           new ManagerCallBack(downloadInfo, callback));
   downloadInfo.setHandler(handler);
   downloadInfo.setState(handler.getState());
   db.saveOrUpdate(downloadInfo);
 }
Beispiel #15
0
  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.chat_comment);
    dbUtils = DBUtilsHelper.getInstance().getDb();
    Intent i = getIntent();
    if (null != i) {
      subjectID = i.getExtras().getString("subjectId");
      try {
        chatInfoBean =
            dbUtils.findFirst(Selector.from(ChatInfoBean.class).where("SubjectID", "=", subjectID));

        if (null != chatInfoBean) {
          subjectType = chatInfoBean.getSubjectType();
        }
      } catch (DbException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
      }
    }
    initView();
    initListener();
    listenET();
  }
Beispiel #16
0
 public void addNewDownload(
     String url,
     String fileName,
     String target,
     boolean autoResume,
     boolean autoRename,
     final RequestCallBack<File> callback)
     throws DbException {
   final DownloadInfo downloadInfo = new DownloadInfo();
   downloadInfo.setDownloadUrl(url);
   downloadInfo.setAutoRename(autoRename);
   downloadInfo.setAutoResume(autoResume);
   downloadInfo.setFileName(fileName);
   downloadInfo.setFileSavePath(target);
   HttpUtils http = new HttpUtils();
   http.configRequestThreadPoolSize(maxDownloadThread);
   HttpHandler<File> handler =
       http.download(
           url, target, autoResume, autoRename, new ManagerCallBack(downloadInfo, callback));
   downloadInfo.setHandler(handler);
   downloadInfo.setState(handler.getState());
   downloadInfoList.add(downloadInfo);
   db.saveBindingId(downloadInfo);
 }
Beispiel #17
0
  private void testDb() {

    SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");

    Parent parent = new Parent();
    parent.name = "测试";
    parent.isVIP = false;
    parent.setAdmin(true);
    parent.setEmail("*****@*****.**");

    /*Parent parent2 = new Parent();
    parent2.name = "测试2";
    parent2.isVIP = false;*/

    try {

      DbUtils db = DbUtils.create(this);
      db.configAllowTransaction(true);

      Child child = new Child();
      child.name = "child name";
      // db.saveBindingId(parent);
      // child.parent = new SQLiteLazyLoader<Parent>(Child.class, "parentId", parent.getId());
      child.parent = parent;

      try {
        Parent test = db.findFirst(parent); // 通过entity的属性查找
        LogUtils.d("wyouflf :" + test);
      } catch (Exception e) {
        LogUtils.e(e.getMessage(), e);
      }

      parent.setTime(new Date());
      parent.setTime2(new java.sql.Date(new Date().getTime()));

      db.saveBindingId(child); // 保存对象关联数据库生成的id

      List<Child> children = db.findAll(Selector.from(Child.class));
      LogUtils.d("wyouflf size:" + children.size());
      if (children.size() > 0) {
        LogUtils.d("wyouflf child:" + children.get(children.size() - 1).parent);
      }

      List<Parent> list =
          db.findAll(
              Selector.from(Parent.class)
                  .where(WhereBuilder.b("id", "<", 54))
                  .orderBy("id")
                  .limit(10));
      LogUtils.d("wyouflf size:" + list.size());
      if (list.size() > 0) {
        LogUtils.d("wyouflf parent:" + list.get(list.size() - 1).toString());
      }

      // parent.name = "hahaha123";
      // db.update(parent);

      Parent entity = db.findById(Parent.class, parent.getId());
      LogUtils.d("wyouflf parent:" + entity.toString());

      List<DbModel> dbModels =
          db.findDbModelAll(
              Selector.from(Parent.class).groupBy("name").select("name", "count(name)"));
      LogUtils.d("wyouflf:" + dbModels.size());

    } catch (DbException e) {
      LogUtils.e(e.getMessage(), e);
    }
  }
 public BlogCommentDaoImpl(Context context, String filename) {
   // TODO Auto-generated method stub
   db = DbUtils.create(context, CacheManager.getBlogCommentDbPath(context), filename + "_comment");
 }