return results;
}
@Override
public Collection<Object> listSubjects(Object property, Object object) {
FieldQuery query = createQuery();
if(this.isURI(object)){
query.setConstraint(property.toString(), new ReferenceConstraint(object.toString()));
} else if(object instanceof Text){
Text text = (Text)object;
TextConstraint constraint;
if(text.getLanguage() == null){
constraint = new TextConstraint(text.getText(), PatternType.none, true);
} else {
constraint = new TextConstraint(text.getText(), PatternType.none, true,text.getLanguage());
}
query.setConstraint(property.toString(), constraint);
} else {
Set<DataTypeEnum> dataTypes = DataTypeEnum.getPrimaryDataTypes(object.getClass());
if(dataTypes == null || dataTypes.isEmpty()){
query.setConstraint(property.toString(),
new ValueConstraint(object));
} else {
Collection<String> types = new ArrayList<String>(dataTypes.size());
for(DataTypeEnum type : dataTypes){
types.add(type.getUri());
}
query.setConstraint(property.toString(),
new ValueConstraint(object,types));
}
}
query.setLimit(Integer.valueOf(DEFAULT_MAX_SELECT));
QueryResultList<String> results;
try {
results = query(query);
} catch (EntityhubException e) {
throw new IllegalStateException("Unable to query for resources with value '"+
object+"' on property '"+property+"'!",e);
}
Collection<Object> references;
if(results.isEmpty()){
references = Collections.emptySet();
} else if(results.size() == 1){ //assuming that a single result is a likely case
references = Collections.singleton(
(Object)getValueFactory().createReference(results.iterator().next()));
} else {
int offset = 0;
references = new HashSet<Object>(results.size());
for(String result : results){
references.add(getValueFactory().createReference(result));
}
while(results.size() >= DEFAULT_MAX_SELECT && references.size() <= DEFAULT_MAX_RESULTS-DEFAULT_MAX_SELECT){
offset = offset + results.size();
query.setOffset(offset);
try {
results = query(query);
} catch (EntityhubException e) {
throw new IllegalStateException("Unable to query for resources with value '"+
object+"' on property '"+property+"'!",e);