GLITE_JP_DB_TYPE_INT, &(*isctx)->param_uniqueid);
if ((ret = glite_jp_db_prepare(jpctx, "UPDATE feeds SET state=?, expires=? WHERE (uniqueid=?)", &(*isctx)->update_error_feed_stmt, myparam, NULL)) != 0) goto fail_cmd6;
+ // sql command: get info about indexed attributes
+ glite_jp_db_create_results(&myres, 1,
+ GLITE_JP_DB_TYPE_VARCHAR, NULL, &(*isctx)->param_indexed, sizeof((*isctx)->param_indexed), &(*isctx)->param_indexed_len);
+ if ((ret = glite_jp_db_prepare(jpctx, "SELECT name FROM attrs WHERE (indexed=1)", &(*isctx)->select_info_attrs_indexed, NULL, myres)) != 0) goto fail_cmd7;
+
+
return 0;
+
+fail_cmd7:
glite_jp_db_freestmt(&(*isctx)->update_error_feed_stmt);
fail_cmd6:
glite_jp_db_freestmt(&(*isctx)->update_state_feed_stmt);
typedef struct _glite_jpis_context {
glite_jp_context_t jpctx;
- glite_jp_db_stmt_t select_unlocked_feed_stmt, lock_feed_stmt, init_feed_stmt, unlock_feed_stmt, select_info_feed_stmt, update_state_feed_stmt, update_error_feed_stmt;
+ glite_jp_db_stmt_t select_unlocked_feed_stmt, lock_feed_stmt, init_feed_stmt, unlock_feed_stmt, select_info_feed_stmt, update_state_feed_stmt, update_error_feed_stmt, select_info_attrs_indexed;
long int param_uniqueid, param_state;
- char param_feedid[33], param_ps[256];
- unsigned long param_ps_len, param_feedid_len;
+ char param_feedid[33], param_ps[256], param_indexed[256];
+ unsigned long param_ps_len, param_feedid_len, param_indexed_len;
void *param_expires;
} *glite_jpis_context_t;
#include "ws_ps_typeref.h"
#include "ws_is_typeref.h"
-
+#define INDEXED_STRIDE 2 // how often realloc indexed indexed attr result
+ // XXX: 2 is only for debugging, replace with e.g. 100
/*------------------*/
/* Helper functions */
}
+static int checkIndexedConditions(glite_jpis_context_t isctx, struct _jpelem__QueryJobs *in)
+{
+ char **indexed_attrs;
+ int i, j, k, ret;
+
+
+ if ((ret = glite_jp_db_execute(isctx->select_info_attrs_indexed)) == -1) {
+ fprintf(stderr, "Error when executing select_info_attrs_indexed, \
+ returned %d records: %s (%s)\n",
+ ret, isctx->jpctx->error->desc, isctx->jpctx->error->source);
+ return SOAP_FAULT;
+ }
+
+ i = 0;
+ while (glite_jp_db_fetch(isctx->select_info_attrs_indexed) == 0) {
+ if (!(i % INDEXED_STRIDE)) {
+ indexed_attrs = realloc(indexed_attrs,
+ ((i / INDEXED_STRIDE) * INDEXED_STRIDE + 1)
+ * sizeof(*indexed_attrs));
+ }
+ i++;
+ indexed_attrs[i] = strdup(isctx->param_indexed);
+ }
+
+ for (k=0; k < in->__sizeconditions; k++) {
+ for (j=0; j < i; j++) {
+ if (!strcmp(in->conditions[k]->attr, indexed_attrs[j])) {
+ ret = 0;
+ goto end;
+ }
+ }
+ }
+ ret = 1;
+
+end:
+ for (j=0; j < i; j++) free(indexed_attrs[j]);
+ free(indexed_attrs);
+
+ return(ret);
+}
+
+
SOAP_FMAC5 int SOAP_FMAC6 __jpsrv__QueryJobs(
struct soap *soap,
- struct _jpelem__QueryJobs *jpelem__QueryJobs,
- struct _jpelem__QueryJobsResponse *jpelem__QueryJobsResponse)
+ struct _jpelem__QueryJobs *in,
+ struct _jpelem__QueryJobsResponse *out)
{
+ CONTEXT_FROM_SOAP(soap, isctx);
+ glite_jp_context_t jpctx = isctx->jpctx;
+ glite_jp_query_rec_t **qr;
+
+
puts(__FUNCTION__);
+ if ( glite_jpis_SoapToQueryConds(soap, in->__sizeconditions, in->conditions, &qr) ) {
+ return SOAP_ERR;
+ }
+
+ if ( checkIndexedConditions(isctx, in) ) {
+ fprintf(stderr, "No indexed attribute in query\n");
+ return SOAP_ERR;
+ }
+
+
return SOAP_OK;
}
}
-/**
- * Translate JP query condition from soap to C query_rec
- *
- * \param IN Soap structure
- * \param OUT in glite_jp_query_rec_t query record
- */
-int glite_jpis_SoapToQueryCond(
+static int SoapToQueryCond(
struct soap *soap,
struct jptype__indexQuery *in,
glite_jp_query_rec_t **out)
&(qr[i].size2), &(qr[i].value2));
// fall through
default:
- SoapToQueryRecordVal(soap, in->record[i]->value, &(qr[i].binary),
- &(qr[i].size), &(qr[i].value));
+ if ( SoapToQueryRecordVal(soap, in->record[i]->value, &(qr[i].binary),
+ &(qr[i].size), &(qr[i].value)) ) {
+ *out = NULL;
+ return 1;
+ }
break;
}
SoapToAttrOrig(soap, in->origin, &(qr[i].origin) );
}
+
+ *out = qr;
+}
+
+/**
+ * Translate JP query conditions from soap to C query_rec
+ *
+ * \param IN Soap structure
+ * \param OUT array of glite_jp_query_rec_t query records
+ */
+int glite_jpis_SoapToQueryConds(
+ struct soap *soap,
+ int size,
+ struct jptype__indexQuery **in,
+ glite_jp_query_rec_t ***out)
+{
+ glite_jp_query_rec_t **qr;
+ int i;
+
+ assert(in); assert(out);
+ qr = calloc(size+1, sizeof(*qr));
+
+ for (i=0; i<size; i++) {
+ if ( SoapToQueryCond(soap, in[i], &(qr[i])) ) {
+ *out = NULL;
+ return 1;
+ }
+ }
+
+ *out = qr;
}
#ifndef GLITE_JPIS_IS_TYPEREF_H
#define GLITE_JPIS_IS_TYPEREF_H
-int glite_jpis_SoapToQueryCond(struct soap *soap, struct jptype__indexQuery *in, glite_jp_query_rec_t **out);
+int glite_jpis_SoapToQueryConds(struct soap *soap, int size, struct jptype__indexQuery **in, glite_jp_query_rec_t ***out);
#endif