本文整理匯總了Java中org.hibernate.criterion.MatchMode.EXACT屬性的典型用法代碼示例。如果您正苦於以下問題:Java MatchMode.EXACT屬性的具體用法?Java MatchMode.EXACT怎麽用?Java MatchMode.EXACT使用的例子?那麽, 這裏精選的屬性代碼示例或許可以為您提供幫助。您也可以進一步了解該屬性所在類org.hibernate.criterion.MatchMode
的用法示例。
在下文中一共展示了MatchMode.EXACT屬性的5個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: runTaxonomyQuery
private List<Taxonomy> runTaxonomyQuery(String query)
{
MatchMode[] modes = {MatchMode.EXACT, MatchMode.START, MatchMode.ANYWHERE};
LinkedHashSet<Taxonomy> results = new LinkedHashSet<Taxonomy>();
for ( MatchMode mode : modes ) {
log.info("Running match mode: "+mode);
List<Taxonomy> taxes = runTaxonomyQuery(query,mode);
results.addAll(taxes);
if(results.size() >= 10){
log.info("Exiting because of results.size() being >= 10");
}else if(results.size() > 0 && mode == MatchMode.EXACT){
log.info("Exiting because of exact match");
}
if ( (results.size() >= 10) || (results.size() > 0 && mode == MatchMode.EXACT) ) {
log.info("Results size:"+results.size());
return new ArrayList<Taxonomy>(results);
}
}
return new ArrayList<Taxonomy>(results);
}
示例2: formatExpr
private String formatExpr(String p1, String p2, MatchMode mode) {
String pct = "'%'";
String expr = p1 + " like ";
if (mode == MatchMode.ANYWHERE) {
return expr + "concat(" + pct + "," + p2 + "," + pct + ")";
} else if (mode == MatchMode.START) {
return expr + "concat(" + p2 + "," + pct + ")";
} else if (mode == MatchMode.END) {
return expr + "concat(" + pct + "," + p2 + ")";
} else if (mode == MatchMode.EXACT) {
return expr + p2;
} else {
throw new RuntimeException("Unrecognized MatchMode: " + mode);
}
}
示例3: toHibernateMatchMode
/**
* Convert match type to Hibernate match mode
*
* @param matchType
* match type
* @return corresponding Hibernate match mode
*/
private static MatchMode toHibernateMatchMode(final MatchType matchType)
{
switch (matchType)
{
case EXACT:
{
return MatchMode.EXACT;
}
case STARTS_WITH:
{
return MatchMode.START;
}
case ENDS_WITH:
{
return MatchMode.END;
}
case CONTAINS:
{
return MatchMode.ANYWHERE;
}
}
return null;
}
示例4: testMatches
/**
* The test.
*/
@Test
public void testMatches() {
String prefix = UUID.randomUUID().toString();
String mainContent = UUID.randomUUID().toString();
String suffix = UUID.randomUUID().toString();
NoteData noteListData = new NoteData();
noteListData.setContent(prefix + mainContent + suffix);
noteListData.setId(1L);
NoteService noteService = EasyMock.createMock(NoteService.class);
EasyMock.expect(noteService.getNote(EasyMock.anyLong(),
EasyMock.anyObject(Converter.class)))
.andReturn(noteListData.getContent()).anyTimes();
EasyMock.replay(noteService);
Matcher<NoteData> matcher = new FullTextSearchFiltersMatcher(noteService,
MatchMode.ANYWHERE);
Assert.assertTrue(matcher.matches(noteListData));
// Anywhere
matcher = new FullTextSearchFiltersMatcher(noteService, MatchMode.ANYWHERE, prefix,
mainContent, suffix);
Assert.assertTrue(matcher.matches(noteListData));
matcher = new FullTextSearchFiltersMatcher(noteService, MatchMode.ANYWHERE, UUID
.randomUUID().toString());
Assert.assertFalse(matcher.matches(noteListData));
// Start
matcher = new FullTextSearchFiltersMatcher(noteService, MatchMode.START, prefix);
Assert.assertTrue(matcher.matches(noteListData));
matcher = new FullTextSearchFiltersMatcher(noteService, MatchMode.START, mainContent);
Assert.assertFalse(matcher.matches(noteListData));
// End
matcher = new FullTextSearchFiltersMatcher(noteService, MatchMode.END, suffix);
Assert.assertTrue(matcher.matches(noteListData));
matcher = new FullTextSearchFiltersMatcher(noteService, MatchMode.END, mainContent);
Assert.assertFalse(matcher.matches(noteListData));
// Exact
matcher = new FullTextSearchFiltersMatcher(noteService, MatchMode.EXACT, prefix
+ mainContent + suffix);
Assert.assertTrue(matcher.matches(noteListData));
matcher = new FullTextSearchFiltersMatcher(noteService, MatchMode.EXACT, mainContent);
Assert.assertFalse(matcher.matches(noteListData));
}
示例5: createLikeRestriction
/**
* Creates a like restriction.
*
* @param propertyDescriptor
* the property descriptor.
* @param prefixedProperty
* the complete property path.
* @param propertyValue
* the value to create the like restriction for
* @param componentDescriptor
* the component descriptor
* @param queryComponent
* the query component
* @param context
* the context
* @return the created criterion or null if no criterion necessary.
*/
protected Criterion createLikeRestriction(IPropertyDescriptor propertyDescriptor, String prefixedProperty,
String propertyValue, IComponentDescriptor<?> componentDescriptor,
IQueryComponent queryComponent, Map<String, Object> context) {
MatchMode matchMode;
if (propertyValue.contains("%")) {
matchMode = MatchMode.EXACT;
} else {
matchMode = MatchMode.START;
}
if (propertyDescriptor instanceof IStringPropertyDescriptor && ((IStringPropertyDescriptor) propertyDescriptor)
.isUpperCase()) {
// don't use ignoreCase() to be able to leverage indices.
return Restrictions.like(prefixedProperty, propertyValue.toUpperCase(), matchMode);
}
return Restrictions.like(prefixedProperty, propertyValue, matchMode).ignoreCase();
}