Java 类org.hibernate.jpa.boot.spi.PersistenceUnitDescriptor 实例源码

项目:lightmare    文件:HibernatePersistenceProviderExt.java   
@Override
   @SuppressWarnings("rawtypes")
   protected EntityManagerFactoryBuilder getEntityManagerFactoryBuilderOrNull(String persistenceUnitName,
    Map properties, ClassLoader providedClassLoader) {

EntityManagerFactoryBuilder builder;

LOG.tracef("Attempting to obtain correct EntityManagerFactoryBuilder for persistenceUnitName : %s",
    persistenceUnitName);

final Map integration = wrap(properties);
PersistenceUnitDescriptor persistenceUnit = getPersistenceXmlDescriptor(persistenceUnitName, properties,
    providedClassLoader);
if (persistenceUnit == null) {
    LOG.debug("Found no matching persistence units");
    builder = null;
} else {
    builder = Bootstrap.getEntityManagerFactoryBuilder(persistenceUnit, integration, providedClassLoader);
}

return builder;
   }
项目:carbon    文件:HibernateConfiguration.java   
@Component
public EntityManagerFactory entityManagerFactory () {
    PersistenceUnitInfo persistenceUnitInfo = persistenceUnitInfo();
    PersistenceUnitDescriptor descriptor = new PersistenceUnitInfoDescriptor(persistenceUnitInfo);
    EntityManagerFactoryBuilder entityManagerFactoryBuilder = new EntityManagerFactoryBuilderImpl(descriptor, null);
    return entityManagerFactoryBuilder.build();
}
项目:lightmare    文件:HibernatePersistenceProviderExt.java   
/**
    * Enriches and configures passed {@link PersistenceUnitInfo} wrapper
    *
    * @param info
    * @return {@link PersistenceUnitDescriptor}
    */
   protected PersistenceUnitDescriptor getPersistenceUnitDescriptor(PersistenceUnitInfo info) {

PersistenceUnitDescriptor descriptor = new PersistenceUnitSwapDescriptor(info);
PersistenceDescriptorUtils.resolve(descriptor, metaConfig);

return descriptor;
   }
项目:lightmare    文件:HibernatePersistenceProviderExt.java   
/**
    * {@inheritDoc}
    * <p/>
    * Improved with transaction and data source swapping properties
    */
   @SuppressWarnings("rawtypes")
   @Override
   public EntityManagerFactory createContainerEntityManagerFactory(PersistenceUnitInfo info, Map properties) {

EntityManagerFactory emf;

LOG.tracef("Starting createContainerEntityManagerFactory : %s", info.getPersistenceUnitName());

PersistenceUnitDescriptor descriptor = getPersistenceUnitDescriptor(info);
emf = Bootstrap.getEntityManagerFactoryBuilder(descriptor, properties).build();

return emf;
   }
项目:lightmare    文件:HibernatePersistenceProviderExt.java   
/**
    * Generates schema from {@link PersistenceUnitInfo} instance
    */
   @SuppressWarnings("rawtypes")
   @Override
   public void generateSchema(PersistenceUnitInfo info, Map map) {
LOG.tracef("Starting generateSchema : PUI.name=%s", info.getPersistenceUnitName());

PersistenceUnitDescriptor descriptor = getPersistenceUnitDescriptor(info);
final EntityManagerFactoryBuilder builder = Bootstrap.getEntityManagerFactoryBuilder(descriptor, map);
builder.generateSchema();
   }
项目:lightmare    文件:PersistenceDescriptorUtils.java   
private static void setTransactionType(PersistenceUnitDescriptor persistenceUnit,
    PersistenceUnitTransactionType type) {

if (persistenceUnit instanceof ParsedPersistenceXmlDescriptor) {
    ObjectUtils.cast(persistenceUnit, ParsedPersistenceXmlDescriptor.class).setTransactionType(type);
} else if (persistenceUnit instanceof PersistenceUnitSwapDescriptor) {
    ObjectUtils.cast(persistenceUnit, PersistenceUnitSwapDescriptor.class).setTransactionType(type);
}
   }
项目:lightmare    文件:PersistenceDescriptorUtils.java   
private static void setNonJtaDataSource(PersistenceUnitDescriptor persistenceUnit, Object dataSource) {

    if (persistenceUnit instanceof ParsedPersistenceXmlDescriptor) {
        ObjectUtils.cast(persistenceUnit, ParsedPersistenceXmlDescriptor.class).setNonJtaDataSource(dataSource);
    } else if (persistenceUnit instanceof PersistenceUnitSwapDescriptor) {
        ObjectUtils.cast(persistenceUnit, PersistenceUnitSwapDescriptor.class).setNonJtaDataSource(dataSource);
    }
    }
项目:lightmare    文件:PersistenceDescriptorUtils.java   
private static void addClasses(PersistenceUnitDescriptor persistenceUnit, List<String> classes) {

    if (persistenceUnit instanceof ParsedPersistenceXmlDescriptor) {
        ObjectUtils.cast(persistenceUnit, ParsedPersistenceXmlDescriptor.class).addClasses(classes);
    } else if (persistenceUnit instanceof PersistenceUnitSwapDescriptor) {
        ObjectUtils.cast(persistenceUnit, PersistenceUnitSwapDescriptor.class).addClasses(classes);
    }
    }
项目:lightmare    文件:PersistenceDescriptorUtils.java   
/**
    * Resolves data source from {@link MetaConfig} object
    * 
    * @param persistenceUnit
    * @param metaConfig
    */
   public static void resolveDataSource(PersistenceUnitDescriptor persistenceUnit, MetaConfig metaConfig) {

Object dataSource = persistenceUnit.getJtaDataSource();
if (MetaConfig.isSwapDataSource(metaConfig)) {
    setNonJtaDataSource(persistenceUnit, dataSource);
}
   }
项目:lightmare    文件:PersistenceDescriptorUtils.java   
/**
    * Resolves entity classes from {@link MetaConfig} object
    * 
    * @param persistenceUnit
    * @param metaConfig
    */
   public static void resolveEntities(PersistenceUnitDescriptor persistenceUnit, MetaConfig metaConfig) {

List<String> classes = MetaConfig.getClasses(metaConfig);
if (CollectionUtils.valid(classes)) {
    addClasses(persistenceUnit, classes);
}
   }
