本文整理汇总了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;
}
示例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;
}
示例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;
}
示例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);
}
}