Exemplo n.º 1
0
def __resource_close(conn, cursor):
    query_struct = Query(OP_RESOURCE_CLOSE, [
        ('cursor', Long),
    ])
    return query_perform(query_struct, conn, query_params={
        'cursor': cursor,
    })
Exemplo n.º 2
0
def __cache_get_configuration(connection, cache_info):
    query_struct = Query(OP_CACHE_GET_CONFIGURATION,
                         [('cache_info', CacheInfo)])
    return query_perform(query_struct,
                         connection,
                         query_params={'cache_info': cache_info},
                         response_config=[('cache_config',
                                           get_cache_config_struct(
                                               connection.protocol_context))],
                         post_process_fun=__post_process_cache_config)
Exemplo n.º 3
0
def __cluster_get_state(connection):
    if not connection.protocol_context.is_cluster_api_supported():
        raise NotSupportedByClusterError('Cluster API is not supported by the cluster')

    query_struct = Query(OP_CLUSTER_GET_STATE)
    return query_perform(
        query_struct, connection,
        response_config=[('state', Byte)],
        post_process_fun=__post_process_get_state
    )
Exemplo n.º 4
0
def __cache_remove_all(connection, cache_info):
    query_struct = Query(OP_CACHE_REMOVE_ALL, [
        ('cache_info', CacheInfo),
    ])
    return query_perform(
        query_struct,
        connection,
        query_params={
            'cache_info': cache_info,
        },
    )
Exemplo n.º 5
0
def __get_binary_type(conn, binary_type):
    query_struct = Query(OP_GET_BINARY_TYPE, [
        ('type_id', Int),
    ],
                         response_type=BinaryTypeResponse)

    return query_perform(query_struct,
                         conn,
                         query_params={
                             'type_id': entity_id(binary_type),
                         })
Exemplo n.º 6
0
def __tx_end(conn, tx_id, committed):
    query_struct = Query(
        OP_TX_END,
        [('tx_id', Int), ('committed', Bool)],
    )
    return query_perform(query_struct,
                         conn,
                         query_params={
                             'tx_id': tx_id,
                             'committed': committed
                         })
Exemplo n.º 7
0
def __cache_clear(connection, cache_info):
    query_struct = Query(OP_CACHE_CLEAR, [
        ('cache_info', CacheInfo),
    ])
    return query_perform(
        query_struct,
        connection,
        query_params={
            'cache_info': cache_info,
        },
    )
Exemplo n.º 8
0
def __cache_put(connection, cache_info, key, value, key_hint, value_hint):
    query_struct = Query(OP_CACHE_PUT, [
        ('cache_info', CacheInfo),
        ('key', key_hint or AnyDataObject),
        ('value', value_hint or AnyDataObject),
    ])
    return query_perform(query_struct,
                         connection,
                         query_params={
                             'cache_info': cache_info,
                             'key': key,
                             'value': value
                         })
Exemplo n.º 9
0
def __cache_clear_key(connection, cache_info, key, key_hint):
    query_struct = Query(OP_CACHE_CLEAR_KEY, [
        ('cache_info', CacheInfo),
        ('key', key_hint or AnyDataObject),
    ])
    return query_perform(
        query_struct,
        connection,
        query_params={
            'cache_info': cache_info,
            'key': key,
        },
    )
Exemplo n.º 10
0
def __cache_remove_keys(connection, cache_info, keys):
    query_struct = Query(OP_CACHE_REMOVE_KEYS, [
        ('cache_info', CacheInfo),
        ('keys', AnyDataArray()),
    ])
    return query_perform(
        query_struct,
        connection,
        query_params={
            'cache_info': cache_info,
            'keys': keys,
        },
    )
Exemplo n.º 11
0
def __cache_put_all(connection, cache_info, pairs):
    query_struct = Query(OP_CACHE_PUT_ALL, [
        ('cache_info', CacheInfo),
        ('data', Map),
    ])
    return query_perform(
        query_struct,
        connection,
        query_params={
            'cache_info': cache_info,
            'data': pairs,
        },
    )
