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
@RolesAllowed({ "admin", "system" })
@TransactionAttribute(TransactionAttributeType.SUPPORTS)
public Workspace systemReadWorkspace(String wskey) throws CoreServiceException, KeyNotFoundException {
    LOGGER.log(Level.FINE, "#SYSTEM# reading workspace for key [" + wskey + "]");
    try {/*  w  w w .  j  a v a  2  s  .c o  m*/
        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");
        }
        workspace.setKey(wskey);

        return workspace;
    } catch (RegistryServiceException e) {
        LOGGER.log(Level.SEVERE, "unexpected error occurred while reading workspace", e);
        throw new CoreServiceException("unable to read workspace with key [" + wskey + "]", e);
    }
}

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

@TransactionAttribute(TransactionAttributeType.SUPPORTS)
private Set<String> systemListCollectionKeys(String key, Set<String> keys)
        throws RegistryServiceException, KeyNotFoundException, CoreServiceException {
    OrtolangObjectIdentifier cidentifier = registry.lookup(key);
    checkObjectType(cidentifier, Collection.OBJECT_TYPE);
    Collection collection = em.find(Collection.class, cidentifier.getId());
    if (collection == null) {
        throw new CoreServiceException(
                "unable to load collection with id [" + cidentifier.getId() + "] from storage");
    }/*from   w  w w  .j  av  a2  s . co  m*/
    if (keys.add(key)) {
        for (MetadataElement element : collection.getMetadatas()) {
            keys.add(element.getKey());
        }

        for (CollectionElement element : collection.getElements()) {
            keys.add(element.getKey());
            if (element.getType().equals(Collection.OBJECT_TYPE)) {
                systemListCollectionKeys(element.getKey(), keys);
            }
            if (element.getType().equals(DataObject.OBJECT_TYPE)) {
                OrtolangObjectIdentifier identifier = registry.lookup(element.getKey());
                checkObjectType(identifier, DataObject.OBJECT_TYPE);
                DataObject object = em.find(DataObject.class, identifier.getId());
                if (object == null) {
                    throw new CoreServiceException(
                            "unable to load object with id [" + identifier.getId() + "] from storage");
                }
                keys.add(element.getKey());
                for (MetadataElement mde : object.getMetadatas()) {
                    keys.add(mde.getKey());
                }
            }
            if (element.getType().equals(Link.OBJECT_TYPE)) {
                OrtolangObjectIdentifier identifier = registry.lookup(element.getKey());
                checkObjectType(identifier, Link.OBJECT_TYPE);
                Link link = em.find(Link.class, identifier.getId());
                if (link == null) {
                    throw new CoreServiceException(
                            "unable to load link with id [" + identifier.getId() + "] from storage");
                }
                keys.add(element.getKey());
                for (MetadataElement mde : link.getMetadatas()) {
                    keys.add(mde.getKey());
                }
            }
        }
    }

    return keys;
}

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

@Override
@TransactionAttribute(TransactionAttributeType.SUPPORTS)
public List<Collection> systemListCollections() throws CoreServiceException {
    try {/* w w w.j a va  2 s . co m*/
        TypedQuery<Collection> query = em.createNamedQuery("findCollections", Collection.class);
        List<Collection> collections = query.getResultList();
        for (Iterator<Collection> iterator = collections.iterator(); iterator.hasNext();) {
            try {
                Collection collection = iterator.next();
                String key = registry.lookup(collection.getObjectIdentifier());
                collection.setKey(key);
            } catch (IdentifierNotRegisteredException e) {
                iterator.remove();
            }
        }
        return collections;
    } catch (RegistryServiceException e) {
        throw new CoreServiceException(e);
    }
}

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

