/** * Adds a persistence unit reference configuration. * * @param \AppserverIo\Psr\EnterpriseBeans\Description\PersistenceUnitReferenceDescriptorInterface $persistenceUnitReference The persistence unit reference configuration * * @return void */ public function addPersistenceUnitReference(PersistenceUnitReferenceDescriptorInterface $persistenceUnitReference) { $this->persistenceUnitReferences[$persistenceUnitReference->getName()] = $persistenceUnitReference; }
/** * Registers the passed persistence unit reference in the applications directory. * * @param \AppserverIo\Psr\EnterpriseBeans\Description\PersistenceUnitReferenceDescriptorInterface $persistenceUnitReference The persistence unit reference to register * * @return void */ public function registerPersistenceUnitReference(PersistenceUnitReferenceDescriptorInterface $persistenceUnitReference) { try { // load the application instance and reference name $application = $this->getApplication(); // initialize the persistence unit URI $uri = sprintf('php:global/%s/%s', $application->getName(), $persistenceUnitReference->getName()); // query whether the reference has already been bound to the application if ($application->getNamingDirectory()->search($uri)) { // log a message that the reference has already been bound $application->getInitialContext()->getSystemLogger()->info(sprintf('Persistence unit reference %s has already been bound to naming directory', $uri)); // return immediately return; } // catch the NamingException if the ref name is not bound yet } catch (NamingException $e) { // log a message that we've to register the resource reference now $application->getInitialContext()->getSystemLogger()->info(sprintf('Persistence unit reference %s has not been bound to naming directory', $uri)); } try { // try to use the unit name to bind the reference to if ($unitName = $persistenceUnitReference->getUnitName()) { // create a reference to a persistence unit in the global directory $application->getNamingDirectory()->bindReference($uri, sprintf('php:global/%s/%s', $application->getName(), $unitName)); // log a critical message that we can't bind the reference } else { $application->getInitialContext()->getSystemLogger()->critical(sprintf('Can\'t bind persistence unit Reference %s to naming directory, because of missing unit name definition', $uri)); } // catch all other exceptions } catch (\Exception $e) { $application->getInitialContext()->getSystemLogger()->critical($e->__toString()); } }
/** * Merges the passed configuration into this one. Configuration values * of the passed configuration will overwrite the this one. * * @param \AppserverIo\Psr\EnterpriseBeans\Description\PersistenceUnitReferenceDescriptorInterface $persistenceUnitReferenceDescriptor The configuration to merge * * @return void */ public function merge(PersistenceUnitReferenceDescriptorInterface $persistenceUnitReferenceDescriptor) { // merge the reference name if ($name = $persistenceUnitReferenceDescriptor->getName()) { $this->setName($name); } // merge the persistence unit name if ($unitName = $persistenceUnitReferenceDescriptor->getUnitName()) { $this->setUnitName($unitName); } // merge the injection target if ($injectionTarget = $persistenceUnitReferenceDescriptor->getInjectionTarget()) { $this->setInjectionTarget($injectionTarget); } }