org.hibernate.criterion.Criterion Java Examples

The following examples show how to use org.hibernate.criterion.Criterion. 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: ConfidenceStatisticsResourceFacadeImp.java    From AIDR with GNU Affero General Public License v3.0 6 votes vote down vote up
@Override
public List<ConfidenceData> getDataAfterTimestampGranularityInBin(String crisisCode, String attributeCode, String labelCode,
																	Long timestamp, Long granularity, Integer bin) {
	Criteria criteria = getCurrentSession().createCriteria(ConfidenceData.class);
	Criterion criterion = Restrictions.conjunction()
			.add(Restrictions.eq("crisisCode", crisisCode))
			.add(Restrictions.eq("attributeCode", attributeCode))
			.add(Restrictions.eq("labelCode", labelCode))
			.add(Restrictions.ge("timestamp", timestamp))
			.add(Restrictions.eq("granularity", granularity))
			.add(Restrictions.eq("bin", bin));
			
	criteria.add(criterion); 		
	try {
		List<ConfidenceData> objList = (List<ConfidenceData>) criteria.list();
		return objList;
	} catch (HibernateException e) {
		logger.error("exception", e);
		e.printStackTrace();
	}
	return null;
}
 
Example #2
Source File: TagDataStatisticsResourceFacadeImp.java    From AIDR with GNU Affero General Public License v3.0 6 votes vote down vote up
@Override
public List<TagData> getDataBeforeTimestampGranularity(String crisisCode, String attributeCode, String labelCode, 
		Long timestamp, Long granularity) {
	Criteria criteria = getCurrentSession().createCriteria(TagData.class);
	Criterion criterion = Restrictions.conjunction()
			.add(Restrictions.eq("crisisCode", crisisCode))
			.add(Restrictions.eq("attributeCode", attributeCode))
			.add(Restrictions.le("timestamp", timestamp))
			.add(Restrictions.eq("granularity", granularity));
	if (labelCode != null) {
		criterion = Restrictions.conjunction()
				.add(criterion)
				.add(Restrictions.eq("labelCode", labelCode));
	}

	criteria.add(criterion);
	try {
		List<TagData> objList = (List<TagData>) criteria.list();
		return objList;
	} catch (HibernateException e) {
		logger.error("exception in getDataBeforeTimestampGranularity for crisisCode : " + crisisCode
				+ " attributeCode : " + attributeCode + " timestamp : " + timestamp
				+ " granularity : " + granularity, e);
	}
	return null;
}
 
Example #3
Source File: ConfidenceStatisticsResourceFacadeImp.java    From AIDR with GNU Affero General Public License v3.0 6 votes vote down vote up
@Override
public List<ConfidenceData> getDataAfterTimestamp(String crisisCode, String attributeCode, String labelCode, Long timestamp) {
	Criteria criteria = getCurrentSession().createCriteria(ConfidenceData.class);
	Criterion criterion = Restrictions.conjunction()
			.add(Restrictions.eq("crisisCode", crisisCode))
			.add(Restrictions.eq("attributeCode", attributeCode))
			.add(Restrictions.eq("labelCode", labelCode))
			.add(Restrictions.ge("timestamp", timestamp));
			
	criteria.add(criterion); 		
	try {
		List<ConfidenceData> objList = (List<ConfidenceData>) criteria.list();
		return objList;
	} catch (HibernateException e) {
		logger.error("exception", e);
		e.printStackTrace();
	}
	return null;	
}
 
