use of org.jbei.ice.storage.DAOException in project ice by JBEI.
the class SampleDAO method getSampleCount.
public int getSampleCount(Entry entry) {
try {
CriteriaQuery<Long> query = getBuilder().createQuery(Long.class);
Root<Sample> from = query.from(Sample.class);
query.select(getBuilder().countDistinct(from.get("id")));
query.where(getBuilder().equal(from.get("entry"), entry));
return currentSession().createQuery(query).uniqueResult().intValue();
} catch (HibernateException e) {
Logger.error(e);
throw new DAOException(e);
}
}
use of org.jbei.ice.storage.DAOException in project ice by JBEI.
the class SequenceDAO method getByEntry.
/**
* Retrieve the {@link Sequence} object associated with the given {@link Entry} object.
*
* @param entry entry associated with sequence
* @return Sequence object.
*/
public Sequence getByEntry(Entry entry) {
try {
CriteriaQuery<Sequence> query = getBuilder().createQuery(Sequence.class);
Root<Sequence> from = query.from(Sequence.class);
query.where(getBuilder().equal(from.get("entry"), entry));
Optional<Sequence> sequence = currentSession().createQuery(query).uniqueResultOptional();
if (!sequence.isPresent())
return null;
return normalizeAnnotationLocations(sequence.get());
} catch (HibernateException e) {
Logger.error(e);
throw new DAOException("Failed to retrieve sequence by entry: " + entry.getId(), e);
}
}
use of org.jbei.ice.storage.DAOException in project ice by JBEI.
the class SequenceDAO method getSequenceFilename.
public String getSequenceFilename(Entry entry) {
try {
CriteriaQuery<String> query = getBuilder().createQuery(String.class);
Root<Sequence> from = query.from(Sequence.class);
query.select(from.get("fileName")).where(getBuilder().equal(from.get("entry"), entry));
return currentSession().createQuery(query).getSingleResult();
} catch (HibernateException he) {
Logger.error(he);
throw new DAOException(he);
}
}
use of org.jbei.ice.storage.DAOException 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);
}
}
use of org.jbei.ice.storage.DAOException in project ice by JBEI.
the class RequestDAO method getSampleRequestInCart.
public Request getSampleRequestInCart(Account account, Entry entry) {
try {
CriteriaQuery<Request> query = getBuilder().createQuery(Request.class);
Root<Request> from = query.from(Request.class);
query.where(getBuilder().and(getBuilder().equal(from.get("status"), SampleRequestStatus.IN_CART), getBuilder().equal(from.get("entry"), entry), getBuilder().equal(from.get("account"), account)));
List<Request> list = currentSession().createQuery(query).list();
if (list.isEmpty())
return null;
HashSet<Request> inCart = new HashSet<>(list);
if (inCart.size() > 1) {
Logger.error("Multiple sample requests found for entry " + entry.getId());
}
return (Request) inCart.toArray()[0];
} catch (HibernateException he) {
Logger.error(he);
throw new DAOException(he);
}
}
Aggregations