Exemplo n.º 12
0
def __tx_start(conn, concurrency, isolation, timeout, label):
    query_struct = Query(OP_TX_START, [('concurrency', Byte),
                                       ('isolation', Byte), ('timeout', Long),
                                       ('label', String)])
    return query_perform(query_struct,
                         conn,
                         query_params={
                             'concurrency': concurrency,
                             'isolation': isolation,
                             'timeout': timeout,
                             'label': label
                         },
                         response_config=[('tx_id', Int)])
Exemplo n.º 13
0
def __scan_cursor_get_page(conn, cursor):
    query_struct = Query(OP_QUERY_SCAN_CURSOR_GET_PAGE, [
        ('cursor', Long),
    ])
    return query_perform(query_struct,
                         conn,
                         query_params={
                             'cursor': cursor,
                         },
                         response_config=[
                             ('data', Map),
                             ('more', Bool),
                         ],
                         post_process_fun=__query_result_post_process)
Exemplo n.º 14
0
def __sql_fields(conn, cache_info, query_str, page_size, query_args, schema,
                 statement_type, distributed_joins, local, replicated_only,
                 enforce_join_order, collocated, lazy, include_field_names,
                 max_rows, timeout):
    if query_args is None:
        query_args = []

    query_struct = Query(OP_QUERY_SQL_FIELDS, [
        ('cache_info', CacheInfo),
        ('schema', String),
        ('page_size', Int),
        ('max_rows', Int),
        ('query_str', String),
        ('query_args', AnyDataArray()),
        ('statement_type', StatementType),
        ('distributed_joins', Bool),
        ('local', Bool),
        ('replicated_only', Bool),
        ('enforce_join_order', Bool),
        ('collocated', Bool),
        ('lazy', Bool),
        ('timeout', Long),
        ('include_field_names', Bool),
    ],
                         response_type=SQLResponse)

    return query_perform(
        query_struct,
        conn,
        query_params={
            'cache_info': cache_info,
            'schema': schema,
            'page_size': page_size,
            'max_rows': max_rows,
            'query_str': query_str,
            'query_args': query_args,
            'statement_type': statement_type,
            'distributed_joins': distributed_joins,
            'local': local,
            'replicated_only': replicated_only,
            'enforce_join_order': enforce_join_order,
            'collocated': collocated,
            'lazy': lazy,
            'timeout': timeout,
            'include_field_names': include_field_names,
        },
        include_field_names=include_field_names,
        has_cursor=True,
    )
Exemplo n.º 15
0
def __cache_contains_keys(connection, cache_info, keys):
    query_struct = Query(OP_CACHE_CONTAINS_KEYS, [
        ('cache_info', CacheInfo),
        ('keys', AnyDataArray()),
    ])
    return query_perform(query_struct,
                         connection,
                         query_params={
                             'cache_info': cache_info,
                             'keys': keys,
                         },
                         response_config=[
                             ('value', Bool),
                         ],
                         post_process_fun=__post_process_value_by_key('value'))
Exemplo n.º 16
0
def __cache_contains_key(connection, cache_info, key, key_hint):
    query_struct = Query(OP_CACHE_CONTAINS_KEY, [
        ('cache_info', CacheInfo),
        ('key', key_hint or AnyDataObject),
    ])
    return query_perform(query_struct,
                         connection,
                         query_params={
                             'cache_info': cache_info,
                             'key': key,
                         },
                         response_config=[
                             ('value', Bool),
                         ],
                         post_process_fun=__post_process_value_by_key('value'))
Exemplo n.º 17
0
def __cache_get_and_remove(connection, cache_info, key, key_hint):
    query_struct = Query(OP_CACHE_GET_AND_REMOVE, [
        ('cache_info', CacheInfo),
        ('key', key_hint or AnyDataObject),
    ])
    return query_perform(query_struct,
                         connection,
                         query_params={
                             'cache_info': cache_info,
                             'key': key,
                         },
                         response_config=[
                             ('value', AnyDataObject),
                         ],
                         post_process_fun=__post_process_value_by_key('value'))
