GenericDaoBase extends ComponentLifecycleBase implements GenericDao<T, ID>, ComponentMethodInterceptable { @DB() @SuppressWarnings("unchecked") protected static <M> M getObject(Class<M> type, ResultSet rs, int index) throws SQLException { if (type == String.class) { byte[] bytes = rs.getBytes(index); if (bytes != null) { try { return (M)new String(bytes, "UTF-8"); } catch (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); } } @SuppressWarnings("unchecked") protected  GenericDaoBase(); static GenericDao<? extends J, ? extends Serializable> getDao(Class<J> entityType); @Override @SuppressWarnings("unchecked") @DB() GenericSearchBuilder<T, J> createSearchBuilder(Class<J> resultType); @Override Map<String, Attribute> getAllAttributes(); @SuppressWarnings("unchecked") T createSearchEntity(MethodInterceptor interceptor); @Override @DB() @SuppressWarnings("unchecked") 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); @Override List<T> searchIncludingRemoved(SearchCriteria<T> sc, final Filter filter, final Boolean lock, final boolean cache); @Override List<T> searchIncludingRemoved(SearchCriteria<T> sc, final Filter filter, final Boolean lock, final boolean cache, final boolean enableQueryCache); @Override @SuppressWarnings("unchecked") List<M> customSearchIncludingRemoved(SearchCriteria<M> sc, final Filter filter); @Override @DB() List<M> customSearch(SearchCriteria<M> sc, final Filter filter); int update(UpdateBuilder ub, final SearchCriteria<?> sc, Integer rows); @DB() @Override Class<T> getEntityBeanType(); @Override @DB() T findOneBy(final SearchCriteria<T> sc); @Override @DB() @SuppressWarnings("unchecked") 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, boolean fresh); @Override @DB() T lockRow(ID id, Boolean lock); @Override @DB() T acquireInLockTable(ID id); @Override T acquireInLockTable(final ID id, int seconds); @Override boolean releaseFromLockTable(final ID id); @Override @DB() boolean lockInLockTable(final String id); @Override boolean lockInLockTable(final String id, 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(ID id, T entity); @DB() int update(final T entity, final SearchCriteria<T> sc, Integer rows); @Override @DB() int update(final T entity, final SearchCriteria<T> sc); @Override @SuppressWarnings("unchecked") T persist(final T entity); @Override void expunge(); @Override boolean remove(final ID id); @Override int remove(SearchCriteria<T> sc); @Override @DB() boolean configure(final String name, final Map<String, Object> params); @DB() static UpdateBuilder getUpdateBuilder(final T entityObject); @Override @DB() SearchBuilder<T> createSearchBuilder(); @Override @DB() SearchCriteria<T> createSearchCriteria(); Integer getDistinctCount(SearchCriteria<T> sc); Integer getCount(SearchCriteria<T> sc);  }
@Test public void getObjectBoolean() throws SQLException { Mockito.when(resultSet.getObject(1)).thenReturn(false); Mockito.when(resultSet.getBoolean(1)).thenReturn(false); Assert.assertFalse(GenericDaoBase .getObject(Boolean.class, resultSet, 1)); Mockito.verify(resultSet).getBoolean(1); }
@Test public void getObjectPrimitiveBoolean() throws SQLException { Mockito.when(resultSet.getObject(1)).thenReturn(false); Mockito.when(resultSet.getBoolean(1)).thenReturn(false); Assert.assertFalse(GenericDaoBase .getObject(boolean.class, resultSet, 1)); Mockito.verify(resultSet).getBoolean(1); }
@Test public void getObjectPrimitiveShort() throws SQLException { Mockito.when(resultSet.getObject(1)).thenReturn((short) 1); Mockito.when(resultSet.getShort(1)).thenReturn((short) 1); Assert.assertEquals(Short.valueOf((short) 1), GenericDaoBase.getObject(short.class, resultSet, 1)); Mockito.verify(resultSet).getShort(1); }
@Test public void getObjectShort() throws SQLException { Mockito.when(resultSet.getObject(1)).thenReturn((short) 1); Mockito.when(resultSet.getShort(1)).thenReturn((short) 1); Assert.assertEquals(Short.valueOf((short) 1), GenericDaoBase.getObject(Short.class, resultSet, 1)); Mockito.verify(resultSet).getShort(1); }
@Test public void getObjectFloat() 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); }
@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); }
@Test public void getObjectPrimitiveDouble() throws SQLException { Mockito.when(resultSet.getObject(1)).thenReturn(0.1d); Mockito.when(resultSet.getDouble(1)).thenReturn(0.1d); Assert.assertEquals(0.1d, GenericDaoBase.getObject(double.class, resultSet, 1), 0.1); Mockito.verify(resultSet).getDouble(1); }
@Test public void getObjectDouble() throws SQLException { Mockito.when(resultSet.getObject(1)).thenReturn(0.1d); Mockito.when(resultSet.getDouble(1)).thenReturn(0.1d); Assert.assertEquals(0.1d, GenericDaoBase.getObject(Double.class, resultSet, 1), 0.1); Mockito.verify(resultSet).getDouble(1); }
@Test public void getObjectLong() throws SQLException { Mockito.when(resultSet.getObject(1)).thenReturn(1l); Mockito.when(resultSet.getLong(1)).thenReturn(1l); Assert.assertEquals((Long) 1l, GenericDaoBase.getObject(Long.class, resultSet, 1)); Mockito.verify(resultSet).getLong(1); }
@Test public void getObjectPrimitiveLong() throws SQLException { Mockito.when(resultSet.getObject(1)).thenReturn(1l); Mockito.when(resultSet.getLong(1)).thenReturn(1l); Assert.assertEquals((Long) 1l, GenericDaoBase.getObject(long.class, resultSet, 1)); Mockito.verify(resultSet).getLong(1); }
@Test public void getObjectPrimitiveInt() throws SQLException { Mockito.when(resultSet.getObject(1)).thenReturn(1l); Mockito.when(resultSet.getInt(1)).thenReturn(1); Assert.assertEquals((Integer) 1, GenericDaoBase.getObject(int.class, resultSet, 1)); Mockito.verify(resultSet).getInt(1); }
@Test public void getObjectInteger() throws SQLException { Mockito.when(resultSet.getObject(1)).thenReturn(1l); Mockito.when(resultSet.getInt(1)).thenReturn(1); Assert.assertEquals((Integer) 1, GenericDaoBase.getObject(Integer.class, resultSet, 1)); Mockito.verify(resultSet).getInt(1); }
@Test public void getObjectPrimitiveByte() throws SQLException { Mockito.when(resultSet.getObject(1)).thenReturn((byte) 1); Mockito.when(resultSet.getByte(1)).thenReturn((byte) 1); Assert.assertTrue((byte) 1 == GenericDaoBase.getObject(byte.class, resultSet, 1)); Mockito.verify(resultSet).getByte(1); }