public ExecutionPlanPartBean saveExecutionPlanPartBean( ExecutionPlanPartBean viewBean, User user, ITransactionHolder transactionPrm) throws BusinessException, ClientBusinessException { HibernatePersistenceAdapter persistenceAdapter = PersistenceUtil.getPersistenceAdapter(); ExecutionPlanPart planPart = null; ITransactionHolder transaction = null; boolean isLocalTransaction = transactionPrm == null; try { if (isLocalTransaction) { transaction = persistenceAdapter.createTransaction(); } else { transaction = transactionPrm; } planPart = gwt2Hib(viewBean, transaction); ActionType actionType = ActionType.get(planPart.getType()); if (viewBean.getId() == null && actionType != ActionType.PARALLEL) { ExecutionPlanPart executionPlanPart = ExecutionPlanPartHelper.getInstance().findWithSameParentsAndType(planPart, transaction); if (executionPlanPart != null) throw new BusinessException( "executionPlan.part.saveError.uniqueType", planPart.getType()); } if (planPart.isUseParallel()) { planPart.setTask(null); viewBean.setTaskBean(null); } ExecutionPlanPartHandler.getInstance().saveOrUpdate(planPart, user, transaction); viewBean.setId(planPart.getId()); saveOrUpdateParallelParts(viewBean, planPart, user, transaction); } catch (BusinessException e) { throw e; } catch (Throwable ex) { if (isLocalTransaction && transaction != null && !transaction.isClosed()) { try { transaction.rollbackAndClose(); } catch (DBException e1) { log.error(e1.getMessage(), e1); } } throw new SystemException(ex); } finally { if (isLocalTransaction && transaction != null && !transaction.isClosed()) { try { transaction.commitAndClose(); } catch (Exception e) { log.error(e.getMessage(), e); } } } return hib2Gwt(planPart); }
/* * (non-Javadoc) * * @see org.talend.gwtadministrator.server.remoterepositorymgt.view.AbstractViewAdapter#gwt2Hib(java.lang.Object, * org.talend.administrator.common.persistence.hibernate.ITransactionHolder) */ @Override public ExecutionPlanPart gwt2Hib(ExecutionPlanPartBean gwtBean, ITransactionHolder transaction) { Action action = (gwtBean.getId() == null ? Constants.Action.ADD : Constants.Action.UPDATE); ExecutionPlanPart hibBean = null; switch (action) { case ADD: hibBean = ConductorFactory.eINSTANCE.createExecutionPlanPart(); break; case UPDATE: hibBean = ExecutionPlanPartHelper.getInstance().findById(gwtBean.getId(), transaction); if (hibBean != null) { hibBean.setId(gwtBean.getId()); } else { log.warn( "Can't find the plan part with the id=" + gwtBean.getId() + ", the plan part might have already been deleted"); return null; } break; } if (gwtBean.getPlanBean() != null) { ExecutionPlan executionPlan = ExecutionPlanHelper.getInstance().findById(gwtBean.getPlanBean().getId(), transaction); hibBean.setExecutionPlan(executionPlan); } if (gwtBean.getTaskBean() != null) { ExecutionTask executionTask = ExecutionTaskHelper.getInstance().findById(gwtBean.getTaskBean().getId(), transaction); hibBean.setTask(executionTask); } ExecutionPlanPartBean parent = gwtBean.getParent(); if (parent != null) { hibBean.setParent(gwt2Hib(parent, transaction)); } if (gwtBean.getType() != null) { hibBean.setType(gwtBean.getType().toString()); PlanPartStatus partStatus = PlanPartStatus.get(gwtBean.getType().toString()); hibBean.setStatus(partStatus.name()); } if (gwtBean.getStatus() != null) { hibBean.setStatus(gwtBean.getStatus()); } hibBean.setStartDate(gwtBean.getStartDate()); hibBean.setEndDate(gwtBean.getEndDate()); hibBean.setUseParallel(gwtBean.isUseParallel()); hibBean.setMaxThreads(gwtBean.getMaxThreads()); return hibBean; }