3 * Copyright (C) 2009-2020 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 @SuppressWarnings("unchecked")
45 public CHILD setString(int columnIndex, @Nullable String value) throws SQLException {
46 pstmt.setString(columnIndex, value);
51 @SuppressWarnings("unchecked")
52 public CHILD setInt(int columnIndex, @Nullable Integer value) throws SQLException {
54 pstmt.setNull(columnIndex, Types.INTEGER);
56 pstmt.setInt(columnIndex, value);
62 @SuppressWarnings("unchecked")
63 public CHILD setLong(int columnIndex, @Nullable Long value) throws SQLException {
65 pstmt.setNull(columnIndex, Types.BIGINT);
67 pstmt.setLong(columnIndex, value);
73 @SuppressWarnings("unchecked")
74 public CHILD setBoolean(int columnIndex, @Nullable Boolean value) throws SQLException {
76 pstmt.setNull(columnIndex, Types.BOOLEAN);
78 pstmt.setBoolean(columnIndex, value);
84 @SuppressWarnings("unchecked")
85 public CHILD setBytes(int columnIndex, @Nullable byte[] value) throws SQLException {
87 pstmt.setNull(columnIndex, Types.BINARY);
89 pstmt.setBytes(columnIndex, value);
95 @SuppressWarnings("unchecked")
96 public CHILD setDouble(int columnIndex, @Nullable Double value) throws SQLException {
98 pstmt.setNull(columnIndex, Types.DOUBLE);
100 pstmt.setDouble(columnIndex, value);
106 @SuppressWarnings("unchecked")
107 public CHILD setDate(int columnIndex, @Nullable Date value) throws SQLException {
109 pstmt.setNull(columnIndex, Types.TIMESTAMP);
111 pstmt.setTimestamp(columnIndex, new Timestamp(value.getTime()));