List of usage examples for org.springframework.dao DataAccessResourceFailureException DataAccessResourceFailureException
public DataAccessResourceFailureException(String msg, @Nullable Throwable cause)
From source file:com.jpeterson.littles3.dao.je.JeBucketDao.java
public void storeBucket(Bucket bucket) throws DataAccessException { DatabaseEntry theKey;//from ww w .j av a 2 s .c o m DatabaseEntry theData; // Environment myDbEnvironment = null; Database database = null; try { theKey = new DatabaseEntry(bucket.getName().getBytes("UTF-8")); theData = new DatabaseEntry(); bucketBinding.objectToEntry(bucket, theData); database = jeCentral.getDatabase(JeCentral.BUCKET_DB_NAME); database.put(null, theKey, theData); } catch (DatabaseException e) { throw new DataAccessResourceFailureException("Unable to load a database record", e); } catch (UnsupportedEncodingException e) { // should not happen e.printStackTrace(); } }
From source file:edu.wisc.my.portlets.bookmarks.dao.file.FileSystemBookmarkStore.java
/** * @see edu.wisc.my.portlets.bookmarks.dao.BookmarkStore#storeBookmarkSet(edu.wisc.my.portlets.bookmarks.domain.BookmarkSet) *//*from w ww .j ava 2 s. c o m*/ public void storeBookmarkSet(BookmarkSet bookmarkSet) { if (bookmarkSet == null) { throw new IllegalArgumentException("AddressBook may not be null"); } final File storeFile = this.getStoreFile(bookmarkSet.getOwner(), bookmarkSet.getName()); try { final FileOutputStream fos = new FileOutputStream(storeFile); final BufferedOutputStream bos = new BufferedOutputStream(fos); final XMLEncoder e = new XMLEncoder(bos); try { e.writeObject(bookmarkSet); } finally { e.close(); } } catch (FileNotFoundException fnfe) { final String errorMsg = "Error storing BookmarkSet='" + bookmarkSet + "' to file='" + storeFile + "'"; logger.error(errorMsg, fnfe); throw new DataAccessResourceFailureException(errorMsg, fnfe); } }
From source file:org.grails.datastore.mapping.cassandra.engine.CassandraEntityPersister.java
@Override protected KeyValueEntry retrieveEntry(PersistentEntity persistentEntity, String family, Serializable nativeKey) { final ClassMapping cm = getPersistentEntity().getMapping(); final String keyspaceName = getKeyspace(cm, CassandraDatastore.DEFAULT_KEYSPACE); final Keyspace keyspace; try {//from w ww . j a v a2s. com keyspace = cassandraClient.getKeyspace(keyspaceName); } catch (HectorException e) { throw new DataAccessResourceFailureException("Exception occurred invoking Cassandra: " + e.getMessage(), e); } SuperColumn sc = getSuperColumn(keyspace, family, nativeKey); KeyValueEntry entry = new KeyValueEntry(family); if (sc != null) { for (Column column : sc.getColumns()) { entry.put(string(column.getName()), string(column.getValue())); } } if (entry.isEmpty()) { return null; } return entry; }
From source file:ar.com.zauber.commons.repository.closures.OpenEntityManagerClosure.java
/** @see Closure#execute(Object) */ public final void execute(final T t) { if (dryrun) { //permite evitar que se hagan commit() en el ambiente de test target.execute(t);/*from w w w . j av a 2 s .c o m*/ } else { boolean participate = false; EntityTransaction transaction = null; if (TransactionSynchronizationManager.hasResource(emf)) { // Do not modify the EntityManager: just set the participate flag. participate = true; } else { try { final EntityManager em = emf.createEntityManager(); if (openTx) { if (!warningPrinted) { logger.warn( "The OpenEntityManagerClosure has Transactions enabled and is not recommended" + ". This behaviour will change in the future. Check setOpenTx(), "); } transaction = em.getTransaction(); transaction.begin(); } TransactionSynchronizationManager.bindResource(emf, new EntityManagerHolder(em)); } catch (PersistenceException ex) { throw new DataAccessResourceFailureException("Could not create JPA EntityManager", ex); } } if (transaction != null) { try { target.execute(t); if (transaction.getRollbackOnly()) { transaction.rollback(); } else { transaction.commit(); } } catch (final Throwable e) { if (transaction != null && transaction.isActive()) { transaction.rollback(); } throw new UnhandledException(e); } finally { if (!participate) { final EntityManagerHolder emHolder = (EntityManagerHolder) TransactionSynchronizationManager .unbindResource(emf); EntityManagerFactoryUtils.closeEntityManager(emHolder.getEntityManager()); } } } else { try { target.execute(t); } finally { if (!participate) { final EntityManagerHolder emHolder = (EntityManagerHolder) TransactionSynchronizationManager .unbindResource(emf); EntityManagerFactoryUtils.closeEntityManager(emHolder.getEntityManager()); } } } } }
From source file:org.guzz.web.context.spring.TransactionManagerUtils.java
/** * Get a Guzz WriteTranSession for the given TransactionManager. Is aware of and will * return any existing corresponding Session bound to the current thread, for * example when using {@link GuzzTransactionManager}. Will create a new * Session otherwise, if "allowCreate" is <code>true</code>. * <p>This is the <code>getSession</code> method used by typical data access code, * in combination with <code>releaseSession</code> called when done with * the Session. Note that SpringWriteTemplate allows to write data access code * without caring about such resource handling. * @param transactionManager Guzz TransactionManager to create the session with * @param allowCreate whether a non-transactional Session should be created * when no transactional Session can be found for the current thread * @return the Guzz WriteTranSession// www . j a va 2 s. c o m * @throws DataAccessResourceFailureException if the Session couldn't be created * @throws IllegalStateException if no thread-bound Session found and * "allowCreate" is <code>false</code> * @see #getSession(TransactionManager, Interceptor, SQLExceptionTranslator) * @see #releaseSession * @see SpringWriteTemplate */ public static WriteTranSession getSession(TransactionManager transactionManager) throws DataAccessResourceFailureException, IllegalStateException { try { return doGetSession(transactionManager); } catch (GuzzException ex) { throw new DataAccessResourceFailureException("Could not open Guzz WriteTranSession", ex); } }
From source file:com.jpeterson.littles3.dao.je.JeBucketDao.java
public void removeBucket(Bucket bucket) throws DataAccessException { DatabaseEntry theKey;/*from w ww . j a va2s. c o m*/ // Environment myDbEnvironment = null; Database database = null; try { theKey = new DatabaseEntry(bucket.getName().getBytes("UTF-8")); database = jeCentral.getDatabase(JeCentral.BUCKET_DB_NAME); database.delete(null, theKey); } catch (DatabaseException e) { throw new DataAccessResourceFailureException("Unable to load a database record", e); } catch (UnsupportedEncodingException e) { // should not happen e.printStackTrace(); } }
From source file:ru.adios.budgeter.BundleProvider.java
private static void transferFile(String source, String destination, String errMsg) { final File sourceFile = new File(source); final File destFile = new File(destination); FileChannel fcSource = null;/*from w w w. j ava 2s . c om*/ FileChannel fcDest = null; try { fcSource = new FileInputStream(sourceFile).getChannel(); fcDest = new FileOutputStream(destFile).getChannel(); fcDest.transferFrom(fcSource, 0, fcSource.size()); fcSource.close(); fcDest.close(); } catch (IOException e) { logger.error(errMsg, e); throw new DataAccessResourceFailureException(errMsg, e); } finally { try { if (fcSource != null) { fcSource.close(); } if (fcDest != null) { fcDest.close(); } } catch (IOException ignore) { logger.warn("Exception while closing IO channels", ignore); } } }
From source file:org.opennms.ng.dao.support.DefaultRrdDao.java
/** * <p>getPrintValues</p>/* w w w .ja v a2 s . c o m*/ * * @param attribute a {@link org.opennms.netmgt.model.OnmsAttribute} object. * @param rraConsolidationFunction a {@link String} object. * @param startTimeInMillis a long. * @param endTimeInMillis a long. * @param printFunctions a {@link String} object. * @return an array of double. */ @Override public double[] getPrintValues(OnmsAttribute attribute, String rraConsolidationFunction, long startTimeInMillis, long endTimeInMillis, String... printFunctions) { Assert.notNull(attribute, "attribute argument must not be null"); Assert.notNull(rraConsolidationFunction, "rraConsolicationFunction argument must not be null"); Assert.isTrue(endTimeInMillis > startTimeInMillis, "end argument must be after start argument"); Assert.isAssignable(attribute.getClass(), RrdGraphAttribute.class, "attribute argument must be assignable to RrdGraphAttribute"); // if no printFunctions are given just use the rraConsolidationFunction if (printFunctions.length < 1) { printFunctions = new String[] { rraConsolidationFunction }; } RrdGraphAttribute rrdAttribute = (RrdGraphAttribute) attribute; String[] command = new String[] { m_rrdBinaryPath, "graph", "-", "--start=" + (startTimeInMillis / 1000), "--end=" + (endTimeInMillis / 1000), "DEF:ds=" + RrdFileConstants.escapeForGraphing(rrdAttribute.getRrdRelativePath()) + ":" + attribute.getName() + ":" + rraConsolidationFunction, }; String[] printDefs = new String[printFunctions.length]; for (int i = 0; i < printFunctions.length; i++) { printDefs[i] = "PRINT:ds:" + printFunctions[i] + ":\"%le\""; } String commandString = StringUtils.arrayToDelimitedString(command, " ") + ' ' + StringUtils.arrayToDelimitedString(printDefs, " "); LOG.debug("commandString: {}", commandString); RrdGraphDetails graphDetails; try { graphDetails = m_rrdStrategy.createGraphReturnDetails(commandString, m_rrdBaseDirectory); } catch (Throwable e) { throw new DataAccessResourceFailureException( "Failure when generating graph to get data with command '" + commandString + "'", e); } String[] printLines; try { printLines = graphDetails.getPrintLines(); } catch (Throwable e) { throw new DataAccessResourceFailureException( "Failure to get print lines from graph after graphing with command '" + commandString + "'", e); } if (printLines.length != printFunctions.length) { throw new DataAccessResourceFailureException("Returned number of print lines should be " + printFunctions.length + ", but was " + printLines.length + " from command: " + commandString); } double[] values = new double[printLines.length]; for (int i = 0; i < printLines.length; i++) { if (printLines[i].endsWith("nan")) { values[i] = Double.NaN; } else { try { values[i] = Double.parseDouble(printLines[i]); } catch (NumberFormatException e) { throw new DataAccessResourceFailureException("Value of line " + (i + 1) + " of output from RRD is not a valid floating point number: '" + printLines[i] + "'"); } } } return values; }
From source file:de.tudarmstadt.ukp.csniper.webapp.search.tgrep.TgrepQuery.java
@Override public List<EvaluationItem> execute() { BufferedReader brInput = null; BufferedReader brError = null; List<String> output = new ArrayList<String>(); List<String> error = new ArrayList<String>(); try {//from ww w.j a v a 2 s .c o m List<String> cmd = new ArrayList<String>(); File exe = engine.getTgrepExecutable(); if (!exe.canExecute()) { exe.setExecutable(true); } cmd.add(exe.getAbsolutePath()); // specify corpus cmd.add("-c"); cmd.add(engine.getCorpusPath(corpus)); // only one match per sentence cmd.add("-f"); // print options cmd.add("-m"); // comment // full sentence // match begin token index // match end token index cmd.add("%c\\n%tw\\n%ym\\n%zm\\n"); // pattern to search for cmd.add(query); if (log.isTraceEnabled()) { log.trace("Invoking [" + StringUtils.join(cmd, " ") + "]"); } final ProcessBuilder pb = new ProcessBuilder(cmd); tgrep = pb.start(); brInput = new BufferedReader(new InputStreamReader(tgrep.getInputStream(), "UTF-8")); brError = new BufferedReader(new InputStreamReader(tgrep.getErrorStream(), "UTF-8")); String line; while ((line = brInput.readLine()) != null) { if (log.isTraceEnabled()) { log.trace("<< " + line); } output.add(line); } while ((line = brError.readLine()) != null) { if (log.isErrorEnabled()) { log.error(line); } error.add(line); } if (!error.isEmpty()) { throw new IOException(StringUtils.join(error, " ")); } } catch (IOException e) { throw new DataAccessResourceFailureException("Unable to start Tgrep process.", e); } finally { IOUtils.closeQuietly(brInput); IOUtils.closeQuietly(brError); } size = output.size() / LINES_PER_MATCH; if (maxResults >= 0 && size > maxResults) { return parseOutput(output.subList(0, LINES_PER_MATCH * maxResults)); } else { return parseOutput(output); } }
From source file:com.jpeterson.littles3.dao.je.JeS3ObjectDao.java
/** * This method retrieves the <code>S3Object</code> representation of an * object from the underlying JE database via the object's bucket and key. * // w w w . j av a2s. c o m * @param bucket * The bucket identifying the object. * @param key * The key identifying the object. * @return The <code>S3Object</code> identified by the provided * <code>bucket</code> + <code>key</code>. * @throws DataRetrievalFailureException * Could not find the <code>S3Object</code> for the provided * <code>bucket</code> and <code>key</code>. * @throws DataAccessResourceFailureException * General failure retrieving the GUID from the JE database. * @throws DataAccessException * General failure retrieving the GUID. */ public S3Object loadS3Object(String bucket, String key) throws DataAccessException { DatabaseEntry theKey; DatabaseEntry theData; // Environment myDbEnvironment = null; Database database = null; try { S3Object s3ObjectBucketKey = new S3ObjectBucketKey(); s3ObjectBucketKey.setBucket(bucket); s3ObjectBucketKey.setKey(key); theKey = new DatabaseEntry(); s3ObjectBucketKeyBinding.objectToEntry(s3ObjectBucketKey, theKey); theData = new DatabaseEntry(); // TODO: generalize this /* * EnvironmentConfig envConfig = new EnvironmentConfig(); * envConfig.setAllowCreate(true); myDbEnvironment = new * Environment(new File( "C:/temp/StorageEngine/db"), envConfig); * * DatabaseConfig dbConfig = new DatabaseConfig(); * dbConfig.setAllowCreate(true); database = * myDbEnvironment.openDatabase(null, "sampleDatabase", dbConfig); */ database = jeCentral.getDatabase(JeCentral.OBJECT_DB_NAME); if (database.get(null, theKey, theData, LockMode.DEFAULT) == OperationStatus.SUCCESS) { return (S3Object) fileS3ObjectBinding.entryToObject(theData); } else { throw new DataRetrievalFailureException("Could not find S3Object"); } } catch (DatabaseException e) { throw new DataAccessResourceFailureException("Unable to load a database record", e); } finally { /* * if (database != null) { try { database.close(); } catch * (DatabaseException e) { // do nothing } } database = null; * * if (myDbEnvironment != null) { try { myDbEnvironment.close(); } * catch (DatabaseException e) { // do nothing } } myDbEnvironment = * null; */ } }