Examples of JdbcChannelException


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

      break;
    case MYSQL:
      handler = new MySQLSchemaHandler(dataSource);
      break;
    default:
      throw new JdbcChannelException("Database " + dbType
          + " not supported yet");
    }

    return handler;
  }
View Full Code Here

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

    // First check if the schema exists
    schemaHandler = SchemaHandlerFactory.getHandler(databaseType, dataSource);

    if (!schemaHandler.schemaExists()) {
      if (!createSchema) {
        throw new JdbcChannelException("Schema does not exist and "
            + "auto-generation is disabled. Please enable auto-generation of "
            + "schema and try again.");
      }

      String createIndexFlag = context.getString(
View Full Code Here

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

  @Override
  public void close() {
    try {
      connectionPool.close();
    } catch (Exception ex) {
      throw new JdbcChannelException("Unable to close connection pool", ex);
    }

    if (databaseType.equals(DatabaseType.DERBY)
        && driverClassName.equals(EMBEDDED_DERBY_DRIVER_CLASSNAME)) {
      // Need to shut down the embedded Derby instance
      if (connectUrl.startsWith("jdbc:derby:")) {
        int index = connectUrl.indexOf(";");
        String baseUrl = null;
        if (index != -1) {
          baseUrl = connectUrl.substring(0, index+1);
        } else {
          baseUrl = connectUrl + ";";
        }
        String shutDownUrl = baseUrl + "shutdown=true";

        LOGGER.debug("Attempting to shutdown embedded Derby using URL: "
            + shutDownUrl);

        try {
          DriverManager.getConnection(shutDownUrl);
        } catch (SQLException ex) {
          // Shutdown for one db instance is expected to raise SQL STATE 45000
          if (ex.getErrorCode() != 45000) {
            throw new JdbcChannelException(
                "Unable to shutdown embedded Derby: " + shutDownUrl
                + " Error Code: " + ex.getErrorCode(), ex);
          }
          LOGGER.info("Embedded Derby shutdown raised SQL STATE "
              + "45000 as expected.");
View Full Code Here

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

      Connection conn = tx.getConnection();

      if (maxCapacity > 0) {
        long currentSize = schemaHandler.getChannelSize(conn);
        if (currentSize >= maxCapacity) {
          throw new JdbcChannelException("Channel capacity reached: "
              + "maxCapacity: " + maxCapacity + ", currentSize: "
              + currentSize);
        }
      }

      // Persist the persistableEvent
      schemaHandler.storeEvent(persistableEvent, tx.getConnection());

      tx.commit();
    } catch (Exception ex) {
      tx.rollback();
      throw new JdbcChannelException("Failed to persist event", ex);
    } finally {
      if (tx != null) {
        tx.close();
      }
    }
View Full Code Here

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

          channelName, tx.getConnection());

      tx.commit();
    } catch (Exception ex) {
      tx.rollback();
      throw new JdbcChannelException("Failed to persist event", ex);
    } finally {
      if (tx != null) {
        tx.close();
      }
    }
View Full Code Here

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

      String canonicalDbDirPath = null;

      try {
        canonicalDbDirPath = dbDir.getCanonicalPath();
      } catch (IOException ex) {
        throw new JdbcChannelException("Unable to find canonical path of dir: "
            + defaultDbDir, ex);
      }

      if (!dbDir.exists()) {
        if (!dbDir.mkdirs()) {
          throw new JdbcChannelException("unable to create directory: "
              + canonicalDbDirPath);
        }
      }

      connectUrl = "jdbc:derby:" + canonicalDbDirPath + "/db;create=true";

      // No jdbc properties file will be used
      jdbcPropertiesFile = null;

      LOGGER.warn("Overriding values for - driver: " + driverClassName
          + ", user: " + userName + "connectUrl: " + connectUrl
          + ", jdbc properties file: " + jdbcPropertiesFile
          + ", dbtype: " + dbTypeName);
    }

    // Right now only Derby and MySQL supported
    databaseType = DatabaseType.getByName(dbTypeName);

    switch (databaseType) {
    case DERBY:
    case MYSQL:
      break;
    default:
      throw new JdbcChannelException("Database " + databaseType
          + " not supported at this time");
    }

    // Register driver
    if (driverClassName == null || driverClassName.trim().length() == 0) {
      throw new JdbcChannelException("No jdbc driver specified");
    }

    try {
      Class.forName(driverClassName);
    } catch (ClassNotFoundException ex) {
      throw new JdbcChannelException("Unable to load driver: "
                  + driverClassName, ex);
    }

    // JDBC Properties
    Properties jdbcProps = new Properties();

    if (jdbcPropertiesFile != null && jdbcPropertiesFile.trim().length() > 0) {
      File jdbcPropsFile = new File(jdbcPropertiesFile.trim());
      if (!jdbcPropsFile.exists()) {
        throw new JdbcChannelException("Jdbc properties file does not exist: "
            + jdbcPropertiesFile);
      }

      InputStream inStream = null;
      try {
        inStream = new FileInputStream(jdbcPropsFile);
        jdbcProps.load(inStream);
      } catch (IOException ex) {
        throw new JdbcChannelException("Unable to load jdbc properties "
            + "from file: " + jdbcPropertiesFile, ex);
      } finally {
        if (inStream != null) {
          try {
            inStream.close();
View Full Code Here

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

      try {
        connection.rollback();
      } catch (SQLException ex2) {
        LOGGER.error("Unable to rollback transaction", ex2);
      }
      throw new JdbcChannelException("Unable to query schema", ex);
    } finally {
      if (stmt != null) {
        try {
          stmt.close();
        } catch (SQLException ex) {
View Full Code Here

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

      try {
        connection.rollback();
      } catch (SQLException ex2) {
        LOGGER.error("Unable to rollback transaction", ex2);
      }
      throw new JdbcChannelException("Unable to run query: "
          + COLUMN_LOOKUP_QUERY + ": 1=" + tableName + ", 2=" + schemaName, ex);
    } finally {
      if (pStmt != null) {
        try {
          pStmt.close();
        } catch (SQLException ex) {
          LOGGER.error("Unable to close statement", ex);
        }
        if (connection != null) {
          try {
            connection.close();
          } catch (SQLException ex) {
            LOGGER.error("Unable to close connection", ex);
          }
        }
      }
    }

    Set<String> columnDiff = new HashSet<String>();
    columnDiff.addAll(columnNames);

    // Expected Column string form
    StringBuilder sb = new StringBuilder("{");
    boolean first = true;
    for (String column : columns) {
      columnDiff.remove(column);
      if (first) {
        first = false;
      } else {
        sb.append(", ");
      }
      sb.append(column);
    }
    sb.append("}");

    String expectedColumns = sb.toString();

    if (LOGGER.isDebugEnabled()) {
      LOGGER.debug("Table " + schemaName + "." + tableName
          + " expected columns: " + expectedColumns + ", actual columns: "
          + columnNames);
    }

    if (columnNames.size() != columns.length || columnDiff.size() != 0) {
      throw new JdbcChannelException("Expected table " + schemaName + "."
          + tableName + " to have columns: " + expectedColumns + ". Instead "
          + "found columns: " + columnNames);
    }
  }
View Full Code Here

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

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

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

      baseEventStmt.setString(2, channelName);
      baseEventStmt.setBoolean(3, hasSpillPayload);

      int baseEventCount = baseEventStmt.executeUpdate();
      if (baseEventCount != 1) {
        throw new JdbcChannelException("Invalid update count on base "
            + "event insert: " + baseEventCount);
      }
      // Extract event ID and set it
      ResultSet eventIdResult = baseEventStmt.getGeneratedKeys();

      if (!eventIdResult.next()) {
        throw new JdbcChannelException("Unable to retrieive inserted event-id");
      }

      long eventId = eventIdResult.getLong(1);
      pe.setEventId(eventId);

      // Persist the payload spill
      if (hasSpillPayload) {
         spillEventStmt = connection.prepareStatement(STMT_INSERT_EVENT_SPILL);
         spillEventStmt.setLong(1, eventId);
         spillEventStmt.setBinaryStream(2,
             new ByteArrayInputStream(spillPayload), spillPayload.length);
         int spillEventCount = spillEventStmt.executeUpdate();
         if (spillEventCount != 1) {
           throw new JdbcChannelException("Invalid update count on spill "
               + "event insert: " + spillEventCount);
         }
      }

      // Persist the headers
      List<HeaderEntry> headers = pe.getHeaderEntries();
      if (headers != null && headers.size() > 0) {
        List<HeaderEntry> headerWithNameSpill = new ArrayList<HeaderEntry>();
        List<HeaderEntry> headerWithValueSpill = new ArrayList<HeaderEntry>();

        baseHeaderStmt = connection.prepareStatement(STMT_INSERT_HEADER_BASE,
                                Statement.RETURN_GENERATED_KEYS);
        Iterator<HeaderEntry> it = headers.iterator();
        while (it.hasNext()) {
          HeaderEntry entry = it.next();
          SpillableString name = entry.getName();
          SpillableString value = entry.getValue();
          baseHeaderStmt.setLong(1, eventId);
          baseHeaderStmt.setString(2, name.getBase());
          baseHeaderStmt.setString(3, value.getBase());
          baseHeaderStmt.setBoolean(4, name.hasSpill());
          baseHeaderStmt.setBoolean(5, value.hasSpill());

          int updateCount = baseHeaderStmt.executeUpdate();
          if (updateCount != 1) {
             throw new JdbcChannelException("Unexpected update header count: "
                 + updateCount);
          }
          ResultSet headerIdResultSet = baseHeaderStmt.getGeneratedKeys();
          if (!headerIdResultSet.next()) {
            throw new JdbcChannelException(
                "Unable to retrieve inserted header id");
          }
          long headerId = headerIdResultSet.getLong(1);
          entry.setId(headerId);

          if (name.hasSpill()) {
            headerWithNameSpill.add(entry);
          }

          if (value.hasSpill()) {
            headerWithValueSpill.add(entry);
          }
        }

        // Persist header name spills
        if (headerWithNameSpill.size() > 0) {
          LOGGER.debug("Number of headers with name spill: "
                  + headerWithNameSpill.size());

          headerNameSpillStmt =
              connection.prepareStatement(STMT_INSERT_HEADER_NAME_SPILL);

          for (HeaderEntry entry : headerWithNameSpill) {
            String nameSpill = entry.getName().getSpill();

            headerNameSpillStmt.setLong(1, entry.getId());
            headerNameSpillStmt.setString(2, nameSpill);
            headerNameSpillStmt.addBatch();
          }

          int[] nameSpillUpdateCount = headerNameSpillStmt.executeBatch();
          if (nameSpillUpdateCount.length != headerWithNameSpill.size()) {
            throw new JdbcChannelException("Unexpected update count for header "
                + "name spills: expected " + headerWithNameSpill.size() + ", "
                + "found " + nameSpillUpdateCount.length);
          }

          for (int i = 0; i < nameSpillUpdateCount.length; i++) {
            if (nameSpillUpdateCount[i] != 1) {
              throw new JdbcChannelException("Unexpected update count for "
                  + "header name spill at position " + i + ", value: "
                  + nameSpillUpdateCount[i]);
            }
          }
        }

        // Persist header value spills
        if (headerWithValueSpill.size() > 0) {
          LOGGER.debug("Number of headers with value spill: "
              + headerWithValueSpill.size());

          headerValueSpillStmt =
              connection.prepareStatement(STMT_INSERT_HEADER_VALUE_SPILL);

          for(HeaderEntry entry : headerWithValueSpill) {
            String valueSpill = entry.getValue().getSpill();

            headerValueSpillStmt.setLong(1, entry.getId());
            headerValueSpillStmt.setString(2, valueSpill);
            headerValueSpillStmt.addBatch();
          }

          int[] valueSpillUpdateCount = headerValueSpillStmt.executeBatch();
          if (valueSpillUpdateCount.length != headerWithValueSpill.size()) {
            throw new JdbcChannelException("Unexpected update count for header "
                + "value spills: expected " + headerWithValueSpill.size() + ", "
                + "found " + valueSpillUpdateCount.length);
          }

          for (int i = 0; i < valueSpillUpdateCount.length; i++) {
            if (valueSpillUpdateCount[i] != 1) {
              throw new JdbcChannelException("Unexpected update count for "
                  + "header value spill at position " + i + ", value: "
                  + valueSpillUpdateCount[i]);
            }
          }
        }
      }
    } catch (SQLException ex) {
      throw new JdbcChannelException("Unable to persist event: " + pe, ex);
    } finally {
      if (baseEventStmt != null) {
        try {
          baseEventStmt.close();
        } catch (SQLException ex) {
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.