private static void export( PropertyIsLike operator, XMLStreamWriter writer ) throws XMLStreamException { writer.writeStartElement( FES_20_NS, "PropertyIsLike" ); writer.writeAttribute( "wildCard", operator.getWildCard() ); writer.writeAttribute( "singleChar", operator.getSingleChar() ); writer.writeAttribute( "escapeChar", operator.getEscapeChar() ); export( operator.getExpression(), writer ); export( operator.getPattern(), writer ); writer.writeEndElement(); }
case PROPERTY_IS_LIKE: PropertyIsLike pil = (PropertyIsLike) op; return new PropertyIsLike( copy( pil.getExpression() ), copyExpression( pil.getPattern(), values ), pil.getWildCard(), pil.getSingleChar(), pil.getEscapeChar(), pil.isMatchCase(), pil.getMatchAction() ); case PROPERTY_IS_NOT_EQUAL_TO: PropertyIsNotEqualTo pine = (PropertyIsNotEqualTo) op;
case PROPERTY_IS_LIKE: PropertyIsLike pil = (PropertyIsLike) o; return new PropertyIsLike( exs[0], exs[1], pil.getWildCard(), pil.getSingleChar(), pil.getEscapeChar(), o.isMatchCase(), o.getMatchAction() ); case PROPERTY_IS_NIL:
private static PropertyIsLike parsePropertyIsLikeOperator( XMLStreamReader xmlStream ) throws XMLStreamException { // this is a deegree extension over Filter 1.1.0 spec. boolean matchCase = getAttributeValueAsBoolean( xmlStream, null, "matchCase", true ); String wildCard = getRequiredAttributeValue( xmlStream, "wildCard" ); String singleChar = getRequiredAttributeValue( xmlStream, "singleChar" ); String escapeChar = getRequiredAttributeValue( xmlStream, "escapeChar" ); nextElement( xmlStream ); ValueReference propName = parsePropertyName( xmlStream, false ); nextElement( xmlStream ); if ( !"Literal".equals( xmlStream.getLocalName() ) ) { String message = "FilterEncoding 1.1.0 does not allow other than Literal elements as second expression in PropertyIsLike filters!"; throw new XMLStreamException( message ); } Literal<?> literal = parseLiteral( xmlStream ); nextElement( xmlStream ); return new PropertyIsLike( propName, literal, wildCard, singleChar, escapeChar, matchCase, null ); }
/** * Translates the given {@link PropertyIsLike} into an {@link SQLOperation}. * <p> * NOTE: This method appends the generated argument inline, i.e. not using a <code>?</code>. This is because of a * problem that has been observed with PostgreSQL 8.0; the execution of the inline version is *much* faster. * </p> * * @param op * comparison operator to be translated, must not be <code>null</code> * @return corresponding SQL expression, never <code>null</code> * @throws UnmappableException * if translation is not possible (usually due to unmappable property names) * @throws FilterEvaluationException * if the expression contains invalid {@link ValueReference}s */ @Override protected SQLOperation toProtoSQL( PropertyIsLike op ) throws UnmappableException, FilterEvaluationException { Expression pattern = op.getPattern(); if ( pattern instanceof Literal ) { String literal = ( (Literal<?>) pattern ).getValue().toString(); return toProtoSql( op, literal ); } else if ( pattern instanceof Function ) { String valueAsString = getStringValueFromFunction( pattern ); return toProtoSql( op, valueAsString ); } String msg = "Mapping of PropertyIsLike with non-literal or non-function comparisons to SQL is not implemented yet."; throw new UnsupportedOperationException( msg ); }
private SQLOperation getOperationFromBuilder( PropertyIsLike op, SQLExpression propName, String sqlEncoded ) { SQLOperationBuilder builder = new SQLOperationBuilder(); if ( !op.isMatchCase() ) { builder.add( "LOWER(" ); } builder.add( propName ); if ( op.isMatchCase() ) { builder.add( "::TEXT LIKE '" ); } else { builder.add( "::TEXT) LIKE '" ); } builder.add( sqlEncoded ); builder.add( "'" ); return builder.toOperation(); }
private PropertyIsLike buildIsLike( Expression propName, Expression literal, boolean matchCase ) throws UnmappableException { if ( !( propName instanceof ValueReference ) || !( literal instanceof Literal ) ) { String msg = "Can not map filter. Multi-valued columns can only be compared to literals."; throw new UnmappableException( msg ); } String wildCard = "*"; String singleChar = "?"; String escapeChar = "\\"; String s = ( (Literal<?>) literal ).getValue().toString(); s = StringUtils.replaceAll( s, escapeChar, escapeChar + escapeChar ); s = StringUtils.replaceAll( s, singleChar, escapeChar + singleChar ); s = StringUtils.replaceAll( s, wildCard, escapeChar + wildCard ); Literal<PrimitiveValue> escapedLiteral = new Literal<PrimitiveValue>( new PrimitiveValue( s ), null ); return new PropertyIsLike( (ValueReference) propName, escapedLiteral, wildCard, singleChar, escapeChar, matchCase, null ); }
private SQLOperation toProtoSql( PropertyIsLike op, String literal ) throws UnmappableException, FilterEvaluationException { String escape = "" + op.getEscapeChar(); String wildCard = "" + op.getWildCard(); String singleChar = "" + op.getSingleChar(); SQLExpression propName = toProtoSQL( op.getExpression() ); IsLikeString specialString = new IsLikeString( literal, wildCard, singleChar, escape ); String sqlEncoded = specialString.toSQL( !op.isMatchCase() ); if ( propName.isMultiValued() ) { // TODO escaping of pipe symbols sqlEncoded = "%|" + sqlEncoded + "|%"; } return getOperationFromBuilder( op, propName, sqlEncoded ); }
private static PropertyIsLike parsePropertyIsLikeOperator( XMLStreamReader xmlStream ) throws XMLStreamException { // this is a deegree extension over Filter 1.0.0 boolean matchCase = getAttributeValueAsBoolean( xmlStream, null, "matchCase", true ); String wildCard = getRequiredAttributeValue( xmlStream, "wildCard" ); String singleChar = getRequiredAttributeValue( xmlStream, "singleChar" ); String escapeChar = getRequiredAttributeValue( xmlStream, "escape" ); nextElement( xmlStream ); ValueReference propName = parsePropertyName( xmlStream ); nextElement( xmlStream ); Literal<?> literal = parseLiteral( xmlStream ); nextElement( xmlStream ); return new PropertyIsLike( propName, literal, wildCard, singleChar, escapeChar, matchCase, null ); }
throws UnmappableException, FilterEvaluationException { if ( !( op.getPattern() instanceof Literal ) ) { String msg = "Mapping of PropertyIsLike with non-literal comparisons to SQL is not implemented yet."; throw new UnsupportedOperationException( msg ); String literal = ( (Literal) op.getPattern() ).getValue().toString(); String escape = "" + op.getEscapeChar(); String wildCard = "" + op.getWildCard(); String singleChar = "" + op.getSingleChar(); SQLExpression propName = toProtoSQL( op.getExpression() ); String sqlEncoded = specialString.toSQL( !op.isMatchCase() ); if ( !op.isMatchCase() ) { builder.add( "LOWER (" + propName + ")" ); } else {
private static PropertyIsLike parsePropertyIsLikeOperator( XMLStreamReader xmlStream ) throws XMLStreamException { // this is a deegree extension over Filter 2.0.0 spec. (TODO should this be null, if not present?) Boolean matchCase = getAttributeValueAsBoolean( xmlStream, null, "matchCase", true ); // this is a deegree extension over Filter 2.0.0 spec. (TODO should this be null, if not present?) MatchAction matchAction = null; String s = XMLStreamUtils.getAttributeValue( xmlStream, "matchAction" ); if ( s != null ) { matchAction = parseMatchAction( xmlStream, s ); } String wildCard = getRequiredAttributeValue( xmlStream, "wildCard" ); String singleChar = getRequiredAttributeValue( xmlStream, "singleChar" ); String escapeChar = getRequiredAttributeValue( xmlStream, "escapeChar" ); nextElement( xmlStream ); Expression value = parseExpression( xmlStream ); nextElement( xmlStream ); Expression pattern = parseExpression( xmlStream ); nextElement( xmlStream ); return new PropertyIsLike( value, pattern, wildCard, singleChar, escapeChar, matchCase, matchAction ); }
throws UnmappableException, FilterEvaluationException { if ( !( op.getPattern() instanceof Literal ) ) { String msg = "Mapping of PropertyIsLike with non-literal comparisons to SQL is not implemented yet."; throw new UnsupportedOperationException( msg ); String literal = ( (Literal) op.getPattern() ).getValue().toString(); String escape = "" + op.getEscapeChar(); String wildCard = "" + op.getWildCard(); String singleChar = "" + op.getSingleChar(); SQLExpression propName = toProtoSQL( op.getExpression() ); String sqlEncoded = specialString.toSQL( !op.isMatchCase() ); if ( !op.isMatchCase() ) { builder.add( "LOWER (" + propName + ")" ); } else {
case PROPERTY_IS_LIKE: PropertyIsLike isLikeOperator = (PropertyIsLike) operator; writer.writeAttribute( "wildCard", isLikeOperator.getWildCard() ); writer.writeAttribute( "singleChar", isLikeOperator.getSingleChar() ); writer.writeAttribute( "escapeChar", isLikeOperator.getEscapeChar() ); if ( isLikeOperator.isMatchCase() != null ) { writer.writeAttribute( "matchCase", "" + isLikeOperator.isMatchCase() ); export( isLikeOperator.getExpression(), writer ); export( isLikeOperator.getPattern(), writer ); break; case PROPERTY_IS_NOT_EQUAL_TO: