Class: VertxSql::SQLConnection

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

Overview

Represents a connection to a SQL database

Instance Method Summary (collapse)

Instance Method Details

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

Calls the given SQL PROCEDURE which returns the result from the procedure.

Parameters:

  • sql (String) (defaults to: nil)
    the SQL to execute. For example {call getEmpName (?, ?)}.

Yields:

  • the handler which is called once the operation completes. It will return a ResultSet.

Returns:

  • (self)

Raises:

  • (ArgumentError)


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

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

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

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"]

Parameters:

  • sql (String) (defaults to: nil)
    the SQL to execute. For example {call getEmpName (?, ?)}.
  • params (Array<String,Object>) (defaults to: nil)
    these are the parameters to fill the statement.
  • outputs (Array<String,Object>) (defaults to: nil)
    these are the outputs to fill the statement.

Yields:

  • the handler which is called once the operation completes. It will return a ResultSet.

Returns:

  • (self)

Raises:

  • (ArgumentError)


111
112
113
114
115
116
117
# File '/Users/julien/java/vertx-stack/stack-docs/target/rb/vertx-sql/sql_connection.rb', line 111

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

- (void) close { ... }

This method returns an undefined value.

Closes the connection. Important to always close the connection when you are done so it's returned to the pool.

Yields:

  • the handler called when this operation completes.

Raises:

  • (ArgumentError)


121
122
123
124
125
126
127
128
# File '/Users/julien/java/vertx-stack/stack-docs/target/rb/vertx-sql/sql_connection.rb', line 121

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) commit { ... }

Commits all changes made since the previous commit/rollback.

Yields:

  • the handler called when this operation completes.

Returns:

  • (self)

Raises:

  • (ArgumentError)


132
133
134
135
136
137
138
# File '/Users/julien/java/vertx-stack/stack-docs/target/rb/vertx-sql/sql_connection.rb', line 132

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

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

Executes the given SQL statement

Parameters:

  • sql (String) (defaults to: nil)
    the SQL to execute. For example CREATE TABLE IF EXISTS table ...

Yields:

  • the handler which is called once this operation completes.

Returns:

  • (self)

Raises:

  • (ArgumentError)


31
32
33
34
35
36
37
# File '/Users/julien/java/vertx-stack/stack-docs/target/rb/vertx-sql/sql_connection.rb', line 31

def execute(sql=nil)
  if sql.class == String && block_given?
    @j_del.java_method(:execute, [Java::java.lang.String.java_class,Java::IoVertxCore::Handler.java_class]).call(sql,(Proc.new { |ar| yield(ar.failed ? ar.cause : nil) }))
    return self
  end
  raise ArgumentError, "Invalid arguments when calling execute(sql)"
end

- (self) get_transaction_isolation { ... }

Attempts to return the transaction isolation level for this Connection object to the one given.

Yields:

  • the handler called when this operation completes.

Returns:

  • (self)

Raises:

  • (ArgumentError)


177
178
179
180
181
182
183
# File '/Users/julien/java/vertx-stack/stack-docs/target/rb/vertx-sql/sql_connection.rb', line 177

def get_transaction_isolation
  if block_given?
    @j_del.java_method(:getTransactionIsolation, [Java::IoVertxCore::Handler.java_class]).call(nil)
    return self
  end
  raise ArgumentError, "Invalid arguments when calling get_transaction_isolation()"
end

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

Executes the given SQL SELECT statement which returns the results of the query.

Parameters:

  • sql (String) (defaults to: nil)
    the SQL to execute. For example SELECT * FROM table ....

Yields:

  • the handler which is called once the operation completes. It will return a ResultSet.

Returns:

  • (self)

Raises:

  • (ArgumentError)


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

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_with_params(sql = nil, params = nil) { ... }

Executes the given SQL SELECT prepared statement which returns the results of the query.

Parameters:

  • sql (String) (defaults to: nil)
    the SQL to execute. For example SELECT * FROM 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. It will return a ResultSet.

Returns:

  • (self)

Raises:

  • (ArgumentError)


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

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

- (self) rollback { ... }

Rolls back all changes made since the previous commit/rollback.

Yields:

  • the handler called when this operation completes.

Returns:

  • (self)

Raises:

  • (ArgumentError)


142
143
144
145
146
147
148
# File '/Users/julien/java/vertx-stack/stack-docs/target/rb/vertx-sql/sql_connection.rb', line 142

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

- (self) set_auto_commit(autoCommit = nil) { ... }

Sets the auto commit flag for this connection. True by default.

Parameters:

  • autoCommit (true, false) (defaults to: nil)
    the autoCommit flag, true by default.

Yields:

  • the handler which is called once this operation completes.

Returns:

  • (self)

Raises:

  • (ArgumentError)


20
21
22
23
24
25
26
# File '/Users/julien/java/vertx-stack/stack-docs/target/rb/vertx-sql/sql_connection.rb', line 20

def set_auto_commit(autoCommit=nil)
  if (autoCommit.class == TrueClass || autoCommit.class == FalseClass) && block_given?
    @j_del.java_method(:setAutoCommit, [Java::boolean.java_class,Java::IoVertxCore::Handler.java_class]).call(autoCommit,(Proc.new { |ar| yield(ar.failed ? ar.cause : nil) }))
    return self
  end
  raise ArgumentError, "Invalid arguments when calling set_auto_commit(autoCommit)"
end

- (self) set_query_timeout(timeoutInSeconds = nil)

Sets a connection wide query timeout. It can be over written at any time and becomes active on the next query call.

Parameters:

  • timeoutInSeconds (Fixnum) (defaults to: nil)
    the max amount of seconds the query can take to execute.

Returns:

  • (self)

Raises:

  • (ArgumentError)


154
155
156
157
158
159
160
# File '/Users/julien/java/vertx-stack/stack-docs/target/rb/vertx-sql/sql_connection.rb', line 154

def set_query_timeout(timeoutInSeconds=nil)
  if timeoutInSeconds.class == Fixnum && !block_given?
    @j_del.java_method(:setQueryTimeout, [Java::int.java_class]).call(timeoutInSeconds)
    return self
  end
  raise ArgumentError, "Invalid arguments when calling set_query_timeout(timeoutInSeconds)"
end

- (self) set_transaction_isolation(isolation = nil) { ... }

Attempts to change the transaction isolation level for this Connection object to the one given. The constants defined in the interface Connection are the possible transaction isolation levels.

Parameters:

  • isolation (:READ_UNCOMMITTED, :READ_COMMITTED, :REPEATABLE_READ, :SERIALIZABLE, :NONE) (defaults to: nil)
    the level of isolation

Yields:

  • the handler called when this operation completes.

Returns:

  • (self)

Raises:

  • (ArgumentError)


167
168
169
170
171
172
173
# File '/Users/julien/java/vertx-stack/stack-docs/target/rb/vertx-sql/sql_connection.rb', line 167

def set_transaction_isolation(isolation=nil)
  if isolation.class == Symbol && block_given?
    @j_del.java_method(:setTransactionIsolation, [Java::IoVertxExtSql::TransactionIsolation.java_class,Java::IoVertxCore::Handler.java_class]).call(Java::IoVertxExtSql::TransactionIsolation.valueOf(isolation),(Proc.new { |ar| yield(ar.failed ? ar.cause : nil) }))
    return self
  end
  raise ArgumentError, "Invalid arguments when calling set_transaction_isolation(isolation)"
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)


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

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)


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

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