当前位置: 首页>>代码示例>>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;未经允许,请勿转载。