Class: VertxSql::SQLClient

Inherits:
Object
  • Object
show all
Includes:
SQLOperations
Defined in:
/Users/julien/java/vertx-stack/stack-docs/target/rb/vertx-sql/sql_client.rb

Overview

A common asynchronous client interface for interacting with SQL compliant database

Direct Known Subclasses

VertxJdbc::JDBCClient, VertxMysqlPostgresql::AsyncSQLClient

Constant Summary

@@j_api_type =
Object.new

Class Method Summary (collapse)

Instance Method Summary (collapse)

Class Method Details

+ (Boolean) accept?(obj)

Returns:

  • (Boolean)


20
21
22
# File '/Users/julien/java/vertx-stack/stack-docs/target/rb/vertx-sql/sql_client.rb', line 20

def @@j_api_type.accept?(obj)
  obj.class == SQLClient
end

+ (Object) j_api_type



29
30
31
# File '/Users/julien/java/vertx-stack/stack-docs/target/rb/vertx-sql/sql_client.rb', line 29

def self.j_api_type
  @@j_api_type
end

+ (Object) j_class



32
33
34
# File '/Users/julien/java/vertx-stack/stack-docs/target/rb/vertx-sql/sql_client.rb', line 32

def self.j_class
  Java::IoVertxExtSql::SQLClient.java_class
end

+ (Object) unwrap(obj)



26
27
28
# File '/Users/julien/java/vertx-stack/stack-docs/target/rb/vertx-sql/sql_client.rb', line 26

def @@j_api_type.unwrap(obj)
  obj.j_del
end

+ (Object) wrap(obj)



23
24
25
# File '/Users/julien/java/vertx-stack/stack-docs/target/rb/vertx-sql/sql_client.rb', line 23

def @@j_api_type.wrap(obj)
  SQLClient.new(obj)
end

Instance Method Details

- (void) close { ... }

This method returns an undefined value.

Close the client and release all resources. Call the handler when close is complete.

Yields:

  • the handler that will be called when close is complete

Raises:

  • (ArgumentError)


77
78
79
80
81
82
83
84
# File '/Users/julien/java/vertx-stack/stack-docs/target/rb/vertx-sql/sql_client.rb', line 77

def close
  if !block_given?
    return @j_del.java_method(:close, []).call()
  elsif block_given?
    return @j_del.java_method(:close, [Java::IoVertxCore::Handler.java_class]).call((Proc.new { |ar| yield(ar.failed ? ar.cause : nil) }))
  end
  raise ArgumentError, "Invalid arguments when calling close()"
end

- (self) get_connection { ... }

Returns a connection that can be used to perform SQL operations on. It's important to remember to close the connection when you are done, so it is returned to the pool.

Yields:

  • the handler which is called when the JdbcConnection object is ready for use.

Returns:

  • (self)

Raises:

  • (ArgumentError)


66
67
68
69
70
71
72
# File '/Users/julien/java/vertx-stack/stack-docs/target/rb/vertx-sql/sql_client.rb', line 66

def get_connection
  if block_given?
    @j_del.java_method(:getConnection, [Java::IoVertxCore::Handler.java_class]).call((Proc.new { |ar| yield(ar.failed ? ar.cause : nil, ar.succeeded ? ::Vertx::Util::Utils.safe_create(ar.result,::VertxSql::SQLConnection) : nil) }))
    return self
  end
  raise ArgumentError, "Invalid arguments when calling get_connection()"
end

- (self) query(sql = nil) { ... }

Execute a single SQL statement, this method acquires a connection from the the pool and executes the SQL statement and returns it back after the execution.

Parameters:

  • sql (String) (defaults to: nil)
    the statement to execute

Yields:

  • the result handler

Returns:

  • (self)

Raises:

  • (ArgumentError)


90
91
92
93
94
95
96
# File '/Users/julien/java/vertx-stack/stack-docs/target/rb/vertx-sql/sql_client.rb', line 90

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

- (self) query_single(sql = nil) { ... }

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.

Parameters:

  • sql (String) (defaults to: nil)
    the statement to execute

Yields:

  • the result handler

Returns:

  • (self)

Raises:

  • (ArgumentError)


41
42
43
44
45
46
47
# File '/Users/julien/java/vertx-stack/stack-docs/target/rb/vertx-sql/sql_client.rb', line 41

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

- (self) query_single_with_params(sql = nil, arguments = nil) { ... }

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.

Parameters:

  • sql (String) (defaults to: nil)
    the statement to execute
  • arguments (Array<String,Object>) (defaults to: nil)
    the arguments

Yields:

  • the result handler

Returns:

  • (self)

Raises:

  • (ArgumentError)


55
56
57
58
59
60
61
# File '/Users/julien/java/vertx-stack/stack-docs/target/rb/vertx-sql/sql_client.rb', line 55

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

- (self) query_with_params(sql = nil, arguments = nil) { ... }

Execute a single SQL prepared statement, this method acquires a connection from the the pool and executes the SQL prepared statement and returns it back after the execution.

Parameters:

  • sql (String) (defaults to: nil)
    the statement to execute
  • arguments (Array<String,Object>) (defaults to: nil)
    the arguments to the statement

Yields:

  • the result handler

Returns:

  • (self)

Raises:

  • (ArgumentError)


103
104
105
106
107
108
109
# File '/Users/julien/java/vertx-stack/stack-docs/target/rb/vertx-sql/sql_client.rb', line 103

def query_with_params(sql=nil,arguments=nil)
  if sql.class == String && arguments.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(arguments),(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},#{arguments})"
end

- (self) update(sql = nil) { ... }

Executes the given SQL statement which may be an INSERT, UPDATE, or DELETE statement.

Parameters:

  • sql (String) (defaults to: nil)
    the SQL to execute. For example INSERT INTO table ...

Yields:

  • the handler which is called once the operation completes.

Returns:

  • (self)

Raises:

  • (ArgumentError)


115
116
117
118
119
120
121
# File '/Users/julien/java/vertx-stack/stack-docs/target/rb/vertx-sql/sql_client.rb', line 115

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

- (self) update_with_params(sql = nil, params = nil) { ... }

Executes the given prepared statement which may be an INSERT, UPDATE, or DELETE statement with the given parameters

Parameters:

  • sql (String) (defaults to: nil)
    the SQL to execute. For example INSERT INTO table ...
  • params (Array<String,Object>) (defaults to: nil)
    these are the parameters to fill the statement.

Yields:

  • the handler which is called once the operation completes.

Returns:

  • (self)

Raises:

  • (ArgumentError)


128
129
130
131
132
133
134
# File '/Users/julien/java/vertx-stack/stack-docs/target/rb/vertx-sql/sql_client.rb', line 128

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