Example usage for org.hibernate Criteria add

List of usage examples for org.hibernate Criteria add

Introduction

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

Prototype

public Criteria add(Criterion criterion);

Source Link

Document

Add a Criterion restriction to constrain the results to be retrieved.

Usage

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

License:Open Source License

public boolean isStudyComponentBeingUsedInConsent(StudyComp studyComp) {
    Criteria criteria = getSession().createCriteria(Consent.class);
    criteria.add(Restrictions.eq("study", studyComp.getStudy()));
    criteria.add(Restrictions.eq("studyComp", studyComp));
    List<Consent> consents = criteria.list();
    return (consents.size() > 0);

}

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./*  www.  j av 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:backendsw2.BackEndSW2.java

/**
    * @param userName//ww w  .j a v a  2  s  . com
    * @param passwd
    * @return return object "account object "
    */
public static Object login(String userName, String passwd) {

    boolean flag = false;
    Account object = new Account();
    Session se = databaseManager.SessionsManager.getSessionFactory().openSession();
    flag = true;
    AdminAccount ad = null;
    Employer em = null;
    Freelancer f = null;
    se.getTransaction().begin();

    // add  criteria to select user
    Criteria cr = se.createCriteria(Account.class);
    Criterion name = Restrictions.eq("userName", userName);
    Criterion pass = Restrictions.eq("password", passwd);
    LogicalExpression andr = Restrictions.and(name, pass);
    cr.add(andr);
    object = (Account) cr.list().get(0);

    try {
        ad = (AdminAccount) se.get(AdminAccount.class, object.getId());
    } catch (Exception e) {
        try {
            em = (Employer) se.get(Employer.class, object.getId());
        } catch (Exception ex) {
            try {
                f = (Freelancer) se.get(Freelancer.class, object.getId());
            } catch (Exception ee) {
                f = null;
            } finally {
                if (flag) {
                    se.close();
                }
                return f;
            }
        } finally {
            if (flag) {
                se.close();
            }
            return em;
        }
    } finally {
        if (flag) {
            se.close();
        }
        return ad;
    }

}

From source file:be.redlab.examples.databasetesting.common.AbstractJpaDao.java

License:Apache License

public List<T> findByEntity(final T entity) {
    Session session = (Session) getEntityManager().getDelegate();
    Criteria crit = session.createCriteria(getEntityClass());
    crit.add(Example.create(entity).excludeZeroes());
    return crit.list();
}

From source file:be.redlab.examples.databasetesting.common.AbstractJpaDao.java

License:Apache License

protected List<T> findByCriteria(final int firstResult, final int maxResults, final Order order,
        final Criterion... criterion) {
    Session session = (Session) getEntityManager().getDelegate();
    Criteria crit = session.createCriteria(getEntityClass());

    for (final Criterion c : criterion) {
        crit.add(c);
    }//w  w w  .  java  2 s  .  co  m

    if (order != null) {
        crit.addOrder(order);
    }

    if (firstResult > 0) {
        crit.setFirstResult(firstResult);
    }

    if (maxResults > 0) {
        crit.setMaxResults(maxResults);
    }

    return crit.list();
}

From source file:be.redlab.examples.databasetesting.common.AbstractJpaDao.java

License:Apache License

protected long countByCriteria(final Criterion... criterion) {
    Session session = (Session) getEntityManager().getDelegate();
    Criteria crit = session.createCriteria(getEntityClass());
    crit.setProjection(Projections.rowCount());

    for (final Criterion c : criterion) {
        crit.add(c);
    }//from w w  w  .jav  a 2 s. c  om

    return (Long) crit.list().get(0);
}

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:be.wolkmaan.klimtoren.party.PartyRepositoryImpl.java

@Override
public List<PartyToPartyRelationship> findRelation(Party context, Party reference, Kind kind,
        boolean bidirectional) {
    Criteria crit;
    if (bidirectional) {
        crit = createBidirectional(context, reference);
    } else {/*from   w w  w  . j av a2s  .c o m*/
        crit = createUnidirectional(context, reference);
    }

    crit.add(Restrictions.eq("kind", kind));

    return (List<PartyToPartyRelationship>) crit.list();
}

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

public List loadRolePlaying(String name) {
    if (StringUtils.isNullOrEmpty(name)) {
        return loadRolePlaying();
    }//from w ww.j  a  va  2 s .co  m
    session = sessionFactory.openSession();
    session.beginTransaction();
    Criteria criteria = session.createCriteria(RolePlayingConfiguration.class);
    criteria.add(Restrictions.like("addonName", "%" + name + "%"));
    List resultList = criteria.list();
    session.getTransaction().commit();
    session.close();
    return resultList;
}

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

public Sound loadSound(String soundName, String actor) {
    session = sessionFactory.openSession();
    session.beginTransaction();/*  w  w  w  . ja  v  a  2s .c o m*/
    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;
}