Package org.hibernate.ejb.packaging

Examples of org.hibernate.ejb.packaging.PersistenceMetadata


/* 138 */     return units;
/*     */   }
/*     */
/*     */   private static PersistenceMetadata parsePersistenceUnit(Element top, PersistenceUnitTransactionType defaultTransactionType) throws Exception
/*     */   {
/* 143 */     PersistenceMetadata metadata = new PersistenceMetadata();
/* 144 */     String puName = top.getAttribute("name");
/* 145 */     if (StringHelper.isNotEmpty(puName)) {
/* 146 */       log.trace("Persistent Unit name from persistence.xml: " + puName);
/* 147 */       metadata.setName(puName);
/*     */     }
/* 149 */     PersistenceUnitTransactionType transactionType = getTransactionType(top.getAttribute("transaction-type"));
/*     */
/* 151 */     transactionType = transactionType != null ? transactionType : defaultTransactionType;
/* 152 */     metadata.setTransactionType(transactionType);
/* 153 */     NodeList children = top.getChildNodes();
/* 154 */     for (int i = 0; i < children.getLength(); i++) {
/* 155 */       if (children.item(i).getNodeType() == 1) {
/* 156 */         Element element = (Element)children.item(i);
/* 157 */         String tag = element.getTagName();
/*     */
/* 164 */         if (tag.equals("non-jta-data-source")) {
/* 165 */           metadata.setNonJtaDatasource(XmlHelper.getElementContent(element));
/*     */         }
/* 167 */         else if (tag.equals("jta-data-source")) {
/* 168 */           metadata.setJtaDatasource(XmlHelper.getElementContent(element));
/*     */         }
/* 170 */         else if (tag.equals("provider")) {
/* 171 */           metadata.setProvider(XmlHelper.getElementContent(element));
/*     */         }
/* 173 */         else if (tag.equals("class")) {
/* 174 */           metadata.getClasses().add(XmlHelper.getElementContent(element));
/*     */         }
/* 176 */         else if (tag.equals("mapping-file")) {
/* 177 */           metadata.getMappingFiles().add(XmlHelper.getElementContent(element));
/*     */         }
/* 179 */         else if (tag.equals("jar-file")) {
/* 180 */           metadata.getJarFiles().add(XmlHelper.getElementContent(element));
/*     */         }
/* 182 */         else if (tag.equals("exclude-unlisted-classes")) {
/* 183 */           metadata.setExcludeUnlistedClasses(true);
/*     */         }
/* 185 */         else if (tag.equals("properties")) {
/* 186 */           NodeList props = element.getChildNodes();
/* 187 */           for (int j = 0; j < props.getLength(); j++) {
/* 188 */             if (props.item(j).getNodeType() == 1) {
/* 189 */               Element propElement = (Element)props.item(j);
/* 190 */               if ("property".equals(propElement.getTagName())) {
/* 191 */                 String propName = propElement.getAttribute("name").trim();
/* 192 */                 String propValue = propElement.getAttribute("value").trim();
/* 193 */                 if (StringHelper.isEmpty(propValue))
/*     */                 {
/* 195 */                   propValue = XmlHelper.getElementContent(propElement, "");
/*     */                 }
/* 197 */                 metadata.getProps().put(propName, propValue);
/*     */               }
/*     */             }
/*     */           }
/*     */         }
/*     */       }
View Full Code Here


/* 147 */     return this.managedFactory;
/*     */   }
/*     */
/*     */   public void addDependencies(DependencyPolicy policy)
/*     */   {
/* 152 */     PersistenceMetadata legacy = this.metaData.getLegacyMetadata();
/* 153 */     Properties props = legacy.getProps();
/* 154 */     if (!props.containsKey("jboss.no.implicit.datasource.dependency"))
/*     */     {
/* 156 */       if (legacy.getJtaDatasource() != null)
/*     */       {
/* 158 */         String ds = legacy.getJtaDatasource();
/* 159 */         policy.addDatasource(ds);
/*     */       }
/* 161 */       if (legacy.getNonJtaDatasource() != null)
/*     */       {
/* 163 */         String ds = legacy.getNonJtaDatasource();
/* 164 */         policy.addDatasource(ds);
/*     */       }
/*     */     }
/* 167 */     for (Iterator i$ = props.keySet().iterator(); i$.hasNext(); ) { Object prop = i$.next();
/*     */
View Full Code Here

/*     */
/* 192 */     ArrayList jarFiles = new ArrayList();
/* 193 */     pi.setJarFiles(jarFiles);
/* 194 */     pi.setPersistenceProviderClassName(HibernatePersistence.class.getName());
/* 195 */     log.debug("Found persistence.xml file in EJB3 jar");
/* 196 */     PersistenceMetadata xml = this.metaData.getLegacyMetadata();
/* 197 */     props.putAll(xml.getProps());
/* 198 */     pi.setManagedClassnames(xml.getClasses());
/* 199 */     pi.setPersistenceUnitName(this.metaData.getName());
/* 200 */     pi.setMappingFileNames(xml.getMappingFiles());
/* 201 */     pi.setExcludeUnlistedClasses(xml.getExcludeUnlistedClasses());
/* 202 */     log.debug("Persistence root url " + this.metaData.getPersistenceUnitRootUrl());
/* 203 */     pi.setPersistenceUnitRootUrl(this.metaData.getPersistenceUnitRootUrl());
/*     */
/* 207 */     PersistenceUnitTransactionType transactionType = xml.getTransactionType();
/* 208 */     pi.setTransactionType(transactionType);
/*     */
/* 210 */     for (String jar : xml.getJarFiles())
/*     */     {
/* 212 */       jarFiles.add(this.deployment.getDeploymentUnit().getRelativeURL(jar));
/*     */     }
/*     */
/* 216 */     if (xml.getProvider() != null) pi.setPersistenceProviderClassName(xml.getProvider());
/* 217 */     if (this.explicitEntityClasses.size() > 0)
/*     */     {
/* 219 */       List classes = pi.getManagedClassNames();
/* 220 */       if (classes == null) classes = this.explicitEntityClasses; else
/* 221 */         classes.addAll(this.explicitEntityClasses);
/* 222 */       pi.setManagedClassnames(classes);
/*     */     }
/* 224 */     if (xml.getJtaDatasource() != null)
/*     */     {
/* 226 */       pi.setJtaDataSource((DataSource)this.initialContext.lookup(xml.getJtaDatasource()));
/*     */     }
/* 228 */     else if (transactionType == PersistenceUnitTransactionType.JTA)
/*     */     {
/* 230 */       throw new RuntimeException("Specification violation [EJB3 JPA 6.2.1.2] - You have not defined a jta-data-source for a JTA enabled persistence context named: " + this.metaData.getName());
/*     */     }
/*     */
/* 233 */     if (xml.getNonJtaDatasource() != null)
/*     */     {
/* 235 */       pi.setNonJtaDataSource((DataSource)this.initialContext.lookup(xml.getNonJtaDatasource()));
/*     */     }
/* 237 */     else if (transactionType == PersistenceUnitTransactionType.RESOURCE_LOCAL)
/*     */     {
/* 239 */       throw new RuntimeException("Specification violation [EJB3 JPA 6.2.1.2] - You have not defined a non-jta-data-source for a RESOURCE_LOCAL enabled persistence context named: " + this.metaData.getName());
/*     */     }
View Full Code Here

/*     */
/*     */   public void stop() throws Exception
/*     */   {
/* 279 */     log.info("Stopping persistence unit " + this.kernelName);
/*     */
/* 281 */     PersistenceMetadata xml = this.metaData.getLegacyMetadata();
/* 282 */     String entityManagerJndiName = (String)xml.getProps().get("jboss.entity.manager.jndi.name");
/* 283 */     if (entityManagerJndiName != null)
/*     */     {
/* 285 */       NonSerializableFactory.unbind(this.initialContext, entityManagerJndiName);
/*     */     }
/* 287 */     String entityManagerFactoryJndiName = (String)xml.getProps().get("jboss.entity.manager.factory.jndi.name");
/* 288 */     if (entityManagerFactoryJndiName != null)
/*     */     {
/* 290 */       NonSerializableFactory.unbind(this.initialContext, entityManagerFactoryJndiName);
/*     */     }
/* 292 */     this.managedFactory.destroy();
View Full Code Here

/*     */
/*     */     }
/*     */
/* 567 */     for (PersistenceUnitMetaData persistenceUnitMetaData : this.persistenceUnitsMetaData)
/*     */     {
/* 569 */       PersistenceMetadata metadata = persistenceUnitMetaData.getLegacyMetadata();
/*     */
/* 571 */       String earShortName = this.deploymentScope == null ? null : this.deploymentScope.getShortName();
/* 572 */       boolean isScoped = this.ejbContainers.size() > 0;
/*     */
/* 575 */       String cache_prefix = metadata.getProps().getProperty("hibernate.cache.region_prefix");
/* 576 */       if (cache_prefix == null)
/*     */       {
/* 580 */         String jarName = isScoped ? this.unit.getShortName() : null;
/* 581 */         cache_prefix = SecondLevelCacheUtil.createCacheRegionPrefix(earShortName, jarName, metadata.getName());
/* 582 */         metadata.getProps().setProperty("hibernate.cache.region_prefix", cache_prefix);
/*     */       }
/* 584 */       PersistenceUnitDeployment deployment = new PersistenceUnitDeployment(this.initialContext, this, this.explicitEntityClasses, persistenceUnitMetaData, earShortName, this.unit.getShortName(), isScoped);
/*     */
/* 586 */       PersistenceUnitRegistry.register(deployment);
/* 587 */       this.persistenceUnitDeployments.add(deployment);
View Full Code Here

      return managedFactory;
   }
  
   public void addDependencies(DependencyPolicy policy)
   {
      PersistenceMetadata legacy = metaData.getLegacyMetadata();
      Properties props = legacy.getProps();
      if (!props.containsKey("jboss.no.implicit.datasource.dependency"))
      {
         if (legacy.getJtaDatasource() != null)
         {
            String ds = legacy.getJtaDatasource();
            policy.addDatasource(ds);
         }
         if (legacy.getNonJtaDatasource() != null)
         {
            String ds = legacy.getNonJtaDatasource();
            policy.addDatasource(ds);
         }
      }
      for (Object prop : props.keySet())
      {
View Full Code Here

      ArrayList<URL> jarFiles = new ArrayList<URL>();
      pi.setJarFiles(jarFiles);
      pi.setPersistenceProviderClassName(HibernatePersistence.class.getName());
      log.debug("Found persistence.xml file in EJB3 jar");
      PersistenceMetadata xml = metaData.getLegacyMetadata();
      props.putAll(xml.getProps());
      pi.setManagedClassnames(xml.getClasses());
      pi.setPersistenceUnitName(metaData.getName());
      pi.setMappingFileNames(xml.getMappingFiles());
      pi.setExcludeUnlistedClasses(xml.getExcludeUnlistedClasses());
      log.debug("Persistence root url " + metaData.getPersistenceUnitRootUrl());
      pi.setPersistenceUnitRootUrl(metaData.getPersistenceUnitRootUrl());
//      PersistenceUnitTransactionType transactionType = PersistenceUnitTransactionType.JTA;
//      if ("RESOURCE_LOCAL".equals(xml.getTransactionType()))
//         transactionType = PersistenceUnitTransactionType.RESOURCE_LOCAL;
      PersistenceUnitTransactionType transactionType = xml.getTransactionType();
      pi.setTransactionType(transactionType);

      for (String jar : xml.getJarFiles())
      {
         jarFiles.add(deployment.getDeploymentUnit().getRelativeURL(jar));
      }


      if (xml.getProvider() != null) pi.setPersistenceProviderClassName(xml.getProvider());
      if (explicitEntityClasses.size() > 0)
      {
         List<String> classes = pi.getManagedClassNames();
         if (classes == null) classes = explicitEntityClasses;
         else classes.addAll(explicitEntityClasses);
         pi.setManagedClassnames(classes);
      }
      if (xml.getJtaDatasource() != null)
      {
         pi.setJtaDataSource((javax.sql.DataSource) initialContext.lookup(xml.getJtaDatasource()));
      }
      else if (transactionType == PersistenceUnitTransactionType.JTA)
      {
         throw new RuntimeException("Specification violation [EJB3 JPA 6.2.1.2] - "
               + "You have not defined a jta-data-source for a JTA enabled persistence context named: " + metaData.getName());
      }
      if (xml.getNonJtaDatasource() != null)
      {
         pi.setNonJtaDataSource((javax.sql.DataSource) initialContext.lookup(xml.getNonJtaDatasource()));
      }
      else if (transactionType == PersistenceUnitTransactionType.RESOURCE_LOCAL)
      {
         throw new RuntimeException("Specification violation [EJB3 JPA 6.2.1.2] - "
               + "You have not defined a non-jta-data-source for a RESOURCE_LOCAL enabled persistence context named: "
View Full Code Here

   public void stop() throws Exception
   {
      log.info("Stopping persistence unit " + kernelName);
     
      PersistenceMetadata xml = metaData.getLegacyMetadata();
      String entityManagerJndiName = (String) xml.getProps().get("jboss.entity.manager.jndi.name");
      if (entityManagerJndiName != null)
      {
         NonSerializableFactory.unbind(initialContext, entityManagerJndiName);
      }
      String entityManagerFactoryJndiName = (String) xml.getProps().get("jboss.entity.manager.factory.jndi.name");
      if (entityManagerFactoryJndiName != null)
      {
         NonSerializableFactory.unbind(initialContext, entityManagerFactoryJndiName);
      }
      managedFactory.destroy();
View Full Code Here

      // scope the unitName if this is an ejb archive
      // todo revert to this: List<PersistenceMetadata> persistenceMetadata = PersistenceXmlLoader.deploy(persistenceXmlUrl, new HashMap(), new EJB3DTDEntityResolver());
      for (PersistenceUnitMetaData persistenceUnitMetaData : persistenceUnitsMetaData)
      {
         PersistenceMetadata metadata = persistenceUnitMetaData.getLegacyMetadata();
        
         String earShortName = deploymentScope == null ? null : deploymentScope.getShortName();
         boolean isScoped = ejbContainers.size() > 0;

         // Ensure 2nd level cache entries are segregated from other deployments
         String cache_prefix = metadata.getProps().getProperty(SecondLevelCacheUtil.HIBERNATE_CACHE_REGION_PREFIX);
         if (cache_prefix == null)
         {
            // Create a region_prefix for the 2nd level cache to ensure
            // deployments are segregated
            String jarName = isScoped ? unit.getShortName() : null;
            cache_prefix = SecondLevelCacheUtil.createCacheRegionPrefix(earShortName, jarName, metadata.getName());
            metadata.getProps().setProperty(SecondLevelCacheUtil.HIBERNATE_CACHE_REGION_PREFIX, cache_prefix);
         }
         PersistenceUnitDeployment deployment = new PersistenceUnitDeployment(initialContext, this,
               explicitEntityClasses, persistenceUnitMetaData, earShortName, unit.getShortName(), isScoped);
         PersistenceUnitRegistry.register(deployment);
         persistenceUnitDeployments.add(deployment);
View Full Code Here

TOP

Related Classes of org.hibernate.ejb.packaging.PersistenceMetadata

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.