Skip to content

Commit

Permalink
Change SQL literals to use parameters -- fixes high number of parse c…
Browse files Browse the repository at this point in the history
…alls in database
  • Loading branch information
erilong committed Aug 21, 2008
1 parent 2a4f28e commit 4ad04e3
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 10 deletions.
Expand Up @@ -112,8 +112,9 @@ public Object doInConnection(Connection conn) throws SQLException, DataAccessExc

select.setQueryTimeout(jdbcTemplate.getQueryTimeout());

select.setString(1, nodeId);
select.setString(2, channel.getId());
select.setInt(1, 0);
select.setString(2, nodeId);
select.setString(3, channel.getId());
results = select.executeQuery();

int count = 0;
Expand Down Expand Up @@ -156,8 +157,9 @@ public Object doInConnection(Connection conn) throws SQLException, DataAccessExc

update.clearParameters();
update.setLong(1, Long.valueOf(newBatch.getBatchId()));
update.setString(2, nodeId);
update.setLong(3, dataId);
update.setInt(2, 1);
update.setString(3, nodeId);
update.setLong(4, dataId);
update.addBatch();

count++;
Expand Down Expand Up @@ -232,8 +234,10 @@ public Object doInPreparedStatement(PreparedStatement ps) throws SQLException, D
*/
@SuppressWarnings("unchecked")
public List<OutgoingBatch> getOutgoingBatches(String nodeId) {
List<OutgoingBatch> list = (List<OutgoingBatch>) jdbcTemplate.query(
getSql("selectOutgoingBatchSql"), new Object[] { nodeId }, new OutgoingBatchMapper());
List<OutgoingBatch> list = (List<OutgoingBatch>) jdbcTemplate.query(getSql("selectOutgoingBatchSql"),
new Object[] { nodeId, OutgoingBatch.Status.NE.toString(),
OutgoingBatch.Status.SE.toString(), OutgoingBatch.Status.ER.toString() },
new OutgoingBatchMapper());
final HashSet<String> errorChannels = new HashSet<String>();
for (OutgoingBatch batch : list) {
if (batch.getStatus().equals(OutgoingBatch.Status.ER)) {
Expand Down
Expand Up @@ -16,8 +16,8 @@
</entry>
<entry key="selectEventsToBatchSql">
<value>
select transaction_id, data_id from ${sync.table.prefix}_data_event where batched = 0 and
node_id = ? and channel_id=? order by data_id asc
select transaction_id, data_id from ${sync.table.prefix}_data_event where batched = ? and
node_id = ? and channel_id = ? order by data_id asc
</value>
</entry>
<entry key="createBatchSql">
Expand All @@ -28,14 +28,14 @@
</entry>
<entry key="updateBatchedEventsSql">
<value>
update ${sync.table.prefix}_data_event set batch_id = ?, batched = 1 where node_id = ? and
update ${sync.table.prefix}_data_event set batch_id = ?, batched = ? where node_id = ? and
data_id = ?
</value>
</entry>
<entry key="selectOutgoingBatchSql">
<value>
select batch_id, node_id, channel_id, status, batch_type, create_time from
${sync.table.prefix}_outgoing_batch where node_id = ? and status in ('NE', 'SE', 'ER')
${sync.table.prefix}_outgoing_batch where node_id = ? and status in (?, ?, ?)
</value>
</entry>
<entry key="selectOutgoingBatchRangeSql">
Expand Down

0 comments on commit 4ad04e3

Please sign in to comment.