Example usage for org.springframework.dao DataRetrievalFailureException DataRetrievalFailureException

List of usage examples for org.springframework.dao DataRetrievalFailureException DataRetrievalFailureException

Introduction

In this page you can find the example usage for org.springframework.dao DataRetrievalFailureException DataRetrievalFailureException.

Prototype

public DataRetrievalFailureException(String msg, @Nullable Throwable cause) 

Source Link

Document

Constructor for DataRetrievalFailureException.

Usage

From source file:org.jenkinsci.plugins.GithubSecurityRealm.java

/**
 *
 * @param groupName/* w  w w.  java2 s  . c o m*/
 * @return
 * @throws UsernameNotFoundException
 * @throws DataAccessException
 */
@Override
public GroupDetails loadGroupByGroupname(String groupName)
        throws UsernameNotFoundException, DataAccessException {
    GithubAuthenticationToken authToken = (GithubAuthenticationToken) SecurityContextHolder.getContext()
            .getAuthentication();

    if (authToken == null)
        throw new UsernameNotFoundException("No known group: " + groupName);

    try {
        int idx = groupName.indexOf(GithubOAuthGroupDetails.ORG_TEAM_SEPARATOR);
        if (idx > -1 && groupName.length() > idx + 1) { // groupName = "GHOrganization*GHTeam"
            String orgName = groupName.substring(0, idx);
            String teamName = groupName.substring(idx + 1);
            LOGGER.config(String.format("Lookup for team %s in organization %s", teamName, orgName));
            GHTeam ghTeam = authToken.loadTeam(orgName, teamName);
            if (ghTeam == null) {
                throw new UsernameNotFoundException(
                        "Unknown GitHub team: " + teamName + " in organization " + orgName);
            }
            return new GithubOAuthGroupDetails(ghTeam);
        } else { // groupName = "GHOrganization"
            GHOrganization ghOrg = authToken.loadOrganization(groupName);
            if (ghOrg == null) {
                throw new UsernameNotFoundException("Unknown GitHub organization: " + groupName);
            }
            return new GithubOAuthGroupDetails(ghOrg);
        }
    } catch (Error e) {
        throw new DataRetrievalFailureException("loadGroupByGroupname (groupname=" + groupName + ")", e);
    }
}

From source file:org.nimbustools.messaging.query.security.FileUserDetailsService.java

public boolean refreshIfNeeded() throws DataAccessException {
    synchronized (this.lock) {

        if (this.file.lastModified() > this.lastModified) {
            try {
                load(this.file);
            } catch (IOException e) {
                throw new DataRetrievalFailureException("Error refreshing user file", e);
            }//from w  ww  .java2  s .c  o m
            return true;
        }
        return false;
    }
}

From source file:org.opennms.netmgt.dao.mock.MockEventConfDao.java

@Override
public void reload() throws DataAccessException {
    InputStream is = null;//from  w  w  w .ja va2 s. c  om
    InputStreamReader isr = null;
    try {
        is = m_resource.getInputStream();
        isr = new InputStreamReader(is);
        m_events = Events.unmarshal(isr);
        m_events.loadEventFiles(m_resource);
        m_events.initialize(new EnterpriseIdPartition(), new EventOrdering());
    } catch (final IOException e) {
        throw new DataRetrievalFailureException("Failed to read from " + m_resource.toString(), e);
    } finally {
        IOUtils.closeQuietly(isr);
        IOUtils.closeQuietly(is);
    }
}

From source file:org.opennms.netmgt.ticketer.quickbase.QuickBaseTicketerPlugin.java

public Ticket get(String ticketId) {
    try {//from w  w  w  .java 2 s .c o m
        Properties props = getProperties();
        MyQuickBaseClient qdb = createClient(getUserName(props), getPassword(props), getUrl(props));

        String dbId = qdb.findDbByName(getApplicationName(props));

        HashMap<String, String> record = qdb.getRecordInfo(dbId, ticketId);

        Ticket ticket = new Ticket();
        ticket.setId(ticketId);
        ticket.setModificationTimestamp(record.get(getModificationTimeStampFile(props)));
        ticket.setSummary(record.get(getSummaryField(props)));
        ticket.setDetails(record.get(getDetailsField(props)));
        ticket.setState(getTicketStateValue(record.get(getStateField(props)), props));

        return ticket;

    } catch (Throwable e) {
        throw new DataRetrievalFailureException("Failed to commit QuickBase transaction: " + e.getMessage(), e);
    }

}

From source file:org.opennms.netmgt.ticketer.quickbase.QuickBaseTicketerPlugin.java

public void saveOrUpdate(Ticket ticket) {

    try {/*  www. j ava  2  s.c  o m*/

        Properties props = getProperties();

        QuickBaseClient qdb = createClient(getUserName(props), getPassword(props), getUrl(props));

        String dbId = qdb.findDbByName(getApplicationName(props));

        HashMap<String, String> record = new HashMap<String, String>();

        record.put(getSummaryField(props), ticket.getSummary());
        record.put(getDetailsField(props), ticket.getDetails());
        record.put(getStateField(props), getQuickBaseStateValue(ticket.getState(), props));

        if (ticket.getId() == null) {
            addAdditionCreationFields(record, props);
            String recordId = qdb.addRecord(dbId, record);
            ticket.setId(recordId);
        } else {
            Ticket oldTicket = get(ticket.getId());
            if (ticket.getModificationTimestamp().equals(oldTicket.getModificationTimestamp())) {
                qdb.editRecord(dbId, record, ticket.getId());
            } else {
                throw new OptimisticLockingFailureException(
                        "Ticket has been updated while this ticket was in memory! Reload and try again!");
            }

        }

    } catch (Throwable e) {
        throw new DataRetrievalFailureException("Failed to commit QuickBase transaction: " + e.getMessage(), e);
    }

}

