public interface GenericDao<T> {
List<T> findAll();
long update(T t);
}
I have a GenericDaoImpl
public class GenericDaoImpl<T, S extends GenericDao<T>> implements GenericDao<T> {
Class<? extends S> type;
S dao;
public GenericDaoImpl() {
Type s = getClass().getGenericSuperclass();
ParameterizedType pt = (ParameterizedType) s;
type = (Class) pt.getActualTypeArguments()[1];
}
@Autowired
DBI dbi;
@Override
public long update(T t) {
return getDao().update(t);
}
@Override
public List<T> findAll() {
return getDao().findAll();
}public S getDao() {
if (dao == null) {
dao = dbi.onDemand(type);
}
return dao;
}
}& I have the Dao & DaoImpl to access my Table
@RegisterMapperFactory(EntityMapperFactory.class)
public interface SchemeDao extends GenericDao<Scheme> {
@Override
@SqlQuery("Select * FROM PORTAL2.scheme")
List<Scheme> findAll();
@Override
@SqlUpdate("UPDATE PORTAL2.scheme SET ifs_id=:s.schemeId" +
", prefix=:s.prefix" +
" WHERE id=:s.id")
long update(@BindBean("s") Scheme scheme);}@Repository
public class SchemeDaoImpl extends GenericDaoImpl<Scheme, SchemeDao> implements SchemeDao {}Scheme is just a plain old POJO with '@Column' annotationsThanks,Bill
> To unsubscribe from this group and stop receiving emails from it, send an email to jdbi+unsubscribe@googlegroups.com.
--
You received this message because you are subscribed to the Google Groups "jDBI" group.
To unsubscribe from this group and stop receiving emails from it, send an email to jdbi+unsubscribe@googlegroups.com.
@SqlUpdate@UseClasspathSqlLocatorvoid insert(T entity);@SqlQuery@UseClasspathSqlLocatorT getById(ID id);@SqlQuery@UseClasspathSqlLocatorList<T> list();@SqlUpdate@UseClasspathSqlLocatorvoid update(T entity);@SqlUpdate@UseClasspathSqlLocatorvoid delete(ID id);}@RegisterBeanMapper(Contact.class)public interface ContactDao extends CrudDao<Contact, Long> {}@RegisterBeanMapper(Account.class)public interface AccountDao extends CrudDao<Account, UUID> {}
> > To unsubscribe from this group and stop receiving emails from it, send an email to jdbi+unsubscribe@googlegroups.com.
> > For more options, visit https://groups.google.com/d/optout.
>
> --
> You received this message because you are subscribed to the Google Groups "jDBI" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to jdbi+unsubscribe@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.
>
>
> --
> You received this message because you are subscribed to the Google Groups "jDBI" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to jdbi+unsubscribe@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.
--
You received this message because you are subscribed to the Google Groups "jDBI" group.
To unsubscribe from this group and stop receiving emails from it, send an email to jdbi+unsubscribe@googlegroups.com.