当前位置: 首页>>代码示例>>Java>>正文


Java Criteria.uniqueResult方法代码示例

本文整理汇总了Java中org.hibernate.Criteria.uniqueResult方法的典型用法代码示例。如果您正苦于以下问题:Java Criteria.uniqueResult方法的具体用法?Java Criteria.uniqueResult怎么用?Java Criteria.uniqueResult使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.hibernate.Criteria的用法示例。


在下文中一共展示了Criteria.uniqueResult方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: findBySSO

import org.hibernate.Criteria; //导入方法依赖的package包/类
public AdmUser findBySSO(String email) {
    logger.info("email : {}", email);
    Criteria crit = createEntityCriteria();
    crit.add(Restrictions.eq("email", email));
    AdmUser user = (AdmUser) crit.uniqueResult();
    if (user != null) {
        Hibernate.initialize(user.getUserRoles());
    }
    return user;
}
 
开发者ID:mustafamym,项目名称:FeedbackCollectionAndMgmtSystem,代码行数:11,代码来源:UserDaoImpl.java

示例2: getByMarketApp

import org.hibernate.Criteria; //导入方法依赖的package包/类
@Override
public CatalogConvertor getByMarketApp(Session sess, String marketName, short catalog, int subCatalog) {
    Criteria cri = sess.createCriteria(CatalogConvertor.class);
    CatalogConvertor catalogConvertor = new CatalogConvertor();
    catalogConvertor.setMarketName(marketName);
    catalogConvertor.setCatalog(catalog);
    catalogConvertor.setSubCatalog(subCatalog);
    Example example = Example.create(catalogConvertor);
    example.excludeZeroes();
    cri.add(example);

    Object o = cri.uniqueResult();
    if (o != null) {
        catalogConvertor = (CatalogConvertor) o;
    }
    return catalogConvertor;
}
 
开发者ID:zhaoxi1988,项目名称:sjk,代码行数:18,代码来源:CatalogConvertorDaoImpl.java

示例3: pageAdminsByConditions

import org.hibernate.Criteria; //导入方法依赖的package包/类
@SuppressWarnings("unchecked")
public Pagination<AdminDO> pageAdminsByConditions(Integer pageIndex, Integer pageSize, Map<String, Object> params){
    //获取记录总数
    Criteria criteria = daoSupport.createCriteria(AdminDO.class);
    //相当于 select count(uid)
    criteria.setProjection(Projections.count("uid"));
    //设置查询条件
    if (Objects.nonNull(params)) {
        criteria.add(Restrictions.allEq(params));
    }
    criteria.add(Restrictions.eq("editEnable", Boolean.TRUE));
    Long total = (Long) criteria.uniqueResult();

    //开始查询列表,首先清除count查询所用Projection
    criteria.setProjection(null);
    criteria.setFirstResult((pageIndex - 1)* pageSize);
    criteria.setMaxResults(pageIndex * pageSize);
    List<AdminDO> admins = criteria.list();

    Pagination<AdminDO> pagination = new Pagination<AdminDO>(Long.valueOf(pageIndex), Long.valueOf(pageSize), total);
    pagination.setItems(admins);
    return pagination;
}
 
开发者ID:wu05281,项目名称:admin-shiro,代码行数:24,代码来源:AdminService.java

示例4: allowAccess

import org.hibernate.Criteria; //导入方法依赖的package包/类
@Override
public boolean allowAccess(String marketName, String key) {
    Criteria cri = getSession().createCriteria(Market.class);
    Market entity = new Market();
    entity.setMarketName(marketName);
    entity.setAllowAccessKey(key);
    Example exa = Example.create(entity);
    exa.excludeZeroes();
    cri.add(exa);
    return cri.uniqueResult() != null;
}
 
开发者ID:zhaoxi1988,项目名称:sjk,代码行数:12,代码来源:MarketDaoImpl.java

示例5: removeUserTokens