@TransactionAttribute(TransactionAttributeType.SUPPORTS)
private OrtolangObject readObject(String key) throws CoreServiceException, KeyNotFoundException {
    try {//from w w w . j a  v a  2 s  . com
        OrtolangObjectIdentifier identifier = registry.lookup(key);

        if (!identifier.getService().equals(CoreService.SERVICE_NAME)) {
            throw new CoreServiceException(
                    "object identifier " + identifier + " does not refer to service " + getServiceName());
        }

        switch (identifier.getType()) {
        case 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");
            }
            workspace.setKey(key);
            return workspace;
        case DataObject.OBJECT_TYPE:
            DataObject object = em.find(DataObject.class, identifier.getId());
            if (object == null) {
                throw new CoreServiceException(
                        "unable to load object with id [" + identifier.getId() + "] from storage");
            }
            object.setKey(key);
            return object;
        case Collection.OBJECT_TYPE:
            Collection collection = em.find(Collection.class, identifier.getId());
            if (collection == null) {
                throw new CoreServiceException(
                        "unable to load collection with id [" + identifier.getId() + "] from storage");
            }
            collection.setKey(key);
            return collection;
        case Link.OBJECT_TYPE:
            Link link = em.find(Link.class, identifier.getId());
            if (link == null) {
                throw new CoreServiceException(
                        "unable to load link with id [" + identifier.getId() + "] from storage");
            }
            link.setKey(key);
            return link;
        case MetadataObject.OBJECT_TYPE:
            MetadataObject meta = em.find(MetadataObject.class, identifier.getId());
            if (meta == null) {
                throw new CoreServiceException(
                        "unable to load metadata with id [" + identifier.getId() + "] from storage");
            }
            meta.setKey(key);
            return meta;
        default:
            throw new CoreServiceException("object identifier " + identifier
                    + " refer to an unknown type for service " + getServiceName());
        }

    } catch (RegistryServiceException e) {
        throw new CoreServiceException("unable to read object with key " + key);
    }
}

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

@TransactionAttribute(TransactionAttributeType.SUPPORTS)
private OrtolangObjectSize getCollectionSize(String key, OrtolangObjectIdentifier cidentifier,
        OrtolangObjectSize ortolangObjectSize, List<String> subjects)
        throws KeyNotFoundException, RegistryServiceException, CoreServiceException {
    LOGGER.log(Level.FINE, "calculating collection size for collection with key [" + key + "]");
    try {/*  ww w.ja v a 2s.c  o m*/
        authorisation.checkPermission(key, subjects, "read");

        Collection collection = em.find(Collection.class, cidentifier.getId());
        if (collection == null) {
            throw new CoreServiceException(
                    "unable to load collection with id [" + cidentifier.getId() + "] from storage");
        }

        for (CollectionElement element : collection.getElements()) {
            if (element.getType().equals(DataObject.OBJECT_TYPE)) {
                try {
                    authorisation.checkPermission(element.getKey(), subjects, "read");
                    ortolangObjectSize.addElement(element.getType(), element.getSize());
                } catch (AuthorisationServiceException | AccessDeniedException e) {
                    ortolangObjectSize.setPartial(true);
                }
            } else if (element.getType().equals(Collection.OBJECT_TYPE)) {
                ortolangObjectSize.addElement(element.getType(), 0);
                OrtolangObjectIdentifier identifier = registry.lookup(element.getKey());
                ortolangObjectSize = getCollectionSize(element.getKey(), identifier, ortolangObjectSize,
                        subjects);
            }
        }
    } catch (AuthorisationServiceException | AccessDeniedException e) {
        ortolangObjectSize.setPartial(true);
    }
    return ortolangObjectSize;
}

From source file:com.lp.server.fertigung.ejbfac.FertigungFacBean.java

