class PropertySettingStrategy {

    public void setProperty( PropertyContainer entity, String key, Object value ) throws PropertyValueException
    {
        if ( value instanceof Collection )
        {
            if ( ((Collection<?>) value).size() == 0 )
            {
                // Special case: Trying to set an empty array property. We cannot determine the type
                // of the collection now, so we fall back to checking if there already is a collection
                // on the entity, and either leave it intact if it is empty, or set it to an empty collection
                // of the same type as the original
                Object currentValue = entity.getProperty( key, null );
                if ( currentValue != null && currentValue.getClass().isArray() )
                {
                    if ( Array.getLength( currentValue ) == 0 )
                    {
                        // Ok, leave it this way
                        return;
                    }
                    value = emptyArrayOfType( currentValue.getClass().getComponentType() );
                }
                else
                {
                    throw new PropertyValueException( "Unable to set property '" + key + "' to an empty array, " +
                            "because, since there are no values of any type in it, " +
                            "and no pre-existing collection to infer type from, it is not possible " +
                            "to determine what type of array to store." );
                }
            }
            else
            {
                // Non-empty collection
                value = convertToNativeArray( (Collection<?>) value );
            }
        }

        try ( Transaction tx = db.beginTx() )
        {
            entity.setProperty( key, value );
            tx.success();
        }
        catch ( IllegalArgumentException e )
        {
            throw new PropertyValueException( "Could not set property \"" + key + "\", unsupported type: " + value );
        }
    }

    public  PropertySettingStrategy( GraphDatabaseAPI db );

}