Package org.hibernate.ejb.packaging

Examples of org.hibernate.ejb.packaging.PersistenceMetadata


    }
  }

  public void testStandaloneBootstrapSharedCacheMode() {
    // first, via the integration vars
    PersistenceMetadata metadata = new PersistenceMetadata();
    {
      // as object
      Ejb3Configuration cfg = new Ejb3Configuration();
      Ejb3Configuration configured = cfg.configure(
          metadata,
          Collections.singletonMap( AvailableSettings.SHARED_CACHE_MODE, SharedCacheMode.DISABLE_SELECTIVE )
      );
      assertEquals( SharedCacheMode.DISABLE_SELECTIVE.name(), configured.getProperties().get( AvailableSettings.SHARED_CACHE_MODE ) );
    }
    {
      // as string
      Ejb3Configuration cfg = new Ejb3Configuration();
      Ejb3Configuration configured = cfg.configure(
          metadata,
          Collections.singletonMap( AvailableSettings.SHARED_CACHE_MODE, SharedCacheMode.DISABLE_SELECTIVE.name() )
      );
      assertEquals( SharedCacheMode.DISABLE_SELECTIVE.name(), configured.getProperties().get( AvailableSettings.SHARED_CACHE_MODE ) );
    }

    // next, via the PM
    metadata.setSharedCacheMode( SharedCacheMode.ENABLE_SELECTIVE.name() );
    {
      Ejb3Configuration cfg = new Ejb3Configuration();
      Ejb3Configuration configured = cfg.configure( metadata, null );
      assertEquals( SharedCacheMode.ENABLE_SELECTIVE.name(), configured.getProperties().get( AvailableSettings.SHARED_CACHE_MODE ) );
    }
View Full Code Here


    }
  }

  public void testStandaloneBootstrapValidationMode() {
    // first, via the integration vars
    PersistenceMetadata metadata = new PersistenceMetadata();
    {
      // as object
      Ejb3Configuration cfg = new Ejb3Configuration();
      Ejb3Configuration configured = cfg.configure(
          metadata,
          Collections.singletonMap( AvailableSettings.VALIDATION_MODE, ValidationMode.CALLBACK )
      );
      assertEquals( ValidationMode.CALLBACK.name(), configured.getProperties().get( AvailableSettings.VALIDATION_MODE ) );
    }
    {
      // as string
      Ejb3Configuration cfg = new Ejb3Configuration();
      Ejb3Configuration configured = cfg.configure(
          metadata,
          Collections.singletonMap( AvailableSettings.VALIDATION_MODE, ValidationMode.CALLBACK.name() )
      );
      assertEquals( ValidationMode.CALLBACK.name(), configured.getProperties().get( AvailableSettings.VALIDATION_MODE ) );
    }

    // next, via the PUI
    metadata.setValidationMode( ValidationMode.AUTO.name() );
    {
      Ejb3Configuration cfg = new Ejb3Configuration();
      Ejb3Configuration configured = cfg.configure( metadata, null );
      assertEquals( ValidationMode.AUTO.name(), configured.getProperties().get( AvailableSettings.VALIDATION_MODE ) );
    }
View Full Code Here

    }
  }

  public void testStandaloneBootstrapValidationFactory() {
    final Object token = new Object();
    PersistenceMetadata metadata = new PersistenceMetadata();
    Ejb3Configuration cfg = new Ejb3Configuration();
    try {
      cfg.configure(
          metadata,
          Collections.singletonMap( AvailableSettings.VALIDATION_FACTORY, token )
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

    for ( int i = 0; i < children.getLength() ; i++ ) {
      if ( children.item( i ).getNodeType() == Node.ELEMENT_NODE ) {
        Element element = (Element) children.item( i );
        String tag = element.getTagName();
        if ( tag.equals( "persistence-unit" ) ) {
          PersistenceMetadata metadata = parsePersistenceUnit( element, defaultTransactionType);
          //override properties of metadata if needed
          String provider = (String) overrides.get( HibernatePersistence.PROVIDER );
          if ( provider != null ) {
            metadata.setProvider( provider );
          }
          String transactionType = (String) overrides.get( HibernatePersistence.TRANSACTION_TYPE );
          if ( StringHelper.isNotEmpty( transactionType ) ) {
            metadata.setTransactionType( getTransactionType( transactionType ) );
          }
          String dataSource = (String) overrides.get( HibernatePersistence.JTA_DATASOURCE );
          if ( dataSource != null ) {
            metadata.setJtaDatasource( dataSource );
          }
          dataSource = (String) overrides.get( HibernatePersistence.NON_JTA_DATASOURCE );
          if ( dataSource != null ) {
            metadata.setNonJtaDatasource( dataSource );
          }
          Properties properties = metadata.getProps();
          ConfigurationHelper.overrideProperties( properties, overrides );
          units.add( metadata );
        }
      }
    }
View Full Code Here

    return units;
  }

  private static PersistenceMetadata parsePersistenceUnit(Element top, PersistenceUnitTransactionType defaultTransactionType)
      throws Exception {
    PersistenceMetadata metadata = new PersistenceMetadata();
    String puName = top.getAttribute( "name" );
    if ( StringHelper.isNotEmpty( puName ) ) {
      log.trace( "Persistent Unit name from persistence.xml: " + puName );
      metadata.setName( puName );
    }
    PersistenceUnitTransactionType transactionType = getTransactionType( top.getAttribute( "transaction-type" ) );
    //parsing a persistence.xml means we are in a JavaSE environment
    transactionType = transactionType != null ? transactionType : defaultTransactionType;
    metadata.setTransactionType( transactionType );
    NodeList children = top.getChildNodes();
    for ( int i = 0; i < children.getLength() ; i++ ) {
      if ( children.item( i ).getNodeType() == Node.ELEMENT_NODE ) {
        Element element = (Element) children.item( i );
        String tag = element.getTagName();
//        if ( tag.equals( "name" ) ) {
//          String puName = XmlHelper.getElementContent( element );
//          log.trace( "FOUND PU NAME: " + puName );
//          metadata.setName( puName );
//        }
//        else
        if ( tag.equals( "non-jta-data-source" ) ) {
          metadata.setNonJtaDatasource( XmlHelper.getElementContent( element ) );
        }
        else if ( tag.equals( "jta-data-source" ) ) {
          metadata.setJtaDatasource( XmlHelper.getElementContent( element ) );
        }
        else if ( tag.equals( "provider" ) ) {
          metadata.setProvider( XmlHelper.getElementContent( element ) );
        }
        else if ( tag.equals( "class" ) ) {
          metadata.getClasses().add( XmlHelper.getElementContent( element ) );
        }
        else if ( tag.equals( "mapping-file" ) ) {
          metadata.getMappingFiles().add( XmlHelper.getElementContent( element ) );
        }
        else if ( tag.equals( "jar-file" ) ) {
          metadata.getJarFiles().add( XmlHelper.getElementContent( element ) );
        }
        else if ( tag.equals( "exclude-unlisted-classes" ) ) {
          metadata.setExcludeUnlistedClasses( true );
        }
        else if ( tag.equals( "properties" ) ) {
          NodeList props = element.getChildNodes();
          for ( int j = 0; j < props.getLength() ; j++ ) {
            if ( props.item( j ).getNodeType() == Node.ELEMENT_NODE ) {
              Element propElement = (Element) props.item( j );
              if ( !"property".equals( propElement.getTagName() ) ) continue;
              String propName = propElement.getAttribute( "name" ).trim();
              String propValue = propElement.getAttribute( "value" ).trim();
              if ( StringHelper.isEmpty( propValue ) ) {
                //fall back to the natural (Hibernate) way of description
                propValue = XmlHelper.getElementContent( propElement, "" );
              }
              metadata.getProps().put( propName, propValue );
            }
          }

        }
      }
View Full Code Here

    for ( int i = 0; i < children.getLength() ; i++ ) {
      if ( children.item( i ).getNodeType() == Node.ELEMENT_NODE ) {
        Element element = (Element) children.item( i );
        String tag = element.getTagName();
        if ( tag.equals( "persistence-unit" ) ) {
          PersistenceMetadata metadata = parsePersistenceUnit( element, defaultTransactionType);
          //override properties of metadata if needed
          String provider = (String) overrides.get( HibernatePersistence.PROVIDER );
          if ( provider != null ) {
            metadata.setProvider( provider );
          }
          String transactionType = (String) overrides.get( HibernatePersistence.TRANSACTION_TYPE );
          if ( StringHelper.isNotEmpty( transactionType ) ) {
            metadata.setTransactionType( getTransactionType( transactionType ) );
          }
          String dataSource = (String) overrides.get( HibernatePersistence.JTA_DATASOURCE );
          if ( dataSource != null ) {
            metadata.setJtaDatasource( dataSource );
          }
          dataSource = (String) overrides.get( HibernatePersistence.NON_JTA_DATASOURCE );
          if ( dataSource != null ) {
            metadata.setNonJtaDatasource( dataSource );
          }
          Properties properties = metadata.getProps();
          ConfigurationHelper.overrideProperties( properties, overrides );
          units.add( metadata );
        }
      }
    }
View Full Code Here

    return units;
  }

  private static PersistenceMetadata parsePersistenceUnit(Element top, PersistenceUnitTransactionType defaultTransactionType)
      throws Exception {
    PersistenceMetadata metadata = new PersistenceMetadata();
    String puName = top.getAttribute( "name" );
    if ( StringHelper.isNotEmpty( puName ) ) {
      log.trace( "Persistent Unit name from persistence.xml: " + puName );
      metadata.setName( puName );
    }
    PersistenceUnitTransactionType transactionType = getTransactionType( top.getAttribute( "transaction-type" ) );
    //parsing a persistence.xml means we are in a JavaSE environment
    transactionType = transactionType != null ? transactionType : defaultTransactionType;
    metadata.setTransactionType( transactionType );
    NodeList children = top.getChildNodes();
    for ( int i = 0; i < children.getLength() ; i++ ) {
      if ( children.item( i ).getNodeType() == Node.ELEMENT_NODE ) {
        Element element = (Element) children.item( i );
        String tag = element.getTagName();
//        if ( tag.equals( "name" ) ) {
//          String puName = XmlHelper.getElementContent( element );
//          log.trace( "FOUND PU NAME: " + puName );
//          metadata.setName( puName );
//        }
//        else
        if ( tag.equals( "non-jta-data-source" ) ) {
          metadata.setNonJtaDatasource( XmlHelper.getElementContent( element ) );
        }
        else if ( tag.equals( "jta-data-source" ) ) {
          metadata.setJtaDatasource( XmlHelper.getElementContent( element ) );
        }
        else if ( tag.equals( "provider" ) ) {
          metadata.setProvider( XmlHelper.getElementContent( element ) );
        }
        else if ( tag.equals( "class" ) ) {
          metadata.getClasses().add( XmlHelper.getElementContent( element ) );
        }
        else if ( tag.equals( "mapping-file" ) ) {
          metadata.getMappingFiles().add( XmlHelper.getElementContent( element ) );
        }
        else if ( tag.equals( "jar-file" ) ) {
          metadata.getJarFiles().add( XmlHelper.getElementContent( element ) );
        }
        else if ( tag.equals( "exclude-unlisted-classes" ) ) {
          metadata.setExcludeUnlistedClasses( true );
        }
        else if ( tag.equals( "properties" ) ) {
          NodeList props = element.getChildNodes();
          for ( int j = 0; j < props.getLength() ; j++ ) {
            if ( props.item( j ).getNodeType() == Node.ELEMENT_NODE ) {
              Element propElement = (Element) props.item( j );
              if ( !"property".equals( propElement.getTagName() ) ) continue;
              String propName = propElement.getAttribute( "name" ).trim();
              String propValue = propElement.getAttribute( "value" ).trim();
              if ( StringHelper.isEmpty( propValue ) ) {
                //fall back to the natural (Hibernate) way of description
                propValue = XmlHelper.getElementContent( propElement, "" );
              }
              metadata.getProps().put( propName, propValue );
            }
          }

        }
      }
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

/* 108 */     for (int i = 0; i < children.getLength(); i++) {
/* 109 */       if (children.item(i).getNodeType() == 1) {
/* 110 */         Element element = (Element)children.item(i);
/* 111 */         String tag = element.getTagName();
/* 112 */         if (tag.equals("persistence-unit")) {
/* 113 */           PersistenceMetadata metadata = parsePersistenceUnit(element, defaultTransactionType);
/*     */
/* 115 */           String provider = (String)overrides.get("javax.persistence.provider");
/* 116 */           if (provider != null) {
/* 117 */             metadata.setProvider(provider);
/*     */           }
/* 119 */           String transactionType = (String)overrides.get("javax.persistence.transactionType");
/* 120 */           if (StringHelper.isNotEmpty(transactionType)) {
/* 121 */             metadata.setTransactionType(getTransactionType(transactionType));
/*     */           }
/* 123 */           String dataSource = (String)overrides.get("javax.persistence.jtaDataSource");
/* 124 */           if (dataSource != null) {
/* 125 */             metadata.setJtaDatasource(dataSource);
/*     */           }
/* 127 */           dataSource = (String)overrides.get("javax.persistence.nonJtaDataSource");
/* 128 */           if (dataSource != null) {
/* 129 */             metadata.setNonJtaDatasource(dataSource);
/*     */           }
/* 131 */           Properties properties = metadata.getProps();
/* 132 */           ConfigurationHelper.overrideProperties(properties, overrides);
/* 133 */           units.add(metadata);
/*     */         }
/*     */       }
/*     */     }
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.