Bugfix to add Hibernate Query Language escape string for single-quotes. Added a convenience method in LexUtilities, hqlEscape.

This commit is contained in:
travismccauley 2003-11-04 16:22:11 +00:00
parent 29e09dce28
commit 496c7eb436
2 changed files with 35 additions and 8 deletions

View File

@ -214,18 +214,17 @@ public class LexComponentRepository
Query query = null;
Iterator it = null;
String termForQuery = null;
if ( lexQuery.getFindMode().equals( LexComponentRepository.EXACT ) )
String termForQuery = LexUtilities.hqlEscape( term.getTerm() );
LexLogger.debug( "Escaped term string: " + termForQuery );
if ( lexQuery.getFindMode().equals( LexComponentRepository.STARTS_WITH ) )
{
termForQuery = term.getTerm();
}
else if ( lexQuery.getFindMode().equals( LexComponentRepository.STARTS_WITH ) )
{
termForQuery = term.getTerm() + "%";
termForQuery = termForQuery + "%";
}
else if ( lexQuery.getFindMode().equals( LexComponentRepository.ANYWHERE ) )
{
termForQuery = "%" + term.getTerm() + "%";
termForQuery = "%" + termForQuery + "%";
}
String queryString = " FROM org.thdl.lex.component.ITerm as term WHERE term.term like '" + termForQuery + "' AND term.deleted=0 ORDER BY term.term";
try

View File

@ -69,6 +69,34 @@ public class LexUtilities
}
/**
* Description of the Method
*
* @param fromString Description of the Parameter
* @return Description of the Return Value
*/
public static String hqlEscape( String fromString )
{
HashMap map = new HashMap();
map.put( "'", "''" );
StringBuffer targetString = new StringBuffer( "" );
if ( null != fromString )
{
StringTokenizer tokens = new StringTokenizer( fromString, "'%_\"", true );
while ( tokens.hasMoreTokens() )
{
String temp = tokens.nextToken();
if ( map.containsKey( temp ) )
{
temp = (String) map.get( temp );
}
targetString.append( temp );
}
}
return targetString.toString();
}
/**
* Description of the Method
*