Example usage for javax.ejb TransactionAttributeType REQUIRED

List of usage examples for javax.ejb TransactionAttributeType REQUIRED

Introduction

In this page you can find the example usage for javax.ejb TransactionAttributeType REQUIRED.

Prototype

TransactionAttributeType REQUIRED

To view the source code for javax.ejb TransactionAttributeType REQUIRED.

Click Source Link

Document

If a client invokes the enterprise bean's method while the client is associated with a transaction context, the container invokes the enterprise bean's method in the client's transaction context.

Usage

From source file:fr.ortolang.diffusion.core.CoreServiceBean.java

@Override
@TransactionAttribute(TransactionAttributeType.REQUIRED)
public DataObject createDataObject(String workspace, String path, String hash) throws CoreServiceException,
        KeyNotFoundException, InvalidPathException, AccessDeniedException, PathNotFoundException,
        PathAlreadyExistsException, WorkspaceReadOnlyException, KeyAlreadyExistsException {
    String key = UUID.randomUUID().toString();
    try {//from  ww  w .  j  av  a2s  . c  o m
        return createDataObject(workspace, key, path, hash);
    } catch (KeyAlreadyExistsException e) {
        ctx.setRollbackOnly();
        LOGGER.log(Level.WARNING, "the generated key already exists : " + key);
        throw e;
    }
}

From source file:fr.ortolang.diffusion.core.CoreServiceBean.java

@Override
@TransactionAttribute(TransactionAttributeType.REQUIRED)
public DataObject createDataObject(String wskey, String key, String path, String hash)
        throws CoreServiceException, KeyAlreadyExistsException, InvalidPathException, AccessDeniedException,
        PathNotFoundException, PathAlreadyExistsException, WorkspaceReadOnlyException {
    LOGGER.log(Level.FINE,/*from w w w .j a v  a2s  .  co  m*/
            "create data object with key [" + key + "] into workspace [" + wskey + "] at path [" + path + "]");
    try {
        PathBuilder npath = PathBuilder.fromPath(path);
        if (npath.isRoot()) {
            throw new InvalidPathException("forbidden to create an object at root level");
        }
        PathBuilder ppath = npath.clone().parent();

        String caller = membership.getProfileKeyForConnectedIdentifier();
        List<String> subjects = membership.getConnectedIdentifierSubjects();
        authorisation.checkAuthentified(subjects);
        LOGGER.log(Level.FINEST, "user [" + caller + "] is authentified");

        OrtolangObjectIdentifier wsidentifier = registry.lookup(wskey);
        checkObjectType(wsidentifier, Workspace.OBJECT_TYPE);
        LOGGER.log(Level.FINEST, "workspace with key [" + wskey + "] exists");

        Workspace ws = em.find(Workspace.class, wsidentifier.getId());
        if (ws == null) {
            throw new CoreServiceException(
                    "unable to load workspace with id [" + wsidentifier.getId() + "] from storage");
        }
        if (applyReadOnly(caller, subjects, ws)) {
            throw new WorkspaceReadOnlyException("unable to create data object in workspace with key [" + wskey
                    + "] because it is read only");
        }
        ws.setKey(wskey);
        LOGGER.log(Level.FINEST, "workspace loaded");

        authorisation.checkPermission(ws.getHead(), subjects, "create");
        LOGGER.log(Level.FINEST,
                "user [" + caller + "] has 'create' permission on the head collection of this workspace");

        Collection parent = loadCollectionAtPath(ws.getHead(), ppath, ws.getClock());
        LOGGER.log(Level.FINEST, "parent collection loaded for path " + ppath.build());

        if (parent.containsElementName(npath.part())) {
            throw new PathAlreadyExistsException(npath.build());
        }

        DataObject object = new DataObject();
        object.setId(UUID.randomUUID().toString());
        object.setName(npath.part());
        if (hash != null && hash.length() > 0) {
            object.setSize(binarystore.size(hash));
            object.setMimeType(binarystore.type(hash, npath.part()));
            object.setStream(hash);
        } else {
            object.setSize(0);
            object.setMimeType("application/octet-stream");
            object.setStream("");
        }
        object.setClock(ws.getClock());
        object.setKey(key);
        em.persist(object);
        LOGGER.log(Level.FINEST, "object [" + key + "] created");

        Properties properties = new Properties();
        properties.put(WORKSPACE_REGISTRY_PROPERTY_KEY, wskey);
        registry.register(key, object.getObjectIdentifier(), caller, properties);
        indexing.index(key);

        authorisation.clonePolicy(key, ws.getHead());
        LOGGER.log(Level.FINEST, "security policy cloned from head collection to key [" + key + "]");

        parent.addElement(new CollectionElement(DataObject.OBJECT_TYPE, object.getName(),
                System.currentTimeMillis(), object.getSize(), object.getMimeType(), key));
        em.merge(parent);
        registry.update(parent.getKey());

        LOGGER.log(Level.FINEST, "object [" + key + "] added to parent [" + parent.getKey() + "]");

        try {
            extraction.extract(object.getKey());
        } catch (ExtractionServiceException e) {
            LOGGER.log(Level.SEVERE, e.getMessage(), e);
        }

        ws.setChanged(true);
        em.merge(ws);
        registry.update(ws.getKey());
        LOGGER.log(Level.FINEST, "workspace set changed");

        ArgumentsBuilder argsBuilder = new ArgumentsBuilder(5).addArgument("ws-alias", ws.getAlias())
                .addArgument("key", key).addArgument("path", npath.build())
                .addArgument("hash", object.getStream()).addArgument("mimetype", object.getMimeType());
        notification.throwEvent(wskey, caller, Workspace.OBJECT_TYPE,
                OrtolangEvent.buildEventType(CoreService.SERVICE_NAME, DataObject.OBJECT_TYPE, "create"),
                argsBuilder.build());

        return object;
    } catch (KeyLockedException | KeyNotFoundException | RegistryServiceException | NotificationServiceException
            | IdentifierAlreadyRegisteredException | AuthorisationServiceException | MembershipServiceException
            | BinaryStoreServiceException | DataNotFoundException | IndexingServiceException e) {
        LOGGER.log(Level.SEVERE, "unexpected error occurred during object creation", e);
        ctx.setRollbackOnly();
        throw new CoreServiceException(
                "unable to create object into workspace [" + wskey + "] at path [" + path + "]", e);
    }
}

