List of usage examples for org.springframework.dao DataAccessResourceFailureException DataAccessResourceFailureException
public DataAccessResourceFailureException(String msg, @Nullable Throwable cause)
From source file:org.emonocot.job.io.StaxEventItemWriter.java
/** * Helper method for opening output source at given file position. * @param position Set the position/* ww w .j av a2 s. c o m*/ * @param restarted Is this execution being restarted */ private void open(final long position, final boolean restarted) { File file; FileOutputStream os = null; try { file = resource.getFile(); FileUtils.setUpOutputFile(file, restarted, overwriteOutput); Assert.state(resource.exists(), "Output resource must exist"); os = new FileOutputStream(file, true); channel = os.getChannel(); setPosition(position); } catch (IOException ioe) { throw new DataAccessResourceFailureException("Unable to write to file resource: [" + resource + "]", ioe); } XMLOutputFactory outputFactory = XMLOutputFactory.newInstance(); if (outputFactory.isPropertySupported("com.ctc.wstx.automaticEndElements")) { // If the current XMLOutputFactory implementation is supplied by // Woodstox >= 3.2.9 we want to disable its // automatic end element feature (see: // http://jira.codehaus.org/browse/WSTX-165) per // http://jira.springframework.org/browse/BATCH-761. outputFactory.setProperty("com.ctc.wstx.automaticEndElements", Boolean.FALSE); } try { if (transactional) { bufferedWriter = new TransactionAwareBufferedWriter(new OutputStreamWriter(os, encoding), new Runnable() { public void run() { closeStream(); } }); } else { bufferedWriter = new BufferedWriter(new OutputStreamWriter(os, encoding)); } delegateEventWriter = outputFactory.createXMLEventWriter(bufferedWriter); eventWriter = new NoStartEndDocumentStreamWriter(delegateEventWriter); if (!restarted) { startDocument(delegateEventWriter); } } catch (XMLStreamException xse) { throw new DataAccessResourceFailureException("Unable to write to file resource: [" + resource + "]", xse); } catch (UnsupportedEncodingException e) { throw new DataAccessResourceFailureException( "Unable to write to file resource: [" + resource + "] with encoding=[" + encoding + "]", e); } }
From source file:org.emonocot.job.io.StaxEventItemWriter.java
/** * Writes the EndDocument tag manually./*from www . j a v a 2 s . c o m*/ * * @param writer * XML event writer * @throws XMLStreamException if there is a problem ending the document */ protected final void endDocument(final XMLEventWriter writer) throws XMLStreamException { // writer.writeEndDocument(); <- this doesn't work after restart // we need to write end tag of the root element manually String nsPrefix = null; if (!StringUtils.hasText(getRootTagNamespacePrefix())) { nsPrefix = ""; } else { nsPrefix = getRootTagNamespacePrefix() + ":"; } try { bufferedWriter.write("</" + nsPrefix + getRootTagName() + ">"); } catch (IOException ioe) { throw new DataAccessResourceFailureException("Unable to close file resource: [" + resource + "]", ioe); } }
From source file:org.emonocot.job.io.StaxEventItemWriter.java
/** * Get the actual position in file channel. This method flushes any buffered * data before position is read./*from w w w . j a v a 2 s . com*/ * * @return byte offset in file channel */ private long getPosition() { long position; try { eventWriter.flush(); position = channel.position(); if (bufferedWriter instanceof TransactionAwareBufferedWriter) { position += ((TransactionAwareBufferedWriter) bufferedWriter).getBufferSize(); } } catch (Exception e) { throw new DataAccessResourceFailureException("Unable to write to file resource: [" + resource + "]", e); } return position; }
From source file:org.emonocot.job.io.StaxEventItemWriter.java
/** * Set the file channel position.// w w w . ja v a2 s .c o m * * @param newPosition * new file channel position */ private void setPosition(final long newPosition) { try { channel.truncate(newPosition); channel.position(newPosition); } catch (IOException e) { throw new DataAccessResourceFailureException("Unable to write to file resource: [" + resource + "]", e); } }
From source file:org.jamwiki.authentication.JAMWikiDaoImpl.java
public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException, DataAccessException { if (StringUtils.isBlank(username)) { throw new UsernameNotFoundException("Cannot retrieve user without a valid username"); }/*from w w w.ja v a2 s .co m*/ String encryptedPassword = null; try { encryptedPassword = WikiBase.getDataHandler().lookupWikiUserEncryptedPassword(username); } catch (org.jamwiki.DataAccessException e) { throw new DataAccessResourceFailureException("Unable to retrieve authorities for user: " + username, e); } if (encryptedPassword == null) { throw new UsernameNotFoundException("Failure retrieving user information for " + username); } Collection<GrantedAuthority> authorities = this.retrieveUserAuthorities(username); return new WikiUserDetails(username, encryptedPassword, true, true, true, true, authorities); }
From source file:org.jamwiki.authentication.JAMWikiDaoImpl.java
/** * */// w w w . j a va 2 s.c om private Collection<GrantedAuthority> retrieveUserAuthorities(String username) throws DataAccessException { if (WikiUtil.isFirstUse() || WikiUtil.isUpgrade()) { return new ArrayList<GrantedAuthority>(); } // add authorities given to all users Collection<GrantedAuthority> results = new ArrayList<GrantedAuthority>(); if (JAMWikiAuthenticationConfiguration.getDefaultGroupRoles() != null) { results.addAll(JAMWikiAuthenticationConfiguration.getDefaultGroupRoles()); } // add authorities specific to this user if (!StringUtils.isBlank(username)) { // FIXME - log error for blank username? RegisterServlet will trigger that. try { List<Role> roles = WikiBase.getDataHandler().getRoleMapUser(username); if (roles != null) { for (Role role : roles) { results.add((RoleImpl) role); } } } catch (org.jamwiki.DataAccessException e) { throw new DataAccessResourceFailureException("Unable to retrieve authorities for user: " + username, e); } } return results; }
From source file:org.jasig.portal.rdbm.DatabaseMetaDataImpl.java
/** * Run a set of tests on the database to provide better meta data. *//* w w w . ja va 2 s .c om*/ private void runDatabaseTests() { Connection conn = null; try { conn = this.dataSource.getConnection(); //The order of these tests is IMPORTANT, each may depend on the //results of the previous tests. this.getMetaData(conn); final SimpleJdbcTemplate jdbcTemplate = new SimpleJdbcTemplate(this.dataSource); this.testDatabaseInitialized(jdbcTemplate); if (this.portalTablesExist) { this.testOuterJoins(jdbcTemplate); this.testTimeStamp(jdbcTemplate); } } catch (SQLException e) { LOG.error("Error during database initialization. ", e); /* * We must throw a RuntimeException here to avoid starting the portal * with incorrect assumptions about what the database supports. */ throw new DataAccessResourceFailureException("Error during database initialization. ", e); } finally { this.releaseConnection(conn); } }
From source file:org.kuali.rice.krad.data.platform.MaxValueIncrementerFactory.java
/** * Creates an {@link DataFieldMaxValueIncrementer} from a {@link DataSource}. * * @param dataSource the {@link DataSource} for which to retrieve the incrementer. * @param incrementerName the name of the incrementer. * @return an {@link DataFieldMaxValueIncrementer} from a {@link DataSource}. *//*w ww. jav a 2 s .c om*/ private static DataFieldMaxValueIncrementer createIncrementer(DataSource dataSource, String incrementerName) { DatabasePlatformInfo platformInfo = DatabasePlatforms.detectPlatform(dataSource); DataFieldMaxValueIncrementer incrementer = getCustomizedIncrementer(platformInfo, dataSource, incrementerName, ID_COLUMN_NAME); if (incrementer != null) { return incrementer; } if (DatabasePlatforms.ORACLE.equalsIgnoreCase(platformInfo.getName())) { incrementer = new OracleSequenceMaxValueIncrementer(dataSource, incrementerName); } else if (DatabasePlatforms.MYSQL.equalsIgnoreCase(platformInfo.getName())) { incrementer = new EnhancedMySQLMaxValueIncrementer(dataSource, incrementerName, ID_COLUMN_NAME); } if (incrementer == null) { throw new UnsupportedDatabasePlatformException(platformInfo); } if (incrementer instanceof InitializingBean) { try { ((InitializingBean) incrementer).afterPropertiesSet(); } catch (Exception e) { throw new DataAccessResourceFailureException( "Failed to initialize max value incrementer for given datasource and incrementer. dataSource=" + dataSource.toString() + ", incrementerName = " + incrementerName, e); } } return incrementer; }
From source file:org.opennms.netmgt.config.DefaultEventConfDao.java
private Events loadAndProcessEvents(Resource rootResource, EventConfiguration eventConfiguration, String resourceDescription, boolean denyIncludes) { if (log().isDebugEnabled()) { log().debug("DefaultEventConfDao: Loading " + resourceDescription + " event configuration from " + rootResource);/*from ww w. j a v a 2 s . com*/ } InputStream in; try { in = rootResource.getInputStream(); } catch (IOException e) { throw new DataAccessResourceFailureException( "Could not get an input stream for resource '" + rootResource + "'; nested exception: " + e, e); } Events events; try { events = CastorUtils.unmarshalWithTranslatedExceptions(Events.class, in); } finally { IOUtils.closeQuietly(in); } processEvents(events, rootResource, eventConfiguration, resourceDescription, denyIncludes); return events; }
From source file:org.opennms.netmgt.config.DefaultEventConfDao.java
/** * <p>saveCurrent</p>/*www .j a v a 2 s .co m*/ */ public synchronized void saveCurrent() { for (Entry<Resource, Events> entry : getEventConfiguration().getEventFiles().entrySet()) { Resource resource = entry.getKey(); Events fileEvents = entry.getValue(); StringWriter stringWriter = new StringWriter(); try { CastorUtils.marshalWithTranslatedExceptions(fileEvents, stringWriter); } catch (DataAccessException e) { throw new DataAccessResourceFailureException( "Could not marshal configuration file for " + resource + ": " + e, e); } if (stringWriter.toString() != null) { File file; try { file = resource.getFile(); } catch (IOException e) { throw new DataAccessResourceFailureException("Event resource '" + resource + "' is not a file resource and cannot be saved. Nested exception: " + e, e); } Writer fileWriter; try { fileWriter = new OutputStreamWriter(new FileOutputStream(file), "UTF-8"); } catch (IOException e) { throw new DataAccessResourceFailureException( "Event file '" + file + "' could not be opened. Nested exception: " + e, e); } try { fileWriter.write(stringWriter.toString()); } catch (IOException e) { throw new DataAccessResourceFailureException( "Event file '" + file + "' could not be written to. Nested exception: " + e, e); } try { fileWriter.close(); } catch (IOException e) { throw new DataAccessResourceFailureException( "Event file '" + file + "' could not be closed. Nested exception: " + e, e); } } } File programmaticStoreFile; try { programmaticStoreFile = getProgrammaticStoreConfigResource().getFile(); } catch (IOException e) { log().info("Programmatic store resource '" + getProgrammaticStoreConfigResource() + "'; not attempting to delete an unused programmatic store file if it exists (since we can't test for it)."); programmaticStoreFile = null; } if (programmaticStoreFile != null) { // Delete the programmatic store if it exists on disk, but isn't in the main store. This is for cleanliness if (programmaticStoreFile.exists() && (!getEventConfiguration().getEventFiles() .containsKey(getProgrammaticStoreConfigResource()))) { log().info( "Deleting programmatic store configuration file because it is no longer referenced in the root config file " + getConfigResource()); if (!programmaticStoreFile.delete()) { LogUtils.warnf(this, "Attempted to delete %s, but failed.", programmaticStoreFile); } } } /* * XXX Should we call reload so that the EventConfData object is updated * without the caller having to call reload() themselves? */ //reload(); }