[open-ils-commits] r12240 - in trunk/Open-ILS: include/openils src/c-apps (scottmk)

svn at svn.open-ils.org svn at svn.open-ils.org
Sat Feb 21 18:56:30 EST 2009


Author: scottmk
Date: 2009-02-21 18:56:29 -0500 (Sat, 21 Feb 2009)
New Revision: 12240

Modified:
   trunk/Open-ILS/include/openils/oils_idl.h
   trunk/Open-ILS/src/c-apps/oils_cstore.c
   trunk/Open-ILS/src/c-apps/oils_idl-core.c
Log:
1. Added two new functions, oilsIDL_links and oilsIDL_fields.  They
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.


Modified: trunk/Open-ILS/include/openils/oils_idl.h
===================================================================
--- trunk/Open-ILS/include/openils/oils_idl.h	2009-02-19 22:45:13 UTC (rev 12239)
+++ trunk/Open-ILS/include/openils/oils_idl.h	2009-02-21 23:56:29 UTC (rev 12240)
@@ -49,6 +49,8 @@
 */
 
 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 *);
 

Modified: trunk/Open-ILS/src/c-apps/oils_cstore.c
===================================================================
--- trunk/Open-ILS/src/c-apps/oils_cstore.c	2009-02-19 22:45:13 UTC (rev 12239)
+++ trunk/Open-ILS/src/c-apps/oils_cstore.c	2009-02-21 23:56:29 UTC (rev 12240)
@@ -1252,7 +1252,7 @@
             );
 
             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 @@
 	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 @@
 			return NULL;
 		}
 
-		const char* class = osrfHashGet(idlClass, "classname");
-
 		char* fkey = jsonObjectToSimpleString( jsonObjectGetKeyConst( snode, "fkey" ) );
 		char* field = jsonObjectToSimpleString( jsonObjectGetKeyConst( snode, "field" ) );
 
@@ -2091,7 +2090,7 @@
 			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 @@
 
 			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 @@
 	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;

Modified: trunk/Open-ILS/src/c-apps/oils_idl-core.c
===================================================================
--- trunk/Open-ILS/src/c-apps/oils_idl-core.c	2009-02-19 22:45:13 UTC (rev 12239)
+++ trunk/Open-ILS/src/c-apps/oils_idl-core.c	2009-02-21 23:56:29 UTC (rev 12240)
@@ -437,6 +437,22 @@
 		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 @@
 		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 @@
 	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;



More information about the open-ils-commits mailing list