List of usage examples for org.springframework.dao DataAccessResourceFailureException DataAccessResourceFailureException
public DataAccessResourceFailureException(String msg)
From source file:org.jasig.cas.adaptors.ldap.util.AuthenticatedLdapContextSource.java
public DirContext getDirContext(final String principal, final String credentials) { final Hashtable<String, String> environment = (Hashtable) getAnonymousEnv().clone(); environment.put(Context.SECURITY_PRINCIPAL, principal); environment.put(Context.SECURITY_CREDENTIALS, credentials); environment.remove("com.sun.jndi.ldap.connect.pool"); // remove this since we're modifying principal try {/* www. j a v a 2 s. c o m*/ return getDirContextInstance(environment); } catch (final NamingException e) { throw new DataAccessResourceFailureException("Unable to create DirContext"); } }
From source file:cz.muni.pa165.carparkapp.Service.BranchServiceImplTest.java
@Before public void setUp() { branch1 = new Branch(); branch1.setId(1);// w w w .j av a2 s.com branch1.setAddress("Brno"); branch1.setCompanyNumber("123456"); branch1.setName("Pobocka 45"); branchdto1 = new BranchDTO(); branchdto1.setId(1); branchdto1.setAddress("Brno"); branchdto1.setCompanyNumber("123456"); branchdto1.setName("Pobocka 45"); branchdto2 = new BranchDTO(); branchdto2.setId(2); branchdto2.setAddress("Praha"); branchdto2.setCompanyNumber("987654"); branchdto2.setName("Pobocka 89"); Mockito.when(branchDaoImplMock.createBranch(Matchers.any(Branch.class))).thenAnswer(new Answer<Branch>() { @Override public Branch answer(InvocationOnMock invocation) throws Throwable { Object[] args = invocation.getArguments(); return (Branch) args[0]; } }); Mockito.when(branchDaoImplMock.updateBranch(Matchers.any(Branch.class))).thenReturn(true); Mockito.when(branchDaoImplMock.findBranch(branch1.getId())).thenReturn(branch1); Mockito.when(branchDaoImplMock.deleteBranch(Matchers.any(Branch.class))).thenReturn(true); Mockito.when(branchDaoImplMock.createBranch(null)) .thenThrow(new DataAccessResourceFailureException("Error occured during storing Branch.")); Mockito.when(branchDaoImplMock.updateBranch(null)) .thenThrow(new DataAccessResourceFailureException("Error occured during updating Branch.")); Mockito.when(branchDaoImplMock.deleteBranch(null)) .thenThrow(new DataAccessResourceFailureException("Error occured during deleting Branch.")); Mockito.when(branchDaoImplMock.findBranch(-1)) .thenThrow(new DataAccessResourceFailureException("Error occured during getting Branch.")); }
From source file:edu.wisc.my.portlets.bookmarks.dao.file.FileSystemBookmarkStore.java
/** * @see edu.wisc.my.portlets.bookmarks.dao.BookmarkStore#getBookmarkSet(java.lang.String, java.lang.String) *//*from ww w .j a va2 s. co m*/ public BookmarkSet getBookmarkSet(String owner, String name) { final File storeFile = this.getStoreFile(owner, name); //Ok if the file doesn't exist, the user hasn't stored one yet. if (!storeFile.exists()) { return null; } try { final FileInputStream fis = new FileInputStream(storeFile); final BufferedInputStream bis = new BufferedInputStream(fis); final XMLDecoder d = new XMLDecoder(bis); try { final BookmarkSet bs = (BookmarkSet) d.readObject(); return bs; } finally { d.close(); } } catch (FileNotFoundException fnfe) { final String errorMsg = "Error reading BookmarkSet for owner='" + owner + "', name='" + name + "' from file='" + storeFile + "'"; logger.error(errorMsg, fnfe); throw new DataAccessResourceFailureException(errorMsg); } }
From source file:ar.com.zauber.commons.spring.exceptions.StatusSimpleMappingExceptionHandlerTest.java
/** test */ public final void testFoo() { final Properties views = new Properties(); views.put(NotOwnerException.class.getName(), "notowner"); views.put(IllegalArgumentException.class.getName(), "arguments"); views.put(DataAccessResourceFailureException.class.getName(), "data"); final Properties status = new Properties(); status.put("arguments", "400"); status.put("notowner", "403"); status.put("data", "500"); final StatusSimpleMappingExceptionHandler h = new StatusSimpleMappingExceptionHandler(); h.setDefaultStatusCode(200);//from w w w. j a v a2 s. c o m h.setExceptionMappings(views); h.setStatusMappings(status); h.setDefaultErrorView("default"); MockHttpServletResponse response; ModelAndView v; response = new MockHttpServletResponse(); v = h.resolveException(new MockHttpServletRequest(), response, null, new IOException("io!io!")); assertEquals("default", v.getViewName()); assertEquals(200, response.getStatus()); response = new MockHttpServletResponse(); v = h.resolveException(new MockHttpServletRequest(), response, null, new IllegalArgumentException("asdasd")); assertEquals("arguments", v.getViewName()); assertEquals(400, response.getStatus()); response = new MockHttpServletResponse(); v = h.resolveException(new MockHttpServletRequest(), response, null, new NotOwnerException()); assertEquals("notowner", v.getViewName()); assertEquals(403, response.getStatus()); response = new MockHttpServletResponse(); v = h.resolveException(new MockHttpServletRequest(), response, null, new DataAccessResourceFailureException("bla bla")); assertEquals("data", v.getViewName()); assertEquals(500, response.getStatus()); }
From source file:org.guzz.web.context.spring.SpringWriteTemplate.java
/** * Return a Session for use by this template. * <p>Returns a new Session in case of "alwaysUseNewSession" (using the same * JDBC Connection as a transactional Session, if applicable), a pre-bound * Session in case of "allowCreate" turned off, and a pre-bound or new Session * otherwise (new only if no transactional or otherwise pre-bound Session exists). * @return the Session to use (never <code>null</code>) * @see TransactionManagerUtils#getSession * @see TransactionManagerUtils#getNewSession * @see #setAlwaysUseNewSession/*from w w w. j a va 2s. c o m*/ * @see #setAllowCreate */ protected WriteTranSession getSession() { if (TransactionManagerUtils.hasTransactionalSession(getTransactionManager())) { return TransactionManagerUtils.getSession(getTransactionManager()); } else { throw new DataAccessResourceFailureException( "Could not obtain current thread-bounded Guzz WriteTranSession."); } }
From source file:de.tudarmstadt.ukp.csniper.webapp.search.tgrep.TgrepQuery.java
private List<EvaluationItem> parseOutput(List<String> aOutput) { List<EvaluationItem> items = new ArrayList<EvaluationItem>(); if (aOutput.size() % LINES_PER_MATCH > 0) { throw new DataAccessResourceFailureException("Tgrep2 produced [" + aOutput.size() + "] output lines, but should have produced a multiple of [" + LINES_PER_MATCH + "]."); } else {//from w w w . j a v a 2 s .co m String[] comment; String text; int tokenBeginIndex; int tokenEndIndex; for (Iterator<String> it = aOutput.iterator(); it.hasNext();) { // comment - split into documentId, beginOffset, endOffset comment = it.next().substring(2).split(TgrepEngine.COMMENT_SEPARATOR); if (comment.length < 3) { throw new DataAccessResourceFailureException("The corpus contains a malformed comment line [" + StringUtils.join(comment, " ,") + "]."); } String documentId = comment[META_DOCUMENT_ID]; int beginOffset = Integer.parseInt(comment[META_BEGIN_OFFSET]); int endOffset = Integer.parseInt(comment[META_END_OFFSET]); // text string - trim and replace bracket placeholders text = it.next().trim(); text = StringUtils.replace(text, LEFT_BRACKET, "("); text = StringUtils.replace(text, RIGHT_BRACKET, ")"); // token index of first token in match (tgrep indices are 1-based, make them // 0-based) tokenBeginIndex = Integer.parseInt(it.next()) - 1; // token index of last token in match (tgrep indices are 1-based, make them 0-based) tokenEndIndex = Integer.parseInt(it.next()) - 1; // set corpus position to -1; this is cqp specific and we don't use it atm EvaluationItem item = new EvaluationItem(corpus, documentId, type, beginOffset, endOffset, text); // text-based (i.e. sentence-based) offsets (+1 to skip the whitespace itself) int matchBegin = StringUtils.ordinalIndexOf(text, " ", tokenBeginIndex) + 1; int matchEnd = StringUtils.ordinalIndexOf(text, " ", tokenEndIndex + 1); item.setMatchOnItemText(matchBegin, matchEnd); item.setMatchOnOriginalTextViaTokenIndicesAndLookGoodWhileDoingSo(tokenBeginIndex, tokenEndIndex); items.add(item); } } return items; }
From source file:org.dkpro.lab.engine.impl.DefaultTaskContext.java
@Override public TaskContextMetadata resolve(URI aUri) { StorageService storage = getStorageService(); if (LATEST_CONTEXT_SCHEME.equals(aUri.getScheme())) { try {// w ww. ja v a2 s.co m return storage.getLatestContext(aUri.getAuthority(), extractConstraints(aUri)); } catch (TaskContextNotFoundException e) { throw new UnresolvedImportException(this, aUri.toString(), e); } } else if (CONTEXT_ID_SCHEME.equals(aUri.getScheme())) { try { return storage.getContext(aUri.getAuthority()); } catch (TaskContextNotFoundException e) { throw new UnresolvedImportException(this, aUri.toString(), e); } } else { throw new DataAccessResourceFailureException("Unknown scheme in import [" + aUri + "]"); } }
From source file:org.opennms.ng.dao.support.PropertiesGraphDao.java
/** * @param type// ww w . j a v a 2 s. c om * - a PrefabGraphType in which graphs * found in 'properties' will be stored * @param properties * - a properties object, usually loaded from a File or * InputStream, with graph definitions in it * @return A list of the graphs found. THIS LIST MAY CONTAIN NULL ENTRIES, one for each * graph in a multi-graph file that failed to load (e.g. missing properties). Other than * logging an error, this is the only way this method indicates a problem with just one graph * The only cause for a real exception is if there's neither a "reports" nor a "report.id" * property, which cannot be recovered from */ private List<PrefabGraph> loadPrefabGraphDefinitions(PrefabGraphTypeDao type, Properties properties) { Assert.notNull(properties, "properties argument cannot be null"); List<PrefabGraph> result = new ArrayList<PrefabGraph>(); String listString = properties.getProperty(DEFAULT_GRAPH_LIST_KEY); // Optional String[] list; if (listString != null) { list = BundleLists.parseBundleList(listString); } else { // A report-per-file properties file; just use the report.id // At this stage, if there was no "reports", then there *must* be // a report.id, otherwise we're pooched list = new String[1]; try { list[0] = getProperty(properties, "report.id"); } catch (DataAccessResourceFailureException e) { // Special case; if this exception is thrown, then report.id // was missing // But, we need to be more clear in the report (no report.id // *or* "reports" property). However, we shouldn't throw // an exception, because that would break loading of all // graphs if just one file was broken throw new DataAccessResourceFailureException( "Properties must " + "contain a 'report.id' property " + "or a 'reports' property"); } } for (String name : list) { try { PrefabGraph graph = makePrefabGraph(name, properties, type.getNextOrdering()); result.add(graph); } catch (DataAccessResourceFailureException e) { LOG.error("Failed to load report '{}'", name, e); result.add(null); //Add a null, indicating a broken graph } } return result; }
From source file:org.grails.datastore.mapping.gemfire.engine.GemfireEntityPersister.java
private Object generateIdentifier(final PersistentEntity persistentEntity, final EntityAccess access) { final GemfireTemplate template = gemfireDatastore.getTemplate(persistentEntity); return template.execute(new GemfireCallback() { public Object doInGemfire(Region region) throws GemFireCheckedException, GemFireException { KeyValue mf = (KeyValue) gemfireDatastore.getMappingContext().getMappingFactory() .createMappedForm(persistentEntity.getIdentity()); if ("uuid".equals(mf.getGenerator())) { String uuid = UUID.randomUUID().toString(); access.setIdentifier(uuid); return uuid; }// w w w .j a va2s . c om Cache cache = CacheFactory.getAnyInstance(); final int uuid = PartitionedRegion .generatePRId((InternalDistributedSystem) cache.getDistributedSystem(), cache); if (uuid == 0) { throw new DataAccessResourceFailureException("Unable to generate Gemfire UUID"); } long finalId = identifierGenerator.getAndIncrement() + uuid; access.setIdentifier(finalId); return finalId; } }); }
From source file:org.opennms.ng.dao.support.PropertiesGraphDao.java
private String getProperty(Properties props, String name) { String property = props.getProperty(name); if (property == null) { throw new DataAccessResourceFailureException("Properties must " + "contain \'" + name + "\' property"); }// w w w.j a v a 2s .c o m return property; }