Example usage for org.hibernate Criteria uniqueResult

List of usage examples for org.hibernate Criteria uniqueResult

Introduction

In this page you can find the example usage for org.hibernate Criteria uniqueResult.

Prototype

public Object uniqueResult() throws HibernateException;

Source Link

Document

Convenience method to return a single instance that matches the query, or null if the query returns no results.

Usage

From source file:au.org.theark.study.model.dao.StudyDao.java

License:Open Source License

private boolean linkSubjectStudyExists(LinkSubjectStudy linkSubjectStudy) {
    Criteria criteria = getStatelessSession().createCriteria(LinkSubjectStudy.class);
    criteria.add(Restrictions.eq("subjectUID", linkSubjectStudy.getSubjectUID()));
    criteria.add(Restrictions.eq("study", linkSubjectStudy.getStudy()));
    return criteria.uniqueResult() != null;
}

From source file:au.org.theark.study.model.dao.StudyDao.java

License:Open Source License

public LinkStudySubstudy isSubStudy(Study study) {
    Criteria criteria = getStatelessSession().createCriteria(LinkStudySubstudy.class);
    criteria.add(Restrictions.eq("subStudy", study));
    LinkStudySubstudy linkedStudy = (LinkStudySubstudy) criteria.uniqueResult();
    return linkedStudy;
}

From source file:au.org.theark.study.model.dao.UserDao.java

License:Open Source License

/**
 * Checks if the Ark User is present in the system. IT does no compare with a particular Study. If a person existed in the system this will return
 * true. This must be used only during create operation. If you want to add a ArkUser to another study then another method with study must be
 * passed in./*  w  w  w .  j a v a2  s. c om*/
 */
public boolean isArkUserPresent(String userName) {
    boolean isPresent = false;
    Criteria criteria = getSession().createCriteria(ArkUser.class);
    if (userName != null) {
        criteria.add(Restrictions.eq("ldapUserName", userName));
    }

    criteria.setProjection(Projections.rowCount());
    Long count = (Long) criteria.uniqueResult();
    if (count > 0) {
        isPresent = true;
    }

    return isPresent;
}

From source file:autoinsert.AutoInsert.java

public int getID(String name) {
    Criteria criteria = sf.createCriteria(PackageTours.class).add(Restrictions.eq("touristName", name));

    Object result = criteria.uniqueResult();
    PackageTours genre = null;//from  w  w w  .j  av a  2  s.com
    if (result != null) {
        genre = (PackageTours) result;
        System.out.println("IDD = " + genre.getTouristId());
    }
    return genre.getTouristId();
}

From source file:be.wolkmaan.klimtoren.location.LocationRepositoryImpl.java

@Override
public Mailbox findByMailbox(Mailbox mailbox) {
    Criteria crit = getSession().createCriteria(Mailbox.class)
            .add(Restrictions.and(Restrictions.eq("street", mailbox.getStreet()),
                    Restrictions.eq("city", mailbox.getCity()),
                    Restrictions.eq("stateOrProvince", mailbox.getStateOrProvince()),
                    Restrictions.eq("country", mailbox.getCountry())));
    return (Mailbox) crit.uniqueResult();
}

From source file:be.wolkmaan.klimtoren.location.LocationRepositoryImpl.java

@Transactional
@Override/*www  .  ja v  a2 s. c om*/
public Country findCountryByCode(String code) {
    Criteria crit = getSession().createCriteria(Country.class).add(Restrictions.eq("countryCode", code));
    return (Country) crit.uniqueResult();
}

From source file:be.wolkmaan.klimtoren.party.PartyRepositoryImpl.java

@Override
public Person findByUsername(String username) {
    Criteria crit = getSession().createCriteria(Person.class)
            .createAlias("authentication", "auth", JoinType.LEFT_OUTER_JOIN)
            .add(Restrictions.eq("auth.username", username).ignoreCase());

    return (Person) crit.uniqueResult();
}

From source file:be.wolkmaan.klimtoren.party.PartyRepositoryImpl.java

@Override
public Organization findOrganization(String name, Organization parent, Kind relationKind) {
    Criteria crit = getSession().createCriteria(PartyToPartyRelationship.class)
            .add(Restrictions.eq("reference", parent)).add(Restrictions.eq("kind", relationKind))
            .createAlias("context", "context").add(Restrictions.eq("context.displayName", name).ignoreCase());

    return (Organization) crit.uniqueResult();
}

From source file:be.wolkmaan.klimtoren.party.PartyRepositoryImpl.java

@Override
public PartyToPartyRelationship findRelation(Party context, Party reference, Kind kind) {
    Criteria crit = createUnidirectional(context, reference);
    crit.add(Restrictions.eq("kind", kind));
    return (PartyToPartyRelationship) crit.uniqueResult();
}

From source file:benedict.zhang.addon.persistence.PersistenceManager.java

public Sound loadSound(String soundName, String actor) {
    session = sessionFactory.openSession();
    session.beginTransaction();/*from   w  ww . j ava 2 s .c om*/
    Criteria criteria = session.createCriteria(Sound.class);
    criteria.add(Restrictions.eq("soundName", soundName));
    criteria.add(Restrictions.and(Restrictions.eq("actor", actor)));
    Sound sound = (Sound) criteria.uniqueResult();
    session.getTransaction().commit();
    session.close();
    String path = UserPreference.getUserPreference().getSetting(UserPreferenceConstants.SOUND_LIBRARY)
            + sound.getActor() + System.getProperty("file.separator") + sound.getSoundName() + ".mp3";
    sound.setSoundPath(path);
    return sound;
}