use of org.apache.openejb.jee.EntityBean$JAXB.readEntityBean 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<>();
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.EntityBean$JAXB.readEntityBean in project tomee by apache.
the class InitEjbDeployments method deploy.
public synchronized AppModule deploy(final AppModule appModule) throws OpenEJBException {
final Set<String> abstractSchemaNames = new HashSet<>();
for (final EjbModule ejbModule : appModule.getEjbModules()) {
for (final EnterpriseBean bean : ejbModule.getEjbJar().getEnterpriseBeans()) {
if (isCmpEntity(bean)) {
final EntityBean entity = (EntityBean) bean;
final String name = entity.getAbstractSchemaName();
if (name != null) {
abstractSchemaNames.add(name);
}
}
}
}
final Map<String, String> contextData = new HashMap<>();
contextData.put("appId", appModule.getModuleId());
for (final EjbModule ejbModule : appModule.getEjbModules()) {
contextData.put("host", ejbModule.isWebapp() ? findHost(ejbModule.getModuleId(), appModule.getWebModules()) : appModule.uniqueHostIfExists());
contextData.put("hash", Integer.toString(ejbModule.hashCode()));
contextData.put("ejbJarId", ejbModule.getModuleId());
deploy(ejbModule, contextData, abstractSchemaNames);
}
contextData.clear();
return appModule;
}
use of org.apache.openejb.jee.EntityBean$JAXB.readEntityBean in project tomee by apache.
the class CheckMethods method check_createMethodsAreImplemented.
public boolean check_createMethodsAreImplemented(final RemoteBean b, final Class bean, final Class home) {
boolean result = true;
final Method[] homeMethods = home.getMethods();
for (Method homeMethod : homeMethods) {
if (!homeMethod.getName().startsWith("create")) {
continue;
}
final Method create = homeMethod;
final StringBuilder ejbCreateName = new StringBuilder(create.getName());
ejbCreateName.replace(0, 1, "ejbC");
try {
if (javax.ejb.EnterpriseBean.class.isAssignableFrom(bean)) {
bean.getMethod(ejbCreateName.toString(), create.getParameterTypes());
}
// TODO: else { /* Check for Init method in pojo session bean class */ }
} catch (final NoSuchMethodException e) {
result = false;
final String paramString = getParameters(create);
if (b instanceof EntityBean) {
final EntityBean entity = (EntityBean) b;
fail(b, "entity.no.ejb.create", b.getEjbClass(), entity.getPrimKeyClass(), ejbCreateName.toString(), paramString);
} else {
if (b instanceof SessionBean) {
final SessionBean sb = (SessionBean) b;
// Under EJB 3.1, it is not required that a stateless session bean have an ejbCreate method, even when it has a home interface
if (!sb.getSessionType().equals(SessionType.STATELESS)) {
fail(b, "session.no.ejb.create", b.getEjbClass(), ejbCreateName.toString(), paramString);
}
}
}
}
}
return result;
}
use of org.apache.openejb.jee.EntityBean$JAXB.readEntityBean in project tomee by apache.
the class LegacyInterfaceTest method test.
public void test() throws Exception {
System.setProperty(javax.naming.Context.INITIAL_CONTEXT_FACTORY, InitContextFactory.class.getName());
final ConfigurationFactory config = new ConfigurationFactory();
final Assembler assembler = new Assembler();
assembler.createTransactionManager(config.configureService(TransactionServiceInfo.class));
assembler.createSecurityService(config.configureService(SecurityServiceInfo.class));
final EjbJar ejbJar = new EjbJar();
ejbJar.addEnterpriseBean(new SingletonBean(MySingletonBean.class));
ejbJar.addEnterpriseBean(new EntityBean(MyBmpBean.class, PersistenceType.BEAN));
// <entity>
// <ejb-name>License</ejb-name>
// <local-home>org.apache.openejb.test.entity.cmr.onetoone.LicenseLocalHome</local-home>
// <local>org.apache.openejb.test.entity.cmr.onetoone.LicenseLocal</local>
// <ejb-class>org.apache.openejb.test.entity.cmr.onetoone.LicenseBean</ejb-class>
// <persistence-type>Container</persistence-type>
// <prim-key-class>java.lang.Integer</prim-key-class>
// <reentrant>false</reentrant>
// <cmp-version>2.x</cmp-version>
// <abstract-schema-name>License</abstract-schema-name>
// <cmp-field>
// <field-name>id</field-name>
// </cmp-field>
// <cmp-field>
// <field-name>number</field-name>
// </cmp-field>
// <cmp-field>
// <field-name>points</field-name>
// </cmp-field>
// <cmp-field>
// <field-name>notes</field-name>
// </cmp-field>
// <primkey-field>id</primkey-field>
// <query>
// <!-- CompondPK one-to-one shares the local home interface so we need to declare this useless finder -->
// <query-method>
// <method-name>findByPrimaryKey</method-name>
// <method-params>
// <method-param>org.apache.openejb.test.entity.cmr.onetoone.LicensePk</method-param>
// </method-params>
// </query-method>
// <ejb-ql>SELECT OBJECT(DL) FROM License DL</ejb-ql>
// </query>
// </entity>
final EntityBean cmp = ejbJar.addEnterpriseBean(new EntityBean(MyCmpBean.class, PersistenceType.CONTAINER));
cmp.setPrimKeyClass(Integer.class.getName());
cmp.setPrimkeyField("id");
cmp.getCmpField().add(new CmpField("id"));
cmp.getCmpField().add(new CmpField("name"));
final Query query = new Query();
query.setQueryMethod(new QueryMethod("findByPrimaryKey", Integer.class.getName()));
query.setEjbQl("SELECT OBJECT(DL) FROM License DL");
cmp.getQuery().add(query);
final List<ContainerTransaction> transactions = ejbJar.getAssemblyDescriptor().getContainerTransaction();
// <container-transaction>
// <method>
// <ejb-name>MyBean</ejb-name>
// <method-name>*</method-name>
// </method>
// <trans-attribute>Supports</trans-attribute>
// </container-transaction>
transactions.add(new ContainerTransaction(TransAttribute.SUPPORTS, null, "MyBmpBean", "*"));
transactions.add(new ContainerTransaction(TransAttribute.SUPPORTS, null, "MyCmpBean", "*"));
transactions.add(new ContainerTransaction(TransAttribute.SUPPORTS, null, "MySingletonBean", "*"));
final File f = new File("test").getAbsoluteFile();
if (!f.exists() && !f.mkdirs()) {
throw new Exception("Failed to create test directory: " + f);
}
final AppModule module = new AppModule(this.getClass().getClassLoader(), f.getAbsolutePath());
module.getEjbModules().add(new EjbModule(ejbJar));
assembler.createApplication(config.configureApplication(module));
}
use of org.apache.openejb.jee.EntityBean$JAXB.readEntityBean in project tomee by apache.
the class LegacyInterfaceTest method testCustomCmpMappings.
public void testCustomCmpMappings() throws Exception {
System.setProperty(javax.naming.Context.INITIAL_CONTEXT_FACTORY, InitContextFactory.class.getName());
final ConfigurationFactory config = new ConfigurationFactory();
final Assembler assembler = new Assembler();
assembler.createTransactionManager(config.configureService(TransactionServiceInfo.class));
assembler.createSecurityService(config.configureService(SecurityServiceInfo.class));
final EjbJar ejbJar = new EjbJar();
ejbJar.addEnterpriseBean(new SingletonBean(MySingletonBean.class));
ejbJar.addEnterpriseBean(new EntityBean(MyBmpBean.class, PersistenceType.BEAN));
final EntityBean cmp = ejbJar.addEnterpriseBean(new EntityBean(MyCmpBean.class, PersistenceType.CONTAINER));
cmp.setPrimKeyClass(Integer.class.getName());
cmp.setPrimkeyField("id");
cmp.getCmpField().add(new CmpField("id"));
cmp.getCmpField().add(new CmpField("name"));
final Query query = new Query();
query.setQueryMethod(new QueryMethod("findByPrimaryKey", Integer.class.getName()));
query.setEjbQl("SELECT OBJECT(DL) FROM License DL");
cmp.getQuery().add(query);
final List<ContainerTransaction> transactions = ejbJar.getAssemblyDescriptor().getContainerTransaction();
transactions.add(new ContainerTransaction(TransAttribute.SUPPORTS, null, "MyBmpBean", "*"));
transactions.add(new ContainerTransaction(TransAttribute.SUPPORTS, null, "MyCmpBean", "*"));
transactions.add(new ContainerTransaction(TransAttribute.SUPPORTS, null, "MySingletonBean", "*"));
final File f = new File("test").getAbsoluteFile();
if (!f.exists() && !f.mkdirs()) {
throw new Exception("Failed to create test directory: " + f);
}
final EntityMappings entityMappings = new EntityMappings();
final Entity entity = new Entity();
entity.setClazz("openejb.org.apache.openejb.core.MyCmpBean");
entity.setName("MyCmpBean");
entity.setDescription("MyCmpBean");
entity.setAttributes(new Attributes());
final NamedQuery namedQuery = new NamedQuery();
namedQuery.setQuery("SELECT OBJECT(DL) FROM License DL");
entity.getNamedQuery().add(namedQuery);
final Id id = new Id();
id.setName("id");
entity.getAttributes().getId().add(id);
final Basic basic = new Basic();
basic.setName("name");
final Column column = new Column();
column.setName("wNAME");
column.setLength(300);
basic.setColumn(column);
entity.getAttributes().getBasic().add(basic);
entityMappings.getEntity().add(entity);
final AppModule module = new AppModule(this.getClass().getClassLoader(), f.getAbsolutePath());
final EjbModule ejbModule = new EjbModule(ejbJar);
ejbModule.getAltDDs().put("openejb-cmp-orm.xml", entityMappings);
module.getEjbModules().add(ejbModule);
assertNull(module.getCmpMappings());
assembler.createApplication(config.configureApplication(module));
assertNotNull(module.getCmpMappings());
final List<Basic> basicList = module.getCmpMappings().getEntityMap().get("openejb.org.apache.openejb.core.MyCmpBean").getAttributes().getBasic();
assertEquals(1, basicList.size());
assertEquals(300, basicList.get(0).getColumn().getLength().intValue());
assertEquals("wNAME", basicList.get(0).getColumn().getName());
}
Aggregations