use of org.jbei.ice.storage.DAOException in project ice by JBEI.
the class SequenceDAO method getSequence.
/**
* Enables retrieving sequences in the database without loading everything in memory
* <p/>
* Expected usage is
* <code>
* long count = getSequenceCount();
* int offset = 0;
* while( offset < count ) {
* Sequence sequence = dao.getSequence(offset);
* // do something with sequence
* }
* </code>
*
* @return Sequence at the specified offset
* @throws DAOException
*/
public Sequence getSequence(int offset) {
try {
CriteriaQuery<Sequence> query = getBuilder().createQuery(Sequence.class);
Root<Sequence> from = query.from(Sequence.class);
Join<Sequence, Entry> entry = from.join("entry");
query.where(getBuilder().equal(entry.get("visibility"), Visibility.OK.getValue()));
return currentSession().createQuery(query).setFirstResult(offset).setMaxResults(1).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 SequenceDAO method hasOriginalSequence.
/**
* Determines if the user uploaded a sequence file and associated it with an entry
*
* @param entryId unique identifier for entry
* @return true if there is a sequence file that was originally uploaded by user, false otherwise
* @throws DAOException
*/
public boolean hasOriginalSequence(long entryId) {
try {
CriteriaQuery<Long> query = getBuilder().createQuery(Long.class);
Root<Sequence> from = query.from(Sequence.class);
Join<Sequence, Entry> entry = from.join("entry");
query.select(getBuilder().countDistinct(from.get("id"))).where(getBuilder().equal(entry.get("id"), entryId), getBuilder().notEqual(from.get("sequenceUser"), ""), getBuilder().isNotNull(from.get("sequenceUser")));
return currentSession().createQuery(query).uniqueResult() > 0;
} catch (HibernateException he) {
Logger.error(he);
throw new DAOException(he);
}
}
use of org.jbei.ice.storage.DAOException in project ice by JBEI.
the class RequestRetriever method placeSampleInCart.
/**
* Creates a new sample request for the specified user and specified entry.
* The default status is "IN CART"
*/
public boolean placeSampleInCart(String userId, SampleRequest sampleRequest) {
long partId = sampleRequest.getPartData().getId();
Entry entry = entryDAO.get(sampleRequest.getPartData().getId());
if (entry == null)
throw new IllegalArgumentException("Cannot find entry with id: " + partId);
Account account = DAOFactory.getAccountDAO().getByEmail(userId);
// check if sample is already in cart with status of "IN CART"
try {
List<Request> requests = dao.getSampleRequestByStatus(account, entry, SampleRequestStatus.IN_CART);
if (requests != null && !requests.isEmpty())
return true;
Request request = new Request();
request.setAccount(account);
request.setGrowthTemperature(sampleRequest.getGrowthTemperature());
request.setEntry(entry);
if (sampleRequest.getRequestType() == null)
sampleRequest.setRequestType(SampleRequestType.LIQUID_CULTURE);
request.setType(sampleRequest.getRequestType());
request.setRequested(new Date(System.currentTimeMillis()));
request.setUpdated(request.getRequested());
request.setPlateDescription(sampleRequest.getPlateDescription());
return dao.create(request) != null;
} catch (DAOException e) {
Logger.error(e);
return false;
}
}
use of org.jbei.ice.storage.DAOException in project ice by JBEI.
the class AuditDAO method getAuditsForEntry.
public List<Audit> getAuditsForEntry(Entry entry, int limit, int offset, boolean asc, String sort) {
try {
if (sort == null)
sort = "id";
CriteriaQuery<Audit> query = getBuilder().createQuery(Audit.class);
Root<Audit> from = query.from(Audit.class);
query.where(getBuilder().equal(from.get("entry"), entry));
query.orderBy(asc ? getBuilder().asc(from.get(sort)) : getBuilder().desc(from.get(sort)));
return currentSession().createQuery(query).setFirstResult(offset).setMaxResults(limit).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 AuditDAO method deleteAll.
public int deleteAll(Entry entry) {
try {
CriteriaDelete<Audit> query = getBuilder().createCriteriaDelete(Audit.class);
Root<Audit> from = query.from(Audit.class);
query.where(getBuilder().equal(from.get("entry"), entry));
return currentSession().createQuery(query).executeUpdate();
} catch (HibernateException he) {
Logger.error(he);
throw new DAOException(he);
}
}
Aggregations