Adaptive Framework  0.9.0
All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Modules Pages
afw_function_indexes.c
Go to the documentation of this file.
1 // See the 'COPYING' file in the project root for licensing information.
2 /*
3  * afw_function_execute_* functions for indexes
4  *
5  * Copyright (c) 2010-2023 Clemson University
6  *
7  */
8 
14 #include "afw_internal.h"
15 #include "afw_adaptor_impl_index.h"
16 
17 
18 /*
19  * Adaptive function: index_create
20  *
21  * afw_function_execute_index_create
22  *
23  * See afw_function_bindings.h for more information.
24  *
25  * Create an index definition.
26  *
27  * This function is not pure, so it may return a different result
28  * given exactly the same parameters and has side effects.
29  *
30  * Declaration:
31  *
32  * ```
33  * function index_create(
34  * adaptorId: string,
35  * key: string,
36  * value?: string,
37  * objectType?: string,
38  * filter?: string,
39  * options?: string,
40  * retroactive?: boolean,
41  * test?: boolean
42  * ): object;
43  * ```
44  *
45  * Parameters:
46  *
47  * adaptorId - (string) Id of adaptor.
48  *
49  * key - (string) Name of the property index to be created.
50  *
51  * value - (optional string) Expression to calculate the index value(s).
52  *
53  * objectType - (optional string) Object Type(s) this index may apply to.
54  *
55  * filter - (optional string) Expression to determine if this index applies
56  * to a particular object.
57  *
58  * options - (optional string) Indexing options.
59  *
60  * retroactive - (optional boolean) Retroactively generate indexes for
61  * existing objects.
62  *
63  * test - (optional boolean) Test create (don't actually perform).
64  *
65  * Returns:
66  *
67  * (object) Object response from the indexing process.
68  */
69 const afw_value_t *
72 {
73  afw_xctx_t *xctx = x->xctx;
74  const afw_value_string_t *adaptorId;
75  const afw_value_string_t *key;
76  const afw_value_string_t *value = NULL;
77  const afw_value_list_t *objectType = NULL;
78  const afw_value_string_t *filter = NULL;
79  const afw_value_list_t *options = NULL;
80  const afw_value_boolean_t *retroactive = NULL;
81  const afw_value_boolean_t *test = NULL;
82  const afw_value_t *parsedFilter;
83  const afw_object_t *result;
84 
87 
88  if (value) {
89  AFW_TRY {
90  /* go ahead and parse the value to make sure it's valid */
92  &value->internal, AFW_FUNCTION_SOURCE_LOCATION,
93  afw_compile_type_expression,
94  NULL, NULL, x->p, xctx);
96  result = afw_object_create_managed(x->p, xctx);
97  afw_object_set_property_as_object(result, &afw_s_error,
98  afw_error_to_object(AFW_ERROR_THROWN, x->p, xctx), xctx);
99  return afw_value_create_object(result, x->p, xctx);
100  }
101 
102  AFW_ENDTRY;
103  }
104 
107  }
108 
111  }
112 
115 
116  /* go ahead and parse the filter to make sure it's valid */
117  parsedFilter = afw_compile_to_value(
118  &filter->internal, AFW_FUNCTION_SOURCE_LOCATION,
119  afw_compile_type_expression,
120  NULL, NULL, x->p, xctx);
121  if (parsedFilter == NULL) {
122  AFW_THROW_ERROR_Z(general, "Error parsing filter expression.", xctx);
123  }
124  }
125 
128  }
129 
132  }
133 
136  }
137 
138  result = afw_adaptor_impl_index_create(
139  &adaptorId->internal, &key->internal,
140  (value ? &value->internal : NULL),
141  (objectType ? objectType->internal : NULL),
142  (filter ? &filter->internal : NULL),
143  (options ? options->internal : NULL),
144  (retroactive ? retroactive->internal : true),
145  (test ? test->internal : false), x->p, xctx);
146 
147  return afw_value_create_object(result, x->p, xctx);
148 }
149 
150 
151 
152 /*
153  * Adaptive function: index_list
154  *
155  * afw_function_execute_index_list
156  *
157  * See afw_function_bindings.h for more information.
158  *
159  * List property indexes
160  *
161  * This function is not pure, so it may return a different result
162  * given exactly the same parameters.
163  *
164  * Declaration:
165  *
166  * ```
167  * function index_list(
168  * adaptorId: string,
169  * objectType?: string
170  * ): object;
171  * ```
172  *
173  * Parameters:
174  *
175  * adaptorId - (string) Id of adaptor.
176  *
177  * objectType - (optional string) Id of adaptive object type indexes.
178  *
179  * Returns:
180  *
181  * (object) Object response from the index repair process.
182  */
183 const afw_value_t *
186 {
187  const afw_value_string_t *adaptorId;
188  const afw_value_string_t *objectType = NULL;
189  const afw_object_t *result;
190 
194  2, string);
195  }
196 
197  result = afw_adaptor_impl_index_list(
198  &adaptorId->internal, (objectType) ? &objectType->internal : NULL,
199  x->p, x->xctx);
200 
201  return afw_value_create_object(result, x->p, x->xctx);
202 }
203 
204 
205 
206 /*
207  * Adaptive function: index_remove
208  *
209  * afw_function_execute_index_remove
210  *
211  * See afw_function_bindings.h for more information.
212  *
213  * Remove an index definition.
214  *
215  * This function is not pure, so it may return a different result
216  * given exactly the same parameters and has side effects.
217  *
218  * Declaration:
219  *
220  * ```
221  * function index_remove(
222  * adaptorId: string,
223  * key: string
224  * ): object;
225  * ```
226  *
227  * Parameters:
228  *
229  * adaptorId - (string) Id of adaptor.
230  *
231  * key - (string) The index key to be removed.
232  *
233  * Returns:
234  *
235  * (object) Object response from the indexing process.
236  */
237 const afw_value_t *
240 {
241  const afw_value_string_t *adaptorId;
242  const afw_value_string_t *key;
243  const afw_object_t *result;
244 
247 
248  result = afw_adaptor_impl_index_remove(
249  &adaptorId->internal, &key->internal, x->p, x->xctx);
250 
251  return afw_value_create_object(result, x->p, x->xctx);
252 }
Helpers for afw_adaptor implementation index development.
Adaptive Framework Core Internal.
afw_object_set_property_as_object(const afw_object_t *object, const afw_utf8_t *property_name, const afw_object_t *internal, afw_xctx_t *xctx)
Set property function for data type object values.
afw_value_create_object(const afw_object_t *internal, const afw_pool_t *p, afw_xctx_t *xctx)
Create function for unmanaged data type object value.
#define afw_compile_to_value(string, source_location, compile_type, parent, shared, p, xctx)
Compile string to adaptive value.
Definition: afw_compile.h:189
#define AFW_CATCH_UNHANDLED
Catch an unhandled error that occurs in a AFW_TRY block.
Definition: afw_error.h:684
#define AFW_ENDTRY
Ends an AFW try block.
Definition: afw_error.h:727
#define AFW_TRY
Begin an AFW TRY block.
Definition: afw_error.h:634
const afw_object_t * afw_error_to_object(const afw_error_t *error, const afw_pool_t *p, afw_xctx_t *xctx)
Create an object with error info in specified pool.
Definition: afw_error.c:998
#define AFW_ERROR_THROWN
Access the thrown error. See AFW_TRY.
Definition: afw_error.h:554
#define AFW_THROW_ERROR_Z(code, message_z, xctx)
Macro used to set error and 0 rv in xctx and throw it.
Definition: afw_error.h:283
#define AFW_FUNCTION_SOURCE_LOCATION
Source location of a value.
Definition: afw_function.h:341
#define AFW_FUNCTION_EVALUATE_REQUIRED_DATA_TYPE_PARAMETER(A_RESULT, A_N, A_TYPE)
Evaluate an arg for a particular data type.
Definition: afw_function.h:328
#define AFW_FUNCTION_PARAMETER_IS_PRESENT(A_N)
Determine if a specific parameter value is present.
Definition: afw_function.h:242
const afw_value_t * afw_function_execute_index_remove(afw_function_execute_t *x)
Adaptive Function index_remove
const afw_value_t * afw_function_execute_index_list(afw_function_execute_t *x)
Adaptive Function index_list
const afw_value_t * afw_function_execute_index_create(afw_function_execute_t *x)
Adaptive Function index_create
#define afw_object_create_managed(p, xctx)
Create an empty entity object in its own pool.
Definition: afw_object.h:913
Function execute parameter.
Definition: afw_function.h:53
afw_xctx_t * xctx
The execution context (xctx) of caller.
Definition: afw_function.h:62
const afw_pool_t * p
Pool for result.
Definition: afw_function.h:59
Interface afw_object public struct.
struct for data type boolean values.
struct for data type list values.
Interface afw_value public struct.
struct for data type string values.
Interface afw_xctx public struct.