Example #4
Source File: ConfidenceStatisticsResourceFacadeImp.java    From AIDR with GNU Affero General Public License v3.0 6 votes vote down vote up
@Override
public List<ConfidenceData> getDataBeforeTimestampInBin(String crisisCode, String attributeCode, String labelCode, 
																	Long timestamp, Integer bin) {
	Criteria criteria = getCurrentSession().createCriteria(ConfidenceData.class);
	Criterion criterion = Restrictions.conjunction()
			.add(Restrictions.eq("crisisCode", crisisCode))
			.add(Restrictions.eq("attributeCode", attributeCode))
			.add(Restrictions.eq("labelCode", labelCode))
			.add(Restrictions.le("timestamp", timestamp))
			.add(Restrictions.eq("bin", bin));
			
	criteria.add(criterion); 		
	try {
		List<ConfidenceData> objList = (List<ConfidenceData>) criteria.list();
		return objList;
	} catch (HibernateException e) {
		logger.error("exception", e);
		e.printStackTrace();
	}
	return null;
}
 
Example #5
Source File: ConfidenceStatisticsResourceFacadeImp.java    From AIDR with GNU Affero General Public License v3.0 6 votes vote down vote up
@Override
public List<ConfidenceData> getDataByCrisisWithBin(String crisisCode, Integer bin) {
	Criteria criteria = getCurrentSession().createCriteria(ConfidenceData.class);
	Criterion criterion = Restrictions.conjunction()
			.add(Restrictions.eq("crisisCode", crisisCode))
			.add(Restrictions.ge("bin", bin));
	criteria.add(criterion); 
	try {
		List<ConfidenceData> objList = (List<ConfidenceData>) criteria.list();
		return objList;
	} catch (HibernateException e) {
		logger.error("exception", e);
		e.printStackTrace();
	}
	return null;
}
 
Example #6
Source File: ConfidenceStatisticsResourceFacadeImp.java    From AIDR with GNU Affero General Public License v3.0 6 votes vote down vote up
@Override
public List<ConfidenceData> getDataInIntervalWithBin(String crisisCode, String attributeCode, String labelCode, Long timestamp1,
																	Long timestamp2, Integer bin) {
	Criteria criteria = getCurrentSession().createCriteria(ConfidenceData.class);
	Criterion criterion = Restrictions.conjunction()
			.add(Restrictions.eq("crisisCode", crisisCode))
			.add(Restrictions.eq("attributeCode", attributeCode))
			.add(Restrictions.eq("labelCode", labelCode))
			.add(Restrictions.ge("timestamp", timestamp1))
			.add(Restrictions.le("timestamp", timestamp2))
			.add(Restrictions.ge("bin", bin));
			
	criteria.add(criterion); 		
	try {
		List<ConfidenceData> objList = (List<ConfidenceData>) criteria.list();
		return objList;
	} catch (HibernateException e) {
		logger.error("exception", e);
		e.printStackTrace();
	}
	return null;
}
 
Example #7
Source File: TestHibernateStorage.java    From gsn with GNU General Public License v3.0 6 votes vote down vote up
@Test
public void testPaginatedQueryWitCriterionWithLimit() {
    int numberOfElements = 817;
    String identifier = "testPaginatedQueryWitCriterionWithLimit";
    generateDataTest(identifier, numberOfElements);
    //
    DataField[] structure = dataField.toArray(new DataField[]{});
    HibernateStorage storage = HibernateStorage.newInstance(dbInfo, identifier, dataField.toArray(new DataField[]{}), false);
    assertNotNull(storage);
    //
    int[] pageSizes = new int[]{1, 11, numberOfElements / 2, numberOfElements / 3, numberOfElements / 3 - 1, numberOfElements / 3 + 1, numberOfElements - 1, numberOfElements + 1, numberOfElements * 2};
    //
    for (int pageSize : pageSizes) {
        System.out.println("testPaginatedQueryWitCriterionWithLimit with pageSize: " + pageSize);
        // Set the limit to a fixed number: 1 and timed > numberOfElements/2
        checkQueryResult(storage.getStreamElements(pageSize, Order.asc("timed"), new Criterion[]{Restrictions.gt("timed", (long)numberOfElements/2)}, 1), numberOfElements/2+1, numberOfElements/2+1);
        // Set the limit to a fixed number: 11 and timed > numberOfElements/2
        checkQueryResult(storage.getStreamElements(pageSize, Order.asc("timed"), new Criterion[]{Restrictions.gt("timed", (long)numberOfElements/2)}, 11), numberOfElements/2+1, numberOfElements/2+11);
        // Set the limit to 0 and timed > numberOfElements/2
        checkQueryResult(storage.getStreamElements(pageSize, Order.asc("timed"), new Criterion[]{Restrictions.gt("timed", (long)numberOfElements/2)}, 0), -1, -1);
    }
}
 
Example #8
Source File: DefaultPullRequestManager.java    From onedev with MIT License 6 votes vote down vote up
@Sessional
@Override
public Map<ProjectAndBranch, PullRequest> findEffectives(ProjectAndBranch target, Collection<ProjectAndBranch> sources) {
	EntityCriteria<PullRequest> criteria = EntityCriteria.of(PullRequest.class);
	Collection<Criterion> criterions = new ArrayList<>();
	for (ProjectAndBranch source: sources) {
		Criterion merged = Restrictions.and(
				Restrictions.eq(PullRequest.PROP_CLOSE_INFO + "." + CloseInfo.PROP_STATUS, CloseInfo.Status.MERGED), 
				Restrictions.eq(PullRequest.PROP_LAST_MERGE_PREVIEW + "." + MergePreview.PROP_HEAD_COMMIT_HASH, source.getObjectName()));
		criterions.add(Restrictions.and(ofTarget(target), ofSource(source), Restrictions.or(ofOpen(), merged)));
	}
	criteria.add(Restrictions.or(criterions.toArray(new Criterion[0])));
	
	Map<ProjectAndBranch, PullRequest> requests = new HashMap<>();
	for(PullRequest request: query(criteria)) 
		requests.put(new ProjectAndBranch(request.getSourceProject(), request.getSourceBranch()), request);
	
	return requests;
}
 
Example #9
Source File: CriteriaParameter.java    From Knowage-Server with GNU Affero General Public License v3.0 6 votes vote down vote up
public Criterion toHibernateCriterion() {
	Criterion restriction = null;
	switch (getMatch()) {
	case LIKE:
		restriction = Restrictions.like(getName(), (String) getValue(), MatchMode.ANYWHERE);
		break;
	case ILIKE:
		restriction = Restrictions.like(getName(), (String) getValue(), MatchMode.ANYWHERE).ignoreCase();
		break;
	case NOT_EQ:
		restriction = Restrictions.ne(getName(), getValue());
		break;
	case IN:
		restriction = Restrictions.in(getName(), (Object[]) getValue());
		break;
	case NOT_IN:
		restriction = Restrictions.not(Restrictions.in(getName(), (Object[]) getValue()));
		break;
	default:
		restriction = Restrictions.eq(getName(), getValue());
		break;
	}
	return restriction;
}
 
Example #10
Source File: DocumentResourceFacadeImp.java    From AIDR with GNU Affero General Public License v3.0 6 votes vote down vote up
@Override
public List<DocumentDTO> findLabeledDocumentsByCrisisID(Long crisisId) throws PropertyNotSetException {
	Criterion criterion = Restrictions.conjunction()
			.add(Restrictions.eq("collection.id",crisisId))
			.add(Restrictions.eq("hasHumanLabels", true));
	List<DocumentDTO> dtoList = new ArrayList<DocumentDTO>();
	List<Document> list = this.getAllByCriteria(criterion);
	if (list != null && !list.isEmpty()) {
		for (Document doc : list) {
			DocumentDTO dto = new DocumentDTO(doc);
			dtoList.add(dto);
		}
	}
	logger.info("Done creating DTO list, size = " + dtoList.size());
	return dtoList;
}
 
