From: Miloš Mulač Date: Wed, 5 Oct 2005 10:59:55 +0000 (+0000) Subject: first step toward user queries X-Git-Tag: gridsite-core_R_1_1_12~17 X-Git-Url: http://scientific.zcu.cz/git/?a=commitdiff_plain;h=6a3a3c5b14ad8e2e5a23d3f909f2be6b00448d28;p=jra1mw.git first step toward user queries - query conversions Soap -> C - check indexed attributes --- diff --git a/org.glite.jp.index/src/db_ops.c b/org.glite.jp.index/src/db_ops.c index c605a78..d896575 100644 --- a/org.glite.jp.index/src/db_ops.c +++ b/org.glite.jp.index/src/db_ops.c @@ -447,8 +447,16 @@ int glite_jpis_init_context(glite_jpis_context_t *isctx, glite_jp_context_t jpct 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); diff --git a/org.glite.jp.index/src/db_ops.h b/org.glite.jp.index/src/db_ops.h index 2a02a05..227a51c 100644 --- a/org.glite.jp.index/src/db_ops.h +++ b/org.glite.jp.index/src/db_ops.h @@ -20,10 +20,10 @@ 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; diff --git a/org.glite.jp.index/src/soap_ops.c b/org.glite.jp.index/src/soap_ops.c index bf4da3c..daaffdb 100644 --- a/org.glite.jp.index/src/soap_ops.c +++ b/org.glite.jp.index/src/soap_ops.c @@ -14,7 +14,8 @@ #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 */ @@ -132,12 +133,69 @@ SOAP_FMAC5 int SOAP_FMAC6 __jpsrv__UpdateJobs( } +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; } diff --git a/org.glite.jp.index/src/ws_is_typeref.c b/org.glite.jp.index/src/ws_is_typeref.c index 866ed20..b3f8e2c 100644 --- a/org.glite.jp.index/src/ws_is_typeref.c +++ b/org.glite.jp.index/src/ws_is_typeref.c @@ -74,13 +74,7 @@ static int SoapToQueryRecordVal( } -/** - * 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) @@ -105,11 +99,44 @@ int glite_jpis_SoapToQueryCond( &(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