BigIntegerType implements UserType { @Override public void nullSafeSet(final PreparedStatement st, final Object value, final int index, final SharedSessionContractImplementor session) throws HibernateException, SQLException { if (value != null) { BigInteger bigInteger = (BigInteger) value; byte[] result = bigInteger.toByteArray(); if (result.length != 16) { byte[] zerofill = new byte[16]; System.arraycopy(result, 0, zerofill, zerofill.length - result.length, result.length); result = zerofill; } st.setBytes(index, result); } else { st.setNull(index, Types.BINARY); } }  @Override int[] sqlTypes(); @Override Class returnedClass(); @Override boolean equals(final Object x,
                          final Object y); @Override int hashCode(final Object x); @Override Object nullSafeGet(final ResultSet rs,
                              final String[] names,
                              final SharedSessionContractImplementor session,
                              final Object owner); @Override void nullSafeSet(final PreparedStatement st,
                            final Object value,
                            final int index,
                            final SharedSessionContractImplementor session); @Override Object deepCopy(final Object value); @Override boolean isMutable(); @Override Serializable disassemble(final Object value); @Override Object assemble(final Serializable cached,
                           final Object owner); @Override Object replace(final Object original,
                          final Object target,
                          final Object owner);  }
@Test public void nullSafeSet() throws Exception { BigIntegerType type = new BigIntegerType(); PreparedStatement st = Mockito.mock(PreparedStatement.class); BigInteger one = BigInteger.ONE; type.nullSafeSet(st, one, 0, null); byte[] zerofill = new byte[16]; byte[] expected = one.toByteArray(); System.arraycopy(expected, 0, zerofill, zerofill.length - expected.length, expected.length); expected = zerofill; Mockito.verify(st, times(1)) .setBytes(0, expected); }
@Test public void nullSafeShort() throws Exception { BigIntegerType type = new BigIntegerType(); PreparedStatement st = Mockito.mock(PreparedStatement.class); BigInteger one = BigInteger.TEN; type.nullSafeSet(st, one, 0, null); Mockito.verify(st, times(1)) .setBytes(0, new byte[]{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 10 }); }
@Test public void nullSafeSetNull() throws Exception { BigIntegerType type = new BigIntegerType(); PreparedStatement st = Mockito.mock(PreparedStatement.class); type.nullSafeSet(st, null, 0, null); Mockito.verify(st, times(1)).setNull(0, Types.BINARY); }