/** * Parse persistence-unit element. */ private void startPersistenceUnit(Attributes attrs) throws SAXException { _excludeUnlistedSet = false; _info = new PersistenceUnitInfoImpl(); _info.setPersistenceUnitName(attrs.getValue("name")); _info.setPersistenceXMLSchemaVersion(_persistenceVersion); // we only parse this ourselves outside a container, so default // transaction type to local String val = attrs.getValue("transaction-type"); if (val == null) _info.setTransactionType(PersistenceUnitTransactionType.RESOURCE_LOCAL); else _info.setTransactionType(Enum.valueOf(PersistenceUnitTransactionType.class, val)); if (_source != null) _info.setPersistenceXmlFileUrl(_source); }
/** * Return a {@link Map} containing the properties necessary to create * a {@link Configuration} that reflects the information in this * persistence unit info. */ public Map toOpenJPAProperties() { return toOpenJPAProperties(this); }
try { InputStream is = Thread.currentThread().getContextClassLoader( ).getResource("META-INF/persistence.xml").openStream(); FileOutputStream output= new FileOutputStream("c:/tmp/show.xml"); IOUtils.copy(is, output); IOUtils.closeQuietly(output); PersistenceUnitInfoImpl impl= new PersistenceUnitInfoImpl(); impl.setPersistenceXmlFileUrl(new URL("file://c:/tmp/show.xml")); JpaBasics basics= new JpaBasics("spektrum"); basics.init(false); EntityManager em= basics.getEm(); _log.debug("have we an em: " + em); new TestLoad().testLoadMagazines(); } catch (Exception e) { _log.error("", e); } }
if (currentDepth() == 1) { endPersistenceUnit(); _info.fromUserProperties(_map); addResult(_info); _info.addManagedClassName(currentText()); break; case 'e': // exclude-unlisted-classes case 'j': if ("jta-data-source".equals(name)) _info.setJtaDataSourceName(currentText()); else { // jar-file try { _info.addJarFileName(currentText()); } catch (IllegalArgumentException iae) { throw getException(iae.getMessage()); _info.addMappingFileName(currentText()); break; case 'n': // non-jta-data-source _info.setNonJtaDataSourceName(currentText()); break; case 'p': if ("provider".equals(name)) _info.setPersistenceProviderClassName(currentText()); break; case 's' : // shared-cache-mode _info.setSharedCacheMode(JPAProperties.getEnumValue(SharedCacheMode.class, currentText()));
protected void endElement(String name) throws SAXException { if (currentDepth() == 1) { _info.fromUserProperties(_map); addResult(_info); _info.addManagedClassName(currentText()); case 'e': // exclude-unlisted-classes _info.setExcludeUnlistedClasses("true".equalsIgnoreCase (currentText())); break; case 'j': if ("jta-data-source".equals(name)) _info.setJtaDataSourceName(currentText()); else // jar-file _info.addJarFileName(currentText()); } catch (IllegalArgumentException iae) { throw getException(iae.getMessage()); _info.addMappingFileName(currentText()); break; case 'n': // non-jta-data-source _info.setNonJtaDataSourceName(currentText()); break; case 'p': if ("provider".equals(name)) _info.setPersistenceProviderClassName(currentText()); break;
/** * Load configuration from the given resource and unit names, which may * be null. */ public ConfigurationProvider load(String rsrc, String name, Map m) throws IOException { boolean explicit = !StringUtils.isEmpty(rsrc); if (!explicit) rsrc = RSRC_DEFAULT; ConfigurationProviderImpl cp = new ConfigurationProviderImpl(); Boolean ret = load(cp, rsrc, name, m, null, explicit); if (ret != null) return (ret.booleanValue()) ? cp : null; if (explicit) return null; // persistence.xml does not exist; just load map PersistenceUnitInfoImpl pinfo = new PersistenceUnitInfoImpl(); pinfo.fromUserProperties(m); if (!isOpenJPAPersistenceProvider(pinfo, null)) { warnUnknownProvider(pinfo); return null; } cp.addProperties(pinfo.toOpenJPAProperties()); return cp; }
rsrc, name, pinfo.getPersistenceProviderClassName()). getMessage(), getClass().getName(), rsrc); AccessController.doPrivileged(J2DoPrivHelper.setContextClassLoaderAction(mutliClassLoader)); pinfo.processJarFileNames(); cp.addProperties(pinfo.toOpenJPAProperties()); cp.setSource(pinfo.getPersistenceXmlFileUrl().toString()); return Boolean.TRUE;
Set<String> added = new HashSet<String>(); if (info.getTransactionType() == PersistenceUnitTransactionType.JTA) replaceAsOpenJPAProperty(map, added, "TransactionMode", "managed"); replaceAsOpenJPAProperty(map, added, "ConnectionFactory", ds); replaceAsOpenJPAProperty(map, added, "ConnectionFactoryMode", "managed"); hasJta = true; } else if (info instanceof PersistenceUnitInfoImpl && ((PersistenceUnitInfoImpl) info).getJtaDataSourceName() != null){ replaceAsOpenJPAProperty(map, added, "ConnectionFactoryName", ((PersistenceUnitInfoImpl)info).getJtaDataSourceName()); replaceAsOpenJPAProperty(map, added, "ConnectionFactoryMode", "managed"); hasJta = true; replaceAsOpenJPAProperty(map, added, hasJta ? "ConnectionFactory2" : "ConnectionFactory", ds); } else if (info instanceof PersistenceUnitInfoImpl && ((PersistenceUnitInfoImpl) info).getNonJtaDataSourceName() != null) { String nonJtaName = ((PersistenceUnitInfoImpl) info).getNonJtaDataSourceName(); replaceAsOpenJPAProperty(map, added, hasJta ? "ConnectionFactory2Name" : "ConnectionFactoryName", nonJtaName); replaceAsOpenJPAProperty(map, added, "ClassResolver", new ClassResolverImpl(info.getClassLoader()));
/** * Load configuration from the given persistence unit with the specified * user properties. */ public ConfigurationProvider load(PersistenceUnitInfo pinfo, Map m) throws IOException { if (pinfo == null) return null; if (!isOpenJPAPersistenceProvider(pinfo, null)) { warnUnknownProvider(pinfo); return null; } ConfigurationProviderImpl cp = new ConfigurationProviderImpl(); cp.addProperties(PersistenceUnitInfoImpl.toOpenJPAProperties(pinfo)); cp.addProperties(m); if (pinfo instanceof PersistenceUnitInfoImpl) { PersistenceUnitInfoImpl impl = (PersistenceUnitInfoImpl) pinfo; if (impl.getPersistenceXmlFileUrl() != null) cp.setSource(impl.getPersistenceXmlFileUrl().toString()); } return cp; }
rsrc, name, pinfo.getPersistenceProviderClassName()). getMessage(), getClass().getName(), rsrc); cp.addProperties(pinfo.toOpenJPAProperties()); cp.setSource(pinfo.getPersistenceXmlFileUrl().toString()); return Boolean.TRUE;
PersistenceUnitInfoImpl pui = new PersistenceUnitInfoImpl(); pui.fromUserProperties(props); EntityManagerFactory emf = provider.createContainerEntityManagerFactory(pui, props); EM = emf.createEntityManager();
Set<String> added = new HashSet<String>(); if (info.getTransactionType() == PersistenceUnitTransactionType.JTA) put(map, added, "TransactionMode", "managed"); put(map, added, "ConnectionFactory", ds); put(map, added, "ConnectionFactoryMode", "managed"); hasJta = true; } else if (info instanceof PersistenceUnitInfoImpl && ((PersistenceUnitInfoImpl) info).getJtaDataSourceName() != null){ put(map, added, "ConnectionFactoryName", ((PersistenceUnitInfoImpl) info).getJtaDataSourceName()); put(map, added, "ConnectionFactoryMode", "managed"); hasJta = true; if (ds != null) { if (!hasJta) put(map, added, "ConnectionFactory", ds); else put(map, added, "ConnectionFactory2", ds); } else if (info instanceof PersistenceUnitInfoImpl && ((PersistenceUnitInfoImpl) info).getNonJtaDataSourceName() != null) { String nonJtaName = ((PersistenceUnitInfoImpl) info). getNonJtaDataSourceName(); if (!hasJta) put(map, added, "ConnectionFactoryName", nonJtaName); else put(map, added, "ConnectionFactory2Name", nonJtaName);
J2DoPrivHelper.getResourceAction(loader, name)); if (url != null) { addJarFile(url); return; || cp[i].endsWith(File.separatorChar + name)) { try { addJarFile((URL) AccessController .doPrivileged(J2DoPrivHelper .toURLAction(new File(cp[i]))));
if (currentDepth() == 1) { endPersistenceUnit(); _info.fromUserProperties(_map); addResult(_info); _info.addManagedClassName(currentText()); break; case 'e': // exclude-unlisted-classes case 'j': if ("jta-data-source".equals(name)) _info.setJtaDataSourceName(currentText()); else { // jar-file try { _info.addJarFileName(currentText()); } catch (IllegalArgumentException iae) { throw getException(iae.getMessage()); _info.addMappingFileName(currentText()); break; case 'n': // non-jta-data-source _info.setNonJtaDataSourceName(currentText()); break; case 'p': if ("provider".equals(name)) _info.setPersistenceProviderClassName(currentText()); break; case 's' : // shared-cache-mode _info.setSharedCacheMode(JPAProperties.getEnumValue(SharedCacheMode.class, currentText()));
/** * Load configuration from the given resource and unit names, which may * be null. */ public ConfigurationProvider load(String rsrc, String name, Map m, ClassLoader loader) throws IOException { boolean explicit = !StringUtils.isEmpty(rsrc); if (!explicit) rsrc = RSRC_DEFAULT; ConfigurationProviderImpl cp = new ConfigurationProviderImpl(); Boolean ret = load(cp, rsrc, name, m, loader, explicit); if (ret != null) return (ret.booleanValue()) ? cp : null; if (explicit) return null; // persistence.xml does not exist; just load map PersistenceUnitInfoImpl pinfo = new PersistenceUnitInfoImpl(); pinfo.fromUserProperties(m); if (!isOpenJPAPersistenceProvider(pinfo, null)) { warnUnknownProvider(pinfo); return null; } cp.addProperties(pinfo.toOpenJPAProperties()); return cp; } }
rsrc, name, pinfo.getPersistenceProviderClassName()). getMessage(), getClass().getName(), rsrc); AccessController.doPrivileged(J2DoPrivHelper.setContextClassLoaderAction(mutliClassLoader)); pinfo.processJarFileNames(); cp.addProperties(pinfo.toOpenJPAProperties()); cp.setSource(pinfo.getPersistenceXmlFileUrl().toString()); return Boolean.TRUE;
Set<String> added = new HashSet<String>(); if (info.getTransactionType() == PersistenceUnitTransactionType.JTA) replaceAsOpenJPAProperty(map, added, "TransactionMode", "managed"); replaceAsOpenJPAProperty(map, added, "ConnectionFactory", ds); replaceAsOpenJPAProperty(map, added, "ConnectionFactoryMode", "managed"); hasJta = true; } else if (info instanceof PersistenceUnitInfoImpl && ((PersistenceUnitInfoImpl) info).getJtaDataSourceName() != null){ replaceAsOpenJPAProperty(map, added, "ConnectionFactoryName", ((PersistenceUnitInfoImpl)info).getJtaDataSourceName()); replaceAsOpenJPAProperty(map, added, "ConnectionFactoryMode", "managed"); hasJta = true; replaceAsOpenJPAProperty(map, added, hasJta ? "ConnectionFactory2" : "ConnectionFactory", ds); } else if (info instanceof PersistenceUnitInfoImpl && ((PersistenceUnitInfoImpl) info).getNonJtaDataSourceName() != null) { String nonJtaName = ((PersistenceUnitInfoImpl) info).getNonJtaDataSourceName(); replaceAsOpenJPAProperty(map, added, hasJta ? "ConnectionFactory2Name" : "ConnectionFactoryName", nonJtaName); replaceAsOpenJPAProperty(map, added, "ClassResolver", new ClassResolverImpl(info.getClassLoader()));
/** * Load configuration from the given persistence unit with the specified * user properties. */ public ConfigurationProvider load(PersistenceUnitInfo pinfo, Map m) throws IOException { if (pinfo == null) return null; if (!isOpenJPAPersistenceProvider(pinfo, null)) { warnUnknownProvider(pinfo); return null; } ConfigurationProviderImpl cp = new ConfigurationProviderImpl(); cp.addProperties(PersistenceUnitInfoImpl.toOpenJPAProperties(pinfo)); cp.addProperties(m); if (pinfo instanceof PersistenceUnitInfoImpl) { PersistenceUnitInfoImpl impl = (PersistenceUnitInfoImpl) pinfo; if (impl.getPersistenceXmlFileUrl() != null) cp.setSource(impl.getPersistenceXmlFileUrl().toString()); } return cp; }
J2DoPrivHelper.getResourceAction(loader, name)); if (url != null) { addJarFile(url); return; || cp[i].endsWith(File.separatorChar + name)) { try { addJarFile(AccessController .doPrivileged(J2DoPrivHelper .toURLAction(new File(cp[i]))));
if (currentDepth() == 1) { endPersistenceUnit(); _info.fromUserProperties(_map); addResult(_info); _info.addManagedClassName(currentText()); break; case 'e': // exclude-unlisted-classes case 'j': if ("jta-data-source".equals(name)) _info.setJtaDataSourceName(currentText()); else { // jar-file try { _info.addJarFileName(currentText()); } catch (IllegalArgumentException iae) { throw getException(iae.getMessage()); _info.addMappingFileName(currentText()); break; case 'n': // non-jta-data-source _info.setNonJtaDataSourceName(currentText()); break; case 'p': if ("provider".equals(name)) _info.setPersistenceProviderClassName(currentText()); break; case 's' : // shared-cache-mode _info.setSharedCacheMode(JPAProperties.getEnumValue(SharedCacheMode.class, currentText()));