當前位置: 首頁>>代碼示例>>Java>>正文


Java AbstractRecord類代碼示例

本文整理匯總了Java中wherehows.common.schemas.AbstractRecord的典型用法代碼示例。如果您正苦於以下問題:Java AbstractRecord類的具體用法?Java AbstractRecord怎麽用?Java AbstractRecord使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


AbstractRecord類屬於wherehows.common.schemas包,在下文中一共展示了AbstractRecord類的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: insert

import wherehows.common.schemas.AbstractRecord; //導入依賴的package包/類
/**
 * use JDBC template PreparedStatement to insert records
 * require record to have getAllValues() and optional getDbColumnNames() method
 * @return boolean if the insert is successful
 * @throws SQLException
 */
public boolean insert() throws SQLException, IllegalAccessException {
  if (records.size() == 0 || !(records.get(0) instanceof AbstractRecord)) {
    logger.debug("DatabaseWriter no record to insert or unknown record Class.");
    System.out.println("DatabaseWriter no record or unknown record Class: " + records.size() + " | " + records.get(0) + " | " + (records.get(0) instanceof AbstractRecord));
    return false;
  }

  final AbstractRecord record0 = (AbstractRecord) records.get(0);
  final String[] columnNames = record0.getDbColumnNames();
  final String sql =
      (columnNames != null) ? PreparedStatementUtil.prepareInsertTemplateWithColumn(tableName, columnNames)
          : PreparedStatementUtil.prepareInsertTemplateWithoutColumn(tableName, record0.getAllFields().length);
  logger.info("sql string: " + sql);
  logger.error("columnNames: " + columnNames);
  System.out.println("sql: " + sql + " | " + columnNames);
  //logger.debug("DatabaseWriter template for " + record0.getClass() + " : " + sql);

  for (final Record record : records) {
    jdbcTemplate.update(sql, ((AbstractRecord) record).getAllValuesToString());
  }
  records.clear();
  return true;
}
 
開發者ID:SirAeroWN,項目名稱:premier-wherehows,代碼行數:30,代碼來源:DatabaseWriter.java

示例2: insert

import wherehows.common.schemas.AbstractRecord; //導入依賴的package包/類
/**
 * use JDBC template PreparedStatement to insert records
 * require record to have getAllValues() and optional getDbColumnNames() method
 * @return boolean if the insert is successful
 * @throws SQLException
 */
public boolean insert()
    throws SQLException {
  if (records.size() == 0 || !(records.get(0) instanceof AbstractRecord)) {
    logger.debug("DatabaseWriter no record to insert or unknown record Class.");
    return false;
  }

  final AbstractRecord record0 = (AbstractRecord) records.get(0);
  final String[] columnNames = record0.getDbColumnNames();
  final String sql =
      (columnNames != null) ? PreparedStatementUtil.prepareInsertTemplateWithColumn(tableName, columnNames)
          : PreparedStatementUtil.prepareInsertTemplateWithoutColumn(tableName, record0.getAllFields().length);
  //logger.debug("DatabaseWriter template for " + record0.getClass() + " : " + sql);

  for (final Record record : records) {
    try {
      jdbcTemplate.update(sql, ((AbstractRecord) record).getAllValuesToString());

      /* jdbcTemplate.update(sql, new PreparedStatementSetter() {
        @Override
        public void setValues(PreparedStatement ps)
            throws SQLException {
          record.setPreparedStatementValues(ps);
        }
      }); */
    } catch (IllegalAccessException | DataAccessException ae) {
      logger.error("DatabaseWriter insert error: " + ae);
    }
  }
  records.clear();
  return true;
}
 
開發者ID:thomas-young-2013,項目名稱:wherehowsX,代碼行數:39,代碼來源:DatabaseWriter.java

示例3: insert

import wherehows.common.schemas.AbstractRecord; //導入依賴的package包/類
/**
 * use JDBC template PreparedStatement to insert records
 * require record to have getAllValues() and optional getDbColumnNames() method
 * @return boolean if the insert is successful
 * @throws SQLException
 */
public boolean insert()
    throws SQLException {
  if (records.size() == 0 || !(records.get(0) instanceof AbstractRecord)) {
    log.debug("DatabaseWriter no record to insert or unknown record Class.");
    return false;
  }

  final AbstractRecord record0 = (AbstractRecord) records.get(0);
  final String[] columnNames = record0.getDbColumnNames();
  final String sql =
      (columnNames != null) ? PreparedStatementUtil.prepareInsertTemplateWithColumn(tableName, columnNames)
          : PreparedStatementUtil.prepareInsertTemplateWithoutColumn(tableName, record0.getAllFields().length);
  //logger.debug("DatabaseWriter template for " + record0.getClass() + " : " + sql);

  for (final Record record : records) {
    try {
      jdbcTemplate.update(sql, ((AbstractRecord) record).getAllValuesToString());

      /* jdbcTemplate.update(sql, new PreparedStatementSetter() {
        @Override
        public void setValues(PreparedStatement ps)
            throws SQLException {
          record.setPreparedStatementValues(ps);
        }
      }); */
    } catch (IllegalAccessException | DataAccessException ae) {
      log.error("DatabaseWriter insert error: " + ae);
    }
  }
  records.clear();
  return true;
}
 
開發者ID:linkedin,項目名稱:WhereHows,代碼行數:39,代碼來源:DatabaseWriter.java

示例4: onReceive

import wherehows.common.schemas.AbstractRecord; //導入依賴的package包/類
@Override
public void onReceive(Object message) throws Exception {
  if (message.equals("Start")) {
    Logger.info("Starting Thread: " + _threadId + " for topic: " + _topic);
    final ConsumerIterator<byte[], byte[]> it = _kafkaStream.iterator();
    final Deserializer<Object> avroDeserializer = new KafkaAvroDeserializer(_schemaRegistryRestfulClient);

    while (it.hasNext()) { // block for next input
      _receivedRecordCount++;

      try {
        MessageAndMetadata<byte[], byte[]> msg = it.next();
        GenericData.Record kafkaMsgRecord = (GenericData.Record) avroDeserializer.deserialize(_topic, msg.message());
        // Logger.debug("Kafka worker ThreadId " + _threadId + " Topic " + _topic + " record: " + rec);

        // invoke processor
        final AbstractRecord record = (AbstractRecord) _processorMethod.invoke(
            _processorClass, kafkaMsgRecord, _topic);

        // save record to database
        if (record != null) {
          _dbWriter.append(record);
          // _dbWriter.close();
          _dbWriter.insert();
          _processedRecordCount++;
        }
      } catch (InvocationTargetException ite) {
        Logger.error("Processing topic " + _topic + " record error: " + ite.getCause()
            + " - " + ite.getTargetException());
      } catch (SQLException | IOException e) {
        Logger.error("Error while inserting event record: ", e);
      } catch (Throwable ex) {
        Logger.error("Error in notify order. ", ex);
      }

      if (_receivedRecordCount % 1000 == 0) {
        Logger.debug(_topic + " received " + _receivedRecordCount + " processed " + _processedRecordCount);
      }
    }
    Logger.info("Shutting down Thread: " + _threadId + " for topic: " + _topic);
  } else {
    unhandled(message);
  }
}
 
開發者ID:thomas-young-2013,項目名稱:wherehowsX,代碼行數:45,代碼來源:KafkaConsumerWorker.java


注:本文中的wherehows.common.schemas.AbstractRecord類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。