From source file:org.springframework.data.jdbc.support.oracle.BeanPropertyStructMapper.java

public STRUCT toStruct(T source, Connection conn, String typeName) throws SQLException {
    StructDescriptor descriptor = new StructDescriptor(typeName, conn);
    ResultSetMetaData rsmd = descriptor.getMetaData();
    int columns = rsmd.getColumnCount();
    Object[] values = new Object[columns];
    for (int i = 1; i <= columns; i++) {
        String column = JdbcUtils.lookupColumnName(rsmd, i).toLowerCase();
        PropertyDescriptor fieldMeta = (PropertyDescriptor) this.mappedFields.get(column);
        if (fieldMeta != null) {
            BeanWrapper bw = new BeanWrapperImpl(source);
            if (bw.isReadableProperty(fieldMeta.getName())) {
                try {
                    if (logger.isDebugEnabled()) {
                        logger.debug("Mapping column named \"" + column + "\"" + " to property \""
                                + fieldMeta.getName() + "\"");
                    }//from w ww  . j a  v a2  s .  c om
                    values[i - 1] = bw.getPropertyValue(fieldMeta.getName());
                } catch (NotReadablePropertyException ex) {
                    throw new DataRetrievalFailureException(
                            "Unable to map column " + column + " to property " + fieldMeta.getName(), ex);
                }
            } else {
                logger.warn("Unable to access the getter for " + fieldMeta.getName() + ".  Check that " + "get"
                        + StringUtils.capitalize(fieldMeta.getName()) + " is declared and has public access.");
            }
        }
    }
    STRUCT struct = new STRUCT(descriptor, conn, values);
    return struct;
}

From source file:org.springframework.data.jdbc.support.oracle.BeanPropertyStructMapper.java

/**
* Extract the values for all attributes in the struct.
* <p>Utilizes public setters and result set metadata.
* @see java.sql.ResultSetMetaData//from ww w.  j a va  2  s. c  om
*/
public T fromStruct(STRUCT struct) throws SQLException {
    Assert.state(this.mappedClass != null, "Mapped class was not specified");
    T mappedObject = BeanUtils.instantiateClass(this.mappedClass);
    BeanWrapper bw = PropertyAccessorFactory.forBeanPropertyAccess(mappedObject);
    initBeanWrapper(bw);

    ResultSetMetaData rsmd = struct.getDescriptor().getMetaData();
    Object[] attr = struct.getAttributes();
    int columnCount = rsmd.getColumnCount();
    for (int index = 1; index <= columnCount; index++) {
        String column = JdbcUtils.lookupColumnName(rsmd, index).toLowerCase();
        PropertyDescriptor pd = (PropertyDescriptor) this.mappedFields.get(column);
        if (pd != null) {
            try {
                Object value = attr[index - 1];
                if (logger.isDebugEnabled()) {
                    logger.debug("Mapping column '" + column + "' to property '" + pd.getName() + "' of type "
                            + pd.getPropertyType());
                }
                bw.setPropertyValue(pd.getName(), value);
            } catch (NotWritablePropertyException ex) {
                throw new DataRetrievalFailureException(
                        "Unable to map column " + column + " to property " + pd.getName(), ex);
            }
        }
    }

    return mappedObject;
}

From source file:org.springframework.data.neo4j.transaction.SessionFactoryUtils.java

/**
 * Convert the given runtime exception to an appropriate exception from the
 * {@code org.springframework.dao} hierarchy.
 * Return null if no translation is appropriate: any other exception may
 * have resulted from user code, and should not be translated.
 * @param ex runtime exception that occurred
 * @return the corresponding DataAccessException instance,
 * or {@code null} if the exception should not be translated
 *//*from  w  w w  .j a va2s. c o  m*/
public static DataAccessException convertOgmAccessException(RuntimeException ex) {

    if (ex instanceof IllegalStateException) {
        return new InvalidDataAccessApiUsageException(ex.getMessage(), ex);
    }
    if (ex instanceof IllegalArgumentException) {
        return new InvalidDataAccessApiUsageException(ex.getMessage(), ex);
    }
    if (ex instanceof NotFoundException) {
        return new DataRetrievalFailureException(ex.getMessage(), ex);
    }
    if (ex instanceof InvalidDepthException) {
        return new InvalidDataAccessApiUsageException(ex.getMessage(), ex);
    }
    if (ex instanceof ResultProcessingException) {
        return new DataRetrievalFailureException(ex.getMessage(), ex);
    }

    // If we get here, we have an exception that resulted from user code,
    // rather than the persistence provider, so we return null to indicate
    // that translation should not occur.
    return null;
}

From source file:org.springframework.integration.cluster.redis.DistributedLockHandler.java

public void acquireLock(String key, String owner) {
    int n = 0;//ww w .j  av a2  s .  co m
    while (this.lockTemplate.opsForValue().setIfAbsent(key + ".lock", getLockValue(owner)) == false) {
        if (++n > this.timeout / 100) {
            throw new CannotAcquireLockException("Failed to procure cluster lock for application " + key);
        }
        try {
            Thread.sleep(100);
        } catch (InterruptedException e) {
            Thread.currentThread().interrupt();
            throw new DataRetrievalFailureException("Interrupted while procuring lock", e);
        }
    }
    this.acquiredThreadLocal.set(new Date());
    if (logger.isDebugEnabled()) {
        logger.debug("Lock acquiredThreadLocal for " + key + " by " + owner);
    }
    this.lockTemplate.opsForValue().getOperations().expire(key + ".lock", timeout * 2, TimeUnit.MILLISECONDS);
}

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   www . j a  va  2 s  .c o  m
    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;
}