Search in sources :

Example 1 with Sample

use of org.jbei.ice.storage.model.Sample in project ice by JBEI.

the class SampleCreator method createSampleObject.

/**
     * Create a {@link Sample} object.
     * <p/>
     * Generates the UUID and the time stamps.
     *
     * @param label     display label for sample
     * @param depositor name of the depositor
     * @param notes     associated notes
     * @return {@link Sample}
     */
public static Sample createSampleObject(String label, String depositor, String notes) {
    String uuid = Utils.generateUUID();
    Date creationTime = Calendar.getInstance().getTime();
    Sample sample = new Sample();
    sample.setLabel(label);
    sample.setDepositor(depositor);
    sample.setNotes(notes);
    sample.setUuid(uuid);
    sample.setCreationTime(creationTime);
    sample.setModificationTime(null);
    return sample;
}
Also used : Sample(org.jbei.ice.storage.model.Sample) Date(java.util.Date)

Example 2 with Sample

use of org.jbei.ice.storage.model.Sample 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);
    }
}
Also used : DAOException(org.jbei.ice.storage.DAOException) HibernateException(org.hibernate.HibernateException) Sample(org.jbei.ice.storage.model.Sample)

Example 3 with Sample

use of org.jbei.ice.storage.model.Sample 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);
    }
}
Also used : DAOException(org.jbei.ice.storage.DAOException) HibernateException(org.hibernate.HibernateException) Sample(org.jbei.ice.storage.model.Sample)

Example 4 with Sample

use of org.jbei.ice.storage.model.Sample in project ice by JBEI.

the class SampleDAO method getSamplesByEntry.

public List<Sample> getSamplesByEntry(Entry entry) {
    try {
        CriteriaQuery<Sample> query = getBuilder().createQuery(Sample.class);
        Root<Sample> from = query.from(Sample.class);
        query.where(getBuilder().equal(from.get("entry"), entry));
        return currentSession().createQuery(query).list();
    } catch (HibernateException e) {
        Logger.error(e);
        throw new DAOException(e);
    }
}
Also used : DAOException(org.jbei.ice.storage.DAOException) HibernateException(org.hibernate.HibernateException) Sample(org.jbei.ice.storage.model.Sample)

Example 5 with Sample

use of org.jbei.ice.storage.model.Sample in project ice by JBEI.

the class SampleDAO method hasSample.

public boolean hasSample(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).setMaxResults(1).uniqueResult() > 0;
    } catch (HibernateException e) {
        Logger.error(e);
        throw new DAOException(e);
    }
}
Also used : DAOException(org.jbei.ice.storage.DAOException) HibernateException(org.hibernate.HibernateException) Sample(org.jbei.ice.storage.model.Sample)

Aggregations

Sample (org.jbei.ice.storage.model.Sample)5 HibernateException (org.hibernate.HibernateException)4 DAOException (org.jbei.ice.storage.DAOException)4 Date (java.util.Date)1