예제 #1
0
  /**
   * 描述:修改数据.
   *
   * @param <T> the generic type
   * @param storageQuery 条件实体
   * @param dao 实现AbDBDaoImpl的Dao
   * @param paramDataInsertListener 返回监听器
   */
  public <T> void deleteData(
      final AbStorageQuery storageQuery,
      final AbDBDaoImpl<T> dao,
      final AbDataOperationListener paramDataInsertListener) {

    AbTaskItem item = new AbTaskItem();
    item.callback =
        new AbTaskCallback() {

          @Override
          public void update() {
            if (retValue >= 0) {
              if (paramDataInsertListener != null) {
                paramDataInsertListener.onSuccess(retValue);
              }
            } else {
              if (paramDataInsertListener != null) {
                paramDataInsertListener.onFailure(errorCode101, errorMessage101);
              }
            }
          }

          @Override
          public void get() {
            // 执行插入
            // (1)获取数据库
            dao.startWritableDatabase(false);
            // (2)执行
            retValue = dao.delete(storageQuery.getWhereClause(), storageQuery.getWhereArgs());
            // (3)关闭数据库
            dao.closeDatabase(false);
          }
        };
    mAbTaskQueue.execute(item);
  }
예제 #2
0
  /**
   * Find data.
   *
   * @param <T> 描述:查询数据
   * @param storageQuery the storage query
   * @param dao 实现AbDBDaoImpl的Dao
   * @param paramDataInsertListener 返回监听器
   */
  public <T> void findData(
      final AbStorageQuery storageQuery,
      final AbDBDaoImpl<T> dao,
      final AbDataInfoListener paramDataInsertListener) {

    final AbTaskItem item = new AbTaskItem();
    item.callback =
        new AbTaskListCallback() {

          @Override
          public void update(List<?> paramList) {
            if (paramDataInsertListener != null) {
              paramDataInsertListener.onSuccess(paramList);
            }
          }

          @Override
          public void get() {
            List<?> list = null;
            // 执行插入
            // (1)获取数据库
            dao.startReadableDatabase(false);
            // (2)执行
            if (storageQuery.getLimit() != -1 && storageQuery.getOffset() != -1) {
              list =
                  dao.queryList(
                      null,
                      storageQuery.getWhereClause(),
                      storageQuery.getWhereArgs(),
                      storageQuery.getGroupBy(),
                      storageQuery.getHaving(),
                      storageQuery.getOrderBy()
                          + " limit "
                          + storageQuery.getLimit()
                          + " offset "
                          + storageQuery.getOffset(),
                      null);
            } else {
              list =
                  dao.queryList(
                      null,
                      storageQuery.getWhereClause(),
                      storageQuery.getWhereArgs(),
                      storageQuery.getGroupBy(),
                      storageQuery.getHaving(),
                      storageQuery.getOrderBy(),
                      null);
            }
            // (3)关闭数据库
            dao.closeDatabase(false);

            // 设置返回结果
            item.setResult(list);
          }
        };
    mAbTaskQueue.execute(item);
  }
예제 #3
0
  /**
   * 描述:插入数据.
   *
   * @param <T> the generic type
   * @param entity 实体类 设置了对象关系映射
   * @param dao 实现AbDBDaoImpl的Dao
   * @param paramDataInsertListener 返回监听器
   */
  public <T> void insertData(
      final T entity,
      final AbDBDaoImpl<T> dao,
      final AbDataInsertListener paramDataInsertListener) {

    if (entity != null) {

      AbTaskItem item = new AbTaskItem();
      item.callback =
          new AbTaskCallback() {

            @Override
            public void update() {
              if (retValue >= 0) {
                if (paramDataInsertListener != null) {
                  paramDataInsertListener.onSuccess(retValue);
                }
              } else {
                if (paramDataInsertListener != null) {
                  paramDataInsertListener.onFailure(errorCode101, errorMessage101);
                }
              }
            }

            @Override
            public void get() {
              // 执行插入
              // (1)获取数据库
              dao.startWritableDatabase(false);
              // (2)执行
              retValue = dao.insert(entity);
              // (3)关闭数据库
              dao.closeDatabase(false);
            }
          };
      mAbTaskQueue.execute(item);

    } else {
      if (paramDataInsertListener != null) {
        paramDataInsertListener.onFailure(errorCode100, errorMessage100);
      }
    }
  }
예제 #4
0
  @Override
  public void onStart() {
    super.onStart();
    // 定义两种查询的事件
    final AbTaskItem item1 = new AbTaskItem();
    item1.callback =
        new AbTaskCallback() {

          @Override
          public void update() {
            list.clear();
            if (newList != null && newList.size() > 0) {
              list.addAll(newList);
              myListViewAdapter.notifyDataSetChanged();
              newList.clear();
            }
            mAbPullListView.stopRefresh();
          }

          @Override
          public void get() {
            try {
              Thread.sleep(1000);
              currentPage = 1;
              newList = new ArrayList<Map<String, Object>>();
              Map<String, Object> map = null;

              for (int i = 0; i < 10; i++) {
                map = new HashMap<String, Object>();
                map.put("itemsIcon", mPhotoList.get(new Random().nextInt(mPhotoList.size())));
                map.put("itemsTitle", "item" + i);
                map.put("itemsText", "item..." + i);
                newList.add(map);
              }
            } catch (Exception e) {
            }
          };
        };

    final AbTaskItem item2 = new AbTaskItem();
    item2.callback =
        new AbTaskCallback() {

          @Override
          public void update() {
            if (newList != null && newList.size() > 0) {
              list.addAll(newList);
              myListViewAdapter.notifyDataSetChanged();
              newList.clear();
              mAbPullListView.stopLoadMore(true);
            } else {
              // 没有新数据了
              mAbPullListView.stopLoadMore(false);
            }
          }

          @Override
          public void get() {
            try {
              currentPage++;
              Thread.sleep(1000);
              newList = new ArrayList<Map<String, Object>>();
              Map<String, Object> map = null;

              for (int i = 0; i < 10; i++) {
                map = new HashMap<String, Object>();
                map.put("itemsIcon", mPhotoList.get(new Random().nextInt(mPhotoList.size())));
                map.put("itemsTitle", "item上拉" + i);
                map.put("itemsText", "item上拉..." + i);
                newList.add(map);
              }
            } catch (Exception e) {
              currentPage--;
              newList.clear();
            }
          };
        };

    mAbPullListView.setAbOnListViewListener(
        new AbOnListViewListener() {

          @Override
          public void onRefresh() {
            mAbTaskQueue.execute(item1);
          }

          @Override
          public void onLoadMore() {
            mAbTaskQueue.execute(item2);
          }
        });

    // 第一次下载数据
    mAbTaskQueue.execute(item1);
  }