List of usage examples for org.springframework.dao DataAccessResourceFailureException DataAccessResourceFailureException
public DataAccessResourceFailureException(String msg, @Nullable Throwable cause)
From source file:org.springframework.data.hadoop.pig.PigUtils.java
static DataAccessException convert(PigException ex) { if (ex instanceof BackendException) { return new DataAccessResourceFailureException("Backend Pig exception", ex); }/* w ww. jav a2s . c om*/ if (ex instanceof VisitorException || ex instanceof PlanException || ex instanceof SchemaMergeException) { return new InvalidDataAccessResourceUsageException("Plan failed", ex); } if (ex instanceof FrontendException) { if (ex instanceof JobCreationException) { return new InvalidDataAccessResourceUsageException("Map Reduce error", ex); } // work-around to let compilation on CDH3 if (PARSER_EXCEPTION != null && PARSER_EXCEPTION.isAssignableFrom(ex.getClass())) { return new InvalidDataAccessResourceUsageException("Syntax error", ex); } } return new NonTransientDataAccessResourceException("Unknown Pig error", ex); }
From source file:org.springframework.data.keyvalue.redis.connection.jedis.JedisConnectionFactory.java
/** * Returns a Jedis instance to be used as a Redis connection. * The instance can be newly created or retrieved from a pool. * // ww w .j ava 2 s .c o m * @return Jedis instance ready for wrapping into a {@link RedisConnection}. */ protected Jedis fetchJedisConnector() { try { if (usePool && pool != null) { return pool.getResource(); } Jedis jedis = new Jedis(getShardInfo()); // force initialization (see Jedis issue #82) jedis.connect(); return jedis; } catch (Exception ex) { throw new DataAccessResourceFailureException("Cannot get Jedis connection", ex); } }
From source file:org.springframework.data.solr.server.support.SolrClientUtils.java
/** * Close the {@link SolrClient} by calling {@link SolrClient#close()} or {@code shutdown} for the generation 5 * libraries./* w w w.j av a 2 s . com*/ * * @param solrClient must not be {@literal null}. * @throws DataAccessResourceFailureException * @since 2.1 */ public static void close(SolrClient solrClient) { Assert.notNull(solrClient, "SolrClient must not be null!"); try { if (solrClient instanceof Closeable) { solrClient.close(); } else { Method shutdownMethod = ReflectionUtils.findMethod(solrClient.getClass(), "shutdown"); if (shutdownMethod != null) { shutdownMethod.invoke(solrClient); } } } catch (Exception e) { throw new DataAccessResourceFailureException("Cannot close SolrClient", e); } }
From source file:org.springframework.jca.cci.core.CciTemplate.java
@Override @Nullable/*from w w w .j a v a 2s.c om*/ public <T> T execute(ConnectionCallback<T> action) throws DataAccessException { Assert.notNull(action, "Callback object must not be null"); ConnectionFactory connectionFactory = obtainConnectionFactory(); Connection con = ConnectionFactoryUtils.getConnection(connectionFactory, getConnectionSpec()); try { return action.doInConnection(con, connectionFactory); } catch (NotSupportedException ex) { throw new CciOperationNotSupportedException("CCI operation not supported by connector", ex); } catch (ResourceException ex) { throw new DataAccessResourceFailureException("CCI operation failed", ex); } catch (SQLException ex) { throw new InvalidResultSetAccessException("Parsing of CCI ResultSet failed", ex); } finally { ConnectionFactoryUtils.releaseConnection(con, getConnectionFactory()); } }
From source file:org.springframework.jdbc.core.AbstractBeanPropertyRowMapper.java
protected Object doMapRow(ResultSet rs, int rowNumber) throws SQLException { if (getMappedClass() == null) throw new InvalidDataAccessApiUsageException("Target class was not specified - it is mandatory"); Object result;//from w ww. java 2s.com try { result = this.defaultConstruct.newInstance((Object[]) null); } catch (IllegalAccessException e) { throw new DataAccessResourceFailureException("Failed to load class " + this.mappedClass.getName(), e); } catch (InvocationTargetException e) { throw new DataAccessResourceFailureException("Failed to load class " + this.mappedClass.getName(), e); } catch (InstantiationException e) { throw new DataAccessResourceFailureException("Failed to load class " + this.mappedClass.getName(), e); } ResultSetMetaData rsmd = rs.getMetaData(); int columns = rsmd.getColumnCount(); for (int i = 1; i <= columns; i++) { String column = JdbcUtils.lookupColumnName(rsmd, i).toLowerCase(); PersistentField fieldMeta = (PersistentField) this.mappedFields.get(column); if (fieldMeta != null) { BeanWrapper bw = new BeanWrapperImpl(mappedClass); bw.setWrappedInstance(result); fieldMeta.setSqlType(rsmd.getColumnType(i)); Object value = null; Class fieldType = fieldMeta.getJavaType(); if (fieldType.equals(String.class)) { value = rs.getString(column); } else if (fieldType.equals(byte.class) || fieldType.equals(Byte.class)) { value = new Byte(rs.getByte(column)); } else if (fieldType.equals(short.class) || fieldType.equals(Short.class)) { value = new Short(rs.getShort(column)); } else if (fieldType.equals(int.class) || fieldType.equals(Integer.class)) { value = new Integer(rs.getInt(column)); } else if (fieldType.equals(long.class) || fieldType.equals(Long.class)) { value = new Long(rs.getLong(column)); } else if (fieldType.equals(float.class) || fieldType.equals(Float.class)) { value = new Float(rs.getFloat(column)); } else if (fieldType.equals(double.class) || fieldType.equals(Double.class)) { value = new Double(rs.getDouble(column)); } else if (fieldType.equals(BigDecimal.class)) { value = rs.getBigDecimal(column); } else if (fieldType.equals(boolean.class) || fieldType.equals(Boolean.class)) { value = (rs.getBoolean(column)) ? Boolean.TRUE : Boolean.FALSE; } else if (fieldType.equals(java.util.Date.class) || fieldType.equals(java.sql.Timestamp.class) || fieldType.equals(java.sql.Time.class) || fieldType.equals(Number.class)) { value = JdbcUtils.getResultSetValue(rs, rs.findColumn(column)); } if (value != null) { if (bw.isWritableProperty(fieldMeta.getFieldName())) { try { if (logger.isDebugEnabled() && rowNumber == 0) { logger.debug("Mapping column named \"" + column + "\"" + " containing values of SQL type " + fieldMeta.getSqlType() + " to property \"" + fieldMeta.getFieldName() + "\"" + " of type " + fieldMeta.getJavaType()); } bw.setPropertyValue(fieldMeta.getFieldName(), value); } catch (NotWritablePropertyException ex) { throw new DataRetrievalFailureException( "Unable to map column " + column + " to property " + fieldMeta.getFieldName(), ex); } } else { if (rowNumber == 0) { logger.warn("Unable to access the setter for " + fieldMeta.getFieldName() + ". Check that " + "set" + StringUtils.capitalize(fieldMeta.getFieldName()) + " is declared and has public access."); } } } } } return result; }
From source file:org.springframework.jdbc.core.AbstractBeanPropertyRowMapper.java
/** * Initialize the mapping metadata/*from w w w . jav a 2 s . c om*/ * @param mappedClass */ protected void initialize(Class mappedClass) { this.mappedClass = mappedClass; try { this.defaultConstruct = mappedClass.getConstructor((Class[]) null); } catch (NoSuchMethodException ex) { throw new DataAccessResourceFailureException( new StringBuffer().append("Failed to access default or no-arg constructor of ") .append(mappedClass.getName()).toString(), ex); } this.mappedFields = new HashMap(); Class metaDataClass = mappedClass; while (metaDataClass != null) { Field[] f = metaDataClass.getDeclaredFields(); for (int i = 0; i < f.length; i++) { PersistentField pf = new PersistentField(); pf.setFieldName(f[i].getName()); pf.setJavaType(f[i].getType()); this.mappedFields.put(f[i].getName().toLowerCase(), pf); String underscoredName = underscoreName(f[i].getName()); if (!f[i].getName().toLowerCase().equals(underscoredName)) { this.mappedFields.put(underscoredName, pf); } } // try any superclass metaDataClass = metaDataClass.getSuperclass(); } }
From source file:org.springframework.jdbc.core.metadata.CallMetaDataProviderFactory.java
/** * Create a CallMetaDataProvider based on the database metadata * @param dataSource used to retrieve metadata * @param context the class that holds configuration and metadata * @return instance of the CallMetaDataProvider implementation to be used *///from w w w. j a va 2s.c o m static public CallMetaDataProvider createMetaDataProvider(DataSource dataSource, final CallMetaDataContext context) { try { CallMetaDataProvider result = (CallMetaDataProvider) JdbcUtils.extractDatabaseMetaData(dataSource, databaseMetaData -> { String databaseProductName = JdbcUtils .commonDatabaseName(databaseMetaData.getDatabaseProductName()); boolean accessProcedureColumnMetaData = context.isAccessCallParameterMetaData(); if (context.isFunction()) { if (!supportedDatabaseProductsForFunctions.contains(databaseProductName)) { if (logger.isWarnEnabled()) { logger.warn(databaseProductName + " is not one of the databases fully supported for function calls " + "-- supported are: " + supportedDatabaseProductsForFunctions); } if (accessProcedureColumnMetaData) { logger.warn( "Metadata processing disabled - you must specify all parameters explicitly"); accessProcedureColumnMetaData = false; } } } else { if (!supportedDatabaseProductsForProcedures.contains(databaseProductName)) { if (logger.isWarnEnabled()) { logger.warn(databaseProductName + " is not one of the databases fully supported for procedure calls " + "-- supported are: " + supportedDatabaseProductsForProcedures); } if (accessProcedureColumnMetaData) { logger.warn( "Metadata processing disabled - you must specify all parameters explicitly"); accessProcedureColumnMetaData = false; } } } CallMetaDataProvider provider; if ("Oracle".equals(databaseProductName)) { provider = new OracleCallMetaDataProvider(databaseMetaData); } else if ("DB2".equals(databaseProductName)) { provider = new Db2CallMetaDataProvider((databaseMetaData)); } else if ("Apache Derby".equals(databaseProductName)) { provider = new DerbyCallMetaDataProvider((databaseMetaData)); } else if ("PostgreSQL".equals(databaseProductName)) { provider = new PostgresCallMetaDataProvider((databaseMetaData)); } else if ("Sybase".equals(databaseProductName)) { provider = new SybaseCallMetaDataProvider((databaseMetaData)); } else if ("Microsoft SQL Server".equals(databaseProductName)) { provider = new SqlServerCallMetaDataProvider((databaseMetaData)); } else if ("HDB".equals(databaseProductName)) { provider = new HanaCallMetaDataProvider((databaseMetaData)); } else { provider = new GenericCallMetaDataProvider(databaseMetaData); } if (logger.isDebugEnabled()) { logger.debug("Using " + provider.getClass().getName()); } provider.initializeWithMetaData(databaseMetaData); if (accessProcedureColumnMetaData) { provider.initializeWithProcedureColumnMetaData(databaseMetaData, context.getCatalogName(), context.getSchemaName(), context.getProcedureName()); } return provider; }); return result; } catch (MetaDataAccessException ex) { throw new DataAccessResourceFailureException("Error retrieving database metadata", ex); } }
From source file:org.springframework.jdbc.core.metadata.TableMetaDataProviderFactory.java
/** * Create a TableMetaDataProvider based on the database metadata. * @param dataSource used to retrieve metadata * @param context the class that holds configuration and metadata * @return instance of the TableMetaDataProvider implementation to be used *//*from ww w .j a va 2 s. c o m*/ public static TableMetaDataProvider createMetaDataProvider(DataSource dataSource, TableMetaDataContext context) { try { TableMetaDataProvider result = (TableMetaDataProvider) JdbcUtils.extractDatabaseMetaData(dataSource, databaseMetaData -> { String databaseProductName = JdbcUtils .commonDatabaseName(databaseMetaData.getDatabaseProductName()); boolean accessTableColumnMetaData = context.isAccessTableColumnMetaData(); TableMetaDataProvider provider; if ("Oracle".equals(databaseProductName)) { provider = new OracleTableMetaDataProvider(databaseMetaData, context.isOverrideIncludeSynonymsDefault()); } else if ("HSQL Database Engine".equals(databaseProductName)) { provider = new HsqlTableMetaDataProvider(databaseMetaData); } else if ("PostgreSQL".equals(databaseProductName)) { provider = new PostgresTableMetaDataProvider(databaseMetaData); } else if ("Apache Derby".equals(databaseProductName)) { provider = new DerbyTableMetaDataProvider(databaseMetaData); } else { provider = new GenericTableMetaDataProvider(databaseMetaData); } if (logger.isDebugEnabled()) { logger.debug("Using " + provider.getClass().getSimpleName()); } provider.initializeWithMetaData(databaseMetaData); if (accessTableColumnMetaData) { provider.initializeWithTableColumnMetaData(databaseMetaData, context.getCatalogName(), context.getSchemaName(), context.getTableName()); } return provider; }); return result; } catch (MetaDataAccessException ex) { throw new DataAccessResourceFailureException("Error retrieving database metadata", ex); } }
From source file:org.springframework.jdbc.support.lob.OracleLobHandler.java
/** * Initialize any LOB resources before a read is done. * <p>This implementation calls {@code BLOB.open(BLOB.MODE_READONLY)} or * {@code CLOB.open(CLOB.MODE_READONLY)} on any non-temporary LOBs if * {@code releaseResourcesAfterRead} property is set to {@code true}. * <p>This method can be overridden by sublcasses if different behavior is desired. * @param con the connection to be usde for initilization * @param lob the LOB to initialize/* w w w .java2 s. co m*/ */ protected void initializeResourcesBeforeRead(Connection con, Object lob) { if (this.releaseResourcesAfterRead) { initOracleDriverClasses(con); try { /* if (!((BLOB) lob.isTemporary() { */ Method isTemporary = lob.getClass().getMethod("isTemporary"); Boolean temporary = (Boolean) isTemporary.invoke(lob); if (!temporary) { /* ((BLOB) lob).open(BLOB.MODE_READONLY); */ Method open = lob.getClass().getMethod("open", int.class); open.invoke(lob, this.modeReadOnlyConstants.get(lob.getClass())); } } catch (InvocationTargetException ex) { logger.error("Could not open Oracle LOB", ex.getTargetException()); } catch (Exception ex) { throw new DataAccessResourceFailureException("Could not open Oracle LOB", ex); } } }
From source file:org.springframework.jdbc.support.lob.OracleLobHandler.java
/** * Release any LOB resources after read is complete. * <p>If {@code releaseResourcesAfterRead} property is set to {@code true} * then this implementation calls/*from ww w .jav a 2 s .c o m*/ * {@code BLOB.close()} or {@code CLOB.close()} * on any non-temporary LOBs that are open or * {@code BLOB.freeTemporary()} or {@code CLOB.freeTemporary()} * on any temporary LOBs. * <p>This method can be overridden by sublcasses if different behavior is desired. * @param con the connection to be usde for initilization * @param lob the LOB to initialize */ protected void releaseResourcesAfterRead(Connection con, Object lob) { if (this.releaseResourcesAfterRead) { initOracleDriverClasses(con); Boolean temporary = Boolean.FALSE; try { /* if (((BLOB) lob.isTemporary() { */ Method isTemporary = lob.getClass().getMethod("isTemporary"); temporary = (Boolean) isTemporary.invoke(lob); if (temporary) { /* ((BLOB) lob).freeTemporary(); */ Method freeTemporary = lob.getClass().getMethod("freeTemporary"); freeTemporary.invoke(lob); } else { /* if (((BLOB) lob.isOpen() { */ Method isOpen = lob.getClass().getMethod("isOpen"); Boolean open = (Boolean) isOpen.invoke(lob); if (open) { /* ((BLOB) lob).close(); */ Method close = lob.getClass().getMethod("close"); close.invoke(lob); } } } catch (InvocationTargetException ex) { if (temporary) { logger.error("Could not free Oracle LOB", ex.getTargetException()); } else { logger.error("Could not close Oracle LOB", ex.getTargetException()); } } catch (Exception ex) { if (temporary) { throw new DataAccessResourceFailureException("Could not free Oracle LOB", ex); } else { throw new DataAccessResourceFailureException("Could not close Oracle LOB", ex); } } } }