本文整理汇总了Java中com.mysql.jdbc.exceptions.MySQLTransactionRollbackException类的典型用法代码示例。如果您正苦于以下问题:Java MySQLTransactionRollbackException类的具体用法?Java MySQLTransactionRollbackException怎么用?Java MySQLTransactionRollbackException使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
MySQLTransactionRollbackException类属于com.mysql.jdbc.exceptions包,在下文中一共展示了MySQLTransactionRollbackException类的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: markAsCompleted
import com.mysql.jdbc.exceptions.MySQLTransactionRollbackException; //导入依赖的package包/类
public int markAsCompleted(Job job) throws SQLException, NoAvailableConnectionException {
Connection c = null;
PreparedStatement pp = null;
SQLException sqle = null;
boolean finished = false;
int rowsUpdated = 0;
while (!finished) { // will loop if MySQLTransactionRollbackException occurs
try {
c = ConnectionProvider.getConnection(connectionProperties, true);
String sql = "UPDATE unit_job SET end_timestamp = ?, status = '" + UnitJobStatus.COMPLETED_OK;
sql += "', processed = 0 WHERE ";
sql += "status = '" + UnitJobStatus.UNCONFIRMED_FAILED + "' AND end_timestamp < ? AND job_id = ?";
pp = c.prepareStatement(sql);
pp.setTimestamp(1, new Timestamp(System.currentTimeMillis()));
pp.setTimestamp(2, new Timestamp(System.currentTimeMillis() - 3600 * 1000));
pp.setInt(3, job.getId());
pp.setQueryTimeout(60);
rowsUpdated = pp.executeUpdate();
finished = true;
} catch (MySQLTransactionRollbackException mtre) {
logger.warn("A deadlock occured, the statement is retried");
} catch (SQLException sqlex) {
sqle = sqlex;
throw sqlex;
} finally {
if (pp != null)
pp.close();
if (c != null)
ConnectionProvider.returnConnection(c, sqle);
}
}
return rowsUpdated;
}
示例2: markAsUnconfirmed
import com.mysql.jdbc.exceptions.MySQLTransactionRollbackException; //导入依赖的package包/类
public int markAsUnconfirmed(Job job) throws SQLException, NoAvailableConnectionException {
Connection c = null;
PreparedStatement pp = null;
SQLException sqle = null;
boolean finished = false;
int rowsUpdated = 0;
while (!finished) { // will loop if MySQLTransactionRollbackException occurs
try {
c = ConnectionProvider.getConnection(connectionProperties, true);
String sql = "UPDATE unit_job SET end_timestamp = ?, status = '" + UnitJobStatus.UNCONFIRMED_FAILED;
sql += "', unconfirmed = unconfirmed + 1 WHERE ";
sql += "status = '" + UnitJobStatus.STARTED + "' AND start_timestamp < ? AND job_id = ?";
pp = c.prepareStatement(sql);
pp.setTimestamp(1, new Timestamp(System.currentTimeMillis()));
pp.setTimestamp(2, new Timestamp(System.currentTimeMillis() - job.getUnconfirmedTimeout() * 1000));
pp.setInt(3, job.getId());
pp.setQueryTimeout(60);
rowsUpdated = pp.executeUpdate();
finished = true;
} catch (MySQLTransactionRollbackException mtre) {
logger.warn("A deadlock occured, the statement is retried");
} catch (SQLException sqlex) {
sqle = sqlex;
throw sqlex;
} finally {
if (pp != null)
pp.close();
if (c != null)
ConnectionProvider.returnConnection(c, sqle);
}
}
return rowsUpdated;
}
示例3: markAsProcessed
import com.mysql.jdbc.exceptions.MySQLTransactionRollbackException; //导入依赖的package包/类
public int markAsProcessed(UnitJob uj) throws SQLException, NoAvailableConnectionException {
Connection c = null;
PreparedStatement pp = null;
SQLException sqle = null;
boolean finished = false;
int rowsUpdated = 0;
while (!finished) { // will loop if MySQLTransactionRollbackException occurs
try {
c = ConnectionProvider.getConnection(connectionProperties, true);
String sql = "UPDATE unit_job SET processed = 1 WHERE unit_id = ? AND job_id = ?";
pp = c.prepareStatement(sql);
pp.setString(1, uj.getUnitId());
pp.setInt(2, uj.getJobId());
pp.setQueryTimeout(60);
rowsUpdated = pp.executeUpdate();
finished = true;
return rowsUpdated;
} catch (MySQLTransactionRollbackException mtre) {
logger.warn("A deadlock occured, the statement is retried");
} catch (SQLException sqlex) {
sqle = sqlex;
throw sqlex;
} finally {
if (pp != null)
pp.close();
if (c != null)
ConnectionProvider.returnConnection(c, sqle);
}
}
return rowsUpdated;
}
示例4: stop
import com.mysql.jdbc.exceptions.MySQLTransactionRollbackException; //导入依赖的package包/类
public boolean stop(UnitJob uj) throws SQLException, NoAvailableConnectionException {
Connection c = null;
PreparedStatement pp = null;
SQLException sqle = null;
boolean finished = false;
int rowsUpdated = 0;
while (!finished) { // will loop if MySQLTransactionRollbackException occurs
try {
c = ConnectionProvider.getConnection(connectionProperties, true);
if (uj.getStatus().equals(UnitJobStatus.COMPLETED_OK) || uj.getStatus().equals(UnitJobStatus.STOPPED)) {
pp = c.prepareStatement("UPDATE unit_job SET status = '" + uj.getStatus() + "', end_timestamp = ?, processed = 0 WHERE unit_id = ? AND job_id = ?");
pp.setTimestamp(1, new Timestamp(uj.getEndTimestamp().getTime()));
pp.setString(2, uj.getUnitId());
pp.setInt(3, uj.getJobId());
pp.setQueryTimeout(60);
rowsUpdated = pp.executeUpdate();
} else {
pp = c.prepareStatement("UPDATE unit_job SET end_timestamp = ?, status = '" + uj.getStatus() + "', confirmed = confirmed + 1, processed = 0 WHERE unit_id = ? AND job_id = ?");
pp.setTimestamp(1, new Timestamp(uj.getEndTimestamp().getTime()));
pp.setString(2, uj.getUnitId());
pp.setInt(3, uj.getJobId());
pp.setQueryTimeout(60);
rowsUpdated = pp.executeUpdate();
}
finished = true;
} catch (MySQLTransactionRollbackException mtre) {
logger.warn("A deadlock occured, the statement is retried");
} catch (SQLException sqlex) {
sqle = sqlex;
throw sqlex;
} finally {
if (pp != null)
pp.close();
if (c != null)
ConnectionProvider.returnConnection(c, sqle);
}
}
if (rowsUpdated > 0)
return true;
return false;
}