Example #11
Source File: RoleRepositoryImpl.java    From AIDR with GNU Affero General Public License v3.0 6 votes vote down vote up
@Override
public Role findByRoleType(RoleType roleType) {
	Role role = null;
	
	try {
		Criteria criteria = getHibernateTemplate().getSessionFactory()
				.getCurrentSession().createCriteria(Role.class);
		Criterion criterion = Restrictions.eq("roleType", roleType);
		criteria.add(criterion);
	    role = (Role) criteria.uniqueResult();
	} catch(Exception e) {
		logger.error("Error in fetching data by roleType : " +roleType, e);
	}
	
	return role;
}
 
Example #12
Source File: SbiMetaTableColumnDAOHibImpl.java    From Knowage-Server with GNU Affero General Public License v3.0 6 votes vote down vote up
/**
 * Load all tablecolumn column linked to a table.
 *
 * @param session
 *            the session
 *
 * @return List of meta tables
 *
 * @throws EMFUserError
 *             the EMF user error
 *
 * @see it.eng.spagobi.metadata.dao.ISbiMetaTableColumnDAOHibImpl#loadTableColumnsFromTable(session, tableId)
 */
@Override
public List<SbiMetaTableColumn> loadTableColumnsFromTable(Session session, int tableId) throws EMFUserError {
	logger.debug("IN");

	List<SbiMetaTableColumn> toReturn = null;

	try {
		Criterion labelCriterrion = Expression.eq("sbiMetaTable.tableId", tableId);
		Criteria criteria = session.createCriteria(SbiMetaTableColumn.class);
		criteria.add(labelCriterrion);

		toReturn = criteria.list();

	} catch (HibernateException he) {
		logException(he);
		throw new HibernateException(he);
	} finally {
		logger.debug("OUT");
	}
	return toReturn;
}
 
Example #13
Source File: CustomUiTemplateResourceFacadeImp.java    From AIDR with GNU Affero General Public License v3.0 6 votes vote down vote up
@Override
public List<CustomUiTemplateDTO> getCustomUITemplateBasedOnTypeByCrisisIDAttributeIDAndStatus(long crisisID, long attributeID, int templateType, int status) {
	Criterion criterion = Restrictions.conjunction()
			.add(Restrictions.eq("crisisID",crisisID))
			.add(Restrictions.eq("templateType", templateType))
			.add(Restrictions.eq("nominalAttributeID", attributeID))
			.add(Restrictions.eq("status", status));
	List<CustomUiTemplateDTO> dtoList = null;
	try {
		List<CustomUiTemplate> customUITemplates = this.getAllByCriteria(criterion);
		if (customUITemplates != null) {
			dtoList = new ArrayList<CustomUiTemplateDTO>(0);
			for (CustomUiTemplate c: customUITemplates) {
				CustomUiTemplateDTO dto = new CustomUiTemplateDTO(c);
				dtoList.add(dto);
			}
		}
		return dtoList;
	} catch (Exception e) {
		logger.error("Error in getCustomUITemplateBasedOnTypeByCrisisIDAttributeIDAndStatus for crisisID : " + crisisID
			+ " and attributeID : " + attributeID);
		return null;
	}
}
 
Example #14
Source File: LikeOperator.java    From dhis2-core with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Override
public Criterion getHibernateCriterion( QueryPath queryPath )
{
    if ( caseSensitive )
    {
        return Restrictions.like( queryPath.getPath(), String.valueOf( args.get( 0 ) ).replace( "%", "\\%" ), matchMode );
    }
    else
    {
        return Restrictions.ilike( queryPath.getPath(), String.valueOf( args.get( 0 ) ).replace( "%", "\\%" ), matchMode );
    }
}
 
Example #15
Source File: CriteriaImpl.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
private Subcriteria(Criteria parent, String path, String alias, JoinType joinType, Criterion withClause) {
	this.alias = alias;
	this.path = path;
	this.parent = parent;
	this.joinType = joinType;
	this.withClause = withClause;
	this.hasRestriction = withClause != null;
	CriteriaImpl.this.subcriteriaList.add( this );
}
 
