Example usage for org.springframework.orm ObjectRetrievalFailureException ObjectRetrievalFailureException

List of usage examples for org.springframework.orm ObjectRetrievalFailureException ObjectRetrievalFailureException

Introduction

In this page you can find the example usage for org.springframework.orm ObjectRetrievalFailureException ObjectRetrievalFailureException.

Prototype

public ObjectRetrievalFailureException(String persistentClassName, Object identifier) 

Source Link

Document

Create a new ObjectRetrievalFailureException for the given object, with the default "not found" message.

Usage

From source file:org.opennms.ng.dao.support.DistributedStatusResourceType.java

/**
 * <p>getResourcesForLocationMonitor</p>
 *
 * @param locationMonitorId a int./*from w ww  .j a v a  2  s. c  om*/
 * @return a {@link java.util.List} object.
 */
public List<OnmsResource> getResourcesForLocationMonitor(int locationMonitorId) {
    ArrayList<OnmsResource> resources = new ArrayList<OnmsResource>();

    /*
     * Verify that the node directory exists so we can throw a good
     * error message if not.
     */
    File locationMonitorDirectory;
    try {
        locationMonitorDirectory = getLocationMonitorDirectory(locationMonitorId, true);
    } catch (DataAccessException e) {
        throw new ObjectRetrievalFailureException("The '" + getName()
                + "' resource type does not exist on this location Monitor.  Nested exception is: "
                + e.getClass().getName() + ": " + e.getMessage(), e);
    }

    File[] intfDirs = locationMonitorDirectory.listFiles(RrdFileConstants.INTERFACE_DIRECTORY_FILTER);

    // XXX is this test even needed?
    if (intfDirs == null) {
        return resources;
    }

    // XXX this isn't right at all
    for (File intfDir : intfDirs) {
        String d = intfDir.getName();
        String defName = getDefinitionNameFromLocationMonitorDirectory(d);
        int id = getLocationMonitorIdFromLocationMonitorDirectory(d);
        resources.add(createResource(defName, id, intfDir.getName()));
    }

    return resources;
}

From source file:corner.orm.gae.impl.JpaEntityServiceImpl.java

/**
 * @see corner.orm.services.EntityService#findUnique(java.lang.Class,
 *      java.lang.Object[])//  ww w  .ja va  2  s  .co m
 */
@Override
public <T> T findUnique(Class<T> clazz, Object[] conditions) {
    Iterator<T> it = this.find(clazz, conditions, null);
    T result = null;
    if (it.hasNext()) {
        result = it.next();
    }
    if (it.hasNext()) {
        throw new ObjectRetrievalFailureException("?!,?.", null);
    }
    return result;
}

From source file:org.opennms.ng.dao.support.DefaultResourceDao.java

/** {@inheritDoc} */
@Override// w ww .  j  a  v  a  2 s .  c  o m
public File getRrdDirectory(boolean verify) {
    if (verify && !getRrdDirectory().isDirectory()) {
        throw new ObjectRetrievalFailureException(
                "RRD directory does not exist: " + getRrdDirectory().getAbsolutePath(), getRrdDirectory());
    }

    return getRrdDirectory();
}

From source file:mx.edu.um.mateo.rh.dao.impl.SolicitudVacacionesDaoHibernate.java

/**
 * @see/*  ww w  .j  av  a 2  s .com*/
 * mx.edu.um.rh.dao.SolicitudVacacionesDao#getSolicitudVacaciones(Integer
 * id)
 */
@Override
@Transactional(readOnly = true)
public SolicitudVacaciones getSolicitudVacaciones(final Integer id) {
    SolicitudVacaciones solicitudVacaciones = (SolicitudVacaciones) getSession().get(SolicitudVacaciones.class,
            id);
    if (solicitudVacaciones == null) {
        log.warn("uh oh, solicitudVacaciones with id '" + id + "' not found...");
        throw new ObjectRetrievalFailureException(SolicitudVacaciones.class, id);
    }

    return solicitudVacaciones;
}

From source file:org.opennms.ng.dao.support.GenericIndexResourceType.java

