本文整理汇总了Java中org.jooq.tools.jdbc.JDBCUtils.safeClose方法的典型用法代码示例。如果您正苦于以下问题:Java JDBCUtils.safeClose方法的具体用法?Java JDBCUtils.safeClose怎么用?Java JDBCUtils.safeClose使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.jooq.tools.jdbc.JDBCUtils
的用法示例。
在下文中一共展示了JDBCUtils.safeClose方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: configure
import org.jooq.tools.jdbc.JDBCUtils; //导入方法依赖的package包/类
@SuppressWarnings( "deprecation" )
@Override
public void configure(Context context) {
// DBCP 초기화
ConnectionManager.instance.initialize( context );
this.batchsize = context.getInteger(CONF_BATCH_SIZE, DEFAULT_BATCH_SIZE);
this.sqlDialect = SQLDialect.valueOf(context.getString(CONF_SQL_DIALECT).toUpperCase(Locale.ENGLISH));
final String sql = context.getString(CONF_SQL);
if (sql == null) {
Connection connection = null;
try {
// Table 정보 매핑
connection = ConnectionManager.instance.getConnection();
final DSLContext create = DSL.using(connection, sqlDialect);
this.queryGenerator = new MappingQueryGenerator(create, context.getString(CONF_TABLE));
} catch (SQLException ex) {
throw new JDBCSinkException(ex);
} finally {
JDBCUtils.safeClose( connection );
}
} else {
this.queryGenerator = new TemplateQueryGenerator(sqlDialect, sql);
}
this.sinkCounter = new SinkCounter(this.getName());
}
示例2: process
import org.jooq.tools.jdbc.JDBCUtils; //导入方法依赖的package包/类
@Override
public Status process() throws EventDeliveryException {
Status status = Status.BACKOFF;
Transaction transaction = this.getChannel().getTransaction();
Connection connection = null;
try {
transaction.begin();
connection = ConnectionManager.instance.getConnection();
final DSLContext create = DSL.using(connection, sqlDialect);
List<Event> eventList = this.takeEventsFromChannel( this.getChannel(), this.batchsize);
status = Status.READY;
if (!eventList.isEmpty()) {
if (eventList.size() == this.batchsize) {
this.sinkCounter.incrementBatchCompleteCount();
} else {
this.sinkCounter.incrementBatchUnderflowCount();
}
final boolean success = this.queryGenerator.executeQuery(create, eventList);
if (!success) {
throw new JDBCSinkException("Query failed");
}
connection.commit();
this.sinkCounter.addToEventDrainSuccessCount(eventList.size());
} else {
this.sinkCounter.incrementBatchEmptyCount();
}
transaction.commit();
status = Status.READY;
} catch (Throwable t) {
log.error("Exception during process", t);
try {
connection.rollback();
} catch (Exception ex) {
log.error("Exception on rollback", ex);
} finally {
transaction.rollback();
status = Status.BACKOFF;
this.sinkCounter.incrementConnectionFailedCount();
if (t instanceof Error) {
throw new JDBCSinkException(t);
}
}
} finally {
transaction.close();
JDBCUtils.safeClose( connection );
}
return status;
}