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); } }
/** * Parse persistence-unit element. */ private void startPersistenceUnit(Attributes attrs) throws SAXException { _info = new PersistenceUnitInfoImpl(); _info.setPersistenceUnitName(attrs.getValue("name")); // 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); } }
/** * 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); }
PersistenceUnitInfoImpl pui = new PersistenceUnitInfoImpl(); pui.fromUserProperties(props); EntityManagerFactory emf = provider.createContainerEntityManagerFactory(pui, props);
/** * 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); }
/** * 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); }
/** * 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); }
/** * 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; }
/** * 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; } }
/** * 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; }
/** * 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; }
/** * 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 = !StringUtil.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; }
/** * 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 = !StringUtil.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; }