private DataSource getDataSource(XMLStreamReader reader) throws PersistenceUnitException { try { String dataSourceName = reader.getElementText(); DataSource dataSource = registry.getDataSource(dataSourceName); if (dataSource == null) { throw new PersistenceUnitException("DataSource not found: " + dataSourceName); } return dataSource; } catch (XMLStreamException e) { throw new PersistenceUnitException(e); } }
private URL getRootJarUrl(URL url) throws PersistenceUnitException { try { String protocol = url.getProtocol(); if ("jar".equals(protocol)) { JarURLConnection jarURLConnection = (JarURLConnection) url.openConnection(); return jarURLConnection.getJarFileURL(); } else if ("file".equals(protocol)) { String path = url.getPath(); return new File(path).getParentFile().getParentFile().toURI().toURL(); } else if ("zip".equals(protocol)) { String path = url.getPath(); String rootJarUrl = path.substring(0, path.lastIndexOf("META-INF") - 2); rootJarUrl = "file:" + rootJarUrl; return new URL(rootJarUrl); } else { throw new PersistenceUnitException("Unknown protocol: " + protocol); } } catch (IOException e) { throw new PersistenceUnitException(e); } }
urls = classLoader.getResources("META-INF/persistence.xml"); } catch (IOException e) { throw new PersistenceUnitException(e); throw new PersistenceUnitException("Persistence context (persistence.xml) not found in /META-INF"); if ("persistence-unit".equals(reader.getName().getLocalPart())) { if (info == null) { throw new PersistenceUnitException("Invalid persistence.xml found in :"+rootUrl); throw new PersistenceUnitException(e); } catch (XMLStreamException e) { throw new PersistenceUnitException(e); } finally { close(stream, reader);
info.setSharedCacheMode(mode); } catch (IllegalArgumentException e) { throw new PersistenceUnitException("Illegal shared cache mode: " + value); info.setValidationMode(mode); } catch (IllegalArgumentException e) { throw new PersistenceUnitException("Illegal validation mode: " + value);