use of org.apache.openejb.assembler.classic.PersistenceContextReferenceInfo in project tomee by apache.
the class TomcatJndiBuilder method mergeJndi.
public void mergeJndi() throws OpenEJBException {
final NamingResourcesImpl naming = standardContext.getNamingResources();
final URI moduleUri = URLs.uri(webAppInfo.moduleId);
for (final EnvEntryInfo ref : webAppInfo.jndiEnc.envEntries) {
mergeRef(naming, ref);
}
for (final EjbReferenceInfo ref : webAppInfo.jndiEnc.ejbReferences) {
mergeRef(naming, ref);
}
for (final EjbLocalReferenceInfo ref : webAppInfo.jndiEnc.ejbLocalReferences) {
mergeRef(naming, ref);
}
for (final PersistenceContextReferenceInfo ref : webAppInfo.jndiEnc.persistenceContextRefs) {
mergeRef(naming, ref, moduleUri);
}
for (final PersistenceUnitReferenceInfo ref : webAppInfo.jndiEnc.persistenceUnitRefs) {
mergeRef(naming, ref, moduleUri);
}
for (final ResourceReferenceInfo ref : webAppInfo.jndiEnc.resourceRefs) {
mergeRef(naming, ref);
}
for (final ResourceEnvReferenceInfo ref : webAppInfo.jndiEnc.resourceEnvRefs) {
mergeRef(naming, ref);
}
for (final ServiceReferenceInfo ref : webAppInfo.jndiEnc.serviceRefs) {
mergeRef(naming, ref);
}
final ContextTransaction contextTransaction = new ContextTransaction();
contextTransaction.setProperty(Constants.FACTORY, UserTransactionFactory.class.getName());
naming.setTransaction(contextTransaction);
}
use of org.apache.openejb.assembler.classic.PersistenceContextReferenceInfo in project aries by apache.
the class RunningApplication method removedService.
public void removedService(ServiceReference reference, Object service) {
Map<Context, PersistenceUnitReferenceInfo> pUnitRefs = unitRegistrations.get(reference.getProperty(PersistenceUnitConstants.OSGI_UNIT_NAME));
Map<Context, PersistenceContextReferenceInfo> pCtxRefs = contextRegistrations.get(reference.getProperty(PersistenceUnitConstants.OSGI_UNIT_NAME));
if (pUnitRefs == null) {
pUnitRefs = new HashMap<Context, PersistenceUnitReferenceInfo>();
}
if (pCtxRefs == null) {
pCtxRefs = new HashMap<Context, PersistenceContextReferenceInfo>();
}
if (pUnitRefs.size() > 0 || pCtxRefs.size() > 0) {
for (Entry<Context, PersistenceUnitReferenceInfo> e : pUnitRefs.entrySet()) {
try {
e.getKey().unbind(e.getValue().referenceName);
} catch (NamingException ex) {
// TODO Auto-generated catch block
ex.printStackTrace();
}
}
for (Entry<Context, PersistenceContextReferenceInfo> e : pCtxRefs.entrySet()) {
PersistenceContextReferenceInfo pci = e.getValue();
try {
e.getKey().unbind(pci.referenceName);
} catch (NamingException ex) {
// TODO Auto-generated catch block
ex.printStackTrace();
}
}
}
}
use of org.apache.openejb.assembler.classic.PersistenceContextReferenceInfo in project aries by apache.
the class RunningApplication method addingService.
public Object addingService(ServiceReference reference) {
if (isTrue(reference, PersistenceUnitConstants.CONTAINER_MANAGED_PERSISTENCE_UNIT) && !!!isTrue(reference, PersistenceContextProvider.PROXY_FACTORY_EMF_ATTRIBUTE)) {
Map<Context, PersistenceUnitReferenceInfo> pUnitRefs = unitRegistrations.get(reference.getProperty(PersistenceUnitConstants.OSGI_UNIT_NAME));
Map<Context, PersistenceContextReferenceInfo> pCtxRefs = contextRegistrations.get(reference.getProperty(PersistenceUnitConstants.OSGI_UNIT_NAME));
if (pUnitRefs == null) {
pUnitRefs = new HashMap<Context, PersistenceUnitReferenceInfo>();
}
if (pCtxRefs == null) {
pCtxRefs = new HashMap<Context, PersistenceContextReferenceInfo>();
}
if (pUnitRefs.size() > 0 || pCtxRefs.size() > 0) {
EntityManagerFactory emf = (EntityManagerFactory) bundle.getBundleContext().getService(reference);
for (Entry<Context, PersistenceUnitReferenceInfo> e : pUnitRefs.entrySet()) {
try {
e.getKey().bind(e.getValue().referenceName, emf);
} catch (NamingException ex) {
// TODO Auto-generated catch block
ex.printStackTrace();
}
}
for (Entry<Context, PersistenceContextReferenceInfo> e : pCtxRefs.entrySet()) {
PersistenceContextReferenceInfo pci = e.getValue();
try {
e.getKey().bind(pci.referenceName, new JtaEntityManager((String) reference.getProperty(PersistenceUnitConstants.OSGI_UNIT_NAME), AriesPersistenceContextIntegration.get(), emf, pci.properties, pci.extended));
} catch (NamingException ex) {
// TODO Auto-generated catch block
ex.printStackTrace();
}
}
return emf;
}
}
return null;
}
use of org.apache.openejb.assembler.classic.PersistenceContextReferenceInfo in project aries by apache.
the class EJBExtender method processJPAMappings.
private void processJPAMappings(EjbJarInfo ejbInfo) {
for (EnterpriseBeanInfo ebi : ejbInfo.enterpriseBeans) {
for (PersistenceUnitReferenceInfo pui : ebi.jndiEnc.persistenceUnitRefs) {
pui.location = new ReferenceLocationInfo();
pui.location.jndiName = "aries/integration/unit/" + pui.persistenceUnitName;
}
for (PersistenceContextReferenceInfo pci : ebi.jndiEnc.persistenceContextRefs) {
pci.location = new ReferenceLocationInfo();
pci.location.jndiName = "aries/integration/context/" + pci.persistenceUnitName;
}
}
}
use of org.apache.openejb.assembler.classic.PersistenceContextReferenceInfo in project tomee by apache.
the class XmlOverridesTest method test.
public void test() throws Exception {
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();
final StatefulBean bean = ejbJar.addEnterpriseBean(new StatefulBean(AnnotatedBean.class));
bean.getEjbLocalRef().add(new EjbLocalRef(name("annotatedLocal"), "BarBean"));
bean.getEnvEntry().add(new EnvEntry(name("striing"), "java.lang.Integer", "2"));
bean.getEnvEntry().add(new EnvEntry(name("doouble"), "java.lang.String", "two"));
bean.getEnvEntry().add(new EnvEntry(name("loong"), "java.lang.String", "three"));
bean.getEnvEntry().add(new EnvEntry(name("flooat"), "java.lang.String", "four"));
bean.getEnvEntry().add(new EnvEntry(name("inteeger"), "java.lang.String", "five"));
bean.getEnvEntry().add(new EnvEntry(name("shoort"), "java.lang.String", "six"));
bean.getEnvEntry().add(new EnvEntry(name("booolean"), "java.lang.String", "seven"));
bean.getEnvEntry().add(new EnvEntry(name("byyte"), "java.lang.String", "eight"));
bean.getEnvEntry().add(new EnvEntry(name("chaaracter"), "java.lang.String", "nine"));
final EnvEntry lookupEntry = new EnvEntry(name("lookup"), "java.lang.String", null);
lookupEntry.setLookupName("java:app/AppName");
bean.getEnvEntry().add(lookupEntry);
bean.getResourceRef().add(new ResourceRef(name("daataSource"), DataSource.class.getName(), ResAuth.CONTAINER, ResSharingScope.SHAREABLE));
bean.getPersistenceUnitRef().add(new PersistenceUnitRef(name("emf"), "yellow"));
bean.getPersistenceContextRef().add(new PersistenceContextRef(name("em"), "yellow", PersistenceContextType.TRANSACTION, new ArrayList(Arrays.asList(new Property("zzzz", "AAAA")))));
final org.apache.openejb.jee.jpa.unit.PersistenceUnit persistenceUnit = new org.apache.openejb.jee.jpa.unit.PersistenceUnit("yellow");
final AppModule app = new AppModule(this.getClass().getClassLoader(), "app");
app.getEjbModules().add(new EjbModule(ejbJar));
app.addPersistenceModule(new PersistenceModule("root", new Persistence(persistenceUnit)));
final AppInfo appInfo = config.configureApplication(app);
final EjbJarInfo ejbJarInfo = appInfo.ejbJars.get(0);
final EnterpriseBeanInfo beanInfo = ejbJarInfo.enterpriseBeans.get(0);
final JndiEncInfo enc = beanInfo.jndiEnc;
assertEquals("Enc.ejbLocalReferences.size()", 1, enc.ejbLocalReferences.size());
assertEquals("Enc.ejbLocalReferences.get(0).link", "BarBean", enc.ejbLocalReferences.get(0).link);
assertEquals("Enc.ejbReferences.size()", 0, enc.ejbReferences.size());
// 10 + ComponentName
assertEquals("Enc.envEntries.size()", 11, enc.envEntries.size());
final Map<String, EnvEntryInfo> entries = map(enc.envEntries);
assertEnvEntry(entries, name("striing"), "java.lang.Integer", "2");
assertEnvEntry(entries, name("doouble"), "java.lang.String", "two");
assertEnvEntry(entries, name("loong"), "java.lang.String", "three");
assertEnvEntry(entries, name("flooat"), "java.lang.String", "four");
assertEnvEntry(entries, name("inteeger"), "java.lang.String", "five");
assertEnvEntry(entries, name("shoort"), "java.lang.String", "six");
assertEnvEntry(entries, name("booolean"), "java.lang.String", "seven");
assertEnvEntry(entries, name("byyte"), "java.lang.String", "eight");
assertEnvEntry(entries, name("chaaracter"), "java.lang.String", "nine");
assertEnvEntryLookup(entries, name("lookup"), "java.lang.String", "java:app/AppName");
assertEquals("Enc.persistenceContextRefs.size()", 1, enc.persistenceContextRefs.size());
final PersistenceContextReferenceInfo context = enc.persistenceContextRefs.get(0);
assertEquals("Context.extended", false, context.extended);
assertEquals("Context.persistenceUnitName", "yellow", context.persistenceUnitName);
assertEquals("Context.properties.size()", 1, context.properties.size());
assertEquals("Context.properties.getProperty(\"zzzz\")", "AAAA", context.properties.getProperty("zzzz"));
assertEquals("Enc.persistenceUnitRefs.size()", 1, enc.persistenceUnitRefs.size());
final PersistenceUnitReferenceInfo unit = enc.persistenceUnitRefs.get(0);
assertEquals("Unit.persistenceUnitName", "yellow", unit.persistenceUnitName);
assertEquals("Enc.resourceRefs.size()", 1, enc.resourceRefs.size());
final ResourceReferenceInfo resource = enc.resourceRefs.get(0);
assertEquals("Resource.referenceAuth", "CONTAINER", resource.referenceAuth);
}
Aggregations