Example #16
Source File: CriteriaQuery.java    From jeewx with Apache License 2.0 5 votes vote down vote up
/**
 * 设置between(之间)查询条件
 * 
 * @param keyname
 * @param keyvalue1
 * @param keyvalue2
 */
public void between(String keyname, Object keyvalue1, Object keyvalue2) {
	Criterion c = null;// 写入between查询条件

	if (!keyvalue1.equals(null) && !keyvalue2.equals(null)) {
		c = Restrictions.between(keyname, keyvalue1, keyvalue2);
	} else if (!keyvalue1.equals(null)) {
		c = Restrictions.ge(keyname, keyvalue1);
	} else if (!keyvalue2.equals(null)) {
		c = Restrictions.le(keyname, keyvalue2);
	}
	criterionList.add(c);
}
 
Example #17
Source File: SQLVisitor.java    From DataHubSystem with GNU Affero General Public License v3.0 5 votes vote down vote up
private Criterion getCriterionLogical(BinaryOperator operator,
      Criterion left, Criterion right)
{
   Criterion criterion;
   if (left == null && right == null)
   {
      criterion = null;
   }
   else if (left != null && right != null)
   {
      switch (operator)
      {
         case AND:
         {
            criterion = Restrictions.and(left, right);
            break;
         }
         case OR:
         {
            criterion = Restrictions.or(left, right);
            break;
         }
         default:
         {
            throw new UnsupportedOperationException(
                  "Unsupported operator: " + operator.toUriLiteral());
         }
      }
   }
   else if (left == null)
   {
      criterion = right;
   }
   else
   {
      criterion = left;
   }
   return criterion;
}
 
Example #18
Source File: QuOrderbyManagerImpl.java    From DWSurvey with GNU Affero General Public License v3.0 5 votes vote down vote up
public int getOrderById(String quId){
	Criterion criterion=Restrictions.eq("quId", quId);
	QuOrderby quOrderby=quOrderbyDao.findFirst("orderById", false, criterion);
	if(quOrderby!=null){
		return quOrderby.getOrderById();
	}
	return 0;
}
 
Example #19
Source File: InvisibleForUsersRuleTest.java    From mamute with Apache License 2.0 5 votes vote down vote up
@Test
public void should_not_add_filter_if_user_is_moderator() {
	LoggedUser user = new LoggedUser(user("leonardo", "[email protected]").asModerator(), null);
	InvisibleForUsersRule invisibleForUsersRule = new InvisibleForUsersRule(user);

	invisibleForUsersRule.addFilter("x", criteria);
	
	verify(criteria, never()).add(Mockito.any(Criterion.class));
}
 
Example #20
Source File: AbstractDaoImpl.java    From AIDR with GNU Affero General Public License v3.0 5 votes vote down vote up
@Override
public List<E> findByCriteria(Criterion criterion, Integer count) {
    Criteria criteria = getCurrentSession().createCriteria(entityClass);
    criteria.add(criterion);

    if(count != null){
        criteria.setMaxResults(count);
    }
    return criteria.list();
}
 
Example #21
Source File: SbiMetaBcAttributeDAOHibImpl.java    From Knowage-Server with GNU Affero General Public License v3.0 5 votes vote down vote up
/**
 * Load BCAttribute by name.
 *
 * @param name
 *            the BCAttribute name
 *
 * @return the meta BCAttribute
 *
 * @throws EMFUserError
 *             the EMF user error
 *
 * @see it.eng.spagobi.metadata.dao.ISbiMetaBcAttributeDAOHibImpl#loadBcAttributeByName(string)
 */
@Override
public SbiMetaBcAttribute loadBcAttributeByName(String name) throws EMFUserError {
	logger.debug("IN");

	SbiMetaBcAttribute toReturn = null;
	Session tmpSession = null;
	Transaction tx = null;

	try {
		tmpSession = getSession();
		tx = tmpSession.beginTransaction();
		Criterion labelCriterrion = Expression.eq("name", name);
		Criteria criteria = tmpSession.createCriteria(SbiMetaBcAttribute.class);
		criteria.add(labelCriterrion);
		toReturn = (SbiMetaBcAttribute) criteria.uniqueResult();
		if (toReturn == null)
			return null;
		tx.commit();

	} catch (HibernateException he) {
		logException(he);
		if (tx != null)
			tx.rollback();
		throw new EMFUserError(EMFErrorSeverity.ERROR, 100);
	} finally {
		if (tmpSession != null) {
			if (tmpSession.isOpen())
				tmpSession.close();
		}
	}

	logger.debug("OUT");
	return toReturn;
}
 
Example #22
Source File: MenuDAOImpl.java    From Knowage-Server with GNU Affero General Public License v3.0 5 votes vote down vote up
@Override
public SbiMenu loadSbiMenubyName(String name) {
	Session tmpSession = null;
	Transaction tx = null;

	try {
		tmpSession = getSession();
		tx = tmpSession.beginTransaction();

		Criterion domainCdCriterrion = Expression.eq("name", name);
		Criteria criteria = tmpSession.createCriteria(SbiMenu.class);
		criteria.add(domainCdCriterrion);
		SbiMenu hibMenu = (SbiMenu) criteria.uniqueResult();

		return hibMenu;
	} catch (HibernateException he) {
		logException(he);
		if (tx != null)
			tx.rollback();

	} finally {
		if (tmpSession != null) {
			if (tmpSession.isOpen())
				tmpSession.close();
		}
	}
	return null;
}
 
Example #23
Source File: QuChenColumnManagerImpl.java    From DWSurvey with GNU Affero General Public License v3.0 5 votes vote down vote up
public int getOrderById(String quId){
	Criterion criterion=Restrictions.eq("quId", quId);
	QuChenColumn quChenColumn=chenColumnDao.findFirst("orderById", false, criterion);
	if(quChenColumn!=null){
		return quChenColumn.getOrderById();
	}
	return 0;
}
 
Example #24
Source File: InterroleController.java    From jeecg with Apache License 2.0 5 votes vote down vote up
/**
 * 用户列表查询
 * 
 * @param request
 * @param response
 * @param dataGrid
 */
@RequestMapping(params = "roleUserDatagrid")
public void roleUserDatagrid(TSUser user, HttpServletRequest request, HttpServletResponse response,
		DataGrid dataGrid) {
	CriteriaQuery cq = new CriteriaQuery(TSUser.class, dataGrid);
	// 查询条件组装器
	String roleId = request.getParameter("roleId");
	// List<TSRoleUser> roleUser =
	// systemService.findByProperty(TSRoleUser.class, "TSRole.id", roleId);
	List<InterroleUserEntity> interRoleUser = systemService.findByProperty(InterroleUserEntity.class,
			"interroleEntity.id", roleId);
	/*
	 * // zhanggm:这个查询逻辑也可以使用这种 子查询的方式进行查询 CriteriaQuery subCq = new
	 * CriteriaQuery(TSRoleUser.class);
	 * subCq.setProjection(Property.forName("TSUser.id"));
	 * subCq.eq("TSRole.id", roleId); subCq.add();
	 * cq.add(Property.forName("id").in(subCq.getDetachedCriteria()));
	 * cq.add();
	 */
	Criterion cc = null;
	if (interRoleUser.size() > 0) {
		for (int i = 0; i < interRoleUser.size(); i++) {
			if (i == 0) {
				cc = Restrictions.eq("id", interRoleUser.get(i).getTSUser().getId());
			} else {
				cc = cq.getor(cc, Restrictions.eq("id", interRoleUser.get(i).getTSUser().getId()));
			}
		}
	} else {
		cc = Restrictions.eq("id", "-1");
	}
	cq.add(cc);
	cq.eq("deleteFlag", Globals.Delete_Normal);
	cq.add();
	org.jeecgframework.core.extend.hqlsearch.HqlGenerateUtil.installHql(cq, user);
	this.systemService.getDataGridReturn(cq, true);
	TagUtil.datagrid(response, dataGrid);
}
 
