
org.intermine.objectstore.query.QueryObjectReference Maven / Gradle / Ivy
package org.intermine.objectstore.query;
/*
* Copyright (C) 2002-2022 FlyMine
*
* This code may be freely distributed and modified under the
* terms of the GNU Lesser General Public Licence. This should
* be distributed with the code. See the LICENSE file for more
* information or http://www.gnu.org/copyleft/lesser.html.
*
*/
import java.lang.reflect.Method;
import java.util.Collection;
import org.intermine.metadata.TypeUtil;
import org.intermine.model.InterMineObject;
/**
* Represents a field of a QueryClass that is a business object
*
* @author Mark Woodbridge
* @author Richard Smith
* @author Matthew Wakeling
*/
public class QueryObjectReference extends QueryReference implements QueryOrderable
{
/**
* Constructs a QueryObjectReference representing the specified field of a QueryClass
*
* @param qc the QueryClass
* @param fieldName the name of the relevant field
* @throws NullPointerException if the field name is null
* @throws IllegalArgumentException if the field is not a reference, or does not exist
*/
public QueryObjectReference(QueryClass qc, String fieldName) {
if (fieldName == null) {
throw new NullPointerException("Field name parameter is null");
}
Method field = TypeUtil.getGetter(qc.getType(), fieldName);
if (field == null) {
throw new IllegalArgumentException("Field " + fieldName + " not found in "
+ qc.getType());
}
if (Collection.class.isAssignableFrom(field.getReturnType())) {
throw new IllegalArgumentException("Field " + fieldName + " is a collection type");
}
if (!InterMineObject.class.isAssignableFrom(field.getReturnType())) {
throw new IllegalArgumentException("Field " + fieldName + " is not a separate database "
+ "object");
}
this.qc = qc;
this.fieldName = fieldName;
this.type = field.getReturnType();
}
/**
* {@inheritDoc}
*/
@SuppressWarnings("unchecked")
@Override
public Class extends InterMineObject> getType() {
return (Class) type;
}
/**
* {@inheritDoc}
*/
@Override
public String toString() {
return qc.toString() + "." + fieldName;
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy