@Override public ConfigurationProvider load(File file, String anchor) throws IOException { if (!file.getName().endsWith(".xml")) return null; ConfigurationParser parser = new ConfigurationParser(null); parser.parse(file); return load(findUnit((List<PersistenceUnitInfoImpl>) parser.getResults(), anchor, null), null); }
@Override public List getAnchorsInResource(String resource) throws Exception { ConfigurationParser parser = new ConfigurationParser(null); try { List results = new ArrayList(); ClassLoader loader = AccessController.doPrivileged( J2DoPrivHelper.getContextClassLoaderAction()); List<URL> urls = getResourceURLs(resource, loader); if (urls != null) { for (URL url : urls) { parser.parse(url); results.addAll(getUnitNames(parser)); } } return results; } catch (IOException e) { // not all configuration files are XML; return null if unparsable return null; } }
/** * 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; }
J2DoPrivHelper.getContextClassLoaderAction()); List<URL> urls = getResourceURLs(rsrc, loader); if (urls == null || urls.size() == 0) return null; PersistenceUnitInfoImpl pinfo = parseResources(parser, urls, name, loader); if (pinfo == null) { rsrc, String.valueOf(name)).getMessage(), getClass().getName(), rsrc); } else if (!isOpenJPAPersistenceProvider(pinfo, loader)) { if (!explicit) { warnUnknownProvider(pinfo); return Boolean.FALSE;
PersistenceProductDerivation pd = new PersistenceProductDerivation(); try { Object poolValue = Configurations.removeProperty(EMF_POOL, m); ConfigurationProvider cp = pd.load(resource, name, m); if (cp == null) { return null; conf.setUserClassLoader(BundleUtils.getBundleClassLoader()); _log = conf.getLog(OpenJPAConfiguration.LOG_RUNTIME); pd.checkPuNameCollisions(_log,name);
/** * Loads the entity manager specified by <code>name</code>, applying * the properties in <code>m</code> as overrides to the properties defined * in the XML configuration file for <code>name</code>. If <code>name</code> * is <code>null</code>, this method loads the XML in the resource * identified by <code>resource</code>, and uses the first resource found * when doing this lookup, regardless of the name specified in the XML * resource or the name of the jar that the resource is contained in. * This does no pooling of EntityManagersFactories. */ public OpenJPAEntityManagerFactory createEntityManagerFactory(String name, String resource, Map m) { PersistenceProductDerivation pd = new PersistenceProductDerivation(); try { Object poolValue = Configurations.removeProperty(EMF_POOL, m); ConfigurationProvider cp = pd.load(resource, name, m); if (cp == null) return null; BrokerFactory factory = getBrokerFactory(cp, poolValue, null); return JPAFacadeHelper.toEntityManagerFactory(factory); } catch (Exception e) { throw PersistenceExceptions.toPersistenceException(e); } }
/** * 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; }
@Override public ConfigurationProvider load(String rsrc, String anchor, ClassLoader loader) throws IOException { if (rsrc != null && !rsrc.endsWith(".xml")) return null; ConfigurationProviderImpl cp = new ConfigurationProviderImpl(); if (load(cp, rsrc, anchor, null, loader, true) == Boolean.TRUE) return cp; return null; }
if (name.equals(pinfo.getPersistenceUnitName())){ if (result != null){ this.addPuNameCollision(name, result.getPersistenceXmlFileUrl().toString(), pinfo.getPersistenceXmlFileUrl().toString()); if (isOpenJPAPersistenceProvider(pinfo, loader)) {
/** * Return whether the given persistence unit uses an OpenJPA provider. */ private static boolean isOpenJPAPersistenceProvider(PersistenceUnitInfo pinfo, ClassLoader loader) { String provider = pinfo.getPersistenceProviderClassName(); if (StringUtils.isEmpty(provider) || PersistenceProviderImpl.class.getName().equals(provider)) return true; if (loader == null) loader = AccessController.doPrivileged(J2DoPrivHelper.getContextClassLoaderAction()); try { if (PersistenceProviderImpl.class.isAssignableFrom(Class.forName(provider, false, loader))) return true; } catch (Throwable t) { log(_loc.get("unloadable-provider", provider, t).getMessage()); return false; } return false; }
@Override public List<String> getAnchorsInFile(File file) throws IOException { ConfigurationParser parser = new ConfigurationParser(null); try { parser.parse(file); return getUnitNames(parser); } catch (IOException e) { // not all configuration files are XML; return null if unparsable return null; } }
/** * Parse resources at the given location. Searches for a * PersistenceUnitInfo with the requested name, or an OpenJPA unit if * no name given (preferring an unnamed OpenJPA unit to a named one). */ private PersistenceUnitInfoImpl parseResources(ConfigurationParser parser, List<URL> urls, String name, ClassLoader loader) throws IOException { List<PersistenceUnitInfoImpl> pinfos = new ArrayList<PersistenceUnitInfoImpl>(); for (URL url : urls) { parser.parse(url); pinfos.addAll((List<PersistenceUnitInfoImpl>) parser.getResults()); } return findUnit(pinfos, name, loader); }
/** * Find the unit with the given name, or an OpenJPA unit if no name is * given (preferring an unnamed OpenJPA unit to a named one). */ private PersistenceUnitInfoImpl findUnit(List<PersistenceUnitInfoImpl> pinfos, String name, ClassLoader loader) { PersistenceUnitInfoImpl ojpa = null; for (PersistenceUnitInfoImpl pinfo : pinfos) { // found named unit? if (name != null) { if (name.equals(pinfo.getPersistenceUnitName())) return pinfo; continue; } if (isOpenJPAPersistenceProvider(pinfo, loader)) { // if no name given and found unnamed unit, return it. // otherwise record as default unit unless we find a // better match later if (StringUtils.isEmpty(pinfo.getPersistenceUnitName())) return pinfo; if (ojpa == null) ojpa = pinfo; } } return ojpa; }
List<URL> urls = getResourceURLs(rsrc, loader); if (urls == null || urls.size() == 0) return null; PersistenceUnitInfoImpl pinfo = parseResources(parser, urls, name, loader); if (pinfo == null) { if (!explicit) throw new MissingResourceException(_loc.get("missing-xml-config", rsrc, String.valueOf(name)).getMessage(), getClass().getName(), rsrc); } else if (!isOpenJPAPersistenceProvider(pinfo, loader)) { if (!explicit) { warnUnknownProvider(pinfo); return Boolean.FALSE;
PersistenceProductDerivation pd = new PersistenceProductDerivation(); try { Object poolValue = Configurations.removeProperty(EMF_POOL, m); ConfigurationProvider cp = pd.load(resource, name, m); if (cp == null) { return null; conf.setUserClassLoader(BundleUtils.getBundleClassLoader()); _log = conf.getLog(OpenJPAConfiguration.LOG_RUNTIME); pd.checkPuNameCollisions(_log,name);
public OpenJPAEntityManagerFactory createContainerEntityManagerFactory( PersistenceUnitInfo pui, Map m) { PersistenceProductDerivation pd = new PersistenceProductDerivation(); try { Object poolValue = Configurations.removeProperty(EMF_POOL, m); ConfigurationProvider cp = pd.load(pui, m); if (cp == null) return null;
/** * 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; }
@Override public ConfigurationProvider loadDefaults(ClassLoader loader) throws IOException { ConfigurationProviderImpl cp = new ConfigurationProviderImpl(); if (load(cp, RSRC_DEFAULT, null, null, loader, false) == Boolean.TRUE) return cp; return null; }
if (name.equals(pinfo.getPersistenceUnitName())){ if (result != null){ this.addPuNameCollision(name, result.getPersistenceXmlFileUrl().toString(), pinfo.getPersistenceXmlFileUrl().toString()); if (isOpenJPAPersistenceProvider(pinfo, loader)) {
/** * Return whether the given persistence unit uses an OpenJPA provider. */ private static boolean isOpenJPAPersistenceProvider(PersistenceUnitInfo pinfo, ClassLoader loader) { String provider = pinfo.getPersistenceProviderClassName(); if (StringUtils.isEmpty(provider) || PersistenceProviderImpl.class.getName().equals(provider)) return true; if (loader == null) loader = AccessController.doPrivileged(J2DoPrivHelper.getContextClassLoaderAction()); try { if (PersistenceProviderImpl.class.isAssignableFrom(Class.forName(provider, false, loader))) return true; } catch (Throwable t) { log(_loc.get("unloadable-provider", provider, t).getMessage()); return false; } return false; }