示例#1
0
 private void waitForBatches(
     DataLoadTimeSummary dataLoadTimeSummary,
     Scenario scenario,
     long start,
     List<Future> writeBatches)
     throws InterruptedException, java.util.concurrent.ExecutionException {
   int sumRows = 0, sumDuration = 0;
   // Wait for all the batch threads to complete
   for (Future<Info> write : writeBatches) {
     Info writeInfo = write.get();
     sumRows += writeInfo.getRowCount();
     sumDuration += writeInfo.getDuration();
     logger.info(
         "Executor ("
             + this.hashCode()
             + ") writes complete with row count ("
             + writeInfo.getRowCount()
             + ") in Ms ("
             + writeInfo.getDuration()
             + ")");
   }
   logger.info(
       "Writes completed with total row count ("
           + sumRows
           + ") with total time of("
           + sumDuration
           + ") Ms");
   dataLoadTimeSummary.add(
       scenario.getTableName(), sumRows, (int) (System.currentTimeMillis() - start));
 }
  public void addInfo(Info addedInfo) {
    Log.i("dataBase", "called method addInfo");

    initColumns();

    Log.i("id", idCollumIndex + "");
    Log.i("id", authorCollumIndex + "");
    Log.i("id", nameCollumIndex + "");
    Log.i("id", likesCountCollumIndex + "");
    Log.i("id", artworkUrlCollumIndex + "");
    Log.i("id", streamUrlCollumIndex + "");
    Log.i("id", durationCollumIndex + "");
    Log.i("id", pathToFileCollumIndex + "");
    cursor = musicBase.query("mytable", null, null, null, null, null, null);

    if (cursor.moveToFirst()) {
      Log.i("dataBase", "cursor moved to first");

      do {
        Info tempInfo =
            new Info(
                cursor.getString(nameCollumIndex),
                cursor.getInt(durationCollumIndex),
                new User(cursor.getString(authorCollumIndex)),
                cursor.getInt(likesCountCollumIndex),
                cursor.getString(streamUrlCollumIndex),
                cursor.getString(pathToFileCollumIndex),
                cursor.getString(artworkUrlCollumIndex));
        Log.i("dataBase info", "addedInfo________" + addedInfo.getStream_url());
        Log.i("dataBase info", "tempInfo________" + tempInfo.getStream_url());

        Log.i("dataBase list", tempInfo.toString());
        Log.i("dataBase list", addedInfo.toString());
        if (addedInfo.getStream_url().equals(tempInfo.getStream_url())) {
          Log.i("dataBase", "we have this music");
          return;
        }

      } while (cursor.moveToNext());
    }

    Calendar c = Calendar.getInstance();
    String seconds =
        c.get(Calendar.YEAR)
            + ""
            + c.get(Calendar.MONTH)
            + ""
            + c.get(Calendar.DAY_OF_MONTH)
            + ""
            + c.get(Calendar.HOUR_OF_DAY)
            + ""
            + c.get(Calendar.MINUTE)
            + ""
            + c.get(Calendar.SECOND);
    Log.i("dataBase", seconds);
    String name = addedInfo.getTitle();
    File dir = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_MUSIC);
    File myFile = new File(dir, name + ".mp3");

    try {
      myFile.createNewFile();
      Log.i("dataBase", "file created");
    } catch (IOException e) {
      e.printStackTrace();
      Log.i("dataBase", e.toString());
      Log.i("dataBase", "file not created");
      return;
    }

    if (myFile.exists()) {

      Log.i("dataBase", "started downloading");
      DownloadService.downloadFile(
          addedInfo.getStream_url() + "?client_id=b45b1aa10f1ac2941910a7f0d10f8e28", myFile);

      addedInfo.setPath_to_file(myFile.getAbsolutePath());
      Log.i("dataBase", "file created");
    } else {
      Log.i("dataBase", "file not found");
      return;
    }

    Log.i("dataBase FileInfo", myFile.getAbsolutePath());

    ContentValues values = new ContentValues();
    values.put("author", addedInfo.getUser().getUsername());
    values.put("name", addedInfo.getTitle());
    values.put("likesCount", addedInfo.getLikes_count());
    values.put("duration", addedInfo.getDuration());
    values.put("artworkUrl", addedInfo.getPath_to_file());
    values.put("pathToFile", addedInfo.getPath_to_file());
    values.put("streamUrl", addedInfo.getStream_url());

    long insertResult = musicBase.insert("mytable", null, values);
    Log.i("dataBase", "insertResult: " + insertResult);

    Log.i("dataBase insert", addedInfo.getUser().getUsername());
    Log.i("dataBase insert", addedInfo.getTitle());
    Log.i("dataBase insert", addedInfo.getLikes_count() + "");
    Log.i("dataBase insert", addedInfo.getDuration() + "");

    Log.i("dataBase", "info inserted");
  }