When loading the IDL code in C or Perl: generate the array_positions
authorscottmk <scottmk@dcc99617-32d9-48b4-a31d-7c20da2025e4>
Wed, 29 Apr 2009 16:06:00 +0000 (16:06 +0000)
committerscottmk <scottmk@dcc99617-32d9-48b4-a31d-7c20da2025e4>
Wed, 29 Apr 2009 16:06:00 +0000 (16:06 +0000)
based on the sequence in which the fields appear in the IDL file
(rather than from attributes in the <field> elements).

In most cases this change will make no difference, because the
fields appear in sequence.  However for classes "brn" and "mvr" the
sequences of fields in the IDL are scrambled.  For those classes,
this change will effectively renumber the fields.

This commit does not affect the corresponding Python or Java code.
So don't go editing the IDL yet to remove the array_position
attributes.

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

Open-ILS/src/c-apps/oils_idl-core.c
Open-ILS/src/perlmods/OpenILS/Utils/Fieldmapper.pm

index c263141..b0cce8d 100644 (file)
@@ -119,6 +119,8 @@ osrfHash* oilsIDLInit( const char* idl_filename ) {
                                                );
                                        }
 
+                                       unsigned int array_pos = 0;
+                                       char array_pos_buf[ 7 ];  // For up to 1,000,000 fields per class
                                        xmlNodePtr _f = _cur->children;
 
                                        while(_f) {
@@ -129,13 +131,9 @@ osrfHash* oilsIDLInit( const char* idl_filename ) {
 
                                                osrfHash* field_def_hash = osrfNewHash();
 
-                                               if( (prop_str = (char*)xmlGetNsProp(_f, BAD_CAST "array_position", BAD_CAST OBJECT_NS)) ) {
-                                                       osrfHashSet(
-                                                               field_def_hash,
-                                                               prop_str,
-                                                               "array_position"
-                                                       );
-                                               }
+                                               // Insert array_position
+                                               snprintf( array_pos_buf, sizeof( array_pos_buf ), "%u", array_pos++ );
+                                               osrfHashSet( field_def_hash, strdup( array_pos_buf ), "array_position" );
 
                                                if( (prop_str = (char*)xmlGetNsProp(_f, BAD_CAST "i18n", BAD_CAST PERSIST_NS)) ) {
                                                        osrfHashSet(
index ac0190f..308976b 100644 (file)
@@ -71,13 +71,13 @@ sub load_fields {
 
        # Load each field -------------------------------------------
 
+       my $array_position = 0;
        for my $field ( $field_list->childNodes() ) {    # For each <field>
                if( $field->nodeName eq 'field' ) {
        
                        my $attribute_list = $field->attributes();
                        
                        my $name     = get_attribute( $attribute_list, 'name' );
-                       my $array_position = get_attribute( $attribute_list, 'oils_obj:array_position' );
                        my $virtual  = get_attribute( $attribute_list, 'oils_persist:virtual' );
                        if( ! defined( $virtual ) ) {
                                $virtual = "false";
@@ -96,6 +96,8 @@ sub load_fields {
                        if( defined( $selector ) ) {
                                $$fieldmap{$fm}{selector} = $selector;
                        }
+
+                       ++$array_position;
                }
        }
 }