[open-ils-commits] r13508 - trunk/Open-ILS/src/c-apps (scottmk)

svn at svn.open-ils.org svn at svn.open-ils.org
Sun Jul 5 17:42:58 EDT 2009


Author: scottmk
Date: 2009-07-05 17:42:54 -0400 (Sun, 05 Jul 2009)
New Revision: 13508

Modified:
   trunk/Open-ILS/src/c-apps/oils_cstore.c
Log:
More tweaks to oils_cstore.c:

1. In osrfAppInitialize(): reuse the growing_buffer method_name
instead of repeatedly destroying and recreating it.  That should
save hundreds of mallocs and frees in the initialization.

2. Also in osrfAppInitialize(): correct an inaccurate debug
message, and rearrange a few lines for clarity.

3. Throughout: replace the dbi_get_* functions, which do lookups
by name, with the corresponding dbi_get_*_idx functions, which
do lookups by index.  Lookups by index are faster than lookups
by name, because they don't have to do a search.


Modified: trunk/Open-ILS/src/c-apps/oils_cstore.c
===================================================================
--- trunk/Open-ILS/src/c-apps/oils_cstore.c	2009-07-05 19:40:23 UTC (rev 13507)
+++ trunk/Open-ILS/src/c-apps/oils_cstore.c	2009-07-05 21:42:54 UTC (rev 13508)
@@ -167,8 +167,6 @@
 	osrfAppRegisterMethod( MODULENAME, OSRF_BUFFER_C_STR(method_name),
 						   "rollbackSavepoint", "", 1, 0 );
 
-    buffer_free(method_name);
-
 	static const char* global_method[] = {
 		"create",
 		"retrieve",
@@ -185,7 +183,7 @@
     osrfStringArray* classes = osrfHashKeys( oilsIDL() );
     osrfLogDebug(OSRF_LOG_MARK, "%d classes loaded", classes->size );
     osrfLogDebug(OSRF_LOG_MARK,
-		"At least %d methods will be generated", classes->size * global_method_count);
+		"At most %d methods will be generated", classes->size * global_method_count);
 
 	// For each class in IDL...
     while ( (classname = osrfStringArrayGetString(classes, c_index++)) ) {
@@ -237,10 +235,7 @@
                     ( *method_type == 'c' || *method_type == 'u' || *method_type == 'd')
                ) continue;
 
-            osrfHash* method_meta = osrfNewHash();
-            osrfHashSet(method_meta, idlClass, "class");
-
-            method_name =  buffer_init(64);
+            buffer_reset( method_name );
 #ifdef PCRUD
             buffer_fadd(method_name, "%s.%s.%s", MODULENAME, method_type, classname);
 #else
@@ -260,17 +255,19 @@
             free(_fm);
 #endif
 
-            char* method = buffer_release(method_name);
+            char* method = buffer_data(method_name);
 
-            osrfHashSet( method_meta, method, "methodname" );
-            osrfHashSet( method_meta, strdup(method_type), "methodtype" );
-
             int flags = 0;
             if (*method_type == 'i' || *method_type == 's') {
                 flags = flags | OSRF_METHOD_STREAMING;
             }
 
-            osrfAppRegisterExtendedMethod(
+			osrfHash* method_meta = osrfNewHash();
+			osrfHashSet( method_meta, idlClass, "class");
+			osrfHashSet( method_meta, method, "methodname" );
+			osrfHashSet( method_meta, strdup(method_type), "methodtype" );
+
+			osrfAppRegisterExtendedMethod(
                     MODULENAME,
                     method,
                     "dispatchCRUDMethod",
@@ -284,6 +281,7 @@
         } // end for each global method
     } // end for each class in IDL
 
+	buffer_free( method_name );
 	osrfStringArrayFree( classes );
 	
     return 0;
@@ -374,7 +372,6 @@
 
     osrfLogInfo(OSRF_LOG_MARK, "%s successfully connected to the database", MODULENAME);
 
-    unsigned short type;
     int i = 0; 
     char* classname;
     osrfStringArray* classes = osrfHashKeys( oilsIDL() );
@@ -408,26 +405,25 @@
             int columnIndex = 1;
             const char* columnName;
             osrfHash* _f;
