View Javadoc

1   /*
2    * Copyright 2004-2007 Brian McCallister
3    *
4    * Licensed under the Apache License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    *      http://www.apache.org/licenses/LICENSE-2.0
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
15   */
16  
17  package org.skife.jdbi.v2;
18  
19  import java.sql.Connection;
20  import java.sql.SQLException;
21  import java.sql.Statement;
22  import java.util.Collections;
23  
24  import org.skife.jdbi.v2.tweak.SQLLog;
25  import org.skife.jdbi.v2.tweak.StatementBuilder;
26  import org.skife.jdbi.v2.tweak.StatementCustomizer;
27  import org.skife.jdbi.v2.tweak.StatementLocator;
28  import org.skife.jdbi.v2.tweak.StatementRewriter;
29  
30  /**
31   * Used for INSERT, UPDATE, and DELETE statements
32   */
33  public class Update extends SQLStatement<Update>
34  {
35      Update(Connection connection,
36             StatementLocator locator,
37             StatementRewriter statementRewriter,
38             StatementBuilder cache,
39             String sql,
40             StatementContext ctx,
41             SQLLog log,
42             TimingCollector timingCollector)
43      {
44          super(new Binding(), locator, statementRewriter, connection, cache, sql, ctx, log, timingCollector, Collections.<StatementCustomizer>emptyList());
45      }
46  
47      /**
48       * Execute the statement
49       * @return the number of rows modified
50       */
51      public int execute()
52      {
53          return this.internalExecute(QueryPreperator.NO_OP, new QueryResultMunger<Integer>()
54          {
55              public Integer munge(Statement results) throws SQLException
56              {
57                  return results.getUpdateCount();
58              }
59          }, QueryPostMungeCleanup.CLOSE_RESOURCES_QUIETLY);
60      }
61  }