Strabon

changeset 632:392c52ed39fe

#6 Improved addLimit function to take into account all the cases. There was a bug when the query was for example:

select *
where
{
?x ?limit 6
}

and the parser infered that there was a limit in the query.
author Stella Giannakopoulou <sgian@di.uoa.gr>
date Thu Oct 11 14:40:47 2012 +0300 (2012-10-11)
parents ce990d2f0155
children 3a946fc8f0f8
files endpoint/src/main/java/eu/earthobservatory/org/StrabonEndpoint/StrabonBeanWrapper.java
line diff
     1.1 --- a/endpoint/src/main/java/eu/earthobservatory/org/StrabonEndpoint/StrabonBeanWrapper.java	Thu Oct 11 13:23:15 2012 +0300
     1.2 +++ b/endpoint/src/main/java/eu/earthobservatory/org/StrabonEndpoint/StrabonBeanWrapper.java	Thu Oct 11 14:40:47 2012 +0300
     1.3 @@ -351,28 +351,26 @@
     1.4  		if(maxLimit == null)
     1.5  			max = this.maxLimit;
     1.6  		else
     1.7 -			max = Integer.valueOf(maxLimit);
     1.8 +			max = Integer.valueOf(maxLimit);		
     1.9  		
    1.10  		if(max > 0)
    1.11  		{	
    1.12 -			Pattern limitPattern = Pattern.compile("limit \\d.*", Pattern.MULTILINE | Pattern.CASE_INSENSITIVE);
    1.13 +			Pattern limitPattern = Pattern.compile(".*limit \\d+", Pattern.DOTALL);							
    1.14  			Matcher limitMatcher = limitPattern.matcher(queryString);
    1.15  			
    1.16  			// check whether the query contains a limit clause
    1.17 -			if(limitMatcher.find())		
    1.18 -			{
    1.19 -				String limitString = limitMatcher.group();
    1.20 -							
    1.21 -				Pattern rowsNumberPattern = Pattern.compile("\\d+");
    1.22 -				Matcher rowsNumberMatcher = rowsNumberPattern.matcher(limitString);
    1.23 -				rowsNumberMatcher.find();
    1.24 +			if(limitMatcher.matches())		
    1.25 +			{								
    1.26 +				Pattern rowsNumberPattern = Pattern.compile("\\d+$");				
    1.27 +				Matcher rowsNumberMatcher = rowsNumberPattern.matcher(queryString);
    1.28 +				rowsNumberMatcher.find();				
    1.29  				
    1.30  				// if the initial limit is greater than the maximum, set it to the maximum
    1.31 -				if(Integer.valueOf(rowsNumberMatcher.group()) > max)			
    1.32 -					limitedQuery = limitMatcher.replaceAll("limit "+max);			
    1.33 +				if(Integer.valueOf(rowsNumberMatcher.group()) > max)
    1.34 +					limitedQuery = rowsNumberMatcher.replaceAll(String.valueOf(max));			
    1.35  			}	
    1.36  			else // add a limit to the query 
    1.37 -				limitedQuery = queryString+"limit "+max;
    1.38 +				limitedQuery = queryString+" limit "+max;
    1.39  		
    1.40  		}
    1.41  		return limitedQuery;