import org.hibernate.Criteria; //导入方法依赖的package包/类
@Override
public void removeUserTokens(String username) {
	logger.info("Removing Token if any for user : {}", username);
	Criteria crit = createEntityCriteria();
	crit.add(Restrictions.eq("userEmail", username));
	UserSessions userSession = (UserSessions) crit.uniqueResult();
	if (userSession != null) {
		logger.info("rememberMe was selected");
		delete(userSession);
	}

}
 
开发者ID:mustafamym,项目名称:FeedbackCollectionAndMgmtSystem,代码行数:13,代码来源:HibernateTokenRepositoryImpl.java

示例6: count

import org.hibernate.Criteria; //导入方法依赖的package包/类
public int count (DetachedCriteria detached)
{
   Session session = getSessionFactory ().getCurrentSession ();
   Criteria criteria = detached.getExecutableCriteria (session);
   criteria.setProjection(Projections.rowCount());
   Object result = criteria.uniqueResult ();
   return ((Number) result).intValue ();
}
 
开发者ID:SentinelDataHub,项目名称:dhus-core,代码行数:9,代码来源:HibernateDao.java

示例7: isUnique

import org.hibernate.Criteria; //导入方法依赖的package包/类
/**
 * 判断对象某些属性的值在数据库中是否唯一.
 * 
 * @param entityClass
 *            实体类型
 * @param entity
 *            实体对象
 * @param uniquePropertyNames
 *            在POJO里不能重复的属性列表,以逗号分割 如"name,loginid,password"
 * @param <T>
 *            实体类泛型
 * @return 如果唯一返回true,否则返回false
 */
@Transactional(readOnly = true)
public <T> boolean isUnique(Class<T> entityClass, T entity,
        String uniquePropertyNames) throws NoSuchMethodException,
        IllegalAccessException, InvocationTargetException {
    Assert.hasText(uniquePropertyNames);

    Criteria criteria = createCriteria(entityClass).setProjection(
            Projections.rowCount());
    String[] nameList = uniquePropertyNames.split(",");

    // 循环加入唯一列
    for (String name : nameList) {
        String getterMethodName = ReflectUtils.getGetterMethodName(entity,
                name);
        criteria.add(Restrictions.eq(name,
                BeanUtils.invokeMethod(entity, getterMethodName)));
    }

    // 以下代码为了如果是update的情况,排除entity自身.
    String idName = getIdName(entityClass);

    // 取得entity的主键值
    Serializable id = getId(entityClass, entity);

    // 如果id!=null,说明对象已存在,该操作为update,加入排除自身的判断
    if (id != null) {
        criteria.add(Restrictions.not(Restrictions.eq(idName, id)));
    }

    Object result = criteria.uniqueResult();

    return HibernateUtils.getNumber(result) == 0;
}
 
开发者ID:zhaojunfei,项目名称:lemon,代码行数:47,代码来源:HibernateGenericDao.java

示例8: getPkByIdOfMarketApp

import org.hibernate.Criteria; //导入方法依赖的package包/类
@Override
public Integer getPkByIdOfMarketApp(int foreignKey) {
    Criteria cri = getSession().createCriteria(App.class);
    cri.add(Restrictions.eq("marketAppId", foreignKey));
    cri.setProjection(Projections.property("id"));
    try {
        Object o = cri.uniqueResult();
        if (o != null) {
            return (Integer) o;
        }
        return null;
    } catch (org.hibernate.AssertionFailure e) {
        return null;
    }
}
 
开发者ID:zhaoxi1988,项目名称:sjk,代码行数:16,代码来源:AppDaoImpl.java

示例9: getByManyId

