Example usage for org.hibernate.jpa AvailableSettings PROVIDER

List of usage examples for org.hibernate.jpa AvailableSettings PROVIDER

Introduction

In this page you can find the example usage for org.hibernate.jpa AvailableSettings PROVIDER.

Prototype

String PROVIDER

To view the source code for org.hibernate.jpa AvailableSettings PROVIDER.

Click Source Link

Usage

From source file:org.lightmare.jpa.hibernate.internal.PersistenceXmlParserImpl.java

License:Open Source License

@SuppressWarnings("rawtypes")
private List<ParsedPersistenceXmlDescriptor> parsePersistenceXml(URL xmlUrl, Map integration) {
    LOG.tracef("Attempting to parse persistence.xml file : %s", xmlUrl.toExternalForm());

    final Document doc = loadUrl(xmlUrl);
    final Element top = doc.getDocumentElement();

    final List<ParsedPersistenceXmlDescriptor> persistenceUnits = new ArrayList<ParsedPersistenceXmlDescriptor>();

    final NodeList children = top.getChildNodes();
    for (int i = 0; i < children.getLength(); i++) {
        if (children.item(i).getNodeType() == Node.ELEMENT_NODE) {
            final Element element = (Element) children.item(i);
            final String tag = element.getTagName();
            if (tag.equals("persistence-unit")) {

                // Decides which sub path in archives to use
                String shortPath = MetaConfig.getShortPath(metaConfig);
                if (StringUtils.invalid(shortPath)) {
                    shortPath = "/META-INF/persistence.xml";
                }/*w  w w . j a  v a2s  . co  m*/

                // Decides whether is needed to scan archives
                final URL puRootUrl;
                if (MetaConfig.isScanArchives(metaConfig)) {
                    puRootUrl = ArchiveHelper.getJarURLFromURLEntry(xmlUrl, shortPath);
                } else {
                    puRootUrl = xmlUrl;
                }

                ParsedPersistenceXmlDescriptor persistenceUnit = new ParsedPersistenceXmlDescriptor(puRootUrl);
                bindPersistenceUnit(persistenceUnit, element);

                // per JPA spec, any settings passed in to
                // PersistenceProvider bootstrap methods should override
                // values found in persistence.xml
                if (integration.containsKey(AvailableSettings.PROVIDER)) {
                    persistenceUnit.setProviderClassName((String) integration.get(AvailableSettings.PROVIDER));
                }

                if (integration.containsKey(AvailableSettings.TRANSACTION_TYPE)) {
                    String transactionType = (String) integration.get(AvailableSettings.TRANSACTION_TYPE);
                    persistenceUnit.setTransactionType(parseTransactionType(transactionType));
                }

                PersistenceDescriptorUtils.resolveTransactionType(persistenceUnit, metaConfig);

                if (integration.containsKey(AvailableSettings.JTA_DATASOURCE)) {
                    persistenceUnit.setJtaDataSource(integration.get(AvailableSettings.JTA_DATASOURCE));
                }
                if (integration.containsKey(AvailableSettings.NON_JTA_DATASOURCE)) {
                    persistenceUnit.setNonJtaDataSource(integration.get(AvailableSettings.NON_JTA_DATASOURCE));
                }

                PersistenceDescriptorUtils.resolveDataSource(persistenceUnit, metaConfig);

                decodeTransactionType(persistenceUnit);

                Properties properties = persistenceUnit.getProperties();
                ConfigurationHelper.overrideProperties(properties, integration);

                persistenceUnits.add(persistenceUnit);
            }
        }
    }
    return persistenceUnits;
}