List of usage examples for javax.ejb TransactionAttributeType REQUIRED
TransactionAttributeType REQUIRED
To view the source code for javax.ejb TransactionAttributeType REQUIRED.
Click Source Link
From source file:com.flexive.ejb.beans.configuration.GenericConfigurationImpl.java
/** * {@inheritDoc}// w w w . j a v a 2 s . co m */ @Override @TransactionAttribute(TransactionAttributeType.REQUIRED) public <T extends Serializable> Pair<Boolean, T> tryGet(Parameter<T> parameter, String key, boolean ignoreDefault) { try { final T value = parameter.getValue(getParameter(parameter, parameter.getPath().getValue(), key)); return new Pair<Boolean, T>(true, value != null ? value : parameter.getDefaultValue()); } catch (FxNotFoundException e) { if (!ignoreDefault && parameter.getDefaultValue() != null) { return new Pair<Boolean, T>(true, parameter.getDefaultValue()); } else { return new Pair<Boolean, T>(false, null); } } catch (FxApplicationException e) { return new Pair<Boolean, T>(false, null); } }
From source file:com.flexive.ejb.beans.structure.TypeEngineBean.java
/** * {@inheritDoc}//from w w w . ja v a 2 s .c om */ @Override @TransactionAttribute(TransactionAttributeType.REQUIRED) public void unflatten(long typeId) throws FxApplicationException { Connection con = null; try { con = Database.getDbConnection(); final FxFlatStorage flatStorage = FxFlatStorageManager.getInstance(); final FxType type = CacheAdmin.getEnvironment().getType(typeId); for (FxAssignment as : type.getAllAssignments()) { if (!(as instanceof FxPropertyAssignment)) continue; FxPropertyAssignment pa = (FxPropertyAssignment) as; if (pa.isFlatStorageEntry()) flatStorage.unflatten(con, pa); } StructureLoader.reload(con); } catch (FxApplicationException e) { EJBUtils.rollback(ctx); throw e; } catch (SQLException e) { EJBUtils.rollback(ctx); throw new FxDbException(e); } catch (FxCacheException e) { EJBUtils.rollback(ctx); throw new FxUpdateException(e); } finally { Database.closeObjects(TypeEngineBean.class, con, null); } }
From source file:com.flexive.ejb.beans.BriefcaseEngineBean.java
/** * {@inheritDoc}/*w w w.j a v a2 s. c om*/ */ @Override @TransactionAttribute(TransactionAttributeType.REQUIRED) public void moveItems(long fromId, long toId, Collection<FxPK> objectIds) throws FxApplicationException { removeItems(fromId, objectIds); addItems(toId, objectIds); }
From source file:com.flexive.ejb.beans.BriefcaseEngineBean.java
/** * {@inheritDoc}//w w w . j a v a2 s. co m */ @Override @TransactionAttribute(TransactionAttributeType.REQUIRED) public long[] getItems(long id) throws FxApplicationException { Connection con = null; PreparedStatement stmt = null; final Briefcase br = load(id); try { con = Database.getDbConnection(); stmt = con.prepareStatement("SELECT id FROM " + TBL_BRIEFCASE_DATA + " WHERE briefcase_id=?"); stmt.setLong(1, id); final ResultSet rs = stmt.executeQuery(); final List<Long> result = new ArrayList<Long>(); while (rs.next()) { result.add(rs.getLong(1)); } return ArrayUtils.toPrimitive(result.toArray(new Long[result.size()])); } catch (Exception e) { EJBUtils.rollback(ctx); throw new FxUpdateException(LOG, e, "ex.briefcase.getItems", br.getName(), e); } finally { closeObjects(BriefcaseEngineBean.class, con, stmt); } }
From source file:gov.nih.nci.caarray.application.project.ProjectManagementServiceBean.java
/** * {@inheritDoc}/*from w w w. j a v a2 s.c o m*/ */ @Override @TransactionAttribute(TransactionAttributeType.REQUIRED) public Extract copyExtract(Project project, long extractId) throws ProposalWorkflowException, InconsistentProjectStateException { LogUtil.logSubsystemEntry(LOG, project, extractId); checkIfProjectSaveAllowed(project); final Extract extract = this.searchDao.retrieve(Extract.class, extractId); final Extract copy = new Extract(); copyInto(Extract.class, copy, extract); project.getExperiment().getExtracts().add(copy); copy.setExperiment(project.getExperiment()); for (final Sample sample : extract.getSamples()) { sample.getExtracts().add(copy); copy.getSamples().add(sample); } this.projectDao.save(project); LogUtil.logSubsystemExit(LOG); return copy; }
From source file:com.flexive.ejb.beans.UserGroupEngineBean.java
/** * {@inheritDoc}//w w w . jav a 2 s . c o m */ @Override @TransactionAttribute(TransactionAttributeType.REQUIRED) public void setRoles(long groupId, long[] roles) throws FxApplicationException { final UserTicket ticket = FxContext.getUserTicket(); UserGroup aGroup = CacheAdmin.getEnvironment().getUserGroup(groupId); // Permission check if (!ticket.isGlobalSupervisor()) try { if (aGroup.getMandatorId() != ticket.getMandatorId()) { // foreign mandator throw new FxNoAccessException("ex.usergroup.noPermSetRoles", aGroup.getName()); } if (!(ticket.isInRole(Role.AccountManagement) || ticket.isInRole(Role.MandatorSupervisor))) { throw new FxNoAccessException("ex.usergroup.noPermSetRoles", aGroup.getName()); } } catch (FxNoAccessException nae) { if (LOG.isInfoEnabled()) LOG.info(nae); throw nae; } // Bye bye duplicates roles = FxArrayUtils.removeDuplicates(roles); //only allow to assign roles which the calling user is a member of (unless it is a global supervisor) if (!ticket.isGlobalSupervisor()) { List<Role> orgRoles = getRoles(groupId); List<Long> orgRoleIds = FxSharedUtils.getSelectableObjectIdList(orgRoles); //check removed roles for (long check : orgRoleIds) { if (!ArrayUtils.contains(roles, check)) { if (!ticket.isInRole(Role.getById(check))) { EJBUtils.rollback(ctx); throw new FxNoAccessException("ex.account.roles.assign.noMember.remove", Role.getById(check).getName()); } } } //check added roles for (long check : roles) { if (!orgRoleIds.contains(check)) { if (!ticket.isInRole(Role.getById(check))) { EJBUtils.rollback(ctx); throw new FxNoAccessException("ex.account.roles.assign.noMember.add", Role.getById(check).getName()); } } } } // Write roles to database Connection con = null; Statement stmt = null; String sCurSql; try { // Obtain a database connection con = Database.getDbConnection(); // Delete the old assignments of the user sCurSql = "DELETE FROM " + TBL_ROLE_MAPPING + " WHERE USERGROUP=" + groupId; stmt = con.createStatement(); stmt.executeUpdate(sCurSql); stmt.close(); // Store the new assignments of the user for (long role : roles) { if (Role.isUndefined(role)) continue; stmt = con.createStatement(); sCurSql = "INSERT INTO " + TBL_ROLE_MAPPING + " (ACCOUNT,USERGROUP,ROLE) VALUES (" + Account.NULL_ACCOUNT + "," + groupId + "," + role + ")"; stmt.executeUpdate(sCurSql); stmt.close(); } // Update all active user tickets that are affected UserTicketStore.flagDirtyHavingGroupId(groupId); } catch (SQLException exc) { EJBUtils.rollback(ctx); FxUpdateException dbe = new FxUpdateException(exc, "ex.usergroup.updateRolesSqlException", aGroup.getName()); LOG.error(dbe); throw dbe; } finally { Database.closeObjects(UserGroupEngineBean.class, con, stmt); } }
From source file:com.flexive.ejb.beans.configuration.GenericConfigurationImpl.java
/** * {@inheritDoc}//from w w w .ja v a 2 s .c om */ @Override @TransactionAttribute(TransactionAttributeType.REQUIRED) public Map<ParameterData, Serializable> getAll() throws FxApplicationException { return getAllWithXStream(ImmutableMap.<String, XStream>of()); }
From source file:com.flexive.ejb.beans.configuration.GlobalConfigurationEngineBean.java
/** * {@inheritDoc}/* ww w. j a v a 2s .co m*/ */ @Override @TransactionAttribute(TransactionAttributeType.REQUIRED) public int getDivisionId(String serverName) throws FxApplicationException { final long timestamp = getTimestamp(); if (domainCacheTimestamp.get() >= timestamp) { Integer cachedDivisionId = domainCache.get(serverName); if (cachedDivisionId != null) { return cachedDivisionId; } } else { synchronized (domainCache) { domainCache.clear(); domainCacheTimestamp.set(timestamp); } } DivisionData[] divisionIds = getDivisions(); int divisionId = -1; for (DivisionData division : divisionIds) { if (division.isMatchingDomain(serverName)) { divisionId = division.getId(); break; } } synchronized (domainCache) { if (domainCache.size() > MAX_CACHED_DOMAINS) { domainCache.clear(); } domainCache.put(serverName, divisionId); } return divisionId; }
From source file:com.flexive.ejb.beans.ScriptingEngineBean.java
/** * {@inheritDoc}/* w w w. j av a 2s.com*/ */ @Override @TransactionAttribute(TransactionAttributeType.REQUIRED) public FxScriptInfo createScript(FxScriptInfoEdit scriptInfo) throws FxApplicationException { FxPermissionUtils.checkRole(FxContext.getUserTicket(), Role.ScriptManagement); FxScriptInfo si; Connection con = null; PreparedStatement ps = null; String sql; boolean success = false; try { // for groovy scripts set cached flag to true si = new FxScriptInfo(seq.getId(FxSystemSequencer.SCRIPTS), scriptInfo.getEvent(), scriptInfo.getName(), scriptInfo.getDescription(), scriptInfo.isActive(), scriptInfo.isCached()); String code = scriptInfo.getCode() == null ? "" : scriptInfo.getCode(); // Obtain a database connection con = Database.getDbConnection(); // 1 2 3 4 5 6 7 sql = "INSERT INTO " + TBL_SCRIPTS + " (ID,SNAME,SDESC,SDATA,STYPE,ACTIVE,IS_CACHED) VALUES (?,?,?,?,?,?,?)"; ps = con.prepareStatement(sql); ps.setLong(1, si.getId()); ps.setString(2, si.getName()); ps.setString(3, si.getDescription()); StorageManager.setBigString(ps, 4, code); ps.setLong(5, si.getEvent().getId()); ps.setBoolean(6, si.isActive()); ps.setBoolean(7, si.isCached()); ps.executeUpdate(); success = true; } catch (SQLException exc) { if (StorageManager.isUniqueConstraintViolation(exc)) throw new FxEntryExistsException("ex.scripting.name.notUnique", scriptInfo.getName()); throw new FxCreateException(LOG, exc, "ex.scripting.create.failed", scriptInfo.getName(), exc.getMessage()); } finally { Database.closeObjects(ScriptingEngineBean.class, con, ps); if (!success) EJBUtils.rollback(ctx); else StructureLoader.reloadScripting(FxContext.get().getDivisionId()); } return si; }
From source file:io.hops.hopsworks.common.user.AuthController.java
/** * Change password to the given password. Will generate a new salt * * @param user/*from w w w .j av a2s. c o m*/ * @param password * @param req * @throws Exception */ @TransactionAttribute(TransactionAttributeType.REQUIRED) public void changePassword(Users user, String password, HttpServletRequest req) { String salt = generateSalt(); String passwordWithSalt = getPasswordHash(password, salt); String oldPassword = user.getPassword(); user.setPassword(passwordWithSalt); user.setSalt(salt); user.setPasswordChanged(new Timestamp(new Date().getTime())); userFacade.update(user); resetProjectCertPassword(user, oldPassword); }