コード例 #1
0
  /**
   * Execute the selection query in the database
   *
   * @return The query result. Each Object is a cell content.
   *     <p>The cell contents use database types (date,int,string...), keep in mind in case of
   *     future conversions/castings.
   * @throws InterruptedException
   */
  @SuppressWarnings("unchecked")
  public List<List<Object>> executeQuery() throws InterruptedException {

    List<List<Object>> rowsList = new ArrayList<List<Object>>();
    Query query;

    if (!session.isConnected()) {
      resetConnection();
    }

    if (sqlSourceHelper.isCustomQuerySet()) {

      query = session.createSQLQuery(sqlSourceHelper.buildQuery());

      if (sqlSourceHelper.getMaxRows() != 0) {
        query = query.setMaxResults(sqlSourceHelper.getMaxRows());
      }
    } else {
      query =
          session
              .createSQLQuery(sqlSourceHelper.getQuery())
              .setFirstResult(Integer.parseInt(sqlSourceHelper.getCurrentIndex()));

      if (sqlSourceHelper.getMaxRows() != 0) {
        query = query.setMaxResults(sqlSourceHelper.getMaxRows());
      }
    }

    try {
      rowsList =
          query
              .setFetchSize(sqlSourceHelper.getMaxRows())
              .setResultTransformer(Transformers.TO_LIST)
              .list();
    } catch (Exception e) {
      resetConnection();
    }

    if (!rowsList.isEmpty()) {
      if (sqlSourceHelper.isCustomQuerySet()) {
        sqlSourceHelper.setCurrentIndex(rowsList.get(rowsList.size() - 1).get(0).toString());
      } else {
        sqlSourceHelper.setCurrentIndex(
            Integer.toString(
                (Integer.parseInt(sqlSourceHelper.getCurrentIndex()) + rowsList.size())));
      }
    }

    return rowsList;
  }
コード例 #2
0
  @Test
  public void checkStatusFileCorrectlyUpdated() throws Exception {

    File file = File.createTempFile("statusFileName", ".txt");

    when(context.getString("status.file.path", "/var/lib/flume")).thenReturn(file.getParent());
    when(context.getString("status.file.name")).thenReturn(file.getName());

    SQLSourceHelper sqlSourceHelper = new SQLSourceHelper(context, "Source Name");
    sqlSourceHelper.setCurrentIndex(10);

    sqlSourceHelper.updateStatusFile();

    SQLSourceHelper sqlSourceHelper2 = new SQLSourceHelper(context, "Source Name");
    assertEquals(10L, sqlSourceHelper2.getCurrentIndex());
  }
コード例 #3
0
 @Test
 public void setCurrentIndex() {
   SQLSourceHelper sqlSourceHelper = new SQLSourceHelper(context, "Source Name");
   sqlSourceHelper.setCurrentIndex(10);
   assertEquals(10, sqlSourceHelper.getCurrentIndex());
 }