Need a unique gift idea?
A Pastebin account makes a great Christmas gift
SHARE
TWEET

Untitled

a guest Jan 12th, 2018 38 Never
Upgrade to PRO!
ENDING IN00days00hours00mins00secs
 
  1.  
  2. public abstract class GenericDaoImpl<T extends AnnotatedElement> implements GenericDao<T> {
  3.     static Logger log = LoggerFactory.getLogger(GenericDaoImpl.class);
  4.  
  5.     @Autowired
  6.     JdbcTemplate jdbcTemplate;
  7.  
  8.     public JdbcTemplate getJdbcTemplate() {
  9.         return jdbcTemplate;
  10.     }
  11.  
  12.     public void setJdbcTemplate(JdbcTemplate jdbcTemplate) {
  13.         this.jdbcTemplate = jdbcTemplate;
  14.     }
  15.  
  16.     @Override
  17.     public T find(Integer Id) {
  18.         String tableName = null;
  19.         AnnotatedElement ae = (AnnotatedElement) T.class;
  20.         if (ae.isAnnotationPresent(Table.class))
  21.         {
  22.             Table t = ae.getAnnotation(Table.class);
  23.             tableName = t.name();
  24.  
  25.         } else {
  26.             tableName = ae.getClass().getName();
  27.         }
  28.         return (T) getJdbcTemplate().queryForObject("SELECT * FROM "+tableName+" where id = ?",
  29.                 new Object[] { Id }, getRowMapper());
  30.     }
  31. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top