List of usage examples for org.springframework.dao DataRetrievalFailureException DataRetrievalFailureException
public DataRetrievalFailureException(String msg)
From source file:com._4dconcept.springframework.data.marklogic.core.MarklogicTemplate.java
@Nullable @Override/* w ww. j a v a2 s . co m*/ public <T> T invokeModule(String moduleName, Class<T> resultClass, MarklogicInvokeOperationOptions options) { List<T> resultList = invokeModuleAsList(moduleName, resultClass, options); if (CollectionUtils.isEmpty(resultList)) { return null; } else if (resultList.size() == 1) { return resultList.get(0); } else { throw new DataRetrievalFailureException( "Only one result expected. You should probably call invokeModuleAsList instead"); } }
From source file:com._4dconcept.springframework.data.marklogic.core.MarklogicTemplate.java
@Override public <T> T invokeAdhocQuery(String query, Class<T> resultClass, MarklogicInvokeOperationOptions options) { List<T> resultList = invokeAdhocQueryAsList(query, resultClass, options); if (CollectionUtils.isEmpty(resultList)) { return null; } else if (resultList.size() == 1) { return resultList.get(0); } else {// w w w.j a v a 2 s.c o m throw new DataRetrievalFailureException( "Only one result expected. You should probably call invokeAdhocQueryAsList instead"); } }
From source file:ei.ne.ke.cassandra.cql3.AstyanaxCql3Repository.java
/** * {@inheritDoc}/*from ww w . j a v a2s.co m*/ */ @Override public synchronized T findOne(ID id) { try { String cql = cqlGen.buildFindOneStatement(); PreparedCqlQuery<String, String> preparedStatement = doPreparedCqlRead(cql); Map<String, ByteBuffer> serializedKeyValues = spec.getSerializedKeyValues(id); for (String column : spec.getKeyColumns()) { preparedStatement = preparedStatement.withValue(serializedKeyValues.get(column)); } OperationResult<CqlResult<String, String>> opResult = preparedStatement.execute(); LOGGER.debug("attempts: {}, latency: {}ms", opResult.getAttemptsCount(), opResult.getLatency(TimeUnit.MILLISECONDS)); CqlResult<String, String> resultSet = opResult.getResult(); Rows<String, String> resultSetRows = resultSet.getRows(); if (resultSetRows.isEmpty()) { return null; } else if (resultSetRows.size() > 1) { throw new DataRetrievalFailureException("Got several rows for single key"); } else { Row<String, String> row = resultSetRows.getRowByIndex(0); ColumnList<String> columns = row.getColumns(); return spec.map(columns); } } catch (ConnectionException e) { throw new DataRetrievalFailureException("Error while executing CQL3 query", e); } }
From source file:com.thinkbiganalytics.schema.QueryRunner.java
/** * Executes the specified SELECT query and returns the results. * * @param query the SELECT query/*from ww w . j av a2 s .co m*/ * @return the query result * @throws DataAccessException if the query cannot be executed */ public QueryResult query(String query) { // Validate the query if (!validateQuery(query)) { throw new DataRetrievalFailureException("Invalid query: " + query); } // Execute the query final DefaultQueryResult queryResult = new DefaultQueryResult(query); jdbcTemplate.query(query, rs -> { // First-time initialization if (queryResult.isEmpty()) { initQueryResult(queryResult, rs.getMetaData()); } // Add row to the result final Map<String, Object> row = new LinkedHashMap<>(); for (final QueryResultColumn column : queryResult.getColumns()) { row.put(column.getDisplayName(), rs.getObject(column.getHiveColumnLabel())); } queryResult.addRow(row); }); return queryResult; }
From source file:com.thoughtworks.go.server.dao.PipelineSqlMapDao.java
public Pipeline pipelineWithMaterialsAndModsByBuildId(long buildId) { String cacheKey = this.cacheKeyGenerator.generate("getPipelineByBuildId", buildId); return pipelineByBuildIdCache.get(cacheKey, new Supplier<Pipeline>() { @Override/*from ww w .j av a 2 s . c o m*/ public Pipeline get() { Pipeline pipeline = (Pipeline) getSqlMapClientTemplate().queryForObject("getPipelineByBuildId", buildId); if (pipeline == null) { throw new DataRetrievalFailureException( "Could not load pipeline from build with id " + buildId); } return loadMaterialRevisions(pipeline); } }); }
From source file:com.thoughtworks.go.server.dao.PipelineSqlMapDao.java
public Pipeline pipelineByIdWithMods(long pipelineId) { Pipeline pipeline = (Pipeline) getSqlMapClientTemplate().queryForObject("pipelineById", pipelineId); if (pipeline == null) { throw new DataRetrievalFailureException("Could not load pipeline with id " + pipelineId); }//w w w .j a v a 2s .com return loadMaterialRevisions(pipeline); }
From source file:net.paoding.rose.jade.statement.UpdateQuerier.java
private Object executeSingle(StatementRuntime runtime, Class<?> returnType) { Number result;/* w ww . jav a 2s . c om*/ DataAccess dataAccess = dataAccessProvider.getDataAccess(// runtime.getMetaData(), runtime.getProperties()); if (returnGeneratedKeys) { ArrayList<Number> keys = new ArrayList<Number>(1); KeyHolder generatedKeyHolder = new GeneratedKeyHolder(keys); dataAccess.update(runtime.getSQL(), runtime.getArgs(), generatedKeyHolder); if (keys.size() > 0) { result = generatedKeyHolder.getKey(); } else { result = null; } } else { result = new Integer(dataAccess.update(runtime.getSQL(), runtime.getArgs(), null)); } // if (result == null || returnType == void.class) { return null; } if (returnType == result.getClass()) { return result; } // ? if (returnType == Integer.class) { return result.intValue(); } else if (returnType == Long.class) { return result.longValue(); } else if (returnType == Boolean.class) { return result.intValue() > 0 ? Boolean.TRUE : Boolean.FALSE; } else if (returnType == Double.class) { return result.doubleValue(); } else if (returnType == Float.class) { return result.floatValue(); } else if (Number.class.isAssignableFrom(returnType)) { return result; } else { throw new DataRetrievalFailureException("The generated key is not of a supported numeric type. " + "Unable to cast [" + result.getClass().getName() + "] to [" + Number.class.getName() + "]"); } }
From source file:org.acegisecurity.acl.basic.cache.EhCacheBasedAclEntryCache.java
public BasicAclEntry[] getEntriesFromCache(AclObjectIdentity aclObjectIdentity) { Element element = null;/*from w w w.j a v a 2 s.co m*/ try { element = cache.get(aclObjectIdentity); } catch (CacheException cacheException) { throw new DataRetrievalFailureException("Cache failure: " + cacheException.getMessage()); } // Return null if cache element has expired or not found if (element == null) { if (logger.isDebugEnabled()) { logger.debug("Cache miss: " + aclObjectIdentity); } return null; } if (logger.isDebugEnabled()) { logger.debug("Cache hit: " + (element != null) + "; object: " + aclObjectIdentity); } BasicAclEntryHolder holder = (BasicAclEntryHolder) element.getValue(); return holder.getBasicAclEntries(); }
From source file:org.acegisecurity.acl.basic.jdbc.JdbcExtendedDaoImpl.java
public void changeMask(AclObjectIdentity aclObjectIdentity, Object recipient, Integer newMask) throws DataAccessException { basicAclEntryCache.removeEntriesFromCache(aclObjectIdentity); // Retrieve acl_object_identity record details AclDetailsHolder aclDetailsHolder = lookupAclDetailsHolder(aclObjectIdentity); // Retrieve applicable acl_permission.id long permissionId = lookupPermissionId(aclDetailsHolder.getForeignKeyId(), recipient.toString()); if (permissionId == -1) { throw new DataRetrievalFailureException( "Could not locate existing acl_permission for aclObjectIdentity: " + aclObjectIdentity + ", recipient: " + recipient.toString()); }/*w ww.ja v a 2 s. c om*/ // Change permission aclPermissionUpdate.update(new Long(permissionId), newMask); }
From source file:org.acegisecurity.acl.basic.jdbc.JdbcExtendedDaoImpl.java
/** * Convenience method that obtains a given acl_object_identity record. * * @param aclObjectIdentity to lookup// w w w .ja v a2 s.c om * * @return details of the record * * @throws DataRetrievalFailureException if record could not be found */ private AclDetailsHolder lookupAclDetailsHolder(AclObjectIdentity aclObjectIdentity) throws DataRetrievalFailureException { String aclObjectIdentityString = convertAclObjectIdentityToString(aclObjectIdentity); // Lookup the object's main properties from the RDBMS (guaranteed no nulls) List objects = objectProperties.execute(aclObjectIdentityString); if (objects.size() == 0) { throw new DataRetrievalFailureException("aclObjectIdentity not found: " + aclObjectIdentityString); } // Should only be one record return (AclDetailsHolder) objects.get(0); }