Example #25
Source File: InvisibleForUsersRuleTest.java    From mamute with Apache License 2.0 5 votes vote down vote up
@Test
public void should_add_filter_if_user_is_not_moderator() {
	LoggedUser user = new LoggedUser(user("leonardo", "[email protected]"), null);
	InvisibleForUsersRule invisibleForUsersRule = new InvisibleForUsersRule(user);
	
	invisibleForUsersRule.addFilter("x", criteria);
	
	verify(criteria, only()).add(Mockito.any(Criterion.class));
}
 
Example #26
Source File: SbiMetaTableColumnDAOHibImpl.java    From Knowage-Server with GNU Affero General Public License v3.0 5 votes vote down vote up
@Override
public void modifyTableColumn(Session session, SbiMetaTableColumn aMetaTableColumn) throws EMFUserError {
	logger.debug("IN");

	Session tmpSession = session;

	try {
		SbiMetaTableColumn hibMeta = (SbiMetaTableColumn) tmpSession.load(SbiMetaTableColumn.class, aMetaTableColumn.getColumnId());

		hibMeta.setName(aMetaTableColumn.getName());
		hibMeta.setType(aMetaTableColumn.getType());
		hibMeta.setDeleted(aMetaTableColumn.isDeleted());

		SbiMetaTable metaTable = null;
		if (aMetaTableColumn.getSbiMetaTable().getTableId() < 0) {
			Criterion aCriterion = Expression.eq("valueId", aMetaTableColumn.getSbiMetaTable().getTableId());
			Criteria criteria = tmpSession.createCriteria(SbiMetaSource.class);
			criteria.add(aCriterion);
			metaTable = (SbiMetaTable) criteria.uniqueResult();
			if (metaTable == null) {
				throw new SpagoBIDAOException("The SbiMetaTable with id= " + aMetaTableColumn.getSbiMetaTable().getTableId() + " does not exist");
			}
			hibMeta.setSbiMetaTable(metaTable);
		}

		updateSbiCommonInfo4Update(hibMeta);

	} catch (HibernateException he) {
		logException(he);
		throw new HibernateException(he);
	} finally {
		logger.debug("OUT");
	}
}
 
Example #27
Source File: HibernateStorage.java    From sailfish-core with Apache License 2.0 5 votes vote down vote up
@Override
@SuppressWarnings("unchecked")
public <T> List<T> getAllEntities(Class<T> entityClass, List<Criterion> criterions, String orderField, boolean orderAsc) {
	
	Session session = null;
	
	try {
           session = sessionFactory.openSession();
		
		Criteria criteria = session.createCriteria(entityClass);
		
		for (Criterion criterion : criterions) {
			criteria.add(criterion);
		}

           criteria.addOrder(orderAsc ? Order.asc(orderField) : Order.desc(orderField));
           criteria.setResultTransformer(Criteria.DISTINCT_ROOT_ENTITY);
		
		return criteria.list();
		
	} finally {
           if(session != null) {
               session.close();
           }
	}
	
}
 
Example #28
Source File: HibernateDao.java    From DWSurvey with GNU Affero General Public License v3.0 5 votes vote down vote up
/**
 * 按属性条件参数创建Criterion,辅助函数.
 */
