public Short toShort(Double self) { return self.shortValue(); }
public short evaluate(String xml, String path) { return xpath.evalNumber(xml, path).shortValue(); } }
public short evaluate(String xml, String path) { return xpath.evalNumber(xml, path).shortValue(); } }
return (X) Short.valueOf( value.shortValue() );
case Types.SMALLINT: case Types.TINYINT: return new PGShort( new Short( val.shortValue() ) ); case Types.VARCHAR: case Types.LONGVARCHAR:
@Test public void testStatement() { OutParameters ret = h.createCall("? = CALL TO_DEGREES(?)") .registerOutParameter(0, Types.DOUBLE) .bind(1, 100.0d) .invoke(); Double expected = Math.toDegrees(100.0d); assertThat(ret.getDouble(0)).isEqualTo(expected, Offset.offset(0.001)); assertThat(ret.getLong(0).longValue()).isEqualTo(expected.longValue()); assertThat(ret.getShort(0).shortValue()).isEqualTo(expected.shortValue()); assertThat(ret.getInt(0).intValue()).isEqualTo(expected.intValue()); assertThat(ret.getFloat(0).floatValue()).isEqualTo(expected.floatValue(), Offset.offset(0.001f)); assertThatExceptionOfType(Exception.class).isThrownBy(() -> ret.getDate(1)); assertThatExceptionOfType(Exception.class).isThrownBy(() -> ret.getDate(2)); }
@Test public void testStatementWithNamedParam() { OutParameters ret = h.createCall(":x = CALL TO_DEGREES(:y)") .registerOutParameter("x", Types.DOUBLE) .bind("y", 100.0d) .invoke(); Double expected = Math.toDegrees(100.0d); assertThat(ret.getDouble("x")).isEqualTo(expected, Offset.offset(0.001)); assertThat(ret.getLong("x").longValue()).isEqualTo(expected.longValue()); assertThat(ret.getShort("x").shortValue()).isEqualTo(expected.shortValue()); assertThat(ret.getInt("x").intValue()).isEqualTo(expected.intValue()); assertThat(ret.getFloat("x")).isEqualTo(expected.floatValue()); assertThatExceptionOfType(Exception.class).isThrownBy(() -> ret.getDate("x")); assertThatExceptionOfType(Exception.class).isThrownBy(() -> ret.getDate("y")); }
/** * @param value string represented numerical value * @return value as Short */ public static Short getShortValue(String value) { nShorts++; return parseDoubleUnit(value).shortValue(); }
private void updateUnsignedTable(Connection conn, double data) throws Exception { PreparedStatement stmt = conn.prepareStatement("UPSERT INTO " + testUnsignedTable + " VALUES (?, ?, ?, ?, ?, ?, ?)"); stmt.setString(1, KEY); Double d = Double.valueOf(data); stmt.setDouble(2, d.doubleValue()); stmt.setFloat(3, d.floatValue()); stmt.setInt(4, d.intValue()); stmt.setLong(5, d.longValue()); stmt.setShort(6, d.shortValue()); stmt.setByte(7, d.byteValue()); stmt.executeUpdate(); conn.commit(); }
private void updateSignedTable(Connection conn, double data) throws Exception { PreparedStatement stmt = conn.prepareStatement("UPSERT INTO " + signedTableName + " VALUES (?, ?, ?, ?, ?, ?, ?)"); stmt.setString(1, KEY); Double d = Double.valueOf(data); stmt.setDouble(2, d.doubleValue()); stmt.setFloat(3, d.floatValue()); stmt.setInt(4, d.intValue()); stmt.setLong(5, d.longValue()); stmt.setShort(6, d.shortValue()); stmt.setByte(7, d.byteValue()); stmt.executeUpdate(); conn.commit(); }
private void updateSignedTable(Connection conn, double data) throws Exception { PreparedStatement stmt = conn.prepareStatement("UPSERT INTO " + testSignedTable + " VALUES (?, ?, ?, ?, ?, ?, ?)"); stmt.setString(1, KEY); Double d = Double.valueOf(data); stmt.setDouble(2, d.doubleValue()); stmt.setFloat(3, d.floatValue()); stmt.setInt(4, d.intValue()); stmt.setLong(5, d.longValue()); stmt.setShort(6, d.shortValue()); stmt.setByte(7, d.byteValue()); stmt.executeUpdate(); conn.commit(); }
private void updateUnsignedTable(Connection conn, double data) throws Exception { PreparedStatement stmt = conn.prepareStatement("UPSERT INTO " + unsignedTableName + " VALUES (?, ?, ?, ?, ?, ?, ?)"); stmt.setString(1, KEY); Double d = Double.valueOf(data); stmt.setDouble(2, d.doubleValue()); stmt.setFloat(3, d.floatValue()); stmt.setInt(4, d.intValue()); stmt.setLong(5, d.longValue()); stmt.setShort(6, d.shortValue()); stmt.setByte(7, d.byteValue()); stmt.executeUpdate(); conn.commit(); }
private void updateSignedTable(Connection conn, double data) throws Exception { PreparedStatement stmt = conn.prepareStatement( "UPSERT INTO " + signedTableName + " VALUES (?, ?, ?, ?, ?, ?, ?)"); stmt.setString(1, KEY); Double d = Double.valueOf(data); stmt.setDouble(2, d.doubleValue()); stmt.setFloat(3, d.floatValue()); stmt.setInt(4, d.intValue()); stmt.setLong(5, d.longValue()); stmt.setShort(6, d.shortValue()); stmt.setByte(7, d.byteValue()); stmt.executeUpdate(); conn.commit(); }
private void updateUnsignedTable(Connection conn, double data) throws Exception { PreparedStatement stmt = conn.prepareStatement( "UPSERT INTO " + unsignedTableName + " VALUES (?, ?, ?, ?, ?, ?, ?)"); stmt.setString(1, KEY); Double d = Double.valueOf(data); stmt.setDouble(2, d.doubleValue()); stmt.setFloat(3, d.floatValue()); stmt.setInt(4, d.intValue()); stmt.setLong(5, d.longValue()); stmt.setShort(6, d.shortValue()); stmt.setByte(7, d.byteValue()); stmt.executeUpdate(); conn.commit(); }
private void updateTableSpec(Connection conn, double data, String tableName) throws Exception { PreparedStatement stmt = conn.prepareStatement("UPSERT INTO " + tableName + " VALUES (?, ?, ?, ?, ?, ?, ?)"); stmt.setString(1, KEY); Double d = Double.valueOf(data); stmt.setDouble(2, d.doubleValue()); stmt.setFloat(3, d.floatValue()); stmt.setInt(4, d.intValue()); stmt.setLong(5, d.longValue()); stmt.setShort(6, d.shortValue()); stmt.setByte(7, d.byteValue()); stmt.executeUpdate(); conn.commit(); }
private void updateUnsignedTable(Connection conn, double data) throws Exception { PreparedStatement stmt = conn.prepareStatement( "UPSERT INTO " + unsignedTableName + " VALUES (?, ?, ?, ?, ?, ?, ?)"); stmt.setString(1, KEY); Double d = Double.valueOf(data); stmt.setDouble(2, d.doubleValue()); stmt.setFloat(3, d.floatValue()); stmt.setInt(4, d.intValue()); stmt.setLong(5, d.longValue()); stmt.setShort(6, d.shortValue()); stmt.setByte(7, d.byteValue()); stmt.executeUpdate(); conn.commit(); }
private void updateSignedTable(Connection conn, double data) throws Exception { PreparedStatement stmt = conn.prepareStatement("UPSERT INTO " + TABLE_NAME + " VALUES (?, ?, ?, ?, ?, ?, ?, ?)"); stmt.setString(1, KEY); Double d = Double.valueOf(data); stmt.setBigDecimal(2, BigDecimal.valueOf(data)); stmt.setDouble(3, d.doubleValue()); stmt.setFloat(4, d.floatValue()); stmt.setInt(5, d.intValue()); stmt.setLong(6, d.longValue()); stmt.setShort(7, d.shortValue()); stmt.setByte(8, d.byteValue()); stmt.executeUpdate(); conn.commit(); }
private void updateTableSpec(Connection conn, double data, String tableName) throws Exception { PreparedStatement stmt = conn.prepareStatement("UPSERT INTO " + tableName + " VALUES (?, ?, ?, ?, ?, ?, ?)"); stmt.setString(1, KEY); Double d = Double.valueOf(data); stmt.setDouble(2, d.doubleValue()); stmt.setFloat(3, d.floatValue()); stmt.setInt(4, d.intValue()); stmt.setLong(5, d.longValue()); stmt.setShort(6, d.shortValue()); stmt.setByte(7, d.byteValue()); stmt.executeUpdate(); conn.commit(); }
private void testUnsignedNumberSpec(Connection conn, double data) throws Exception { updateUnsignedTable(conn, data); ResultSet rs = conn.createStatement().executeQuery("SELECT EXP(doub),EXP(fl),EXP(inte),EXP(lon),EXP(smalli),EXP(tinyi) FROM " + unsignedTableName); assertTrue(rs.next()); Double d = Double.valueOf(data); assertTrue(Math.abs(rs.getDouble(1) - Math.exp(d.doubleValue())) < ZERO); assertTrue(Math.abs(rs.getDouble(2) - Math.exp(d.floatValue())) < ZERO); assertTrue(Math.abs(rs.getDouble(3) - Math.exp(d.intValue())) < ZERO); assertTrue(Math.abs(rs.getDouble(4) - Math.exp(d.longValue())) < ZERO); assertTrue(Math.abs(rs.getDouble(5) - Math.exp(d.shortValue())) < ZERO); assertTrue(Math.abs(rs.getDouble(6) - Math.exp(d.byteValue())) < ZERO); assertTrue(!rs.next()); }
private void testSignedNumberSpec(Connection conn, double data) throws Exception { updateSignedTable(conn, data); ResultSet rs = conn.createStatement().executeQuery("SELECT EXP(doub),EXP(fl),EXP(inte),EXP(lon),EXP(smalli),EXP(tinyi) FROM " + signedTableName); assertTrue(rs.next()); Double d = Double.valueOf(data); assertTrue(Math.abs(rs.getDouble(1) - Math.exp(d.doubleValue())) < ZERO); assertTrue(Math.abs(rs.getDouble(2) - Math.exp(d.floatValue())) < ZERO); assertTrue(Math.abs(rs.getDouble(3) - Math.exp(d.intValue())) < ZERO); assertTrue(Math.abs(rs.getDouble(4) - Math.exp(d.longValue())) < ZERO); assertTrue(Math.abs(rs.getDouble(5) - Math.exp(d.shortValue())) < ZERO); assertTrue(Math.abs(rs.getDouble(6) - Math.exp(d.byteValue())) < ZERO); assertTrue(!rs.next()); }