protected List<AppItem> loadApps() {
   List<AppItem> result = new ArrayList<>();
   Iterator<ApplicationInfo> infoIterator = getAllAppInfos().iterator();
   try {
     while (infoIterator.hasNext()) {
       ApplicationInfo next = infoIterator.next();
       AppItem appitem = getAppItem(next);
       result.add(appitem);
     }
   } catch (SQLException | FileNotFoundException e) {
     e.printStackTrace();
   }
   return result;
 }
  private void checkCurrApps() {
    List<ApplicationInfo> allAppInfos = mDataManager.getAllAppInfos();
    List<AppItem> cache = mDataManager.getCache();
    for (ApplicationInfo next : allAppInfos) {
      boolean hasSave = false;
      for (AppItem appItem : cache) {
        if (appItem.getPackageName().equals(next.packageName)) {
          hasSave = true;
        }
      }

      if (!hasSave) {
        try {
          AppItem appItem = getAppItem(next);
          saveAppItem(appItem);
          LOGGER.i(TAG, "add = " + appItem);
        } catch (SQLException | FileNotFoundException e) {
          e.printStackTrace();
        }
      }
    }
  }
Exemple #3
0
  public static boolean initDatabase(Configuration config) {
    try (Connection connection = Database.getConnection(config);
        Statement statement = connection.createStatement()) {
      Scanner s = new Scanner(FileUtil.getInputStreamFrom(PATH_TO_SQL_SCRIPT));
      s.useDelimiter("(;(\r)?\n)|(--\n)");
      while (s.hasNext()) {
        String line = s.next();
        if (line.startsWith("/*!") && line.endsWith("*/")) {
          int i = line.indexOf(' ');
          line = line.substring(i + 1, line.length() - " */".length());
        }

        if (line.trim().length() > 0) {
          statement.execute(line);
        }
      }
    } catch (SQLException | FileNotFoundException ex) {
      ex.printStackTrace();
      return false;
    }
    return true;
  }