Search in sources :

Example 1 with UtilityException

use of org.jbei.ice.lib.utils.UtilityException in project ice by JBEI.

the class SequenceDAO method getFeatureBySequence.

/**
     * Retrieve the {@link Feature} object with the given DNA sequence string.
     *
     * @param featureDnaSequence dna sequence of feature
     * @return Feature object.
     * @throws DAOException
     */
private Feature getFeatureBySequence(String featureDnaSequence) {
    featureDnaSequence = featureDnaSequence.toLowerCase();
    try {
        String hash = SequenceUtils.calculateSequenceHash(featureDnaSequence);
        CriteriaQuery<Feature> query = getBuilder().createQuery(Feature.class);
        Root<Feature> from = query.from(Feature.class);
        query.where(getBuilder().equal(from.get("hash"), hash));
        Optional<Feature> result = currentSession().createQuery(query).uniqueResultOptional();
        if (result.isPresent())
            return result.get();
        String reverseComplement = SequenceUtils.reverseComplement(featureDnaSequence);
        String sequenceHash = SequenceUtils.calculateSequenceHash(reverseComplement);
        query.getRestriction().getExpressions().clear();
        query.where(getBuilder().equal(from.get("hash"), sequenceHash));
        return currentSession().createQuery(query).uniqueResult();
    } catch (HibernateException | UtilityException e) {
        Logger.error(e);
        throw new DAOException("Failed to get Feature by sequence!", e);
    }
}
Also used : DAOException(org.jbei.ice.storage.DAOException) HibernateException(org.hibernate.HibernateException) UtilityException(org.jbei.ice.lib.utils.UtilityException)

Aggregations

HibernateException (org.hibernate.HibernateException)1 UtilityException (org.jbei.ice.lib.utils.UtilityException)1 DAOException (org.jbei.ice.storage.DAOException)1