| /** |
| * A builder bean for testing puposes. |
| * Usefull to "mimic" bulder patterns |
| * buildBean -> Create Bean created a detached bean |
| * createBeanInstance -> Created an attached instance. |
| * @author josecanovamauger. |
| * |
| */ |
package org.nanotek.tests.hibernate;
| /** |
| * A builder bean for testing puposes. |
| * Usefull to "mimic" bulder patterns |
| * buildBean -> Create Bean created a detached bean |
| * createBeanInstance -> Created an attached instance. |
| * @author josecanovamauger. |
| * |
*/
|
|
|
|
import org.nanotek.util.Base;
|
import org.nanotek.util.BeanReflectorBuilder;
|
import org.springframework.beans.BeansException;
|
import org.springframework.context.ApplicationContext;
|
import org.springframework.context.ApplicationContextAware;
|
|
public abstract class SpringBaseBuilder implements BeanReflectorBuilder<String ,Base<?>>, ApplicationContextAware{
|
|
protected ApplicationContext ctx;
|
|
public SpringBaseBuilder() {
|
}
|
|
@Override
|
public void setApplicationContext(ApplicationContext arg0)
|
throws BeansException {
|
this.ctx = arg0;
|
}
|
|
| } |
package org.nanotek.tests.hibernate;
|
|
import org.nanotek.cms.domain.lucene.config.IndexConfig;
|
import org.nanotek.dao.DAO;
|
import org.nanotek.util.Base;
|
import org.nanotek.util.PersistenceBaseBeanBuilder;
|
|
@SuppressWarnings("hiding")
|
public class IndexConfigSpringBuilder <String , C extends IndexConfig> extends SpringBaseBuilder implements PersistenceBaseBeanBuilder<String,C> {
|
|
@Override
|
public Base<?> createBeanInstance(java.lang.String ref, Base<?> clazz) {
|
return ctx.getBean(ref,clazz.getClass());
|
}
|
|
@Override
|
public C persistBean(String r, C k) {
|
@SuppressWarnings("unchecked")
|
DAO<IndexConfig> dao = (DAO<IndexConfig>) ctx.getBean((java.lang.String) r);
|
dao.persist(k);
|
return k;
|
}
|
|
@Override
|
public void deleteBean(String r, C k) {
|
DAO<IndexConfig> dao = (DAO<IndexConfig>) ctx.getBean((java.lang.String) r);
|
dao.delete(k);
|
}
|
|
| } |
Keith Moon ~ Amazing Journey