use of org.jbei.ice.storage.DAOException in project ice by JBEI.
the class SequenceDAO method deleteSequence.
/**
* Delete the given {@link Sequence} object in the database.
*
* @param sequence sequence to delete
* @param pigeonImageFolder path of the image folder where the pigeon images are cached
*/
public void deleteSequence(Sequence sequence, String pigeonImageFolder) {
String sequenceHash = sequence.getFwdHash();
try {
sequence.setEntry(null);
sequence.getSequenceFeatures();
super.delete(sequence);
currentSession().flush();
Files.deleteIfExists(Paths.get(pigeonImageFolder, sequenceHash + ".png"));
} catch (IOException e) {
Logger.warn(e.getMessage());
} 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 hasSequence.
public boolean hasSequence(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)).distinct(true);
return currentSession().createQuery(query).setMaxResults(1).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 RemoteClientModelDAO method getClientCount.
/**
* Retrieves number of clients for the specified group
*
* @param group group whose clients are of interest
* @return number of clients for group
* @throws DAOException
*/
public int getClientCount(Group group) {
try {
CriteriaQuery<Long> query = getBuilder().createQuery(Long.class);
Root<RemoteClientModel> from = query.from(RemoteClientModel.class);
Join<RemoteClientModel, Group> groups = from.join("groups");
query.select(getBuilder().countDistinct(from.get("id")));
query.where(getBuilder().equal(groups.get("id"), group.getId()), getBuilder().isNotNull(from.get("email")));
return currentSession().createQuery(query).uniqueResult().intValue();
} catch (HibernateException he) {
Logger.error(he);
throw new DAOException(he);
}
}
use of org.jbei.ice.storage.DAOException in project ice by JBEI.
the class SelectionMarkerDAO method getMatchingSelectionMarkers.
public List<String> getMatchingSelectionMarkers(String token, int limit) {
try {
CriteriaQuery<String> query = getBuilder().createQuery(String.class);
Root<SelectionMarker> from = query.from(SelectionMarker.class);
query.where(getBuilder().like(getBuilder().lower(from.get("name")), "%" + token.toLowerCase() + "%"));
query.select(from.get("name")).distinct(true);
return currentSession().createQuery(query).setMaxResults(limit).list();
// return currentSession().createCriteria(SelectionMarker.class)
// .add(Restrictions.ilike("name", token, MatchMode.ANYWHERE))
// .setMaxResults(limit)
// .setProjection(Projections.distinct(Projections.property("name")))
// .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 SampleDAO method getSamplesByStorage.
/**
* Retrieve {@link Sample} objects associated with the given {@link Storage} object.
*
* @param storage
* @return ArrayList of Sample objects.
* @throws DAOException
*/
public List<Sample> getSamplesByStorage(Storage storage) {
try {
CriteriaQuery<Sample> query = getBuilder().createQuery(Sample.class);
Root<Sample> from = query.from(Sample.class);
query.where(getBuilder().equal(from.get("storage"), storage));
return currentSession().createQuery(query).list();
} catch (HibernateException e) {
Logger.error(e);
throw new DAOException("Failed to retrieve sample by storage id: " + storage.getId(), e);
}
}
Aggregations