From source file:com.flexive.ejb.beans.PhraseEngineBean.java

/**
 * {@inheritDoc}/*from   www .j av  a 2  s.c om*/
 */
@Override
@TransactionAttribute(TransactionAttributeType.REQUIRED)
public boolean removePhraseAssignment(long assignmentOwner, long nodeId, long nodeMandator, long phraseId,
        long phraseMandator) throws FxNoAccessException {
    return removePhraseAssignment(FxPhraseCategorySelection.CATEGORY_DEFAULT, assignmentOwner, nodeId,
            nodeMandator, phraseId, phraseMandator);
}

From source file:com.flexive.ejb.beans.PhraseEngineBean.java

/**
 * {@inheritDoc}/*ww w  . j av a  2  s  . c  o m*/
 */
@Override
@TransactionAttribute(TransactionAttributeType.REQUIRED)
public boolean removePhraseAssignment(int category, long assignmentOwner, long nodeId, long nodeMandator,
        long phraseId, long phraseMandator) throws FxNoAccessException {
    checkMandatorAccess(assignmentOwner, FxContext.getUserTicket());
    Connection con = null;
    PreparedStatement ps = null;
    try {
        // Obtain a database connection
        con = Database.getDbConnection();
        ps = con.prepareStatement("DELETE FROM " + TBL_PHRASE_MAP
                + " WHERE MANDATOR=? AND NODEID=? AND NODEMANDATOR=? AND PHRASEID=? AND PMANDATOR=? AND CAT=?");
        ps.setLong(1, assignmentOwner);
        ps.setLong(2, nodeId);
        ps.setLong(3, nodeMandator);
        ps.setLong(4, phraseId);
        ps.setLong(5, phraseMandator);
        ps.setInt(6, category);
        boolean found = ps.executeUpdate() > 0;
        if (found) {
            updatePhrasePosition(con, category, assignmentOwner, nodeId, nodeMandator, phraseId, phraseMandator,
                    0, true);
        }
        rebuildPhraseChildMapping(con, nodeMandator, category, phraseId, phraseMandator);
        if (nodeMandator != phraseMandator)
            rebuildPhraseChildMapping(con, phraseMandator, category, phraseId, phraseMandator);
        else if (assignmentOwner != nodeMandator)
            rebuildPhraseChildMapping(con, assignmentOwner, category, phraseId, phraseMandator);
        return found;
    } catch (SQLException exc) {
        EJBUtils.rollback(ctx);
        throw new FxDbException(LOG, exc, "ex.db.sqlError", exc.getMessage()).asRuntimeException();
    } finally {
        Database.closeObjects(PhraseEngineBean.class, con, ps);
    }
}

From source file:com.stratelia.webactiv.kmelia.control.ejb.KmeliaBmEJB.java

/**
 * Updates the publication links//from   w w  w .  j a v a  2s  .co  m
 *
 * @param pubPK publication identifier which you want to update links
 * @param links list of publication to link with current.
 */
