59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
|
# File 'ext/aerospike_native/batch.c', line 59
VALUE batch_get(int argc, VALUE* vArgs, VALUE vSelf)
{
VALUE vKeys, vClient, vArray, vBins;
as_batch batch;
as_policy_batch policy;
as_key* key;
aerospike* ptr;
as_error err;
uint32_t n = 0, idx = 0, bins_idx = 0;
if (argc > 3 || argc < 1) { // there should only be 1, 2 or 3 arguments
rb_raise(rb_eArgError, "wrong number of arguments (%d for 1..3)", argc);
}
vKeys = vArgs[0];
Check_Type(vKeys, T_ARRAY);
as_policy_batch_init(&policy);
if (argc == 3) {
vBins = vArgs[1];
Check_Type(vBins, T_ARRAY);
bins_idx = RARRAY_LEN(vBins);
if (TYPE(vArgs[2]) != T_NIL) {
SET_POLICY(policy, vArgs[2]);
}
} else {
switch(TYPE(vArgs[1])) {
case T_NIL:
break;
case T_ARRAY:
vBins = vArgs[1];
bins_idx = RARRAY_LEN(vBins);
break;
case T_HASH: {
SET_POLICY(policy, vArgs[1]);
break;
}
default:
rb_raise(rb_eTypeError, "wrong argument type (expected Array or Hash)");
}
}
idx = RARRAY_LEN(vKeys);
as_batch_inita(&batch, idx);
for(n = 0; n < idx; n++) {
VALUE vKey = rb_ary_entry(vKeys, n);
Data_Get_Struct(vKey, as_key, key);
as_key_init_value(as_batch_keyat(&batch, n), key->ns, key->set, key->valuep);
}
vClient = rb_iv_get(vSelf, "@client");
Data_Get_Struct(vClient, aerospike, ptr);
vArray = rb_ary_new();
if (bins_idx > 0) {
char* sBins[bins_idx];
for(n = 0; n < bins_idx; n++) {
VALUE vEl = rb_ary_entry(vBins, n);
GET_STRING(vEl);
sBins[n] = StringValueCStr(vEl);
}
if (aerospike_batch_get_bins(ptr, &err, &policy, &batch, sBins, bins_idx, batch_read_callback, &vArray) != AEROSPIKE_OK) {
as_batch_destroy(&batch);
raise_aerospike_exception(err.code, err.message);
}
} else {
if (aerospike_batch_get(ptr, &err, &policy, &batch, batch_read_callback, &vArray) != AEROSPIKE_OK) {
as_batch_destroy(&batch);
raise_aerospike_exception(err.code, err.message);
}
}
as_batch_destroy(&batch);
if ( rb_block_given_p() ) {
return Qnil;
}
return vArray;
}
|