@Test public void getObjectPrimitiveFloat() throws SQLException { Mockito.when(resultSet.getObject(1)).thenReturn(0.1f); Mockito.when(resultSet.getFloat(1)).thenReturn(0.1f); Assert.assertEquals(0.1f, GenericDaoBase.getObject(float.class, resultSet, 1), 0.1); Mockito.verify(resultSet).getFloat(1); }
@DB() protected static <M> M getObject(final Class<M> type, final ResultSet rs, final int index) throws SQLException { if (type == String.class) { final byte[] bytes = rs.getBytes(index); if (bytes != null) { try { return (M) new String(bytes, "UTF-8"); } catch (final UnsupportedEncodingException e) { throw new CloudRuntimeException("UnsupportedEncodingException exception while converting UTF-8 data"); } } else { return null; } } else if (type == int.class) { return (M) (Integer) rs.getInt(index); } else if (type == Integer.class) { if (rs.getObject(index) == null) { return null; } else { return (M) (Integer) rs.getInt(index); } } else if (type == long.class) { return (M) (Long) rs.getLong(index); } else if (type == Long.class) { if (rs.getObject(index) == null) { return null; } else { return (M) (Long) rs.getLong(index); } } else if (type == Date.class) { final Object data = rs.getDate(index); if (data == null) { return null; } else { return (M) DateUtil.parseDateString(s_gmtTimeZone, rs.getString(index)); } } else if (type == short.class) { return (M) (Short) rs.getShort(index); } else if (type == Short.class) { if (rs.getObject(index) == null) { return null; } else { return (M) (Short) rs.getShort(index); } } else if (type == boolean.class) { return (M) (Boolean) rs.getBoolean(index); } else if (type == Boolean.class) { if (rs.getObject(index) == null) { return null; } else { return (M) (Boolean) rs.getBoolean(index); } } else if (type == float.class) { return (M) (Float) rs.getFloat(index); } else if (type == Float.class) { if (rs.getObject(index) == null) { return null; } else { return (M) (Float) rs.getFloat(index); } } else if (type == double.class) { return (M) (Double) rs.getDouble(index); } else if (type == Double.class) { if (rs.getObject(index) == null) { return null; } else { return (M) (Double) rs.getDouble(index); } } else if (type == byte.class) { return (M) (Byte) rs.getByte(index); } else if (type == Byte.class) { if (rs.getObject(index) == null) { return null; } else { return (M) (Byte) rs.getByte(index); } } else if (type == Calendar.class) { final Object data = rs.getDate(index); if (data == null) { return null; } else { final Calendar cal = Calendar.getInstance(); cal.setTime(DateUtil.parseDateString(s_gmtTimeZone, rs.getString(index))); return (M) cal; } } else if (type == byte[].class) { return (M) rs.getBytes(index); } else { return (M) rs.getObject(index); } }
GenericDaoBase extends ComponentLifecycleBase implements GenericDao<T, ID>, ComponentMethodInterceptable { @DB() protected static <M> M getObject(final Class<M> type, final ResultSet rs, final int index) throws SQLException { if (type == String.class) { final byte[] bytes = rs.getBytes(index); if (bytes != null) { try { return (M) new String(bytes, "UTF-8"); } catch (final UnsupportedEncodingException e) { throw new CloudRuntimeException("UnsupportedEncodingException exception while converting UTF-8 data"); } } else { return null; } } else if (type == int.class) { return (M) (Integer) rs.getInt(index); } else if (type == Integer.class) { if (rs.getObject(index) == null) { return null; } else { return (M) (Integer) rs.getInt(index); } } else if (type == long.class) { return (M) (Long) rs.getLong(index); } else if (type == Long.class) { if (rs.getObject(index) == null) { return null; } else { return (M) (Long) rs.getLong(index); } } else if (type == Date.class) { final Object data = rs.getDate(index); if (data == null) { return null; } else { return (M) DateUtil.parseDateString(s_gmtTimeZone, rs.getString(index)); } } else if (type == short.class) { return (M) (Short) rs.getShort(index); } else if (type == Short.class) { if (rs.getObject(index) == null) { return null; } else { return (M) (Short) rs.getShort(index); } } else if (type == boolean.class) { return (M) (Boolean) rs.getBoolean(index); } else if (type == Boolean.class) { if (rs.getObject(index) == null) { return null; } else { return (M) (Boolean) rs.getBoolean(index); } } else if (type == float.class) { return (M) (Float) rs.getFloat(index); } else if (type == Float.class) { if (rs.getObject(index) == null) { return null; } else { return (M) (Float) rs.getFloat(index); } } else if (type == double.class) { return (M) (Double) rs.getDouble(index); } else if (type == Double.class) { if (rs.getObject(index) == null) { return null; } else { return (M) (Double) rs.getDouble(index); } } else if (type == byte.class) { return (M) (Byte) rs.getByte(index); } else if (type == Byte.class) { if (rs.getObject(index) == null) { return null; } else { return (M) (Byte) rs.getByte(index); } } else if (type == Calendar.class) { final Object data = rs.getDate(index); if (data == null) { return null; } else { final Calendar cal = Calendar.getInstance(); cal.setTime(DateUtil.parseDateString(s_gmtTimeZone, rs.getString(index))); return (M) cal; } } else if (type == byte[].class) { return (M) rs.getBytes(index); } else { return (M) rs.getObject(index); } } }
GenericDaoBase extends ComponentLifecycleBase implements GenericDao<T, ID>, ComponentMethodInterceptable { @DB() protected static <M> M getObject(final Class<M> type, final ResultSet rs, final int index) throws SQLException { if (type == String.class) { final byte[] bytes = rs.getBytes(index); if (bytes != null) { try { return (M) new String(bytes, "UTF-8"); } catch (final UnsupportedEncodingException e) { throw new CloudRuntimeException("UnsupportedEncodingException exception while converting UTF-8 data"); } } else { return null; } } else if (type == int.class) { return (M) (Integer) rs.getInt(index); } else if (type == Integer.class) { if (rs.getObject(index) == null) { return null; } else { return (M) (Integer) rs.getInt(index); } } else if (type == long.class) { return (M) (Long) rs.getLong(index); } else if (type == Long.class) { if (rs.getObject(index) == null) { return null; } else { return (M) (Long) rs.getLong(index); } } else if (type == Date.class) { final Object data = rs.getDate(index); if (data == null) { return null; } else { return (M) DateUtil.parseDateString(s_gmtTimeZone, rs.getString(index)); } } else if (type == short.class) { return (M) (Short) rs.getShort(index); } else if (type == Short.class) { if (rs.getObject(index) == null) { return null; } else { return (M) (Short) rs.getShort(index); } } else if (type == boolean.class) { return (M) (Boolean) rs.getBoolean(index); } else if (type == Boolean.class) { if (rs.getObject(index) == null) { return null; } else { return (M) (Boolean) rs.getBoolean(index); } } else if (type == float.class) { return (M) (Float) rs.getFloat(index); } else if (type == Float.class) { if (rs.getObject(index) == null) { return null; } else { return (M) (Float) rs.getFloat(index); } } else if (type == double.class) { return (M) (Double) rs.getDouble(index); } else if (type == Double.class) { if (rs.getObject(index) == null) { return null; } else { return (M) (Double) rs.getDouble(index); } } else if (type == byte.class) { return (M) (Byte) rs.getByte(index); } else if (type == Byte.class) { if (rs.getObject(index) == null) { return null; } else { return (M) (Byte) rs.getByte(index); } } else if (type == Calendar.class) { final Object data = rs.getDate(index); if (data == null) { return null; } else { final Calendar cal = Calendar.getInstance(); cal.setTime(DateUtil.parseDateString(s_gmtTimeZone, rs.getString(index))); return (M) cal; } } else if (type == byte[].class) { return (M) rs.getBytes(index); } else { return (M) rs.getObject(index); } } protected  GenericDaoBase(); }
GenericDaoBase extends ComponentLifecycleBase implements GenericDao<T, ID>, ComponentMethodInterceptable { @DB() protected static <M> M getObject(final Class<M> type, final ResultSet rs, final int index) throws SQLException { if (type == String.class) { final byte[] bytes = rs.getBytes(index); if (bytes != null) { try { return (M) new String(bytes, "UTF-8"); } catch (final UnsupportedEncodingException e) { throw new CloudRuntimeException("UnsupportedEncodingException exception while converting UTF-8 data"); } } else { return null; } } else if (type == int.class) { return (M) (Integer) rs.getInt(index); } else if (type == Integer.class) { if (rs.getObject(index) == null) { return null; } else { return (M) (Integer) rs.getInt(index); } } else if (type == long.class) { return (M) (Long) rs.getLong(index); } else if (type == Long.class) { if (rs.getObject(index) == null) { return null; } else { return (M) (Long) rs.getLong(index); } } else if (type == Date.class) { final Object data = rs.getDate(index); if (data == null) { return null; } else { return (M) DateUtil.parseDateString(s_gmtTimeZone, rs.getString(index)); } } else if (type == short.class) { return (M) (Short) rs.getShort(index); } else if (type == Short.class) { if (rs.getObject(index) == null) { return null; } else { return (M) (Short) rs.getShort(index); } } else if (type == boolean.class) { return (M) (Boolean) rs.getBoolean(index); } else if (type == Boolean.class) { if (rs.getObject(index) == null) { return null; } else { return (M) (Boolean) rs.getBoolean(index); } } else if (type == float.class) { return (M) (Float) rs.getFloat(index); } else if (type == Float.class) { if (rs.getObject(index) == null) { return null; } else { return (M) (Float) rs.getFloat(index); } } else if (type == double.class) { return (M) (Double) rs.getDouble(index); } else if (type == Double.class) { if (rs.getObject(index) == null) { return null; } else { return (M) (Double) rs.getDouble(index); } } else if (type == byte.class) { return (M) (Byte) rs.getByte(index); } else if (type == Byte.class) { if (rs.getObject(index) == null) { return null; } else { return (M) (Byte) rs.getByte(index); } } else if (type == Calendar.class) { final Object data = rs.getDate(index); if (data == null) { return null; } else { final Calendar cal = Calendar.getInstance(); cal.setTime(DateUtil.parseDateString(s_gmtTimeZone, rs.getString(index))); return (M) cal; } } else if (type == byte[].class) { return (M) rs.getBytes(index); } else { return (M) rs.getObject(index); } } protected  GenericDaoBase(); @Override @DB() GenericSearchBuilder<T, J> createSearchBuilder(final Class<J> resultType); static GenericDao<? extends J, ? extends Serializable> getDao(final Class<J> entityType); @Override Map<String, Attribute> getAllAttributes(); T createSearchEntity(final MethodInterceptor interceptor); @Override @DB() T createForUpdate(final ID id); @Override @DB() T createForUpdate(); @Override @DB() K getNextInSequence(final Class<K> clazz, final String name); @Override @DB() K getRandomlyIncreasingNextInSequence(final Class<K> clazz, final String name); @Override @DB() List<T> lockRows(final SearchCriteria<T> sc, final Filter filter, final boolean exclusive); @Override @DB() T lockOneRandomRow(final SearchCriteria<T> sc, final boolean exclusive); @DB() int update(final T entity, final SearchCriteria<T> sc, final Integer rows); @Override List<T> searchIncludingRemoved(final SearchCriteria<T> sc, final Filter filter, final Boolean lock, final boolean cache); @DB() static UpdateBuilder getUpdateBuilder(final T entityObject); int update(final UpdateBuilder ub, final SearchCriteria<?> sc, final Integer rows); @Override List<T> searchIncludingRemoved(final SearchCriteria<T> sc, final Filter filter, final Boolean lock, final boolean cache, final boolean enableQueryCache); @Override List<M> customSearchIncludingRemoved(final SearchCriteria<M> sc, final Filter filter); @Override @DB() List<M> customSearch(final SearchCriteria<M> sc, final Filter filter); @Override @DB() boolean configure(final String name, final Map<String, Object> params); Integer getDistinctCount(final SearchCriteria<T> sc); Integer getCount(final SearchCriteria<T> sc); @DB() @Override Class<T> getEntityBeanType(); @Override @DB() T findOneBy(final SearchCriteria<T> sc); @Override @DB() T findById(final ID id); @Override @DB() T findByUuid(final String uuid); @Override @DB() T findByUuidIncludingRemoved(final String uuid); @Override @DB() T findByIdIncludingRemoved(final ID id); @Override @DB() T findById(final ID id, final boolean fresh); @Override @DB() T lockRow(final ID id, final Boolean lock); @Override @DB() T acquireInLockTable(final ID id); @Override T acquireInLockTable(final ID id, final int seconds); @Override boolean releaseFromLockTable(final ID id); @Override @DB() boolean lockInLockTable(final String id); @Override boolean lockInLockTable(final String id, final int seconds); @Override boolean unlockFromLockTable(final String id); @Override @DB() List<T> listAllIncludingRemoved(); @Override @DB() List<T> listAllIncludingRemoved(final Filter filter); @Override @DB() List<T> listAll(); @Override @DB() List<T> listAll(final Filter filter); @Override boolean expunge(final ID id); @Override int expunge(final SearchCriteria<T> sc); @Override @DB() List<T> search(final SearchCriteria<T> sc, final Filter filter); @Override @DB() Pair<List<T>, Integer> searchAndCount(final SearchCriteria<T> sc, final Filter filter); @Override @DB() Pair<List<T>, Integer> searchAndDistinctCount(final SearchCriteria<T> sc, final Filter filter); @Override @DB() List<T> search(final SearchCriteria<T> sc, final Filter filter, final boolean enableQueryCache); @Override @DB() boolean update(final ID id, final T entity); @Override @DB() int update(final T entity, final SearchCriteria<T> sc); @Override T persist(final T entity); @Override void expunge(); @Override boolean remove(final ID id); @Override int remove(final SearchCriteria<T> sc); @Override @DB() SearchBuilder<T> createSearchBuilder(); @Override @DB() SearchCriteria<T> createSearchCriteria(); }
GenericDaoBase extends ComponentLifecycleBase implements GenericDao<T, ID>, ComponentMethodInterceptable { @DB() protected static <M> M getObject(final Class<M> type, final ResultSet rs, final int index) throws SQLException { if (type == String.class) { final byte[] bytes = rs.getBytes(index); if (bytes != null) { try { return (M) new String(bytes, "UTF-8"); } catch (final UnsupportedEncodingException e) { throw new CloudRuntimeException("UnsupportedEncodingException exception while converting UTF-8 data"); } } else { return null; } } else if (type == int.class) { return (M) (Integer) rs.getInt(index); } else if (type == Integer.class) { if (rs.getObject(index) == null) { return null; } else { return (M) (Integer) rs.getInt(index); } } else if (type == long.class) { return (M) (Long) rs.getLong(index); } else if (type == Long.class) { if (rs.getObject(index) == null) { return null; } else { return (M) (Long) rs.getLong(index); } } else if (type == Date.class) { final Object data = rs.getDate(index); if (data == null) { return null; } else { return (M) DateUtil.parseDateString(s_gmtTimeZone, rs.getString(index)); } } else if (type == short.class) { return (M) (Short) rs.getShort(index); } else if (type == Short.class) { if (rs.getObject(index) == null) { return null; } else { return (M) (Short) rs.getShort(index); } } else if (type == boolean.class) { return (M) (Boolean) rs.getBoolean(index); } else if (type == Boolean.class) { if (rs.getObject(index) == null) { return null; } else { return (M) (Boolean) rs.getBoolean(index); } } else if (type == float.class) { return (M) (Float) rs.getFloat(index); } else if (type == Float.class) { if (rs.getObject(index) == null) { return null; } else { return (M) (Float) rs.getFloat(index); } } else if (type == double.class) { return (M) (Double) rs.getDouble(index); } else if (type == Double.class) { if (rs.getObject(index) == null) { return null; } else { return (M) (Double) rs.getDouble(index); } } else if (type == byte.class) { return (M) (Byte) rs.getByte(index); } else if (type == Byte.class) { if (rs.getObject(index) == null) { return null; } else { return (M) (Byte) rs.getByte(index); } } else if (type == Calendar.class) { final Object data = rs.getDate(index); if (data == null) { return null; } else { final Calendar cal = Calendar.getInstance(); cal.setTime(DateUtil.parseDateString(s_gmtTimeZone, rs.getString(index))); return (M) cal; } } else if (type == byte[].class) { return (M) rs.getBytes(index); } else { return (M) rs.getObject(index); } } protected  GenericDaoBase(); @Override @DB() GenericSearchBuilder<T, J> createSearchBuilder(final Class<J> resultType); static GenericDao<? extends J, ? extends Serializable> getDao(final Class<J> entityType); @Override Map<String, Attribute> getAllAttributes(); T createSearchEntity(final MethodInterceptor interceptor); @Override @DB() T createForUpdate(final ID id); @Override @DB() T createForUpdate(); @Override @DB() K getNextInSequence(final Class<K> clazz, final String name); @Override @DB() K getRandomlyIncreasingNextInSequence(final Class<K> clazz, final String name); @Override @DB() List<T> lockRows(final SearchCriteria<T> sc, final Filter filter, final boolean exclusive); @Override @DB() T lockOneRandomRow(final SearchCriteria<T> sc, final boolean exclusive); @DB() int update(final T entity, final SearchCriteria<T> sc, final Integer rows); @Override List<T> searchIncludingRemoved(final SearchCriteria<T> sc, final Filter filter, final Boolean lock, final boolean cache); @DB() static UpdateBuilder getUpdateBuilder(final T entityObject); int update(final UpdateBuilder ub, final SearchCriteria<?> sc, final Integer rows); @Override List<T> searchIncludingRemoved(final SearchCriteria<T> sc, final Filter filter, final Boolean lock, final boolean cache, final boolean enableQueryCache); @Override List<M> customSearchIncludingRemoved(final SearchCriteria<M> sc, final Filter filter); @Override @DB() List<M> customSearch(final SearchCriteria<M> sc, final Filter filter); @Override @DB() boolean configure(final String name, final Map<String, Object> params); Integer getDistinctCount(final SearchCriteria<T> sc); Integer getCount(final SearchCriteria<T> sc); @DB() @Override Class<T> getEntityBeanType(); @Override @DB() T findOneBy(final SearchCriteria<T> sc); @Override @DB() T findById(final ID id); @Override @DB() T findByUuid(final String uuid); @Override @DB() T findByUuidIncludingRemoved(final String uuid); @Override @DB() T findByIdIncludingRemoved(final ID id); @Override @DB() T findById(final ID id, final boolean fresh); @Override @DB() T lockRow(final ID id, final Boolean lock); @Override @DB() T acquireInLockTable(final ID id); @Override T acquireInLockTable(final ID id, final int seconds); @Override boolean releaseFromLockTable(final ID id); @Override @DB() boolean lockInLockTable(final String id); @Override boolean lockInLockTable(final String id, final int seconds); @Override boolean unlockFromLockTable(final String id); @Override @DB() List<T> listAllIncludingRemoved(); @Override @DB() List<T> listAllIncludingRemoved(final Filter filter); @Override @DB() List<T> listAll(); @Override @DB() List<T> listAll(final Filter filter); @Override boolean expunge(final ID id); @Override int expunge(final SearchCriteria<T> sc); @Override @DB() List<T> search(final SearchCriteria<T> sc, final Filter filter); @Override @DB() Pair<List<T>, Integer> searchAndCount(final SearchCriteria<T> sc, final Filter filter); @Override @DB() Pair<List<T>, Integer> searchAndDistinctCount(final SearchCriteria<T> sc, final Filter filter); @Override @DB() List<T> search(final SearchCriteria<T> sc, final Filter filter, final boolean enableQueryCache); @Override @DB() boolean update(final ID id, final T entity); @Override @DB() int update(final T entity, final SearchCriteria<T> sc); @Override T persist(final T entity); @Override void expunge(); @Override boolean remove(final ID id); @Override int remove(final SearchCriteria<T> sc); @Override @DB() SearchBuilder<T> createSearchBuilder(); @Override @DB() SearchCriteria<T> createSearchCriteria();  }