DBUtils { public static String getDBTypeForClass(final Class<?> valueType){ if ( CharSequence.class.isAssignableFrom(valueType) || BigDecimal.class.isAssignableFrom(valueType)) { return "TEXT"; }else if (Long.class.isAssignableFrom(valueType) || Integer.class.isAssignableFrom(valueType) || Short.class.isAssignableFrom(valueType) || Boolean.class.isAssignableFrom(valueType) || Date.class.isAssignableFrom(valueType)) { return "INTEGER"; }else if (Float.class.isAssignableFrom(valueType) || Double.class.isAssignableFrom(valueType)){ return "REAL"; }else if (valueType == byte[].class){ return "BLOB"; }else{ throw new IllegalStateException("Type " + valueType + " not supported."); } }  static Closeable wrapAsCloseable(final ResultSet resultSet); static boolean setAutoCommit(final Connection connection, final boolean value); static void commit(final Connection connection); static boolean rollback(final Connection connection); static void closeQuietly(java.sql.ResultSet resultSet); static void closeQuietly(Statement statement); static void closeQuietly(Connection connection); static String getDBTypeForClass(final Class<?> valueType); static void setValueToPreparedStatement(int index, final PreparedStatement preparedStatement, Object value); static int setValuesToPreparedStatement(final int startIndex, final PreparedStatement preparedStatement, final Iterable values); @SuppressWarnings("unchecked") static T getValueFromResultSet(int index, final ResultSet resultSet, final Class<T> type); static String sanitizeForTableName(String input);  }
@Test public void testGetDBTypeForClass() throws Exception { Assert.assertEquals("INTEGER", DBUtils.getDBTypeForClass(Integer.class)); Assert.assertEquals("INTEGER", DBUtils.getDBTypeForClass(Long.class)); Assert.assertEquals("INTEGER", DBUtils.getDBTypeForClass(Short.class)); Assert.assertEquals("INTEGER", DBUtils.getDBTypeForClass(Boolean.class)); Assert.assertEquals("REAL", DBUtils.getDBTypeForClass(Float.class)); Assert.assertEquals("REAL", DBUtils.getDBTypeForClass(Double.class)); Assert.assertEquals("TEXT", DBUtils.getDBTypeForClass(String.class)); Assert.assertEquals("TEXT", DBUtils.getDBTypeForClass(CharSequence.class)); Assert.assertEquals("TEXT", DBUtils.getDBTypeForClass(BigDecimal.class)); Assert.assertEquals("INTEGER", DBUtils.getDBTypeForClass(java.util.Date.class)); Assert.assertEquals("INTEGER", DBUtils.getDBTypeForClass(java.sql.Date.class)); Assert.assertEquals("INTEGER", DBUtils.getDBTypeForClass(Time.class)); Assert.assertEquals("INTEGER", DBUtils.getDBTypeForClass(Timestamp.class)); Assert.assertEquals("BLOB", DBUtils.getDBTypeForClass(byte[].class)); }
@Test(expected = IllegalStateException.class) public void testGetDBTypeForClass_UnsupportedType() throws Exception { DBUtils.getDBTypeForClass(Calendar.class); }