Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
 /*
  * Copyright (c) 2009 Mysema Ltd.
  * All rights reserved.
  * 
  */
 package com.mysema.rdfbean.sesame.query;
 
import  javax.annotation.Nullable;
import  org.openrdf.query.algebra.Compare;
import  org.openrdf.query.algebra.Exists;
import  org.openrdf.query.algebra.ValueExpr;
import  org.openrdf.query.algebra.Var;
import  org.openrdf.query.algebra.Compare.CompareOp;
ContainsKeyValueTransformer provides

Author(s):
tiwe
Version:
$Id$
    @Override
    public Collection<? extends Operator<?>> getSupportedOperations() {
        return Arrays.<Operator<?>>asList(..);
    }
    @Override
    public ValueExpr transform(Operation<?, ?> operationTransformerContext context) {
        Path<?> path = (Path<?>) operation.getArg(0);
        Var pathVar = context.toVar(path);
        MappedPath mappedPath = context.getMappedPath(path); 
        if (!mappedPath.getMappedProperty().isLocalized()){
            Var valNodekeyNode;
            if (operation.getOperator().equals(.)){
                keyNode = (Var) context.toValue(operation.getArg(1));
                valNode = null;                        
            }else{                    
                keyNode = null;
                valNode = (Var) context.toValue(operation.getArg(1));
            }                
            return transformMapAccess(pathVarmappedPathvalNodekeyNodecontext);
        }else{  
            // TODO
            return null;
        }
    }
    
    @Nullable
    private ValueExpr transformMapAccess(Var pathVarMappedPath mappedPath
            @Nullable Var valNode, @Nullable Var keyNodeTransformerContext context) {
        MappedProperty<?> mappedProperty = mappedPath.getMappedProperty();
        JoinBuilder builder = context.createJoinBuilder();
        if (valNode != null){
            if (mappedProperty.getValuePredicate() != null){
                context.match(builderpathVarmappedProperty.getValuePredicate(), valNode);
            }else if (!context.inNegation()){    
                pathVar.setValue(valNode.getValue());
            }
        }
        if (keyNode != null){
            context.match(builderpathVarmappedProperty.getKeyPredicate(), keyNode);   
        }                        
        
        if (!builder.isEmpty()){
            return new Exists(builder.getTupleExpr()); 
        }else if (context.inNegation()){
            return new Compare(pathVarvalNode, CompareOp.EQ);
        }else{
            return null;
        }        
    }
New to GrepCode? Check out our FAQ X