GFunk911-dataload 0.8.2 → 0.8.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/VERSION.yml +1 -1
 - data/lib/dataload/batch_insert.rb +21 -2
 - data/lib/dataload/master_loader.rb +2 -2
 - data/lib/dataload/table_loader.rb +7 -1
 - metadata +1 -1
 
    
        data/VERSION.yml
    CHANGED
    
    
| 
         @@ -1,4 +1,4 @@ 
     | 
|
| 
       1 
     | 
    
         
            -
            class  
     | 
| 
      
 1 
     | 
    
         
            +
            class StandardBatchInsert
         
     | 
| 
       2 
2 
     | 
    
         
             
              include FromHash
         
     | 
| 
       3 
3 
     | 
    
         
             
              attr_accessor :rows, :table_name
         
     | 
| 
       4 
4 
     | 
    
         
             
              fattr(:column_names) { rows.first.sorted_column_names }
         
     | 
| 
         @@ -15,4 +15,23 @@ class BatchInsert 
     | 
|
| 
       15 
15 
     | 
    
         
             
                ActiveRecord::Base.connection.execute(insert_sql) 
         
     | 
| 
       16 
16 
     | 
    
         
             
              end
         
     | 
| 
       17 
17 
     | 
    
         
             
            end
         
     | 
| 
       18 
     | 
    
         
            -
                
         
     | 
| 
      
 18 
     | 
    
         
            +
                
         
     | 
| 
      
 19 
     | 
    
         
            +
            class OracleBatchInsert < StandardBatchInsert
         
     | 
| 
      
 20 
     | 
    
         
            +
              fattr(:insert_sql) do
         
     | 
| 
      
 21 
     | 
    
         
            +
                str = ["INSERT ALL "]
         
     | 
| 
      
 22 
     | 
    
         
            +
                rows.each do |row|
         
     | 
| 
      
 23 
     | 
    
         
            +
                  str << "INTO #{table_name} #{columns_sql} VALUES #{row.insert_values_sql}"
         
     | 
| 
      
 24 
     | 
    
         
            +
                end
         
     | 
| 
      
 25 
     | 
    
         
            +
                str.join("\n") + "\nSELECT * from dual;"
         
     | 
| 
      
 26 
     | 
    
         
            +
              end
         
     | 
| 
      
 27 
     | 
    
         
            +
            end
         
     | 
| 
      
 28 
     | 
    
         
            +
             
     | 
| 
      
 29 
     | 
    
         
            +
            class BatchInsert
         
     | 
| 
      
 30 
     | 
    
         
            +
              def self.get_class
         
     | 
| 
      
 31 
     | 
    
         
            +
                if %w(oci oci8 oracle).include?(MasterLoader.instance.db_ops[:adapter])
         
     | 
| 
      
 32 
     | 
    
         
            +
                  OracleBatchInsert
         
     | 
| 
      
 33 
     | 
    
         
            +
                else
         
     | 
| 
      
 34 
     | 
    
         
            +
                  StandardBatchInsert
         
     | 
| 
      
 35 
     | 
    
         
            +
                end
         
     | 
| 
      
 36 
     | 
    
         
            +
              end
         
     | 
| 
      
 37 
     | 
    
         
            +
            end
         
     | 
| 
         @@ -3,10 +3,10 @@ class MasterLoader 
     | 
|
| 
       3 
3 
     | 
    
         
             
              attr_accessor_nn :raw_table_load_order, :db_ops, :block_size
         
     | 
| 
       4 
4 
     | 
    
         
             
              fattr(:raw_table_delete_order) { raw_table_load_order.reverse }
         
     | 
| 
       5 
5 
     | 
    
         
             
              fattr(:tables_in_load_order) do
         
     | 
| 
       6 
     | 
    
         
            -
                raw_table_load_order.map { |x| table_hash[x.to_s] }
         
     | 
| 
      
 6 
     | 
    
         
            +
                raw_table_load_order.map { |x| table_hash[x.to_s]||raise("can't find table #{x}") }
         
     | 
| 
       7 
7 
     | 
    
         
             
              end
         
     | 
| 
       8 
8 
     | 
    
         
             
              fattr(:tables_in_delete_order) do
         
     | 
| 
       9 
     | 
    
         
            -
                raw_table_delete_order.map { |x| table_hash[x.to_s] }
         
     | 
| 
      
 9 
     | 
    
         
            +
                raw_table_delete_order.map { |x| table_hash[x.to_s]||raise("can't find table #{x}") }
         
     | 
| 
       10 
10 
     | 
    
         
             
              end
         
     | 
| 
       11 
11 
     | 
    
         
             
              fattr(:table_hash) { {} }
         
     | 
| 
       12 
12 
     | 
    
         
             
              def add(tl)
         
     | 
| 
         @@ -38,12 +38,18 @@ class TableLoader 
     | 
|
| 
       38 
38 
     | 
    
         
             
                  yield(target_hashes(rows),i*block_size+rows.size)
         
     | 
| 
       39 
39 
     | 
    
         
             
                end
         
     | 
| 
       40 
40 
     | 
    
         
             
              end
         
     | 
| 
      
 41 
     | 
    
         
            +
              def next_pk
         
     | 
| 
      
 42 
     | 
    
         
            +
                @next_pk ||= 1
         
     | 
| 
      
 43 
     | 
    
         
            +
                @next_pk += 1
         
     | 
| 
      
 44 
     | 
    
         
            +
                @next_pk
         
     | 
| 
      
 45 
     | 
    
         
            +
              end
         
     | 
| 
       41 
46 
     | 
    
         
             
              def load!
         
     | 
| 
       42 
47 
     | 
    
         
             
                migrate!
         
     | 
| 
       43 
48 
     | 
    
         
             
                Dataload.log "Starting load of table '#{table_name}'"
         
     | 
| 
       44 
49 
     | 
    
         
             
                total = 0
         
     | 
| 
       45 
50 
     | 
    
         
             
                target_hash_groups do |hs,num_inserted|
         
     | 
| 
       46 
     | 
    
         
            -
                   
     | 
| 
      
 51 
     | 
    
         
            +
                  hs.each { |h| h[:id] = next_pk }
         
     | 
| 
      
 52 
     | 
    
         
            +
                  BatchInsert.get_class.new(:rows => hs, :table_name => table_name).insert!
         
     | 
| 
       47 
53 
     | 
    
         
             
                  Dataload.log "Inserted #{block_size} rows into table '#{table_name}'.  Total of #{num_inserted} rows inserted."
         
     | 
| 
       48 
54 
     | 
    
         
             
                  total = num_inserted
         
     | 
| 
       49 
55 
     | 
    
         
             
                end
         
     |