Examples of JdbcChannelException


Examples of org.apache.flume.channel.jdbc.JdbcChannelException

            connection.prepareStatement(STMT_FETCH_PAYLOAD_SPILL);

        spillEventFetchStmt.setLong(1, eventId);
        ResultSet rsetSpillEvent = spillEventFetchStmt.executeQuery();
        if (!rsetSpillEvent.next()) {
          throw new JdbcChannelException("Payload spill expected but not "
              + "found for event: " + eventId);
        }
        Blob payloadSpillBlob = rsetSpillEvent.getBlob(1);
        payloadInputStream = payloadSpillBlob.getBinaryStream();
        ByteArrayOutputStream spillStream = new ByteArrayOutputStream();
        byte[] buffer = new byte[1024];
        int length = 0;
        while ((length = payloadInputStream.read(buffer)) != -1) {
          spillStream.write(buffer, 0, length);
        }
        peBuilder.setSpillPayload(spillStream.toByteArray());

        // Delete this spill
        deleteSpillEventStmt =
            connection.prepareStatement(STMT_DELETE_EVENT_SPILL);
        deleteSpillEventStmt.setLong(1, eventId);

        int updateCount = deleteSpillEventStmt.executeUpdate();
        if (updateCount != 1) {
          throw new JdbcChannelException("Unexpected row count for spill "
              + "delete: " + updateCount);
        }
      }

      if (rsetBaseEvent.next()) {
        throw new JdbcChannelException("More than expected events retrieved");
      }

      // Populate headers
      List<Long> nameSpillHeaders = null;
      List<Long> valueSpillHeaders = null;
      baseHeaderFetchStmt = connection.prepareStatement(STMT_FETCH_HEADER_BASE);
      baseHeaderFetchStmt.setLong(1, eventId);
      int headerCount = 0; // for later delete validation

      ResultSet rsetBaseHeader = baseHeaderFetchStmt.executeQuery();
      while (rsetBaseHeader.next()) {
        headerCount++;
        long headerId = rsetBaseHeader.getLong(1);
        String baseName = rsetBaseHeader.getString(2);
        String baseValue = rsetBaseHeader.getString(3);
        boolean hasNameSpill = rsetBaseHeader.getBoolean(4);
        boolean hasValueSpill = rsetBaseHeader.getBoolean(5);

        peBuilder.setHeader(headerId, baseName, baseValue);
        if (hasNameSpill) {
          if (nameSpillHeaders == null) {
            nameSpillHeaders = new ArrayList<Long>();
          }
          nameSpillHeaders.add(headerId);
        }

        if (hasValueSpill) {
          if (valueSpillHeaders == null) {
            valueSpillHeaders = new ArrayList<Long>();
          }
          valueSpillHeaders.add(headerId);
        }
      }

      if (nameSpillHeaders != null) {

        nameSpillHeaderStmt =
            connection.prepareStatement(STMT_FETCH_HEADER_NAME_SPILL);

        deleteNameSpillHeaderStmt =
            connection.prepareStatement(STMT_DELETE_HEADER_NAME_SPILL);
        for (long headerId : nameSpillHeaders) {
          nameSpillHeaderStmt.setLong(1, headerId);
          ResultSet rsetHeaderNameSpill = nameSpillHeaderStmt.executeQuery();
          if (!rsetHeaderNameSpill.next()) {
            throw new JdbcChannelException("Name spill was set for header "
                + headerId + " but was not found");
          }
          String nameSpill = rsetHeaderNameSpill.getString(1);

          peBuilder.setHeaderNameSpill(headerId, nameSpill);
          deleteNameSpillHeaderStmt.setLong(1, headerId);
          deleteNameSpillHeaderStmt.addBatch();
        }

        // Delete header name spills
        int[] headerNameSpillDelete = deleteNameSpillHeaderStmt.executeBatch();
        if (headerNameSpillDelete.length != nameSpillHeaders.size()) {
          throw new JdbcChannelException("Unexpected number of header name "
              + "spill deletes: expected " + nameSpillHeaders.size()
              + ", found: " + headerNameSpillDelete.length);
        }

        for (int numRowsAffected : headerNameSpillDelete) {
          if (numRowsAffected != 1) {
            throw new JdbcChannelException("Unexpected number of deleted rows "
                + "for header name spill deletes: " + numRowsAffected);
          }
        }
      }

      if (valueSpillHeaders != null) {
        valueSpillHeaderStmt =
            connection.prepareStatement(STMT_FETCH_HEADER_VALUE_SPILL);

        deleteValueSpillHeaderStmt =
            connection.prepareStatement(STMT_DELETE_HEADER_VALUE_SPILL);
        for (long headerId: valueSpillHeaders) {
          valueSpillHeaderStmt.setLong(1, headerId);
          ResultSet rsetHeaderValueSpill = valueSpillHeaderStmt.executeQuery();
          if (!rsetHeaderValueSpill.next()) {
            throw new JdbcChannelException("Value spill was set for header "
                + headerId + " but was not found");
          }
          String valueSpill = rsetHeaderValueSpill.getString(1);

          peBuilder.setHeaderValueSpill(headerId, valueSpill);
          deleteValueSpillHeaderStmt.setLong(1, headerId);
          deleteValueSpillHeaderStmt.addBatch();
        }
        // Delete header value spills
        int[] headerValueSpillDelete = deleteValueSpillHeaderStmt.executeBatch();
        if (headerValueSpillDelete.length != valueSpillHeaders.size()) {
          throw new JdbcChannelException("Unexpected number of header value "
              + "spill deletes: expected " + valueSpillHeaders.size()
              + ", found: " + headerValueSpillDelete.length);
        }

        for (int numRowsAffected : headerValueSpillDelete) {
          if (numRowsAffected != 1) {
            throw new JdbcChannelException("Unexpected number of deleted rows "
                + "for header value spill deletes: " + numRowsAffected);
          }
        }
      }

      // Now delete Headers
      if (headerCount > 0) {
        deleteBaseHeaderStmt =
            connection.prepareStatement(STMT_DELETE_HEADER_BASE);
        deleteBaseHeaderStmt.setLong(1, eventId);

        int rowCount = deleteBaseHeaderStmt.executeUpdate();
        if (rowCount != headerCount) {
          throw new JdbcChannelException("Unexpected base header delete count: "
              + "expected: " + headerCount + ", found: " + rowCount);
        }
      }

      // Now delete the Event
      deleteBaseEventStmt = connection.prepareStatement(STMT_DELETE_EVENT_BASE);
      deleteBaseEventStmt.setLong(1, eventId);
      int rowCount = deleteBaseEventStmt.executeUpdate();

      if (rowCount != 1) {
        throw new JdbcChannelException("Unexpected row count for delete of "
            + "event-id: " + eventId + ", count: " + rowCount);
      }

    } catch (SQLException ex) {
      throw new JdbcChannelException("Unable to retrieve event", ex);
    } catch (IOException ex) {
      throw new JdbcChannelException("Unable to read data", ex);
    } finally {
      if (payloadInputStream != null) {
        try {
          payloadInputStream.close();
        } catch (IOException ex) {
View Full Code Here

Examples of org.apache.flume.channel.jdbc.JdbcChannelException

    try {
      stmt = connection.createStatement();
      stmt.execute(QUERY_CHANNEL_SIZE);
      ResultSet rset = stmt.getResultSet();
      if (!rset.next()) {
        throw new JdbcChannelException("Failed to determine channel size: "
              + "Query (" + QUERY_CHANNEL_SIZE
              + ") did not produce any results");
      }

      size = rset.getLong(1);
      connection.commit();
    } catch (SQLException ex) {
      try {
        connection.rollback();
      } catch (SQLException ex2) {
        LOGGER.error("Unable to rollback transaction", ex2);
      }
      throw new JdbcChannelException("Unable to run query: "
          + QUERY_CHANNEL_SIZE, ex);
    } finally {
      if (stmt != null) {
        try {
          stmt.close();
View Full Code Here

Examples of org.apache.flume.channel.jdbc.JdbcChannelException

      if (bHeaderParts == null) {
        bHeaderParts = new HashMap<Long, HeaderPart>();
      }
      HeaderPart hp = new HeaderPart(baseName, baseValue);
      if (bHeaderParts.put(headerId, hp) != null) {
        throw new JdbcChannelException("Duplicate header found: "
            + "headerId: " + headerId + ", baseName: " + baseName + ", "
            + "baseValue: " + baseValue);
      }

      return this;
View Full Code Here

Examples of org.apache.flume.channel.jdbc.JdbcChannelException

    }

    public Builder setHeaderNameSpill(long headerId, String nameSpill) {
      HeaderPart hp = bHeaderParts.get(headerId);
      if (hp == null) {
        throw new JdbcChannelException("Header not found for spill: "
            + headerId);
      }

      hp.setSpillName(nameSpill);
View Full Code Here

Examples of org.apache.flume.channel.jdbc.JdbcChannelException

    }

    public Builder setHeaderValueSpill(long headerId, String valueSpill) {
      HeaderPart hp = bHeaderParts.get(headerId);
      if (hp == null) {
        throw new JdbcChannelException("Header not found for spill: "
            + headerId);
      }

      hp.setSpillValue(valueSpill);
View Full Code Here

Examples of org.apache.flume.channel.jdbc.JdbcChannelException

  }

  @Override
  public void begin() {
    if (!active) {
      throw new JdbcChannelException("Inactive transaction");
    }
    if (count == 0) {
      // Lease a connection now
      try {
        connection = dataSource.getConnection();
      } catch (SQLException ex) {
        throw new JdbcChannelException("Unable to lease connection", ex);
      }
      // Clear any prior warnings on the connection
      try {
        connection.clearWarnings();
      } catch (SQLException ex) {
View Full Code Here

Examples of org.apache.flume.channel.jdbc.JdbcChannelException

  }

  @Override
  public void commit() {
    if (!active) {
      throw new JdbcChannelException("Inactive transaction");
    }
    if (rollback) {
      throw new JdbcChannelException(
          "Cannot commit transaction marked for rollback");
    }
    LOGGER.debug("Tx count-commit: " + count + ", rollback: " + rollback);
  }
View Full Code Here

Examples of org.apache.flume.channel.jdbc.JdbcChannelException

  }

  @Override
  public void rollback() {
    if (!active) {
      throw new JdbcChannelException("Inactive transaction");
    }
    LOGGER.warn("Marking transaction for rollback");
    rollback = true;
    LOGGER.debug("Tx count-rollback: " + count + ", rollback: " + rollback);
  }
View Full Code Here

Examples of org.apache.flume.channel.jdbc.JdbcChannelException

  }

  @Override
  public void close() {
    if (!active) {
      throw new JdbcChannelException("Inactive transaction");
    }
    count--;
    LOGGER.debug("Tx count-close: " + count + ", rollback: " + rollback);
    if (count == 0) {
      active = false;
      try {
        if (rollback) {
          LOGGER.info("Attempting transaction roll-back");
          connection.rollback();
        } else {
          LOGGER.debug("Attempting transaction commit");
          connection.commit();
        }
      } catch (SQLException ex) {
        throw new JdbcChannelException("Unable to finalize transaction", ex);
      } finally {
        if (connection != null) {
          // Log Warnings
          try {
            SQLWarning warning = connection.getWarnings();
View Full Code Here

Examples of org.apache.flume.channel.jdbc.JdbcChannelException

    }
  }

  protected Connection getConnection() {
    if (!active) {
      throw new JdbcChannelException("Inactive transaction");
    }
    return connection;
  }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.