@Override
@TransactionAttribute(TransactionAttributeType.REQUIRED)
public void addInfoLinks(PublicationPK pubPK, List<ForeignPK> links) {
    SilverTrace.info("kmelia", "KmeliaBmEJB.addInfoLinks()", "root.MSG_GEN_ENTER_METHOD",
            "pubId = " + pubPK.getId() + ", pubIds = " + links.toString());
    try {
        publicationBm.addLinks(pubPK, links);
    } catch (Exception e) {
        throw new KmeliaRuntimeException("KmeliaBmEJB.addInfoLinks()", ERROR,
                "kmelia.EX_IMPOSSIBLE_DE_MODIFIER_LE_CONTENU_DU_MODELE", e);
    }
}

From source file:com.flexive.ejb.beans.PhraseEngineBean.java

/**
 * {@inheritDoc}/*from   ww  w  .  j a  v  a  2s .  c o  m*/
 */
@Override
@TransactionAttribute(TransactionAttributeType.REQUIRED)
public void removeAssignmentsFromNode(long nodeId, long nodeMandator) {
    removeAssignmentsFromNode(FxPhraseCategorySelection.CATEGORY_DEFAULT, nodeId, nodeMandator);
}

From source file:com.stratelia.webactiv.kmelia.control.ejb.KmeliaBmEJB.java

@Override
@TransactionAttribute(TransactionAttributeType.REQUIRED)
public void deleteInfoLinks(PublicationPK pubPK, List<ForeignPK> links) {
    SilverTrace.info("kmelia", "KmeliaBmEJB.deleteInfoLinks()", "root.MSG_GEN_ENTER_METHOD",
            "pubId = " + pubPK.getId() + ", pubIds = " + links.toString());
    try {//  w ww  . ja  v a  2  s . com
        publicationBm.deleteInfoLinks(pubPK, links);
    } catch (Exception e) {
        throw new KmeliaRuntimeException("KmeliaBmEJB.deleteInfoLinks()", ERROR,
                "kmelia.EX_IMPOSSIBLE_DE_MODIFIER_LE_CONTENU_DU_MODELE", e);
    }
}

From source file:com.flexive.ejb.beans.PhraseEngineBean.java

/**
 * {@inheritDoc}/*from w  w  w .j  a  va2  s .  c o  m*/
 */
@Override
@TransactionAttribute(TransactionAttributeType.REQUIRED)
public void removeAssignmentsFromNode(int category, long nodeId, long nodeMandator) {
    final long ownMandator = FxContext.getUserTicket().getMandatorId();
    final boolean removeAll = ownMandator == nodeMandator;
    Connection con = null;
    PreparedStatement ps = null;
    try {
        // Obtain a database connection
        con = Database.getDbConnection();
        if (removeAll) {
            ps = con.prepareStatement(
                    "DELETE FROM " + TBL_PHRASE_MAP + " WHERE NODEID=? AND NODEMANDATOR=? AND CAT=?");
            ps.setLong(1, nodeId);
            ps.setLong(2, nodeMandator);
            ps.setInt(3, category);
        } else {
            ps = con.prepareStatement("DELETE FROM " + TBL_PHRASE_MAP
                    + " WHERE MANDATOR=? AND NODEID=? AND NODEMANDATOR=? AND CAT=?");
            ps.setLong(1, ownMandator);
            ps.setLong(2, nodeId);
            ps.setLong(3, nodeMandator);
            ps.setInt(4, category);
        }
        ps.executeUpdate();
        rebuildPhraseChildMapping(con, ownMandator, category, -1, -1);
        if (!removeAll)
            rebuildPhraseChildMapping(con, nodeMandator, category, -1, -1);
    } catch (SQLException exc) {
        EJBUtils.rollback(ctx);
        throw new FxDbException(LOG, exc, "ex.db.sqlError", exc.getMessage()).asRuntimeException();
    } finally {
        Database.closeObjects(PhraseEngineBean.class, con, ps);
    }
}

From source file:org.nightlabs.jfire.accounting.AccountingManagerBean.java

@TransactionAttribute(TransactionAttributeType.REQUIRED)
@RolesAllowed("org.nightlabs.jfire.accounting.editPriceFragmentType")
@Override/*from  ww  w.j a  va  2  s. c o m*/
public PriceFragmentType storePriceFragmentType(final PriceFragmentType priceFragmentType, final boolean get,
        final String[] fetchGroups, final int maxFetchDepth) {
    final PersistenceManager pm = createPersistenceManager();
    try {
        return NLJDOHelper.storeJDO(pm, priceFragmentType, get, fetchGroups, maxFetchDepth);
    } finally {
        pm.close();
    }
}

From source file:com.flexive.ejb.beans.PhraseEngineBean.java

/**
 * {@inheritDoc}/*  w w  w.  j a  va2 s  . co m*/
 */
@Override
@TransactionAttribute(TransactionAttributeType.REQUIRED)
public List<FxPhraseTreeNodePosition> getAssignedNodes(String phraseKey, long... _mandators) {
    return getAssignedNodes(FxPhraseCategorySelection.CATEGORY_DEFAULT, phraseKey, _mandators);
}