-            while( (columnName = dbi_result_get_field_name(result, columnIndex++)) ) {
+            while( (columnName = dbi_result_get_field_name(result, columnIndex)) ) {
 
                 osrfLogInternal(OSRF_LOG_MARK, "Looking for column named [%s]...", (char*)columnName);
 
                 /* fetch the fieldmapper index */
                 if( (_f = osrfHashGet(fields, (char*)columnName)) ) {
 
-                    osrfLogDebug(OSRF_LOG_MARK, "Found [%s] in IDL hash...", (char*)columnName);
+					osrfLogDebug(OSRF_LOG_MARK, "Found [%s] in IDL hash...", (char*)columnName);
 
-                    /* determine the field type and storage attributes */
-                    type = dbi_result_get_field_type(result, columnName);
+					/* determine the field type and storage attributes */
 
-                    switch( type ) {
+					switch( dbi_result_get_field_type_idx(result, columnIndex) ) {
 
 						case DBI_TYPE_INTEGER : {
 
 							if ( !osrfHashGet(_f, "primitive") )
 								osrfHashSet(_f,"number", "primitive");
 
-							int attr = dbi_result_get_field_attribs(result, columnName);
+							int attr = dbi_result_get_field_attribs_idx(result, columnIndex);
 							if( attr & DBI_INTEGER_SIZE8 ) 
 								osrfHashSet(_f,"INT8", "datatype");
 							else 
@@ -469,8 +465,9 @@
                             osrfHashGet(_f, "datatype")
                             );
                 }
-            }
-            dbi_result_free(result);
+				++columnIndex;
+			} // end while loop for traversing result
+			dbi_result_free(result);
         } else {
             osrfLogDebug(OSRF_LOG_MARK, "No data found for class [%s]...", (char*)classname);
         }
@@ -4807,15 +4804,15 @@
 	const char* columnName;
 
 	/* cycle through the column list */
-	while( (columnName = dbi_result_get_field_name(result, columnIndex++)) ) {
+	while( (columnName = dbi_result_get_field_name(result, columnIndex)) ) {
 
 		osrfLogInternal(OSRF_LOG_MARK, "Looking for column named [%s]...", (char*)columnName);
 
 		fmIndex = -1; // reset the position
 		
 		/* determine the field type and storage attributes */
-		type = dbi_result_get_field_type(result, columnName);
-		attr = dbi_result_get_field_attribs(result, columnName);
+		type = dbi_result_get_field_type_idx(result, columnIndex);
+		attr = dbi_result_get_field_attribs_idx(result, columnIndex);
 
 		/* fetch the fieldmapper index */
 		if( (_f = osrfHashGet(fields, (char*)columnName)) ) {
@@ -4832,7 +4829,7 @@
 			continue;
 		}
 
-		if (dbi_result_field_is_null(result, columnName)) {
+		if (dbi_result_field_is_null_idx(result, columnIndex)) {
 			jsonObjectSetIndex( object, fmIndex, jsonNewObject(NULL) );
 		} else {
 
@@ -4842,16 +4839,16 @@
 
 					if( attr & DBI_INTEGER_SIZE8 ) 
 						jsonObjectSetIndex( object, fmIndex, 
-							jsonNewNumberObject(dbi_result_get_longlong(result, columnName)));
+							jsonNewNumberObject(dbi_result_get_longlong_idx(result, columnIndex)));
 					else 
 						jsonObjectSetIndex( object, fmIndex, 
-							jsonNewNumberObject(dbi_result_get_int(result, columnName)));
+							jsonNewNumberObject(dbi_result_get_int_idx(result, columnIndex)));
 
 					break;
 
 				case DBI_TYPE_DECIMAL :
 					jsonObjectSetIndex( object, fmIndex, 
-							jsonNewNumberObject(dbi_result_get_double(result, columnName)));
+							jsonNewNumberObject(dbi_result_get_double_idx(result, columnIndex)));
 					break;
 
 				case DBI_TYPE_STRING :
@@ -4860,7 +4857,7 @@
 					jsonObjectSetIndex(
 						object,
 						fmIndex,
-						jsonNewObject( dbi_result_get_string(result, columnName) )
+						jsonNewObject( dbi_result_get_string_idx(result, columnIndex) )
 					);
 
 					break;
@@ -4870,7 +4867,7 @@
 					memset(dt_string, '\0', sizeof(dt_string));
 					memset(&gmdt, '\0', sizeof(gmdt));
 
-					_tmp_dt = dbi_result_get_datetime(result, columnName);
+					_tmp_dt = dbi_result_get_datetime_idx(result, columnIndex);
 
 
 					if (!(attr & DBI_DATETIME_DATE)) {
@@ -4890,9 +4887,10 @@
 
 				case DBI_TYPE_BINARY :
 					osrfLogError( OSRF_LOG_MARK, 
-						"Can't do binary at column %s : index %d", columnName, columnIndex - 1);
+						"Can't do binary at column %s : index %d", columnName, columnIndex);
 			}
 		}
