(final List<Transaction> transactions)
| 257 | // the ORA-00001 exception in Oracle instead of client-side to get around |
| 258 | // that. |
| 259 | void processBatch(final List<Transaction> transactions) throws SQLException { |
| 260 | final String insertTxQ = mTransactionsTbl.getInsertStatement(); |
| 261 | final String insertInputQ = mTransactionInputsTbl.getInsertStatement(); |
| 262 | final String insertOutputQ = mTransactionOutputsTbl.getInsertStatement(); |
| 263 | |
| 264 | try (Connection conn = mDataSource.getConnection(); |
| 265 | PreparedStatement psTx = conn.prepareStatement(insertTxQ); |
| 266 | PreparedStatement psIn = conn.prepareStatement(insertInputQ); |
| 267 | PreparedStatement psOut = conn.prepareStatement(insertOutputQ); |
| 268 | PreparedStatement psSpent = conn.prepareStatement(SQL_MARK_SPENT_QUERY)) { |
| 269 | |
| 270 | // Manage our own SQL transactions so we can make this whole |
| 271 | // blockchain transaction atomic. |
| 272 | conn.setAutoCommit(false); |
| 273 | |
| 274 | for (Transaction tx : transactions) { |
| 275 | try { |
| 276 | ThreadContext.put("tx_id", tx.id); |
| 277 | logger.debug("Importing transaction {}", tx.id); |
| 278 | |
| 279 | // Insert the transaction itself. |
| 280 | psTx.setString(1, tx.id); |
| 281 | psTx.setLong(2, tx.blockHeight); |
| 282 | psTx.setTimestamp(3, new Timestamp(tx.timestamp.getTime())); |
| 283 | psTx.setInt(4, tx.position); |
| 284 | psTx.setString(5, "yes".equals(tx.isLocal) ? TRUE : FALSE); |
| 285 | psTx.setBlob(6, asJsonBlob(tx.referenceData)); |
| 286 | psTx.setBlob(7, asJsonBlob(tx)); |
| 287 | for (int j = 0; j < mConfig.transactionColumns.size(); j++) { |
| 288 | Config.CustomColumn col = mConfig.transactionColumns.get(j); |
| 289 | Object value = col.jsonPath.extract(tx); |
| 290 | psTx.setObject(8 + j, value, col.type.getType()); |
| 291 | } |
| 292 | |
| 293 | // TODO(jackson): We can't use addBatch in Oracle |
| 294 | // earlier than 12.1. If customers need support for |
| 295 | // Oracle < 12.1, we'll need to use the deprecated |
| 296 | // OraclePreparedStatement.setExecuteBatch method: |
| 297 | // http://docs.oracle.com/cd/B28359_01/java.111/b31224/oraperf.htm |
| 298 | psTx.addBatch(); |
| 299 | |
| 300 | // Insert each of the inputs. |
| 301 | boolean spentOutput = false; |
| 302 | for (int i = 0; i < tx.inputs.size(); i++) { |
| 303 | final Transaction.Input input = tx.inputs.get(i); |
| 304 | |
| 305 | psIn.setString(1, tx.id); |
| 306 | psIn.setInt(2, i); |
| 307 | psIn.setString(3, input.type); |
| 308 | psIn.setString(4, input.assetId); |
| 309 | psIn.setString(5, input.assetAlias); |
| 310 | psIn.setBlob(6, asJsonBlob(input.assetDefinition)); |
| 311 | psIn.setBlob(7, asJsonBlob(input.assetTags)); |
| 312 | psIn.setString(8, "yes".equals(input.assetIsLocal) ? TRUE : FALSE); |
| 313 | psIn.setLong(9, input.amount); |
| 314 | psIn.setString(10, input.accountId); |
| 315 | psIn.setString(11, input.accountAlias); |
| 316 | psIn.setBlob(12, asJsonBlob(input.accountTags)); |
no test coverage detected