Skip to content

Commit

Permalink
chore: spotless apply
Browse files Browse the repository at this point in the history
  • Loading branch information
gotson committed Nov 7, 2022
1 parent 8bcba01 commit 5879783
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 35 deletions.
42 changes: 23 additions & 19 deletions src/main/java/org/sqlite/jdbc4/JDBC4ResultSet.java
Original file line number Diff line number Diff line change
Expand Up @@ -311,31 +311,35 @@ public void updateNClob(String columnLabel, Reader reader) throws SQLException {
}

public <T> T getObject(int columnIndex, Class<T> type) throws SQLException {
if(type == null) throw new SQLException("requested type cannot be null");
if(type == String.class) return type.cast( getString(columnIndex));
if(type == Boolean.class) return type.cast( getBoolean(columnIndex));
if(type == BigDecimal.class) return type.cast(getBigDecimal(columnIndex));
if(type == byte[].class) return type.cast(getBytes(columnIndex));
if(type == Date.class) return type.cast(getDate(columnIndex));
if(type == Time.class) return type.cast(getTime(columnIndex));
if(type == Timestamp.class) return type.cast(getTimestamp(columnIndex));
if (type == null) throw new SQLException("requested type cannot be null");
if (type == String.class) return type.cast(getString(columnIndex));
if (type == Boolean.class) return type.cast(getBoolean(columnIndex));
if (type == BigDecimal.class) return type.cast(getBigDecimal(columnIndex));
if (type == byte[].class) return type.cast(getBytes(columnIndex));
if (type == Date.class) return type.cast(getDate(columnIndex));
if (type == Time.class) return type.cast(getTime(columnIndex));
if (type == Timestamp.class) return type.cast(getTimestamp(columnIndex));

int columnType = safeGetColumnType(markCol(columnIndex));
if(type == Double.class) {
if(columnType == SQLITE_INTEGER || columnType == SQLITE_FLOAT) return type.cast(getDouble(columnIndex));
if (type == Double.class) {
if (columnType == SQLITE_INTEGER || columnType == SQLITE_FLOAT)
return type.cast(getDouble(columnIndex));
throw new SQLException("Bad value for type Double");
}
if(type == Long.class) {
if(columnType == SQLITE_INTEGER || columnType == SQLITE_FLOAT) return type.cast(getLong(columnIndex));
throw new SQLException("Bad value for type Long");
if (type == Long.class) {
if (columnType == SQLITE_INTEGER || columnType == SQLITE_FLOAT)
return type.cast(getLong(columnIndex));
throw new SQLException("Bad value for type Long");
}
if(type == Float.class) {
if(columnType == SQLITE_INTEGER || columnType == SQLITE_FLOAT) return type.cast(getFloat(columnIndex));
throw new SQLException("Bad value for type Float");
if (type == Float.class) {
if (columnType == SQLITE_INTEGER || columnType == SQLITE_FLOAT)
return type.cast(getFloat(columnIndex));
throw new SQLException("Bad value for type Float");
}
if(type == Integer.class) {
if(columnType == SQLITE_INTEGER || columnType == SQLITE_FLOAT) return type.cast(getInt(columnIndex));
throw new SQLException("Bad value for type Integer");
if (type == Integer.class) {
if (columnType == SQLITE_INTEGER || columnType == SQLITE_FLOAT)
return type.cast(getInt(columnIndex));
throw new SQLException("Bad value for type Integer");
}

throw unsupported();
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/org/sqlite/util/OSInfo.java
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,7 @@ static String resolveArmArchType() {

public static String getArchName() {
String override = System.getProperty("org.sqlite.osinfo.architecture");
if(override != null) {
if (override != null) {
return override;
}

Expand Down
24 changes: 11 additions & 13 deletions src/test/java/org/sqlite/ResultSetTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
import java.sql.Statement;
import java.sql.Time;
import java.sql.Timestamp;

import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
Expand Down Expand Up @@ -284,8 +283,7 @@ public void testGetBigDecimal() throws SQLException {

@Test
void getObjectWithRequestedType() throws SQLException {
stat.executeUpdate(
"create table getobject(c1)");
stat.executeUpdate("create table getobject(c1)");
stat.executeUpdate("insert into getobject values (1)");
stat.executeUpdate("insert into getobject values ('abc')");

Expand All @@ -309,20 +307,20 @@ void getObjectWithRequestedType() throws SQLException {
assertThat(rs.getObject(1, Boolean.class)).isFalse();
assertThat(rs.getObject(1, byte[].class)).isEqualTo(rs.getBytes(1));
assertThatExceptionOfType(SQLException.class)
.isThrownBy(() -> rs.getObject(1, BigDecimal.class))
.withMessageContaining("Bad value for type BigDecimal");
.isThrownBy(() -> rs.getObject(1, BigDecimal.class))
.withMessageContaining("Bad value for type BigDecimal");
assertThatExceptionOfType(SQLException.class)
.isThrownBy(() -> rs.getObject(1, Double.class))
.withMessageContaining("Bad value for type Double");
.isThrownBy(() -> rs.getObject(1, Double.class))
.withMessageContaining("Bad value for type Double");
assertThatExceptionOfType(SQLException.class)
.isThrownBy(() -> rs.getObject(1, Long.class))
.withMessageContaining("Bad value for type Long");
.isThrownBy(() -> rs.getObject(1, Long.class))
.withMessageContaining("Bad value for type Long");
assertThatExceptionOfType(SQLException.class)
.isThrownBy(() -> rs.getObject(1, Float.class))
.withMessageContaining("Bad value for type Float");
.isThrownBy(() -> rs.getObject(1, Float.class))
.withMessageContaining("Bad value for type Float");
assertThatExceptionOfType(SQLException.class)
.isThrownBy(() -> rs.getObject(1, Integer.class))
.withMessageContaining("Bad value for type Integer");
.isThrownBy(() -> rs.getObject(1, Integer.class))
.withMessageContaining("Bad value for type Integer");

assertThat(rs.next()).isFalse();
}
Expand Down
3 changes: 1 addition & 2 deletions src/test/java/org/sqlite/util/OSInfoTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,6 @@ public void testArm64NativePath() throws IOException, InterruptedException {
@SetSystemProperty(key = "os.name", value = "Windows")
void testOverride() {
assertThat(OSInfo.getArchName()).isEqualTo("overridden");
assertThat(OSInfo.getNativeLibFolderPathForCurrentOS())
.isEqualTo("Windows/overridden");
assertThat(OSInfo.getNativeLibFolderPathForCurrentOS()).isEqualTo("Windows/overridden");
}
}

0 comments on commit 5879783

Please sign in to comment.