项目:sdcct    文件:SdcctEntityManagerFactoryFactoryBean.java   
public SdcctEntityManagerFactoryBuilder(PersistenceUnitDescriptor persistenceUnit, Map props, @Nullable ClassLoader classLoader) {
    super(persistenceUnit, props, classLoader);
}
项目:sdcct    文件:SdcctEntityManagerFactoryFactoryBean.java   
@Override
protected EntityManagerFactoryBuilder getEntityManagerFactoryBuilder(PersistenceUnitDescriptor persistenceUnitDescriptor, Map props,
    @Nullable ClassLoader classLoader) {
    return new SdcctEntityManagerFactoryBuilder(persistenceUnitDescriptor, props, classLoader);
}
项目:pm-persistence-utils    文件:HibernateDDL.java   
protected static EntityManagerFactoryBuilderImpl getEntityManagerFactoryBuilder(PersistenceUnitDescriptor persistenceUnitDescriptor,
        Map<String, Object> integration, ClassLoader providedClassLoader) {
    return new EntityManagerFactoryBuilderImpl( persistenceUnitDescriptor, integration, providedClassLoader );
}
项目:rapidoid    文件:CustomDescriptor.java   
public CustomDescriptor(PersistenceUnitDescriptor descriptor, List<String> names) {
    this.descriptor = descriptor;
    this.names = names;
    this.names.addAll(U.safe(descriptor.getManagedClassNames()));
}
项目:rapidoid    文件:CustomHibernatePersistenceProvider.java   
@Override
protected EntityManagerFactoryBuilder getEntityManagerFactoryBuilder(PersistenceUnitDescriptor persistenceUnitDescriptor, Map integration, ClassLoader cl) {
    return emfBuilder(persistenceUnitDescriptor, integration, cl);
}
项目:rapidoid    文件:CustomHibernatePersistenceProvider.java   
private EntityManagerFactoryBuilder emfBuilder(PersistenceUnitDescriptor persistenceUnitDescriptor, Map integration, ClassLoader cl) {
    CustomDescriptor descriptor = new CustomDescriptor(persistenceUnitDescriptor, names);
    return super.getEntityManagerFactoryBuilder(descriptor, integration, cl);
}
项目:lightmare    文件:HibernatePersistenceProviderExt.java   
/**
    * Creates {@link PersistenceUnitDescriptor} for passed persistence unit
    * name {@link Map} of properties and {@link ClassLoader} instance
    *
    * @param persistenceUnitName
    * @param properties
    * @param providedClassLoader
    * @return {@link PersistenceUnitDescriptor}
    */
   @SuppressWarnings({ "rawtypes" })
   public PersistenceUnitDescriptor getPersistenceXmlDescriptor(String persistenceUnitName, Map properties,
    ClassLoader providedClassLoader) {

ParsedPersistenceXmlDescriptor descriptor = null;

final Map integration = wrap(properties);
final List<ParsedPersistenceXmlDescriptor> units;

try {
    units = PersistenceXmlParserImpl.locatePersistenceUnits(integration, metaConfig);
} catch (Exception ex) {
    LOG.debug("Unable to locate persistence units", ex);
    throw new PersistenceException("Unable to locate persistence units", ex);
}

LOG.debugf("Located and parsed %s persistence units; checking each", units.size());

if (persistenceUnitName == null && units.size() > CollectionUtils.SINGLTON_LENGTH) {
    // no persistence-unit name to look for was given and we found
    // multiple persistence-units
    throw new PersistenceException("No name provided and multiple persistence units found");
}

boolean notMatches = Boolean.TRUE;
Iterator<ParsedPersistenceXmlDescriptor> descriptorIterator = units.iterator();
ParsedPersistenceXmlDescriptor persistenceUnit;
while (descriptorIterator.hasNext() && notMatches) {
    persistenceUnit = descriptorIterator.next();
    LOG.debugf(
        "Checking persistence-unit [name=%s, explicit-provider=%s] against incoming persistence unit name [%s]",
        persistenceUnit.getName(), persistenceUnit.getProviderClassName(), persistenceUnitName);

    final boolean matches = (persistenceUnitName == null
        || persistenceUnitName.equals(persistenceUnit.getName()));
    notMatches = Boolean.FALSE.equals(matches);
    if (notMatches) {
    LOG.debug("Excluding from consideration due to name mis-match");
    // See if we (Hibernate) are the persistence provider
    } else if (Boolean.FALSE.equals(ProviderChecker.isProvider(persistenceUnit, properties))) {
    LOG.debug("Excluding from consideration due to provider mis-match");
    } else {
    descriptor = persistenceUnit;
    }
}

return descriptor;
   }
项目:lightmare    文件:HibernatePersistenceProviderExt.java   
@SuppressWarnings({ "rawtypes" })
   public PersistenceUnitDescriptor getPersistenceUnitDescriptor(String persistenceUnitName, Map properties) {

PersistenceUnitDescriptor persistenceUnit;

ClassLoader loader = MetaConfig.getOverridenClassLoader(metaConfig);
persistenceUnit = getPersistenceXmlDescriptor(persistenceUnitName, properties, loader);

return persistenceUnit;
   }
项目:lightmare    文件:PersistenceDescriptorUtils.java   
/**
    * Resolved which transaction type should be set from {@link MetaConfig}
    * object
    * 
    * @param persistenceUnit
    * @param metaConfig
    */
   public static void resolveTransactionType(PersistenceUnitDescriptor persistenceUnit, MetaConfig metaConfig) {

if (MetaConfig.isSwapDataSource(metaConfig)) {
    setTransactionType(persistenceUnit, PersistenceUnitTransactionType.RESOURCE_LOCAL);
}
   }
项目:lightmare    文件:PersistenceDescriptorUtils.java   
/**
    * Changes JPA configuration and resolves additional data from
    * {@link MetaConfig} parameter
    * 
    * @param persistenceUnit
    * @param metaConfig
    */
   public static void resolve(PersistenceUnitDescriptor persistenceUnit, MetaConfig metaConfig) {

PersistenceDescriptorUtils.resolveTransactionType(persistenceUnit, metaConfig);
PersistenceDescriptorUtils.resolveDataSource(persistenceUnit, metaConfig);
PersistenceDescriptorUtils.resolveEntities(persistenceUnit, metaConfig);
   }