Exemplo n.º 18
0
def __cache_get_all(connection, cache_info, keys):
    query_struct = Query(OP_CACHE_GET_ALL, [
        ('cache_info', CacheInfo),
        ('keys', AnyDataArray()),
    ])
    return query_perform(query_struct,
                         connection,
                         query_params={
                             'cache_info': cache_info,
                             'keys': keys,
                         },
                         response_config=[
                             ('data', Map),
                         ],
                         post_process_fun=__post_process_value_by_key('data'))
Exemplo n.º 19
0
def __sql_fields_cursor_get_page(conn, cursor, field_count):
    query_struct = Query(OP_QUERY_SQL_FIELDS_CURSOR_GET_PAGE, [
        ('cursor', Long),
    ])
    return query_perform(query_struct,
                         conn,
                         query_params={
                             'cursor': cursor,
                         },
                         response_config=[
                             ('data',
                              StructArray([(f'field_{i}', AnyDataObject)
                                           for i in range(field_count)])),
                             ('more', Bool),
                         ],
                         post_process_fun=__post_process_sql_fields_cursor)
Exemplo n.º 20
0
def __cluster_set_state(connection, state):
    if not ClusterState.has_value(state):
        raise ClusterError(f'Unknown cluster state [state={state}]')
    if not connection.protocol_context.is_cluster_api_supported():
        raise NotSupportedByClusterError('Cluster API is not supported by the cluster')

    query_struct = Query(
        OP_CLUSTER_CHANGE_STATE,
        [
            ('state', Byte)
        ]
    )
    return query_perform(
        query_struct, connection,
        query_params={
            'state': state,
        }
    )
Exemplo n.º 21
0
def __cache_replace(connection, cache_info, key, value, key_hint, value_hint):
    query_struct = Query(OP_CACHE_REPLACE, [
        ('cache_info', CacheInfo),
        ('key', key_hint or AnyDataObject),
        ('value', value_hint or AnyDataObject),
    ])
    return query_perform(
        query_struct,
        connection,
        query_params={
            'cache_info': cache_info,
            'key': key,
            'value': value,
        },
        response_config=[
            ('success', Bool),
        ],
        post_process_fun=__post_process_value_by_key('success'))
Exemplo n.º 22
0
def __cache_get_and_put_if_absent(connection, cache_info, key, value, key_hint,
                                  value_hint):
    query_struct = Query(OP_CACHE_GET_AND_PUT_IF_ABSENT, [
        ('cache_info', CacheInfo),
        ('key', key_hint or AnyDataObject),
        ('value', value_hint or AnyDataObject),
    ])
    return query_perform(query_struct,
                         connection,
                         query_params={
                             'cache_info': cache_info,
                             'key': key,
                             'value': value,
                         },
                         response_config=[
                             ('value', AnyDataObject),
                         ],
                         post_process_fun=__post_process_value_by_key('value'))
Exemplo n.º 23
0
def __cache_create_with_config(op_code, connection, cache_props):
    prop_types, prop_values = {}, {}
    is_expiry_policy_supported = connection.protocol_context.is_expiry_policy_supported(
    )
    for i, prop_item in enumerate(cache_props.items()):
        prop_code, prop_value = prop_item
        if prop_code == PROP_EXPIRY_POLICY and not is_expiry_policy_supported:
            raise NotSupportedByClusterError(
                "'ExpiryPolicy' API is not supported by the cluster")

        prop_name = 'property_{}'.format(i)
        prop_types[prop_name] = prop_map(prop_code)
        prop_values[prop_name] = prop_value
    prop_values['param_count'] = len(cache_props)

    following = [('param_count', Short)] + list(prop_types.items())
    query_struct = ConfigQuery(op_code, following)
    return query_perform(query_struct, connection, query_params=prop_values)