private File getResourceTypeDirectory(String nodeSource, boolean verify) {
    File snmp = new File(m_resourceDao.getRrdDirectory(verify), DefaultResourceDao.SNMP_DIRECTORY);

    File dir = new File(snmp, ResourceTypeUtils.getRelativeNodeSourceDirectory(nodeSource).toString());
    if (verify && !dir.isDirectory()) {
        throw new ObjectRetrievalFailureException(File.class,
                "No directory exists for nodeSource " + nodeSource);
    }//from w  w  w  .  j  a  v a 2s  . c  o  m

    File generic = new File(dir, getName());
    if (verify && !generic.isDirectory()) {
        throw new ObjectRetrievalFailureException(File.class,
                "No node directory exists for generic index " + getName() + ": " + generic);
    }

    return generic;
}

From source file:org.musicrecital.dao.hibernate.GenericDaoHibernate.java

/**
 * {@inheritDoc}//from  ww w. java2  s.  c o m
 */
@SuppressWarnings("unchecked")
public T get(PK id) {
    Session sess = getSession();
    IdentifierLoadAccess byId = sess.byId(persistentClass);
    T entity = (T) byId.load(id);

    if (entity == null) {
        log.warn("Uh oh, '" + this.persistentClass + "' object with id '" + id + "' not found...");
        throw new ObjectRetrievalFailureException(this.persistentClass, id);
    }

    return entity;
}

From source file:com.edgenius.core.dao.hibernate.UserDAOHibernate.java

/**
 * @see com.edgenius.paradise.dao.UserDAO#getUserByName(java.lang.String)
 *///from  w  w w. j av a2s  . com
@SuppressWarnings("unchecked")
public User getUserByName(String username) {
    List<User> list = (List<User>) find(SQL_GET_BY_USERNAME, username);
    User user = null;
    if (list != null && list.size() > 0) {
        user = list.get(0);
        //put here as SpringSecuirty UserDetailsService will get user directly from here rather than UserService..
        refreshInstancePermissionCache(user);
    } else {
        log.warn("user '" + username + "' not found");
        throw new ObjectRetrievalFailureException(User.class, username);
    }

    return user;
}

From source file:org.openhie.openempi.dao.hibernate.UniversalDaoHibernate.java

/**
 * {@inheritDoc}/*from   w  w  w . j  av a2  s  .  c o  m*/
 */
@SuppressWarnings("rawtypes")
public Object get(Class clazz, Serializable id) {
    Object o = getHibernateTemplate().get(clazz, id);

    if (o == null) {
        throw new ObjectRetrievalFailureException(clazz, id);
    }

    return o;
}

From source file:mx.edu.um.mateo.rh.dao.impl.EmpleadoDaoHibernate.java

/**
 * @see mx.edu.um.mateo.rh.dao.EmpleadoDao#getEmpleado(Empleado empleado)
 *///from  www  .  j a va2  s . c  o  m
@Override
@Transactional(readOnly = true)
public Empleado getEmpleado(final Empleado empleado) {
    Empleado emp = new Empleado();

    if (empleado != null) {
        Criteria sql = getSession().createCriteria(Empleado.class);

        // Buscar por id
        if (empleado.getId() != null) {
            sql.add(Restrictions.idEq(empleado.getId()));
        } // Buscar por clave
        else if (empleado.getClave() != null && !"".equals(empleado.getClave())) {
            sql.add(Restrictions.eq("clave", empleado.getClave()));
        }
        emp = (Empleado) sql.uniqueResult();

    }
    if (emp == null) {
        log.warn("uh oh, empleado with id '" + empleado.getId() + "' not found...");
        throw new ObjectRetrievalFailureException(Empleado.class, empleado.getId());
    }
    return emp;
}

From source file:org.opennms.ng.dao.support.DistributedStatusResourceType.java

private File getLocationMonitorDirectory(String locationMonitorId, boolean verify)
        throws ObjectRetrievalFailureException {
    File locationMonitorDirectory = new File(m_resourceDao.getRrdDirectory(verify), locationMonitorId);

    if (verify && !locationMonitorDirectory.isDirectory()) {
        throw new ObjectRetrievalFailureException(File.class,
                "No node directory exists for node " + locationMonitorId + ": " + locationMonitorDirectory);
    }//  w  ww  . j a v a  2  s. co  m

    return locationMonitorDirectory;
}