if(logger.isDebugEnabled()) {
logger.debug("Inserting bean under BeanId '" + beanIdName + "' with DAO '" + daoName + "'.");
}
BeanContext beanRepository = executionContext.getBeanContext();
Object bean = beanRepository.getBean(beanId);
final DaoRegister emr = PersistenceUtil.getDAORegister(executionContext);
Object dao = null;
try {
if(daoName == null) {
dao = emr.getDefaultDao();
} else {
dao = emr.getDao(daoName);
}
if(dao == null) {
throw new IllegalStateException("The DAO register returned null while getting the DAO '" + daoName + "'");
}
final DaoInvoker daoInvoker = DaoInvokerFactory.getInstance().create(dao, objectStore);
Object result = name == null ? daoInvoker.insert(bean) : daoInvoker.insert(name, bean) ;
if(insertedBeanId != null) {
if(result == null) {
result = bean;
}
beanRepository.addBean(insertedBeanId, result, source);
} else if(result != null && bean != result) {
beanRepository.changeBean(beanId, bean, source);
}
} finally {
if(dao != null) {
emr.returnDao(dao);
}