def __resource_close(conn, cursor): query_struct = Query(OP_RESOURCE_CLOSE, [ ('cursor', Long), ]) return query_perform(query_struct, conn, query_params={ 'cursor': cursor, })
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)
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 )
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, }, )
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), })
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 })
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, }, )
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 })
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, }, )
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, }, )
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, }, )
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)])
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)
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, )
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'))
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'))
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'))
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'))
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)
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, } )
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'))
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'))
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)
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'))
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)
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'))
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'))
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)
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)})
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)