3 * Copyright (C) 2009-2017 SonarSource SA
4 * mailto:info AT sonarsource DOT com
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 3 of the License, or (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public License
17 * along with this program; if not, write to the Free Software Foundation,
18 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
20 package org.sonar.server.platform.db.migration.step;
22 import java.sql.PreparedStatement;
23 import java.sql.SQLException;
24 import java.sql.Timestamp;
25 import java.sql.Types;
26 import java.util.Date;
27 import javax.annotation.Nullable;
28 import org.apache.commons.dbutils.DbUtils;
30 class BaseSqlStatement<CHILD extends SqlStatement> implements SqlStatement<CHILD> {
31 protected PreparedStatement pstmt;
33 protected BaseSqlStatement(PreparedStatement pstmt) {
39 DbUtils.closeQuietly(pstmt);
44 public CHILD setString(int columnIndex, @Nullable String value) throws SQLException {
45 pstmt.setString(columnIndex, value);
50 public CHILD setInt(int columnIndex, @Nullable Integer value) throws SQLException {
52 pstmt.setNull(columnIndex, Types.INTEGER);
54 pstmt.setInt(columnIndex, value);
60 public CHILD setLong(int columnIndex, @Nullable Long value) throws SQLException {
62 pstmt.setNull(columnIndex, Types.BIGINT);
64 pstmt.setLong(columnIndex, value);
70 public CHILD setBoolean(int columnIndex, @Nullable Boolean value) throws SQLException {
72 pstmt.setNull(columnIndex, Types.BOOLEAN);
74 pstmt.setBoolean(columnIndex, value);
80 public CHILD setDouble(int columnIndex, @Nullable Double value) throws SQLException {
82 pstmt.setNull(columnIndex, Types.DECIMAL);
84 pstmt.setDouble(columnIndex, value);
90 public CHILD setDate(int columnIndex, @Nullable Date value) throws SQLException {
92 pstmt.setNull(columnIndex, Types.TIMESTAMP);
94 pstmt.setTimestamp(columnIndex, new Timestamp(value.getTime()));