
vertx-sql.sql_operations.rb Maven / Gradle / Ivy
require 'vertx/util/utils.rb'
# Generated from io.vertx.ext.sql.SQLOperations
module VertxSql
module SQLOperations
# Executes the given SQL SELECT
statement which returns the results of the query.
# @param [String] sql the SQL to execute. For example SELECT * FROM table ...
.
# @yield the handler which is called once the operation completes. It will return a ResultSet
.
# @return [self]
def query(sql=nil)
if sql.class == String && block_given?
@j_del.java_method(:query, [Java::java.lang.String.java_class,Java::IoVertxCore::Handler.java_class]).call(sql,(Proc.new { |ar| yield(ar.failed ? ar.cause : nil, ar.succeeded ? ar.result != nil ? JSON.parse(ar.result.toJson.encode) : nil : nil) }))
return self
end
raise ArgumentError, "Invalid arguments when calling query(#{sql})"
end
# Executes the given SQL SELECT
prepared statement which returns the results of the query.
# @param [String] sql the SQL to execute. For example SELECT * FROM table ...
.
# @param [Array] params these are the parameters to fill the statement.
# @yield the handler which is called once the operation completes. It will return a ResultSet
.
# @return [self]
def query_with_params(sql=nil,params=nil)
if sql.class == String && params.class == Array && block_given?
@j_del.java_method(:queryWithParams, [Java::java.lang.String.java_class,Java::IoVertxCoreJson::JsonArray.java_class,Java::IoVertxCore::Handler.java_class]).call(sql,::Vertx::Util::Utils.to_json_array(params),(Proc.new { |ar| yield(ar.failed ? ar.cause : nil, ar.succeeded ? ar.result != nil ? JSON.parse(ar.result.toJson.encode) : nil : nil) }))
return self
end
raise ArgumentError, "Invalid arguments when calling query_with_params(#{sql},#{params})"
end
# Execute a one shot SQL statement that returns a single SQL row. This method will reduce the boilerplate code by
# getting a connection from the pool (this object) and return it back after the execution. Only the first result
# from the result set is returned.
# @param [String] sql the statement to execute
# @yield the result handler
# @return [self]
def query_single(sql=nil)
if sql.class == String && block_given?
@j_del.java_method(:querySingle, [Java::java.lang.String.java_class,Java::IoVertxCore::Handler.java_class]).call(sql,(Proc.new { |ar| yield(ar.failed ? ar.cause : nil, ar.succeeded ? ar.result != nil ? JSON.parse(ar.result.encode) : nil : nil) }))
return self
end
raise ArgumentError, "Invalid arguments when calling query_single(#{sql})"
end
# Execute a one shot SQL statement with arguments that returns a single SQL row. This method will reduce the
# boilerplate code by getting a connection from the pool (this object) and return it back after the execution.
# Only the first result from the result set is returned.
# @param [String] sql the statement to execute
# @param [Array] arguments the arguments
# @yield the result handler
# @return [self]
def query_single_with_params(sql=nil,arguments=nil)
if sql.class == String && arguments.class == Array && block_given?
@j_del.java_method(:querySingleWithParams, [Java::java.lang.String.java_class,Java::IoVertxCoreJson::JsonArray.java_class,Java::IoVertxCore::Handler.java_class]).call(sql,::Vertx::Util::Utils.to_json_array(arguments),(Proc.new { |ar| yield(ar.failed ? ar.cause : nil, ar.succeeded ? ar.result != nil ? JSON.parse(ar.result.encode) : nil : nil) }))
return self
end
raise ArgumentError, "Invalid arguments when calling query_single_with_params(#{sql},#{arguments})"
end
# Executes the given SQL statement which may be an INSERT
, UPDATE
, or DELETE
# statement.
# @param [String] sql the SQL to execute. For example INSERT INTO table ...
# @yield the handler which is called once the operation completes.
# @return [self]
def update(sql=nil)
if sql.class == String && block_given?
@j_del.java_method(:update, [Java::java.lang.String.java_class,Java::IoVertxCore::Handler.java_class]).call(sql,(Proc.new { |ar| yield(ar.failed ? ar.cause : nil, ar.succeeded ? ar.result != nil ? JSON.parse(ar.result.toJson.encode) : nil : nil) }))
return self
end
raise ArgumentError, "Invalid arguments when calling update(#{sql})"
end
# Executes the given prepared statement which may be an INSERT
, UPDATE
, or DELETE
# statement with the given parameters
# @param [String] sql the SQL to execute. For example INSERT INTO table ...
# @param [Array] params these are the parameters to fill the statement.
# @yield the handler which is called once the operation completes.
# @return [self]
def update_with_params(sql=nil,params=nil)
if sql.class == String && params.class == Array && block_given?
@j_del.java_method(:updateWithParams, [Java::java.lang.String.java_class,Java::IoVertxCoreJson::JsonArray.java_class,Java::IoVertxCore::Handler.java_class]).call(sql,::Vertx::Util::Utils.to_json_array(params),(Proc.new { |ar| yield(ar.failed ? ar.cause : nil, ar.succeeded ? ar.result != nil ? JSON.parse(ar.result.toJson.encode) : nil : nil) }))
return self
end
raise ArgumentError, "Invalid arguments when calling update_with_params(#{sql},#{params})"
end
# Calls the given SQL PROCEDURE
which returns the result from the procedure.
# @param [String] sql the SQL to execute. For example {call getEmpName}
.
# @yield the handler which is called once the operation completes. It will return a ResultSet
.
# @return [self]
def call(sql=nil)
if sql.class == String && block_given?
@j_del.java_method(:call, [Java::java.lang.String.java_class,Java::IoVertxCore::Handler.java_class]).call(sql,(Proc.new { |ar| yield(ar.failed ? ar.cause : nil, ar.succeeded ? ar.result != nil ? JSON.parse(ar.result.toJson.encode) : nil : nil) }))
return self
end
raise ArgumentError, "Invalid arguments when calling call(#{sql})"
end
# Calls the given SQL PROCEDURE
which returns the result from the procedure.
#
# The index of params and outputs are important for both arrays, for example when dealing with a prodecure that
# takes the first 2 arguments as input values and the 3 arg as an output then the arrays should be like:
#
#
# params = [VALUE1, VALUE2, null]
# outputs = [null, null, "VARCHAR"]
#
# @param [String] sql the SQL to execute. For example {call getEmpName (?, ?)}
.
# @param [Array] params these are the parameters to fill the statement.
# @param [Array] outputs these are the outputs to fill the statement.
# @yield the handler which is called once the operation completes. It will return a ResultSet
.
# @return [self]
def call_with_params(sql=nil,params=nil,outputs=nil)
if sql.class == String && params.class == Array && outputs.class == Array && block_given?
@j_del.java_method(:callWithParams, [Java::java.lang.String.java_class,Java::IoVertxCoreJson::JsonArray.java_class,Java::IoVertxCoreJson::JsonArray.java_class,Java::IoVertxCore::Handler.java_class]).call(sql,::Vertx::Util::Utils.to_json_array(params),::Vertx::Util::Utils.to_json_array(outputs),(Proc.new { |ar| yield(ar.failed ? ar.cause : nil, ar.succeeded ? ar.result != nil ? JSON.parse(ar.result.toJson.encode) : nil : nil) }))
return self
end
raise ArgumentError, "Invalid arguments when calling call_with_params(#{sql},#{params},#{outputs})"
end
end
class SQLOperationsImpl
include SQLOperations
# @private
# @param j_del [::VertxSql::SQLOperations] the java delegate
def initialize(j_del)
@j_del = j_del
end
# @private
# @return [::VertxSql::SQLOperations] the underlying java delegate
def j_del
@j_del
end
@@j_api_type = Object.new
def @@j_api_type.accept?(obj)
obj.class == SQLOperations
end
def @@j_api_type.wrap(obj)
SQLOperations.new(obj)
end
def @@j_api_type.unwrap(obj)
obj.j_del
end
def self.j_api_type
@@j_api_type
end
def self.j_class
Java::IoVertxExtSql::SQLOperations.java_class
end
end
end
© 2015 - 2025 Weber Informatics LLC | Privacy Policy