protected Criterion buildCriterion(final String propertyName, final Object propertyValue, final MatchType matchType) {
	AssertUtils.hasText(propertyName, "propertyName不能为空");
	Criterion criterion = null;
	//根据MatchType构造criterion
	switch (matchType) {
	case EQ:
		criterion = Restrictions.eq(propertyName, propertyValue);
		break;
	case LIKE:
		criterion = Restrictions.like(propertyName, (String) propertyValue, MatchMode.ANYWHERE);
		break;

	case LE:
		criterion = Restrictions.le(propertyName, propertyValue);
		break;
	case LT:
		criterion = Restrictions.lt(propertyName, propertyValue);
		break;
	case GE:
		criterion = Restrictions.ge(propertyName, propertyValue);
		break;
	case GT:
		criterion = Restrictions.gt(propertyName, propertyValue);
		break;
	case NE:
		criterion = Restrictions.ne(propertyName, propertyValue);
	}
	return criterion;
}
 
Example #29
Source File: ModeratorOrVisibleNewsFilterTest.java    From mamute with Apache License 2.0 5 votes vote down vote up
@Test
public void should_not_add_filter_if_user_is_moderator() {
	LoggedUser user = new LoggedUser(user("leonardo", "[email protected]").asModerator(), null);
	ModeratorOrVisibleNewsFilter moderatorOrVisible = new ModeratorOrVisibleNewsFilter(user, null);

	moderatorOrVisible.addFilter("x", criteria);
	
	verify(criteria, never()).add(Mockito.any(Criterion.class));
}
 
Example #30
Source File: DocumentFacadeImp.java    From AIDR with GNU Affero General Public License v3.0 5 votes vote down vote up
@Override
public ResponseWrapper removeTrainingExample(Long documentID) {
	// Alternative way of doing the same update
	//qa.qcri.aidr.task.dto.DocumentDTO fetchedDoc  = remoteTaskManager.getTaskById(id);
	//fetchedDoc.setHasHumanLabels(false);
	//fetchedDoc.setNominalLabelCollection(null);
	//taskManager.updateTask(fetchedDoc);

	Map<String, String> paramMap = new HashMap<String, String>();
	paramMap.put("setHasHumanLabels", new Boolean(false).toString());
	try {
		DocumentDTO newDoc = (DocumentDTO) remoteTaskManager.setTaskParameter(qa.qcri.aidr.dbmanager.entities.task.Document.class, documentID, paramMap);
		if (newDoc != null) {
			Criterion criterion = Restrictions.eq("id.documentId", documentID);
			remoteDocumentNominalLabel.deleteByCriteria(criterion);
			if (!remoteDocumentNominalLabel.isDocumentExists(documentID)) {
				logger.info("Removed training example: " + newDoc.getDocumentID() + ", for crisisID = " + newDoc.getCrisisDTO().getCrisisID());
				return new ResponseWrapper(TaggerAPIConfigurator.getInstance().getProperty(TaggerAPIConfigurationProperty.STATUS_CODE_SUCCESS),
						"Deleted training example id " + documentID);
			} else {
				logger.error("Could NOT remove document from document nominal label table! id = " + documentID + "hasHumanLabels = " + remoteDocument.findDocumentByID(documentID).getHasHumanLabels());
				return new ResponseWrapper(TaggerAPIConfigurator.getInstance().getProperty(TaggerAPIConfigurationProperty.STATUS_CODE_FAILED),
						"Error while deleting training example id " + documentID);
			}
		} else {
			logger.error("Could NOT remove document from document nominal label table! id = " + documentID + "hasHumanLabels = " + remoteDocument.findDocumentByID(documentID).getHasHumanLabels());
			return new ResponseWrapper(TaggerAPIConfigurator.getInstance().getProperty(TaggerAPIConfigurationProperty.STATUS_CODE_FAILED),
					"Error while deleting training example id " + documentID);
		}
	} catch (Exception e) {
		logger.error("Error while deleting training example id " + documentID, e);
		return new ResponseWrapper(TaggerAPIConfigurator.getInstance().getProperty(TaggerAPIConfigurationProperty.STATUS_CODE_FAILED),
				"Error while deleting training example id " + documentID);
	}
}