Sha256: 5d13170b74f34368b94eb83c800a9d7ad46949a62526ac098de7fed6839c41f6

Contents?: true

Size: 1.23 KB

Versions: 22

Compression:

Stored size: 1.23 KB

Contents

require 'upsert/merge_function/mysql'

class Upsert
  class MergeFunction
    # @private
    class Java_ComMysqlJdbc_JDBC4Connection < MergeFunction
      include Mysql

      def sql
        @sql ||= begin
          bind_params = Array.new(selector_keys.length + setter_keys.length, '?')
          %{CALL #{name}(#{bind_params.join(', ')})}
        end
      end

      def execute(row)
        first_try = true
        bind_selector_values = row.selector.values.map { |v| connection.bind_value v }
        bind_setter_values = row.setter.values.map { |v| connection.bind_value v }
        begin
          connection.execute sql, (bind_selector_values + bind_setter_values)
        rescue com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException => e
          if e.message =~ /PROCEDURE.*does not exist/i
            if first_try
              Upsert.logger.info %{[upsert] Function #{name.inspect} went missing, trying to recreate}
              first_try = false
              create!
              retry
            else
              Upsert.logger.info %{[upsert] Failed to create function #{name.inspect} for some reason}
              raise e
            end
          else
            raise e
          end
        end
      end


    end
  end
end

Version data entries

22 entries across 22 versions & 1 rubygems

Version Path
upsert-1.1.1 lib/upsert/merge_function/Java_ComMysqlJdbc_JDBC4Connection.rb
upsert-1.1.0 lib/upsert/merge_function/Java_ComMysqlJdbc_JDBC4Connection.rb