Exemplo n.º 24
0
def __cache_remove_if_equals(connection, cache_info, key, sample, key_hint,
                             sample_hint):
    query_struct = Query(OP_CACHE_REMOVE_IF_EQUALS, [
        ('cache_info', CacheInfo),
        ('key', key_hint or AnyDataObject),
        ('sample', sample_hint or AnyDataObject),
    ])
    return query_perform(
        query_struct,
        connection,
        query_params={
            'cache_info': cache_info,
            'key': key,
            'sample': sample,
        },
        response_config=[
            ('success', Bool),
        ],
        post_process_fun=__post_process_value_by_key('success'))
Exemplo n.º 25
0
def __cache_get_node_partitions(conn, caches):
    query_struct = Query(OP_CACHE_PARTITIONS, [
        ('cache_ids', cache_ids),
    ])
    if not is_iterable(caches):
        caches = [caches]

    return query_perform(query_struct,
                         conn,
                         query_params={
                             'cache_ids': [{
                                 'cache_id': cache
                             } for cache in caches],
                         },
                         response_config=[
                             ('version_major', Long),
                             ('version_minor', Int),
                             ('partition_mapping', partition_mapping),
                         ],
                         post_process_fun=__post_process_partitions)
Exemplo n.º 26
0
def __cache_get_size(connection, cache_info, peek_modes):
    if peek_modes is None:
        peek_modes = []
    elif not isinstance(peek_modes, (list, tuple)):
        peek_modes = [peek_modes]

    query_struct = Query(OP_CACHE_GET_SIZE, [
        ('cache_info', CacheInfo),
        ('peek_modes', ByteArray),
    ])
    return query_perform(query_struct,
                         connection,
                         query_params={
                             'cache_info': cache_info,
                             'peek_modes': peek_modes,
                         },
                         response_config=[
                             ('count', Long),
                         ],
                         post_process_fun=__post_process_value_by_key('count'))
Exemplo n.º 27
0
def __cache_local_peek(conn, cache_info, key, key_hint, peek_modes):
    if peek_modes is None:
        peek_modes = []
    elif not isinstance(peek_modes, (list, tuple)):
        peek_modes = [peek_modes]

    query_struct = Query(OP_CACHE_LOCAL_PEEK, [
        ('cache_info', CacheInfo),
        ('key', key_hint or AnyDataObject),
        ('peek_modes', ByteArray),
    ])
    return query_perform(query_struct,
                         conn,
                         query_params={
                             'cache_info': cache_info,
                             'key': key,
                             'peek_modes': peek_modes,
                         },
                         response_config=[
                             ('value', AnyDataObject),
                         ],
                         post_process_fun=__post_process_value_by_key('value'))
Exemplo n.º 28
0
def __scan(conn, cache_info, page_size, partitions, local):
    query_struct = Query(OP_QUERY_SCAN, [
        ('cache_info', CacheInfo),
        ('filter', Null),
        ('page_size', Int),
        ('partitions', Int),
        ('local', Bool),
    ])
    return query_perform(query_struct,
                         conn,
                         query_params={
                             'cache_info': cache_info,
                             'filter': None,
                             'page_size': page_size,
                             'partitions': partitions,
                             'local': 1 if local else 0,
                         },
                         response_config=[
                             ('cursor', Long),
                             ('data', Map),
                             ('more', Bool),
                         ],
                         post_process_fun=__query_result_post_process)
Exemplo n.º 29
0
def __cache_destroy(connection, cache):
    query_struct = Query(OP_CACHE_DESTROY, [('cache_id', Int)])

    return query_perform(query_struct,
                         connection,
                         query_params={'cache_id': cache_id(cache)})
Exemplo n.º 30
0
def __cache_get_names(connection):
    query_struct = Query(OP_CACHE_GET_NAMES)
    return query_perform(query_struct,
                         connection,
                         response_config=[('cache_names', StringArray)],
                         post_process_fun=__post_process_cache_names)