use of org.jbei.ice.storage.DAOException in project ice by JBEI.
the class AccountDAO method getAccountsCount.
/**
* Retrieves maximum number of distinct accounts available and, if specified, whose firstName, lastName and email
* fields match the filter token. This is intended to be used for paging.
*
* @param filter optional token used to match against the firstName, lastName and email fields of accounts
* @return number of accounts that match the optional filter.
* @throws DAOException on {@link HibernateException} retrieving the number
*/
public long getAccountsCount(String filter) {
try {
CriteriaQuery<Long> query = getBuilder().createQuery(Long.class);
Root<Account> from = query.from(Account.class);
if (filter != null && !filter.isEmpty()) {
filter = filter.toLowerCase();
query.where(getBuilder().or(getBuilder().like(getBuilder().lower(from.get("firstName")), "%" + filter + "%"), getBuilder().like(getBuilder().lower(from.get("lastName")), "%" + filter + "%"), getBuilder().like(getBuilder().lower(from.get("email")), "%" + filter + "%")));
}
query.select(getBuilder().countDistinct(from.get("id")));
return currentSession().createQuery(query).uniqueResult();
} catch (HibernateException he) {
Logger.error(he);
throw new DAOException(he);
}
}
use of org.jbei.ice.storage.DAOException in project ice by JBEI.
the class SequenceFeatureDAO method getEntrySequenceFeatures.
public List<SequenceFeature> getEntrySequenceFeatures(Entry entry) {
try {
CriteriaQuery<SequenceFeature> query = getBuilder().createQuery(SequenceFeature.class);
Root<SequenceFeature> from = query.from(SequenceFeature.class);
Join<SequenceFeature, Sequence> sequence = from.join("sequence");
query.where(getBuilder().equal(sequence.get("entry"), entry)).distinct(true);
return currentSession().createQuery(query).list();
} catch (HibernateException he) {
Logger.error(he);
throw new DAOException(he);
}
}
use of org.jbei.ice.storage.DAOException in project ice by JBEI.
the class TraceSequenceDAO method save.
/**
* Save the given {@link TraceSequence} object in the database.
*
* @param traceSequence object to save
* @return Saved TraceSequence object.
* @throws DAOException on hibernate exception saving
*/
public TraceSequence save(TraceSequence traceSequence) {
TraceSequenceAlignment traceSequenceAlignment = traceSequence.getTraceSequenceAlignment();
Session session = currentSession();
try {
session.saveOrUpdate(traceSequenceAlignment);
traceSequence.setTraceSequenceAlignment(traceSequenceAlignment);
session.saveOrUpdate(traceSequence);
return traceSequence;
} catch (HibernateException e) {
throw new DAOException("Error saving trace sequence", e);
}
}
use of org.jbei.ice.storage.DAOException in project ice by JBEI.
the class TraceSequenceDAO method getByEntry.
/**
* Retrieve all {@link TraceSequence} objects associated with the given {@link Entry} object
* using the paging parameters, ordered by creation time in ascending order
*
* @param entry entry whose trace sequences are being retrieved
* @param start start for traces retrieval
* @param limit maximum number of trace records to retrieve
* @return List of TraceSequence objects.
* @throws DAOException
*/
public List<TraceSequence> getByEntry(Entry entry, int start, int limit) {
try {
CriteriaQuery<TraceSequence> query = getBuilder().createQuery(TraceSequence.class);
Root<TraceSequence> from = query.from(TraceSequence.class);
query.where(getBuilder().equal(from.get("entry"), entry));
query.orderBy(getBuilder().asc(from.get("creationTime")));
return currentSession().createQuery(query).setMaxResults(limit).setFirstResult(start).list();
} catch (HibernateException he) {
Logger.error(he);
throw new DAOException(he);
}
}
use of org.jbei.ice.storage.DAOException in project ice by JBEI.
the class TraceSequenceDAO method getByFileId.
/**
* Retrieve the {@link TraceSequence} object by its fileId.
*
* @param fileId unique file identifier
* @return {@link Optional} container that contains the trace sequence if found.
* @throws DAOException
*/
public Optional<TraceSequence> getByFileId(String fileId) {
try {
CriteriaQuery<TraceSequence> query = getBuilder().createQuery(TraceSequence.class);
Root<TraceSequence> from = query.from(TraceSequence.class);
query.where(getBuilder().equal(from.get("fileId"), fileId));
return currentSession().createQuery(query).uniqueResultOptional();
} catch (HibernateException e) {
throw new DAOException("Failed to retrieve entry by fileId: " + fileId, e);
}
}
Aggregations