Example #1
0
    def get_object_with_index(self, column_index: int) -> typing.Any:
        """Gets the value of the column by index.

        The class of the returned value depends on the SQL type of the column.
        No implicit conversions are performed on the value.

        Warnings:

            Each call to this method might result in a deserialization if the
            column type for this object is :const:`SqlColumnType.OBJECT`.
            It is advised to assign the result of this method call to some
            variable and reuse it.

        Args:
            column_index: Zero-based column index.

        Returns:
            Value of the column.

        Raises:
            IndexError: If the column index is out of bounds.
            AssertionError: If the column index is not an integer.
            HazelcastSqlError: If the object cannot be deserialized.

        See Also:
            :attr:`metadata`

            :attr:`SqlColumnMetadata.type`
        """
        check_is_int(column_index, "Column index must be an integer")
        return self._deserialize_fn(self._row[column_index])
Example #2
0
    def set(self, new_value: int) -> Future[None]:
        """Atomically sets the given value.

        Args:
            new_value: The new value
        """
        check_is_int(new_value)
        codec = atomic_long_get_and_set_codec
        request = codec.encode_request(self._group_id, self._object_name, new_value)
        return self._invoke(request)
    def get_and_add(self, delta):
        """Atomically adds the given value to the current value.

        Args:
            delta (int): The value to add to the current value.

        Returns:
            hazelcast.future.Future[int]: The old value before the add.
        """
        check_is_int(delta)
        codec = atomic_long_get_and_add_codec
        request = codec.encode_request(self._group_id, self._object_name, delta)
        return self._invoke(request, codec.decode_response)
    def get_and_set(self, new_value):
        """Atomically sets the given value and returns the old value.

        Args:
            new_value (int): The new value.

        Returns:
            hazelcast.future.Future[int]: The old value.
        """
        check_is_int(new_value)
        codec = atomic_long_get_and_set_codec
        request = codec.encode_request(self._group_id, self._object_name, new_value)
        return self._invoke(request, codec.decode_response)
Example #5
0
    def add_and_get(self, delta: int) -> Future[int]:
        """Atomically adds the given value to the current value.

        Args:
            delta: The value to add to the current value.

        Returns:
            The updated value, the given value added to the current value.
        """
        check_is_int(delta)
        codec = atomic_long_add_and_get_codec
        request = codec.encode_request(self._group_id, self._object_name, delta)
        return self._invoke(request, codec.decode_response)
Example #6
0
    def get_column(self, index: int) -> SqlColumnMetadata:
        """
        Args:
            index: Zero-based column index.

        Returns:
            Metadata for the given column index.

        Raises:
            IndexError: If the index is out of bounds.
            AssertionError: If the index is not an integer.
        """
        check_is_int(index, "Index must an integer")
        return self._columns[index]
    def compare_and_set(self, expect, update):
        """Atomically sets the value to the given updated value
        only if the current value equals the expected value.

        Args:
            expect (int): The expected value.
            update (int): The new value.

        Returns:
            hazelcast.future.Future[bool]: ``True`` if successful; or ``False`` if
            the actual value was not equal to the expected value.
        """
        check_is_int(expect)
        check_is_int(update)
        codec = atomic_long_compare_and_set_codec
        request = codec.encode_request(self._group_id, self._object_name, expect, update)
        return self._invoke(request, codec.decode_response)
Example #8
0
    def try_set_count(self, count):
        """Sets the count to the given value if the current count is zero.

        If count is not zero, then this method does nothing and returns
        ``False``.

        Args:
            count (int): The number of times ``count_down()`` must be invoked
                before callers can pass through ``await_latch()``.

        Returns:
            hazelcast.future.Future[bool]: ``True`` if the new count was set,
            ``False`` if the current count is not zero.
        """
        check_is_int(count)
        check_true(count > 0, "Count must be positive")
        codec = count_down_latch_try_set_count_codec
        request = codec.encode_request(self._group_id, self._object_name,
                                       count)
        return self._invoke(request, codec.decode_response)
Example #9
0
 def cursor_buffer_size(self, cursor_buffer_size):
     check_is_int(cursor_buffer_size, "Cursor buffer size must an integer")
     if cursor_buffer_size <= 0:
         raise ValueError("Cursor buffer size must be positive, not %s" %
                          cursor_buffer_size)
     self._cursor_buffer_size = cursor_buffer_size