Value v = subj.getValue();
t_subject = T_NODES.as(name+"_subject");
j_subject = new JoinTable(t_subject);
if(v instanceof KiWiNode && ((KiWiNode) v).getId() != null) {
KiWiNode n = (KiWiNode) v;
j_triple.addCondition(triple.SUBJECT_ID.equal((Field) create.val(n.getId())));
} else if(v instanceof URI) {
if(configurationService.getBooleanConfiguration("sparql.native.preload_constants",true)) {
KiWiUriResource r_subject = resourceService.getUriResource(v.stringValue());
if(r_subject != null) {
j_triple.addCondition(triple.SUBJECT_ID.equal((Field) create.val(r_subject.getId())));
} else {
j_triple.addCondition(create.falseCondition());
}
} else {
// performance improvement: if uri already was used, reuse the node instead of doing a new join
if(uriNodes.containsKey(v.stringValue())) {
t_subject = uriNodes.get(v.stringValue());
Condition c_subject = triple.SUBJECT_ID.equal((Field) t_subject.ID);
j_triple.addCondition(c_subject);
j_triple.addBackCondition(c_subject);
} else {
resultTables.add(j_subject);
j_subject.addCondition(t_subject.URI.equal((Field) create.val(v.stringValue())));
j_subject.addCondition(triple.SUBJECT_ID.equal((Field) t_subject.ID));
uriNodes.put(v.stringValue(),t_subject);
}
}
} else if(v instanceof BNode) {
resultTables.add(j_subject);
j_subject.addCondition(t_subject.ANONID.equal((Field) create.val(((BNode) v).getID())));
j_subject.addCondition(triple.SUBJECT_ID.equal((Field) t_subject.ID));
} else {
throw new UnsupportedOperationException("value of type "+v.getClass()+" not supported!");
}
} else {
String varname = subj.getName().replace("-", "_");
t_subject = getVariable(varname);
if(!hasQueryVariable(query,varname)) {
// variable does not exist yet, so we create it and join it to the current from clause ...
t_subject = createVariable(varname);
addQueryVariable(query,varname,t_subject);
j_subject = new JoinTable(t_subject);
j_subject.addCondition(triple.SUBJECT_ID.equal((Field) t_subject.ID));
resultTables.add(j_subject);
} else {
// variable already exists in FROM, we simply add a join condition
Condition c_subject = triple.SUBJECT_ID.equal((Field) t_subject.ID);
j_triple.addCondition(c_subject);
j_triple.addBackCondition(c_subject);
}
}
Var prop = p.getPredicateVar();
if(prop.hasValue()) {
Value v = prop.getValue();
t_property = T_NODES.as(name+"_property");
j_property = new JoinTable(t_property);
if(v instanceof KiWiNode && ((KiWiNode) v).getId() != null) {
KiWiNode n = (KiWiNode) v;
j_triple.addCondition(triple.PROPERTY_ID.equal((Field) create.val(n.getId())));
} else if(v instanceof URI) {
if(configurationService.getBooleanConfiguration("sparql.native.preload_constants",true)) {
KiWiUriResource r_property = resourceService.getUriResource(v.stringValue());
if(r_property != null) {
j_triple.addCondition(triple.PROPERTY_ID.equal((Field) create.val(r_property.getId())));
} else {
j_triple.addCondition(create.falseCondition());
}
} else {
// performance improvement: if uri already was used, reuse the node instead of doing a new join
if(uriNodes.containsKey(v.stringValue())) {
t_property = uriNodes.get(v.stringValue());
Condition c_property = triple.PROPERTY_ID.equal((Field) t_property.ID);
j_triple.addCondition(c_property);
j_triple.addBackCondition(c_property);
} else {
resultTables.add(j_property);
j_property.addCondition(t_property.URI.equal((Field) create.val(v.stringValue())));
j_property.addCondition(triple.PROPERTY_ID.equal((Field) t_property.ID));
uriNodes.put(v.stringValue(),t_property);
}
}
} else {
throw new UnsupportedOperationException("value of type "+v.getClass()+" not supported!");
}
} else {
String varname = prop.getName().replace("-","_");
t_property = getVariable(varname);
if(!hasQueryVariable(query,varname)) {
// variable does not exist yet, so we create it and join it to the current from clause ...
t_property = createVariable(varname);
addQueryVariable(query,varname,t_property);
j_property = new JoinTable(t_property);
j_property.addCondition(triple.PROPERTY_ID.equal((Field) t_property.ID));
resultTables.add(j_property);
} else {
// variable already exists in FROM, we simply add a join condition
Condition c_property = triple.PROPERTY_ID.equal((Field) t_property.ID);
j_triple.addCondition(c_property);
j_triple.addBackCondition(c_property);
}
}
Var obj = p.getObjectVar();
if(obj.hasValue()) {
Value v = obj.getValue();
t_object = T_NODES.as(name+"_object");
j_object = new JoinTable(t_object);
if(v instanceof KiWiNode && ((KiWiNode) v).getId() != null) {
KiWiNode n = (KiWiNode) v;
j_triple.addCondition(triple.OBJECT_ID.equal((Field) create.val(n.getId())));
} else if(v instanceof URI) {
if(configurationService.getBooleanConfiguration("sparql.native.preload_constants",true)) {
KiWiUriResource r_object = resourceService.getUriResource(v.stringValue());
if(r_object != null) {
j_triple.addCondition(triple.OBJECT_ID.equal((Field) create.val(r_object.getId())));
} else {
j_triple.addCondition(create.falseCondition());
}
} else {
// performance improvement: if uri already was used, reuse the node instead of doing a new join
if(uriNodes.containsKey(v.stringValue())) {
t_object = uriNodes.get(v.stringValue());
Condition c_object = triple.OBJECT_ID.equal((Field) t_object.ID);
j_triple.addCondition(c_object);
j_triple.addBackCondition(c_object);
} else {
resultTables.add(j_object);
j_object.addCondition(t_object.URI.equal((Field) create.val(v.stringValue())));
j_object.addCondition(triple.OBJECT_ID.equal((Field) t_object.ID));
uriNodes.put(v.stringValue(),t_object);
}
}
} else if(v instanceof BNode) {
resultTables.add(j_object);
j_object.addCondition(t_object.ANONID.equal((Field) create.val(((BNode) v).getID())));
j_object.addCondition(triple.OBJECT_ID.equal((Field) t_object.ID));
} else if(v instanceof Literal) {
resultTables.add(j_object);
j_object.addCondition(t_object.CONTENTMD5.equal((Field) create.val(HashUtils.md5sum(v.stringValue()))));
j_object.addCondition(triple.OBJECT_ID.equal((Field) t_object.ID));
} else {
throw new UnsupportedOperationException("value of type "+v.getClass()+" not supported!");
}
} else {
String varname = obj.getName().replace("-","_");
t_object = getVariable(varname);
if(!hasQueryVariable(query,varname)) {
// variable does not exist yet, so we create it and join it to the current from clause ...
t_object = createVariable(varname);
addQueryVariable(query,varname,t_object);
j_object = new JoinTable(t_object);
j_object.addCondition(triple.OBJECT_ID.equal((Field) t_object.ID));
resultTables.add(j_object);
} else {
// variable already exists in FROM, we simply add a join condition
Condition c_object = triple.OBJECT_ID.equal((Field) t_object.ID);
j_triple.addCondition(c_object);
j_triple.addBackCondition(c_object);
}
}
Var ctx = p.getContextVar();
if(ctx != null) {
if(ctx.hasValue()) {
Value v = ctx.getValue();
t_context = T_NODES.as(name+"_context");
j_context = new JoinTable(t_context);
if(v instanceof KiWiNode && ((KiWiNode) v).getId() != null) {
KiWiNode n = (KiWiNode) v;
j_triple.addCondition(triple.CONTEXT_ID.equal((Field) create.val(n.getId())));
} else if(v instanceof URI) {
if(configurationService.getBooleanConfiguration("sparql.native.preload_constants",true)) {
KiWiUriResource r_context = resourceService.getUriResource(v.stringValue());
if(r_context != null) {
j_triple.addCondition(triple.CONTEXT_ID.equal((Field) create.val(r_context.getId())));