Package org.apache.openejb.jee.oejb3

Examples of org.apache.openejb.jee.oejb3.QueryMethod


    }

    private EjbModule deploy(EjbModule ejbModule, Map<String, String> contextData, Set<String> abstractSchemaNames) throws OpenEJBException {
        contextData.put("moduleId", ejbModule.getModuleId());

        OpenejbJar openejbJar;
        if (ejbModule.getOpenejbJar() != null) {
            openejbJar = ejbModule.getOpenejbJar();
        } else {
            openejbJar = new OpenejbJar();
            ejbModule.setOpenejbJar(openejbJar);
        }

        StringTemplate deploymentIdTemplate = this.deploymentIdTemplate;
        if (openejbJar.getProperties().containsKey(DEPLOYMENT_ID_FORMAT)) {
            String format = openejbJar.getProperties().getProperty(DEPLOYMENT_ID_FORMAT);
            logger.info("Using " + DEPLOYMENT_ID_FORMAT + " '" + format + "'");
            deploymentIdTemplate = new StringTemplate(format);
        }


        for (EnterpriseBean bean : ejbModule.getEjbJar().getEnterpriseBeans()) {
            StringTemplate template = deploymentIdTemplate;

            org.apache.openejb.api.EjbDeployment annotation = getEjbDeploymentAnnotation(ejbModule, bean);

            EjbDeployment ejbDeployment = openejbJar.getDeploymentsByEjbName().get(bean.getEjbName());
            if (ejbDeployment == null) {

                ejbDeployment = new EjbDeployment();

                ejbDeployment.setEjbName(bean.getEjbName());

                if (annotation != null && isDefined(annotation.id())) {
                    template = new StringTemplate(annotation.id());
                    ejbDeployment.setDeploymentId(formatDeploymentId(bean, contextData, template));
                } else {
                    ejbDeployment.setDeploymentId(formatDeploymentId(bean, contextData, template));
                    logger.info("Auto-deploying ejb " + bean.getEjbName() + ": EjbDeployment(deployment-id=" + ejbDeployment.getDeploymentId() + ")");
                }

                openejbJar.getEjbDeployment().add(ejbDeployment);
            } else if (ejbDeployment.getDeploymentId() == null) {
                if (annotation != null && isDefined(annotation.id())) {
                    template = new StringTemplate(annotation.id());
                    ejbDeployment.setDeploymentId(formatDeploymentId(bean, contextData, template));
                } else {
View Full Code Here


    private EntityMappings convert(String ejbJarFileName, String sunEjbJarFileName, String sunCmpMappingsFileName, String expectedFileName) throws Exception {
        InputStream in = getClass().getClassLoader().getResourceAsStream(ejbJarFileName);
        EjbJar ejbJar = (EjbJar) JaxbJavaee.unmarshal(EjbJar.class, new ByteArrayInputStream(readContent(in).getBytes()));

        // create and configure the module
        EjbModule ejbModule = new EjbModule(getClass().getClassLoader(), "TestModule", ejbJarFileName, ejbJar, new OpenejbJar());
        InitEjbDeployments initEjbDeployments = new InitEjbDeployments();
        initEjbDeployments.deploy(ejbModule, new HashMap<String,String>());
        AppModule appModule = new AppModule(getClass().getClassLoader(), "TestModule");
        appModule.getEjbModules().add(ejbModule);
View Full Code Here

        return appModule;
    }

    private void writeOpenejbJar(EjbModule ejbModule) {
        try {
            OpenejbJar openejbJar = ejbModule.getOpenejbJar();
            File tempFile = File.createTempFile(ejbModule.getModuleId(), ".openejb-jar.xml");
            FileOutputStream fout = new FileOutputStream(tempFile);
            BufferedOutputStream out = new BufferedOutputStream(fout);
            try {
                JaxbOpenejbJar3.marshal(OpenejbJar.class, openejbJar, out);
View Full Code Here

        return entityMappings;
    }

    public void generateEntityMappings(EjbModule ejbModule, EntityMappings entityMappings) throws OpenEJBException {
        EjbJar ejbJar = ejbModule.getEjbJar();
        OpenejbJar openejbJar = ejbModule.getOpenejbJar();
        ClassLoader classLoader = ejbModule.getClassLoader();

        Map<String, MappedSuperclass> mappedSuperclassByClass = new TreeMap<String,MappedSuperclass>();
        for (MappedSuperclass mappedSuperclass : entityMappings.getMappedSuperclass()) {
            mappedSuperclassByClass.put(mappedSuperclass.getClazz(), mappedSuperclass);
        }

        Map<String, Entity> entitiesByName = new TreeMap<String,Entity>();
        for (Entity entity : entityMappings.getEntity()) {
            entitiesByName.put(entity.getName(), entity);
        }
       
        for (org.apache.openejb.jee.EnterpriseBean enterpriseBean : ejbJar.getEnterpriseBeans()) {
            // skip all non-CMP beans
            if (!(enterpriseBean instanceof EntityBean) ||
                    ((EntityBean) enterpriseBean).getPersistenceType() != PersistenceType.CONTAINER) {
                continue;
            }
            EntityBean bean = (EntityBean) enterpriseBean;

            // Always set the abstract schema name
            if (bean.getAbstractSchemaName() == null) {
                String abstractSchemaName = bean.getEjbName().trim().replaceAll("[ \\t\\n\\r-]+", "_");
                if (entitiesByName.containsKey(abstractSchemaName)) {
                    int i = 2;
                    while (entitiesByName.containsKey(abstractSchemaName + i)) {
                         i++;
                    }
                    abstractSchemaName = abstractSchemaName + i;
                }
                bean.setAbstractSchemaName(abstractSchemaName);
            }

            // try to add a new persistence-context-ref for cmp
            if (!addPersistenceContextRef(bean)) {
                // Bean already has a persistence-context-ref for cmp
                // which means it has a mapping, so skip this bean
                continue;
            }

            Entity entity = new Entity();

            // description: contains the name of the entity bean
            entity.setDescription(ejbModule.getModuleId() + "#" + bean.getEjbName());

            // name: the name of the entity in queries
            String entityName = bean.getAbstractSchemaName();
            entity.setName(entityName);

            // class: impl class name
            String cmpImplClassName = CmpUtil.getCmpImplClassName(bean.getAbstractSchemaName(), bean.getEjbClass());
            entity.setClazz(cmpImplClassName);

            // add the entity
            entityMappings.getEntity().add(entity);
            entitiesByName.put(bean.getEjbName(), entity);

            if (bean.getCmpVersion() == CmpVersion.CMP2) {
                mapClass2x(entity, bean, classLoader);
            } else {
                // map the cmp class, but if we are using a mapped super class, generate attribute-override instead of id and basic
                Collection<MappedSuperclass> mappedSuperclasses = mapClass1x(bean.getEjbClass(), entity, bean, classLoader);
                for (MappedSuperclass mappedSuperclass : mappedSuperclasses) {
                    mappedSuperclassByClass.put(mappedSuperclass.getClazz(), mappedSuperclass);
                }
            }

            // process queries
            for (Query query : bean.getQuery()) {
                NamedQuery namedQuery = new NamedQuery();
                QueryMethod queryMethod = query.getQueryMethod();

                // todo deployment id could change in one of the later conversions... use entity name instead, but we need to save it off
                StringBuilder name = new StringBuilder();
                name.append(entityName).append(".").append(queryMethod.getMethodName());
                if (queryMethod.getMethodParams() != null && !queryMethod.getMethodParams().getMethodParam().isEmpty()) {
                    name.append('(');
                    boolean first = true;
                    for (String methodParam : queryMethod.getMethodParams().getMethodParam()) {
                        if (!first) name.append(",");
                        name.append(methodParam);
                        first = false;
                    }
                    name.append(')');
                }
                namedQuery.setName(name.toString());

                namedQuery.setQuery(query.getEjbQl());
                entity.getNamedQuery().add(namedQuery);
            }
            // todo: there should be a common interface between ejb query object and openejb query object
            EjbDeployment ejbDeployment = openejbJar.getDeploymentsByEjbName().get(bean.getEjbName());
            if (ejbDeployment != null) {
                for (org.apache.openejb.jee.oejb3.Query query : ejbDeployment.getQuery()) {
                    NamedQuery namedQuery = new NamedQuery();
                    org.apache.openejb.jee.oejb3.QueryMethod queryMethod = query.getQueryMethod();
View Full Code Here

    }

    private void pruneRefs(JndiConsumer bean, EjbDeployment ejbDeployment) {
        for (ResourceRef ref : copy(bean.getResourceRef())) {
            if (ref.getResType().startsWith("javax.jms.")){
                ResourceLink resourceLink = ejbDeployment.getResourceLink(ref.getName());
                ejbDeployment.getResourceLink().remove(resourceLink);
                bean.getResourceRef().remove(ref);
            }
        }

        for (ResourceEnvRef ref : bean.getResourceEnvRef()) {
            ResourceLink resourceLink = ejbDeployment.getResourceLink(ref.getName());
            ejbDeployment.getResourceLink().remove(resourceLink);
        }
        bean.getResourceEnvRef().clear();

        for (MessageDestinationRef ref : bean.getMessageDestinationRef()) {
            ResourceLink resourceLink = ejbDeployment.getResourceLink(ref.getName());
            ejbDeployment.getResourceLink().remove(resourceLink);
        }
        bean.getMessageDestinationRef().clear();

        bean.getPersistenceContextRef().clear();
View Full Code Here

            bean.mdbInterface = mdb.getMessagingType();
        } else {
            bean.mdbInterface = "javax.jms.MessageListener";
        }

        ResourceLink resourceLink = d.getResourceLink("openejb/destination");
        if (resourceLink != null) {
            bean.destinationId = resourceLink.getResId();
        }

        if (mdb.getMessageDestinationType() != null) {
            bean.activationProperties.put("destinationType", mdb.getMessageDestinationType());
        }
View Full Code Here

            bean.mdbInterface = mdb.getMessagingType();
        } else {
            bean.mdbInterface = "javax.jms.MessageListener";
        }

        ResourceLink resourceLink = d.getResourceLink("openejb/destination");
        if (resourceLink != null) {
            bean.destinationId = resourceLink.getResId();
        }

        if (mdb.getMessageDestinationType() != null) {
            bean.activationProperties.put("destinationType", mdb.getMessageDestinationType());
        }
View Full Code Here

                    destination = ejbDeployment.getDeploymentId();
                    mdb.getActivationConfig().addProperty("destination", destination);
                }

                // destination identifier
                ResourceLink link = ejbDeployment.getResourceLink("openejb/destination");
                if (link == null && mdb.getMessageDestinationLink() == null) {
                    link = new ResourceLink();
                    link.setResId(destination);
                    link.setResRefName("openejb/destination");
                    ejbDeployment.addResourceLink(link);
                }

                // destination type
                String destinationType = properties.getProperty("destinationType");
View Full Code Here

                    if (mdb.getMessageDestinationType() != null && !destinationTypes.containsKey(destination)) {
                        destinationTypes.put(destination, mdb.getMessageDestinationType());
                    }

                    // destination identifier
                    ResourceLink resourceLink = ejbDeployment.getResourceLink("openejb/destination");
                    if (resourceLink == null) {
                        resourceLink = new ResourceLink();
                        resourceLink.setResRefName("openejb/destination");
                        ejbDeployment.addResourceLink(resourceLink);
                    }
                    resourceLink.setResId(destinationId);
                }
            }
        }

        // resolve all message destination refs with links and assign a ref id to the reference
        for (EjbModule ejbModule : appModule.getEjbModules()) {
            AssemblyDescriptor assembly = ejbModule.getEjbJar().getAssemblyDescriptor();
            if (assembly == null) {
                continue;
            }

            URI moduleUri = ejbModule.getModuleUri();
            OpenejbJar openejbJar = ejbModule.getOpenejbJar();

            for (EnterpriseBean bean : ejbModule.getEjbJar().getEnterpriseBeans()) {
                EjbDeployment ejbDeployment = openejbJar.getDeploymentsByEjbName().get(bean.getEjbName());
                if (ejbDeployment == null) {
                    throw new OpenEJBException("No ejb deployment found for ejb " + bean.getEjbName());
                }

                for (MessageDestinationRef ref : bean.getMessageDestinationRef()) {
                    // skip destination refs with a resource link already assigned
                    if (ref.getMappedName() == null && ejbDeployment.getResourceLink(ref.getName()) == null) {
                        String destinationId = resolveDestinationId(ref, moduleUri, destinationResolver, destinationTypes);
                        if (destinationId != null) {
                            // build the link and add it
                            ResourceLink resourceLink = new ResourceLink();
                            resourceLink.setResId(destinationId);
                            resourceLink.setResRefName(ref.getName());
                            ejbDeployment.addResourceLink(resourceLink);
                        }

                    }
                }
View Full Code Here

            // mdb message destination id
            if (autoCreateResources && bean instanceof MessageDrivenBean) {
                MessageDrivenBean mdb = (MessageDrivenBean) bean;

                ResourceLink resourceLink = ejbDeployment.getResourceLink("openejb/destination");
                if (resourceLink != null) {
                    try {
                        String destinationId = getResourceEnvId(bean.getEjbName(), resourceLink.getResId(), mdb.getMessageDestinationType(), appResources);
                        resourceLink.setResId(destinationId);
                    } catch (OpenEJBException e) {
                        // The MDB doesn't need the auto configured "openejb/destination" env entry
                        ejbDeployment.removeResourceLink("openejb/destination");
                    }
                }
View Full Code Here

TOP

Related Classes of org.apache.openejb.jee.oejb3.QueryMethod

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.