Example usage for javax.ejb TransactionAttributeType SUPPORTS

List of usage examples for javax.ejb TransactionAttributeType SUPPORTS

Introduction

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

Prototype

TransactionAttributeType SUPPORTS

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

Click Source Link

Document

If the client calls with a transaction context, the container performs the same steps as described in the REQUIRED case.

Usage

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

@Override
@TransactionAttribute(TransactionAttributeType.SUPPORTS)
public void notifyWorkspaceOwner(String wskey, String email, String message) throws CoreServiceException {
    LOGGER.log(Level.FINE, "notify owner of workspace [" + wskey + "]");
    try {/*from ww w.  j a v  a2s .  c o  m*/
        String caller = membership.getProfileKeyForConnectedIdentifier();

        OrtolangObjectIdentifier identifier = registry.lookup(wskey);
        checkObjectType(identifier, Workspace.OBJECT_TYPE);
        Workspace workspace = em.find(Workspace.class, identifier.getId());
        if (workspace == null) {
            throw new CoreServiceException(
                    "unable to load workspace with id [" + identifier.getId() + "] from storage");
        }

        ArgumentsBuilder argsBuilder = new ArgumentsBuilder(2).addArgument("email", email)
                .addArgument("message", message);
        notification.throwEvent(wskey, caller, Workspace.OBJECT_TYPE,
                OrtolangEvent.buildEventType(CoreService.SERVICE_NAME, Workspace.OBJECT_TYPE, "notify-owner"),
                argsBuilder.build());
    } catch (RegistryServiceException | KeyNotFoundException | NotificationServiceException e) {
        ctx.setRollbackOnly();
        LOGGER.log(Level.SEVERE, "unexpected error occurred while trying to notify workspace owner", e);
        throw new CoreServiceException("unable to notify owner of workspace with key [" + wskey + "]", e);
    }
}

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

/**
 * {@inheritDoc}// w w  w .  j av a  2 s . c o  m
 */
@Override
@TransactionAttribute(TransactionAttributeType.SUPPORTS)
public long getBinaryId(FxPK pk, String xpath, FxLanguage language, boolean fallbackToDefault)
        throws FxApplicationException {
    FxSharedUtils.checkParameterNull(pk, "pk");
    FxSharedUtils.checkParameterNull(xpath, "xpath");
    Connection con = null;
    try {
        ContentStorage storage = StorageManager.getContentStorage(pk.getStorageMode());
        con = Database.getDbConnection();
        FxContent co = load(pk);
        UserTicket ticket = FxContext.getUserTicket();
        if (xpath.equals("/")) {
            if (!ticket.isGlobalSupervisor()) {
                FxType type = CacheAdmin.getEnvironment().getType(co.getTypeId());
                if (type.isUsePermissions()) {
                    FxContentSecurityInfo si = storage.getContentSecurityInfo(con, pk, null);
                    FxPermissionUtils.checkPermission(ticket, ACLPermission.READ, si, true);
                }
            }
            return co.getBinaryPreviewId();
        }
        FxPropertyData pd = co.getPropertyData(xpath);
        if (!pd.getValue().isEmpty() && pd.getValue() instanceof FxBinary) {
            final FxBinary bin = (FxBinary) pd.getValue();
            if (language == null)
                return bin.getBestTranslation(ticket.getLanguage()).getId();
            if (fallbackToDefault)
                return bin.getBestTranslation(language).getId();
            if (!bin.translationExists(language.getId()))
                throw new FxInvalidParameterException("language", "ex.content.value.notTranslated", language);
            return bin.getTranslation(language).getId();
        }
        throw new FxInvalidParameterException("XPATH", "ex.content.binary.xpath.invalid", xpath);
    } catch (FxNotFoundException e) {
        throw new FxLoadException(e);
    } catch (SQLException e) {
        throw new FxLoadException(LOG, e, "ex.db.sqlError", e.getMessage());
    } finally {
        Database.closeObjects(ContentEngineBean.class, con, null);
    }
}

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

@Override
@TransactionAttribute(TransactionAttributeType.SUPPORTS)
public void notifyWorkspaceMembers(String wskey, String email, String message) throws CoreServiceException {
    LOGGER.log(Level.FINE, "notify members of workspace [" + wskey + "]");
    try {//  ww  w  . j a  v  a 2  s .c o m
        String caller = membership.getProfileKeyForConnectedIdentifier();

        OrtolangObjectIdentifier identifier = registry.lookup(wskey);
        checkObjectType(identifier, Workspace.OBJECT_TYPE);
        Workspace workspace = em.find(Workspace.class, identifier.getId());
        if (workspace == null) {
            throw new CoreServiceException(
                    "unable to load workspace with id [" + identifier.getId() + "] from storage");
        }

        ArgumentsBuilder argsBuilder = new ArgumentsBuilder(2).addArgument("email", email)
                .addArgument("message", message);
        notification.throwEvent(wskey, caller, Workspace.OBJECT_TYPE,
                OrtolangEvent.buildEventType(CoreService.SERVICE_NAME, Workspace.OBJECT_TYPE, "notify-members"),
                argsBuilder.build());
    } catch (RegistryServiceException | KeyNotFoundException | NotificationServiceException e) {
        ctx.setRollbackOnly();
        LOGGER.log(Level.SEVERE, "unexpected error occurred while trying to notify workspace members", e);
        throw new CoreServiceException("unable to notify members of workspace with key [" + wskey + "]", e);
    }
}

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

/**
 * {@inheritDoc}//from ww w .  ja va 2 s.c  o m
 */
@Override
@TransactionAttribute(TransactionAttributeType.SUPPORTS)
public long getBinaryId(FxPK pk, String xpath, FxLanguage language) throws FxApplicationException {
    return getBinaryId(pk, xpath, language, false);
}

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

/**
 * {@inheritDoc}/* w  ww.  j  a  v a  2  s  .co m*/
 */
@Override
@TransactionAttribute(TransactionAttributeType.SUPPORTS)
public String getBinaryMetaData(long id) {
    if (!FxContext.getUserTicket().isGlobalSupervisor())
        return "";
    Connection con = null;
    try {
        con = Database.getDbConnection();
        return StorageManager.getContentStorage(TypeStorageMode.Hierarchical).getBinaryMetaData(con, id);
    } catch (FxNotFoundException e) {
        LOG.error(e);
    } catch (SQLException e) {
        LOG.error(e);
    } finally {
        Database.closeObjects(ContentEngineBean.class, con, null);
    }
    return "";
}

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

@Override
@TransactionAttribute(TransactionAttributeType.SUPPORTS)
public String resolveWorkspaceAlias(String alias) throws CoreServiceException, AliasNotFoundException {
    LOGGER.log(Level.FINE, "finding workspace for alias: " + alias);
    try {//www  . j ava  2s. co  m
        TypedQuery<Workspace> query = em.createNamedQuery("findWorkspaceByAlias", Workspace.class)
                .setParameter("alias", alias);
        try {
            Workspace workspace = query.getSingleResult();
            return registry.lookup(workspace.getObjectIdentifier());
        } catch (NoResultException e) {
            throw new AliasNotFoundException(alias);
        }
    } catch (RegistryServiceException | IdentifierNotRegisteredException e) {
        LOGGER.log(Level.SEVERE, "unexpected error occurred during resolving workspace alias: " + alias, e);
        throw new CoreServiceException("unable to resolve workspace alias: " + alias, e);
    }
}

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

/**
 * {@inheritDoc}/*from  w  ww  .ja  v  a2s. c  o  m*/
 */
@Override
@TransactionAttribute(TransactionAttributeType.SUPPORTS)
public BinaryDescriptor getBinaryDescriptor(long id) throws FxApplicationException {
    if (!FxContext.getUserTicket().isGlobalSupervisor()) {
        throw new FxNoAccessException("ex.content.type.getAll.noPermission");
    }
    Connection con = null;
    try {
        con = Database.getDbConnection();
        return StorageManager.getContentStorage(TypeStorageMode.Hierarchical).getBinaryDescriptor(con, id);
    } catch (SQLException e) {
        throw new FxLoadException(LOG, e);
    } finally {
        Database.closeObjects(ContentEngineBean.class, con, null);
    }
}

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

/**
 * {@inheritDoc}//  w w  w. j a  va 2s . co m
 */
@Override
@TransactionAttribute(TransactionAttributeType.SUPPORTS)
public FxContent importContent(String xml, boolean newInstance) throws FxApplicationException {
    FxContent co;
    try {
        co = (FxContent) ConversionEngine.getXStream().fromXML(xml);
    } catch (ConversionException e) {
        String key;
        Iterator i = e.keys();
        String path = "unknown";
        String line = "unknown";
        while (i.hasNext()) {
            key = (String) i.next();
            if ("path".equals(key))
                path = e.get(key);
            else if ("line number".equals(key))
                line = e.get(key);
            //                System.out.println("Key ["+key+"] -> "+e.get(key));
        }
        throw new FxApplicationException("ex.content.import.conversionError", path, line, e.getShortMessage());
    } catch (Exception e) {
        throw new FxApplicationException("ex.content.import.error", e.getMessage());
    }
    return co;
}

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

@Override
@TransactionAttribute(TransactionAttributeType.SUPPORTS)
public String resolveWorkspacePath(String wskey, String root, String path)
        throws CoreServiceException, InvalidPathException, PathNotFoundException {
    LOGGER.log(Level.FINE,/*from  w w  w. j  a  v  a 2 s.  c om*/
            "resolving into workspace [" + wskey + "] and root [" + root + "] path [" + path + "]");
    try {
        PathBuilder npath = PathBuilder.fromPath(path);
        PathBuilder ppath = npath.clone().parent();

        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");
        }
        ws.setKey(wskey);
        LOGGER.log(Level.FINEST, "workspace loaded");

        String rroot = ws.getHead();
        if (root != null && root.length() > 0 && !root.equals(Workspace.HEAD)) {
            String snapshot = root;
            TagElement tag = ws.findTagByName(root);
            if (tag != null) {
                LOGGER.log(Level.FINEST, "root is a tag, resolving tag snapshot");
                snapshot = tag.getSnapshot();
            }
            SnapshotElement element = ws.findSnapshotByName(snapshot);
            if (element == null) {
                throw new RootNotFoundException(root);
            } else {
                rroot = element.getKey();
            }
        }

        if (npath.isRoot()) {
            return rroot;
        }

        Collection parent = readCollectionAtPath(rroot, ppath);
        LOGGER.log(Level.FINEST, "parent collection loaded for path " + ppath.build());

        CollectionElement element = parent.findElementByName(npath.part());
        if (element == null) {
            throw new PathNotFoundException(npath.build());
        }
        return element.getKey();
    } catch (KeyNotFoundException | RegistryServiceException e) {
        LOGGER.log(Level.SEVERE, "unexpected error occurred during resolving path", e);
        throw new CoreServiceException("unable to resolve into workspace [" + wskey + "] path [" + path + "]",
                e);
    }
}

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

/**
 * {@inheritDoc}//  w w w  .  ja v a2 s  .  com
 */
@Override
@TransactionAttribute(TransactionAttributeType.SUPPORTS)
public List<Account> loadAll(String name, String loginName, String email, Boolean isActive, Boolean isConfirmed,
        Long mandatorId, int[] isInRole, long[] isInGroup, int startIdx, int maxEntries)
        throws FxApplicationException {

    Connection con = null;
    Statement stmt = null;
    final UserTicket ticket = FxContext.getUserTicket();

    String curSql = _buildSearchStmt(ticket, name, loginName, email, isActive, isConfirmed, mandatorId,
            isInRole, isInGroup, false);

    try {
        // Obtain a database connection
        con = Database.getDbConnection();

        // Load the users
        stmt = con.createStatement();
        ResultSet rs = stmt.executeQuery(curSql);
        ArrayList<Account> alResult = new ArrayList<Account>(1000);
        int counter = 0;
        if (startIdx < 0)
            startIdx = 0;
        if (rs != null) {
            while (rs.next()) {

                // jump to startIndex
                if (startIdx > 0) {
                    startIdx--;
                    continue;
                }

                // return only maxEntries
                if (counter > -1) {
                    if (counter == maxEntries)
                        break;
                    counter++;
                }

                // add to result
                long id = rs.getLong(1);
                String _email = rs.getString(2);
                long contactDataId = rs.getLong(3);
                if (rs.wasNull())
                    contactDataId = -1;
                long mandator = rs.getLong(4);
                FxLanguage lang = language.load(rs.getInt(5));
                Date validFrom = new Date(rs.getLong(6));
                Date validTo = new Date(rs.getLong(7));
                String description = rs.getString(8);
                String _name = rs.getString(9);
                String _loginName = rs.getString(10);
                boolean active = rs.getBoolean(11);
                boolean validated = rs.getBoolean(12);
                boolean multiLogin = rs.getBoolean(13);
                String updateToken = rs.getString(14);
                String restToken = rs.getString(19);
                long restTokenExpires = rs.getLong(20);

                alResult.add(new Account(id, _name, _loginName, mandator, _email, lang, active, validated,
                        validFrom, validTo, -1, description, contactDataId, multiLogin, updateToken, restToken,
                        restTokenExpires, LifeCycleInfoImpl.load(rs, 15, 16, 17, 18)));
            }
        }

        return alResult;
    } catch (FxInvalidLanguageException exc) {
        throw new FxLoadException(exc);
    } catch (SQLException exc) {
        throw new FxLoadException(LOG, exc, "ex.account.loadAll.failed.sql", exc.getMessage(), curSql);
    } finally {
        Database.closeObjects(AccountEngineBean.class, con, stmt);
    }
}