1. Added two new functions, oilsIDL_links and oilsIDL_fields. They
authorscottmk <scottmk@dcc99617-32d9-48b4-a31d-7c20da2025e4>
Sat, 21 Feb 2009 23:56:29 +0000 (23:56 +0000)
committerscottmk <scottmk@dcc99617-32d9-48b4-a31d-7c20da2025e4>
Sat, 21 Feb 2009 23:56:29 +0000 (23:56 +0000)
return pointers to the links oar fields hash of the IDL, respectively,
for a specified class.  They do not use oilsIDLFindPath() or any form
of strtok().

2. Applied the new oilsIDL_fields function in oilsIDL_ntop()
and oilsIDl_pton().

3. Applied the new oilsIDOL_links function to a couple of spots
in oils_cstore.c, to avoid the inefficient oilsIDLFindPath function.

4. Eliminated a couple of unnecessary lookups for class names that
are already in hand.

git-svn-id: svn://svn.open-ils.org/ILS/trunk@12240 dcc99617-32d9-48b4-a31d-7c20da2025e4

Open-ILS/include/openils/oils_idl.h
Open-ILS/src/c-apps/oils_cstore.c
Open-ILS/src/c-apps/oils_idl-core.c

index d8a1093..07c858e 100644 (file)
@@ -49,6 +49,8 @@ osrfHash* oilsIDLFindPath( const char*, ... );
 */
 
 int oilsIDL_classIsFieldmapper(const char*);
+osrfHash* oilsIDL_links( const char* classname );
+osrfHash* oilsIDL_fields( const char* classname );
 char * oilsIDL_pton(const char *, int);
 int oilsIDL_ntop(const char *, const char *);
 
index d0674cb..5a8eca8 100644 (file)
@@ -1252,7 +1252,7 @@ static int verifyObjectPCRUD (  osrfMethodContext* ctx, const jsonObject* obj )
             );
 
             if (result) {
-                   osrfLogDebug( OSRF_LOG_MARK, "Recieved a result for permission [%s] for user %d at org %d", perm, userid, atoi(context_org) );
+                   osrfLogDebug( OSRF_LOG_MARK, "Received a result for permission [%s] for user %d at org %d", perm, userid, atoi(context_org) );
                 if (dbi_result_first_row(result)) {
                     jsonObject* return_val = oilsMakeJSONFromResult( result );
                     char* has_perm = jsonObjectToSimpleString( jsonObjectGetKeyConst(return_val, "has_perm") );
@@ -2030,7 +2030,8 @@ static char* searchJOIN ( const jsonObject* join_hash, osrfHash* leftmeta ) {
        jsonIterator* search_itr = jsonNewIterator( working_hash );
 
        while ( (snode = jsonIteratorNext( search_itr )) ) {
-               osrfHash* idlClass = osrfHashGet( oilsIDL(), search_itr->key );
+               const char* class = search_itr->key;
+               osrfHash* idlClass = osrfHashGet( oilsIDL(), class );
                if( !idlClass ) {
                        osrfLogError(
                                OSRF_LOG_MARK,
@@ -2045,8 +2046,6 @@ static char* searchJOIN ( const jsonObject* join_hash, osrfHash* leftmeta ) {
                        return NULL;
                }
 
-               const char* class = osrfHashGet(idlClass, "classname");
-
                char* fkey = jsonObjectToSimpleString( jsonObjectGetKeyConst( snode, "fkey" ) );
                char* field = jsonObjectToSimpleString( jsonObjectGetKeyConst( snode, "field" ) );
 
@@ -2091,7 +2090,7 @@ static char* searchJOIN ( const jsonObject* join_hash, osrfHash* leftmeta ) {
                        field = strdup( field );
 
                } else if (!field && !fkey) {
-                       osrfHash* _links = oilsIDLFindPath("/%s/links", leftclass);
+                       osrfHash* _links = oilsIDL_links( leftclass );
 
                        // For each link defined for the left class:
                        // see if the link references the joined class
@@ -2112,7 +2111,7 @@ static char* searchJOIN ( const jsonObject* join_hash, osrfHash* leftmeta ) {
 
                        if (!field || !fkey) {
                                // Do another such search, with the classes reversed
-                               _links = oilsIDLFindPath("/%s/links", class);
+                               _links = oilsIDL_links( class );
 
                                // For each link defined for the joined class:
                                // see if the link references the left class
@@ -2952,9 +2951,9 @@ static char* buildSELECT ( jsonObject* search_hash, jsonObject* order_hash, osrf
        jsonIterator* class_itr = jsonNewIterator( selhash );
        while ( (snode = jsonIteratorNext( class_itr )) ) {
 
-               osrfHash* idlClass = osrfHashGet( oilsIDL(), class_itr->key );
+               char* cname = class_itr->key;
+               osrfHash* idlClass = osrfHashGet( oilsIDL(), cname );
                if (!idlClass) continue;
-               char* cname = osrfHashGet(idlClass, "classname");
 
                if (strcmp(core_class,class_itr->key)) {
                        if (!join_hash) continue;
index 6d511e5..a0aca23 100644 (file)
@@ -437,6 +437,22 @@ static osrfHash* findClassDef( const char* classname ) {
                return osrfHashGet( idlHash, classname );
 }
 
+osrfHash* oilsIDL_links( const char* classname ) {
+       osrfHash* classdef = findClassDef( classname );
+       if( classdef )
+               return osrfHashGet( classdef, "links" );
+       else
+               return NULL;
+}
+
+osrfHash* oilsIDL_fields( const char* classname ) {
+       osrfHash* classdef = findClassDef( classname );
+       if( classdef )
+               return osrfHashGet( classdef, "fields" );
+       else
+               return NULL;
+}
+
 int oilsIDL_classIsFieldmapper ( const char* classname ) {
        if( findClassDef( classname ) )
                return 1;
@@ -444,14 +460,12 @@ int oilsIDL_classIsFieldmapper ( const char* classname ) {
                return 0;
 }
 
+// For a given class: return the array_position associated with a 
+// specified field. (or -1 if it doesn't exist)
 int oilsIDL_ntop (const char* classname, const char* fieldname) {
-       osrfHash* class_def_hash = findClassDef( classname );
-       if( !class_def_hash )
-               return -1;                      // No such class
-       
-       osrfHash* fields_hash = osrfHashGet( class_def_hash, "fields" );
+       osrfHash* fields_hash = oilsIDL_fields( classname );
        if( !fields_hash )
-               return -1;                      // No list of fields fo the class
+               return -1;     // No such class, or no fields for it
 
        osrfHash* field_def_hash = osrfHashGet( fields_hash, fieldname );
        if( !field_def_hash )
@@ -464,14 +478,12 @@ int oilsIDL_ntop (const char* classname, const char* fieldname) {
        return atoi( pos_attr );        // Return position as int
 }
 
+// For a given class: return a copy of the name of the field 
+// at a specified array_position (or NULL if there is none)
 char * oilsIDL_pton (const char* classname, int pos) {
-       osrfHash* class_def_hash = findClassDef( classname );
-       if( !class_def_hash )
-               return NULL;            // No such class
-       
-       osrfHash* fields_hash = osrfHashGet( class_def_hash, "fields" );
+       osrfHash* fields_hash = oilsIDL_fields( classname );
        if( !fields_hash )
-               return NULL;            // No list of fields fo the class
+               return NULL;     // No such class, or no fields for it
 
        char* ret = NULL;
        osrfHash* field_def_hash = NULL;