@Test void getPostgreSqlValueQueryCompound() { assertThrows( RuntimeException.class, () -> PostgreSqlUtils.getPostgreSqlQueryValue(null, createAttr("attrCompound", COMPOUND))); }
static Object getPostgreSqlQueryValue(Object queryValue, Attribute attr) { while (true) { String attrName = attr.getName(); AttributeType attrType = attr.getDataType(); switch (attrType) { case BOOL: if (queryValue != null && !(queryValue instanceof Boolean)) { return throwExceptionUnexpectedQueryValueType( attrName, queryValue, Boolean.class.getSimpleName()); } return queryValue; case CATEGORICAL: case CATEGORICAL_MREF: case FILE: case MREF: case XREF: case ONE_TO_MANY: if (queryValue != null) { if (queryValue instanceof Entity) { queryValue = ((Entity) queryValue).getIdValue(); } attr = attr.getRefEntity().getIdAttribute(); continue; } else { return null; } case DATE: if (queryValue != null && !(queryValue instanceof LocalDate)) { throwExceptionUnexpectedQueryValueType( attrName, queryValue, LocalDate.class.getSimpleName()); } return queryValue; case DATE_TIME: if (queryValue == null) { return null; } if (!(queryValue instanceof Instant)) { throwExceptionUnexpectedQueryValueType( attrName, queryValue, Instant.class.getSimpleName()); } return ((Instant) queryValue).atOffset(UTC); case DECIMAL: if (queryValue != null && !(queryValue instanceof Double)) { throwExceptionUnexpectedQueryValueType( attrName, queryValue, Double.class.getSimpleName()); } return queryValue; case ENUM: if (queryValue != null) { if (queryValue instanceof String) { return queryValue; } else if (queryValue instanceof Enum<?>) { return queryValue.toString(); } else { throw new MolgenisDataException( format( "Attribute [%s] query value is of type [%s] instead of [%s] or [%s]", attrName, queryValue.getClass().getSimpleName(), String.class.getSimpleName(), Enum.class.getSimpleName())); } } else { return null; } case EMAIL: case HTML: case HYPERLINK: case SCRIPT: case STRING: case TEXT: if (queryValue != null && !(queryValue instanceof String)) { throwExceptionUnexpectedQueryValueType( attrName, queryValue, String.class.getSimpleName()); } return queryValue; case INT: if (queryValue != null && !(queryValue instanceof Integer)) { throwExceptionUnexpectedQueryValueType( attrName, queryValue, Integer.class.getSimpleName()); } return queryValue; case LONG: if (queryValue != null && !(queryValue instanceof Long)) { throwExceptionUnexpectedQueryValueType( attrName, queryValue, Long.class.getSimpleName()); } return queryValue; case COMPOUND: throw new IllegalAttributeTypeException(attrType); default: throw new UnexpectedEnumException(attrType); } } }
PostgreSqlUtils { static Object getPostgreSqlQueryValue(Object queryValue, Attribute attr) { while (true) { String attrName = attr.getName(); AttributeType attrType = attr.getDataType(); switch (attrType) { case BOOL: if (queryValue != null && !(queryValue instanceof Boolean)) { return throwExceptionUnexpectedQueryValueType( attrName, queryValue, Boolean.class.getSimpleName()); } return queryValue; case CATEGORICAL: case CATEGORICAL_MREF: case FILE: case MREF: case XREF: case ONE_TO_MANY: if (queryValue != null) { if (queryValue instanceof Entity) { queryValue = ((Entity) queryValue).getIdValue(); } attr = attr.getRefEntity().getIdAttribute(); continue; } else { return null; } case DATE: if (queryValue != null && !(queryValue instanceof LocalDate)) { throwExceptionUnexpectedQueryValueType( attrName, queryValue, LocalDate.class.getSimpleName()); } return queryValue; case DATE_TIME: if (queryValue == null) { return null; } if (!(queryValue instanceof Instant)) { throwExceptionUnexpectedQueryValueType( attrName, queryValue, Instant.class.getSimpleName()); } return ((Instant) queryValue).atOffset(UTC); case DECIMAL: if (queryValue != null && !(queryValue instanceof Double)) { throwExceptionUnexpectedQueryValueType( attrName, queryValue, Double.class.getSimpleName()); } return queryValue; case ENUM: if (queryValue != null) { if (queryValue instanceof String) { return queryValue; } else if (queryValue instanceof Enum<?>) { return queryValue.toString(); } else { throw new MolgenisDataException( format( "Attribute [%s] query value is of type [%s] instead of [%s] or [%s]", attrName, queryValue.getClass().getSimpleName(), String.class.getSimpleName(), Enum.class.getSimpleName())); } } else { return null; } case EMAIL: case HTML: case HYPERLINK: case SCRIPT: case STRING: case TEXT: if (queryValue != null && !(queryValue instanceof String)) { throwExceptionUnexpectedQueryValueType( attrName, queryValue, String.class.getSimpleName()); } return queryValue; case INT: if (queryValue != null && !(queryValue instanceof Integer)) { throwExceptionUnexpectedQueryValueType( attrName, queryValue, Integer.class.getSimpleName()); } return queryValue; case LONG: if (queryValue != null && !(queryValue instanceof Long)) { throwExceptionUnexpectedQueryValueType( attrName, queryValue, Long.class.getSimpleName()); } return queryValue; case COMPOUND: throw new IllegalAttributeTypeException(attrType); default: throw new UnexpectedEnumException(attrType); } } } }
PostgreSqlUtils { static Object getPostgreSqlQueryValue(Object queryValue, Attribute attr) { while (true) { String attrName = attr.getName(); AttributeType attrType = attr.getDataType(); switch (attrType) { case BOOL: if (queryValue != null && !(queryValue instanceof Boolean)) { return throwExceptionUnexpectedQueryValueType( attrName, queryValue, Boolean.class.getSimpleName()); } return queryValue; case CATEGORICAL: case CATEGORICAL_MREF: case FILE: case MREF: case XREF: case ONE_TO_MANY: if (queryValue != null) { if (queryValue instanceof Entity) { queryValue = ((Entity) queryValue).getIdValue(); } attr = attr.getRefEntity().getIdAttribute(); continue; } else { return null; } case DATE: if (queryValue != null && !(queryValue instanceof LocalDate)) { throwExceptionUnexpectedQueryValueType( attrName, queryValue, LocalDate.class.getSimpleName()); } return queryValue; case DATE_TIME: if (queryValue == null) { return null; } if (!(queryValue instanceof Instant)) { throwExceptionUnexpectedQueryValueType( attrName, queryValue, Instant.class.getSimpleName()); } return ((Instant) queryValue).atOffset(UTC); case DECIMAL: if (queryValue != null && !(queryValue instanceof Double)) { throwExceptionUnexpectedQueryValueType( attrName, queryValue, Double.class.getSimpleName()); } return queryValue; case ENUM: if (queryValue != null) { if (queryValue instanceof String) { return queryValue; } else if (queryValue instanceof Enum<?>) { return queryValue.toString(); } else { throw new MolgenisDataException( format( "Attribute [%s] query value is of type [%s] instead of [%s] or [%s]", attrName, queryValue.getClass().getSimpleName(), String.class.getSimpleName(), Enum.class.getSimpleName())); } } else { return null; } case EMAIL: case HTML: case HYPERLINK: case SCRIPT: case STRING: case TEXT: if (queryValue != null && !(queryValue instanceof String)) { throwExceptionUnexpectedQueryValueType( attrName, queryValue, String.class.getSimpleName()); } return queryValue; case INT: if (queryValue != null && !(queryValue instanceof Integer)) { throwExceptionUnexpectedQueryValueType( attrName, queryValue, Integer.class.getSimpleName()); } return queryValue; case LONG: if (queryValue != null && !(queryValue instanceof Long)) { throwExceptionUnexpectedQueryValueType( attrName, queryValue, Long.class.getSimpleName()); } return queryValue; case COMPOUND: throw new IllegalAttributeTypeException(attrType); default: throw new UnexpectedEnumException(attrType); } } } private  PostgreSqlUtils(); }
PostgreSqlUtils { static Object getPostgreSqlQueryValue(Object queryValue, Attribute attr) { while (true) { String attrName = attr.getName(); AttributeType attrType = attr.getDataType(); switch (attrType) { case BOOL: if (queryValue != null && !(queryValue instanceof Boolean)) { return throwExceptionUnexpectedQueryValueType( attrName, queryValue, Boolean.class.getSimpleName()); } return queryValue; case CATEGORICAL: case CATEGORICAL_MREF: case FILE: case MREF: case XREF: case ONE_TO_MANY: if (queryValue != null) { if (queryValue instanceof Entity) { queryValue = ((Entity) queryValue).getIdValue(); } attr = attr.getRefEntity().getIdAttribute(); continue; } else { return null; } case DATE: if (queryValue != null && !(queryValue instanceof LocalDate)) { throwExceptionUnexpectedQueryValueType( attrName, queryValue, LocalDate.class.getSimpleName()); } return queryValue; case DATE_TIME: if (queryValue == null) { return null; } if (!(queryValue instanceof Instant)) { throwExceptionUnexpectedQueryValueType( attrName, queryValue, Instant.class.getSimpleName()); } return ((Instant) queryValue).atOffset(UTC); case DECIMAL: if (queryValue != null && !(queryValue instanceof Double)) { throwExceptionUnexpectedQueryValueType( attrName, queryValue, Double.class.getSimpleName()); } return queryValue; case ENUM: if (queryValue != null) { if (queryValue instanceof String) { return queryValue; } else if (queryValue instanceof Enum<?>) { return queryValue.toString(); } else { throw new MolgenisDataException( format( "Attribute [%s] query value is of type [%s] instead of [%s] or [%s]", attrName, queryValue.getClass().getSimpleName(), String.class.getSimpleName(), Enum.class.getSimpleName())); } } else { return null; } case EMAIL: case HTML: case HYPERLINK: case SCRIPT: case STRING: case TEXT: if (queryValue != null && !(queryValue instanceof String)) { throwExceptionUnexpectedQueryValueType( attrName, queryValue, String.class.getSimpleName()); } return queryValue; case INT: if (queryValue != null && !(queryValue instanceof Integer)) { throwExceptionUnexpectedQueryValueType( attrName, queryValue, Integer.class.getSimpleName()); } return queryValue; case LONG: if (queryValue != null && !(queryValue instanceof Long)) { throwExceptionUnexpectedQueryValueType( attrName, queryValue, Long.class.getSimpleName()); } return queryValue; case COMPOUND: throw new IllegalAttributeTypeException(attrType); default: throw new UnexpectedEnumException(attrType); } } } private  PostgreSqlUtils();  }
PostgreSqlUtils { static Object getPostgreSqlQueryValue(Object queryValue, Attribute attr) { while (true) { String attrName = attr.getName(); AttributeType attrType = attr.getDataType(); switch (attrType) { case BOOL: if (queryValue != null && !(queryValue instanceof Boolean)) { return throwExceptionUnexpectedQueryValueType( attrName, queryValue, Boolean.class.getSimpleName()); } return queryValue; case CATEGORICAL: case CATEGORICAL_MREF: case FILE: case MREF: case XREF: case ONE_TO_MANY: if (queryValue != null) { if (queryValue instanceof Entity) { queryValue = ((Entity) queryValue).getIdValue(); } attr = attr.getRefEntity().getIdAttribute(); continue; } else { return null; } case DATE: if (queryValue != null && !(queryValue instanceof LocalDate)) { throwExceptionUnexpectedQueryValueType( attrName, queryValue, LocalDate.class.getSimpleName()); } return queryValue; case DATE_TIME: if (queryValue == null) { return null; } if (!(queryValue instanceof Instant)) { throwExceptionUnexpectedQueryValueType( attrName, queryValue, Instant.class.getSimpleName()); } return ((Instant) queryValue).atOffset(UTC); case DECIMAL: if (queryValue != null && !(queryValue instanceof Double)) { throwExceptionUnexpectedQueryValueType( attrName, queryValue, Double.class.getSimpleName()); } return queryValue; case ENUM: if (queryValue != null) { if (queryValue instanceof String) { return queryValue; } else if (queryValue instanceof Enum<?>) { return queryValue.toString(); } else { throw new MolgenisDataException( format( "Attribute [%s] query value is of type [%s] instead of [%s] or [%s]", attrName, queryValue.getClass().getSimpleName(), String.class.getSimpleName(), Enum.class.getSimpleName())); } } else { return null; } case EMAIL: case HTML: case HYPERLINK: case SCRIPT: case STRING: case TEXT: if (queryValue != null && !(queryValue instanceof String)) { throwExceptionUnexpectedQueryValueType( attrName, queryValue, String.class.getSimpleName()); } return queryValue; case INT: if (queryValue != null && !(queryValue instanceof Integer)) { throwExceptionUnexpectedQueryValueType( attrName, queryValue, Integer.class.getSimpleName()); } return queryValue; case LONG: if (queryValue != null && !(queryValue instanceof Long)) { throwExceptionUnexpectedQueryValueType( attrName, queryValue, Long.class.getSimpleName()); } return queryValue; case COMPOUND: throw new IllegalAttributeTypeException(attrType); default: throw new UnexpectedEnumException(attrType); } } } private  PostgreSqlUtils();   }