@TransactionAttribute(TransactionAttributeType.SUPPORTS)
public int wiederholendeLoseAnlegen(TheClientDto theClientDto) {

    int iAnzahlAngelegterLose = 0;
    DateFormatSymbols symbols = new DateFormatSymbols(theClientDto.getLocUi());
    String[] defaultMonths = symbols.getMonths();
    int iStandarddurchlaufzeit = 0;
    try {/*from ww w  . ja v a  2  s  . c  o m*/
        ParametermandantDto parameter = getParameterFac().getMandantparameter(theClientDto.getMandant(),
                ParameterFac.KATEGORIE_FERTIGUNG, ParameterFac.INTERNEBESTELLUNG_DEFAULTDURCHLAUFZEIT);
        iStandarddurchlaufzeit = ((Integer) parameter.getCWertAsObject()).intValue();
    } catch (RemoteException ex2) {
        throwEJBExceptionLPRespectOld(ex2);
    }

    Session session = FLRSessionFactory.getFactory().openSession();

    Criteria crit = session.createCriteria(FLRWiederholendelose.class);

    crit.add(Restrictions.eq("mandant_c_nr", theClientDto.getMandant()));
    crit.add(Restrictions.eq(FertigungFac.FLR_WIEDERHOLENDELOSE_B_VERSTECKT, Helper.boolean2Short(false)));

    List<?> resultList = crit.list();
    Iterator<?> resultListIterator = resultList.iterator();
    while (resultListIterator.hasNext()) {
        FLRWiederholendelose flrWiederholendelose = (FLRWiederholendelose) resultListIterator.next();

        // Naechster faelliger Termin nach Heute
        Calendar cBeginn = Calendar.getInstance();
        cBeginn.setTimeInMillis(flrWiederholendelose.getT_termin().getTime());

        String intervall = flrWiederholendelose.getAuftragwiederholungsintervall_c_nr();

        Timestamp tHeute = Helper.cutTimestamp(new Timestamp(System.currentTimeMillis()));

        while (cBeginn.getTimeInMillis() < tHeute.getTime()) {

            if (intervall.equals(AuftragServiceFac.AUFTRAGWIEDERHOLUNGSINTERVALL_2WOECHENTLICH)) {
                cBeginn.set(Calendar.DAY_OF_MONTH, cBeginn.get(Calendar.DAY_OF_MONTH) + 14);
            } else if (intervall.equals(AuftragServiceFac.AUFTRAGWIEDERHOLUNGSINTERVALL_WOECHENTLICH)) {
                cBeginn.set(Calendar.DAY_OF_MONTH, cBeginn.get(Calendar.DAY_OF_MONTH) + 7);
            }

            if (intervall.equals(AuftragServiceFac.AUFTRAGWIEDERHOLUNGSINTERVALL_JAHR)) {
                cBeginn.set(Calendar.YEAR, cBeginn.get(Calendar.YEAR) + 1);
            } else if (intervall.equals(AuftragServiceFac.AUFTRAGWIEDERHOLUNGSINTERVALL_2JAHR)) {
                cBeginn.set(Calendar.YEAR, cBeginn.get(Calendar.YEAR) + 2);
            } else if (intervall.equals(AuftragServiceFac.AUFTRAGWIEDERHOLUNGSINTERVALL_3JAHR)) {
                cBeginn.set(Calendar.YEAR, cBeginn.get(Calendar.YEAR) + 3);
            } else if (intervall.equals(AuftragServiceFac.AUFTRAGWIEDERHOLUNGSINTERVALL_4JAHR)) {
                cBeginn.set(Calendar.YEAR, cBeginn.get(Calendar.YEAR) + 4);
            } else if (intervall.equals(AuftragServiceFac.AUFTRAGWIEDERHOLUNGSINTERVALL_5JAHR)) {
                cBeginn.set(Calendar.YEAR, cBeginn.get(Calendar.YEAR) + 5);
            } else if (intervall.equals(AuftragServiceFac.AUFTRAGWIEDERHOLUNGSINTERVALL_MONATLICH)) {
                cBeginn.set(Calendar.MONTH, cBeginn.get(Calendar.MONTH) + 1);
            } else if (intervall.equals(AuftragServiceFac.AUFTRAGWIEDERHOLUNGSINTERVALL_QUARTAL)) {
                cBeginn.set(Calendar.MONTH, cBeginn.get(Calendar.MONTH) + 3);
            }
        }

        Timestamp tBeginndatumFuerLos = new Timestamp(cBeginn.getTimeInMillis());
        // Voreilende Tage abziehen

        String monatsname = defaultMonths[cBeginn.get(Calendar.MONTH)];
        int iJahr = cBeginn.get(Calendar.YEAR);

        int iTageVoreilend = flrWiederholendelose.getI_tagevoreilend();
        cBeginn.set(Calendar.DAY_OF_MONTH, cBeginn.get(Calendar.DAY_OF_MONTH) - iTageVoreilend);

        Timestamp tAnlagedatum = new Timestamp(cBeginn.getTimeInMillis());

        if (tAnlagedatum.before(tHeute) || tAnlagedatum.equals(tHeute)) {
            // try {
            Query query = em.createNamedQuery("LosfindWiederholendeloseIIdTProduktionsbeginnMandantCNr");
            query.setParameter(1, flrWiederholendelose.getI_id());
            query.setParameter(2, tBeginndatumFuerLos);
            query.setParameter(3, theClientDto.getMandant());
            Collection<?> cl = query.getResultList();
            // if (cl.isEmpty()) {
            // throw new EJBExceptionLP(EJBExceptionLP.FEHLER, null);
            // }
            LosDto[] lose = assembleLosDtos(cl);

            // Wenn noch nicht angelegt
            if (lose.length == 0) {

                WiederholendeloseDto dto = wiederholendeloseFindByPrimaryKey(flrWiederholendelose.getI_id());
                String projektname = "";
                if (dto.getCProjekt() != null) {
                    projektname += dto.getCProjekt() + " ";
                }
                projektname += monatsname + " " + iJahr;

                if (projektname.length() > 50) {
                    projektname = projektname.substring(0, 49);
                }

                LosDto losDto = new LosDto();
                losDto.setWiederholendeloseIId(dto.getIId());
                losDto.setCProjekt(projektname);
                losDto.setFertigungsgruppeIId(dto.getFertigungsgruppeIId());
                losDto.setKostenstelleIId(dto.getKostenstelleIId());
                losDto.setLagerIIdZiel(dto.getLagerIIdZiel());
                losDto.setMandantCNr(theClientDto.getMandant());
                losDto.setNLosgroesse(dto.getNLosgroesse());
                losDto.setPartnerIIdFertigungsort(dto.getPartnerIIdFertigungsort());
                losDto.setStuecklisteIId(dto.getStuecklisteIId());
                losDto.setTProduktionsbeginn(new java.sql.Date(tBeginndatumFuerLos.getTime()));

                // Produktionsende

                try {

                    int laufzeit = iStandarddurchlaufzeit;
                    if (dto.getStuecklisteIId() != null) {
                        StuecklisteDto stuecklisteDto = getStuecklisteFac()
                                .stuecklisteFindByPrimaryKey(dto.getStuecklisteIId(), theClientDto);
                        if (stuecklisteDto.getNDefaultdurchlaufzeit() != null) {
                            laufzeit = stuecklisteDto.getNDefaultdurchlaufzeit().intValue();
                        }
                    }
                    Calendar cTemp = Calendar.getInstance();
                    cTemp.setTimeInMillis(tBeginndatumFuerLos.getTime());
                    cTemp.set(Calendar.DAY_OF_MONTH, cTemp.get(Calendar.DAY_OF_MONTH) + laufzeit);
                    losDto.setTProduktionsende(new java.sql.Date(cTemp.getTime().getTime()));
                    context.getBusinessObject(FertigungFac.class).createLos(losDto, theClientDto);
                } catch (RemoteException ex1) {
                    throwEJBExceptionLPRespectOld(ex1);
                }

                iAnzahlAngelegterLose++;
            }
            // }
            // catch (FinderException ex) {
            // throw new EJBExceptionLP(EJBExceptionLP.FEHLER, ex);
            // }

        }

    }

    return iAnzahlAngelegterLose;
}

