use of org.apache.openejb.jee.EntityBean 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<String>();
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<String, String>();
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 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.EntityBean 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 (int i = 0; i < homeMethods.length; i++) {
if (!homeMethods[i].getName().startsWith("create")) {
continue;
}
final Method create = homeMethods[i];
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 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 in project tomee by apache.
the class SunConversion method mergeEntityMappings.
private void mergeEntityMappings(final Map<String, EntityData> entities, final String moduleId, final EjbJar ejbJar, final OpenejbJar openejbJar, final SunEjbJar sunEjbJar) {
if (openejbJar == null) {
return;
}
if (sunEjbJar == null) {
return;
}
if (sunEjbJar.getEnterpriseBeans() == null) {
return;
}
for (final Ejb ejb : sunEjbJar.getEnterpriseBeans().getEjb()) {
final Cmp cmp = ejb.getCmp();
if (cmp == null) {
// skip non cmp beans
continue;
}
// skip all non-CMP beans
final EnterpriseBean enterpriseBean = ejbJar.getEnterpriseBean(ejb.getEjbName());
if (!(enterpriseBean instanceof EntityBean) || ((EntityBean) enterpriseBean).getPersistenceType() != PersistenceType.CONTAINER) {
continue;
}
final EntityBean bean = (EntityBean) enterpriseBean;
final EntityData entityData = entities.get(moduleId + "#" + ejb.getEjbName());
if (entityData == null) {
// todo warn no such ejb in the ejb-jar.xml
continue;
}
final Collection<String> cmpFields = new ArrayList<String>(bean.getCmpField().size());
for (final CmpField cmpField : bean.getCmpField()) {
cmpFields.add(cmpField.getFieldName());
}
final OneOneFinders oneOneFinders = cmp.getOneOneFinders();
if (oneOneFinders != null) {
for (final Finder finder : oneOneFinders.getFinder()) {
final List<List<String>> params = parseQueryParamters(finder.getQueryParams());
final String queryFilter = finder.getQueryFilter();
final String ejbQl = convertToEjbQl(entityData.entity.getName(), cmpFields, finder.getQueryParams(), queryFilter);
final NamedQuery namedQuery = new NamedQuery();
final StringBuilder name = new StringBuilder();
name.append(entityData.entity.getName()).append(".").append(finder.getMethodName());
if (!params.isEmpty()) {
name.append('(');
boolean first = true;
for (final List<String> methodParam : params) {
if (!first) {
name.append(",");
}
name.append(methodParam.get(0));
first = false;
}
name.append(')');
}
namedQuery.setName(name.toString());
namedQuery.setQuery(ejbQl);
entityData.entity.getNamedQuery().add(namedQuery);
}
}
}
}
Aggregations