Class QueryBinding
java.lang.Object
com.invirgance.convirgance.web.binding.QueryBinding
- All Implemented Interfaces:
Binding
For retrieving data from SQL database.
QueryBinding executes parameterized SQL queries against a database and
returns the results as JSON objects. It supports named parameter binding,
allowing request parameters to be safely used in SQL statements.
- Author:
- jbanes
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionIterable
<com.invirgance.convirgance.json.JSONObject> getBinding
(com.invirgance.convirgance.json.JSONObject parameters) Executes the SQL query with the provided parameters.The JNDI name used to look up the database connection.getSql()
Returns the SQL query that will be executed.void
setJndiName
(String jndiName) Sets the JNDI name for the data source lookup.void
Sets the query used to retrieve data.
-
Constructor Details
-
QueryBinding
public QueryBinding()
-
-
Method Details
-
getJndiName
The JNDI name used to look up the database connection.This property must reference a valid JNDI resource that returns a
DataSource
.- Returns:
- the JNDI name
-
setJndiName
Sets the JNDI name for the data source lookup.- Parameters:
jndiName
- The JDNI name.
-
getSql
Returns the SQL query that will be executed.- Returns:
- The SQL query.
-
setSql
Sets the query used to retrieve data. Named bindings can be used, they will be bound by key, to the parameters provided through throughgetBinding(JSONObject)
.- Parameters:
sql
- The new SQL query.
-
getBinding
public Iterable<com.invirgance.convirgance.json.JSONObject> getBinding(com.invirgance.convirgance.json.JSONObject parameters) Executes the SQL query with the provided parameters. Parameter values are bound to named parameters in the SQL query.- Specified by:
getBinding
in interfaceBinding
- Parameters:
parameters
- JSON object containing parameter names and values- Returns:
- Query results as an iterable of JSONObjects
-