import org.hibernate.Criteria; //导入方法依赖的package包/类
@Override
public MarketApp getByManyId(Session sess, String marketName, Integer appIdOfMarket, int apkIdOfMarket) {
    Criteria cri = sess.createCriteria(MarketApp.class);
    if (appIdOfMarket != null && appIdOfMarket.intValue() > 0) {
        cri.add(Restrictions.eq("appId", appIdOfMarket));
    }
    cri.add(Restrictions.eq("apkId", apkIdOfMarket));
    cri.add(Restrictions.eq("marketName", marketName));
    cri.setCacheable(false);
    Object o = cri.uniqueResult();
    if (o != null) {
        return (MarketApp) o;
    }
    return null;
}
 
开发者ID:zhaoxi1988,项目名称:sjk,代码行数:16,代码来源:MarketAppDaoImpl.java

示例10: execute

import org.hibernate.Criteria; //导入方法依赖的package包/类
public HistoryVariable execute(Context context) {
	Criteria criteria=context.getSession().createCriteria(HistoryVariable.class);
	criteria.add(Restrictions.eq("historyProcessInstanceId", historyProcessInstanceId));
	criteria.add(Restrictions.eq("key", key));
	HistoryVariable hisVar=(HistoryVariable)criteria.uniqueResult();
	if(hisVar!=null){
		hisVar.init(context);			
	}
	return hisVar;
}
 
开发者ID:youseries,项目名称:uflo,代码行数:11,代码来源:GetHistoryVariableCommand.java

示例11: find

import org.hibernate.Criteria; //导入方法依赖的package包/类
@Sessional
@Override
public <T extends AbstractEntity> T find(EntityCriteria<T> entityCriteria) {
	Criteria criteria = entityCriteria.getExecutableCriteria(getSession());
	criteria.setFirstResult(0);
	criteria.setMaxResults(1);
	return (T) criteria.uniqueResult();
}
 
开发者ID:jmfgdev,项目名称:gitplex-mit,代码行数:9,代码来源:DefaultDao.java

示例12: getTokenForSeries

import org.hibernate.Criteria; //导入方法依赖的package包/类
@Override
public PersistentRememberMeToken getTokenForSeries(String seriesId) {
    logger.info("Fetch Token if any for seriesId : {}", seriesId);
    try {
        Criteria crit = createEntityCriteria();
        crit.add(Restrictions.eq("series", seriesId));
        PersistentLogin persistentLogin = (PersistentLogin) crit.uniqueResult();

        return new PersistentRememberMeToken(persistentLogin.getUsername(), persistentLogin.getSeries(),
                persistentLogin.getToken(), persistentLogin.getLast_used());
    } catch (Exception e) {
        logger.info("Token not found...");
        return null;
    }
}
 
开发者ID:TomirKlos,项目名称:Webstore,代码行数:16,代码来源:HibernateTokenRepositoryImpl.java

示例13: findByType

import org.hibernate.Criteria; //导入方法依赖的package包/类
public UserRoles findByType(String type) {
	Criteria crit = createEntityCriteria();
	crit.add(Restrictions.eq("permissionType", type));
	return (UserRoles) crit.uniqueResult();
}
 
开发者ID:mustafamym,项目名称:FeedbackCollectionAndMgmtSystem,代码行数:6,代码来源:UserProfileDaoImpl.java

示例14: findFirst

import org.hibernate.Criteria; //导入方法依赖的package包/类
@Override
public T findFirst(Criterion... criterions) {
	Criteria c = createCriteria(criterions);
	c.setMaxResults(1);
	return (T) c.uniqueResult();
}
 
开发者ID:wkeyuan,项目名称:DWSurvey,代码行数:7,代码来源:HibernateDao.java

示例15: deleteBySSO

import org.hibernate.Criteria; //导入方法依赖的package包/类
public void deleteBySSO(String sso) {
    Criteria crit = createEntityCriteria();
    crit.add(Restrictions.eq("userId", sso));
    AdmUser user = (AdmUser) crit.uniqueResult();
    delete(user);
}
 
开发者ID:mustafamym,项目名称:FeedbackCollectionAndMgmtSystem,代码行数:7,代码来源:UserDaoImpl.java


注:本文中的org.hibernate.Criteria.uniqueResult方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。