Cache Java class constants to speed up lookups
Cache type translator methods so that duplicate Method objects are not created.
Correctly return rows from the database and return them as hashes.
# File lib/sequel/adapters/jdbc.rb, line 611 611: def fetch_rows(sql, &block) 612: execute(sql){|result| process_result_set(result, &block)} 613: self 614: end
Create a named prepared statement that is stored in the database (and connection) for reuse.
# File lib/sequel/adapters/jdbc.rb, line 618 618: def prepare(type, name=nil, *values) 619: ps = to_prepared_statement(type, values) 620: ps.extend(PreparedStatementMethods) 621: if name 622: ps.prepared_statement_name = name 623: db.set_prepared_statement(name, ps) 624: end 625: ps 626: end
Return a callable object that will convert any value of v’s class to a ruby object. If no callable object can handle v’s class, return false so that the negative lookup is cached.
# File lib/sequel/adapters/jdbc.rb, line 680 680: def convert_type_proc(v) 681: case v 682: when JAVA_BIG_DECIMAL 683: DECIMAL_METHOD 684: when JAVA_SQL_TIMESTAMP 685: method(:convert_type_timestamp) 686: when JAVA_SQL_TIME 687: TIME_METHOD 688: when JAVA_SQL_DATE 689: DATE_METHOD 690: when JAVA_BUFFERED_READER 691: BUFFERED_READER_METHOD 692: when JAVA_BYTE_ARRAY 693: BYTE_ARRAY_METHOD 694: when JAVA_SQL_BLOB 695: BLOB_METHOD 696: when JAVA_SQL_CLOB 697: CLOB_METHOD 698: else 699: false 700: end 701: end
Convert the given Java timestamp to an instance of Sequel.datetime_class.
# File lib/sequel/adapters/jdbc.rb, line 673 673: def convert_type_timestamp(v) 674: db.to_application_timestamp([v.getYear + 1900, v.getMonth + 1, v.getDate, v.getHours, v.getMinutes, v.getSeconds, v.getNanos]) 675: end
Extend the dataset with the JDBC stored procedure methods.
# File lib/sequel/adapters/jdbc.rb, line 704 704: def prepare_extend_sproc(ds) 705: ds.extend(StoredProcedureMethods) 706: end
Split out from fetch rows to allow processing of JDBC result sets that don’t come from issuing an SQL string.
# File lib/sequel/adapters/jdbc.rb, line 710 710: def process_result_set(result, &block) 711: # get column names 712: meta = result.getMetaData 713: cols = [] 714: i = 0 715: meta.getColumnCount.times{cols << [output_identifier(meta.getColumnLabel(i+=1)), i]} 716: columns = cols.map{|c| c.at(0)} 717: if opts[:offset] && offset_returns_row_number_column? 718: rn = row_number_column 719: columns.delete(rn) 720: end 721: @columns = columns 722: ct = @convert_types 723: if (ct.nil? ? db.convert_types : ct) 724: cols.each{|c| c << nil} 725: process_result_set_convert(cols, result, rn, &block) 726: else 727: process_result_set_no_convert(cols, result, rn, &block) 728: end 729: ensure 730: result.close 731: end
Use conversion procs to convert data retrieved from the database. This has been optimized, the algorithm it uses is roughly, for each column value in each row:
check if the value is truthy (not false/nil)
if not truthy, return object
otherwise, see if a conversion method exists for the column. All columns start with a nil conversion proc, since unlike other adapters, Sequel doesn’t get the type of the column when parsing the column metadata.
if a conversion proc is not false/nil, call it with the object and return the result.
if a conversion proc has already been looked up and doesn’t exist (false value), return object.
if a conversion proc hasn’t been looked up yet (nil value), call convert_type_proc to get the conversion method. Cache the result of as the column’s conversion proc to speed up later processing. If the conversion proc exists, call it and return the result, otherwise, return the object.
# File lib/sequel/adapters/jdbc.rb, line 751 751: def process_result_set_convert(cols, result, rn) 752: while result.next 753: row = {} 754: cols.each do |n, i, p| 755: v = result.getObject(i) 756: row[n] = if v 757: if p 758: p.call(v) 759: elsif p.nil? 760: cols[i-1][2] = p = convert_type_proc(v) 761: if p 762: p.call(v) 763: else 764: v 765: end 766: else 767: v 768: end 769: else 770: v 771: end 772: end 773: row.delete(rn) if rn 774: yield row 775: end 776: end
Yield rows without calling any conversion procs. This may yield Java values and not ruby values.
# File lib/sequel/adapters/jdbc.rb, line 780 780: def process_result_set_no_convert(cols, result, rn) 781: while result.next 782: row = {} 783: cols.each{|n, i| row[n] = result.getObject(i)} 784: row.delete(rn) if rn 785: yield row 786: end 787: end
Disabled; run with --debug to generate this.
Generated with the Darkfish Rdoc Generator 1.1.6.