From source file:org.cesecore.audit.impl.integrityprotected.IntegrityProtectedAuditorSessionBean.java

@Override
@TransactionAttribute(TransactionAttributeType.SUPPORTS)
public List<? extends AuditLogEntry> selectAuditLogs(final AuthenticationToken token, final int startIndex,
        final int max, final QueryCriteria criteria, final Properties properties) {
    return internalSelectAuditLogs(startIndex, max, criteria);
}

From source file:org.cesecore.certificates.ca.CaSessionBean.java

@Override
@TransactionAttribute(TransactionAttributeType.SUPPORTS)
public void flushCACache() {
    CaCache.INSTANCE.flush();//w  ww  .j ava2s. c o  m
    if (log.isDebugEnabled()) {
        log.debug("Flushed CA cache.");
    }
}

From source file:org.cesecore.certificates.ca.CaSessionBean.java

@Override
@TransactionAttribute(TransactionAttributeType.SUPPORTS)
public CA getCA(final AuthenticationToken admin, final int caid)
        throws CADoesntExistsException, AuthorizationDeniedException {
    if (!authorizedToCA(admin, caid)) {
        String msg = intres.getLocalizedMessage("caadmin.notauthorizedtoca", admin.toString(),
                Integer.valueOf(caid));
        throw new AuthorizationDeniedException(msg);
    }/*from   w ww.  ja  v  a2  s.co m*/
    return getCAInternal(caid, null, true);
}

From source file:org.cesecore.certificates.ca.CaSessionBean.java

@Override
@TransactionAttribute(TransactionAttributeType.SUPPORTS)
public CA getCA(final AuthenticationToken admin, final String name)
        throws CADoesntExistsException, AuthorizationDeniedException {
    CA ca = getCAInternal(-1, name, true);
    if (!authorizedToCA(admin, ca.getCAId())) {
        String msg = intres.getLocalizedMessage("caadmin.notauthorizedtoca", admin.toString(), name);
        throw new AuthorizationDeniedException(msg);
    }/*  w  ww  .ja  va  2 s  .  co m*/
    return ca;
}