Example usage for org.hibernate.jpa.boot.spi ProviderChecker isProvider

List of usage examples for org.hibernate.jpa.boot.spi ProviderChecker isProvider

Introduction

In this page you can find the example usage for org.hibernate.jpa.boot.spi ProviderChecker isProvider.

Prototype

public static boolean isProvider(PersistenceUnitDescriptor persistenceUnit, Map integration) 

Source Link

Document

Does the descriptor and/or integration request Hibernate as the javax.persistence.spi.PersistenceProvider ?

Usage

From source file:org.babyfish.hibernate.jpa.HibernatePersistenceProvider.java

License:Open Source License

public static boolean isProvider(PersistenceUnitDescriptor persistenceUnit, Map<?, ?> integration) {
    if (ProviderChecker.isProvider(persistenceUnit, integration)) {
        return true;
    }//from w  w  w  . jav a2 s. c o  m
    String providerClassName = ProviderChecker.extractRequestedProviderName(persistenceUnit, integration);
    return HibernatePersistenceProvider.class.getName().equals(providerClassName);
}

From source file:org.lightmare.jpa.hibernate.jpa.HibernatePersistenceProviderExt.java

License:Open Source License

/**
 * Creates {@link PersistenceUnitDescriptor} for passed persistence unit
 * name {@link Map} of properties and {@link ClassLoader} instance
 * /*from   w ww  . ja  v a2s .c o  m*/
 * @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;
}