@Test void getPostgreSqlValueCompound() { assertThrows( RuntimeException.class, () -> PostgreSqlUtils.getPostgreSqlValue( mock(Entity.class), createAttr("attrCompound", COMPOUND))); }
static Object getPostgreSqlValue(Entity entity, Attribute attr) { String attrName = attr.getName(); AttributeType attrType = attr.getDataType(); switch (attrType) { case BOOL: return entity.getBoolean(attrName); case CATEGORICAL: case XREF: Entity xrefEntity = entity.getEntity(attrName); return xrefEntity != null ? getPostgreSqlValue(xrefEntity, xrefEntity.getEntityType().getIdAttribute()) : null; case CATEGORICAL_MREF: case MREF: case ONE_TO_MANY: Iterable<Entity> entities = entity.getEntities(attrName); return stream(entities) .map( mrefEntity -> getPostgreSqlValue(mrefEntity, mrefEntity.getEntityType().getIdAttribute())) .collect(toList()); case DATE: return entity.getLocalDate(attrName); case DATE_TIME: Instant instant = entity.getInstant(attrName); return instant != null ? instant.truncatedTo(ChronoUnit.SECONDS).atOffset(UTC) : null; case DECIMAL: return entity.getDouble(attrName); case EMAIL: case ENUM: case HTML: case HYPERLINK: case SCRIPT: case STRING: case TEXT: return entity.getString(attrName); case FILE: FileMeta fileEntity = entity.getEntity(attrName, FileMeta.class); return fileEntity != null ? getPostgreSqlValue(fileEntity, fileEntity.getEntityType().getIdAttribute()) : null; case INT: return entity.getInt(attrName); case LONG: return entity.getLong(attrName); case COMPOUND: throw new IllegalAttributeTypeException(attrType); default: throw new UnexpectedEnumException(attrType); } }
PostgreSqlUtils { static Object getPostgreSqlValue(Entity entity, Attribute attr) { String attrName = attr.getName(); AttributeType attrType = attr.getDataType(); switch (attrType) { case BOOL: return entity.getBoolean(attrName); case CATEGORICAL: case XREF: Entity xrefEntity = entity.getEntity(attrName); return xrefEntity != null ? getPostgreSqlValue(xrefEntity, xrefEntity.getEntityType().getIdAttribute()) : null; case CATEGORICAL_MREF: case MREF: case ONE_TO_MANY: Iterable<Entity> entities = entity.getEntities(attrName); return stream(entities) .map( mrefEntity -> getPostgreSqlValue(mrefEntity, mrefEntity.getEntityType().getIdAttribute())) .collect(toList()); case DATE: return entity.getLocalDate(attrName); case DATE_TIME: Instant instant = entity.getInstant(attrName); return instant != null ? instant.truncatedTo(ChronoUnit.SECONDS).atOffset(UTC) : null; case DECIMAL: return entity.getDouble(attrName); case EMAIL: case ENUM: case HTML: case HYPERLINK: case SCRIPT: case STRING: case TEXT: return entity.getString(attrName); case FILE: FileMeta fileEntity = entity.getEntity(attrName, FileMeta.class); return fileEntity != null ? getPostgreSqlValue(fileEntity, fileEntity.getEntityType().getIdAttribute()) : null; case INT: return entity.getInt(attrName); case LONG: return entity.getLong(attrName); case COMPOUND: throw new IllegalAttributeTypeException(attrType); default: throw new UnexpectedEnumException(attrType); } } }
PostgreSqlUtils { static Object getPostgreSqlValue(Entity entity, Attribute attr) { String attrName = attr.getName(); AttributeType attrType = attr.getDataType(); switch (attrType) { case BOOL: return entity.getBoolean(attrName); case CATEGORICAL: case XREF: Entity xrefEntity = entity.getEntity(attrName); return xrefEntity != null ? getPostgreSqlValue(xrefEntity, xrefEntity.getEntityType().getIdAttribute()) : null; case CATEGORICAL_MREF: case MREF: case ONE_TO_MANY: Iterable<Entity> entities = entity.getEntities(attrName); return stream(entities) .map( mrefEntity -> getPostgreSqlValue(mrefEntity, mrefEntity.getEntityType().getIdAttribute())) .collect(toList()); case DATE: return entity.getLocalDate(attrName); case DATE_TIME: Instant instant = entity.getInstant(attrName); return instant != null ? instant.truncatedTo(ChronoUnit.SECONDS).atOffset(UTC) : null; case DECIMAL: return entity.getDouble(attrName); case EMAIL: case ENUM: case HTML: case HYPERLINK: case SCRIPT: case STRING: case TEXT: return entity.getString(attrName); case FILE: FileMeta fileEntity = entity.getEntity(attrName, FileMeta.class); return fileEntity != null ? getPostgreSqlValue(fileEntity, fileEntity.getEntityType().getIdAttribute()) : null; case INT: return entity.getInt(attrName); case LONG: return entity.getLong(attrName); case COMPOUND: throw new IllegalAttributeTypeException(attrType); default: throw new UnexpectedEnumException(attrType); } } private  PostgreSqlUtils(); }
PostgreSqlUtils { static Object getPostgreSqlValue(Entity entity, Attribute attr) { String attrName = attr.getName(); AttributeType attrType = attr.getDataType(); switch (attrType) { case BOOL: return entity.getBoolean(attrName); case CATEGORICAL: case XREF: Entity xrefEntity = entity.getEntity(attrName); return xrefEntity != null ? getPostgreSqlValue(xrefEntity, xrefEntity.getEntityType().getIdAttribute()) : null; case CATEGORICAL_MREF: case MREF: case ONE_TO_MANY: Iterable<Entity> entities = entity.getEntities(attrName); return stream(entities) .map( mrefEntity -> getPostgreSqlValue(mrefEntity, mrefEntity.getEntityType().getIdAttribute())) .collect(toList()); case DATE: return entity.getLocalDate(attrName); case DATE_TIME: Instant instant = entity.getInstant(attrName); return instant != null ? instant.truncatedTo(ChronoUnit.SECONDS).atOffset(UTC) : null; case DECIMAL: return entity.getDouble(attrName); case EMAIL: case ENUM: case HTML: case HYPERLINK: case SCRIPT: case STRING: case TEXT: return entity.getString(attrName); case FILE: FileMeta fileEntity = entity.getEntity(attrName, FileMeta.class); return fileEntity != null ? getPostgreSqlValue(fileEntity, fileEntity.getEntityType().getIdAttribute()) : null; case INT: return entity.getInt(attrName); case LONG: return entity.getLong(attrName); case COMPOUND: throw new IllegalAttributeTypeException(attrType); default: throw new UnexpectedEnumException(attrType); } } private  PostgreSqlUtils();  }
PostgreSqlUtils { static Object getPostgreSqlValue(Entity entity, Attribute attr) { String attrName = attr.getName(); AttributeType attrType = attr.getDataType(); switch (attrType) { case BOOL: return entity.getBoolean(attrName); case CATEGORICAL: case XREF: Entity xrefEntity = entity.getEntity(attrName); return xrefEntity != null ? getPostgreSqlValue(xrefEntity, xrefEntity.getEntityType().getIdAttribute()) : null; case CATEGORICAL_MREF: case MREF: case ONE_TO_MANY: Iterable<Entity> entities = entity.getEntities(attrName); return stream(entities) .map( mrefEntity -> getPostgreSqlValue(mrefEntity, mrefEntity.getEntityType().getIdAttribute())) .collect(toList()); case DATE: return entity.getLocalDate(attrName); case DATE_TIME: Instant instant = entity.getInstant(attrName); return instant != null ? instant.truncatedTo(ChronoUnit.SECONDS).atOffset(UTC) : null; case DECIMAL: return entity.getDouble(attrName); case EMAIL: case ENUM: case HTML: case HYPERLINK: case SCRIPT: case STRING: case TEXT: return entity.getString(attrName); case FILE: FileMeta fileEntity = entity.getEntity(attrName, FileMeta.class); return fileEntity != null ? getPostgreSqlValue(fileEntity, fileEntity.getEntityType().getIdAttribute()) : null; case INT: return entity.getInt(attrName); case LONG: return entity.getLong(attrName); case COMPOUND: throw new IllegalAttributeTypeException(attrType); default: throw new UnexpectedEnumException(attrType); } } private  PostgreSqlUtils();   }