org.hibernate.criterion.SimpleExpression Java Examples

The following examples show how to use org.hibernate.criterion.SimpleExpression. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: DefaultSshKeyManager.java    From onedev with MIT License 5 votes vote down vote up
@Sessional
@Override
public SshKey findByDigest(String digest) {
    SimpleExpression eq = Restrictions.eq("digest", digest);
    EntityCriteria<SshKey> entityCriteria = EntityCriteria.of(SshKey.class).add(eq);
    entityCriteria.setCacheable(true);
    return find(entityCriteria);
}
 
Example #2
Source File: SbiUserDAOHibImpl.java    From Knowage-Server with GNU Affero General Public License v3.0 5 votes vote down vote up
/**
 * Get value of failed login attemtpts counter from DB.
 *
 * @author Marco Libanori
 */
@Override
public int getFailedLoginAttempts(String userId) {
	logger.debug("IN");

	Session aSession = null;
	Transaction tx = null;
	try {

		Integer result = 0;

		if (isUserIdAlreadyInUse(userId) != null) {

			aSession = getSession();
			tx = aSession.beginTransaction();

			ProjectionList projList = Projections.projectionList().add(Projections.property("failedLoginAttempts"), "failedLoginAttempts");

			SimpleExpression eq = Restrictions.eq("userId", userId);

			result = (Integer) aSession.createCriteria(SbiUser.class).add(eq).setProjection(projList).uniqueResult();

			tx.commit();
		}

		return result;
	} catch (HibernateException he) {
		if (tx != null)
			tx.rollback();
		throw new SpagoBIDAOException("Error while reading failed login attempts counter for user " + userId, he);
	} finally {
		logger.debug("OUT");
		if (aSession != null) {
			if (aSession.isOpen())
				aSession.close();
		}
	}
}
 
Example #3
Source File: DB.java    From MirServer-Netty with GNU General Public License v3.0 5 votes vote down vote up
public static List query(Class clazz, SimpleExpression... simpleExpressions) {
	Criteria criteria = getSession().createCriteria(clazz);
	for (SimpleExpression simpleExpression : simpleExpressions) {
		criteria.add(simpleExpression);
	}
	List result = criteria.list();
	return result;
}
 
Example #4
Source File: HibernateRepositoryDao.java    From livingdoc-confluence with GNU General Public License v3.0 5 votes vote down vote up
@SuppressWarnings(SUPPRESS_UNCHECKED)
private List<Repository> getAllRepositories(String projectName, ContentType type) {
    final Criteria crit = sessionService.getSession().createCriteria(Repository.class);
    SimpleExpression restriction = Restrictions.eq("contentType", type);
    SimpleExpression bothRestriction = Restrictions.eq("contentType", ContentType.BOTH);
    crit.add(Restrictions.or(restriction, bothRestriction));
    if (projectName != null) {
        crit.createAlias("project", "p");
        crit.add(Restrictions.eq("p.name", projectName));
    }
    List<Repository> list = crit.list();
    HibernateLazyInitializer.initCollection(list);
    return list;
}
 
Example #5
Source File: HibernateUtil.java    From SensorWebClient with GNU General Public License v2.0 5 votes vote down vote up
@SuppressWarnings("unchecked")
public static List<BasicRule> getAllOtherPublishedBasicRules(String userID) {
    Session session = getSessionFactory().getCurrentSession();
    session.beginTransaction();
    Criteria crit = session.createCriteria(BasicRule.class);
    Criterion isOwner = Restrictions.not(Restrictions.eq(OWNER_ID, valueOf(userID)));
    SimpleExpression isPublished = Restrictions.eq(PUBLISHED, true);
    List<BasicRule> rules = crit.add(Restrictions.and(isOwner, isPublished)).list();
    session.getTransaction().commit();
    return rules;
}
 
Example #6
Source File: HibernateUtil.java    From SensorWebClient with GNU General Public License v2.0 5 votes vote down vote up
@Deprecated
@SuppressWarnings("unchecked")
public static List<ComplexRule> getAllOtherPublishedComplexRules(String userID) {
    Session session = getSessionFactory().getCurrentSession();
    session.beginTransaction();
    Criteria crit = session.createCriteria(ComplexRule.class);
    Criterion isOwner = Restrictions.not(Restrictions.eq(OWNER_ID, valueOf(userID)));
    SimpleExpression isPublished = Restrictions.eq(PUBLISHED, true);
    List<ComplexRule> rules = crit.add(Restrictions.and(isOwner, isPublished)).list();
    session.getTransaction().commit();
    return rules;
}
 
Example #7
Source File: InvisibleForUsersRule.java    From mamute with Apache License 2.0 4 votes vote down vote up
private SimpleExpression isAuthor(String modelAlias) {
	return eq(modelAlias+".author.id", currentUser.getCurrent().getId());
}
 
Example #8
Source File: InvisibleForUsersRule.java    From mamute with Apache License 2.0 4 votes vote down vote up
private SimpleExpression isVisible(String modelAlias) {
	return eq(modelAlias+".moderationOptions.invisible", false);
}
 
Example #9
Source File: VisibleNewsFilter.java    From mamute with Apache License 2.0 4 votes vote down vote up
private SimpleExpression moderationOptionsVisible(String modelAlias) {
	return eq(modelAlias+".moderationOptions.invisible", false);
}