use of org.apache.openejb.jee.oejb3.EjbDeployment in project tomee by apache.
the class DebuggableVmHackery method deploy.
public AppModule deploy(final AppModule appModule) throws OpenEJBException {
for (final EjbModule ejbModule : appModule.getEjbModules()) {
final EjbJar ejbJar = ejbModule.getEjbJar();
final OpenejbJar openejbJar = ejbModule.getOpenejbJar();
final Map<String, EjbDeployment> deployments = openejbJar.getDeploymentsByEjbName();
ejbJar.setRelationships(null);
final List<String> removed = new ArrayList<String>();
for (final EnterpriseBean bean : ejbJar.getEnterpriseBeans()) {
final String ejbName = bean.getEjbName();
final EjbDeployment ejbDeployment = deployments.get(ejbName);
pruneRefs(bean, ejbDeployment);
// }
if (!(bean instanceof MessageDrivenBean) && !(bean instanceof EntityBean)) {
continue;
}
ejbJar.removeEnterpriseBean(ejbName);
openejbJar.removeEjbDeployment(ejbDeployment);
removed.add(ejbName);
final AssemblyDescriptor assemblyDescriptor = ejbJar.getAssemblyDescriptor();
if (assemblyDescriptor != null) {
for (final MethodPermission permission : copy(assemblyDescriptor.getMethodPermission())) {
for (final Method method : copy(permission.getMethod())) {
if (method.getEjbName().equals(ejbName)) {
permission.getMethod().remove(method);
}
}
if (permission.getMethod().size() == 0) {
assemblyDescriptor.getMethodPermission().remove(permission);
}
}
for (final ContainerTransaction transaction : copy(assemblyDescriptor.getContainerTransaction())) {
for (final Method method : copy(transaction.getMethod())) {
if (method.getEjbName().equals(ejbName)) {
transaction.getMethod().remove(method);
}
}
if (transaction.getMethod().size() == 0) {
assemblyDescriptor.getContainerTransaction().remove(transaction);
}
}
for (final InterceptorBinding binding : copy(assemblyDescriptor.getInterceptorBinding())) {
if (binding.getEjbName().equals(ejbName)) {
assemblyDescriptor.getInterceptorBinding().remove(binding);
}
}
}
}
// Drop any ejb ref to with an ejb-link to a removed ejb
for (final EnterpriseBean bean : ejbJar.getEnterpriseBeans()) {
bean.getEjbLocalRefMap().keySet().removeAll(removed);
bean.getEjbRefMap().keySet().removeAll(removed);
}
for (final Interceptor interceptor : ejbJar.getInterceptors()) {
pruneRefs(interceptor, new EjbDeployment());
}
}
return appModule;
}
use of org.apache.openejb.jee.oejb3.EjbDeployment in project tomee by apache.
the class DeploymentContextOptionsTest method testBeanContextOptions.
public void testBeanContextOptions() throws Exception {
final ConfigurationFactory config = new ConfigurationFactory();
final Assembler assembler = new Assembler();
{
assembler.createTransactionManager(config.configureService(TransactionServiceInfo.class));
assembler.createSecurityService(config.configureService(SecurityServiceInfo.class));
}
{
// Setup the descriptor information
final EjbModule ejbModule = new EjbModule(new EjbJar(), new OpenejbJar());
final EjbJar ejbJar = ejbModule.getEjbJar();
final OpenejbJar openejbJar = ejbModule.getOpenejbJar();
final StatelessBean statelessBean = ejbJar.addEnterpriseBean(new StatelessBean(WidgetBean.class));
{
// Set at BeanContext level
final EjbDeployment deployment = openejbJar.addEjbDeployment(statelessBean);
deployment.getProperties().put("color", "orange");
}
assembler.createApplication(config.configureApplication(ejbModule));
}
final ContainerSystem containerSystem = SystemInstance.get().getComponent(ContainerSystem.class);
final BeanContext beanContext = containerSystem.getBeanContext("WidgetBean");
assertOption(beanContext.getOptions(), "color", "orange");
assertNoOption(beanContext.getModuleContext().getOptions(), "color");
assertNoOption(beanContext.getModuleContext().getAppContext().getOptions(), "color");
}
use of org.apache.openejb.jee.oejb3.EjbDeployment in project tomee by apache.
the class DeploymentContextPropertiesTest method testBeanContextProperties.
public void testBeanContextProperties() throws Exception {
final ConfigurationFactory config = new ConfigurationFactory();
final Assembler assembler = new Assembler();
{
assembler.createTransactionManager(config.configureService(TransactionServiceInfo.class));
assembler.createSecurityService(config.configureService(SecurityServiceInfo.class));
}
{
// Setup the descriptor information
final EjbModule ejbModule = new EjbModule(new EjbJar(), new OpenejbJar());
final EjbJar ejbJar = ejbModule.getEjbJar();
final OpenejbJar openejbJar = ejbModule.getOpenejbJar();
final StatelessBean statelessBean = ejbJar.addEnterpriseBean(new StatelessBean(WidgetBean.class));
final EjbDeployment deployment = openejbJar.addEjbDeployment(statelessBean);
deployment.getProperties().put("color", "orange");
assembler.createApplication(config.configureApplication(ejbModule));
}
final ContainerSystem containerSystem = SystemInstance.get().getComponent(ContainerSystem.class);
final BeanContext beanContext = containerSystem.getBeanContext("WidgetBean");
final Properties properties = beanContext.getProperties();
assertProperty(properties, "color", "orange");
}
use of org.apache.openejb.jee.oejb3.EjbDeployment in project tomee by apache.
the class ActiveMQResourceAdapterControlTest method app.
@Module
@Classes(value = Mdb.class)
public EjbModule app() {
return new EjbModule(new EjbJar("test"), new OpenejbJar() {
{
setId("test");
getEjbDeployment().add(new EjbDeployment() {
{
setEjbName("ejb/Mdb");
getProperties().put("MdbActiveOnStartup", "false");
getProperties().put("MdbJMXControl", "default:type=test");
}
});
}
});
}
use of org.apache.openejb.jee.oejb3.EjbDeployment in project tomee by apache.
the class CmpJpaConversion method processEntityBean.
/**
* Generate the CMP mapping data for an individual
* EntityBean.
*
* @param ejbModule The module containing the bean.
* @param entityMappings The accumulated set of entity mappings.
* @param bean The been we're generating the mapping for.
*/
private void processEntityBean(final EjbModule ejbModule, final EntityMappings entityMappings, final EntityBean bean) {
// try to add a new persistence-context-ref for cmp
if (!addPersistenceContextRef(bean)) {
// which means it has a mapping, so skip this bean
return;
}
// get the real bean class
final Class ejbClass = loadClass(ejbModule.getClassLoader(), bean.getEjbClass());
// and generate a name for the subclass that will be generated and handed to the JPA
// engine as the managed class.
final String jpaEntityClassName = CmpUtil.getCmpImplClassName(bean.getAbstractSchemaName(), ejbClass.getName());
// We don't use this mapping directly, instead we pull entries from it
// the reason being is that we intend to support mappings that aren't
// exactly correct. i.e. users should be able to write mappings completely
// ignorant of the fact that we subclass. The fact that we subclass means
// these user supplied mappings might need to be adjusted as the jpa orm.xml
// file is extremely subclass/supperclass aware and mappings specified in it
// need to be spot on.
final EntityMappings userMappings = getUserEntityMappings(ejbModule);
// chain of the bean looking for any that have user defined mappings.
for (Class clazz = ejbClass; clazz != null; clazz = clazz.getSuperclass()) {
final MappedSuperclass mappedSuperclass = removeMappedSuperclass(userMappings, clazz.getName());
// that the mapping is correct. Copy it from their mappings to ours
if (mappedSuperclass != null) {
entityMappings.getMappedSuperclass().add(mappedSuperclass);
}
}
// Look for an existing mapping using the openejb generated subclass name
Entity entity = removeEntity(userMappings, jpaEntityClassName);
// because we are going to ignore all other xml metadata.
if (entity != null) {
// XmlMetadataComplete is an OpenEJB specific flag that
// tells all other legacy descriptor converters to keep
// their hands off.
entity.setXmlMetadataComplete(true);
entityMappings.getEntity().add(entity);
return;
}
if (entity == null) {
entity = new Entity(jpaEntityClassName);
}
// have to check for null everywhere.
if (entity.getAttributes() == null) {
entity.setAttributes(new Attributes());
}
// add the entity
entityMappings.getEntity().add(entity);
// OVERWRITE: description: contains the name of the entity bean
entity.setDescription(ejbModule.getModuleId() + "#" + bean.getEjbName());
// PRESERVE has queries: name: the name of the entity in queries
final String entityName = bean.getAbstractSchemaName();
entity.setName(entityName);
entity.setEjbName(bean.getEjbName());
final ClassLoader classLoader = ejbModule.getClassLoader();
final Collection<MappedSuperclass> mappedSuperclasses;
if (bean.getCmpVersion() == CmpVersion.CMP2) {
// perform the 2.x class mapping. This really just identifies the primary key and
// other cmp fields that will be generated for the concrete class and identify them
// to JPA.
mappedSuperclasses = 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
mappedSuperclasses = mapClass1x(bean.getEjbClass(), entity, bean, classLoader);
}
// configuration. f
if (mappedSuperclasses != null) {
// that will get passed to the JPA engine.
for (final MappedSuperclass mappedSuperclass : mappedSuperclasses) {
entityMappings.getMappedSuperclass().add(mappedSuperclass);
}
}
// process queries
for (final Query query : bean.getQuery()) {
final NamedQuery namedQuery = new NamedQuery();
final 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
final 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 (final 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
final OpenejbJar openejbJar = ejbModule.getOpenejbJar();
final EjbDeployment ejbDeployment = openejbJar.getDeploymentsByEjbName().get(bean.getEjbName());
if (ejbDeployment != null) {
for (final org.apache.openejb.jee.oejb3.Query query : ejbDeployment.getQuery()) {
final NamedQuery namedQuery = new NamedQuery();
final org.apache.openejb.jee.oejb3.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
final 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 (final String methodParam : queryMethod.getMethodParams().getMethodParam()) {
if (!first) {
name.append(",");
}
name.append(methodParam);
first = false;
}
name.append(')');
}
namedQuery.setName(name.toString());
namedQuery.setQuery(query.getObjectQl());
entity.getNamedQuery().add(namedQuery);
}
}
}
Aggregations