+		++columnIndex;
 	}
 
 	return object;
@@ -4914,17 +4912,17 @@
 	const char* columnName;
 
 	/* cycle through the column list */
-	while( (columnName = dbi_result_get_field_name(result, columnIndex++)) ) {
+	while( (columnName = dbi_result_get_field_name(result, columnIndex)) ) {
 
 		osrfLogInternal(OSRF_LOG_MARK, "Looking for column named [%s]...", (char*)columnName);
 
 		fmIndex = -1; // reset the position
 		
 		/* determine the field type and storage attributes */
-		type = dbi_result_get_field_type(result, columnName);
-		attr = dbi_result_get_field_attribs(result, columnName);
+		type = dbi_result_get_field_type_idx(result, columnIndex);
+		attr = dbi_result_get_field_attribs_idx(result, columnIndex);
 
-		if (dbi_result_field_is_null(result, columnName)) {
+		if (dbi_result_field_is_null_idx(result, columnIndex)) {
 			jsonObjectSetKey( object, columnName, jsonNewObject(NULL) );
 		} else {
 
@@ -4933,17 +4931,21 @@
 				case DBI_TYPE_INTEGER :
 
 					if( attr & DBI_INTEGER_SIZE8 ) 
-						jsonObjectSetKey( object, columnName, jsonNewNumberObject(dbi_result_get_longlong(result, columnName)) );
+						jsonObjectSetKey( object, columnName,
+								jsonNewNumberObject(dbi_result_get_longlong_idx(result, columnIndex)) );
 					else 
-						jsonObjectSetKey( object, columnName, jsonNewNumberObject(dbi_result_get_int(result, columnName)) );
+						jsonObjectSetKey( object, columnName,
+								jsonNewNumberObject(dbi_result_get_int_idx(result, columnIndex)) );
 					break;
 
 				case DBI_TYPE_DECIMAL :
-					jsonObjectSetKey( object, columnName, jsonNewNumberObject(dbi_result_get_double(result, columnName)) );
+					jsonObjectSetKey( object, columnName,
+							jsonNewNumberObject(dbi_result_get_double_idx(result, columnIndex)) );
 					break;
 
 				case DBI_TYPE_STRING :
-					jsonObjectSetKey( object, columnName, jsonNewObject(dbi_result_get_string(result, columnName)) );
+					jsonObjectSetKey( object, columnName,
+							jsonNewObject(dbi_result_get_string_idx(result, columnIndex)) );
 					break;
 
 				case DBI_TYPE_DATETIME :
@@ -4951,7 +4953,7 @@
 					memset(dt_string, '\0', sizeof(dt_string));
 					memset(&gmdt, '\0', sizeof(gmdt));
 
-					_tmp_dt = dbi_result_get_datetime(result, columnName);
+					_tmp_dt = dbi_result_get_datetime_idx(result, columnIndex);
 
 
 					if (!(attr & DBI_DATETIME_DATE)) {
@@ -4970,10 +4972,11 @@
 
 				case DBI_TYPE_BINARY :
 					osrfLogError( OSRF_LOG_MARK, 
-						"Can't do binary at column %s : index %d", columnName, columnIndex - 1);
+						"Can't do binary at column %s : index %d", columnName, columnIndex );
 			}
 		}
-	}
+		++columnIndex;
+	} // end while loop traversing result
 
 	return object;
 }



More information about the open-ils-commits mailing list